TSQLQuery holds dataset records, TSQLTransaction.action is not fired. lazarus / 16-Databases ---------------------------------------------------------------------- mangakissa · 2017-11-14 09:18 I have on a form: TSQLConnector, TSQLTransaction, TSQLQuery, TDatasource and an TDBGrid. TSQLTransaction.action is set to caRollback. The TSQLquery.AfterPost procedure applyupdates is called. When I insert a record after the TSQLquery is active, the record will be saved. By closing TSQLQuery the TDBgrid shows no data. When TSQLQuery opens again (no refresh!) the just inserted record is showed in TDBGrid. It looks like the transaction is not started when applyupdates is called. When I physically close the application and run it again the just inserted record is gone. It looks like the transaction is only working when the application ends. But is this logical? The TSQLTransaction.action should be called after applyupdates and not at the end when application is closing. ---------------------------------------------------------------------- rvk · 2017-11-14 10:10 Quote from: mangakissa on November 14, 2017, 10:18:24 amTSQLTransaction.action is set to caRollback. ... The TSQLTransaction.action should be called after applyupdates and not at the end when application is closing. So you want caRollback to be called right after ApplyUpdates, automatically ??. Mmmm, that would just remove your just inserted record. That can't be right. Otherwise you could never commit a transaction You can check TSQLTransaction.Active (or .InTransaction) to see if the transaction is still active. The (default) TSQLTransaction.Action is only called ONLY when You close the connection (not the query)When you set TSQLTransaction.Active to false or you call TSQLTransaction.EndTransactionDestroy the transaction-component So the transaction stays active even after closing and opening a table (so you can do multiple actions on multiple tables). If you don't want that you need to commit or rollback the transaction manually. ---------------------------------------------------------------------- Thaddy · 2017-11-14 11:07 Quote from: mangakissa on November 14, 2017, 10:18:24 amBut is this logical? The TSQLTransaction.action should be called after applyupdates and not at the end when application is closing. Yes. Call commit or Rollback  when you are sure what you want. Once committed there is no rollback (only if it is scripted). ---------------------------------------------------------------------- mangakissa · 2017-11-14 12:45 QuoteSo you want caRollback to be called right after ApplyUpdates, automatically ??. Mmmm, that would just remove your just inserted record. That can't be right. It's a test to see what TSQLTransaction is doing when property action is set to an action. @Thaddy I know wat you mean. But as said above, I want to see wat TSQLTransaction is doing. Offcourse it's working if I manually commit the record. But I want to act as a very beginner who only workt with the givven options. I also miss caReadComitted. ---------------------------------------------------------------------- rvk · 2017-11-14 13:10 Quote from: mangakissa on November 14, 2017, 01:45:53 pmI also miss caReadComitted. Read committed is an isolation level NOT an Transaction action. (where do you mis it? It should be put it in transaction parameters if you want it.) If you want to test the default action of the transaction you can just call EndTransaction or close the database connection. As said... closing a table/qeury does not end the transaction yet. ---------------------------------------------------------------------- mangakissa · 2017-11-14 15:48 If I call TSQLTransaction.Commit, all my changes are sent to the database and close the TSQLQuery component. TSQLTransaction. If I call TSQLTransaction.CommitRetaining, all my changes are sent to the database and but doesn't close the TSQLQuery component. TSQLTransaction. I know that. Let's say I'm a beginner. Doesn't know anything about databases and transactions. So I tell the property action that every action to the database (insert / update / delete) must be send to the database. My database is 'remote' database. I go to my navigator and push on the insert button. Fill in some data and push on the post button. Nothing happens to the database. SQLdb have to create an insert / update query to update my database. This will be done with applyupdates(). Now I go to a databasebroser to see the changes. Nothing happened. The TSQLTansaction is not triggered by the property action to commit the transaction automatically. It should be. Otherwise the property is useless. All can be done by doing it manually. I know that. But the beginner doesn't. AFAIK ZEOS is doing it. ---------------------------------------------------------------------- rvk · 2017-11-14 16:01 Quote from: mangakissa on November 14, 2017, 04:48:12 pmIf I call TSQLTransaction.Commit, all my changes are sent to the database and close the TSQLQuery component. TSQLTransaction. If I call TSQLTransaction.CommitRetaining, all my changes are sent to the database and but doesn't close the TSQLQuery component. TSQLTransaction. I know that.NO. TSQLTransaction.Commit doesn't "send" anything to the server. ApplyUpdates does that. TSQLTransaction is just the transaction-control of the database. If the database doesn't have transaction control you wouldn't even need TSQLTransaction. QuoteLet's say I'm a beginner. Doesn't know anything about databases and transactions.In that case you would fiddle with the TSQLQuery.Options. sqoKeepOpenOnCommit, sqoAutoApplyUpdates and sqoAutoCommit will do what you want and take transaction control (and even ApplyUpdates) out of your hands. QuoteThe TSQLTansaction is not triggered by the property action to commit the transaction automatically. It should be. Otherwise the property is useless.I wouldn't want TSQLTansaction to do anything automatically. If it does, I can't control it. And IT IS triggered when you end the transaction with EndTransaction or free the transaction or close the database connection. So beginners should set the options and it will be done automatically. ---------------------------------------------------------------------- miab3 · 2017-11-16 20:28 Quote from: rvk on November 14, 2017, 05:01:19 pmI wouldn't want TSQLTansaction to do anything automatically. If it does, I can't control it. And that's why AutoCommit mode can be switched off at ZEOS at any time. Michał