DatabaseProcApplicationCreatedLinks
sybsystemprocssp_sqlrep_check_syntax  14 déc. 14Defects Propagation Dependencies

1     
2     
3     /*
4     ** sp_sqlrep_check_syntax checks that @parameter is a valid substring
5     ** of @sqlrep.
6     **
7     ** It returns 1 if it is, and 0 if it is not.
8     **
9     ** For example, if @sqlrep = 'udis', then a valid substring of @sqlrep
10    ** is a string in which only characters 'u', 'd', 'i' or 's' may appear.
11    ** They may appear exactly 0 or 1 time.
12    **
13    ** 'ud' is a valid substring, so is 'si'.
14    ** 'uu' is not and neither ' ', nor 'uais' are.
15    */
16    create or replace procedure sp_sqlrep_check_syntax
17        @parameter varchar(20) = NULL, /* parameter to be checked */
18        @sqlrep varchar(4) = NULL, /* 'udis' or 'udi' */
19        @syntax_ok int output /* 1 if ok, 0 otherwise */
20    as
21        begin
22            declare @c char(1)
23            declare @update char(1)
24            declare @delete char(1)
25            declare @inserts char(1)
26            declare @selinto char(1)
27            declare @sqlrep_length int
28            declare @param_count int
29            declare @num_update int
30            declare @num_delete int
31            declare @num_inserts int
32            declare @num_selinto int
33    
34            select @sqlrep_length = datalength(@sqlrep)
35            select @syntax_ok = 1
36    
37            /*
38            ** If displaying mode only, syntax is OK;
39            ** just return.
40            */
41            if (@parameter is NULL)
42                return
43    
44            select @parameter = ltrim(@parameter)
45            select @parameter = rtrim(@parameter)
46    
47            /*
48            ** Expedite obviously invalid conditions.
49            ** Single out NULL value for @parameter
50            ** because the NULL value would pass the
51            ** other tests below.
52            */
53            if (datalength(@parameter) > @sqlrep_length) or
54                (@parameter is NULL) or
55                @sqlrep is NULL
56            begin
57                select @syntax_ok = 0
58            end
59            else
60            begin
61                select @update = substring(@sqlrep, 1, 1)
62                select @delete = substring(@sqlrep, 2, 1)
63                select @inserts = substring(@sqlrep, 3, 1)
64    
65                /*
66                ** @selinto is NULL if the @sqlrep string
67                ** is 'udi'.
68                ** It is 's' if the @sqlrep string is 'udis'.
69                */
70                select @selinto = substring(@sqlrep, 4, 1)
71    
72                select @num_update = 0
73                select @num_delete = 0
74                select @num_inserts = 0
75                select @num_selinto = 0
76    
77                select @param_count = 1
78                while (@param_count < datalength(@parameter) + 1)
79                begin
80                    select @c = substring(@parameter, @param_count, 1)
81                    if (@c = @update)
82                    begin
83                        select @num_update = @num_update + 1
84                        if (@num_update > 1)
85                        begin
86                            select @syntax_ok = 0
87                            break
88                        end
89                    end
90                    else
91                    if (@c = @delete)
92                    begin
93                        select @num_delete = @num_delete + 1
94                        if (@num_delete > 1)
95                        begin
96                            select @syntax_ok = 0
97                            break
98                        end
99                    end
100                   else
101                   if (@c = @inserts)
102                   begin
103                       select @num_inserts = @num_inserts + 1
104                       if (@num_inserts > 1)
105                       begin
106                           select @syntax_ok = 0
107                           break
108                       end
109                   end
110                   else
111                   if (@c = @selinto)
112                   begin
113                       select @num_selinto = @num_selinto + 1
114                       if (@num_selinto > 1)
115                       begin
116                           select @syntax_ok = 0
117                           break
118                       end
119                   end
120                   else
121                   begin
122                       select @syntax_ok = 0
123                       break
124                   end
125                   select @param_count = @param_count + 1
126               end
127           end
128           return (0)
129       end
130   


exec sp_procxmode 'sp_sqlrep_check_syntax', 'AnyMode'
go

Grant Execute on sp_sqlrep_check_syntax to public
go
DEFECTS
 MGTP 3 Grant to public sybsystemprocs..sp_sqlrep_check_syntax  
 MUCO 3 Useless Code Useless Begin-End Pair 21
 MUCO 3 Useless Code Useless Brackets 41
 MUCO 3 Useless Code Useless Brackets 78
 MUCO 3 Useless Code Useless Brackets 81
 MUCO 3 Useless Code Useless Brackets 84
 MUCO 3 Useless Code Useless Brackets 91
 MUCO 3 Useless Code Useless Brackets 94
 MUCO 3 Useless Code Useless Brackets 101
 MUCO 3 Useless Code Useless Brackets 104
 MUCO 3 Useless Code Useless Brackets 111
 MUCO 3 Useless Code Useless Brackets 114
 MUCO 3 Useless Code Useless Brackets 128
 MTR1 2 Metrics: Comments Ratio Comments: 29% 16
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 15 = 14dec - 1exi + 2 16
 MTR3 2 Metrics: Query Complexity Complexity: 68 16

DEPENDENCIES
CALLERS
called by proc sybsystemprocs..sp_setrepdefmode  
called by proc sybsystemprocs..sp_setrepdbmode