DatabaseProcApplicationCreatedLinks
sybsystemprocssp_chklangparam  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/chklangparam */
4     /*
5     ** sp_checklangparam is called by sp_addlanguage to check the lists of
6     ** full month names, short month names, and day names.  It returns a status
7     ** indicating whether any errors were found:
8     **	0 - name list is valid
9     **	1 - spaces were found, which are not allowed
10    **	2 - not enough names in the list (must be exactly @numnames of them)
11    **	3 - too many names in the list (must be exactly @numnames of them)
12    **	4 - some name(s) are too long
13    **	5 - some name(s) have non-aphabetic characters
14    */
15    
16    /*
17    ** Messages for "sp_chklangparam"       17373
18    **
19    ** %1! is either "month" or "day" 
20    ** 17373, "List of %1! names contains spaces, which are not allowed."
21    ** 17374, "List of %1! names has too few names."
22    ** 17375, "List of %1! names has too many names."
23    ** 17376, "List of %1! names has name(s) which are too long."
24    ** 17377, "List of %1! names contains name(s) which have '%2!' non-alphabetic characters."
25    ** %2! is the character set name 
26    */
27    
28    create procedure sp_chklangparam
29        @namelist varchar(251), /* month or day name list */
30        @msgparam varchar(30), /* name of list, for error messages */
31        @numnames int, /* correct number of names in the list */
32        @maxnamelen int /* maximum length of any name in list */
33    as
34    
35        declare @totallen int
36        declare @mthlen int
37        declare @mthname varchar(251)
38        declare @csid int
39        declare @csname varchar(30)
40    
41        if @@trancount = 0
42        begin
43            set chained off
44        end
45    
46        set transaction isolation level 1
47    
48        /* Get the Character Set id (csid) */
49        /* (Up to the version 4.2)
50        select @csid = csid from master..syscharsets
51        where id = (select value from master..sysconfigures
52        where config = 123)
53        */
54        /* (After 4.9) */
55        select @csid = value from master..sysconfigures
56        where config = 131
57    
58        /* Get the Character Set Name (csname) */
59        select @csname = name from master..syscharsets
60        where id = @csid and type < 2000
61    
62        /* Make sure the list has no blanks. */
63        if (charindex(" ", @namelist) != 0)
64        begin
65            /*
66            ** 17373, "List of %1! names contains spaces, which are not allowed."
67            */
68            raiserror 17373, @msgparam
69            return 1
70        end
71    
72        /* Keep track of number of *CHARACTERS* */
73        select @totallen = char_length(@namelist)
74        /* select @totallen = datalength( @namelist ) */
75        while (@totallen > 0)
76        begin
77            /* Move to the next name in the list. */
78            select @namelist = right (@namelist, @totallen)
79    
80            /* If this is not the last name in the list then there must
81            ** be another comma.
82            */
83            if (@numnames > 1)
84            begin
85                select @mthlen = charindex(",", @namelist) - 1
86                if (@mthlen < 0)
87                begin
88                    /*
89                    ** 17374, "List of %1! names has too few names."
90                    */
91                    raiserror 17374, @msgparam
92                    return 2
93                end
94            end
95    
96            /* This is the last name in the list, so there cannot be
97            ** another comma.  This name is all remaining characters
98            ** in the list.
99            */
100           else
101           begin
102               if (charindex(",", @namelist) != 0)
103               begin
104                   /*
105                   ** 17375, "List of %1! names has too many names."
106                   */
107                   raiserror 17375, @msgparam
108                   return 3
109               end
110               select @mthlen = @totallen
111           end
112   
113           /* Check the name length. */
114           if (@mthlen > @maxnamelen)
115           begin
116               /*
117               ** 17376, "List of %1! names has name(s) which are too long."
118               */
119               raiserror 17376, @msgparam
120               return 4
121           end
122   
123           /*
124           ** Check to see that the names contain only valid
125           ** P_ALPHA characters; not even DIGITs should be allowed.
126           ** Note that valid_name() returns a bit-mask of the lexical
127           ** values found in the string passed to it, where P_ALPHA
128           ** is 0x01.
129           ** Note too that as of CR 638115 and follow-on CR 645112,
130           ** when sp_config "enable functionality group" is 1,
131           ** valid_name 'or's in the value 0x80 (128) when the name 
132           ** is valid as a quoted identifier. Thus, in the following
133           ** expression, we must 'and' this bit back out.
134           */
135           if ((valid_name(substring(@namelist, 1, @mthlen)) & 127) != 1)
136           begin
137               /*
138               ** 17377, "List of %1! names contains name(s) which have 
139               ** '%2!' non-alphabetic characters."
140               */
141               raiserror 17377, @msgparam, @csname
142               return 5
143           end
144   
145           /* Move to the next name in the list. */
146           select @numnames = @numnames - 1
147           select @totallen = @totallen - @mthlen - 1
148       end
149   
150       /* No problems were found with the name list. */
151       return 0
152   

DEFECTS
 MINU 4 Unique Index with nullable columns master..sysconfigures master..sysconfigures
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 56
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 60
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs int 60
 QTYP 4 Comparison type mismatch tinyint = int 60
 MGTP 3 Grant to public master..syscharsets  
 MGTP 3 Grant to public master..sysconfigures  
 MUCO 3 Useless Code Useless Brackets 63
 MUCO 3 Useless Code Useless Brackets 75
 MUCO 3 Useless Code Useless Brackets 83
 MUCO 3 Useless Code Useless Brackets 86
 MUCO 3 Useless Code Useless Brackets 102
 MUCO 3 Useless Code Useless Brackets 114
 MUCO 3 Useless Code Useless Brackets 135
 QAFM 3 Var Assignment from potentially many rows 55
 QAFM 3 Var Assignment from potentially many rows 59
 QISO 3 Set isolation level 46
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscharsets.csyscharsets unique clustered
(id, csid)
Intersection: {id}
60
 VUNU 3 Variable is not used @mthname 37
 MTR1 2 Metrics: Comments Ratio Comments: 62% 28
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 5 = 9dec - 6exi + 2 28
 MTR3 2 Metrics: Query Complexity Complexity: 48 28

DEPENDENCIES
PROCS AND TABLES USED
reads table master..sysconfigures (1)  
reads table master..syscharsets (1)  

CALLERS
called by proc sybsystemprocs..sp_addlanguage