DatabaseProcApplicationCreatedLinks
sybsystemprocssp_who  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/serveroption */
4     
5     /*
6     ** Messages for "sp_who"		17nnn
7     ** 
8     ** 17231, "No login with the specified name exists." 
9     */
10    
11    create procedure sp_who @loginame varchar(255) = NULL as
12    
13        declare @low int
14        declare @high int
15        declare @spidlow int
16        declare @spidhigh int
17        declare @len1 int, @len2 int, @len3 int
18        declare @kernel_mode varchar(15)
19    
20        select @kernel_mode = @@kernelmode
21    
22        if @@trancount = 0
23        begin
24            set chained off
25        end
26    
27        set transaction isolation level 1
28    
29        select @low = @@minsuid, @high = @@maxsuid,
30            @spidlow = @@minspid, @spidhigh = @@maxspid
31    
32        if @loginame is not NULL
33        begin
34            select @low = suser_id(@loginame), @high = suser_id(@loginame)
35            if @low is NULL
36            begin
37                if @loginame like "[0-9]%"
38                begin
39                    select @spidlow = convert(int, @loginame),
40                        @spidhigh = convert(int, @loginame),
41                        @low = @@minsuid, @high = @@maxsuid
42                end
43                else
44                begin
45                    /*
46                    ** 17231, "No login with the specified name exists." 
47                    */
48                    raiserror 17231
49                    return (1)
50                end
51            end
52        end
53    
54        select fid, spid, status, loginame = suser_name(suid),
55            origname = isnull(suser_name(origsuid), suser_name(suid)), hostname,
56            blk_spid = blocked, dbname = db_name(dbid),
57            tempdbname = db_name(tempdb_id(spid)), cmd, block_xloid, affinity
58        into #who1result
59        from master..sysprocesses
60        where suid >= @low and suid <= @high
61            and spid >= @spidlow and spid <= @spidhigh
62    
63        if (@kernel_mode = 'process')
64        begin
65            exec sp_autoformat @fulltabname = #who1result,
66                @selectlist = "fid, spid, status, loginame, origname, hostname, blk_spid, dbname, tempdbname, cmd, block_xloid",
67                @orderby = "order by fid, spid, dbname"
68        end
69        else
70        begin
71            exec sp_autoformat @fulltabname = #who1result,
72                @selectlist = "fid, spid, status, loginame, origname, hostname, blk_spid, dbname, tempdbname, cmd, block_xloid, threadpool = affinity",
73                @orderby = "order by fid, spid, dbname"
74        end
75    
76    
77        drop table #who1result
78    
79    
80        return (0)
81    
82    


exec sp_procxmode 'sp_who', 'AnyMode'
go

Grant Execute on sp_who to public
go
DEFECTS
 MTYP 4 Assignment type mismatch @kernel_mode: varchar(15) = int 20
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 65
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 71
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 61
 TNOI 4 Table with no index master..sysprocesses master..sysprocesses
 MGTP 3 Grant to public master..sysprocesses  
 MGTP 3 Grant to public sybsystemprocs..sp_who  
 MNER 3 No Error Check should check @@error after select into 54
 MNER 3 No Error Check should check return value of exec 65
 MNER 3 No Error Check should check return value of exec 71
 MUCO 3 Useless Code Useless Brackets 49
 MUCO 3 Useless Code Useless Brackets 63
 MUCO 3 Useless Code Useless Brackets 80
 QISO 3 Set isolation level 27
 VUNU 3 Variable is not used @len1 17
 VUNU 3 Variable is not used @len2 17
 VUNU 3 Variable is not used @len3 17
 MTR1 2 Metrics: Comments Ratio Comments: 11% 11
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 8 = 8dec - 2exi + 2 11
 MTR3 2 Metrics: Query Complexity Complexity: 36 11

DEPENDENCIES
PROCS AND TABLES USED
writes table tempdb..#who1result (1) 
calls proc sybsystemprocs..sp_autoformat  
   calls proc sybsystemprocs..sp_namecrack  
   reads table tempdb..systypes (1)  
   reads table tempdb..syscolumns (1)  
   reads table master..systypes (1)  
   reads table master..syscolumns (1)  
   read_writes table tempdb..#colinfo_af (1) 
   calls proc sybsystemprocs..sp_autoformat  
reads table master..sysprocesses (1)