May 29, 2012

sp_MSsetcontext_replagent (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData


sys.sp_MSsetcontext_replagent(tinyint @agent_type
, bit @is_publisher)


 create procedure sys.sp_MSsetcontext_replagent @agent_type tinyint, @is_publisher bit = 0  
declare @cur_context varbinary(128)
declare @cur_context_first_byte binary(1)
declare @bitmask tinyint

-- agent type: snapshot=1, logreader=2, distrib=3, merge=4
-- bit to set: snapshot=1, logreader=2, distrib=4, merge=8
select @bitmask = case
when @agent_type = 1 then 1
when @agent_type = 2 then 2
when @agent_type = 3 then 4
when @agent_type = 4 then 8

if @is_publisher = 1
select @bitmask = (@bitmask | 16)

select @cur_context = isnull(context_info(),0x00)

-- get the first byte out. the replication agent flags are set in the first byte.
select @cur_context_first_byte = substring(@cur_context, 1, 1)
-- set the appropriate bit in this one byte (leaving other bits unchanged).
select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
-- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
-- set the context_info again with the new binary(128) value.
set context_info @cur_context

if @@error <> 0
return 1

return 0

No comments:

Post a Comment

Total Pageviews