TClientDataSet and processing records with StatusFilter
Asked Answered
C

0

7

I'm using a TClientDataSet as a local dataset without the provider concept. After working with it a method is called that should generate the corresponding SQL statements using the StatusFilter to resolve the changes (generate SQL basically).

This looked easy initially after reading documentation (set StatusFilter to [dsInsert], process all inserts SQL, set StatusFilter to [dsModified] process all updates, the same with deletes) but after a few tests now looks far from trivial, for example:

If I add a record, then edit it: setting the StatusFilter to [dsInserted] displays it, but with the original data.

If I add a record, then edit, then delete it: the record appears with StatusFilter set to [dsInserted] and [dsModified] also.

And other similar situations..

1) I know that if first I process all inserts, then all updates then all deletes the database will be updated in the correct state but it looks far from right this approach (generating useless sql statements).

2) I've tried to access the PRecInfo(ClientDataSet.ActiveBuffer + ClientDataSet.RecordSize).Attribute information (dsRecNew, dsRecOrg, etc.) but still not manage to resolve the logic.

3) I can program the logic to resolve it, for example before processing and insert, set StatusFilter to [dsDeleted], and locating by the primary key if the record to see if its deleted thereafter.. the same with edits, before inserting, checking if the record was updated after so the insert sql in the updated version and so on.. but it should be more easy..

¿Did someone tried to solve this in an elegant and straightforward way? ¿I'm missing something? Thanks

Cardoon answered 24/11, 2011 at 23:31 Comment(7)
Strongly related: to track the modified rows and manually update from the TClientDataSet's Delta. Have to read the comments to the answers to make some some sense out of that thread though, might not be fun..Extinguish
@SertacAkyuz: the problem it's stated but not resolved in that question.. I'm precisely asking how to deal with the "multiple records versions" that you mencion in your comment..Cardoon
Well, it seems to have been resolved to me (even if in the comments) ... (you've clicked the "add / show 10 more comments"link?)Extinguish
@SertacAkyuz I have read them all, I think you mean principally your comment that starts with "In the final stage..". There you are processing all the records like in point 1 of my question, the "dumb but works approach" let's say. For example I you insert a record, then delete it you are processing the insert and the delete, when in reality there should be nothing to do. Do you understand my point? ThanksCardoon
You are not mistaken in your approach, the cache is literally that, everything you do is being kept in the buffer until it is committed. The end result in the database is correct, but you are also correct in stipulating that the posts will include data you have inserted then deleted.Acre
Have you tried cdsName.Post after making your changes?Eldwen
@Eldwen this is a 6 years old question.. to be honest I don't work with Delphi / Windows anymore for a long long time (and hope never going back).Cardoon

© 2022 - 2024 — McMap. All rights reserved.