DatabaseProcApplicationCreatedLinks
sybsystemprocssp_diskdefault  14 déc. 14Defects Propagation Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/diskdefault */
4     
5     /*
6     ** Messages for "sp_diskdefault"        17470
7     **
8     ** 17260, "Can't run %1! from within a transaction." 
9     ** 17470, "No such device exists -- run sp_helpdevice to list the DataServer devices."
10    ** 17471, "The device name supplied is not a database disk."
11    ** 17472, "Usage: sp_diskdefault logicalname {defaulton | defaultoff}." 
12    ** 17473, "The device '%1!' is a private device. This operation is not valid for private devices." 
13    */
14    
15    create or replace procedure sp_diskdefault
16        @logicalname varchar(30), /* logical name of the device */
17        @defstatus varchar(15) /* turn on or off */
18    as
19        declare @nullarg char(1)
20        declare @dummy int
21        declare @status int
22        declare @gp_enabled int
23    
24    
25    
26        /*
27        **  If we're in a transaction, disallow this since it might make recovery
28        **  impossible.
29        */
30        if @@trancount > 0
31        begin
32            /*
33            ** 17260, "Can't run %1! from within a transaction." 
34            */
35            raiserror 17260, "sp_diskdefault"
36            return (1)
37        end
38        else
39        begin
40            set chained off
41        end
42    
43        set transaction isolation level 1
44    
45        /* 
46        ** If granular permissions is not enabled then sa_role is required.
47        ** If granular permissions is enabled then the permission 'manage disk' is
48        ** required.  proc_role and proc_auditperm will also do auditing
49        ** if required. Both will also print error message if required.
50        */
51    
52        select @nullarg = NULL
53        execute @status = sp_aux_checkroleperm "sa_role", "manage disk",
54            @nullarg, @gp_enabled output
55    
56        /* For Auditing */
57        if (@gp_enabled = 0)
58        begin
59            if (proc_role("sa_role") = 0)
60                return (1)
61        end
62        else
63        begin
64            select @dummy = proc_auditperm("manage disk", @status)
65        end
66    
67        if (@status != 0)
68            return (1)
69    
70        /*
71        **  Make sure that a device with @logicalname exists.
72        */
73        if not exists (select *
74                from master.dbo.sysdevices
75                where name = @logicalname)
76        begin
77            /*
78            ** 17470, "No such device exists -- run sp_helpdevice to list the DataServer devices."
79            */
80            raiserror 17470
81            return (1)
82        end
83    
84        /*
85        **  Make sure that is a database disk and not a dump device.
86        */
87        if exists (select *
88                from master.dbo.sysdevices
89                where name = @logicalname
90                    and status & 16 = 16)
91        begin
92            /*
93            ** 17471, "The device name supplied is not a database disk."
94            */
95            raiserror 17471
96            return (1)
97        end
98    
99        /* Do not allow this operation for a private device. */
100       if exists (select *
101               from master.dbo.sysdevices
102               where name = @logicalname
103                   and (status2 & 2) = 2)
104       begin
105           raiserror 17473, @logicalname
106           return (1)
107       end
108   
109       /* Do not allow this operation for a virtual cache device. */
110       if exists (select *
111               from master.dbo.sysdevices
112               where name = @logicalname
113                   and (status2 & 8) = 8)
114       begin
115           raiserror 17474, @logicalname
116           return (1)
117       end
118   
119       if @defstatus = "defaulton"
120       begin
121           update master.dbo.sysdevices
122           set status = status | 1
123           where name = @logicalname
124           return (0)
125       end
126   
127       if @defstatus = "defaultoff"
128       begin
129           update master.dbo.sysdevices
130           set status = status & ~ 1
131           where name = @logicalname
132           return (0)
133       end
134   
135       /*
136       **  @defstatus must be "defaulton" or "defaultoff"
137       */
138       /*
139       ** 17472, "Usage: sp_diskdefault logicalname {defaulton | defaultoff}." 
140       */
141       raiserror 17472
142       return (1)
143   


exec sp_procxmode 'sp_diskdefault', 'AnyMode'
go

Grant Execute on sp_diskdefault to public
go
DEFECTS
 MGTP 3 Grant to public master..sysdevices  
 MGTP 3 Grant to public sybsystemprocs..sp_diskdefault  
 MNER 3 No Error Check should check @@error after update 121
 MNER 3 No Error Check should check @@error after update 129
 MUCO 3 Useless Code Useless Brackets 36
 MUCO 3 Useless Code Useless Brackets 57
 MUCO 3 Useless Code Useless Brackets 59
 MUCO 3 Useless Code Useless Brackets 60
 MUCO 3 Useless Code Useless Brackets 67
 MUCO 3 Useless Code Useless Brackets 68
 MUCO 3 Useless Code Useless Brackets 81
 MUCO 3 Useless Code Useless Brackets 96
 MUCO 3 Useless Code Useless Brackets 106
 MUCO 3 Useless Code Useless Brackets 116
 MUCO 3 Useless Code Useless Brackets 124
 MUCO 3 Useless Code Useless Brackets 132
 MUCO 3 Useless Code Useless Brackets 142
 MUOT 3 Updates outside transaction 129
 QISO 3 Set isolation level 43
 VNRD 3 Variable is not read @dummy 64
 MSUB 2 Subquery Marker 73
 MSUB 2 Subquery Marker 87
 MSUB 2 Subquery Marker 100
 MSUB 2 Subquery Marker 110
 MTR1 2 Metrics: Comments Ratio Comments: 46% 15
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 14dec - 9exi + 2 15
 MTR3 2 Metrics: Query Complexity Complexity: 63 15

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)  
read_writes table master..sysdevices (1)