TCustomClientDataset 可以以批处理模式应用更新吗?

发布于 2024-11-14 09:43:45 字数 236 浏览 4 评论 0原文

我有一个连接到 Firebird 数据库的 DB Express TSimpleDataset。我刚刚向数据集中添加了数千行数据,现在是时候调用 ApplyUpdates 了。

不幸的是,当它尝试单独插入每一行时,这会导致数千次数据库命中。这有点令人失望。我真正希望看到的是数据集生成一个事务,其中包含数千个 INSERT 语句,并立即发送整个事务。如果需要的话,我可以自己进行设置,但首先我想知道数据集或 DBX 框架中是否内置了任何方法。

I've got a DB Express TSimpleDataset connected to a Firebird database. I've just added several thousand rows of data to the dataset, and now it's time to call ApplyUpdates.

Unfortunately, this results in several thousand database hits as it tries to INSERT each row individually. That's a bit disappointing. What I'd really like to see is the dataset generate a single transaction with a few thousand INSERT statements in it and send the whole thing at once. I could set that up myself if I had to, but first I'd like to know if there's any method for it built in to the dataset or the DBX framework.

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

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

发布评论

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

评论(1

美人迟暮 2024-11-21 09:43:45

不知道是否可以使用 TSimpleDataset(从未使用过),但如果您使用 TClientDataset + TDatasetProvider + <将您的数据库数据集放在这里>,那么您肯定可以。您可以编写一个BeforeUpdateRecord来自己处理应用过程。基本上,它允许您绕过标准应用流程,访问对记录进行更改的数据集delta,然后使用您自己的代码和组件将更改应用到数据库。例如,您可以调用存储过程来修改数据等等。

然而,事务与所谓的“数组DML”、“批量插入”等之间存在差异。即使您使用单个事务(并且“应用”AFAIK 发生在单个事务中),在事务中您可能仍然需要发送“n”个 INSERT。某些数据库支持发送单个 INSERT(或更新、删除)以及要插入的参数数组的方式,从而减少要使用的单个语句的数量 - 但这可能是特定于数据库的,据我所知 dbExpress/Datasnap 不支持它 - 您仍然可以使用 BeforeUpdateRecord 事件来利用特定的数据库功能。

Don't know if it is possible with a TSimpleDataset (never used it), but surely you can if you use a TClientDataset + TDatasetProvider + <put your db dataset here>. You can write a BeforeUpdateRecord to handle the apply process yourself. Basically, it allows you to bypass the standard apply process, access the dataset delta with changes made to records, and then use your own code and components to apply changes to the database. For example you could call stored procedures to modify data, and so on.

However, there is a difference between a transaction and what is called "array DML", "bulk insert" or the like. Even if you use a single transaction (and an "apply" AFAIK happens in a single transaction), within the transaction you may still need to send "n" INSERTs. Some databases supports a way of sending a single INSERT (or update, delete) with an array of parameters to be inserted, reducing the number of single statements to be used - but that may be very database specific and AFAIK dbExpress/Datasnap do not support it - you still could use the BeforeUpdateRecord event to take advantage of specific database capabililties.

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