{解析出sql语句}
function TFormgensqls(AdoCon:TADOConnection; pdelta: OleVariant; const ptablename pkeyfields: WideString): WideString;
var
i j: integer;
s s: string;
Cmdstr: string;
FieldList Keylist: TstringList;
Cdsupdate: TClientDataSet;
sqlstr: WideString;
ado: TADOQuery;
begin
if varisnull(pdelta) then
Exit;
Cdsupdate:=TClientDataSetCreate(nil);
Cdsupdatedata:=pdelta;
if not CdsupdateActive then
CdsupdateOpen;
try
FieldList:=TstringListCreate;
Keylist:=TstringListCreate;
KeylistDelimiter:=;
KeylistDelimitedText:=pkeyfields;
ado:=TADOQueryCreate(nil);
adoConnection:=AdoCon;
adosqlText:=select * from +ptablename+ where =;
adoOpen;
adoGetFieldNames(FieldList);
adoFree;
for i:= to FieldListCount do
if CdsupdateFindField(FieldList[i])<>nil then
CdsupdateFindField(FieldList[i])tag:=;
FieldListFree;
if CdsupdateRecordCount> then
begin
CdsupdateFirst;
s:=;
s:=;
while not CdsupdateEof do
begin
Cmdstr:=;
case CdsupdateUpdateStatus of
usUnmodified: //从原数据行取得修改条件
begin
s:=;
for j:= to KeylistCount do
begin
if s= then
s:=Keylist[j]+=+vartosql(Cdsupdate[Keylist[j]])
else
s:=s+ and +Keylist[j]+=+vartosql(Cdsupdate[Keylist[j]]);
end;
end;
usModified:
begin
s:=;
for i:= to CdsupdateFieldCount do
begin
if (not CdsupdateFields[i]isNull)and(CdsupdateFields[i]tag=) then
begin
if s= then
s:=Trim(CdsupdateFields[i]FieldName)+ = +vartosql(CdsupdateFields[i]value)
else
s:=s++Trim(CdsupdateFields[i]FieldName)+ = +vartosql(CdsupdateFields[i]value);
end;
end;
if s<> then
begin
Cmdstr:= update +ptablename+ set +s+ where +s;
end;
end;
usInserted:
begin
s:=;
s:=;
for i:= to CdsupdateFieldCount do
if (not CdsupdateFields[i]isNull)and(CdsupdateFields[i]tag=) then
begin
if s= then
begin
s:=Trim(CdsupdateFields[i]FieldName);
s:=vartosql(CdsupdateFields[i]value);
end
else
begin
s:=s++Trim(CdsupdateFields[i]FieldName);
s:=s++vartosql(CdsupdateFields[i]value);
end;
end;
if s<> then
begin
Cmdstr:= Insert into +ptablename+(+s+) values(+s+);
end;
end;
usDeleted:
begin
s:=;
for j:= to KeylistCount do
begin
if s= then
s:=Keylist[j]+=+vartosql(Cdsupdate[Keylist[j]])
else
s:=s+ and +Keylist[j]+=+vartosql(Cdsupdate[Keylist[j]]);
end;
Cmdstr:=Delete +ptablename+ where +s;
end;
end;
if Cmdstr<> then
sqlstr:=sqlstr+Cmdstr+;+chr()+chr();
CdsupdateNext;
end;
end;
finally
Cdsupdateclose;
CdsupdateFree();
end;
Result:=sqlstr;
end;