DatabaseProcApplicationCreatedLinks
sybsystemprocssp_setreptable  14 déc. 14Defects Propagation Dependencies

1     
2     /*
3     ** Generated by spgenmsgs.pl on Wed Feb  8 14:55:58 2006 
4     */
5     /*
6     ** raiserror Messages for setreptable [Total 10]
7     **
8     ** 17756, "The execution of the stored procedure '%1!' in database '%2!' was aborted because there was an error in writing the replication log record."
9     ** 17962, "The replication status for '%1!' is already set to %2!. Replication status for '%3!' does not change."
10    ** 17966, "Due to system failure, the replication status for '%1!' has not been changed."
11    ** 18100, "Usage: sp_setreptable [ table_name [, {true | false} [, {owner_on | owner_off} ] ] ]"
12    ** 18101, "The specified table must be in the current database."
13    ** 18102, "Table '%1!' does not exist in this database."
14    ** 18103, "An object with the same name, but owned by a different user, is already being replicated.  The table '%1!' cannot be replicated."
15    ** 18409, "The built-in function '%1!' failed. Please see any other messages printed along with this message."
16    ** 18410, "The replication status of '%1!' is corrupt. Please contact Sybase Technical Support."
17    ** 18418, "Only the System Administrator (SA), the Database Owner (dbo) or a user with REPLICATION authorization may execute this stored procedure."
18    */
19    /*
20    ** sp_getmessage Messages for setreptable [Total 7]
21    **
22    ** 17431, "true"
23    ** 17432, "false"
24    ** 17964, "The replication status for '%1!' is set to %2!."
25    ** 17965, "The replication status for '%1!' is currently %2!."
26    ** 17968, "The built-in function logschema() failed for '%1!'. See the other messages printed along with this message for more information."
27    ** 18538, "owner_on"
28    ** 18539, "owner_off"
29    */
30    /*
31    ** End spgenmsgs.pl output.
32    */
33    
34    create or replace procedure sp_setreptable
35        @replicate_name varchar(767) = NULL, /* obj we want to mark as replicate */
36        @setflag varchar(5) = NULL, /* set or unset the replicate status.*/
37        @repdefmode varchar(10) = NULL, /* Send Owner Information ? */
38        @use_index varchar(12) = NULL /* Use indexes for text columns */
39    as
40    
41        declare @current_status int /* current sysstat value for the object. */
42        declare @current_mode int /* current repdef mode for the object. */
43        declare @current_index_mode
44            int /* current index mode for the object. */
45        declare @current_never int /* current never mode for the object. */
46        declare @status_set int /* sysstat bits to be set for the object. */
47        declare @status_reset int /* sysstat bits to be reset for the object. */
48        declare @status2_set int /* sysstat2 bits to be set for the object. */
49        declare @status2_reset int /* sysstat2 bits to be reset for the object. */
50        declare @rep_constant smallint /* bit which indicates a replicated object. */
51        declare @setrep_repl int /* setrepstatus() LT_SETREP_REPLICATE flag
52        ** for setting the replication bit.
53        */
54        declare @setrep_owner int /* Bit which indicates if the replicated object
55        ** will use owner information for replication
56        */
57        declare @setrep_index int /* Bit which indicates if the replicated object
58        ** will use internal indexes for text
59        ** replication */
60        declare @setrep_never int /* Bit which indicates if the object will be
61        ** marked as never replicated regardless of the
62        ** database configuration setting.
63        */
64        declare @colrepalwys smallint
65        declare @colrepifch smallint
66        declare @tipsa_in_index smallint
67        declare @pkindid int /* PK index id   */
68        declare @pkname varchar(255) /* PK index name */
69        declare @db varchar(255) /* db of object. */
70        declare @owner varchar(255) /* owner of object. */
71        declare @object varchar(255) /* object's name. */
72        declare @true varchar(10)
73        declare @false varchar(10)
74        declare @never varchar(10)
75        declare @msg varchar(1024)
76        declare @tmpstr varchar(302)
77        declare @sptlang int
78        declare @procval int
79        declare @texttype smallint
80        declare @imagetype smallint
81        declare @unitexttype smallint /* UNITEXT type. */
82        declare @xtype_type smallint
83        declare @offrow smallint
84        declare @objid int
85        declare @rep_on_schema int /* log schema when turning replication on? */
86        declare @rep_off_schema int /* log schema when turning replication off? */
87        declare @owner_on varchar(10)
88        declare @owner_off varchar(10)
89        declare @user_tran int /* are we inside a user tran? */
90        declare @after_image int /* log the after image of the schema */
91        declare @mod_versionts int /* modify version timestamp after logging
92        ** the schema
93        */
94        declare @owner_bit int
95        declare @index_bit int
96        declare @setrep_flags int /* repflags parm passed to setrepstatus(). */
97        declare @retstat int
98        declare @omsg varchar(40)
99        declare @dbname varchar(255)
100       declare @col_name varchar(255)
101   
102       declare @curstat int
103       declare @reptostandbyon int /* 1: standby server is running */
104       declare @db_rep_level_all int /* All level replication */
105       declare @db_rep_level_none int /* no replication        */
106       declare @db_rep_level_l1 int /* L1 level replication  */
107       declare @lt_rep_get_failed int /* LT_GET_REP_FAILED */
108       declare @lt_rep_all int /* LT_REP_ALL */
109       declare @lt_rep_l1 int /* LT_REP_L1 */
110       declare @dummy int
111       declare @nullarg char(1)
112       declare @gp_enabled int
113       declare @status1 int
114       declare @status2 int
115       declare @status3 int
116       declare @linked int
117   
118       select @status1 = 1
119       select @status2 = 1
120       select @status3 = 1
121   
122       if @@trancount = 0
123       begin
124           set transaction isolation level 1
125           set chained off
126       end
127   
128       if (@@trancount > 0)
129           select @user_tran = 1
130       else
131           select @user_tran = 0
132   
133       /*
134       ** Replication enabled flag is 8000H (which is -32768D)
135       */
136       select @rep_constant = - 32768,
137           @colrepalwys = 1,
138           @colrepifch = 2,
139           @imagetype = 34,
140           @texttype = 35,
141           @xtype_type = 36,
142           @unitexttype = 174,
143           @offrow = 1,
144           @owner_bit = 4096, /* 0x1000 in sysstat2 */
145           @db_rep_level_all = - 1,
146           @db_rep_level_l1 = 1,
147           @tipsa_in_index = 2048,
148           @setrep_index = 8, /* LT_SETREP_TIPSA_INDEX */
149           @setrep_owner = 16, /* LT_SETREP_OWNER */
150           @setrep_never = 1024, /* LT_REP_NEVER */
151           @retstat = 1,
152           @index_bit = 8388608, /* 0x800000 in sysstat2 */
153           @lt_rep_get_failed = - 2, /* LT_GET_REP_FAILED */
154           @lt_rep_all = 2048, /* LT_REP_ALL */
155           @lt_rep_l1 = 4096 /* LT_REP_L1 */
156   
157       /*
158       ** Initialize @setrep_repl to LT_SETREP_REPLICATE (0x00000001).
159       ** setrepstatus() flags are defined in logtrans.h
160       */
161       select @setrep_repl = 1
162   
163       /* set @rep_on_schema and rep_off_schema to false initially */
164       select @rep_on_schema = 0
165       select @rep_off_schema = 0
166   
167       /* Initialize masks for sysstat and sysstat2. */
168       select @status_set = 0, @status_reset = 0, @status2_set = 0, @status2_reset = 0
169   
170       /*
171       ** Initialize 'true' and 'false' strings
172       */
173       /* 17431, "true" */
174       exec sp_getmessage 17431, @true out
175       /* 17432, "false" */
176       exec sp_getmessage 17432, @false out
177       /* 18538, "owner_on" */
178       exec sp_getmessage 18538, @owner_on out
179       /* 18539, "owner_off" */
180       exec sp_getmessage 18539, @owner_off out
181       /* 19896, "never" */
182       exec sp_getmessage 19896, @never out
183   
184       /* Create the temporary table for printing the values */
185       create table #repdefmode(val int, str varchar(10))
186   
187       insert #repdefmode values (0, @owner_off)
188       insert #repdefmode values (@owner_bit, @owner_on)
189   
190       /* Create the temporary table for printing index status value */
191       create table #indexmode(val int, str varchar(15))
192   
193       insert #indexmode values (0, 'no index')
194       insert #indexmode values (@index_bit, 'using index')
195   
196       /* Create the temporary table for printing primary key */
197       create table #primarykey(val int, str varchar(255))
198   
199       select @dbname = db_name()
200   
201       /*
202       ** Set 'sptlang' for proper printing of object information.  Used mainly
203       ** for the 'select' statement which is executed when we are invoked with
204       ** no parameters.  Copied from similar code in 'sp_help'
205       */
206       select @sptlang = @@langid
207       if @@langid != 0
208       begin
209           if not exists (
210                   select * from master.dbo.sysmessages where error
211                       between 17100 and 17109
212                       and langid = @@langid)
213               select @sptlang = 0
214       end
215   
216       /*
217       ** If we are invoked with no parameters, then just print out all objects
218       ** which are marked for replication.  The 'select' statement is heavily
219       ** based upon the one found in 'sp_help'.
220       */
221       if (@replicate_name is NULL and @setflag is NULL and @use_index is NULL)
222       /*
223       ** First obtain the information needed to print the primary 
224       ** or unique index name chosen for replication.
225       */
226       begin
227           select @objid = min(id)
228           from sysobjects
229           where type = "U"
230               and (sysstat & @rep_constant) = @rep_constant
231   
232           while (@objid is not NULL)
233           begin
234               select @pkindid = getreppkindid(@objid)
235   
236               if (@pkindid > 0)
237               begin
238                   select @pkname = name
239                   from sysindexes
240                   where id = @objid
241                       and
242                       indid = @pkindid
243   
244                   insert #primarykey values (@objid, @pkname)
245               end
246               else if (@pkindid = 0)
247                   insert #primarykey values (@objid, "no primary key")
248               else
249               begin
250                   /*
251                   ** 18409, "The built-in function '%1!' failed. Please see any 
252                   ** other messages printed along with this message."
253                   */
254                   raiserror 18409, "getreppkindid"
255                   return (1)
256               end
257   
258               select @objid = min(id)
259               from sysobjects
260               where type = "U"
261                   and (sysstat & @rep_constant) = @rep_constant
262                   and id > @objid
263           end
264   
265           select
266               Name = o.name,
267               "Repdef_Mode" = t.str,
268               "Index_Mode" = x.str,
269               "Primary_Key" = i.str
270           into #show_replicate_table
271           from
272               sysobjects o,
273               #repdefmode t,
274               #indexmode x,
275               #primarykey i
276           where
277               o.id = i.val
278               and (o.sysstat2 & @owner_bit) = t.val
279               and (o.sysstat2 & @index_bit) = x.val
280           order by o.name
281   
282           exec sp_autoformat #show_replicate_table,
283               "Name = Name,
284   	   'Repdef Mode' = Repdef_Mode,
285   	   'Index Mode' = Index_Mode,
286   	   'Primary Key' = Primary_Key"
287   
288           drop table #show_replicate_table, #repdefmode,
289               #indexmode, #primarykey
290   
291           return (0)
292       end
293   
294       /*
295       ** Crack the name into its corresponding pieces.
296       */
297       execute sp_namecrack @replicate_name,
298           @db = @db output,
299           @owner = @owner output,
300           @object = @object output
301   
302       /*
303       ** Make sure that the object is in the current database.
304       */
305       if (@db is not NULL and @db != db_name())
306       begin
307           /*
308           ** 18101, "Table must be in the current database."
309           */
310           raiserror 18101
311           return (1)
312       end
313   
314       /*
315       **  Make sure that the object actually exists.
316       */
317       select @objid = object_id(@replicate_name)
318   
319       if (@objid is NULL) or
320           (not exists (select name from sysobjects where
321                       id = @objid and
322                       type = "U"
323                   ))
324       begin
325           /*
326           ** 18102, "Table '%1!' does not exist in this database."
327           */
328           raiserror 18102, @replicate_name
329           return (1)
330       end
331   
332       /*
333       ** Check if the object is back linked 
334       */
335       select @linked = back_linked(0, @objid)
336   
337       /*
338       ** If the table is back-lined we do not need to use indexes for
339       ** replication, even if the parameter was passed
340       */
341       if (@linked = 1)
342       begin
343           select @use_index = NULL
344       end
345   
346       /*
347       ** Currently, marking for replication user tables in the 'master' database
348       ** is not allowed.
349       **
350       ** Therefore, if the current database is the 'master' database, reset the
351       ** '@setflag' to NULL so that the system procedure will report the current
352       ** status of the user table.  A proper error message should be implemented
353       ** at a later date.
354       */
355       if (db_name() = "master")
356       begin
357           select @setflag = NULL
358       end
359   
360       /*
361       ** If the 'setflag' parameter is NULL, then we are only interested in the
362       ** current replication status of the specified object.
363       */
364       if (@setflag is NULL)
365       begin
366           select
367               @current_status = (sysstat & @rep_constant),
368               @current_mode = (sysstat2 & @owner_bit),
369               @current_index_mode = (sysstat2 & @index_bit)
370           from
371               sysobjects
372           where
373               id = @objid
374   
375           select @current_never = getrepdefmode(@objid)
376   
377           if (@current_never < 0)
378           begin
379               /*
380               ** 18409, "The built-in function '%1!' failed. Please see any 
381               ** other messages printed along with this message."
382               */
383               raiserror 18409, "getrepdefmode"
384               return (1)
385           end
386   
387           /* 
388           ** Obtain the primary or unique index chosen for
389           ** the replication of this object.
390           */
391           select @pkindid = getreppkindid(@objid)
392   
393           if (@pkindid < 0)
394           begin
395               /*
396               ** 18409, "The built-in function '%1!' failed. Please see any 
397               ** other messages printed along with this message."
398               */
399               raiserror 18409, "getreppkindid"
400               return (1)
401           end
402   
403           if (@pkindid > 0)
404           begin
405               select
406                   @pkname = name
407               from
408                   sysindexes
409               where
410                   id = @objid
411                   and
412                   indid = @pkindid
413           end
414   
415           if @current_status = @rep_constant
416               select @tmpstr = @true
417           else
418           begin
419               if ((@current_never & @setrep_never) != 0)
420                   select @tmpstr = @never
421               else
422                   select @tmpstr = @false
423           end
424           if @current_mode = 0
425               select @tmpstr = @tmpstr + ", " + @owner_off
426           else
427               select @tmpstr = @tmpstr + ", " + @owner_on
428           if @current_index_mode = @index_bit
429               select @tmpstr = @tmpstr + ", " + "using index"
430           if @pkindid = 0
431               select @tmpstr = @tmpstr + ", " + "no primary key"
432           else
433               select @tmpstr = @tmpstr + ", " + "primary key = '" + @pkname + "'"
434           /*
435           ** 17965 "The replication status for '%1!' is currently %2!."
436           */
437           exec sp_getmessage 17965, @msg output
438           print @msg, @replicate_name, @tmpstr
439   
440           return (0)
441       end
442   
443       /*
444       ** If granular permissions is not enabled, 
445       ** you must be SA, dbo or have REPLICATION role to execute this
446       ** sproc.
447       **  If granular permissions is enabled then users with 
448       ** 'manage replication' permission can execute it.
449       */
450       select @nullarg = NULL
451       execute @status1 = sp_aux_checkroleperm "dbo", "manage replication",
452           @dbname, @gp_enabled output
453   
454       if (@gp_enabled = 0)
455       begin
456           if (@status1 != 0)
457           begin
458               execute @status2 = sp_aux_checkroleperm "sa_role",
459                   @nullarg, @nullarg, @gp_enabled output
460   
461               if (@status2 != 0)
462                   execute @status3 = sp_aux_checkroleperm
463                       "replication_role", @nullarg, @nullarg,
464                       @gp_enabled output
465   
466               if (@status3 != 0)
467               begin
468                   /* 
469                   ** proc_role() will raise permission errors
470                   ** and send audit records to the audit trail.
471                   */
472                   select @dummy = proc_role("sa_role")
473                   select @dummy = proc_role("replication_role")
474                   return (1)
475               end
476           end
477           if (@status2 = 0)
478               select @dummy = proc_role("sa_role")
479           if (@status3 = 0)
480               select @dummy = proc_role("replication_role")
481       end
482       else
483       begin
484           select @dummy = proc_auditperm("manage replication", @status1, @dbname)
485           if (@status1 != 0)
486               return 1
487       end
488   
489       /*
490       ** Check for a valid setflag parameter
491       */
492       if (lower(@setflag) not in ("true", "false", "never", @true, @false, @never))
493       begin
494           /*
495           ** 18100 "Usage: sp_setreptable table_name, {true | false | never} 
496           **	   				 {owner_on | owner_off}
497           **					 [, use_index ]"
498           */
499           raiserror 18100
500           return (1)
501       end
502   
503       /* Default repdefmode is "owner_off"
504       */
505       if (@repdefmode is NULL)
506           select @repdefmode = @owner_off
507       /*
508       ** Check for a valid repdefmode parameter
509       */
510       if (lower(@repdefmode) not in (@owner_on, @owner_off, "owner_on", "owner_off"))
511       begin
512           /*
513           ** 18100, "Usage: sp_setreptable table_name, {true | false | never},
514           **	   				 {owner_on | owner_off}
515           **					 [, use_index ]"
516           */
517           raiserror 18100
518           return (1)
519       end
520   
521       /*
522       ** Check for valid use_index parameter
523       */
524       if (@use_index is not null and (lower(@use_index) != "use_index"))
525       begin
526           /*
527           ** 18100, "Usage: sp_setreptable table_name, {true | false | never},
528           **	   				 {owner_on | owner_off}
529           **					 [, use_index ]"
530           */
531           raiserror 18100
532           return (1)
533       end
534       if (@use_index is not null)
535       begin
536           select @setrep_repl = @setrep_repl | @setrep_index
537       end
538   
539       /*
540       ** First, determine the current replication status of the database.
541       */
542       select @curstat = getdbrepstat()
543   
544       /*
545       ** Perform sanity checks on the returned value
546       ** getdbrepstat() return current status of replication server. Check returned
547       ** message, system supports only L1 and All level replication.
548       */
549       if (@curstat = @lt_rep_get_failed)
550       begin
551           /*
552           ** 18409, "The built-in function '%1!' failed. Please
553           ** see any other messages printed along with this message."
554           */
555           raiserror 18409, "getdbrepstat"
556           return (1)
557       end
558   
559       if ((@curstat & @lt_rep_all = @lt_rep_all) or
560               (@curstat & @lt_rep_l1 = @lt_rep_l1))
561       begin
562           select @reptostandbyon = 1
563       end
564       else
565       begin
566           select @reptostandbyon = 0
567       end
568   
569       /*
570       ** Get the object's current status. Hold a read lock on sysobjects so that 
571       **	the status cannot be changed until we're done.
572       */
573       select @current_status = sysstat, @current_mode = sysstat2
574       from sysobjects holdlock
575       where id = @objid
576   
577       /*
578       ** Perform the requested operation on the object.
579       ** If setflag is FALSE or NEVER, we ignore the other parameters.
580       */
581       if lower(@setflag) in ("false", @false)
582       begin
583           select @current_never = getrepdefmode(@objid)
584   
585           /*
586           ** Check if we have to remove the replication status
587           */
588           if ((@current_never & @setrep_never) = 0)
589               and (@current_status & @rep_constant) = 0
590           begin
591               /*
592               ** 17962 "The replication status for '%1!' is already
593               **	  set to %2!.  Replication status for '%3!'
594               **	  does not change."
595               */
596               raiserror 17962, @replicate_name, @setflag, @replicate_name
597               return (1)
598           end
599   
600           select @status_reset = @status_reset | @rep_constant
601           select @status2_reset = @status2_reset | @owner_bit | @index_bit
602           select @rep_off_schema = 1
603           select @setrep_flags = 0
604   
605           /*
606           ** Even if the user gives a third parameter, set it to
607           ** "owner_off" so that the message printed out at the end
608           ** of the procedure is correct.
609           */
610           select @repdefmode = @owner_off
611       end
612       else if lower(@setflag) in ("never", @never)
613       begin
614           select @current_never = getrepdefmode(@objid)
615   
616           if (@current_never & @setrep_never) != 0
617           begin
618               /*
619               ** 17962 "The replication status for '%1!' is already
620               **	  set to %2!.  Replication status for '%3!'
621               **	  does not change."
622               */
623               raiserror 17962, @replicate_name, @setflag, @replicate_name
624               return (1)
625           end
626           set @setrep_flags = @setrep_never
627       end
628       else
629       begin
630           /*
631           ** We are turning ON replication on this table.
632           **
633           ** Is the replicate status bit already set?
634           */
635           if (@current_status & @rep_constant) != 0
636           begin
637               /*
638               ** 17962 "The replication status for '%1!' is already
639               **	  set to %2!.  Replication status for '%3!'
640               **	  does not change."
641               */
642               raiserror 17962, @replicate_name, @setflag, @replicate_name
643               return (1)
644           end
645   
646           if (lower(@repdefmode) in (@owner_off, "owner_off"))
647           begin
648               /*
649               ** Make sure that no like object with the same name, but a
650               ** different owner, exists.  We need to do this because
651               ** the SQL Server does not send owner information along
652               ** with the object to the Replication Server.  This
653               ** restriction may be lifted in future versions.
654               */
655               if exists (select * from sysobjects
656                       where name = @object
657                           and (
658                               (type = "U ") /* user table */
659                               or
660                               (type = "P ") /* stored procedure */
661                           )
662                           and sysstat & @rep_constant != 0
663                           and sysstat2 & @owner_bit = 0)
664               begin
665                   /*
666                   ** 18103 "An object with the same name, but owned by a
667                   **	  different user is already being replicated.
668                   **	  The table '%1!' cannot be replicated."
669                   */
670                   raiserror 18103, @replicate_name
671                   return (1)
672               end
673   
674               select @status_set = @status_set | @rep_constant
675               select @status2_reset = @status2_reset | @owner_bit
676               select @rep_on_schema = 1
677               select @setrep_flags = @setrep_repl
678           end
679           else
680           begin
681               /* We are setting owner mode to ON */
682               select @status_set = @status_set | @rep_constant
683               select @status2_set = @status2_set | @owner_bit
684               select @rep_on_schema = 1
685               select @setrep_flags = @setrep_repl
686           end
687   
688           /* Check if we want to use indexes for replication */
689           if @use_index is not null
690           begin
691               select @status2_set = @status2_set | @index_bit
692           end
693           else
694           begin
695               select @status2_reset = @status2_reset | @index_bit
696           end
697       end
698   
699       /*
700       ** Update the object's sysstat column
701       **
702       ** IMPORTANT: This transaction name is significant and is used by
703       **            Replication Server
704       */
705       begin transaction rs_logexec
706   
707       /* 
708       ** Log the schema first if we are turning off replication 
709       ** or if we repdefmode has ower_mode on, or if standby replication
710       ** server is running.
711       */
712       if ((@rep_off_schema = 1) or (@repdefmode = @owner_on)
713               or (@reptostandbyon = 1))
714       begin
715           select @after_image = 0
716           select @mod_versionts = 1
717           if (logschema(@objid, @user_tran, @after_image,
718                       @mod_versionts) != 1)
719           begin
720               /*
721               ** 17968 "The built-in function logschema() failed 
722               ** for '%1!'." 
723               */
724               exec sp_getmessage 17968, @msg output
725               print @msg, @replicate_name
726   
727               rollback transaction
728               return (1)
729           end
730       end
731   
732   
733       /* 
734       ** Update the column bits for text/image/off-row-object columns 
735       */
736       if (@setrep_flags = @setrep_repl)
737       begin
738           update syscolumns
739           set status = status | @colrepalwys,
740               status2 =
741               case
742                   when status2 is null
743                       and @use_index is not null
744                   then @tipsa_in_index
745                   when status2 is not null
746                       and @use_index is not null
747                   then status2 | @tipsa_in_index
748                   else status2
749               end
750           where
751               id = @objid
752               and (type in (@imagetype, @texttype, @unitexttype)
753                   or (type = @xtype_type
754                       and (xstatus & @offrow) = @offrow))
755   
756       end
757       /* If we are turning off replication, reset status in syscolumns */
758       else if (@setrep_flags = 0)
759       begin
760           update syscolumns
761           set status = status & ~ (@colrepalwys | @colrepifch),
762               status2 = status2 & ~ (@tipsa_in_index)
763           where
764               id = @objid
765               and (type in (@imagetype, @texttype, @unitexttype)
766                   or (type = @xtype_type
767                       and (xstatus & @offrow) = @offrow))
768   
769       end
770   
771       /* 
772       ** Log the schema now if we are turning on replication and we are
773       ** inside a user transaction.
774       */
775       if ((@rep_on_schema = 1) and (@user_tran = 1))
776       begin
777           select @after_image = 1
778           select @mod_versionts = 0
779           if (logschema(@objid, @user_tran, @after_image,
780                       @mod_versionts) != 1)
781           begin
782               /*
783               ** 17968 "The built-in function logschema() failed 
784               ** for '%1!'." 
785               */
786               exec sp_getmessage 17968, @msg output
787               print @msg, @replicate_name
788   
789               goto clear_all
790           end
791       end
792   
793       /*
794       ** Update the object's status in cache.
795       */
796       if (setrepstatus(@objid, @setrep_flags) != 1)
797       begin
798           /*
799           ** 17966 "Due to system failure, the replication status
800           **	  for '%1!' has not been changed."
801           */
802           raiserror 17966, @replicate_name, @setflag
803   
804           goto clear_all
805       end
806   
807       /* We are turning on /off replication. Update status */
808       if (@setrep_flags = @setrep_repl) or (@setrep_flags = 0)
809       begin
810           /* We are turning on replication */
811           if (@setrep_flags = @setrep_repl)
812           begin
813               /* Set individual status bits in the cache */
814               if ((@status2_set & @owner_bit) != 0)
815               begin
816                   select @retstat = setrepdefmode(@objid,
817                           @setrep_owner, 1)
818               end
819               if (@retstat = 1) and ((@status2_set & @index_bit) != 0)
820               begin
821                   select @retstat = setrepdefmode(@objid,
822                           @setrep_index, 1)
823               end
824           end
825           else
826           begin
827               /* 
828               ** We are turning off replication, remove the 
829               ** index status from the cache 
830               */
831               select @retstat = setrepdefmode(@objid,
832                       @setrep_index, 0)
833               if (@retstat = 1)
834               begin
835                   /* Remove the owner status from the cache */
836                   select @retstat = setrepdefmode(@objid,
837                           @setrep_owner, 0)
838               end
839           end
840           if (@retstat != 1)
841           begin
842               /*
843               ** 17966 "Due to system failure, the replication status
844               **	  for '%1!' has not been changed."
845               */
846               raiserror 17966, @replicate_name, @setflag
847   
848               goto clear_all
849           end
850   
851           /*
852           ** Set status at table level
853           */
854           update sysobjects
855           set sysstat = (sysstat | @status_set) & ~ @status_reset,
856               sysstat2 = (sysstat2 | @status2_set) & ~ @status2_reset
857           where
858               id = @objid
859       end
860   
861       /*
862       ** Write the log record to replicate this invocation 
863       ** of the stored procedure.
864       */
865       if (logexec() != 1)
866       begin
867           /*
868           ** 17756, "The execution of the stored procedure '%1!'
869           ** 	   in database '%2!' was aborted because there
870           ** 	   was an error in writing the replication log
871           **	   record."
872           */
873           raiserror 17756, "sp_setreptable", @dbname
874   
875           goto clear_all
876       end
877   
878       commit transaction
879   
880       /*
881       ** If the object is back-linked, the internal processing has not created
882       ** index for replication, do indicate that fact in the message we are
883       ** returning.
884       */
885   
886       if (@use_index is not null)
887           select @use_index = ", " + @use_index
888   
889       if (@setrep_flags = @setrep_never)
890           select @omsg = @setflag
891       else
892           select @omsg = @setflag + ", " + @repdefmode + @use_index
893   
894       /*
895       ** 17964 "The replication status for '%1!' is set to %2!."
896       */
897   
898       exec sp_getmessage 17964, @msg output
899       print @msg, @replicate_name, @omsg
900       return (0)
901   
902   clear_all:
903       rollback transaction rs_logexec
904       return (1)
905   


exec sp_procxmode 'sp_setreptable', 'AnyMode'
go

Grant Execute on sp_setreptable to public
go
DEFECTS
 MINU 4 Unique Index with nullable columns master..sysmessages master..sysmessages
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: parameter # 1 282
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 212
 QTYP 4 Comparison type mismatch smallint = int 212
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 242
 QTYP 4 Comparison type mismatch smallint = int 242
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 412
 QTYP 4 Comparison type mismatch smallint = int 412
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs smallint 753
 QTYP 4 Comparison type mismatch tinyint = smallint 753
 QTYP 4 Comparison type mismatch Comparison type mismatch: tinyint vs smallint 766
 QTYP 4 Comparison type mismatch tinyint = smallint 766
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 227
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 240
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 258
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 262
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 277
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 321
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 373
 MAW1 3 Warning message on %name% sybsystemprocs..sysindexes.id: Warning message on sysindexes 410
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 575
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 751
 MAW1 3 Warning message on %name% sybsystemprocs..syscolumns.id: Warning message on syscolumns 764
 MAW1 3 Warning message on %name% sybsystemprocs..sysobjects.id: Warning message on sysobjects 858
 MGTP 3 Grant to public master..sysmessages  
 MGTP 3 Grant to public sybsystemprocs..sp_setreptable  
 MGTP 3 Grant to public sybsystemprocs..syscolumns  
 MGTP 3 Grant to public sybsystemprocs..sysindexes  
 MGTP 3 Grant to public sybsystemprocs..sysobjects  
 MNER 3 No Error Check should check return value of exec 174
 MNER 3 No Error Check should check return value of exec 176
 MNER 3 No Error Check should check return value of exec 178
 MNER 3 No Error Check should check return value of exec 180
 MNER 3 No Error Check should check return value of exec 182
 MNER 3 No Error Check should check @@error after insert 187
 MNER 3 No Error Check should check @@error after insert 188
 MNER 3 No Error Check should check @@error after insert 193
 MNER 3 No Error Check should check @@error after insert 194
 MNER 3 No Error Check should check @@error after insert 244
 MNER 3 No Error Check should check @@error after insert 247
 MNER 3 No Error Check should check @@error after select into 265
 MNER 3 No Error Check should check return value of exec 282
 MNER 3 No Error Check should check return value of exec 297
 MNER 3 No Error Check should check return value of exec 437
 MNER 3 No Error Check should check return value of exec 724
 MNER 3 No Error Check should check @@error after update 738
 MNER 3 No Error Check should check @@error after update 760
 MNER 3 No Error Check should check return value of exec 786
 MNER 3 No Error Check should check @@error after update 854
 MNER 3 No Error Check should check return value of exec 898
 MUCO 3 Useless Code Useless Brackets 128
 MUCO 3 Useless Code Useless Brackets 221
 MUCO 3 Useless Code Useless Brackets 232
 MUCO 3 Useless Code Useless Brackets 236
 MUCO 3 Useless Code Useless Brackets 246
 MUCO 3 Useless Code Useless Brackets 255
 MUCO 3 Useless Code Useless Brackets 291
 MUCO 3 Useless Code Useless Brackets 305
 MUCO 3 Useless Code Useless Brackets 311
 MUCO 3 Useless Code Useless Brackets 329
 MUCO 3 Useless Code Useless Brackets 341
 MUCO 3 Useless Code Useless Brackets 355
 MUCO 3 Useless Code Useless Brackets 364
 MUCO 3 Useless Code Useless Brackets 377
 MUCO 3 Useless Code Useless Brackets 384
 MUCO 3 Useless Code Useless Brackets 393
 MUCO 3 Useless Code Useless Brackets 400
 MUCO 3 Useless Code Useless Brackets 403
 MUCO 3 Useless Code Useless Brackets 419
 MUCO 3 Useless Code Useless Brackets 440
 MUCO 3 Useless Code Useless Brackets 454
 MUCO 3 Useless Code Useless Brackets 456
 MUCO 3 Useless Code Useless Brackets 461
 MUCO 3 Useless Code Useless Brackets 466
 MUCO 3 Useless Code Useless Brackets 474
 MUCO 3 Useless Code Useless Brackets 477
 MUCO 3 Useless Code Useless Brackets 479
 MUCO 3 Useless Code Useless Brackets 485
 MUCO 3 Useless Code Useless Brackets 492
 MUCO 3 Useless Code Useless Brackets 500
 MUCO 3 Useless Code Useless Brackets 505
 MUCO 3 Useless Code Useless Brackets 510
 MUCO 3 Useless Code Useless Brackets 518
 MUCO 3 Useless Code Useless Brackets 524
 MUCO 3 Useless Code Useless Brackets 532
 MUCO 3 Useless Code Useless Brackets 534
 MUCO 3 Useless Code Useless Brackets 549
 MUCO 3 Useless Code Useless Brackets 556
 MUCO 3 Useless Code Useless Brackets 559
 MUCO 3 Useless Code Useless Brackets 597
 MUCO 3 Useless Code Useless Brackets 624
 MUCO 3 Useless Code Useless Brackets 643
 MUCO 3 Useless Code Useless Brackets 646
 MUCO 3 Useless Code Useless Brackets 671
 MUCO 3 Useless Code Useless Brackets 712
 MUCO 3 Useless Code Useless Brackets 717
 MUCO 3 Useless Code Useless Brackets 728
 MUCO 3 Useless Code Useless Brackets 736
 MUCO 3 Useless Code Useless Brackets 758
 MUCO 3 Useless Code Useless Brackets 775
 MUCO 3 Useless Code Useless Brackets 779
 MUCO 3 Useless Code Useless Brackets 796
 MUCO 3 Useless Code Useless Brackets 811
 MUCO 3 Useless Code Useless Brackets 814
 MUCO 3 Useless Code Useless Brackets 833
 MUCO 3 Useless Code Useless Brackets 840
 MUCO 3 Useless Code Useless Brackets 865
 MUCO 3 Useless Code Useless Brackets 886
 MUCO 3 Useless Code Useless Brackets 889
 MUCO 3 Useless Code Useless Brackets 900
 MUCO 3 Useless Code Useless Brackets 904
 MUIN 3 Column created using implicit nullability 185
 MUIN 3 Column created using implicit nullability 191
 MUIN 3 Column created using implicit nullability 197
 QCTC 3 Conditional Table Creation 265
 QISO 3 Set isolation level 124
 QJWT 3 Join or Sarg Without Index on temp table 278
 QJWT 3 Join or Sarg Without Index on temp table 279
 QNAJ 3 Not using ANSI Inner Join 271
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysmessages.ncsysmessages unique
(error, dlevel, langid)
Intersection: {error, langid}
210
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: sysobjects.ncsysobjects unique
(name, uid)
Intersection: {name}
656
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
751
 QPRI 3 Join or Sarg with Rooted Partial Index Use SARG Candidate index: syscolumns.csyscolumns unique clustered
(id, number, colid)
Intersection: {id}
764
 VNRD 3 Variable is not read @db_rep_level_all 145
 VNRD 3 Variable is not read @db_rep_level_l1 146
 VNRD 3 Variable is not read @sptlang 213
 VNRD 3 Variable is not read @owner 299
 VNRD 3 Variable is not read @gp_enabled 464
 VNRD 3 Variable is not read @dummy 484
 VNRD 3 Variable is not read @current_mode 573
 VUNU 3 Variable is not used @procval 78
 VUNU 3 Variable is not used @col_name 100
 VUNU 3 Variable is not used @db_rep_level_none 105
 MSUB 2 Subquery Marker 209
 MSUB 2 Subquery Marker 320
 MSUB 2 Subquery Marker 655
 MTR1 2 Metrics: Comments Ratio Comments: 41% 34
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 69 = 86dec - 19exi + 2 34
 MTR3 2 Metrics: Query Complexity Complexity: 409 34

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_getmessage  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
   reads table master..syslanguages (1)  
   reads table sybsystemprocs..sysusermessages  
   reads table master..sysmessages (1)  
reads table sybsystemprocs..sysindexes  
read_writes table tempdb..#repdefmode (1) 
reads table master..sysmessages (1)  
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)  
writes table tempdb..#show_replicate_table (1) 
writes table sybsystemprocs..syscolumns  
read_writes table sybsystemprocs..sysobjects  
calls proc sybsystemprocs..sp_autoformat  
   writes table sybsystemprocs..sp_autoformat_rset_002 
   reads table master..syscolumns (1)  
   reads table master..systypes (1)  
   writes table sybsystemprocs..sp_autoformat_rset_004 
   writes table sybsystemprocs..sp_autoformat_rset_003 
   calls proc sybsystemprocs..sp_autoformat  
   read_writes table tempdb..#colinfo_af (1) 
   reads table tempdb..systypes (1)  
   writes table sybsystemprocs..sp_autoformat_rset_001 
   reads table tempdb..syscolumns (1)  
   calls proc sybsystemprocs..sp_namecrack  
   writes table sybsystemprocs..sp_autoformat_rset_005 
read_writes table tempdb..#indexmode (1) 
read_writes table tempdb..#primarykey (1) 
calls proc sybsystemprocs..sp_namecrack