Database | Proc | Application | Created | Links |
sybsystemprocs | sp_defaultlanguage ![]() | ![]() | 31 Aug 14 | Defects 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 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 declare @sa_role int /* has sa role */ 83 declare @sso_role int /* has sso_role */ 84 85 declare @log_for_rep int 86 declare @db_rep_level_all int 87 declare @db_rep_level_none int 88 declare @db_rep_level_l1 int 89 declare @lt_rep_get_failed int 90 91 /* 92 ** Initialize some constants 93 */ 94 select @db_rep_level_all = - 1, 95 @db_rep_level_none = 0, 96 @db_rep_level_l1 = 1, 97 @lt_rep_get_failed = - 2 98 99 select @HA_CERTIFIED = 0 100 101 select @sa_role = charindex("sa_role", show_role()), 102 @sso_role = charindex("sso_role", show_role()) 103 104 105 106 /* check to see if we are using HA specific SP for a HA enabled server */ 107 exec @retstat = sp_ha_check_certified 'sp_defaultlanguage', @HA_CERTIFIED 108 if (@retstat != 0) 109 return (1) 110 111 /* 112 ** Do not allow this system procedure to be run from within a transaction 113 ** to avoid creating a multi-database transaction where the 'master' 114 ** database is not the co-ordinating database. 115 */ 116 if @@trancount > 0 117 begin 118 /* 119 ** 17260, "Can't run %1! from within a transaction." 120 */ 121 raiserror 17260, "sp_defaultlanguage" 122 return (1) 123 end 124 else 125 begin 126 set chained off 127 end 128 129 set transaction isolation level 1 130 131 /* 132 ** Get the replication status of the 'master' database 133 */ 134 select @log_for_rep = getdbrepstat(1) 135 if (@log_for_rep = @lt_rep_get_failed) 136 begin 137 raiserror 18409, "getdbrepstat" 138 return (1) 139 end 140 141 /* 142 ** Convert the replication status to a boolean 143 */ 144 if (@log_for_rep != @db_rep_level_none) 145 select @log_for_rep = 1 146 else 147 select @log_for_rep = 0 148 149 /* 150 ** If we are logging this system procedure for replication, we must be in 151 ** the 'master' database to avoid creating a multi-database transaction 152 ** which could make recovery of the 'master' database impossible. 153 */ 154 if (@log_for_rep = 1) and (db_name() != "master") 155 begin 156 raiserror 18388, "sp_defaultlanguage" 157 return (1) 158 end 159 160 /* 161 ** Check to see that the @language is valid. 162 */ 163 if @language is not null 164 begin 165 select @returncode = 0 166 execute @returncode = sp_validlang @language 167 if @returncode != 0 168 begin 169 if @language != "us_english" 170 begin 171 /* 172 ** 17201, "'%1!' is not a valid official language name." ** 173 */ 174 raiserror 17201, @language 175 return @returncode 176 end 177 end 178 end 179 180 /* 181 ** Make sure the login already exist. 182 */ 183 if not exists (select * 184 from master.dbo.syslogins 185 where name = @loginame 186 and (status & 512) != 512) /* not LOGIN PROFILE */ 187 begin 188 /* 189 ** 17451, "This user does not exist. Run sp_addlogin to add this user in." 190 */ 191 raiserror 17451 192 return 1 193 end 194 195 /* 196 ** Only the Account Owner or 197 ** Accounts with SA role or SSO role can execute it. 198 ** proc_role will also do auditing if required and 199 ** will also print error message if required. 200 ** 201 */ 202 if ((suser_id() != suser_id(@loginame)) and 203 (@sa_role = 0) and (@sso_role = 0)) 204 begin 205 select @dummy = proc_role("sa_role") 206 select @dummy = proc_role("sso_role") 207 return (1) 208 end 209 else 210 begin 211 if (@sa_role > 0) 212 begin 213 select @dummy = proc_role("sa_role") 214 end 215 if (@sso_role > 0) 216 begin 217 select @dummy = proc_role("sso_role") 218 end 219 end 220 221 222 223 if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1)) 224 begin tran rs_logexec 225 226 227 228 /* 229 ** Set the default language for this user. 230 */ 231 232 update master.dbo.syslogins 233 set language = @language 234 where name = @loginame 235 236 if (@@rowcount = 1) 237 begin 238 239 240 241 if (@log_for_rep = 1) 242 begin 243 /* 244 ** If the 'master' database is marked for replication, the 245 ** T-SQL built-in 'logexec()' will log for replication the 246 ** execution instance of this system procedure. Otherwise, 247 ** the T-SQL built-in 'logexec()' is a no-op. 248 */ 249 if (logexec(1) != 1) 250 begin 251 raiserror 17756, "sp_defaultlanguage", "master" 252 goto clean_all 253 end 254 end 255 256 if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1)) 257 commit tran rs_logexec 258 259 /* 260 ** 17452, "%1!'s default language has been changed to %2!." 261 */ 262 exec sp_getmessage 17452, @msg output 263 print @msg, @loginame, @language 264 select @returncode = 0 265 end 266 else 267 begin 268 /* 269 ** 17453, "Error in changing the default language." 270 */ 271 272 if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1)) 273 rollback tran rs_logexec 274 275 raiserror 17453 276 select @returncode = 1 277 end 278 return (@returncode) 279 280 clean_all: 281 if ((@log_for_rep = 1) or (@HA_CERTIFIED = 1)) 282 rollback tran rs_logexec 283 return (1) 284 285
exec sp_procxmode 'sp_defaultlanguage', 'AnyMode' go Grant Execute on sp_defaultlanguage to public go
DEPENDENCIES |
PROCS AND TABLES USED calls proc sybsystemprocs..sp_ha_check_certified ![]() reads table tempdb..sysobjects (1) ![]() calls proc sybsystemprocs..sp_getmessage ![]() reads table master..sysmessages (1) ![]() reads table master..syslanguages (1) ![]() reads table sybsystemprocs..sysusermessages ![]() calls proc sybsystemprocs..sp_validlang ![]() reads table master..syslanguages (1) ![]() calls proc sybsystemprocs..sp_validlang ![]() read_writes table master..syslogins (1) ![]() CALLERS called by proc sybsystemprocs..sp_modifylogin ![]() |