是否可以拍摄数据集快照?

发布于 2024-12-10 17:30:33 字数 609 浏览 0 评论 0原文

在我的应用程序中,我专门使用 DBAware 组件(少数地方除外)。

我有一个场景,其中创建主数据集(例如客户)、详细数据集(例如订单)、子详细数据集(例如订单项)。通常,我允许用户进行更改(数据集处于浏览模式),然后我发布。简单的。

无论如何,在编辑子数据集时,我想添加一种简单的撤消功能:打开一个表单来编辑数据集(即使用数据库组件,因此对表单的更改将更改数据集),如果用户取消操作,我会喜欢将数据集恢复为打开表单之前的状态。

现在,为了实现这一点,我可以考虑在 TClientDataSet 或类似组件中创建数据集的副本,但是还有其他技术吗?就像使用 Delphi 可以以简单的方式创建数据的“快照”一样。使用伪代码:

MySubDetailDataSet.SaveSnapShot;
SubDetailForm.ShowModal;
if ModalResult = mrCancel then MySubDetailDataSet.RestoreSnapShot;

使用 Delphi 组件是否可以“现成”类似的东西?

顺便说一句,我使用 DevArt 组件中的 SDAC,因此,如果您知道一种仅适用于这些组件而不适用于 Delphi 标准组件的技术,那么欢迎您!

IN my application I use DBAware components exclusively (except a few places).

I have a scenario in which I create a Master dataset (e.g. customer), detail dataset (e.g. Orders), subdetail dataset (e.g. order items). TYpically I allow users to make changes (the dataset are in Browse mode) and then I post. Simple.

Anyway on editing the subdataset I want to add a kind of simple undo feature: one opens a form to edit the dataset (that is with db componets, so changes to the form will change the dataset), if the user Cancels the operation I would like to restore the dataset as it was before opening the form.

Now for implementing this I can think of makeing a copy of the dataset in a TClientDataSet or similar component, but are there other techiniques? Like is it possible with Delphi to create in an easy way a "snapshot" of the data. With pseudocode:

MySubDetailDataSet.SaveSnapShot;
SubDetailForm.ShowModal;
if ModalResult = mrCancel then MySubDetailDataSet.RestoreSnapShot;

Is something like that possible "off the shelf" with Delphi components?

By the way I use SDAC from DevArt components, so if you know a technique that is available only with those components and not with Delphi standard ones it is welcome!

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

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

发布评论

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

评论(4

寂寞花火° 2024-12-17 17:30:33

在客户端数据集中,更改存储在增量中 - 您可以调用 CancelUpdates 来清除增量并恢复到原始数据集。还有其他更细粒度的方法。请参阅帮助中的“撤消更改”。

如果您使用的是 RDBMS 并且正确地处于事务内部,则可以回滚该事务。某些数据库提供保存点来回滚到给定的保存点,而不是回滚整个事务,但这是特定于数据库的。事务通常是按会话进行的,而不是按单个表或查询进行的。您必须确保在给定事务中仅执行可能需要回滚的更改。

客户端数据集可能是一种“较轻”的方法,因为它们仅管理客户端数据并且不需要数据库资源。当您处于数据库内的事务中时,需要一些资源来跟踪它和更改的数据。交易时间应根据需要而定,但不能更长。

还要注意事务可能意味着一些锁定。不同数据库的锁管理可能有很大不同,有些可能会升级锁,从而阻止比需要的更多的用户。始终使用足够数量的并发用户进行测试,以确保正确使用事务。

In a client dataset changes are stored in a delta - you can call CancelUpdates to clear the delta and revert to the original dataset. There are other more granular approaches. See "Undoing changes" in the help.

If you're using a RDBMS and you're properly inside a transaction, you can rollback the transaction. Some databases offer savepoints to rollback to a given savepoint instead of rolling back a whole transaction, but that's database specific. Transactions usually are per session, not per single table or query. You have to be sure only the changes you may need to roll back are performed in a given transaction.

Client dataset may be a "lighter" approach because they manage data client-side only and don't require database resources. While you're in a transaction inside the database, some resources are needed to keep track of it and changed data. Transaction should be as long as required, but not longer.

Be also aware that transactions may imply some locks. Lock management can be very different from database to database, and some may escalate locks, blocking more users than needed. Always test with a sufficient number of concurrent users to ensure transactions are used properly.

暗地喜欢 2024-12-17 17:30:33

AnyDAC 中,您可以执行以下操作:

var
 iPrevSP: Integer;
...
iPrevSP := MySubDetailDataSet.SavePoint; 
SubDetailForm.ShowModal; 
if ModalResult = mrCancel then 
  MySubDetailDataSet.SavePoint := iPrevSP; 

使用 TClientDataSet、kbmMemTable 可以访问类似的技术。可能不是答案,因为您正在使用 DevArt 产品。

In AnyDAC you can do:

var
 iPrevSP: Integer;
...
iPrevSP := MySubDetailDataSet.SavePoint; 
SubDetailForm.ShowModal; 
if ModalResult = mrCancel then 
  MySubDetailDataSet.SavePoint := iPrevSP; 

The similar technique is accessible with TClientDataSet, kbmMemTable. Not the answer probably, as you are using DevArt product.

染墨丶若流云 2024-12-17 17:30:33

通过 DevArt,我成功地将数据复制到 TVitualTableTCLientDataSet 的 DevArt 版本),无论如何,SavePoint 功能不像 AnyDAC 那样简单。

With DevArt I managed copying data to a TVitualTable (a DevArt Version of a TCLientDataSet), anyway SavePoint feature as easy as in AnyDAC is not there.

粉红×色少女 2024-12-17 17:30:33

您可以使用 TClientDataset 并从文件或流加载它,并将原始数据保存在里面,每次要回滚时,从原始数据重新加载它。

You can use TClientDataset and load it from file or stream and save the original data inside, and every time you want to rollback, reload it from original data.

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