DatabaseProcApplicationCreatedLinks
sybsystemprocssp_addlanguage  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
3     /*	4.8	1.1	06/14/90	sproc/src/addlanguage */
4     
5     /*
6     ** Messages for "sp_addlanguage"        17250
7     **
8     ** 17240, "'%1!' is not a valid name."
9     ** 17250, "'%1!' already exists in Syslanguages."
10    ** 17251, "'%1!' is not a valid date order."
11    ** 17252, "'%1!' is not a valid first day."
12    ** 17253, "'%1!' alias already exists in Syslanguages."
13    ** 17254, "Language not inserted."
14    ** 17255, "New language inserted."
15    ** 18773, "HA_LOG: HA consistency check failure in '%1!' on the companion server '%2!'"
16    ** 18774, "Languange name '%1!', alias '%2!', and/or language id '% 3!' already exists in Syslanguages."
17    ** 18881, "Unable to generate %1! for HA use. Please Refer to documentation for details."
18    */
19    
20    /* 
21    ** IMPORTANT: Please read the following instructions before
22    **   making changes to this stored procedure.
23    **
24    **	To make this stored procedure compatible with High Availability (HA),
25    **	changes to certain system tables must be propagated 
26    **	to the companion server under some conditions.
27    **	The tables include (but are not limited to):
28    **		syslogins, sysservers, sysattributes, systimeranges,
29    **		sysresourcelimits, sysalternates, sysdatabases,
30    **		syslanguages, sysremotelogins, sysloginroles,
31    **		sysalternates (master DB only), systypes (master DB only),
32    **		sysusers (master DB only), sysprotects (master DB only)
33    **	please refer to the HA documentation for detail.
34    **
35    **	Here is what you need to do: 
36    **	For each insert/update/delete statement, add three sections to
37    **	-- start HA transaction prior to the statement
38    **	-- add the statement
39    **	-- add HA synchronization code to propagate the change to the companion
40    **
41    **	For example, if you are adding 
42    **		insert master.dbo.syslogins ......
43    **	the code should look like:
44    **	1. Before that SQL statement:
45    **		
46    **	2. Now, the SQL statement:
47    **		insert master.dbo.syslogins ......
48    **	3. Add a HA synchronization section right after the SQL statement:
49    **		
50    **
51    **	You may need to do similar change for each built-in function you
52    **	want to add.
53    **
54    **	Finally, add a separate part at a place where it can not
55    **	be reached by the normal execution path:
56    **	clean_all:
57    **		
58    **		return (1)
59    */
60    
61    create procedure sp_addlanguage
62        @language varchar(255),
63        @alias varchar(255) = NULL,
64        @months varchar(251),
65        @shortmons varchar(119),
66        @days varchar(216),
67        @datefmt char(3),
68        @datefirst tinyint
69    as
70    
71        declare @msg varchar(1024)
72        declare @nextlangid smallint
73        declare @returncode int
74        declare @convdate char(3)
75        declare @maxlen int
76        declare @HA_CERTIFIED tinyint /* Is the SP HA certified ? */
77        declare @retstat int
78    
79    
80        select @HA_CERTIFIED = 0
81    
82    
83    
84    
85        /* check to see if we are using HA specific SP for a HA enabled server */
86        exec @retstat = sp_ha_check_certified 'sp_addlanguage', @HA_CERTIFIED
87        if (@retstat != 0)
88            return (1)
89    
90    
91        /*
92        ** NOTE:
93        ** We should check here to see if we're in a transaction, and return
94        ** with a 17260 error ("Can't run %1! from within a transaction.") if
95        ** we are in a transaction.  However, the langinstall utility currently
96        ** calls sp_addlanguage from within a transaction.  Until this behavior
97        ** is changed we'll allow ourselves to be called from within a xact.
98        */
99    
100       /* 
101       ** check if user has sa role, proc_role will also do auditing
102       ** if required. proc_role will also print error message if required.
103       */
104   
105       if (proc_role("sa_role") = 0)
106           return (1)
107   
108   
109       /* Check to see if the language name is valid */
110       if (@language is not null)
111       begin
112           select @maxlen = length from master.dbo.syscolumns
113           where id = object_id("master.dbo.syslanguages") and name = "name"
114   
115           if (char_length(@language) > @maxlen)
116           begin
117               /*
118               ** 17240, "'%1!' is not a valid name."
119               */
120               raiserror 17240, @language
121               return 1
122           end
123       end
124   
125       /*  Check to see if the language exists. */
126       select @returncode = 0
127       execute @returncode = sp_validlang @language
128       if @returncode = 0
129       begin
130           /*
131           **  17250, "'%1!' already exists in Syslanguages."
132           */
133           raiserror 17250, @language
134           return 1
135       end
136   
137       /* Check to see that the list of full month names is valid. */
138       execute @returncode = sp_chklangparam @months, "full month", 12, 20
139       if @returncode != 0
140           return 1
141   
142       /* Check to see that the list of short month names is valid. */
143       execute @returncode = sp_chklangparam @shortmons, "short month", 12, 9
144       if @returncode != 0
145           return 1
146   
147       /* Check to see that the list of day names is valid. */
148       execute @returncode = sp_chklangparam @days, "day", 7, 30
149       if @returncode != 0
150           return 1
151   
152       /* Check to see that the @datefmt is valid. */
153       if (@datefmt != 'mdy' and @datefmt != 'dmy' and @datefmt != 'ymd' and @datefmt != 'ydm'
154               and @datefmt != 'myd' and @datefmt != 'dym')
155       begin
156           /*
157           ** 17251, "'%1!' is not a valid date order."
158           */
159           raiserror 17251, @datefmt
160           return 1
161       end
162   
163       /*
164       **  Check to see that the @datefirst is valid.
165       */
166       if (@datefirst < 1 or @datefirst > 7)
167       begin
168           /*
169           ** 17252, "'%1!' is not a valid first day."
170           */
171           select @convdate = convert(char(3), @datefirst)
172           raiserror 17252, @convdate
173           return 1
174       end
175   
176       /* Check if @alias is valid */
177       if (@alias is not null)
178       begin
179           select @maxlen = length from master.dbo.syscolumns
180           where id = object_id("master.dbo.syslanguages") and name = "alias"
181   
182           if (char_length(@alias) > @maxlen)
183           begin
184               /*
185               ** 17240, "'%1!' is not a valid name."
186               */
187               raiserror 17240, @alias
188               return 1
189           end
190       end
191   
192       /*
193       **  If the user didn't specify the alias name, the alias name is same as 
194       **  the official name.
195       */
196       if @alias is null
197       begin
198           select @alias = @language
199       end
200   
201   
202   
203       /*  Check to see if the alias exists. */
204       select @returncode = 0
205       execute @returncode = sp_validaltlang @alias
206       if @returncode = 0
207       begin
208   
209           /*
210           ** 17253, "'%1!' alias already exists in Syslanguages."
211           */
212           raiserror 17253, @alias
213           return 1
214       end
215   
216       if @language = 'us_english'
217       begin
218   
219   
220   
221           /*  The language id of us_english is 0. */
222           insert master.dbo.syslanguages(langid, dateformat, datefirst, upgrade,
223               name, alias, months, shortmonths, days)
224           select 0, @datefmt, @datefirst, 0,
225               @language, @alias, @months, @shortmons, @days
226       end
227       else
228       begin
229           /* 
230           ** Attention:
231           ** 	if this ID generating algorithm is changed, please 
232           **	change the corresponding part in HA section too.
233           */
234           if (select max(langid) from master.dbo.syslanguages) is null
235           begin
236               select @nextlangid = 1
237           end
238           else
239           begin
240               select @nextlangid = (select max(langid) + 1
241                       from master.dbo.syslanguages)
242           end
243   
244   
245   
246           insert master.dbo.syslanguages(langid, dateformat, datefirst, upgrade,
247               name, alias, months, shortmonths, days)
248           select @nextlangid, @datefmt, @datefirst, 0,
249               @language, @alias, @months, @shortmons, @days
250       end
251   
252   
253       /* If the insert failed, say so. */
254       if @@error != 0
255       begin
256           /*
257           ** 17254, "Language not inserted."
258           */
259           raiserror 17254
260           goto clean_all
261       end
262   
263   
264   
265       /*
266       ** 17255, "New language inserted."
267       */
268       exec sp_getmessage 17255, @msg output
269       print @msg
270       return (0)
271   
272   clean_all:
273   
274   
275   
276       return (1)
277   
278   


exec sp_procxmode 'sp_addlanguage', 'AnyMode'
go

Grant Execute on sp_addlanguage to public
go
DEFECTS
 MINU 4 Unique Index with nullable columns master..syslanguages master..syslanguages
 MTYP 4 Assignment type mismatch alias: varchar(30) = varchar(255) 225
 MTYP 4 Assignment type mismatch name: varchar(30) = varchar(255) 225
 MTYP 4 Assignment type mismatch alias: varchar(30) = varchar(255) 249
 MTYP 4 Assignment type mismatch name: varchar(30) = varchar(255) 249
 MGTP 3 Grant to public master..syscolumns  
 MGTP 3 Grant to public master..syslanguages  
 MGTP 3 Grant to public sybsystemprocs..sp_addlanguage  
 MNER 3 No Error Check should check @@error after insert 222
 MNER 3 No Error Check should check @@error after insert 246
 MNER 3 No Error Check should check return value of exec 268
 MUCO 3 Useless Code Useless Brackets 87
 MUCO 3 Useless Code Useless Brackets 88
 MUCO 3 Useless Code Useless Brackets 105
 MUCO 3 Useless Code Useless Brackets 106
 MUCO 3 Useless Code Useless Brackets 110
 MUCO 3 Useless Code Useless Brackets 115
 MUCO 3 Useless Code Useless Brackets 153
 MUCO 3 Useless Code Useless Brackets 166
 MUCO 3 Useless Code Useless Brackets 177
 MUCO 3 Useless Code Useless Brackets 182
 MUCO 3 Useless Code Useless Brackets 270
 MUCO 3 Useless Code Useless Brackets 276
 MUOT 3 Updates outside transaction 246
 QAFM 3 Var Assignment from potentially many rows 112
 QAFM 3 Var Assignment from potentially many rows 179
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
113
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
180
 MTR1 2 Metrics: Comments Ratio Comments: 56% 61
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 20 = 25dec - 7exi + 2 61
 MTR3 2 Metrics: Query Complexity Complexity: 99 61

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_ha_check_certified  
   reads table tempdb..sysobjects (1)  
calls proc sybsystemprocs..sp_validaltlang  
   reads table master..syslanguages (1)  
reads table master..syscolumns (1)  
read_writes table master..syslanguages (1)  
calls proc sybsystemprocs..sp_validlang  
   reads table master..syslanguages (1)  
calls proc sybsystemprocs..sp_chklangparam  
   reads table master..sysconfigures (1)  
   reads table master..syscharsets (1)  
calls proc sybsystemprocs..sp_getmessage  
   reads table master..syslanguages (1)  
   calls proc sybsystemprocs..sp_validlang  
   reads table sybsystemprocs..sysusermessages  
   reads table master..sysmessages (1)