在 TClientDataset 的 ReconcileError 方法中处理多个记录中的更新错误

发布于 2024-08-31 23:09:22 字数 551 浏览 1 评论 0原文

我试图使用 ReconcileError 事件来允许用户在特定记录等发生更新错误后更正数据。

示例:

我有一个包含 1 个字段和 3 条记录的数据集,该字段对数据库有唯一约束,然后我更改一个值以使其在到达数据库时发生冲突,然后我对数据集调用 ApplyUpdates。

这将在提供程序中生成错误(违反唯一约束)并中止 applyupdates 进程,并在 ReconcileError 方法的 Action var 中返回 raAbort。

在 ReconcileError 方法中,我尝试使用:

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

** 编辑 **

在调试和转储从服务器返回的 DataSet 记录后,我注意到此 Dataset 中有 2 条记录,第一个是旧记录,第二个包含所有记录我对第一条记录所做的更改。

我有点困惑,我总是会得到这个有 2 条记录的 DataSet 吗?我认为它应该只有一条包含旧/新值的记录。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

在你怀里撒娇 2024-09-07 23:09:22

经过一番调试和阅读后,我得出以下结论:

  • 为每个无法应用的记录调用 OnReconcileError ,并为每个记录创建一个数据集。
  • 当UpdateKind为ukModify时,该DataSet有2条记录,一条记录为usUnModified(原始记录),第二条记录为usModified(所有修改都在第二条记录中)
  • 当更改为ukInsert或ukDelete时,DataSet只有一条
  • 记录不应更改数据集,因为这只是创建的临时数据集,以便您可以读取数据
  • 协调对话框无法按预期工作,因为它永远不会显示修改记录的正确值(Delphi 2010 bug?)

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?)
不羁少年 2024-09-07 23:09:22

传递给 OnReconcileError 或 OnUpdateError 的记录是无法应用更新的记录。根据D2007帮助文件(注意这是一个帮助文件链接而不是 Web 链接!) - 请注意有关 DataSet 参数的部分:

您应该始终编写
OnReconcileError 或 OnUpdateError
事件处理程序,即使只是丢弃
返回的记录无法被
应用。这些的事件处理程序
两个事件的工作方式相同。他们
包括以下参数:

DataSet:客户端数据集
包含更新的记录
无法应用。你可以用这个
数据集获取信息的方法
关于问题记录并编辑
记录以便更正任何
问题。特别是,您会想要
使用 CurValue、OldValue 和
中字段的 NewValue 属性
当前记录来确定
更新问题的原因。然而,
您不得调用任何客户端数据集
改变当前记录的方法
在您的事件处理程序中。

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.

木有鱼丸 2024-09-07 23:09:22

在dbExpress中你会发现TSQLConnection组件,在参数中有一个条目Mars_Connection,默认设置为False,将其设置为True并且错误消息已解决

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文