To track changed rows and manually update from Delta TClientDataSet

Is there a way to manually track the changes made for the delta client and update the changes manually, then db. I dynamically created a clientdataset and without a provider to which I can download it using tquery, now the user will perform some operations to update and remove the data insertion available in the CDs, and at the last stage this data (changed) should be sent to the database using tquery (do not apply updates).

+4
source share
2 answers

After filling in the dataset from the TQuery MergeChangeLog call so that the records do not stand out as recently inserted, and make sure LogChanges installed.

Then, when in the last step, before updating the query using the dataset, set the StatusFilter so that only the records you want to take are displayed. For instance,

 ClientDataSet1.StatusFilter := [usDeleted]; 

You can also use UpdateStatus in a record to find out if it has been modified, etc.

But be careful, it seems that there will be several versions of the record, and it’s a little difficult to understand how the change log is tracked. And there can also be several actions on the record, for example, changing it several times, and then deleting it.

+5
source
 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 the number of changed cheers fam

0
source

Source: https://habr.com/ru/post/902341/


All Articles