June 4, 2012

sp_MSupdate_subscriber_info (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

Definition:

sys.sp_MSupdate_subscriber_info(nvarchar @publisher
, nvarchar @subscriber
, tinyint @type
, nvarchar @login
, nvarchar @password
, int @commit_batch_size
, int @status_batch_size
, int @flush_frequency
, int @frequency_type
, int @frequency_interval
, int @frequency_relative_interval
, int @frequency_recurrence_factor
, int @frequency_subday
, int @frequency_subday_interval
, int @active_start_time_of_day
, int @active_end_time_of_day
, int @active_start_date
, int @active_end_date
, int @retryattempts
, int @retrydelay
, nvarchar @description
, int @security_mode)

MetaData:

 CREATE PROCEDURE sys.sp_MSupdate_subscriber_info  
(
@publisher sysname,
@subscriber sysname,
@type tinyint = NULL,
@login sysname = NULL,
@password nvarchar(524) = '%',
@commit_batch_size int = NULL,
@status_batch_size int = NULL,
@flush_frequency int = NULL,
@frequency_type int = NULL,
@frequency_interval int = NULL,
@frequency_relative_interval int = NULL,
@frequency_recurrence_factor int = NULL,
@frequency_subday int = NULL,
@frequency_subday_interval int = NULL,
@active_start_time_of_day int = NULL,
@active_end_time_of_day int = NULL,
@active_start_date int = NULL,
@active_end_date int = NULL,
@retryattempts int = NULL,
@retrydelay int = NULL,
@description nvarchar (255) = NULL,
@security_mode int = NULL
)
AS
begin
set nocount on

declare @cmd1 nvarchar (255)
declare @retcode int
declare @platform_nt binary

--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end

select @platform_nt = 0x1

IF (UPPER(@subscriber) = UPPER(@@SERVERNAME) and ( @platform_nt != platform() & @platform_nt ) and @security_mode = 1)
BEGIN
RAISERROR(21038, 16, -1)
goto FAILED
END


begin transaction
save transaction update_subscriber

-- Check if subscriber exists --
if not exists (select * from MSsubscriber_info
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber))
goto FAILED

if not exists (select * from MSsubscriber_schedule
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0)
goto FAILED

if @type is not NULL
update MSsubscriber_info set type = @type
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED

if @security_mode = 1
begin
-- set the password here to newid. by doing
-- this we will force a reset of the password
-- to an encrypted invalid password. the encryp
-- and storing of the password is below...

select @password = newid()

update MSsubscriber_info
set security_mode = 1,
login = N''
where UPPER(publisher) = UPPER(@publisher)
and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED
end
else if @security_mode = 0
begin
update MSsubscriber_info
set security_mode = 0
where UPPER(publisher) = UPPER(@publisher)
and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED
end
else if @security_mode is not NULL
begin
raiserror(14109, 16, -1)
goto FAILED
end

if @login is not NULL
begin
update MSsubscriber_info
set login = @login
where UPPER(publisher) = UPPER(@publisher)
and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED
end

if isnull(@password, '') <> '%'
begin
-- Encrypt the password
EXEC @retcode = sys.sp_MSreplencrypt @password OUTPUT
IF @@error <> 0 OR @retcode <> 0
goto FAILED

update MSsubscriber_info
set password = @password
where UPPER(publisher) = UPPER(@publisher)
and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED
end

if @frequency_type is not NULL
update MSsubscriber_schedule set frequency_type = @frequency_type
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @frequency_interval is not NULL
update MSsubscriber_schedule set frequency_interval = @frequency_interval
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @frequency_relative_interval is not NULL
update MSsubscriber_schedule set frequency_relative_interval = @frequency_relative_interval
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @frequency_recurrence_factor is not NULL
update MSsubscriber_schedule set frequency_recurrence_factor = @frequency_recurrence_factor
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @frequency_subday is not NULL
update MSsubscriber_schedule set frequency_subday = @frequency_subday
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @frequency_subday_interval is not NULL
update MSsubscriber_schedule set frequency_subday_interval = @frequency_subday_interval
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @active_start_time_of_day is not NULL
update MSsubscriber_schedule set active_start_time_of_day = @active_start_time_of_day
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @active_end_time_of_day is not NULL
update MSsubscriber_schedule set active_end_time_of_day = @active_end_time_of_day
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @active_start_date is not NULL
update MSsubscriber_schedule set active_start_date = @active_start_date
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @active_end_date is not NULL
update MSsubscriber_schedule set active_end_date = @active_end_date
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
if @@error <> 0
goto FAILED

if @description is not NULL
update MSsubscriber_info set description = @description
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED

if @security_mode is not NULL
update MSsubscriber_info set security_mode = @security_mode
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
if @@error <> 0
goto FAILED

commit transaction
return (0)

FAILED:
if @@trancount > 0
begin
rollback transaction update_subscriber
commit tran -- to finish off the tran we started in this proc (though
-- work was rolled back to savepoint)
end
return (1)
end

No comments:

Post a Comment

Total Pageviews