function tdsserver.updatecompany(delta: olevariant;
var msg: widestring): integer;
var
cdstemp: tclientdataset;
i, tempint: integer;
cmdinsert, cmddelete, cmdupdate: tadocommand;
sname, chmsg: string;
tempstr: widestring;
begin
adoconnds.errors.clear; //for catch the error
cdstemp := tclientdataset.create(self);
cmdinsert := tadocommand.create(self);
cmddelete := tadocommand.create(self);
cmdupdate := tadocommand.create(self);
cmdinsert.connection := adoconnds;
cmddelete.connection := adoconnds;
cmdupdate.connection := adoconnds;
result := 0;
cmdupdate.commandtext := update company set
+ scompanyname = :scompanyname,
+ sheadname = :sheadname, sheadtelnum = :sheadtelnum,ckind=:ckind,
+ ctype = :ctype,tsurvey = :tsurvey where scompanyid = :old_scompanyid;
cmddelete.commandtext := delete from company where scompanyid = :old_scompanyid;
cmdinsert.commandtext := insert into company
+ (scompanyid, scompanyname, sheadname, sheadtelnum,ckind,ctype, tsurvey)
+ values(:scompanyid, :scompanyname, :sheadname, :sheadtelnum,:ckind,:ctype, :tsurvey);
adoconnds.begintrans;
try
try
cdstemp.data := delta;
cdstemp.first;
while not cdstemp.eof do
begin
case cdstemp.updatestatus of
usunmodified:
begin
for i := 0 to cmdupdate.parameters.count - 2 do
begin
sname := cmdupdate.parameters.items[i].name;
cmdupdate.parameters.items[i].value :=
cdstemp.fieldbyname(sname).value;
end;
cmdupdate.parameters.parambyname(old_scompanyid).value :=
cdstemp.fieldbyname(scompanyid).value;
end;
usmodified:
begin
for i := 0 to cmdupdate.parameters.count - 2 do
begin
if not (cdstemp.fieldbyname(cmdupdate.parameters.items[i].name).isnull ) then
begin
sname := cmdupdate.parameters.items[i].name;
cmdupdate.parameters.items[i].value :=
cdstemp.fieldbyname(sname).value;
end;
end;
cmdupdate.execute;
end;
usinserted:
begin
for i := 0 to cmdinsert.parameters.count - 1 do
begin
sname := cmdinsert.parameters.items[i].name;
cmdinsert.parameters.items[i].value :=
cdstemp.fieldbyname(sname).value;
end;
cmdinsert.execute;
end;
usdeleted:
begin
cmddelete.parameters.parambyname(old_scompanyid).value :=
cdstemp.fieldbyname(scompanyid).value;
cmddelete.execute;
end;
end;
cdstemp.next;
end;
adoconnds.committrans;
except
adoconnds.rollbacktrans;
catchadoerror(tempint, tempstr, chmsg);
msg := tempstr;
result := tempint;
end;
finally
cdstemp.free;
cmdinsert.free;
cmddelete.free;
cmdupdate.free;
end;
end;
该函数中的delta是一个临时表,是clientdataset.delta,是返回的一个临时表!
ClientDataset作为缓存提交数据,后台分析并存储数据
最新推荐文章于 2020-11-26 00:51:23 发布