May 16, 2012

sp_MSgetrowmetadata (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_MSgetrowmetadata(int @tablenick
, uniqueidentifier @rowguid
, uniqueidentifier @pubid
, int @compatlevel)

MetaData:

   
create procedure sys.sp_MSgetrowmetadata
(@tablenick int,
@rowguid uniqueidentifier,
@generation bigint output,
@type tinyint output,
@lineage varbinary(311) output,
@colv varbinary(2953) output,
@pubid uniqueidentifier = NULL,
@compatlevel int = 10) -- backward compatibility level, default=Sphinx
as
declare @retcode smallint
declare @rc int
declare @procname nvarchar(270)

--
-- To public.
--

if (@tablenick is null)
begin
RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSgetrowmetadata')
return (1)
end

-- security check
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick=@tablenick, @pubid = @pubid
if @@error <> 0 or @retcode <> 0
return 1

if (@rowguid is null)
begin
RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSgetrowmetadata')
return (1)
end

set @type= 4
set @generation= 0
set @lineage= NULL
set @colv= NULL

select @procname= 'dbo.' + select_proc from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid

-- check for row in base table
exec @retcode= @procname @maxschemaguidforarticle = NULL, @type=@type output, @rowguid=@rowguid
if @@error <>0 or @retcode <> 0
begin
return (1)
end

begin tran
if (@type = 3)
begin
if @compatlevel < 90
begin
declare @iscoltracked int
declare @cCols int
set @iscoltracked= sys.fn_fIsColTracked(@tablenick)
if @iscoltracked = 1
begin
set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
end
end

-- row is in base table; check whether it is in contents, too
--
-- serializable makes sure row does not go from tombstone to contents between
-- querying contents and tombstone, which would falsely result in type = missing
select @type= 2, @generation= generation,
@lineage= case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end,
@colv= case when @compatlevel >= 90 or @iscoltracked = 0 then colv1 else {fn COLV_90_TO_80(colv1, @cCols)} end
from dbo.MSmerge_contents
with (serializable)
where tablenick = @tablenick and rowguid = @rowguid
end
else
begin
-- row is not in base table; either it is in tombstone, or it is missing
set @type= 0

select @type= type, @generation= generation,
@lineage= case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end
from dbo.MSmerge_tombstone where
tablenick = @tablenick and rowguid = @rowguid
end
commit tran

return (0)

No comments:

Post a Comment

Total Pageviews