Thanks for the explanation, anyway with your Approach there is a problem that with my is not there.
Imagine in the table I have initially 2 records, i mean doing MSQuery.Open initially returns: (let's do the case of a simple query with name and age)
John, 34
Mary, 23
now if in DBGrid I Replace John with Johnny so MSQuery contains now:
Johnny, 34 -- I MODIFIED THIS!
Mary, 23
So now I take the savepoint:
Code: Select all
//savepoint using two TVirtualTable
oldUpdateRecordTypes := MSQuery.UpdateRecordTypes;
MSQuery.UpdateRecordTypes := [rtDeleted];
VirtualTable1.Assign(MSQuery); // VirtualTable1 contains only the records which were deleted
MSQuery.UpdateRecordTypes := [rtModified, rtInserted];
VirtualTable2.Assign(MSQuery); // VirtualTable1 contains only the records which were inserted or updated
MSQuery.UpdateRecordTypes := oldUpdateRecordTypes;
At this moment VirtualTable1 contains NOTHING and VirtualTable2 contains:
Johnny, 34
Now by running your code to restore savepoint:
Code: Select all
MSQuery.CancelUpdates; // all changes are undone here
Now MSQUery contains the original values:
John, 34
Mary, 23
And now I use CRBatchMove for deleted records:
Code: Select all
CRBatchMove1.Mode := bmDelete;
CRBatchMove1.Source := VirtualTable1;
CRBatchMove1.Destination := MSQuery;
CRBatchMove1.Execute
but this does nothing. TO WORK IT SHOULD DELETE John, 34 but it doesn't. -- THIS IS THE PROBLEM
Now MSQuery (UNFORTUNATELY) still has:
John, 34
Mary, 23
When i use CRBatchMove for updated records I got the record I modified but the final result is:
John, 34 -- THIS SHOULD NOT BE HERE!!! (savepoint should contain Johnny and Mary only)
Mary, 23
Johnny, 34
So my code is terrible in performance, but it is a workaround I found.
The problem is that the record I modified from John to Johnny is not considered a deleted record.
How your example should be modified to take care of this so that I can discard my workaround? Thanks.