create procedure sys.sp_MScreate_article_repl_view
@pubid uniqueidentifier,
@artid uniqueidentifier
as
begin
declare @artid_str nvarchar(50)
, @pubid_str nvarchar(50)
, @retcode int
, @repl_view_name nvarchar(260)
, @repl_view_id int
, @qualified_table_name nvarchar(270)
, @cmd nvarchar(max)
, @source_objid int
exec @retcode=sys.sp_MSguidtostr @artid, @artid_str output
if @retcode<>0 or @@ERROR<>0 return (1)
exec @retcode=sys.sp_MSguidtostr @pubid, @pubid_str output
if @retcode<>0 or @@ERROR<>0 return (1)
select @repl_view_name = 'dbo.MSmerge_repl_view_' + @pubid_str + '_' + @artid_str
if object_id(@repl_view_name) is not null
begin
exec ('drop view ' + @repl_view_name)
if @@ERROR<>0 return (1)
end
select @qualified_table_name =
(select quotename(SCHEMA_NAME(o.schema_id)) from sys.objects o where o.object_id = v.objid) + '.' +
quotename(object_name(v.objid)),
@source_objid = v.objid
from dbo.sysmergepartitioninfoview v
where v.artid = @artid
and v.pubid = @pubid
-- the following will be true for a light weight subscription
if @qualified_table_name is NULL
return 0
select @cmd = 'create view ' + @repl_view_name + ' as select * from ' + @qualified_table_name +
' where ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 or permissions(' + convert(nvarchar(12),@source_objid) + ') & 0x1b <> 0)'
exec (@cmd)
if @@ERROR<>0
begin
select @retcode = 1
goto FAILURE
end
exec ('grant select on ' + @repl_view_name + ' to public')
if @@ERROR<>0
begin
select @retcode = 1
goto FAILURE
end
execute dbo.sp_MS_marksystemobject @repl_view_name
if @@ERROR<>0
begin
select @retcode = 1
goto FAILURE
end
update dbo.sysmergepartitioninfo set repl_view_id = object_id (@repl_view_name)
where pubid = @pubid and artid = @artid
select @retcode = 0
FAILURE:
return @retcode
end