DatabaseProcApplicationCreatedLinks
sybsystemprocssp_addlanguage  14 déc. 14Defects Propagation 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 or replace 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        declare @dummy int
79        declare @gp_enabled int
80        declare @nullarg char(1)
81    
82    
83        select @HA_CERTIFIED = 0
84    
85    
86    
87    
88    
89        /* check to see if we are using HA specific SP for a HA enabled server */
90        exec @retstat = sp_ha_check_certified 'sp_addlanguage', @HA_CERTIFIED
91        if (@retstat != 0)
92            return (1)
93    
94    
95        /*
96        ** NOTE:
97        ** We should check here to see if we're in a transaction, and return
98        ** with a 17260 error ("Can't run %1! from within a transaction.") if
99        ** we are in a transaction.  However, the langinstall utility currently
100       ** calls sp_addlanguage from within a transaction.  Until this behavior
101       ** is changed we'll allow ourselves to be called from within a xact.
102       */
103   
104       /* 
105       ** check if user has sa role, proc_role will also do auditing
106       ** if required. proc_role will also print error message if required.
107       */
108       select @nullarg = NULL
109       execute @retstat = sp_aux_checkroleperm "sa_role",
110           "manage server", @nullarg, @gp_enabled output
111   
112       /*
113       **	For auditing.
114       */
115       if (@gp_enabled = 0)
116       begin
117           if (proc_role("sa_role") = 0)
118               return 1
119       end
120       else
121       begin
122           select @dummy = proc_auditperm("manage server", @retstat)
123       end
124   
125       if (@retstat != 0)
126           return 1
127   
128   
129       /* Check to see if the language name is valid */
130       if (@language is not null)
131       begin
132           select @maxlen = length from master.dbo.syscolumns
133           where id = object_id("master.dbo.syslanguages") and name = "name"
134   
135           if (char_length(@language) > @maxlen)
136           begin
137               /*
138               ** 17240, "'%1!' is not a valid name."
139               */
140               raiserror 17240, @language
141               return 1
142           end
143       end
144   
145       /*  Check to see if the language exists. */
146       select @returncode = 0
147       execute @returncode = sp_validlang @language
148       if @returncode = 0
149       begin
150           /*
151           **  17250, "'%1!' already exists in Syslanguages."
152           */
153           raiserror 17250, @language
154           return 1
155       end
156   
157       /* Check to see that the list of full month names is valid. */
158       execute @returncode = sp_chklangparam @months, "full month", 12, 20
159       if @returncode != 0
160           return 1
161   
162       /* Check to see that the list of short month names is valid. */
163       execute @returncode = sp_chklangparam @shortmons, "short month", 12, 9
164       if @returncode != 0
165           return 1
166   
167       /* Check to see that the list of day names is valid. */
168       execute @returncode = sp_chklangparam @days, "day", 7, 30
169       if @returncode != 0
170           return 1
171   
172       /* Check to see that the @datefmt is valid. */
173       if (@datefmt != 'mdy' and @datefmt != 'dmy' and @datefmt != 'ymd' and @datefmt != 'ydm'
174               and @datefmt != 'myd' and @datefmt != 'dym')
175       begin
176           /*
177           ** 17251, "'%1!' is not a valid date order."
178           */
179           raiserror 17251, @datefmt
180           return 1
181       end
182   
183       /*
184       **  Check to see that the @datefirst is valid.
185       */
186       if (@datefirst < 1 or @datefirst > 7)
187       begin
188           /*
189           ** 17252, "'%1!' is not a valid first day."
190           */
191           select @convdate = convert(char(3), @datefirst)
192           raiserror 17252, @convdate
193           return 1
194       end
195   
196       /* Check if @alias is valid */
197       if (@alias is not null)
198       begin
199           select @maxlen = length from master.dbo.syscolumns
200           where id = object_id("master.dbo.syslanguages") and name = "alias"
201   
202           if (char_length(@alias) > @maxlen)
203           begin
204               /*
205               ** 17240, "'%1!' is not a valid name."
206               */
207               raiserror 17240, @alias
208               return 1
209           end
210       end
211   
212       /*
213       **  If the user didn't specify the alias name, the alias name is same as 
214       **  the official name.
215       */
216       if @alias is null
217       begin
218           select @alias = @language
219       end
220   
221   
222   
223       /*  Check to see if the alias exists. */
224       select @returncode = 0
225       execute @returncode = sp_validaltlang @alias
226       if @returncode = 0
227       begin
228   
229           /*
230           ** 17253, "'%1!' alias already exists in Syslanguages."
231           */
232           raiserror 17253, @alias
233           return 1
234       end
235   
236       if @language = 'us_english'
237       begin
238   
239   
240   
241           /*  The language id of us_english is 0. */
242           insert master.dbo.syslanguages(langid, dateformat, datefirst, upgrade,
243               name, alias, months, shortmonths, days)
244           select 0, @datefmt, @datefirst, 0,
245               @language, @alias, @months, @shortmons, @days
246       end
247       else
248       begin
249           /* 
250           ** Attention:
251           ** 	if this ID generating algorithm is changed, please 
252           **	change the corresponding part in HA section too.
253           */
254           if (select max(langid) from master.dbo.syslanguages) is null
255           begin
256               select @nextlangid = 1
257           end
258           else
259           begin
260               select @nextlangid = (select max(langid) + 1
261                       from master.dbo.syslanguages)
262           end
263   
264   
265   
266           insert master.dbo.syslanguages(langid, dateformat, datefirst, upgrade,
267               name, alias, months, shortmonths, days)
268           select @nextlangid, @datefmt, @datefirst, 0,
269               @language, @alias, @months, @shortmons, @days
270       end
271   
272   
273       /* If the insert failed, say so. */
274       if @@error != 0
275       begin
276           /*
277           ** 17254, "Language not inserted."
278           */
279           raiserror 17254
280           goto clean_all
281       end
282   
283   
284   
285       /*
286       ** 17255, "New language inserted."
287       */
288       exec sp_getmessage 17255, @msg output
289       print @msg
290       return (0)
291   
292   clean_all:
293   
294   
295   
296       return (1)
297   
298   


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) 245
 MTYP 4 Assignment type mismatch name: varchar(30) = varchar(255) 245
 MTYP 4 Assignment type mismatch alias: varchar(30) = varchar(255) 269
 MTYP 4 Assignment type mismatch name: varchar(30) = varchar(255) 269
 MAW1 3 Warning message on %name% master..syscolumns.id: Warning message on syscolumns 133
 MAW1 3 Warning message on %name% master..syscolumns.id: Warning message on syscolumns 200
 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 242
 MNER 3 No Error Check should check @@error after insert 266
 MNER 3 No Error Check should check return value of exec 288
 MUCO 3 Useless Code Useless Brackets 91
 MUCO 3 Useless Code Useless Brackets 92
 MUCO 3 Useless Code Useless Brackets 115
 MUCO 3 Useless Code Useless Brackets 117
 MUCO 3 Useless Code Useless Brackets 125
 MUCO 3 Useless Code Useless Brackets 130
 MUCO 3 Useless Code Useless Brackets 135
 MUCO 3 Useless Code Useless Brackets 173
 MUCO 3 Useless Code Useless Brackets 186
 MUCO 3 Useless Code Useless Brackets 197
 MUCO 3 Useless Code Useless Brackets 202
 MUCO 3 Useless Code Useless Brackets 290
 MUCO 3 Useless Code Useless Brackets 296
 MUOT 3 Updates outside transaction 266
 QAFM 3 Var Assignment from potentially many rows 132
 QAFM 3 Var Assignment from potentially many rows 199
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
133
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
200
 VNRD 3 Variable is not read @dummy 122
 MTR1 2 Metrics: Comments Ratio Comments: 52% 61
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 22 = 28dec - 8exi + 2 61
 MTR3 2 Metrics: Query Complexity Complexity: 110 61

DATA PROPAGATION detailed
ColumnWritten To
@aliassyslanguages.alias  
@datefirstsyslanguages.datefirst  
@datefmtsyslanguages.dateformat  
@dayssyslanguages.days  
@languagesyslanguages.name   °.alias   sp_checkreswords_rset_005.Reserved Word Datatype Names
@monthssyslanguages.months  
@shortmonssyslanguages.shortmonths  

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