DatabaseProcApplicationCreatedLinks
sybsystemprocssp_unbindexeclass  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/%M% %I% %G%"	*/
3     
4     /*
5     ** Messages for "sp_unbindexeclass"
6     ** 17260, "Can't run %1! from within a transaction."
7     ** 18255, "%1! cannot be NULL."
8     ** 18256, "%1! is not a valid object type for this stored procedure."
9     ** 18259, "No login with the specified name '%1!' exists."
10    ** 18278, "Failed to unbind '%1!' from execution class. Check server errorlog
11    **	   for any additional information."
12    ** 18279, "The specified binding to be dropped does not exist"
13    ** 18552, "%1! is not a valid user of this database.
14    ** 18291, "The parameter value '%1!' is invalid."
15    */
16    
17    create procedure sp_unbindexeclass
18        @object_name varchar(255), /* name of object */
19        @object_type varchar(2), /* Type of object */
20        @scope varchar(255) = null /* user scope of the class */
21    as
22    
23        declare @attrib_id int,
24            @user_id int,
25            @action int,
26            @classname varchar(255),
27            @sp_objid int,
28            @owner_id int,
29            @stored_objid int,
30            @upcase_str varchar(2),
31            @instanceid int
32    
33        select @action = 3 /* drop action */
34        select @user_id = NULL /* Id of user from Syslogins table */
35        select @attrib_id = 0 /* Execution class attribute */
36        select @sp_objid = 0 /* object id of a stored proc */
37        select @instanceid = NULL /* instance id */
38    
39        /*
40        **  If we're in a transaction, disallow this since it might make recovery
41        **  impossible.
42        */
43        IF @@trancount > 0
44        BEGIN
45            /*
46            ** 17260, "Can't run %1! from within a transaction."
47            */
48            raiserror 17260, "sp_dropexeclass"
49            return (1)
50        END
51        ELSE
52        BEGIN
53            /* Use TSQL mode of unchained transactions */
54            set chained off
55        END
56    
57        /* Dont do "Dirty Reads" */
58        set transaction isolation level 1
59    
60        /* convert types to upper case */
61        select @upcase_str = upper(@object_type)
62        IF ((@upcase_str = "LG") OR (@upcase_str = "AP") OR
63                (@upcase_str = "PR") OR (@upcase_str = "DF") OR
64                (@upcase_str = "SV"))
65        BEGIN
66            select @object_type = @upcase_str
67        END
68    
69        /*
70        ** Check to see that the input params are correct
71        */
72        IF ((@object_name is NULL) and (@object_type != 'DF'))
73        BEGIN
74            /*
75            ** 18255, "%1! cannot be NULL."
76            */
77            raiserror 18255, "Object name"
78            return (1)
79        END
80    
81        IF ((@object_type = "PR") AND (@scope is NULL))
82        BEGIN
83            /*
84            ** 18255, "%1! cannot be NULL."
85            */
86            raiserror 18255, "Scope"
87            return (1)
88        END
89    
90        /* For object_type SV, scope should be NULL */
91        IF ((@object_type = 'SV') AND (@scope is not NULL))
92        BEGIN
93            /*
94            ** 18291, "The parameter value '%1!' is invalid."
95            */
96            raiserror 18291, "scope"
97            return (1)
98        END
99    
100       /* object_type SV is only usable in threaded mode */
101       IF ((@object_type = 'SV') AND (@@kernelmode != 'threaded'))
102       BEGIN
103           /*
104           ** 18119, "'%1!' is not available in process mode."
105           */
106           raiserror 18119, "Service task binding"
107           return (1)
108       END
109   
110       /* For object_type DF the object name and scope should be NULL */
111       IF ((@object_type = 'DF') AND ((@object_name is not NULL) OR
112                   (@scope is not NULL)))
113       BEGIN
114           /*
115           ** 18291, "The parameter value '%1!' is invalid."
116           */
117           raiserror 18291, "Object name or scope"
118           return (1)
119       END
120   
121   
122       IF ((@object_type != "LG") AND (@object_type != "AP")
123               AND (@object_type != "PR") AND (@object_type != "DF")
124               AND (@object_type != "SV"))
125       BEGIN
126           /*
127           ** 18256, "%1! is not a valid object type for this stored procedure."
128           */
129           raiserror 18256, @object_type
130           return (1)
131       END
132   
133       /* In case of a stored proc, if the object still exits, get obj id */
134       IF (@object_type = "PR")
135       BEGIN
136   
137           /* get owner id from scope param */
138           IF not exists (select uid from sysusers
139                   where (name = @scope))
140           BEGIN
141               /*
142               ** 18552 "%1! is not a valid user of this database."
143               */
144               raiserror 18552, @scope
145               return (1)
146           END
147           ELSE
148               select @owner_id = (select uid from sysusers
149                       where (name = @scope))
150   
151           IF exists (select id from sysobjects
152                   where ((name = @object_name) AND (uid = @owner_id)))
153               select @sp_objid = (select id from sysobjects
154                       where ((name = @object_name) AND (uid = @owner_id)))
155       END
156   
157   
158       /* Now convert user name to user id */
159       IF (@object_type = "LG")
160       BEGIN
161           IF not exists (select suid from master..syslogins
162                   where (name = @object_name)
163                       and ((status & 512) != 512)) /* not LOGIN PROFILE */
164           BEGIN
165               /*
166               ** 18259, "No login with specified name '%1!' exists." 
167               */
168               raiserror 18259, @object_name
169               return (1)
170           END
171   
172           select @user_id =
173                   (select suid from master..syslogins
174                   where (name = @object_name))
175       END
176       ELSE IF ((@object_type = "AP") and (@scope is not NULL))
177       BEGIN
178           IF not exists (select suid from master..syslogins where (name = @scope)
179                       and ((status & 512) != 512)) /* not LOGIN PROFILE */
180           BEGIN
181               /*
182               ** 18259, "No login with specified name '%1!' exists" 
183               */
184               raiserror 18259, @scope
185               return (1)
186           END
187   
188           select @user_id = (select suid from master..syslogins
189                   where (name = @scope))
190       END
191   
192       /* 
193       ** Now delete the matching entry from Sysattributes Table...
194       ** Verify that the attributes passed to sysattributes is correct. Note
195       ** that for stored procedures, the sysattributes table in the current
196       ** database is searched. For other objects, the sysattributes table in
197       ** master is searched.
198       */
199       IF (@object_type = "LG")
200       BEGIN
201   
202           select @classname = char_value
203   
204           from
205               master..sysattributes where
206               class = 6 AND
207               attribute = @attrib_id AND
208               object_type = @object_type AND
209               object = @user_id AND
210               object_cinfo = @scope
211   
212           IF (@classname is not NULL)
213           BEGIN
214   
215               delete master..sysattributes
216               where class = 6 AND
217                   attribute = @attrib_id AND
218                   object_type = @object_type AND
219                   object = @user_id AND
220                   object_cinfo = @scope
221           END
222           ELSE
223           BEGIN
224               /*
225               ** 18279, "The specified binding to be dropped does 
226               **	   not exist"
227               */
228               raiserror 18279
229               return (1)
230           END
231   
232           IF attrib_notify(6, @attrib_id, @object_type, @user_id,
233                   NULL, NULL, NULL, @scope, NULL, NULL,
234                   NULL, NULL, "", @action) = 0
235           BEGIN
236               insert master..sysattributes
237               (class, attribute, object_type, object,
238                   object_info3, object_cinfo, char_value)
239               values (6, @attrib_id, @object_type, @user_id,
240                   @instanceid,
241                   @scope, @classname)
242   
243               /*
244               ** 18278,"Failed to unbind '%1!' from execution class.
245               **	  Check server errorlog for any additional
246               **	  information."
247               */
248               raiserror 18278, @object_name
249               return (1)
250           END
251       END
252       ELSE IF (@object_type = "AP")
253       BEGIN
254           select @classname = char_value,
255               @instanceid = object_info3 from
256               master..sysattributes where
257               class = 6 AND
258               attribute = @attrib_id AND
259               object_type = @object_type AND
260               object_info1 = @user_id AND
261               object_cinfo = @object_name
262   
263           IF (@classname is not NULL)
264           BEGIN
265   
266               delete master..sysattributes
267               where class = 6 AND
268                   attribute = @attrib_id AND
269                   object_type = @object_type AND
270                   object_info1 = @user_id AND
271                   object_cinfo = @object_name
272           END
273           ELSE
274           BEGIN
275               /*
276               ** 18279, "The specified binding to be dropped does 
277               **	   not exist"
278               */
279               raiserror 18279
280               return (1)
281           END
282   
283           IF attrib_notify(6, @attrib_id, @object_type, NULL,
284                   @user_id, NULL, NULL, @object_name, NULL, NULL,
285                   NULL, NULL, "", @action) = 0
286           BEGIN
287               insert master..sysattributes
288               (class, attribute, object_type, object_info1,
289                   object_info3, object_cinfo, char_value)
290               values (6, @attrib_id, @object_type, @user_id,
291                   @instanceid, @object_name, @classname)
292               /*
293               ** 18278,"Failed to unbind '%1!' from execution class.
294               **	  Check server errorlog for any additional
295               **	  information."
296               */
297               raiserror 18278, @object_name
298               return (1)
299           END
300       END
301       ELSE IF (@object_type = "DF")
302       BEGIN
303           select @classname = char_value,
304               @instanceid = object_info3 from
305               master..sysattributes where
306               class = 6 AND
307               attribute = @attrib_id AND
308               object_type = @object_type
309   
310           IF (@classname is not NULL)
311           BEGIN
312   
313               delete master..sysattributes
314               where class = 6 AND
315                   attribute = @attrib_id AND
316                   object_type = @object_type
317           END
318           ELSE
319           BEGIN
320               /*
321               ** 18279, "The specified binding to be dropped does
322               **         not exist"
323               */
324               raiserror 18279
325               return (1)
326           END
327   
328           IF attrib_notify(6, @attrib_id, @object_type, NULL,
329                   NULL, NULL, NULL, NULL, NULL, @classname,
330                   NULL, NULL, "", @action) = 0
331           BEGIN
332               insert master..sysattributes
333               (class, attribute, object_type, object_info3, char_value)
334               values (6, @attrib_id, @object_type, @instanceid, @classname)
335           END
336       END
337       ELSE IF (@object_type = "PR")
338       BEGIN
339           select @classname = (select char_value from sysattributes where
340                       class = 6 AND
341                       attribute = @attrib_id AND
342                       object_type = @object_type AND
343                       object_info1 = @owner_id AND
344                       object_cinfo = @object_name),
345               @stored_objid = (select object from sysattributes where
346                       class = 6 AND
347                       attribute = @attrib_id AND
348                       object_type = @object_type AND
349                       object_info1 = @owner_id AND
350                       object_cinfo = @object_name),
351               @instanceid = (select object_info3 from sysattributes where
352   
353                       class = 6 AND
354                       attribute = @attrib_id AND
355                       object_type = @object_type AND
356                       object_info1 = @owner_id AND
357                       object_cinfo = @object_name)
358   
359           IF (@classname != NULL)
360           BEGIN
361   
362               delete sysattributes
363               where class = 6 AND
364                   attribute = @attrib_id AND
365                   object_type = @object_type AND
366                   object_info1 = @owner_id AND
367                   object_cinfo = @object_name
368           END
369           ELSE
370           BEGIN
371               /*
372               ** 18279, "The specified binding to be dropped does 
373               **	   not exist"
374               */
375               raiserror 18279
376               return (1)
377           END
378   
379           IF attrib_notify(6, @attrib_id, @object_type, @sp_objid,
380                   NULL, NULL, NULL, @object_name, NULL, NULL,
381                   NULL, NULL, "", @action) = 0
382           BEGIN
383               insert sysattributes
384               (class, attribute, object_type, object,
385                   object_info1, object_info3,
386                   object_cinfo, char_value)
387               values (6, @attrib_id, @object_type,
388                   @stored_objid, @owner_id, @instanceid,
389                   @object_name, @classname)
390   
391               /*
392               ** 18278,"Failed to unbind '%1!' from execution class.
393               **	  Check server errorlog for any additional
394               **	  information."
395               */
396               raiserror 18278, @object_name
397               return (1)
398           END
399       END
400       ELSE /* object is of type "SV" */
401       BEGIN
402           delete master..sysattributes
403           where class = 6 AND
404               attribute = @attrib_id AND
405               object_type = @object_type AND
406               object_cinfo = @object_name
407   
408           IF attrib_notify(6, @attrib_id, @object_type, NULL,
409                   NULL, NULL, NULL, @object_name, NULL, @classname,
410                   NULL, NULL, "", @action) = 0
411           BEGIN
412               insert sysattributes
413               (class, attribute, object_type, object_cinfo,
414                   char_value) values
415               (6, @attrib_id, @object_type, @object_name,
416                   @classname)
417               /*
418               ** 18278,"Failed to unbind '%1!' from execution class.
419               **	Check server errorlog for any additional information."
420               */
421               raiserror 18278, @object_name
422               return (1)
423           END
424       END
425   
426       return (0)
427   

DEFECTS
 MEST 4 Empty String will be replaced by Single Space 234
 MEST 4 Empty String will be replaced by Single Space 285
 MEST 4 Empty String will be replaced by Single Space 330
 MEST 4 Empty String will be replaced by Single Space 381
 MEST 4 Empty String will be replaced by Single Space 410
 MINU 4 Unique Index with nullable columns master..sysattributes master..sysattributes
 MINU 4 Unique Index with nullable columns sybsystemprocs..sysattributes sybsystemprocs..sysattributes
 MTYP 4 Assignment type mismatch @classname: varchar(255) = varchar(768) 202
 MTYP 4 Assignment type mismatch attribute: smallint = int 239
 MTYP 4 Assignment type mismatch @classname: varchar(255) = varchar(768) 254
 MTYP 4 Assignment type mismatch attribute: smallint = int 290
 MTYP 4 Assignment type mismatch @classname: varchar(255) = varchar(768) 303
 MTYP 4 Assignment type mismatch attribute: smallint = int 334
 MTYP 4 Assignment type mismatch attribute: smallint = int 387
 MTYP 4 Assignment type mismatch attribute: smallint = int 415
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 206
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 207
 QTYP 4 Comparison type mismatch smallint = int 207
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 216
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 217
 QTYP 4 Comparison type mismatch smallint = int 217
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 257
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 258
 QTYP 4 Comparison type mismatch smallint = int 258
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 267
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 268
 QTYP 4 Comparison type mismatch smallint = int 268
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 306
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 307
 QTYP 4 Comparison type mismatch smallint = int 307
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 314
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 315
 QTYP 4 Comparison type mismatch smallint = int 315
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 340
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 341
 QTYP 4 Comparison type mismatch smallint = int 341
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 346
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 347
 QTYP 4 Comparison type mismatch smallint = int 347
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 353
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 354
 QTYP 4 Comparison type mismatch smallint = int 354
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 363
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 364
 QTYP 4 Comparison type mismatch smallint = int 364
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 403
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 404
 QTYP 4 Comparison type mismatch smallint = int 404
 MGTP 3 Grant to public master..sysattributes  
 MGTP 3 Grant to public master..syslogins  
 MGTP 3 Grant to public sybsystemprocs..sysattributes  
 MGTP 3 Grant to public sybsystemprocs..sysobjects  
 MGTP 3 Grant to public sybsystemprocs..sysusers  
 MNAC 3 Not using ANSI 'is null' 359
 MNER 3 No Error Check should check @@error after delete 215
 MNER 3 No Error Check should check @@error after insert 236
 MNER 3 No Error Check should check @@error after delete 266
 MNER 3 No Error Check should check @@error after insert 287
 MNER 3 No Error Check should check @@error after delete 313
 MNER 3 No Error Check should check @@error after insert 332
 MNER 3 No Error Check should check @@error after delete 362
 MNER 3 No Error Check should check @@error after insert 383
 MNER 3 No Error Check should check @@error after delete 402
 MNER 3 No Error Check should check @@error after insert 412
 MUCO 3 Useless Code Useless Brackets 49
 MUCO 3 Useless Code Useless Brackets 62
 MUCO 3 Useless Code Useless Brackets 72
 MUCO 3 Useless Code Useless Brackets 78
 MUCO 3 Useless Code Useless Brackets 81
 MUCO 3 Useless Code Useless Brackets 87
 MUCO 3 Useless Code Useless Brackets 91
 MUCO 3 Useless Code Useless Brackets 97
 MUCO 3 Useless Code Useless Brackets 101
 MUCO 3 Useless Code Useless Brackets 107
 MUCO 3 Useless Code Useless Brackets 111
 MUCO 3 Useless Code Useless Brackets 118
 MUCO 3 Useless Code Useless Brackets 122
 MUCO 3 Useless Code Useless Brackets 130
 MUCO 3 Useless Code Useless Brackets 134
 MUCO 3 Useless Code Useless Brackets 139
 MUCO 3 Useless Code Useless Brackets 145
 MUCO 3 Useless Code Useless Brackets 149
 MUCO 3 Useless Code Useless Brackets 152
 MUCO 3 Useless Code Useless Brackets 154
 MUCO 3 Useless Code Useless Brackets 159
 MUCO 3 Useless Code Useless Brackets 169
 MUCO 3 Useless Code Useless Brackets 174
 MUCO 3 Useless Code Useless Brackets 176
 MUCO 3 Useless Code Useless Brackets 185
 MUCO 3 Useless Code Useless Brackets 189
 MUCO 3 Useless Code Useless Brackets 199
 MUCO 3 Useless Code Useless Brackets 212
 MUCO 3 Useless Code Useless Brackets 229
 MUCO 3 Useless Code Useless Brackets 249
 MUCO 3 Useless Code Useless Brackets 252
 MUCO 3 Useless Code Useless Brackets 263
 MUCO 3 Useless Code Useless Brackets 280
 MUCO 3 Useless Code Useless Brackets 298
 MUCO 3 Useless Code Useless Brackets 301
 MUCO 3 Useless Code Useless Brackets 310
 MUCO 3 Useless Code Useless Brackets 325
 MUCO 3 Useless Code Useless Brackets 337
 MUCO 3 Useless Code Useless Brackets 359
 MUCO 3 Useless Code Useless Brackets 376
 MUCO 3 Useless Code Useless Brackets 397
 MUCO 3 Useless Code Useless Brackets 422
 MUCO 3 Useless Code Useless Brackets 426
 MUOT 3 Updates outside transaction 412
 QAFM 3 Var Assignment from potentially many rows 202
 QAFM 3 Var Assignment from potentially many rows 254
 QAFM 3 Var Assignment from potentially many rows 303
 QISO 3 Set isolation level 58
 QIWC 3 Insert with not all columns specified missing 8 columns out of 15 237
 QIWC 3 Insert with not all columns specified missing 8 columns out of 15 288
 QIWC 3 Insert with not all columns specified missing 10 columns out of 15 333
 QIWC 3 Insert with not all columns specified missing 7 columns out of 15 384
 QIWC 3 Insert with not all columns specified missing 10 columns out of 15 413
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_type, object, object_cinfo, attribute, class}
206
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_type, object, object_cinfo, attribute, class}
216
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_info1, object_type, object_cinfo, attribute, class}
257
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_info1, object_type, object_cinfo, attribute, class}
267
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {class, object_type, attribute}
306
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {class, object_type, attribute}
314
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_info1, object_type, object_cinfo, attribute, class}
340
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_info1, object_type, object_cinfo, attribute, class}
346
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_info1, object_type, object_cinfo, attribute, class}
353
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_info1, object_type, object_cinfo, attribute, class}
363
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysattributes.csysattributes unique clustered
(class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo)
Intersection: {object_type, object_cinfo, attribute, class}
403
 MSUB 2 Subquery Marker 138
 MSUB 2 Subquery Marker 148
 MSUB 2 Subquery Marker 151
 MSUB 2 Subquery Marker 153
 MSUB 2 Subquery Marker 161
 MSUB 2 Subquery Marker 173
 MSUB 2 Subquery Marker 178
 MSUB 2 Subquery Marker 188
 MSUB 2 Subquery Marker 339
 MSUB 2 Subquery Marker 345
 MSUB 2 Subquery Marker 351
 MTR1 2 Metrics: Comments Ratio Comments: 28% 17
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 52 = 69dec - 19exi + 2 17
 MTR3 2 Metrics: Query Complexity Complexity: 223 17

DEPENDENCIES
PROCS AND TABLES USED
reads table sybsystemprocs..sysobjects  
reads table sybsystemprocs..sysusers  
read_writes table sybsystemprocs..sysattributes  
read_writes table master..sysattributes (1)  
reads table master..syslogins (1)