DatabaseProcApplicationCreatedLinks
sybsystemprocssp_odbc_databases  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
3     
4     create procedure sp_odbc_databases
5     as
6     
7         declare @startedInTransaction bit
8         if (@@trancount > 0)
9             select @startedInTransaction = 1
10        else
11            select @startedInTransaction = 0
12    
13    
14    
15        if @@trancount = 0
16        begin
17            set chained off
18        end
19    
20        set transaction isolation level 1
21    
22        if (@startedInTransaction = 1)
23            save transaction odbc_keep_temptable_tx
24    
25    
26        /* Use temporary table to sum up database size w/o using group by */
27        create table #databases(
28            database_name varchar(32),
29            size int)
30    
31        /* Insert row for each database */
32        insert into #databases
33        select
34            name,
35                (select sum(size) from master.dbo.sysusages
36                where dbid = d.dbid)
37        from master.dbo.sysdatabases d
38    
39        select
40            database_name,
41            /* Convert from number of pages to K */
42            database_size = size * (@@maxpagesize / 1024),
43            remarks = convert(varchar(254), null) /* Remarks are NULL */
44        from #databases
45    
46        drop table #databases
47        if (@startedInTransaction = 1)
48            rollback transaction odbc_keep_temptable_tx
49    
50        return (0)
51    


exec sp_procxmode 'sp_odbc_databases', 'AnyMode'
go

Grant Execute on sp_odbc_databases to public
go
RESULT SETS
sp_odbc_databases_rset_001

DEFECTS
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public master..sysusages  
 MGTP 3 Grant to public sybsystemprocs..sp_odbc_databases  
 MNER 3 No Error Check should check @@error after insert 32
 MUCO 3 Useless Code Useless Brackets 8
 MUCO 3 Useless Code Useless Brackets 22
 MUCO 3 Useless Code Useless Brackets 47
 MUCO 3 Useless Code Useless Brackets 50
 MUIN 3 Column created using implicit nullability 27
 QISO 3 Set isolation level 20
 MRST 2 Result Set Marker 39
 MSUC 2 Correlated Subquery Marker 35
 MTR1 2 Metrics: Comments Ratio Comments: 15% 4
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 5 = 4dec - 1exi + 2 4
 MTR3 2 Metrics: Query Complexity Complexity: 27 4
 PRED_QUERY_COLLECTION 2 {d=master..sysdatabases, u=master..sysusages} 0 35

DEPENDENCIES
PROCS AND TABLES USED
read_writes table tempdb..#databases (1) 
reads table master..sysusages (1)  
reads table master..sysdatabases (1)