改良的 sp_lock 函数 xp_lock

CREATE PROCEDURE dbo.xp_lock --- 2008-04-18 彦程工作室(http://www.greatengine.com) 萧鹏 改良自 sp_lock
@spid1 int = NULL,  /* server process id to check for locks */
@spid2 int = NULL  /* other process id to check for locks */
as
declare @sql nvarchar(4000)
declare @dbid smallint
declare @dbname nvarchar(256)

set nocount on
/*
**  Show the locks for both parameters.
*/
if @spid1 is not NULL
begin
 select  convert (smallint, req_spid) As spid,
  p.hostname,
  p.program_name,
  p.loginame,
  d.name As dbname,
  rsc_dbid As dbid,
  rsc_objid As ObjId,
  convert(nvarchar(256),'') as ObjName,
  rsc_indid As IndId,
  convert(nvarchar(256),'') as IndName,
  substring (v.name, 1, 4) As Type,
  substring (rsc_text, 1, 16) as Resource,
  substring (u.name, 1, 8) As Mode,
  substring (x.name, 1, 5) As Status
 into #xp_lock
 from  master.dbo.syslockinfo,
  master.dbo.spt_values v,
  master.dbo.spt_values x,
  master.dbo.spt_values u,
  master.dbo.sysdatabases d,
  master.dbo.sysprocesses p
 where   master.dbo.syslockinfo.rsc_type = v.number
  and v.type = 'LR'
  and master.dbo.syslockinfo.req_status = x.number
  and x.type = 'LS'
  and master.dbo.syslockinfo.req_mode + 1 = u.number
  and u.type = 'L'
  and req_spid in (@spid1, @spid2)
  and d.dbid=rsc_dbid
  and req_spid=p.spid

 declare cur_get_dbname cursor forward_only read_only for
 select distinct dbname,dbid
 from #xp_lock

 open cur_get_dbname
 fetch next from cur_get_dbname into @dbname,@dbid
 
 while (@@fetch_status = 0)
 begin
  select @sql=N'update #xp_lock set ObjName=b.name from #xp_lock a,'+@dbname+N'.dbo.sysobjects b where a.ObjId=b.id and a.dbid='+Convert(nvarchar(256),@dbid)
  exec(@sql)
 
  select @sql=N'update #xp_lock set IndName=b.name from #xp_lock a,'+@dbname+N'.dbo.sysobjects b where a.IndId=b.id and a.dbid='+Convert(nvarchar(256),@dbid)
  exec(@sql)
 
  fetch next from cur_get_dbname into @dbname,@dbid
 end
 close cur_get_dbname
 deallocate cur_get_dbname

 select * from #xp_lock
end

/*
**  No parameters, so show all the locks.
*/
else
begin
 select  convert (smallint, req_spid) As spid,
  p.hostname,
  p.program_name,
  p.loginame,
  d.name As dbname,
  rsc_dbid As dbid,
  rsc_objid As ObjId,
  convert(nvarchar(256),'') as ObjName,
  rsc_indid As IndId,
  convert(nvarchar(256),'') as IndName,
  substring (v.name, 1, 4) As Type,
  substring (rsc_text, 1, 16) as Resource,
  substring (u.name, 1, 8) As Mode,
  substring (x.name, 1, 5) As Status

 into #xp_lock1
 from  master.dbo.syslockinfo,
  master.dbo.spt_values v,
  master.dbo.spt_values x,
  master.dbo.spt_values u,
  master.dbo.sysdatabases d,
  master.dbo.sysprocesses p

 where   master.dbo.syslockinfo.rsc_type = v.number
  and v.type = 'LR'
  and master.dbo.syslockinfo.req_status = x.number
  and x.type = 'LS'
  and master.dbo.syslockinfo.req_mode + 1 = u.number
  and u.type = 'L'
  and d.dbid=rsc_dbid
  and req_spid=p.spid
 order by spid

 declare cur_get_dbname1 cursor forward_only read_only for
 select distinct dbname,dbid
 from #xp_lock1

 open cur_get_dbname1
 fetch next from cur_get_dbname1 into @dbname,@dbid
 
 while (@@fetch_status = 0)
 begin
  select @sql=N'update #xp_lock1 set ObjName=b.name from #xp_lock1 a,'+@dbname+N'.dbo.sysobjects b where a.ObjId=b.id and a.dbid='+Convert(nvarchar(256),@dbid)
  exec(@sql)
 
  select @sql=N'update #xp_lock1 set IndName=b.name from #xp_lock1 a,'+@dbname+N'.dbo.sysobjects b where a.IndId=b.id and a.dbid='+Convert(nvarchar(256),@dbid)
  exec(@sql)
 
  fetch next from cur_get_dbname1 into @dbname,@dbid
 end
 close cur_get_dbname1
 deallocate cur_get_dbname1

 select * from #xp_lock1
end

return (0) -- sp_lock
GO


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#0 Homer::RtpSessionState::deprovisionAtDestruction (this=0x7f1fe00e7650) at ../components/mos/state/session_state/src/rtp_session_state.cpp:886 886 ../components/mos/state/session_state/src/rtp_session_state.cpp: No such file or directory. [Current thread is 1 (Thread 0x7f1ffffff700 (LWP 372))] (gdb) bt #0 Homer::RtpSessionState::deprovisionAtDestruction (this=0x7f1fe00e7650) at ../components/mos/state/session_state/src/rtp_session_state.cpp:886 #1 0x00005653759a8e33 in Homer::DeviceState::~DeviceState (this=0x7f1fe00ecf50) at ../components/mos/state/device_state/src/device_state.cpp:87 #2 0x0000565375c4229e in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7f1fe00ecf40) at /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:155 #3 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x7f1fe00bbb08) at /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:730 #4 std::__shared_ptr<Homer::DeviceStateBase, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x7f1fe00bbb00) at /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:1169 #5 Homer::Device::~Device (this=0x7f1fe00bb070) at ../components/mos/device/src/device.cpp:94 #6 0x0000565375c3c08a in Homer::WebsocketDevice::~WebsocketDevice (this=0x7f1fe00bb070) at ../components/mos/device/src/websocket_device.h:31 #7 Homer::WebsocketClientDevice::~WebsocketClientDevice (this=0x7f1fe00bb070) at ../components/mos/device/src/websocket_client_device.cpp:20
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值