DatabaseProcApplicationCreatedLinks
sybsystemprocssp_diskdefault  31 Aug 14Defects 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 procedure sp_diskdefault
16        @logicalname varchar(30), /* logical name of the device */
17        @defstatus varchar(15) /* turn on or off */
18    as
19    
20    
21        /*
22        **  If we're in a transaction, disallow this since it might make recovery
23        **  impossible.
24        */
25        if @@trancount > 0
26        begin
27            /*
28            ** 17260, "Can't run %1! from within a transaction." 
29            */
30            raiserror 17260, "sp_diskdefault"
31            return (1)
32        end
33        else
34        begin
35            set chained off
36        end
37    
38        set transaction isolation level 1
39    
40        /* check if user has sa role, proc_role will also do auditing
41        ** if required. proc_role will also print error message if required.
42        */
43    
44        if (proc_role("sa_role") = 0)
45            return (1)
46    
47        /*
48        **  Make sure that a device with @logicalname exists.
49        */
50        if not exists (select *
51                from master.dbo.sysdevices
52                where name = @logicalname)
53        begin
54            /*
55            ** 17470, "No such device exists -- run sp_helpdevice to list the DataServer devices."
56            */
57            raiserror 17470
58            return (1)
59        end
60    
61        /*
62        **  Make sure that is a database disk and not a dump device.
63        */
64        if exists (select *
65                from master.dbo.sysdevices
66                where name = @logicalname
67                    and status & 16 = 16)
68        begin
69            /*
70            ** 17471, "The device name supplied is not a database disk."
71            */
72            raiserror 17471
73            return (1)
74        end
75    
76        /* Do not allow this operation for a private device. */
77        if exists (select *
78                from master.dbo.sysdevices
79                where name = @logicalname
80                    and (status2 & 2) = 2)
81        begin
82            raiserror 17473, @logicalname
83            return (1)
84        end
85    
86        /* Do not allow this operation for a virtual cache device. */
87        if exists (select *
88                from master.dbo.sysdevices
89                where name = @logicalname
90                    and (status2 & 8) = 8)
91        begin
92            raiserror 17474, @logicalname
93            return (1)
94        end
95    
96        if @defstatus = "defaulton"
97        begin
98            update master.dbo.sysdevices
99            set status = status | 1
100           where name = @logicalname
101           return (0)
102       end
103   
104       if @defstatus = "defaultoff"
105       begin
106           update master.dbo.sysdevices
107           set status = status & ~ 1
108           where name = @logicalname
109           return (0)
110       end
111   
112       /*
113       **  @defstatus must be "defaulton" or "defaultoff"
114       */
115       /*
116       ** 17472, "Usage: sp_diskdefault logicalname {defaulton | defaultoff}." 
117       */
118       raiserror 17472
119       return (1)
120   


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 98
 MNER 3 No Error Check should check @@error after update 106
 MUCO 3 Useless Code Useless Brackets 31
 MUCO 3 Useless Code Useless Brackets 44
 MUCO 3 Useless Code Useless Brackets 45
 MUCO 3 Useless Code Useless Brackets 58
 MUCO 3 Useless Code Useless Brackets 73
 MUCO 3 Useless Code Useless Brackets 83
 MUCO 3 Useless Code Useless Brackets 93
 MUCO 3 Useless Code Useless Brackets 101
 MUCO 3 Useless Code Useless Brackets 109
 MUCO 3 Useless Code Useless Brackets 119
 MUOT 3 Updates outside transaction 106
 QISO 3 Set isolation level 38
 MSUB 2 Subquery Marker 50
 MSUB 2 Subquery Marker 64
 MSUB 2 Subquery Marker 77
 MSUB 2 Subquery Marker 87
 MTR1 2 Metrics: Comments Ratio Comments: 48% 15
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 5 = 11dec - 8exi + 2 15
 MTR3 2 Metrics: Query Complexity Complexity: 51 15

DEPENDENCIES
PROCS AND TABLES USED
read_writes table master..sysdevices (1)