DatabaseProcApplicationCreatedLinks
sybsystemprocssp_setlangalias  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/serveroption */
4     
5     /*
6     ** Messages for "sp_setlangalias"       17810
7     **
8     ** 17201, "'%1!' is not an official language name from Syslanguages."
9     ** 17240, "'" + @alias + "' is not a valid name." 
10    ** 17260, "Can't run %1! from within a transaction."
11    ** 17253, "'%1!' alias already exists in Syslanguages."
12    ** 17810, "Language alias not changed."
13    ** 17811, "Language alias reset."
14    ** 18773, "HA_LOG: HA consistency check failure in stored procedure '%1!' on companion server '%2!'"
15    ** 18775, "Unable to find a language entry with language name '%1!' and language id '%2!'."
16    */
17    
18    /* 
19    ** IMPORTANT: Please read the following instructions before
20    **   making changes to this stored procedure.
21    **
22    **	To make this stored procedure compatible with High Availability (HA),
23    **	changes to certain system tables must be propagated 
24    **	to the companion server under some conditions.
25    **	The tables include (but are not limited to):
26    **		syslogins, sysservers, sysattributes, systimeranges,
27    **		sysresourcelimits, sysalternates, sysdatabases,
28    **		syslanguages, sysremotelogins, sysloginroles,
29    **		sysalternates (master DB only), systypes (master DB only),
30    **		sysusers (master DB only), sysprotects (master DB only)
31    **	please refer to the HA documentation for detail.
32    **
33    **	Here is what you need to do: 
34    **	For each insert/update/delete statement, add three sections to
35    **	-- start HA transaction prior to the statement
36    **	-- add the statement
37    **	-- add HA synchronization code to propagate the change to the companion
38    **
39    **	For example, if you are adding 
40    **		insert master.dbo.syslogins ......
41    **	the code should look like:
42    **	1. Before that SQL statement:
43    **		
44    **	2. Now, the SQL statement:
45    **		insert master.dbo.syslogins ......
46    **	3. Add a HA synchronization section right after the SQL statement:
47    **		
48    **
49    **	You may need to do similar change for each built-in function you
50    **	want to add.
51    **
52    **	Finally, add a separate part at a place where it can not
53    **	be reached by the normal execution path:
54    **	clean_all:
55    **		
56    **		return (1)
57    */
58    
59    create or replace procedure sp_setlangalias
60        @language varchar(255),
61        @alias varchar(255)
62    as
63    
64        declare @msg varchar(1024)
65    
66        declare @returncode int
67        declare @HA_CERTIFIED tinyint /* Is the SP HA certified ? */
68        declare @retstat int
69        declare @maxlen int
70        declare @nullarg char(1)
71        declare @dummy int
72        declare @status int
73        declare @gp_enabled int
74    
75    
76    
77    
78    
79        select @HA_CERTIFIED = 0
80    
81    
82    
83    
84        /* check to see if we are using HA specific SP for a HA enabled server */
85        exec @retstat = sp_ha_check_certified 'sp_setlangalias', @HA_CERTIFIED
86        if (@retstat != 0)
87            return (1)
88    
89        /*
90        **  Check to see that the @alias is valid.
91        */
92        select @maxlen = length from syscolumns
93        where id = object_id("syslanguages") and name = "alias"
94    
95        if (char_length(@alias) > @maxlen)
96        begin
97            /*
98            ** 17240, "'" + @alias + "' is not a valid name."
99            */
100           raiserror 17240, @alias
101           return (1)
102       end
103   
104       /*
105       **  If we're in a transaction, disallow this since it might make recovery
106       **  impossible.
107       */
108       if @@trancount > 0
109       begin
110           /*
111           ** 17260, "Can't run %1! from within a transaction."
112           */
113           raiserror 17260, "sp_setlangalias"
114           return (1)
115       end
116       else
117       begin
118           set chained off
119       end
120   
121       set transaction isolation level 1
122   
123       /* 
124       ** If granular permissions is not enabled then sa_role is required.
125       ** If granular permissions is enabled then 'manage server' permission is 
126       ** required.  proc_role and proc_auditperm will also do auditing
127       ** if required. Both will also print error message if required.
128       */
129   
130       select @nullarg = NULL
131       execute @status = sp_aux_checkroleperm "sa_role",
132           "manage server", @nullarg, @gp_enabled output
133   
134       /* For Auditing */
135       if (@gp_enabled = 0)
136       begin
137           if (proc_role("sa_role") = 0)
138               return 1
139       end
140       else
141       begin
142           select @dummy = proc_auditperm("manage server", @status)
143       end
144   
145       if (@status != 0)
146           return 1
147   
148       /*  Check to see if the language exists. */
149       select @returncode = 0
150       execute @returncode = sp_validlang @language
151       if @returncode != 0
152       begin
153           /*
154           ** 17201, "'%1!' is not an official language name from Syslanguages."
155           */
156           raiserror 17201, @language
157           return 1
158       end
159   
160       /*  Check to see if the alias exists. */
161       select @returncode = 0
162       execute @returncode = sp_validaltlang @alias
163       if @returncode = 0
164       begin
165           /*
166           ** 17253, "'%1!' alias already exists in Syslanguages."
167           */
168           raiserror 17253, @alias
169           return 1
170       end
171   
172   
173   
174       /* Reset the alternate language name. */
175       update master.dbo.syslanguages
176       set alias = @alias
177       where name = @language
178   
179       /* If the update failed, say so. */
180       if (@@error != 0)
181       begin
182           /*
183           ** 17810, "Language alias not changed."
184           */
185           raiserror 17810
186           goto clean_all
187       end
188   
189   
190   
191       /*
192       ** 17811, "Language alias reset."
193       */
194       exec sp_getmessage 17811, @msg output
195       print @msg
196       return (0)
197   
198   clean_all:
199   
200       return (1)
201   
202   


exec sp_procxmode 'sp_setlangalias', 'AnyMode'
go

Grant Execute on sp_setlangalias 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) 176
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 93
 MGTP 3 Grant to public master..syslanguages  
 MGTP 3 Grant to public sybsystemprocs..sp_setlangalias  
 MGTP 3 Grant to public sybsystemprocs..syscolumns  
 MNER 3 No Error Check should check return value of exec 194
 MUCO 3 Useless Code Useless Brackets 86
 MUCO 3 Useless Code Useless Brackets 87
 MUCO 3 Useless Code Useless Brackets 95
 MUCO 3 Useless Code Useless Brackets 101
 MUCO 3 Useless Code Useless Brackets 114
 MUCO 3 Useless Code Useless Brackets 135
 MUCO 3 Useless Code Useless Brackets 137
 MUCO 3 Useless Code Useless Brackets 145
 MUCO 3 Useless Code Useless Brackets 180
 MUCO 3 Useless Code Useless Brackets 196
 MUCO 3 Useless Code Useless Brackets 200
 MUPK 3 Update column which is part of a PK or unique index alias 176
 QAFM 3 Var Assignment from potentially many rows 92
 QISO 3 Set isolation level 121
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
93
 VNRD 3 Variable is not read @dummy 142
 MTR1 2 Metrics: Comments Ratio Comments: 64% 59
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 11dec - 6exi + 2 59
 MTR3 2 Metrics: Query Complexity Complexity: 64 59

DATA PROPAGATION detailed
ColumnWritten To
@aliassyslanguages.alias  

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