|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于insert操作,只需要把event_type改成DELETE_ROWS_EVENT;对于delete操作,改成WRITE_ROWS_EVENTselect|语句TBPROC
CREATEProcedureTbProc
@modelvarchar(2),@pagenamevarchar(32),@objectvarchar(32),@autoFieldvarchar(32)=null
as
setnocounton
select@model=upper(@model)
select@pagename=lower(@pagename)
select@object=upper(@object)
declare@headvarchar(100),@headfctvarchar(105),@paravarchar(1500),@contentvarchar(5000)
declare@paravarvarchar(2000),@saveStrvarchar(3000),@deleteStrvarchar(500),@selectFieldStrvarchar(1000),@returnPkvarchar(250),@pkeyStrvarchar(500),@pkeyParaStrvarchar(500)
select@head=,@headfct=,@para=,@content=
execTbField@object,@autofield,@paravaroutput,@saveStroutput,@deleteStroutput,@selectFieldStroutput,@pkeyStroutput,@pkeyParaStroutput
select@head=createprocedurep+@model+@pagename+_
--Head
print注重:单元换算和泉币换算都是在存储历程里完成!
--Sav
select@headfct=@head+Sav
select@para=@paravar
select@content=@saveStr
select@headfct+char(13)+@para+char(13)+as+char(13)+@content+char(10)+char(13)+GO+char(13)
--Tree
select@para=
select@headfct=@head+Tree
select@content=@selectFieldStr
select@headfct+char(13)+@para+char(13)+as+char(13)+@content+char(10)+char(13)+GO+char(13)
--Del
select@headfct=@head+Del
select@para=@pkeyParaStr
--test
--select@paravar,charindex(@IsValid,@paravar)
ifcharindex(IsValid,@selectFieldStr)>0
select@deleteStr=replace(replace(@deleteStr,delete,update),where,setIsValid=0where)
select@content=@deleteStr
select@headfct+char(13)+@para+char(13)+as+char(13)+@content+char(10)+char(13)+GO+char(13)
--Back
select@headfct=@head+Back
select@content=@selectFieldStr
select@headfct+char(13)+@para+char(13)+as+char(13)+@content+char(10)+char(13)+GO+char(13)
GO
TbField
CREATEprocedureTbField
@objectvarchar(32),@autofieldvarchar(32),@stringvarchar(2000)output,@saveStrvarchar(3000)output,@deleteStrvarchar(500)output,@selectFieldStrvarchar(1000)output,@pkeyStrvarchar(500)output,@pkeyParaStrvarchar(500)output
as
setnocounton
select@object=upper(@object)
declare@nameStrvarchar(1000),@varStrvarchar(1000),@updStrvarchar(1500),@pkeyvarStrvarchar(500)--,@pkeyParaStrvarchar(150),@pkeyStrvarchar(250)作为了输入参数
select@string=,@nameStr=,@varStr=,@updStr=,@pkeyvarStr=,@pkeyStr=,@pkeyParaStr=
declare@moneyStrvarchar(500)
select@moneyStr=
declare@ismallint
select@i=1
declare@fieldtbtable(pkintidentity,fieldvarchar(32))
declare@attrtbtable(fieldvarchar(32),typenamevarchar(32),lengthsmallint)
declare@fieldvarchar(32)
declarecurfieldcursorfor
selectnamefromsyscolumnswhereid=object_id(@OBJECT)
opencurfield
fetchnextfromcurfieldinto@field
while@@fetch_status=0
begin
insert@fieldtb(field)values(@field)
select@nameStr=@nameStr++@field+,
select@varStr=@varStr+@+@field+,
select@updStr=@updStr+@field+=@+@field+,
iflen(@updStr)>@i*100
begin
select@updStr=@updStr+char(13)+char(9)+char(9)
select@i=@i+1
end
fetchnextfromcurfieldinto@field
end
closecurfield
deallocatecurfield
insert@attrtb
selectdistinctc.name,replace(replace(d.type_name,identity,),(),),c.length
fromsyscolumnsc
innerjoinmaster.dbo.spt_datatype_infodonc.xtype=d.ss_dtype
wherec.id=object_id(@OBJECT)
-----select*from@attrtb--测试
select@i=1
declare@typenamevarchar(32),@lengthvarchar(5)
declarerecordcursorfor
selecta.*
from@fieldtbfinnerjoin@attrtbaonf.field=a.field
orderbyf.pk
openrecord
fetchnextfromrecordinto@field,@typename,@length
while@@fetch_status=0
begin
if@typenamenotin(varchar,nvarchar,char,nchar,text,ntext)
begin
select@length=case@typenamewhensmalldatetimethen10
whendatetimethen32
whenbitthen1
else16
end
if@typenamein(money,smallmoney)
select@moneyStr=@moneyStr+@+@field+__+@typename+,
select@typename=varchar
end
select@string=@string+@+@field++@typename+(+@length+)+,
iflen(@string)>@i*128
begin
select@string=@string+char(13)
select@i=@i+1
end
fetchnextfromrecordinto@field,@typename,@length
end
closerecord
deallocaterecord
--Aboutpkeys
declare@pkeytbtable(fieldvarchar(32))
insert@pkeytb
selectc.name
fromsyscolumnscinnerjoinsysindexesionc.id=i.id
wherec.id=object_id(@object)and(i.status&0x800)=0x800
and(c.name=index_col(@object,i.indid,1)or
c.name=index_col(@object,i.indid,2)or
c.name=index_col(@object,i.indid,3)or
c.name=index_col(@object,i.indid,4)or
c.name=index_col(@object,i.indid,5)or
c.name=index_col(@object,i.indid,6)or
c.name=index_col(@object,i.indid,7)or
c.name=index_col(@object,i.indid,8)or
c.name=index_col(@object,i.indid,9)or
c.name=index_col(@object,i.indid,10)or
c.name=index_col(@object,i.indid,11)or
c.name=index_col(@object,i.indid,12)or
c.name=index_col(@object,i.indid,13)or
c.name=index_col(@object,i.indid,14)or
c.name=index_col(@object,i.indid,15)or
c.name=index_col(@object,i.indid,16)
)
if(selectcount(*)from@pkeytb)>1
begin
declarecurpkeyscursorfor
selectfieldfrom@pkeytb
opencurpkeys
fetchnextfromcurpkeysinto@field
while@@fetch_status=0
begin
select@pkeyvarStr=@pkeyvarStr+@field+=@+@field+and
select@pkeyStr=@pkeyStr+@field+,
select@i=charindex(@+@field,@string)
if@i>0select@pkeyParaStr=@pkeyParaStr+substring(@string,@i,charindex(,,@string,@i)-@i)+,
fetchnextfromcurpkeysinto@field
end
closecurpkeys
deallocatecurpkeys
select@pkeyvarStr=left(@pkeyvarStr,len(@pkeyvarStr)-3)
select@pkeyStr=left(@pkeyStr,len(@pkeyStr)-1)
select@pkeyParaStr=left(@pkeyParaStr,len(@pkeyParaStr)-1)
end
elseif(selectcount(*)from@pkeytb)=1
begin
select@field=fieldfrom@pkeytb
select@pkeyvarStr=@field+=@+@field
select@pkeyStr=@field
select@i=charindex(@+@field,@string)
if@i>0select@pkeyParaStr=substring(@string,@i,charindex(,,@string,@i)-@i)
end
ifright(@string,1)=char(13)
select@string=left(@string,len(@string)-2)
else
select@string=left(@string,len(@string)-1)
select@nameStr=left(@nameStr,len(@nameStr)-1)
select@varStr=left(@varStr,len(@varStr)-1)
select@varStr=replace(@varStr,@ModDate,getdate())
select@varStr=replace(@varStr,@IsValid,space(7)+1)
ifright(@updStr,1)=char(9)
select@updStr=left(@updStr,len(@updStr)-4)
else
select@updStr=left(@updStr,len(@updStr)-1)
select@updStr=replace(@updStr,@ModDate,getdate())
select@updStr=replace(@updStr,@IsValid,IsValid)
----处置@moneyStr
declare@covNameStrvarchar(1000)
select@covNameStr=@nameStr
if@moneyStr
BEGIN
declare@itemStrvarchar(50),@itemfieldvarchar(32),@itemtypevarchar(20),@covStrvarchar(50)
select@moneyStr=,+@moneyStr
select@moneyStr
select@i=1,@itemStr=substring(@moneyStr,@i+1,charindex(,,@moneyStr,@i+1)-@i-1)
while@itemStr
begin
select@itemfield=left(@itemStr,charindex(__,@itemstr)-1)
select@itemtype=right(@itemStr,len(@itemStr)-charindex(__,@itemStr)-1)
select@covStr=cast(+@itemfield+as+@itemtype+)
select@varStr=replace(@varStr,@itemfield,@covStr)
select@updStr=replace(@updStr,@itemfield,@covStr)
select@covNameStr=replace(@covNameStr,right(@itemfield,len(@itemfield)-1),space(len(@covStr)-len(@itemfield))+right(@itemfield,len(@itemfield)-1))
select@i=charindex(,,@moneyStr,@i+1)
if@i=len(@moneyStr)
break
elseselect@itemStr=substring(@moneyStr,@i+1,charindex(,,@moneyStr,@i+1)-@i-1)
end
END
--------------------
declare@insertStrvarchar(2000),@updateStrvarchar(2000),@selectStrvarchar(500)--,@deleteStrvarchar(500)作为了输入参数
declare@returnPkvarchar(250)--,@selectFieldStrvarchar(1000)作为了输入参数
if@autofieldisnull
select@insertStr=char(9)+insert+@object+(+@covNameStr+)+char(13)+char(9)+values+space(len(@object))+(+@varStr+)
else
select@insertStr=space(3)+begin+char(13)+char(9)+declare@countint+char(13)+char(9)+select@count=count(*)from+@object+wheresubstring(+@autofield+,3,4)=convert(varchar(4),getdate(),12)+char(13)+char(9)+select@+@autofield+=XX+convert(varchar(4),getdate(),12)+cast(@count+1asvarchar(16))+char(13)+char(13)+char(9)+insert+@object+(+@covNameStr+)+char(13)+char(9)+values+space(len(@object))+(+@varStr+)+char(13)+space(3)+end
select@updateStr=char(9)+update+@object+char(13)+char(9)+set+@updStr+char(13)+char(9)+where+@pkeyvarStr
select@deleteStr=delete+@object+where+@pkeyvarStr
select@selectStr=select*from+@object+where+@pkeyvarStr
select@returnPk=select@+replace(@pkeyStr,,,,@)
ifcharindex(IsValid,@covNameStr)>0
select@selectFieldStr=IsValid=1and
else
select@selectFieldStr=
select@selectFieldStr=select+@nameStr+from+@object+where+@selectFieldStr+@pkeyvarStr
--declare@saveStrvarchar(3000)作为了输入参数
--select@moneyStr=stuff(@moneyStr,len(@moneyStr),1,char(10)+char(13))
select@saveStr=ifnotexists(+@selectStr+)+char(13)+@insertStr+char(13)+else+char(13)+@updateStr+char(10)+char(13)+@returnPk
ifcharindex(@IsValid,@string)>0
select@string=replace(@string,,@IsValidvarchar(1),)
ifcharindex(,+char(13)+@IsValid,@string)>0
select@string=replace(@string,,+char(13)+@IsValidvarchar(1),)
ifcharindex(,+char(13)+@ModDate,@string)>0
select@string=replace(@string,,+char(13)+@ModDatevarchar(32),)
ifcharindex(,@ModDate,@string)>0
select@string=replace(@string,,@ModDatevarchar(32),)
/*
select@string
select@pkeyParaStr
select@saveStr
--select@insertStr
--select@updateStr
select@deleteStr
--select@selectStr
select@selectFieldStr
*/因此我们看到,这些信息足够让我们对单个操作实现“逆操作”。 |
|