请教中间层有代码如何进行更新?(16分)

  • 主题发起人 主题发起人 jesse-zxw
  • 开始时间 开始时间
J

jesse-zxw

Unregistered / Unconfirmed
GUEST, unregistred user!
请问中间层如何解析客户端传过来的数据(clientdataset.delta)?
如何用代码更新到数据库中?
中代在码更新数据时如何知道数据被其他用户修改了?
这种情况应该如何处理?
希望各位不要看到分了,我现在只有16分!
 
把clientdataset.delta赋值给另个clientdataset,连接个dbgrid,自己看下就明啦!
根据clientdataset的每条记录状态生成相应的sql语句!我就是这样更新的!
 
skyzerobase,谢谢你的回答!
可不可以给一点代码说明一下呀?
 
这是我在中间层的更新函数!
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;
 
对于主从表该如何分解,还望次教!!
 
后退
顶部