We just upgraded our software from Delphi 2009 to Alexandria, and it broke in some places, always related to nested clientdatasets.
For instance, I just traced the error
Record not found or changed by another user
received from a delete attempt. The main dataset contains 3 child datasets - let's call them A, B, and C. Clientdatasets B & C are "pointing" at the same physical table on our SQL server.
In Data.Win.ADODB
, TCustomADODataSet.PSExecute
, I can see the generated delete statements come in with their respective parameters:
- Record(s) from table A get deleted, and in DataSnap.Provider, TSQLResolver.DoExecSQL I see that RowsAffected is <> 0
- Record(s) from table B get deleted, and in DataSnap.Provider, TSQLResolver.DoExecSQL I see that RowsAffected is <> 0
- Record(s) from table C get deleted ???, and in DataSnap.Provider, TSQLResolver.DoExecSQL I see that RowsAffected is 0 and the 'Record not found or changed by another user' exception is triggered.
I assume this happens because 3) Table C attempts to delete the same record that just deleted for table B - thus the record cannot be found and the exception occurs.
My question: Short of rewiring much of the data module containing all these tables, is there an easier/preferred way to say "It is OK if deletes on table C fail" so that the whole master table delete goes through?
TDataSetProvider.ResolveToDataSet
and write your ownTDataSetProvider.BeforeUpdateRecord
event hander code. This would be specific to your application though, and nobody could write that code without knowing your database requirements. For guidance read Cary Jensen's books "Delphi in depth: Clientdatasets" (1st or 2nd edition)