DatabaseProcApplicationCreatedLinks
sybsystemprocssp_shmdumpconfig_config  14 déc. 14Defects Propagation Dependencies

1     
2     /*
3     ** SP_SHMDUMPCONFIG_CONFIG
4     **
5     ** This file contains the definition of the sp_shmdumpconfig_config system
6     ** stored procedure.  This stored procedure is used to set "global" shared
7     ** memory dump configuration options (these are options not specified on a
8     ** per-condition basis. If granular permissions is not enabled the  sa_role 
9     ** is required to make any changes to the system configuration.  If granular
10    ** permissions is enabled then the permission 'manage server configuration' is
11    ** required.
12    **
13    ** Security: The sa_role role is required in order to execute this
14    ** stored procedure
15    **
16    ** History:
17    ** 06apr05	dwein		Initial coding
18    ** 18apr11	malloy		Added support for granular permissions.
19    */
20    
21    create or replace procedure sp_shmdumpconfig_config
22        /* -------------- Stored Procedure Parameters ----------------------- */
23        @option varchar(20), /* config option requested by user   */
24        @value int /* new value for config option	      */
25    
26    as
27    
28        /* ----------------- Declare Local Variables ------------------------ */
29        declare @cfgitem int, /* configuration option	      */
30            @not_status int, /* notification return status */
31            @ret_value int, /* return value */
32            @nullarg char(1),
33            @dummy int,
34            @status int,
35            @gp_enabled int
36    
37    
38    
39        /*
40        ** The following variables are treated as constants within this
41        ** stored procedure. They are set below.
42        */
43        declare @DUMPCOND_CLASS int, /* sysattributes class		*/
44            @OBJTYPE char(2), /* sysattributes object type	*/
45            @ATTRIB int, /* attribute column value	*/
46            @CFG_ERRORLOG int, /* include errorlog record id	*/
47            @CFG_MERGE int, /* merge pll dump record id	*/
48            @ATTR_ADD int, /* add notification value	*/
49            @ATTR_CHANGE int, /* change notification value	*/
50            @ATTR_DROP int, /* drop notification value	*/
51            @ATTR_FETCH int /* fetch notification value	*/
52    
53    
54        /* ----------------- Setup and Validation ------------------------ */
55        set nocount on
56    
57        /* 
58        ** If granular permissions is not enabled then sa_role is required.
59        ** If granular permissions is enabled then the permission 
60        ** 'manage server configuration' is required.  proc_role and proc_auditperm 
61        ** will also do auditing if required. Both will also print error message if 
62        ** required.
63        */
64    
65        select @nullarg = NULL
66        execute @status = sp_aux_checkroleperm "sa_role", "manage server configuration",
67            @nullarg, @gp_enabled output
68    
69        /* For Auditing */
70        if (@gp_enabled = 0)
71        begin
72            if (proc_role("sa_role") = 0)
73                return (1)
74        end
75        else
76        begin
77            select @dummy = proc_auditperm("manage server configuration", @status)
78        end
79    
80        if (@status != 0)
81            return (1)
82    
83        /*
84        ** Class ID and type defined in utils/attrib.lst
85        */
86        select @DUMPCOND_CLASS = 7
87        select @OBJTYPE = "DC"
88        select @ATTRIB = 0
89    
90        /*
91        ** The following constants define record types for the dump condition
92        ** class in the sysattributes table for the config records. The values 
93        ** set here must be the same as those defined in utils/shmdump.c.
94        */
95        select @CFG_ERRORLOG = 1
96        select @CFG_MERGE = 2
97    
98        /*
99        ** The following must correspond to values in sysattr.h
100       */
101       select @ATTR_ADD = 1
102       select @ATTR_CHANGE = 2
103       select @ATTR_DROP = 3
104       select @ATTR_FETCH = 4
105   
106       select @ret_value = 0
107   
108       /* Validate the config option */
109       if (@option = "merge files")
110       begin
111           select @cfgitem = @CFG_MERGE
112       end
113       else if @option = "include errorlog"
114       begin
115           select @cfgitem = @CFG_ERRORLOG
116       end
117       else if @option is NULL
118       begin
119           goto usage
120       end
121       else
122       begin
123           /* 
124           ** 19401, "Invalid dump configuration option: '%1!'"
125           */
126           raiserror 19401, @option
127           select @ret_value = 2
128           goto usage
129       end
130   
131       /* Validate the value against the config option */
132       if (@cfgitem in (@CFG_MERGE, @CFG_ERRORLOG))
133       begin
134           /* valid values are 0 or 1 */
135           if (@value not in (0, 1))
136           begin
137               /* 
138               ** 19402, "Invalid configuration value '%1!' for option '%2!'"
139               */
140               raiserror 19402, @value, @option
141               select @ret_value = 3
142               goto usage
143           end
144       end
145   
146       begin tran update_dump_config
147   
148       /*
149       ** The sysattributes rows that represent this configuration options
150       ** do not exist until a user explicitly configures an option.  Prior
151       ** to that point ASE will use a hard coded default.  This procedure
152       ** needs to determine if it will be creating the row for the first
153       ** time, or if it will be updating an existing row
154       */
155       if exists (select * from master.dbo.sysattributes
156               where class = @DUMPCOND_CLASS
157                   and attribute = @ATTRIB
158                   and object = @cfgitem)
159       begin
160           /* the row already exists, update it */
161           update master.dbo.sysattributes
162           set int_value = @value
163           where class = @DUMPCOND_CLASS
164               and attribute = @ATTRIB
165               and object = @cfgitem
166       end
167       else
168       begin
169           /* insert the new row */
170           insert master.dbo.sysattributes
171           (class, attribute, object_type, object, int_value)
172           values
173           (@DUMPCOND_CLASS, @ATTRIB, @OBJTYPE,
174               @cfgitem, @value)
175       end
176   
177       if (@@error = 0)
178       begin
179           select @not_status
180               = attrib_notify(@DUMPCOND_CLASS, /*cl*/
181                   @ATTRIB, /*attrib*/
182                   @OBJTYPE, /*type*/
183                   @cfgitem, /*object*/
184                   NULL, /*info1*/
185                   NULL, /*info2*/
186                   NULL, /*info3*/
187                   NULL, /*cinfo*/
188                   @value, /*intval*/
189                   NULL, /*charval*/
190                   NULL, /*textval*/
191                   NULL, /*imageval*/
192                   NULL, /*comment*/
193                   @ATTR_CHANGE)
194   
195           if (@not_status = 0)
196           begin
197               /*
198               ** 18510, "Notification failed. Your change did not take affect."
199               */
200               raiserror 18510
201               rollback tran update_dump_config
202               return 3
203           end
204       end
205       else
206       begin
207           /* we had an error either inserting into or updating sysattributes */
208           rollback tran update_dump_config
209           return 4
210       end
211   
212       /*
213       ** Delete of rows and notification were successful.
214       ** Commit transaction.
215       */
216       commit tran uppdate_dump_config
217   
218       /*
219       ** Indicate success
220       */
221       return 0
222   
223   usage:
224       print ""
225       print "Valid CSMD configuration options:"
226       print "---------------------------------"
227       print "  'include errorlog', 0 | 1  (include the ASE errorlog in the dump file)"
228       print "  'merge files', 0 | 1  (merge dump files after a parellel dump)"
229       print ""
230   
231       return @ret_value
232   
233   /*
234   ** End sp_shmdumpconfig_config
235   */
236   


exec sp_procxmode 'sp_shmdumpconfig_config', 'AnyMode'
go

Grant Execute on sp_shmdumpconfig_config to public
go
DEFECTS
 MEST 4 Empty String will be replaced by Single Space 224
 MEST 4 Empty String will be replaced by Single Space 229
 MINU 4 Unique Index with nullable columns master..sysattributes master..sysattributes
 MTYP 4 Assignment type mismatch attribute: smallint = int 173
 MTYP 4 Assignment type mismatch class: smallint = int 173
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 156
 QTYP 4 Comparison type mismatch smallint = int 156
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 157
 QTYP 4 Comparison type mismatch smallint = int 157
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 163
 QTYP 4 Comparison type mismatch smallint = int 163
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 164
 QTYP 4 Comparison type mismatch smallint = int 164
 MGTP 3 Grant to public master..sysattributes  
 MGTP 3 Grant to public sybsystemprocs..sp_shmdumpconfig_config  
 MNER 3 No Error Check should check @@error after update 161
 MNER 3 No Error Check should check @@error after insert 170
 MUCO 3 Useless Code Useless Brackets 70
 MUCO 3 Useless Code Useless Brackets 72
 MUCO 3 Useless Code Useless Brackets 73
 MUCO 3 Useless Code Useless Brackets 80
 MUCO 3 Useless Code Useless Brackets 81
 MUCO 3 Useless Code Useless Brackets 109
 MUCO 3 Useless Code Useless Brackets 132
 MUCO 3 Useless Code Useless Brackets 135
 MUCO 3 Useless Code Useless Brackets 177
 MUCO 3 Useless Code Useless Brackets 195
 QIWC 3 Insert with not all columns specified missing 10 columns out of 15 171
 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, class, attribute}
156
 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, class, attribute}
163
 VNRD 3 Variable is not read @dummy 77
 VNRD 3 Variable is not read @ATTR_ADD 101
 VNRD 3 Variable is not read @ATTR_DROP 103
 VNRD 3 Variable is not read @ATTR_FETCH 104
 MSUB 2 Subquery Marker 155
 MTR1 2 Metrics: Comments Ratio Comments: 49% 21
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 12 = 14dec - 4exi + 2 21
 MTR3 2 Metrics: Query Complexity Complexity: 78 21

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..sysattributes (1)  

CALLERS
called by proc sybsystemprocs..sp_shmdumpconfig