select@i=count(1)fromsysobjectswherename=@objectName
if@i=0
begin
printObject+@objectName+isntexist!--工具不存在
return
end
select@type=casextypewhenTRthenTelsextypeendfromsysobjectswherename=@objectName
if(@typeTand@typeVand@typeP)
begin
printObject+@objectName+isntprocedureortriggerorview!--没有所必要的工具范例
return
end
select@bb=encryptedFROMsyscommentsWHEREid=object_id(@objectName)
select@m=max(colid)FROMsyscommentsWHEREid=object_id(@objectName)
if@bb=0
begin
printObject+@objectName+isnotencrypted!--工具没有加密
return
end
createtable#temp(colidint,ctextvarbinary(8000))
createtable#tempresult(cctextnvarchar(4000))
insert#tempSELECTcolid,ctextFROMsyscommentsWHEREid=object_id(@objectName)--getencrypteddata将加密信息存储于一时表中
IF@type=T--假如是触发子,则获得它的表名和范例
BEGIN
SET@tablename=(SELECTsysobjects_1.nameFROMdbo.sysobjectsINNERJOINdbo.sysobjectssysobjects_1ONdbo.sysobjects.parent_obj=sysobjects_1.idWHERE(dbo.sysobjects.type=TR)AND(dbo.sysobjects.name=@ObjectName))
SET@trigtype=(SELECTCASEWHENdbo.sysobjects.deltrig>0THENDELETEWHENdbo.sysobjects.instrig>0THENINSERTWHENdbo.sysobjects.updtrig>0THENUPDATEENDFROMdbo.sysobjectsINNERJOINdbo.sysobjectssysobjects_1ONdbo.sysobjects.parent_obj=sysobjects_1.idWHERE(dbo.sysobjects.type=TR)AND(dbo.sysobjects.name=@ObjectName))
END
SET@sql1=case@type--为修正原本的工具内容筹办ALTER语句
WHENPTHENALTERPROCEDURE+@ObjectName+WITHENCRYPTIONAS
WHENVTHENALTERVIEW+@ObjectName+WITHENCRYPTIONASSELECTdbo.dtproperties.*FROMdbo.dtproperties
WHENTTHENALTERTRIGGER+@ObjectName+ON+@tablename+WITHENCRYPTIONFOR+@trigtype+ASPRINTa
END
set@q=len(@sql1)
set@sql1=@sql1+REPLICATE(-,4000-@q)
select@sql2=REPLICATE(-,4000),@sql3=REPLICATE(-,4000),@sql4=REPLICATE(-,4000),@sql5=REPLICATE(-,4000),@sql6=REPLICATE(-,4000),@sql7=REPLICATE(-,4000),@sql8=REPLICATE(-,4000),@sql9=REPLICATE(-,4000),@sql10=REPLICATE(-,4000)
exec(@sql1+@sql2+@sql3+@sql4+@sql5+@sql6+@sql7+@sql8+@sql9+@sql10)
select@sql1=,@sql2=,@sql3=,@sql4=,@sql5=,@sql6=,@sql7=,@sql8=,@sql9=,@sql10=
set@n=1--从编号为1入手下手
while@n<=@m
begin
SET@OrigSpText1=(SELECTctextFROM#tempWHEREcolid=@n)--从一时表中取加密数据
SET@OrigSpText3=(SELECTctextFROMsyscommentsWHEREid=object_id(@objectName)andcolid=@n)--从修正过的工具获得工具数据
if@n=1--假如是第一次轮回,则必要筹办后面的开首部分的语句
begin
SET@OrigSpText2=case@type
WHENPTHENCREATEPROCEDURE+@ObjectName+WITHENCRYPTIONAS
WHENVTHENCREATEVIEW+@ObjectName+WITHENCRYPTIONASSELECTdbo.dtproperties.*FROMdbo.dtproperties
WHENTTHENCREATETRIGGER+@ObjectName+ON+@tablename+WITHENCRYPTIONFOR+@trigtype+ASPRINTa
END
set@q=4000-len(@OrigSpText2)
set@OrigSpText2=@OrigSpText2+REPLICATE(-,@q)
end
else
begin
SET@OrigSpText2=REPLICATE(-,4000)
end
SET@i=1
SET@resultsp=replicate(NA,(datalength(@OrigSpText1)/2))--filltemporaryvariable
WHILE@i<=datalength(@OrigSpText1)/2
BEGIN
--reverseencryption(XORoriginal+bogus+bogusencrypted)
SET@resultsp=stuff(@resultsp,@i,1,NCHAR(
UNICODE(substring(@OrigSpText1,@i,1))^
(
UNICODE(substring(@OrigSpText2,@i,1))^UNICODE(substring(@OrigSpText3,@i,1))
)
)
)
SET@i=@i+1
END