DatabaseProcApplicationCreatedLinks
sybsystemprocssp_addumpdevice  14 déc. 14Defects Propagation Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/addumpdevice */
4     
5     /*
6     ** Messages for "sp_addumpdevice"       17310
7     **
8     ** 17260, "Can't run %1! from within a transaction." 
9     ** 17240, "'" + @logicalname + "' is not a valid name." 
10    ** 17310, "Unknown device type.  Use 'disk' or 'tape'."
11    ** 17311, "@logicalname may not be NULL."
12    ** 17312, "@physicalname may not be NULL."
13    ** 17314, "Device with same logical name already exists."
14    ** 17317, "Please specify media capacity in megabytes (1 MB minimum)."
15    ** 17318, "WARNING: specified size parameter is not used for the disk device type."
16    ** 17319, "'Disk' device added."
17    ** 17320, "'Tape' device added."
18    ** 17321, "WARNING: physical device name '%1!' is not unique." 
19    ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
20    ** 18388, "You must be in the master database to run %1!"
21    */
22    create or replace procedure sp_addumpdevice
23        @devtype varchar(30), /* disk, tape, or special */
24        @logicalname varchar(255), /* logical name of the device */
25        @physicalname varchar(128), /* physical name of the device */
26        @tapesize int = NULL /* capacity of tape in MB */
27    
28    as
29    
30        declare @status smallint /* status bits for device */
31        declare @msg varchar(1024)
32        declare @tapeblocksize int
33        declare @cntrltype smallint
34        declare @maxlen int
35        declare @maxphylen int
36        declare @retstat int
37        declare @dummy int
38    
39        declare @nullarg char(1)
40        declare @gp_enabled int
41    
42    
43    
44        /* check the lenghts of the input parameters */
45        select @maxlen = length from master.dbo.syscolumns
46        where id = object_id("master.dbo.sysdevices") and name = "name"
47    
48        if char_length(@logicalname) > @maxlen
49        begin
50            /*
51            ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters." 
52            */
53            raiserror 17325, @logicalname, @maxlen
54            return (1)
55        end
56        select @maxphylen = length from master.dbo.syscolumns
57        where id = object_id("master.dbo.sysdevices") and name = "phyname"
58    
59        if char_length(@physicalname) > @maxphylen
60        begin
61            /*
62            ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
63            */
64            raiserror 17325, @physicalname, @maxphylen
65            return (1)
66        end
67    
68        /*
69        **  If we're in a transaction, disallow this since it might make recovery
70        **  impossible.
71        */
72        if @@trancount > 0
73        begin
74            /*
75            ** 17260, "Can't run %1! from within a transaction." 
76            */
77            raiserror 17260, "sp_addumpdevice"
78            return (1)
79        end
80        else
81        begin
82            set chained off
83        end
84    
85        set transaction isolation level 1
86    
87        /* 
88        ** If granular permissions is not enabled check if user has sa role, 
89        ** proc_role will also do auditing if required. proc_role will also print 
90        ** error message if required.  If granular permissions is enabled check that
91        ** user has 'manage disk' permission.  proc_auditperm will produce an audit
92        ** record if required and it will also produce an error message if one occurred.
93        */
94        select @nullarg = NULL
95        execute @retstat = sp_aux_checkroleperm "sa_role", "manage disk",
96            @nullarg, @gp_enabled output
97    
98        if (@gp_enabled = 0)
99        begin
100           if (proc_role("sa_role") = 0)
101           begin
102               return (1)
103           end
104       end
105       else
106       begin
107           select @dummy = proc_auditperm("manage disk",
108                   @retstat)
109   
110           if (@retstat != 0)
111           begin
112               return (1)
113           end
114       end
115   
116       /*
117       ** Check to see that the @logicalname is valid.
118       */
119       if valid_name(@logicalname, @maxlen) = 0
120       begin
121           /*
122           ** 17240, "'%1!' is not a valid name."
123           */
124           raiserror 17240, @logicalname
125           return (1)
126       end
127   
128       /*
129       **  The rules for updating sysdevices are as follows:
130       **	devtype - may be 'disk', 'tape' or 'archive database'.
131       **		If 'disk' then cntrltype will be 2,
132       **		If 'tape' then 3.  
133       **		cntrltype is not used for 'archive database'.
134       **	logicalname - may be any identifier but must be unique
135       **	physicalname - may be anything and doesn't have to be unique
136       **		If it contains illegal id characters, e.g., '/', then
137       **		it must be in quotes.
138       **	tapesize - for a tape device, this is the tape capacity in MB.  It
139       **		is ignored on VMS.
140       */
141   
142   
143       /*
144       **  Check out the @devtype.
145       */
146       select @devtype = lower(@devtype)
147   
148       if (@devtype = "tape")
149       begin
150           select @cntrltype = 3
151       end
152       else if (@devtype = "disk")
153       begin
154           select @cntrltype = 2
155       end
156       else if (@devtype != "archive database")
157       begin
158           /*
159           ** 17310, "Unknown device type.  Use 'disk' or 'tape'."
160           */
161           raiserror 17310
162           return (1)
163       end
164   
165       /*
166       **  Check the args are not NULL.
167       */
168       if @logicalname is NULL
169       begin
170           /*
171           ** 17311, "@logicalname may not be NULL."
172           */
173           raiserror 17311, @logicalname
174           return (1)
175       end
176   
177   
178       if @physicalname is NULL
179       begin
180           /*
181           ** 17312, "@physicalname may not be NULL."
182           */
183           raiserror 17312, @physicalname
184           return (1)
185       end
186   
187       /*
188       **  Make sure that a device with @logicalname doesn't already exist.
189       */
190       if exists (select *
191               from master.dbo.sysdevices
192               where name = @logicalname)
193       begin
194           /*
195           ** 17314, "Device with same logical name already exists."
196           */
197           raiserror 17314
198           return (1)
199       end
200   
201       /*
202       **  Always turn on the dump status bit.
203       */
204       select @status = 16
205   
206       /*
207       **  If @devtype is a tape then check to see if devstatus is 'skip'.
208       */
209       if @devtype = "tape"
210       begin
211           /*
212           **  If this is not VMS, then @tapesize is required.
213           */
214           if not exists (select *
215                   from master.dbo.spt_values
216                   where type = "E"
217                       and name = "vms")
218           begin
219               if @tapesize is NULL or @tapesize < 1
220               begin
221                   /*
222                   ** 17317, "Please specify media capacity in megabytes (1 MB minimum)."
223                   */
224                   raiserror 17317
225                   return (1)
226               end
227   
228               select @tapeblocksize = 32768
229   
230               select @tapesize =
231                   convert(int, ((@tapesize * 1048576.)
232                   + @tapeblocksize - 1) / @tapeblocksize)
233           end
234           else
235           begin
236               select @tapesize = 0
237           end
238       end
239       else
240       begin
241           if @tapesize is not NULL
242           begin
243               /*
244               ** 17318, "WARNING: specified size parameter is not used for the disk device type."
245               */
246               raiserror 17318
247           end
248           select @tapesize = 0
249       end
250   
251       if @devtype = "archive database"
252       begin
253   
254           /*
255           ** If we're not in the master database, the do not allow the adding 
256           ** of archive database devices.
257           */
258           if db_name() != "master"
259           begin
260               /*
261               ** 18388, "You must be in the master database in order to run %1!
262               */
263               raiserror 18388, "sp_addumpdevice 'archive database'"
264               return (1)
265           end
266           disk reinit name = @logicalname, physname = @physicalname, adb
267   
268           if (@@error != 0)
269               return (1)
270       end
271       else
272       begin
273           /* Tell the server about the device by inserting into sysdevices */
274           insert into master.dbo.sysdevices(vdevno, low, high, status, status2, cntrltype, name, phyname)
275           values (0, 0, @tapesize, @status, 0, @cntrltype, @logicalname, @physicalname)
276       end
277   
278       if @devtype = "disk" or @devtype = "archive database"
279           /*
280           ** 17319, "'Disk' device added."
281           */
282           exec sp_getmessage 17319, @msg output
283       else
284           /*
285           ** 17320, "'Tape' device added."
286           */
287           exec sp_getmessage 17320, @msg output
288   
289       print @msg
290   
291       /*
292       **  Warn about duplicate physical names.
293       */
294       if (select count(*)
295               from master.dbo.sysdevices
296               where phyname = @physicalname) > 1
297       begin
298           /*
299           ** 17321, "WARNING: physical device name '%1!' is not unique."   
300           */
301           exec sp_getmessage 17321, @msg output
302           print @msg, @physicalname
303       end
304   
305       return (0)
306   


exec sp_procxmode 'sp_addumpdevice', 'AnyMode'
go

Grant Execute on sp_addumpdevice to public
go
DEFECTS
 MTYP 4 Assignment type mismatch name: sysname = varchar(255) 275
 MTYP 4 Assignment type mismatch phyname: varchar(127) = varchar(128) 275
 QPUI 4 Join or Sarg with Un-Rooted Partial Index Use SARG Candidate index: spt_values.spt_valuesclust clustered
(number, type)
Intersection: {type}
216
 TNOU 4 Table with no unique index master..spt_values master..spt_values
 MAW1 3 Warning message on %name% master..syscolumns.id: Warning message on syscolumns 46
 MAW1 3 Warning message on %name% master..syscolumns.id: Warning message on syscolumns 57
 MGTP 3 Grant to public master..spt_values  
 MGTP 3 Grant to public master..syscolumns  
 MGTP 3 Grant to public master..sysdevices  
 MGTP 3 Grant to public sybsystemprocs..sp_addumpdevice  
 MNER 3 No Error Check should check @@error after insert 274
 MNER 3 No Error Check should check return value of exec 282
 MNER 3 No Error Check should check return value of exec 287
 MNER 3 No Error Check should check return value of exec 301
 MUCO 3 Useless Code Useless Brackets 54
 MUCO 3 Useless Code Useless Brackets 65
 MUCO 3 Useless Code Useless Brackets 78
 MUCO 3 Useless Code Useless Brackets 98
 MUCO 3 Useless Code Useless Brackets 100
 MUCO 3 Useless Code Useless Brackets 102
 MUCO 3 Useless Code Useless Brackets 110
 MUCO 3 Useless Code Useless Brackets 112
 MUCO 3 Useless Code Useless Brackets 125
 MUCO 3 Useless Code Useless Brackets 148
 MUCO 3 Useless Code Useless Brackets 152
 MUCO 3 Useless Code Useless Brackets 156
 MUCO 3 Useless Code Useless Brackets 162
 MUCO 3 Useless Code Useless Brackets 174
 MUCO 3 Useless Code Useless Brackets 184
 MUCO 3 Useless Code Useless Brackets 198
 MUCO 3 Useless Code Useless Brackets 225
 MUCO 3 Useless Code Useless Brackets 231
 MUCO 3 Useless Code Useless Brackets 264
 MUCO 3 Useless Code Useless Brackets 268
 MUCO 3 Useless Code Useless Brackets 269
 MUCO 3 Useless Code Useless Brackets 305
 QAFM 3 Var Assignment from potentially many rows 45
 QAFM 3 Var Assignment from potentially many rows 56
 QISO 3 Set isolation level 85
 QIWC 3 Insert with not all columns specified missing 3 columns out of 11 274
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
46
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
57
 VNRD 3 Variable is not read @dummy 107
 MSUB 2 Subquery Marker 190
 MSUB 2 Subquery Marker 214
 MSUB 2 Subquery Marker 294
 MTR1 2 Metrics: Comments Ratio Comments: 50% 22
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 16 = 28dec - 14exi + 2 22
 MTR3 2 Metrics: Query Complexity Complexity: 118 22

DATA PROPAGATION detailed
ColumnWritten To
@logicalnamesysdevices.name   sp_dropdevice_rset_002.device sp_dropdevice_rset_003.sqlbNoName3 sp_checknames_rset_012.segment sp_checkreswords_rset_004.Object Type sp_dropdevice_rset_002.device sp_dropdevice_rset_003.sqlbNoName67
@physicalnamesysdevices.phyname  
@tapesizesysdevices.high  

DEPENDENCIES
PROCS AND TABLES USED
reads table master..spt_values (1)  
reads table master..syscolumns (1)  
read_writes table master..sysdevices (1)  
calls proc sybsystemprocs..sp_getmessage  
   reads table master..syslanguages (1)  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
   reads table sybsystemprocs..sysusermessages  
   reads table master..sysmessages (1)  
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..sysconfigures (1)  
   reads table master..syscurconfigs (1)