DatabaseProcApplicationCreatedLinks
sybsystemprocssp_setrepproc  31 Aug 14Defects Dependencies

1     
2     /* Sccsid = "@(#) generic/sproc/setreplicate 155.1 11/10/94" */
3     /*
4     ** Messages for "sp_setreplicate"	17960
5     **
6     ** 17230, "Only the System Administrator (SA) or the Database Owner
7     **	   (dbo) may execute this stored procedure."
8     ** 17432, "false"
9     ** 17756, "The execution of the stored procedure '%1!' in database
10    **         '%2!' was aborted because there was an error in writing the
11    **         replication log record."
12    ** 17962, "The replication status for '%1!' is already set to %2!.
13    **	   Replication status for '%3!' does not change."
14    ** 17963, "A object with the same name, but owned by a different user
15    **	   is already being replicated.  The object '%1!' cannot be
16    **	   replicated."
17    ** 17965, "The replication status for '%1!' is currently %2!."
18    ** 17966, "Due to system failure, the replication status for '%1!' has
19    **	   not been changed."
20    ** 18418, "Only the System Administrator (SA), the Database Owner (dbo) or
21    **	   a user with REPLICATION authorization may execute this stored
22    **	   procedure."
23    ** 17968, "The built-in function logschema() failed for '%1!'."
24    ** 18104, "table"
25    ** 18105, "function"
26    ** 18106, "Stored Procedure must be in the current database."
27    ** 18107, "Stored Procedure '%1!' does not exist in this database."
28    ** 18108, "Usage: sp_setrepproc [proc_name [, {'false' | 'table' | 
29    			{'function' [,{'log_current' | 'log_sproc'}]}}]]
30    ** 18688, "Stored procedures with object parameters cannot be marked for
31    **	   replication yet at this time. Instead, use sp_setreptable to
32    **	   mark the invidual tables for replication. The replication status
33    **	   for '%1!' is not changed."
34    ** 18846, "Object name cannot be null when other parameters are non null.
35    ** 18847, "The log mode for '%1!' is currently %2!."
36    ** 18848, "The replication status for '%1!' is already set to %2!,
37    **	   with log mode set to %3!. Replication status for '%4!'
38    **	   does not change.
39    ** 18849, "The log mode is set to %1!."
40    */
41    
42    create procedure sp_setrepproc
43        @replicate_name varchar(767) = NULL, /* obj we want to mark as replicate */
44        @setflag varchar(20) = NULL, /* set or unset the replicate status. */
45        @logflag varchar(20) = NULL /* log EXECBEGIN in the current
46    					** database or in the sproc's database.
47    					*/
48    as
49    
50        declare @sysstat1_curr int /* current sysobjects.sysstat.	*/
51        declare @sysstat1_new int /* new sysobjects.sysstat.	*/
52        declare @sysstat1_mask int /* mask for sysobjects.sysstat.	*/
53        declare @sysstat2_curr int /* current sysobjects.sysstat2.	*/
54        declare @sysstat2_new int /* new sysobjects.sysstat2.	*/
55        declare @sysstat2_mask int /* mask for sysobjects.sysstat2.*/
56        declare @rep_constant int /* O_REPLICATED (0x8000) bit in
57        ** bit in sysobjects.sysstat.	*/
58        declare @sub_constant int /* O_PROC_SUBSCRIBABLE (0x40)
59        ** bit in sysobjects.sysstat.	*/
60        declare @log_constant int /* O2_REP_LOG_SPROC (0x800000)
61        ** bit in sysobjects.sysstat2.	*/
62        declare @setrep_flags int /* repflags parameter passed to
63        ** setrepstatus().		*/
64        declare @db varchar(255) /* db of object. */
65        declare @owner varchar(255) /* owner of object. */
66        declare @object varchar(255) /* object's name. */
67        declare @true varchar(30) /* "TRUE" */
68        declare @table varchar(30) /* "TABLE" */
69        declare @function varchar(30) /* "FUNCTION" */
70        declare @false varchar(30) /* "FALSE" */
71        declare @log_current varchar(30) /* "LOG_CURRENT" */
72        declare @log_sproc varchar(30) /* "LOG_SPROC" */
73        declare @msg varchar(1024) /* Used to get Error messages */
74        declare @tmpstr varchar(20) /* Used to display replication type
75        ** (table/function) in messages.
76        */
77        declare @logstr varchar(20) /* Used to display logmode in messages.
78        */
79        declare @procval int
80        declare @objid int /* Id of the procedure to be marked */
81        declare @log_aft_img int /* log after image schema when replication
82        ** status is turned on, or the replication
83        ** status is already on, but the sproc
84        ** replication type (function/table), or
85        ** logging mode (sproc/current) changes.
86        */
87        declare @log_bef_img int /* log before image schema when replication
88        ** status is turned off.
89        */
90        declare @user_tran int /* are we inside a user tran? */
91        declare @after_image int /* log the after image of the schema */
92        declare @mod_versionts int /* modify version timestamp after logging
93        ** the schema
94        */
95        declare @dbname varchar(30)
96        declare @xtype_token int /* Type for object parameters. */
97        declare @textlocator_token int /* Type for LOB TEXT locator or
98        ** parameter 
99        */
100       declare @imagelocator_token int /* Type for LOB IMAGE locator or
101       ** parameter 
102       */
103       declare @unitextlocator_token int /* Type for LOB UNITEXT locator or
104       ** parameter 
105       */
106       declare @setrep_replicate int /* setrepstatus() LT_SETREP_REPLICATE
107       ** flag.   */
108       declare @setrep_subscribable int /* setrepstatus() LT_SETREP_SUBSCRIBABLE
109       ** flag.*/
110       declare @setrep_log_sproc int /* setrepstatus() LT_SETREP_LOG_SPROC
111       ** flag. */
112   
113       if @@trancount = 0
114       begin
115           set transaction isolation level 1
116           set chained off
117       end
118   
119       if (@@trancount > 0)
120           select @user_tran = 1
121       else
122           select @user_tran = 0
123   
124       /*
125       ** Define sysobject sysstat and sysstat2 constants.
126       **
127       ** O_REPLICATED bit flag in sysstat is 0x8000 (-32768)
128       ** O_PROC_SUBSCRIBABLE bit flag in sysstat flag is 0x0040 (64)
129       ** O2_REP_LOG_SPROC bit flag in sysstat2 is 0x800000 (8388608).
130       ** See objects.h for bit flag defines.
131       */
132       select @rep_constant = - 32768,
133           @sub_constant = 64,
134           @log_constant = 8388608
135   
136   
137       /* set @log_aft_img and @log_bef_img to false initially */
138       select @log_aft_img = 0,
139           @log_bef_img = 0
140   
141       /* Datatype value for objects. */
142       select @xtype_token = 36
143   
144       /* 
145       ** Column type value for LOB, stands for either of these datatypes:
146       ** text = 35, image = 34, unitext = 174.  
147       */
148       select @textlocator_token = 169
149       select @imagelocator_token = 170
150       select @unitextlocator_token = 171
151   
152       /*
153       ** Initialize ssetrepstatus() repflags constants.
154       ** See logtrans.h for bit flag defines.
155       */
156       select @setrep_replicate = 1, /* LT_SETREP_REPLICATE	  0x00000001 */
157           @setrep_subscribable = 2, /* LT_SETREP_SUBSCRIBABLE 0x00000002 */
158           @setrep_log_sproc = 4 /* LT_SETREP_LOG_SPROC    0x00000004 */
159   
160       /*
161       ** Initialize 'true' and 'false' strings
162       */
163       /* 18104, "table" */
164       exec sp_getmessage 18104, @table out
165       /* 18105, "function" */
166       exec sp_getmessage 18105, @function out
167       /* 17432, "false" */
168       exec sp_getmessage 17432, @false out
169       /* 18844, "log_current" */
170       exec sp_getmessage 18844, @log_current out
171       /* 18845, "log_sproc" */
172       exec sp_getmessage 18845, @log_sproc out
173   
174       /*
175       ** If we are invoked with no parameters, then just print out all procedures
176       ** which are marked for replication.  The 'select' statement is heavily
177       ** based upon the one found in 'sp_help'.
178       */
179       if (@replicate_name is NULL and @setflag is NULL and @logflag is NULL)
180       begin
181           select
182               Name = o.name,
183               Type = convert(char(14), m1.description),
184               Mode = convert(char(14), m2.description)
185           into #setrepproc1rs
186           from
187               sysobjects o,
188               master.dbo.sysmessages m1,
189               master.dbo.sysmessages m2
190           where
191               o.type = "P"
192               and isnull(m1.langid, 0) = @@langid
193               and isnull(m2.langid, 0) = @@langid
194               and (o.sysstat & @rep_constant) = @rep_constant
195               and (((o.sysstat & @sub_constant) = @sub_constant
196                       and m1.error = 18105) /* function */
197                   or ((o.sysstat & @sub_constant) = 0
198                       and m1.error = 18104)) /* table */
199               and (((o.sysstat2 & @log_constant) = @log_constant
200                       and m2.error = 18845) /* log_sproc */
201                   or ((o.sysstat2 & @log_constant) = 0
202                       and m2.error = 18844)) /* log_current */
203           exec sp_autoformat @fulltabname = #setrepproc1rs,
204               @selectlist = "Name, Type,'Log Mode'= Mode"
205           drop table #setrepproc1rs
206           return (0)
207       end
208   
209       /*
210       ** Don't allow replicate name to be null, with non-null setflag and/or logflag.
211       */
212       if (@replicate_name is NULL) and (@setflag is not NULL or @logflag is not NULL)
213       begin
214           /*
215           ** 18846, "Object name cannot be null when other parameters
216           **	   are non null."
217           */
218           raiserror 18846
219           return (1)
220       end
221   
222       /*
223       ** Crack the name into its corresponding pieces.
224       */
225       execute sp_namecrack @replicate_name,
226           @db = @db output,
227           @owner = @owner output,
228           @object = @object output
229   
230       /*
231       ** Make sure that the object is in the current database.
232       */
233       if (@db is not NULL and @db != db_name())
234       begin
235           /*
236           ** 18106, "Procedure must be in the current database."
237           */
238           raiserror 18106
239           return (1)
240       end
241   
242       /*
243       **  Make sure that the object actually exists.
244       */
245       select @objid = object_id(@replicate_name)
246   
247       if (@objid is NULL)
248           or (not exists (select name from sysobjects where
249                       id = @objid and
250                       type = "P"
251                   ))
252       begin
253           /*
254           ** 18107, "Procedure does not exist in this database."
255           */
256           raiserror 18107, @replicate_name
257           return (1)
258       end
259   
260       /*
261       ** If the @setflag and @logflag are NULL, then we are only interested in the
262       ** current replication status of the specified object.
263       */
264       if (@setflag is NULL and @logflag is NULL)
265       begin
266           /*
267           ** Get the sproc's current sysstat and sysstat2 from sysobjects
268           ** Hold a read lock on sysobjects so that the statuses cannot be
269           ** changed until we're done.
270           */
271           select
272               @sysstat1_curr = sysstat,
273               @sysstat2_curr = sysstat2
274           from
275               sysobjects holdlock
276           where
277               id = @objid
278   
279           /*
280           ** If sproc is replicated, get replication type and log mode.
281           */
282           if (@sysstat1_curr & @rep_constant) = @rep_constant
283           begin
284               /* Is this a subscribable function?. */
285               if (@sysstat1_curr & @sub_constant) = @sub_constant
286               begin
287                   select @tmpstr = @function
288               end
289               else
290               begin
291                   select @tmpstr = @table
292               end
293   
294               /* Is log mode log_sproc?. */
295               if (@sysstat2_curr & @log_constant) = @log_constant
296               begin
297                   select @logstr = @log_sproc
298               end
299               else
300               begin
301                   select @logstr = @log_current
302               end
303           end
304   
305           /* Otherwise, sproc is not replicated. */
306           else
307           begin
308               select @tmpstr = @false
309           end
310   
311   
312           /*
313           ** 17965 "The replication status for '%1!' is currently %2!."
314           */
315           exec sp_getmessage 17965, @msg output
316           print @msg, @replicate_name, @tmpstr
317   
318           /* If the sproc is replicated, display the log mode. */
319           if (@tmpstr != @false)
320           begin
321               /*
322               ** 18847 "The log mode for '%1!' is currently %2!"
323               */
324               exec sp_getmessage 18847, @msg output
325               print @msg, @replicate_name, @logstr
326           end
327           return (0)
328       end
329   
330       /*
331       ** You must be SA, dbo or have REPLICATION role to execute this
332       ** sproc.
333       */
334       if (user_id() != 1)
335       begin
336           if (charindex("sa_role", show_role()) = 0 and
337                   charindex("replication_role", show_role()) = 0)
338           begin
339               /*
340               ** 18418, "Only the System Administrator (SA), the
341               **	   Database Owner (dbo) or a user with REPLICATION
342               **	   authorization may execute this stored
343               **	   procedure."
344               */
345               raiserror 18418
346               return (1)
347           end
348           else
349           begin
350               /*
351               ** Call proc_role() with each role that the user has
352               ** in order to send the success audit records.
353               ** Note that this could mean 1 or 2 audit records.
354               */
355               if (charindex("sa_role", show_role()) > 0)
356                   select @procval = proc_role("sa_role")
357               if (charindex("replication_role", show_role()) > 0)
358                   select @procval = proc_role("replication_role")
359           end
360       end
361   
362       /*
363       ** At this point, we know that the sproc is not being invoked for
364       ** informational purposes. 
365       */
366   
367       /*
368       ** Disallow any log mode when the replication status is not "function".
369       ** The default value will be applied.
370       */
371       if (lower(@setflag) not in ("function", @function)) and (@logflag is not NULL)
372       begin
373           /*
374           ** 18108 "Usage: sp_setrepproc [proc_name [, {'false' | 'table' |
375           {'function' [,{'log_current' | 'log_sproc'}]}}]]
376           */
377           raiserror 18108
378           return (1)
379       end
380   
381       /*
382       ** Replace any null parameters by the default value for that parameter.
383       */
384   
385       /* If @setflag is null, default is function. */
386       if (@setflag is NULL)
387       begin
388           select @setflag = @function
389       end
390   
391       /* If @logflag is null, default is log_sproc. */
392       if (@logflag is NULL)
393       begin
394           select @logflag = @log_sproc
395       end
396   
397       /*
398       ** Check for a valid setname parameter
399       */
400       if (lower(@setflag) not in ("function", "table", "false",
401                   @function, @table, @false))
402       begin
403           /*
404           ** 18108 "Usage: sp_setrepproc [proc_name [, {'false' | 'table' |
405           {'function' [,{'log_current' | 'log_sproc'}]}}]]
406           */
407           raiserror 18108
408           return (1)
409       end
410   
411       /*
412       ** Check for a valid logflag parameter
413       */
414       if (lower(@logflag) not in ("log_sproc", "log_current",
415                   @log_sproc, @log_current))
416       begin
417           /*
418           ** 18108 "Usage: sp_setrepproc [proc_name [, {'false' | 'table' |
419           {'function' [,{'log_current' | 'log_sproc'}]}}]]
420           */
421           raiserror 18108
422           return (1)
423       end
424   
425       /*
426       ** Get the object's current status. Hold a read lock on sysobjects so that 
427       **	the statuses cannot be changed until we're done.
428       */
429       select
430           @sysstat1_curr = sysstat,
431           @sysstat2_curr = sysstat2
432       from
433           sysobjects holdlock
434       where
435           id = @objid
436   
437       /*
438       ** Perform the requested operation on the object.
439       */
440       if lower(@setflag) in ("false", @false)
441       begin
442           /* Is the replicate status bit even set? */
443           if (@sysstat1_curr & @rep_constant) = 0
444           begin
445               /*
446               ** 17962 "The replication status for '%1!' is already
447               **	  set to %2!.  Replication status for '%3!'
448               **	  does not change."
449               */
450               raiserror 17962, @replicate_name, @setflag, @replicate_name
451               return (1)
452           end
453   
454           /*
455           ** Initialize new values for sysstat, sysstat2 with all replication
456           ** related bit cleared. Initialize @setrep_flags to 0 to have
457           ** setrepstatus() clear all replication related bits.
458           ** Since the replication status is being turned off, we need to
459           ** set @log_bef_img to log the before image.
460           */
461           select @sysstat1_new = @sysstat1_curr &
462               ~ (@rep_constant | @sub_constant),
463               @sysstat2_new = @sysstat2_curr & ~ @log_constant,
464               @setrep_flags = 0,
465               @log_bef_img = 1
466       end
467   
468       /*
469       ** If @setflag is table or function, check the following..
470       **	- not already marked for replication
471       **	- another object with same name but different owner is
472       **	  already marked  for replication
473       **	- has no parameters of type object.
474       */
475       else if lower(@setflag) in ("table", @table, "function", @function)
476       begin
477           /* The @sysstat1 mask has all replication related bits set. */
478           select @sysstat1_mask = (@rep_constant | @sub_constant)
479   
480           /* Calculate the new the sysstat value based on @setflag. */
481           if lower(@setflag) in ("table", @table)
482           begin
483               /* New sysstat will have the replicate bit set. */
484               select @sysstat1_new = @rep_constant
485           end
486           else
487           begin
488               /*
489               ** New sysstat will have the replicate and the subscribable
490               ** bits set.
491               */
492               select @sysstat1_new = @rep_constant | @sub_constant
493           end
494   
495           /* The @sysstat2 mask has all replication related bits set. */
496           select @sysstat2_mask = @log_constant
497   
498           /* Calculate the new sysstat2 value. */
499           if lower(@logflag) in ("log_sproc", @log_sproc)
500           begin
501               /* New sysstat2 value will have the log_sproc bit set. */
502               select @sysstat2_new = @log_constant
503           end
504           else
505           begin
506               /* New sysstat2 value will have the log_sproc bit cleared. */
507               select @sysstat2_new = 0
508           end
509   
510           /*
511           ** If sysstat and sysstat2 are not going to change, raise 18848
512           */
513           if ((@sysstat1_curr & @sysstat1_mask) = @sysstat1_new)
514               and ((@sysstat2_curr & @sysstat2_mask) = @sysstat2_new)
515           begin
516               /*
517               ** 18848 "The replication status for '%1!' is already
518               **	  set to %2!, with log mode set to %3!. Replication
519               **	  status for '%4!' does not change."
520               */
521               raiserror 18848, @replicate_name, @setflag, @logflag,
522                   @replicate_name
523               return (1)
524           end
525   
526           /*
527           ** Make sure that no like object with the same name, but a
528           ** different owner, exists.  We need to do this because
529           ** the SQL Server does not send owner information along
530           ** with the object to the Replication Server.  This
531           ** restriction may be lifted in future versions.
532           */
533           if exists (select * from sysobjects
534                   where name = @object
535                       and id != @objid
536                       and (
537                           (type = "U ") /* user table */
538                           or
539                           (type = "P ") /* stored procedure */
540                       )
541                       and sysstat & @rep_constant != 0)
542           begin
543               /*
544               ** 17963 "An object with the same name, but owned by a
545               **	  different user is already being replicated.
546               **	  The object '%1!' cannot be replicated."
547               */
548               raiserror 17963, @replicate_name
549               return (1)
550           end
551   
552           /* Disallow sprocs with LOB or object parameters. */
553           if exists (select * from syscolumns
554                   where id = @objid
555                       and (
556                           type = @xtype_token
557                           or
558                           type = @textlocator_token
559                           or
560                           type = @imagelocator_token
561                           or
562                           type = @unitextlocator_token
563                       ))
564   
565           begin
566               /*
567               ** 18688, "Stored procedures with LOB or object parameters
568               **	   cannot be marked for replication yet at this time.
569               **	   Instead, use sp_setreptable to mark the invidual
570               **	   tables for replication. The replication status for
571               **	   '%1!' is not changed."
572               */
573               raiserror 18688, @replicate_name
574               return (1)
575           end
576   
577           /*
578           ** Calculate @sysstat1_new and @sysstat2_new values.
579           ** The new value is calculated by first clearing all replication
580           ** related bits, and then setting the desired bits.
581           */
582           select @sysstat1_new = (@sysstat1_curr & ~ @sysstat1_mask)
583               | @sysstat1_new
584           select @sysstat2_new = (@sysstat2_curr & ~ @sysstat2_mask)
585               | @sysstat2_new
586   
587           /*
588           ** Calcuate @setrep_flags based on the new sysstat1 and sysstat2 values.
589           ** This variable is the repflags parameter to be passed to
590           ** setrepstatus(), which will update the replication status of
591           ** an object in cache. Whatever bits that are cleared or set in
592           ** the object's sysobjects row, must also be cleared or set in the
593           ** cached version.
594           **
595           ** First initialize @setrep_flags to 0.
596           */
597           select @setrep_flags = 0
598   
599           /* Is the replication bit set?. */
600           if ((@sysstat1_new & @rep_constant) != 0)
601           begin
602               select @setrep_flags = @setrep_flags | @setrep_replicate
603           end
604   
605           /* Is the subscribable bit set?. */
606           if ((@sysstat1_new & @sub_constant) != 0)
607           begin
608               select @setrep_flags = @setrep_flags | @setrep_subscribable
609           end
610   
611           /* Is the log_sproc bit set?. */
612           if ((@sysstat2_new & @log_constant) != 0)
613           begin
614               select @setrep_flags = @setrep_flags | @setrep_log_sproc
615           end
616   
617           /*
618           ** The after image needs to be logged because replication is being
619           ** turned from off to on, or the sproc's replication type or
620           ** logging mode is being changed. Any of these changes require the
621           ** after image to be logged.
622           */
623           select @log_aft_img = 1
624       end
625   
626       /*
627       ** Update the object's sysstat and sysstat2 columns
628       **
629       ** IMPORTANT: This transaction name is significant and is used by
630       **            Replication Server
631       */
632       begin transaction rs_logexec
633   
634       select @objid = @objid
635   
636       /* log the schema first if we are turning off replication */
637       if (@log_bef_img = 1)
638       begin
639           /*
640           ** Initialize flags passed to logschema().
641           **   @after_image is 0 because this is not an after image.
642           **   @mod_versionts is 1 to modify the object's log version
643           **		timestamp.
644           **
645           ** logschema() will log the objects schema, before image in
646           ** this case.
647           */
648           select @after_image = 0,
649               @mod_versionts = 1
650           if (logschema(@objid, @user_tran, @after_image, @mod_versionts)
651                   != 1)
652           begin
653               /*
654               ** 17968 "The built-in function logschema() failed 
655               ** for '%1!'."
656               */
657               exec sp_getmessage 17968, @msg output
658               print @msg, @replicate_name
659   
660               rollback transaction rs_logexec
661               return (1)
662           end
663       end
664   
665       /* Update the sysobjects row. */
666       update sysobjects
667       set sysstat = @sysstat1_new,
668           sysstat2 = @sysstat2_new
669       where id = @objid
670   
671       /*
672       ** Log the after image only if we are in a user initiated transaction.
673       ** After images are needed to rebuild the object's schema in the case
674       ** or rollbacks and ddl-in-tran is on.
675       */
676       if ((@log_aft_img = 1) and (@user_tran = 1))
677       begin
678           /*
679           ** Initialize flags passed to logschema().
680           **    @after_image is 1 because this is an after image.
681           **    @mod_versionts is 0 because we don't want to change
682           **	the object's log version timestamp.
683           */
684           select @after_image = 1,
685               @mod_versionts = 0
686           if (logschema(@objid, @user_tran, @after_image, @mod_versionts)
687                   != 1)
688           begin
689               /*
690               ** 17968 "The built-in function logschema() failed 
691               ** for '%1!'."
692               */
693               exec sp_getmessage 17968, @msg output
694               print @msg, @replicate_name
695   
696               rollback transaction rs_logexec
697               return (1)
698           end
699       end
700   
701       /*
702       ** Update the object's status in cache.
703       */
704       if (setrepstatus(@objid, @setrep_flags) != 1)
705       begin
706           /*
707           ** 17966 "Due to system failure, the replication status
708           **	  for '%1!' has not been changed."
709           */
710           raiserror 17966, @replicate_name
711   
712           rollback transaction rs_logexec
713   
714           return (1)
715       end
716   
717       /*
718       ** Write the log record to replicate this invocation 
719       ** of the stored procedure.
720       */
721       if (logexec() != 1)
722       begin
723           /*
724           ** 17756, "The execution of the stored procedure '%1!'
725           ** 	   in database '%2!' was aborted because there
726           ** 	   was an error in writing the replication log
727           **	   record."
728           */
729           select @dbname = db_name()
730           raiserror 17756, "sp_setrepproc", @dbname
731   
732           rollback transaction rs_logexec
733           return (1)
734       end
735   
736       commit transaction
737   
738       /*
739       ** 17964 "The replication status for '%1!' is set to %2!."
740       */
741       exec sp_getmessage 17964, @msg output
742       print @msg, @replicate_name, @setflag
743   
744       /*
745       ** If status is not being turned off, also display log_mode.
746       ** Detect the status not being turned off by @setrep_flags not being 0.
747       */
748       if (@setrep_flags != 0)
749       begin
750           /*
751           ** 18849 "The log mode is set to %1!."
752           */
753           exec sp_getmessage 18849, @msg output
754           print @msg, @logflag
755       end
756   
757       return (0)
758   


exec sp_procxmode 'sp_setrepproc', 'AnyMode'
go

Grant Execute on sp_setrepproc to public
go
DEFECTS
 QCAR 6 Cartesian product between tables sybsystemprocs..sysobjects o and [master..sysmessages m1, master..sysmessages m2] 186
 MINU 4 Unique Index with nullable columns master..sysmessages master..sysmessages
 MTYP 4 Assignment type mismatch @tmpstr: varchar(20) = varchar(30) 287
 MTYP 4 Assignment type mismatch @tmpstr: varchar(20) = varchar(30) 291
 MTYP 4 Assignment type mismatch @logstr: varchar(20) = varchar(30) 297
 MTYP 4 Assignment type mismatch @logstr: varchar(20) = varchar(30) 301
 MTYP 4 Assignment type mismatch @tmpstr: varchar(20) = varchar(30) 308
 MTYP 4 Assignment type mismatch @setflag: varchar(20) = varchar(30) 388
 MTYP 4 Assignment type mismatch @logflag: varchar(20) = varchar(30) 394
 MTYP 4 Assignment type mismatch sysstat: smallint = int 667
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 203
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs int 556
 QTYP 4 Comparison type mismatch tinyint = int 556
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs int 558
 QTYP 4 Comparison type mismatch tinyint = int 558
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs int 560
 QTYP 4 Comparison type mismatch tinyint = int 560
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs int 562
 QTYP 4 Comparison type mismatch tinyint = int 562
 MGTP 3 Grant to public master..sysmessages  
 MGTP 3 Grant to public sybsystemprocs..sp_setrepproc  
 MGTP 3 Grant to public sybsystemprocs..syscolumns  
 MGTP 3 Grant to public sybsystemprocs..sysobjects  
 MNER 3 No Error Check should check return value of exec 164
 MNER 3 No Error Check should check return value of exec 166
 MNER 3 No Error Check should check return value of exec 168
 MNER 3 No Error Check should check return value of exec 170
 MNER 3 No Error Check should check return value of exec 172
 MNER 3 No Error Check should check @@error after select into 181
 MNER 3 No Error Check should check return value of exec 203
 MNER 3 No Error Check should check return value of exec 225
 MNER 3 No Error Check should check return value of exec 315
 MNER 3 No Error Check should check return value of exec 324
 MNER 3 No Error Check should check return value of exec 657
 MNER 3 No Error Check should check @@error after update 666
 MNER 3 No Error Check should check return value of exec 693
 MNER 3 No Error Check should check return value of exec 741
 MNER 3 No Error Check should check return value of exec 753
 MUCO 3 Useless Code Useless Brackets 119
 MUCO 3 Useless Code Useless Brackets 179
 MUCO 3 Useless Code Useless Brackets 206
 MUCO 3 Useless Code Useless Brackets 219
 MUCO 3 Useless Code Useless Brackets 233
 MUCO 3 Useless Code Useless Brackets 239
 MUCO 3 Useless Code Useless Brackets 257
 MUCO 3 Useless Code Useless Brackets 264
 MUCO 3 Useless Code Useless Brackets 319
 MUCO 3 Useless Code Useless Brackets 327
 MUCO 3 Useless Code Useless Brackets 334
 MUCO 3 Useless Code Useless Brackets 336
 MUCO 3 Useless Code Useless Brackets 346
 MUCO 3 Useless Code Useless Brackets 355
 MUCO 3 Useless Code Useless Brackets 357
 MUCO 3 Useless Code Useless Brackets 378
 MUCO 3 Useless Code Useless Brackets 386
 MUCO 3 Useless Code Useless Brackets 392
 MUCO 3 Useless Code Useless Brackets 400
 MUCO 3 Useless Code Useless Brackets 408
 MUCO 3 Useless Code Useless Brackets 414
 MUCO 3 Useless Code Useless Brackets 422
 MUCO 3 Useless Code Useless Brackets 451
 MUCO 3 Useless Code Useless Brackets 523
 MUCO 3 Useless Code Useless Brackets 549
 MUCO 3 Useless Code Useless Brackets 574
 MUCO 3 Useless Code Useless Brackets 600
 MUCO 3 Useless Code Useless Brackets 606
 MUCO 3 Useless Code Useless Brackets 612
 MUCO 3 Useless Code Useless Brackets 637
 MUCO 3 Useless Code Useless Brackets 650
 MUCO 3 Useless Code Useless Brackets 661
 MUCO 3 Useless Code Useless Brackets 676
 MUCO 3 Useless Code Useless Brackets 686
 MUCO 3 Useless Code Useless Brackets 697
 MUCO 3 Useless Code Useless Brackets 704
 MUCO 3 Useless Code Useless Brackets 714
 MUCO 3 Useless Code Useless Brackets 721
 MUCO 3 Useless Code Useless Brackets 733
 MUCO 3 Useless Code Useless Brackets 748
 MUCO 3 Useless Code Useless Brackets 757
 QCTC 3 Conditional Table Creation 181
 QISO 3 Set isolation level 115
 QNAJ 3 Not using ANSI Inner Join 186
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
192
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
193
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
554
 VNRD 3 Variable is not read @owner 227
 VNRD 3 Variable is not read @procval 358
 VUNU 3 Variable is not used @true 67
 MSUB 2 Subquery Marker 248
 MSUB 2 Subquery Marker 533
 MSUB 2 Subquery Marker 553
 MTR1 2 Metrics: Comments Ratio Comments: 56% 42
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 53 = 69dec - 18exi + 2 42
 MTR3 2 Metrics: Query Complexity Complexity: 262 42

DEPENDENCIES
PROCS AND TABLES USED
writes table tempdb..#setrepproc1rs (1) 
reads table sybsystemprocs..syscolumns  
calls proc sybsystemprocs..sp_autoformat  
   calls proc sybsystemprocs..sp_autoformat  
   reads table tempdb..syscolumns (1)  
   calls proc sybsystemprocs..sp_namecrack  
   reads table master..syscolumns (1)  
   reads table master..systypes (1)  
   read_writes table tempdb..#colinfo_af (1) 
   reads table tempdb..systypes (1)  
reads table master..sysmessages (1)  
calls proc sybsystemprocs..sp_getmessage  
   reads table master..sysmessages (1)  
   reads table master..syslanguages (1)  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
   reads table sybsystemprocs..sysusermessages  
calls proc sybsystemprocs..sp_namecrack  
read_writes table sybsystemprocs..sysobjects