Search code examples
delphidelphi-2010tclientdatasetmidas-server

Handling update errors in multiple records in the TClientDataset's ReconcileError method


I'm trying to use the ReconcileError event to allow the user to correct the data after an update error which occurred in a specific record among others.

Example:

I have a dataset with one field and 3 records, this field have a unique constraint on the database, then I change one value to conflict when it reaches the database, then I call ApplyUpdates on the Dataset.

This will generate an error (violation of unique constraint) in the provider and abort the applyupdates process, returning raAbort in the Action var of the ReconcileError method.

In the ReconcileError method I tryied to use:

Action := HandleReconcileError(aDataSet, UpdateKind, E); 

** EDIT **

After debugging and dumping the DataSet records which were returned from the server, I noticed that there are 2 records in this Dataset, the first is the Old record and the second have all the changes I made to the first record.

I'm a bit confused, will I always get this DataSet with 2 records? I thought that it should have only one record with the Old/New values.

Thanks.


Solution

  • After a bit of debugging and reading I figured out the following:

    • The OnReconcileError is called for each Record that couldn't be applyied and a DataSet is created for each.
    • This DataSet have 2 records when the UpdateKind is ukModify, one record as usUnModified (the original record) and the second record as usModified (All the modifications are in this second record)
    • When the change is ukInsert or ukDelete the DataSet have just one record
    • This DataSet should not be changed, as this is just a temporary dataset created so you can read the data
    • The reconcile dialog just isn't working as expected, as it never shows the correct values of the modified record (Delphi 2010 bug?)