开发者

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 ApplyUpdat开发者_如何学编程es 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.


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?)


The record passed to OnReconcileError or OnUpdateError is the record that couldn't have updates applied. According to the D2007 help file (note this is a help file link and not a web link!) - note the section regarding the DataSet parameter:

You should always code an OnReconcileError or OnUpdateError event handler, even if only to discard the records returned that could not be applied. The event handlers for these two events work the same way. They include the following parameters:

DataSet: A client dataset that contains the updated record which couldn't be applied. You can use this dataset's methods to get information about the problem record and to edit the record in order to correct any problems. In particular, you will want to use the CurValue, OldValue, and NewValue properties of the fields in the current record to determine the cause of the update problem. However, you must not call any client dataset methods that change the current record in your event handler.


In dbExpress you will find with TSQLConnection component, in the parameters an entry, Mars_Connection,which is set to False by default, set this to True and the error message is resolved

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜