to track the modified rows and manually update fro

2019-06-28 08:23发布

Is there any way to manually track the changes done to a clientdataset's delta and update the changes manually on to then db. i have dynamically created a clientdataset and with out a provider i am able to load it with a tquery, now user will do some insert update and delete operations on the data available in the cds, and at final stage these data(modified) should be post in to database by using a tquery(not apply updates)..

2条回答
2楼-- · 2019-06-28 09:17
Change:= TPacketDataSet.create;

Change.Data:= YourClientDataSet.Delta;
while not Change.Eof do
begin
 Change.InitAltRecBuffers(False);
 if Change.UpdateStatus = usUnmodified then
   Change.InitAltRecBuffers(True);

 case Change.UpdateStatus of
  usModified:  ;//your logic read codes in Provider.pas for further hint
  usInserted:  ;//your logic read codes in Provider.pas for further hint
  usDeleted: ;//your logic read codes in Provider.pas for further hint
 end;

 Change.Next;
end;

Above should work regardless of number of modified Cheers Pham

查看更多
地球回转人心会变
3楼-- · 2019-06-28 09:18

After populating your data set from the TQuery call MergeChangeLog so that the records do not stand out as newly inserted, and be sure that LogChanges is set.

Then when at the final stage, before updating the query with the dataset, set StatusFilter so that only the records that you want to take action on should be showing. For instance;

ClientDataSet1.StatusFilter := [usDeleted];

You can also use UpdateStatus on a record to see if it has been modified etc..

But be careful that, is seems that there will be multiple versions of a record, and it is a bit difficult to understand how the "change log" keeps track. And there also can be multiple actions on a record, like modifying it a few times and then deleting it.

查看更多
登录 后发表回答