DatabaseProcApplicationCreatedLinks
sybsystemprocssp_metrics  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */
3     
4     /*
5     ** Messages for "sp_metrics"
6     **
7     ** 19357, "Syntax error. Extra arguments passed to '%1!' command. Run: sp_metrics 'help', '%1!' for usage information."
8     ** 19356, "'%1!' is an unsupported command. Check command and retry sp_metrics"
9     ** 19421, "Syntax error. '%1!' should be a string representation of an integer, such as '100'."
10    */
11    
12    /*
13    ** sp_metrics
14    **
15    **	Top-level user-interface procedure for QP metrics procedures.
16    **
17    **	This procedure is the command-control for the entire interface. It
18    **	receives the command from the user, parses it, and then calls other
19    **	sub-procs to execute on each command.
20    **
21    ** Returns:
22    **	0	- All checks are ok. Execution is ok.
23    **	1	- Some errors (arguments, usage) or permission(s) issues.
24    */
25    create procedure sp_metrics
26        @command varchar(30) = NULL
27        , @arg1 varchar(30) = NULL
28        , @arg2 varchar(600) = NULL
29    as
30    
31        declare @retval int /* From called sub-procedure.*/
32            , @param1 int
33            , @param2 int
34            , @param_len int
35            , @loopcount int
36            , @param_bit char(1)
37    
38        select @retval = 1 /* Expect failure. */
39    
40        set transaction isolation level 1
41        if @@trancount = 0
42        begin
43            set chained off
44        end
45        set nocount on
46    
47        /*
48        ** Allow non-sa users (or even non-dbo users) to run without any
49        ** arguments, at least so that the dbo can get some help info before
50        ** working on a particular command. (It is difficult to further restrict
51        ** this to regular users when we have absolutely no arguments.)
52        ** Remaining permissions checks will be done shortly hereafter.
53        */
54        if (@command IS NULL)
55        begin
56            exec @retval = sp_help_metrics
57            return @retval
58        end
59    
60        /*
61        ** ****************************************************************
62        ** No top-level permissions checks are being done in this procedure
63        ** as the permissions vary depending on the command being run and
64        ** granularity of the operation. Permission checking will be
65        ** implemented by each sub-command's procedure.
66        ** ****************************************************************
67        */
68        if (@command = 'flush')
69        begin
70            if (@arg1 is NOT NULL or @arg2 is NOT NULL)
71            begin
72                /* Report on extra arguments, and fail.*/
73                raiserror 19357, @command
74                return 1
75            end
76    
77            exec @retval = sp_flushmetrics
78        end
79        else if (@command = 'backup')
80        begin
81            if (@arg2 is NOT NULL)
82            begin
83                /* Report on extra arguments, and fail. */
84                raiserror 19357, @command
85                return 1
86            end
87    
88            select @loopcount = 0
89            select @param_len = char_length(@arg1)
90            while (@loopcount <= @param_len)
91            begin
92                select @param_bit = substring(@arg1, @loopcount, 1)
93                if NOT (@param_bit >= '0' and @param_bit <= '9')
94                begin
95                    raiserror 19421, '@arg1'
96                    return 1
97                end
98                select @loopcount = @loopcount + 1
99            end
100   
101           select @param1 = convert(integer, @arg1)
102           exec @retval = sp_backup_metrics @param1
103       end
104       else if (@command = 'drop')
105       begin
106           select @loopcount = 0
107           select @param_len = char_length(@arg1)
108           while (@loopcount <= @param_len)
109           begin
110               select @param_bit = substring(@arg1, @loopcount, 1)
111               if NOT (@param_bit >= '0' and @param_bit <= '9')
112               begin
113                   raiserror 19421, '@arg1'
114                   return 1
115               end
116               select @loopcount = @loopcount + 1
117           end
118   
119           select @loopcount = 0
120           select @param_len = char_length(@arg2)
121           while (@loopcount <= @param_len)
122           begin
123               select @param_bit = substring(@arg2, @loopcount, 1)
124               if NOT (@param_bit >= '0' and @param_bit <= '9')
125               begin
126                   raiserror 19421, '@arg2'
127                   return 1
128               end
129               select @loopcount = @loopcount + 1
130           end
131   
132           select @param1 = convert(integer, @arg1)
133           select @param2 = convert(integer, @arg2)
134           exec @retval = sp_drop_metrics @param1, @param2
135       end
136       else if (@command = 'filter')
137       begin
138           select @loopcount = 0
139           select @param_len = char_length(@arg1)
140           while (@loopcount <= @param_len)
141           begin
142               select @param_bit = substring(@arg1, @loopcount, 1)
143               if NOT (@param_bit >= '0' and @param_bit <= '9')
144               begin
145                   raiserror 19421, '@arg1'
146                   return 1
147               end
148               select @loopcount = @loopcount + 1
149           end
150   
151           exec @retval = sp_filter_metrics @arg1, @arg2
152       end
153       else if (@command = 'show')
154       begin
155           if (@arg1 is NOT NULL or @arg2 is NOT NULL)
156           begin
157               /* Report on extra arguments, and fail.*/
158               raiserror 19357, @command
159               return 1
160           end
161   
162           exec @retval = sp_show_metrics
163       end
164       else if (@command = 'help')
165       begin
166           if (@arg2 is NOT NULL)
167           begin
168               /* Report on extra arguments, and fail. */
169               raiserror 19357, @command
170               return 1
171           end
172           exec @retval = sp_help_metrics @arg1
173       end
174       else
175       begin
176           raiserror 19356, @command
177           return 1
178       end
179   
180       set nocount off
181   
182       return @retval
183   


exec sp_procxmode 'sp_metrics', 'AnyMode'
go

Grant Execute on sp_metrics to public
go
DEFECTS
 MGTP 3 Grant to public sybsystemprocs..sp_metrics  
 MNER 3 No Error Check should check return value of exec 56
 MNER 3 No Error Check should check return value of exec 77
 MNER 3 No Error Check should check return value of exec 102
 MNER 3 No Error Check should check return value of exec 134
 MNER 3 No Error Check should check return value of exec 151
 MNER 3 No Error Check should check return value of exec 162
 MNER 3 No Error Check should check return value of exec 172
 MUCO 3 Useless Code Useless Brackets 54
 MUCO 3 Useless Code Useless Brackets 68
 MUCO 3 Useless Code Useless Brackets 70
 MUCO 3 Useless Code Useless Brackets 79
 MUCO 3 Useless Code Useless Brackets 81
 MUCO 3 Useless Code Useless Brackets 90
 MUCO 3 Useless Code Useless Brackets 104
 MUCO 3 Useless Code Useless Brackets 108
 MUCO 3 Useless Code Useless Brackets 121
 MUCO 3 Useless Code Useless Brackets 136
 MUCO 3 Useless Code Useless Brackets 140
 MUCO 3 Useless Code Useless Brackets 153
 MUCO 3 Useless Code Useless Brackets 155
 MUCO 3 Useless Code Useless Brackets 164
 MUCO 3 Useless Code Useless Brackets 166
 QISO 3 Set isolation level 40
 MTR1 2 Metrics: Comments Ratio Comments: 36% 25
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 17 = 26dec - 11exi + 2 25
 MTR3 2 Metrics: Query Complexity Complexity: 99 25

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_filter_metrics  
   reads table sybsystemprocs..sysqueryplans  
calls proc sybsystemprocs..sp_help_metrics  
   calls proc sybsystemprocs..sp_getmessage  
      reads table sybsystemprocs..sysusermessages  
      reads table master..sysmessages (1)  
      calls proc sybsystemprocs..sp_validlang  
         reads table master..syslanguages (1)  
      reads table master..syslanguages (1)  
calls proc sybsystemprocs..sp_flushmetrics  
calls proc sybsystemprocs..sp_drop_metrics  
   read_writes table sybsystemprocs..sysqueryplans  
calls proc sybsystemprocs..sp_show_metrics  
   reads view sybsystemprocs..sysquerymetrics  
      reads table sybsystemprocs..sysqueryplans  
calls proc sybsystemprocs..sp_backup_metrics  
   read_writes table sybsystemprocs..sysqueryplans