DatabaseProcApplicationCreatedLinks
sybsystemprocssp_defaultlanguage  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/defaultlanguage */
4     
5     /*
6     ** Generated by spgenmsgs.pl on Thu Feb  2 00:39:15 2006 
7     */
8     /*
9     ** raiserror Messages for defaultlanguage [Total 7]
10    **
11    ** 17201, "'%1!' is not an official language name from syslanguages."
12    ** 17260, "Can't run %1! from within a transaction."
13    ** 17451, "This user does not exist.  Run sp_addlogin to add this user in."
14    ** 17453, "Error in changing the default language."
15    ** 17756, "The execution of the stored procedure '%1!' in database '%2!' was aborted because there was an error in writing the replication log record."
16    ** 18388, "You must be in the master database in order to run '%1!'."
17    ** 18409, "The built-in function %1! failed. Please see the other messages printed along with this message."
18    */
19    /*
20    ** sp_getmessage Messages for defaultlanguage [Total 3]
21    **
22    ** 17452, "%1!'s default language has been changed to %2!."
23    ** 18773, "HA_LOG: HA consistency check failure in stored procedure '%1!' on the companion server '%2!'."
24    ** 18778, "Unable to find login '%1!' with id '%2!' in syslogins."
25    */
26    /*
27    ** End spgenmsgs.pl output.
28    */
29    
30    /* 
31    ** IMPORTANT: Please read the following instructions before
32    **   making changes to this stored procedure.
33    **
34    **	To make this stored procedure compatible with High Availability (HA),
35    **	changes to certain system tables must be propagated 
36    **	to the companion server under some conditions.
37    **	The tables include (but are not limited to):
38    **		syslogins, sysservers, sysattributes, systimeranges,
39    **		sysresourcelimits, sysalternates, sysdatabases,
40    **		syslanguages, sysremotelogins, sysloginroles,
41    **		sysalternates (master DB only), systypes (master DB only),
42    **		sysusers (master DB only), sysprotects (master DB only)
43    **	please refer to the HA documentation for detail.
44    **
45    **	Here is what you need to do: 
46    **	For each insert/update/delete statement, add three sections to
47    **	-- start HA transaction prior to the statement
48    **	-- add the statement
49    **	-- add HA synchronization code to propagate the change to the companion
50    **
51    **	For example, if you are adding 
52    **		insert master.dbo.syslogins ......
53    **	the code should look like:
54    **	1. Before that SQL statement:
55    **		
56    **	2. Now, the SQL statement:
57    **		insert master.dbo.syslogins ......
58    **	3. Add a HA synchronization section right after the SQL statement:
59    **		
60    **
61    **	You may need to do similar change for each built-in function you
62    **	want to add.
63    **
64    **	Finally, add a separate part at a place where it can not
65    **	be reached by the normal execution path:
66    **	clean_all:
67    **		
68    **		return (1)
69    */
70    
71    create or replace procedure sp_defaultlanguage
72        @loginame varchar(30), /* login name of the user */
73        @language varchar(30) = NULL /* default language for the new user */
74    as
75    
76        declare @msg varchar(1024)
77        declare @returncode int
78        declare @suid int
79        declare @HA_CERTIFIED tinyint /* Is the SP HA certified ? */
80        declare @retstat int
81        declare @dummy int
82    
83        declare @log_for_rep int
84        declare @db_rep_level_all int
85        declare @db_rep_level_none int
86        declare @db_rep_level_l1 int
87        declare @lt_rep_get_failed int
88        declare @nullarg char(1)
89        declare @status1 int
90        declare @status2 int
91        declare @gp_enabled int
92    
93        select @status1 = 1
94        select @status2 = 1
95    
96        /*
97        ** Initialize some constants
98        */
99        select @db_rep_level_all = - 1,
100           @db_rep_level_none = 0,
101           @db_rep_level_l1 = 1,
102           @lt_rep_get_failed = - 2
103   
104       select @HA_CERTIFIED = 0
105   
106   
107   
108   
109       /* check to see if we are using HA specific SP for a HA enabled server */
110       exec @retstat = sp_ha_check_certified 'sp_defaultlanguage', @HA_CERTIFIED
111       if (@retstat != 0)
112           return (1)
113   
114       /*
115       ** Do not allow this system procedure to be run from within a transaction
116       ** to avoid creating a multi-database transaction where the 'master'
117       ** database is not the co-ordinating database.
118       */
119       if @@trancount > 0
120       begin
121           /*
122           ** 17260, "Can't run %1! from within a transaction."
123           */
124           raiserror 17260, "sp_defaultlanguage"
125           return (1)
126       end
127       else
128       begin
129           set chained off
130       end
131   
132       set transaction isolation level 1
133   
134       /*
135       ** Get the replication status of the 'master' database
136       */
137       select @log_for_rep = getdbrepstat(1)
138       if (@log_for_rep = @lt_rep_get_failed)
139       begin
140           raiserror 18409, "getdbrepstat"
141           return (1)
142       end
143   
144       /*
145       ** Convert the replication status to a boolean
146       */
147       if (@log_for_rep != @db_rep_level_none)
148           select @log_for_rep = 1
149       else
150           select @log_for_rep = 0
151   
152       /*
153       ** If we are logging this system procedure for replication, we must be in
154       ** the 'master' database to avoid creating a multi-database transaction
155       ** which could make recovery of the 'master' database impossible.
156       */
157       if (@log_for_rep = 1) and (db_name() != "master")
158       begin
159           raiserror 18388, "sp_defaultlanguage"
160           return (1)
161       end
162   
163       /* 
164       **  Check to see that the @language is valid.
165       */
166       if @language is not null
167       begin
168           select @returncode = 0
169           execute @returncode = sp_validlang @language
170           if @returncode != 0
171           begin
172               if @language != "us_english"
173               begin
174                   /*
175                   ** 17201, "'%1!' is not a valid official language name." **
176                   */
177                   raiserror 17201, @language
178                   return @returncode
179               end
180           end
181       end
182   
183       /*
184       **  Make sure the login already exist.
185       */
186       if not exists (select *
187               from master.dbo.syslogins
188               where name = @loginame
189                   and (status & 512) != 512) /* not LOGIN PROFILE */
190       begin
191           /*
192           ** 17451, "This user does not exist.  Run sp_addlogin to add this user in."
193           */
194           raiserror 17451
195           return 1
196       end
197   
198       /*
199       **  If granular permissions is not enabled, 
200       **  Only the Account Owner or accounts with sa_role or sso_role
201       **  can execute it.  If granular permissions is enabled then users with 
202       ** 'manage any login' permission can execute it.
203       */
204       if (suser_id() != suser_id(@loginame))
205       begin -- {
206           select @nullarg = NULL
207           execute @status1 = sp_aux_checkroleperm "sa_role", "manage any login",
208               @nullarg, @gp_enabled output
209   
210           if (@gp_enabled = 0)
211           begin
212               if (@status1 != 0)
213               begin
214                   execute @status2 = sp_aux_checkroleperm "sso_role",
215                       @nullarg, @nullarg, @gp_enabled output
216   
217                   if (@status2 != 0)
218                   begin
219                       /* 
220                       ** proc_role() will raise permission errors
221                       ** and send audit records to the audit trail.
222                       */
223                       select @dummy = proc_role("sa_role")
224                       select @dummy = proc_role("sso_role")
225                       return (1)
226                   end
227               end
228               if (@status1 = 0)
229                   select @dummy = proc_role("sa_role")
230   
231               if (@status2 = 0)
232                   select @dummy = proc_role("sso_role")
233           end
234           else
235           begin
236               select @dummy = proc_auditperm("manage any login",
237                       @status1)
238               if (@status1 != 0)
239                   return 1
240           end
241       end --}
242   
243   
244   
245       if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1))
246           begin tran rs_logexec
247   
248   
249   
250       /*
251       **  Set the default language for this user.
252       */
253   
254       update master.dbo.syslogins
255       set language = @language
256       where name = @loginame
257   
258       if (@@rowcount = 1)
259       begin
260   
261   
262   
263           if (@log_for_rep = 1)
264           begin
265               /*
266               ** If the 'master' database is marked for replication, the
267               ** T-SQL built-in 'logexec()' will log for replication the
268               ** execution instance of this system procedure.  Otherwise,
269               ** the T-SQL built-in 'logexec()' is a no-op.
270               */
271               if (logexec(1) != 1)
272               begin
273                   raiserror 17756, "sp_defaultlanguage", "master"
274                   goto clean_all
275               end
276           end
277   
278           if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1))
279               commit tran rs_logexec
280   
281           /*
282           ** 17452, "%1!'s default language has been changed to %2!."
283           */
284           exec sp_getmessage 17452, @msg output
285           print @msg, @loginame, @language
286           select @returncode = 0
287       end
288       else
289       begin
290           /*
291           ** 17453, "Error in changing the default language."
292           */
293   
294           if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1))
295               rollback tran rs_logexec
296   
297           raiserror 17453
298           select @returncode = 1
299       end
300       return (@returncode)
301   
302   clean_all:
303       if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1))
304           rollback tran rs_logexec
305       return (1)
306   
307   


exec sp_procxmode 'sp_defaultlanguage', 'AnyMode'
go

Grant Execute on sp_defaultlanguage to public
go
DEFECTS
 MCTR 4 Conditional Begin Tran or Commit Tran 246
 MCTR 4 Conditional Begin Tran or Commit Tran 279
 MGTP 3 Grant to public master..syslogins  
 MGTP 3 Grant to public sybsystemprocs..sp_defaultlanguage  
 MNER 3 No Error Check should check @@error after update 254
 MNER 3 No Error Check should check return value of exec 284
 MUCO 3 Useless Code Useless Brackets 111
 MUCO 3 Useless Code Useless Brackets 112
 MUCO 3 Useless Code Useless Brackets 125
 MUCO 3 Useless Code Useless Brackets 138
 MUCO 3 Useless Code Useless Brackets 141
 MUCO 3 Useless Code Useless Brackets 147
 MUCO 3 Useless Code Useless Brackets 160
 MUCO 3 Useless Code Useless Brackets 204
 MUCO 3 Useless Code Useless Brackets 210
 MUCO 3 Useless Code Useless Brackets 212
 MUCO 3 Useless Code Useless Brackets 217
 MUCO 3 Useless Code Useless Brackets 225
 MUCO 3 Useless Code Useless Brackets 228
 MUCO 3 Useless Code Useless Brackets 231
 MUCO 3 Useless Code Useless Brackets 238
 MUCO 3 Useless Code Useless Brackets 245
 MUCO 3 Useless Code Useless Brackets 258
 MUCO 3 Useless Code Useless Brackets 263
 MUCO 3 Useless Code Useless Brackets 271
 MUCO 3 Useless Code Useless Brackets 278
 MUCO 3 Useless Code Useless Brackets 294
 MUCO 3 Useless Code Useless Brackets 300
 MUCO 3 Useless Code Useless Brackets 303
 MUCO 3 Useless Code Useless Brackets 305
 QISO 3 Set isolation level 132
 VNRD 3 Variable is not read @db_rep_level_all 99
 VNRD 3 Variable is not read @db_rep_level_l1 101
 VNRD 3 Variable is not read @gp_enabled 215
 VNRD 3 Variable is not read @dummy 236
 VUNU 3 Variable is not used @suid 78
 MSUB 2 Subquery Marker 186
 MTR1 2 Metrics: Comments Ratio Comments: 56% 71
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 24 = 30dec - 8exi + 2 71
 MTR3 2 Metrics: Query Complexity Complexity: 120 71

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

CALLERS
called by proc sybsystemprocs..sp_modifylogin