DatabaseProcApplicationCreatedLinks
sybsystemprocssp_aux_getsize  31 Aug 14Defects Dependencies

1     
2     /* This stored procedure is for parsing a size string of the form:
3     **		 "%f[pPkKmMgG]
4     ** and return the value in equivalent "k" units if @format_str is NULL.
5     ** If a format string is specified then another conversion to the required
6     ** format is done. @output_str has the string equivalent of the return value.
7     ** If a format string is specified then @ret_size value will be set to 0.
8     ** For example sp_aux_getsize "1024K",@ret_size, "M" will put 1 in @ret_size.
9     **
10    **	Messages for sp_aux_getsize
11    ** 
12    ** 18146, "Syntax error encountered. Sizes must be of the form int[KMGP].
13    **         For example, a size of 5 megabytes may be specified as '5M'."
14    **
15    ** 18149, "Invalid size of %1! encountered. Sizes must be greater than zero."
16    */
17    create procedure sp_aux_getsize
18        @size_str varchar(30),
19        @ret_size int output,
20        @input_size int = NULL,
21        @output_str varchar(30) = NULL output
22    as
23    
24        declare
25            @unit_loc int,
26            @multiplier int,
27            @one_char char(1),
28            @digits varchar(30),
29            @units varchar(30),
30            @float_size float,
31            @count int,
32            @found_invalid_char int,
33            @num_decimal int,
34            @digit_str_len int
35    
36        select @unit_loc = patindex("%[kKmMgGpP]%", @size_str)
37    
38        if @unit_loc != 0
39        begin
40            /*
41            ** Separate the unit specifier from the digits.
42            */
43            select @digits = substring(@size_str, 1, @unit_loc - 1)
44            select @units = lower(substring(@size_str, @unit_loc, 30))
45    
46            /*
47            ** Remove any blanks that may have been between the digits 
48            ** and the unit specifier (for example, '2 M').
49            */
50            select @digits = rtrim(@digits)
51    
52            /* 
53            ** Make sure the unit specifier is valid.  Acceptable values
54            ** are [pPkKmMgG]; however; we will allow the user to specify 
55            ** [kKmMgG]b. For example, 8Mb will be allowed.
56            */
57            if ((datalength(@units) > 2)
58                    or ((datalength(@units) > 1) and (substring(@units, 2, 1) != 'b'))
59                    or ((datalength(@units) > 1) and (substring(@units, 1, 1) = 'p')))
60            begin
61                /* 18146, "Syntax error encountered. Sizes must be
62                ** of the form int[KMGP]. For example, a size of 5 
63                ** megabytes may be specified as '5M'."
64                */
65                raiserror 18146
66                select @ret_size = 0
67                return 0
68            end
69    
70            select @units = substring(@units, 1, 1)
71        end
72        else
73        begin
74            select @digits = substring(@size_str, 1, char_length(@size_str))
75            select @units = "k"
76        end
77    
78        /*
79        ** Ensure that @digits contains a valid floating-point 
80        ** number.
81        */
82        if (@digits is NULL)
83        begin
84            /*
85            ** 18146, "Syntax error encountered. Sizes must be of the form
86            **        int[KMGP]. For example, a size of 5 megabytes may be
87            **        specified as '5M'."
88            */
89            raiserror 18146
90            select @ret_size = 0
91            return 0
92        end
93    
94        select @found_invalid_char = patindex("%[^0-9.]%", @digits)
95        select @num_decimal = 0
96    
97        if (@found_invalid_char = 0)
98        begin
99            /*
100           ** Shake out errors like '.2.0M'
101           */
102           select @count = 1
103           select @digit_str_len = char_length(@digits)
104   
105           while (@count <= @digit_str_len)
106           begin
107               select @one_char = substring(@digits, @count, 1)
108               if (@one_char = ".")
109               begin
110                   select @num_decimal = @num_decimal + 1
111               end
112               select @count = @count + 1
113           end
114       end
115   
116       if ((@found_invalid_char != 0) or (@num_decimal > 1))
117       begin
118           /* 
119           ** 18146, "Syntax error encountered. Sizes must be of the form
120           **        int[KMGP]. For example, a size of 5 megabytes may be
121           **        specified as '5M'."
122           */
123           raiserror 18146
124           select @ret_size = 0
125           return 0
126       end
127   
128       if @input_size is NULL
129       begin
130           select @float_size = convert(float, @digits)
131   
132           if @float_size < 0
133           begin
134               select @size_str = rtrim(@size_str)
135               /*
136               ** 18149, "Invalid size of %1! encountered. Sizes must be
137               ** greater than zero."
138               */
139               raiserror 18149, @size_str
140               return 0
141           end
142   
143           if (@units = "p")
144               select @float_size = @float_size * @@maxpagesize / 1024
145           else if (@units = "m")
146               select @float_size = @float_size * 1024
147           else if (@units = "g")
148               select @float_size = @float_size * 1024 * 1024
149       end
150       else
151       begin
152           select @float_size = @input_size
153       end
154   
155       if @input_size is not NULL
156       begin
157           /* Here the input size is assumed to be in K units */
158           if (@units = "p")
159               select @float_size = @float_size / (@@maxpagesize / 1024)
160           else if (@units = "m")
161               select @float_size = @float_size / 1024
162           else if (@units = "g")
163               select @float_size = @float_size / (1024 * 1024)
164       end
165   
166       /*
167       **  Now round config size to the nearest integer value since
168       **  we'll be inserting this into sysconfigures as the integer
169       **  representation of the number of kilobytes for this size of this
170       **  cache.  But if a format string is given as an input, round it off
171       **  to the 4 digit precision after a decimal point.
172       */
173       if @input_size is not NULL
174       begin
175           select @ret_size = 0
176           select @output_str = ltrim(str(round(@float_size, 4), 15, 4)) + @units
177       end
178       else
179       begin
180           select @ret_size = convert(int, round(@float_size, 0))
181       end
182       return 1
183   


exec sp_procxmode 'sp_aux_getsize', 'AnyMode'
go

Grant Execute on sp_aux_getsize to public
go
DEFECTS
 MGTP 3 Grant to public sybsystemprocs..sp_aux_getsize  
 MUCO 3 Useless Code Useless Brackets 57
 MUCO 3 Useless Code Useless Brackets 82
 MUCO 3 Useless Code Useless Brackets 97
 MUCO 3 Useless Code Useless Brackets 105
 MUCO 3 Useless Code Useless Brackets 108
 MUCO 3 Useless Code Useless Brackets 116
 MUCO 3 Useless Code Useless Brackets 143
 MUCO 3 Useless Code Useless Brackets 145
 MUCO 3 Useless Code Useless Brackets 147
 MUCO 3 Useless Code Useless Brackets 158
 MUCO 3 Useless Code Useless Brackets 160
 MUCO 3 Useless Code Useless Brackets 162
 VUNU 3 Variable is not used @multiplier 26
 MTR1 2 Metrics: Comments Ratio Comments: 43% 17
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 19 = 22dec - 5exi + 2 17
 MTR3 2 Metrics: Query Complexity Complexity: 79 17

DEPENDENCIES
CALLERS
called by proc sybsystemprocs..sp_helpconfig  
called by proc sybsystemprocs..sp_helpcache  
called by proc sybsystemprocs..sp_cacheconfig  
   called by proc sybsystemprocs..sp_do_poolconfig  
      called by proc sybsystemprocs..sp_poolconfig  
called by proc sybsystemprocs..sp_estspace  
called by proc sybsystemprocs..sp_configure  
   called by proc sybsystemprocs..sp_configure  
   called by proc sybsystemprocs..sp_setlockpromote  
      called by proc sybsystemprocs..sp_setpglockpromote  
      called by proc sybsystemprocs..sp_setrowlockpromote  
called by proc sybsystemprocs..sp_do_poolconfig