这是我在中间层的更新函数!
function huan(str:string):string;
var
oldstr,newstr,str2:string;
replaceflag:TReplaceFlags;
begin
oldstr:='''';
//单引号
newstr:=''''+'''';
//双引号
Include(replaceflag,rfReplaceAll);
str2:=StringReplace(str,oldstr,newstr,replaceflag);
result:=str2;
end;
function sstring(xx:tfield):string;
begin
case xx.DataType of
ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftLargeInt
:result:=xx.AsString;
ftDateTime, ftDate,ftwidestring,ftString:result:=''''+huan(xx.AsString)+'''';
end;
end;
procedure tijiao(deltax: OleVariant;firstid,biao:wideString);
var
zzz,za,jk:string;
xx:widestring;
i,j:integer;
mylist:tstringlist;
begin
za:='';
jk:='';
xx:='';
clientdataset1.Data:=deltax;
with clientdataset1do
begin
//with
if not IsEmpty then
begin
//1
first;
mylist:=tstringlist.Create;
try
while not eofdo
begin
//while
case UpdateStatus of //case
usInserted: begin
//case aa
zzz:='insert into '+biao+'(';
for i:=0 to FieldCount-1do
begin
//for2
if i=0 then
zzz:=zzz+Fields.FieldName
else
zzz:=zzz+','+Fields.FieldName;
end;
//for2
zzz:=zzz+')values(';
for i:=0 to FieldCount-1do
begin
//22
if (Fields.datatype=ftsmallint)and(Fields.value<>null) then
zzz:=zzz+inttostr(fields.asInteger)
else
if(Fields.datatype=ftInteger)and(Fields.value<>null) then
zzz:=zzz+inttostr(fields.asInteger)
else
if(Fields.datatype=ftfloat)and(Fields.value<>null) then
zzz:=zzz+floattostr(fields.asfloat)
else
if(Fields.datatype=ftboolean)and(Fields.value<>null) then
zzz:=zzz+floattostr(fields.value)
else
if (Fields.datatype=ftstring)and(Fields.value<>null) then
zzz:=zzz+''''+huan(fields.asstring)+''''
else
if (Fields.datatype=ftwidestring)and(Fields.value<>null) then
zzz:=zzz+''''+huan(fields.asstring)+''''
else
if (Fields.datatype=ftdatetime)and(Fields.value<>null) then
zzz:=zzz+''''+datetimetostr(fields.asdatetime)+''''
else
zzz:=zzz+'null';
if (i<(FieldCount-1)) then
zzz:=zzz+',';
end;
//22
zzz:=zzz+')';
xx:=xx+' '+zzz+#13;
end;
//case aa
usdeleted:begin
//case bb
xx:=xx+' Delete from '+biao+' where '+firstid+'='+sstring(fields[0])+#13;
end;
//case bb
usModified:begin
//case cc
za:='';
Prior;
za:=firstid+'='+sstring(fields[0]);
next;
for i:=0 to fields.Count-1do
begin
//do a
if not fields.IsNull then
begin
mylist.Add(fields.DisplayName+'='+sstring(fields));
end;
//
end;
//do a
for j:=0 to mylist.Count-1do
begin
//kkk
if j=0 then
jk:=jk+mylist.Strings[j]
else
jk:=jk+','+mylist.Strings[j];
end;
//kkk
mylist.Clear;
xx:=xx+' update '+biao+' set '+jk+' where '+za+#13;
jk:='';
end;
//case cc
end;
//case
Next;
end;
//while
mylist.Clear;
mylist.add(xx);
mylist.SaveToFile(ExtractFilePath(Application.ExeName)+'mm.txt');
tmp.Close;
tmp.sql.Clear;
for i:=0 to mylist.count-1do
begin
////for
tmp.sql.Add(mylist.strings);
if tmp.sql.count>50 then
begin
////50
tmp.execsql;
tmp.close;
tmp.sql.Clear;
end;
////50
end;
////for
if tmp.sql.count>0 then
begin
////0
tmp.execsql;
tmp.close;
end;
////0
finally//try
mylist.free;
end;
//try
end;
//1
end;
//with
end;