简体   繁体   English

FireDAC ApplyUpdates和事务控制

[英]FireDAC ApplyUpdates and transaction control

I am converting application written in DBExpress to use new FireDAC components. 我正在转换用DBExpress编写的应用程序来使用新的FireDAC组件。 The basic things like opening the query, changing filter or ordering, displaying in grid are working correctly. 打开查询,更改过滤器或排序,在网格中显示等基本操作正常。 But I am surprised that some functions behave differently in comparison to dbexpress and I cant seem to comprehend it. 但令我感到惊讶的是,与dbexpress相比,某些函数的行为有所不同,我似乎无法理解它。

My application contains database editor. 我的应用包含数据库编辑器 When user opens the editor new transaction is started by calling method TFDConnection::StartTransaction . 当用户打开编辑器时,通过调用方法TFDConnection::StartTransaction启动新事务。 When the user clicks on OK button, the active transaction is committed and editor closes. 当用户单击“确定”按钮时,将提交活动事务并关闭编辑器。

In editor I use two queries to edit records. 在编辑器中,我使用两个查询来编辑记录。 In first query I manually compose SQL update command (like " update TEST set NAME='some name' where ID=1234 ") and execute it. 在第一个查询中,我手动编写SQL更新命令(如“ update TEST set NAME='some name' where ID=1234 ”)并执行它。 So far so good. 到现在为止还挺好。

Second query is connected to TDBAdvGrid (equivalent of TDBGrid from TMS Software company ) and have CachedUpdates = true . 第二个查询连接到TDBAdvGrid (相当于TMS Software公司TDBGrid ),并且CachedUpdates = true If I change some record in that grid I call TFDQuery::Post and TFDQuery::ApplyUpdates . 如果我更改了该网格中的某些记录,我会调用TFDQuery::PostTFDQuery::ApplyUpdates

Whats weird calling TFDQuery::ApplyUpdates commits not only pending changes in this specific query, but all queries connected to instance of TFDConnection . 什么奇怪的调用TFDQuery::ApplyUpdates不仅提交此特定查询中的挂起更改,还提交连接到TFDConnection实例的所有查询。 I thought that calling of ApplyUpdates should issue SQL update calls but should not interfere with transaction control. 我认为调用ApplyUpdates应该发出SQL更新调用但不应该干扰事务控制。

I want to give the user option to reject all changes made by him in database editor window. 我想让用户选择拒绝他在数据库编辑器窗口中所做的所有更改。 How to do it correctly ? 怎么做正确? Should I postpone call to ApplyUpdates to time when closing window ? 关闭窗口时,我应该ApplyUpdates调用推迟到时间吗? What is then the purpose of TFDQuery::CommitUpdates and TFDConnection::Commit if all that is necessary is the call of TFDQuery::ApplyUpdates ? 那么TFDQuery::CommitUpdatesTFDConnection::Commit的目的是什么呢?如果只需要调用TFDQuery::ApplyUpdates吗?

Set TFDConnection::TxOptions::StopOptions::xoIfCmdsInactive to false. 将TFDConnection :: TxOptions :: StopOptions :: xoIfCmdsInactive设置为false。 This will also disable TFDConnection::TxOptions::AutoCommit option and application can controls transactions by itself. 这也将禁用TFDConnection :: TxOptions :: AutoCommit选项,应用程序可以自行控制事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM