Recent

Author Topic: [SOLVED] What to specify for Transaction auto-start and commit/rollback?  (Read 2946 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1266
I did not set anything but TSQLTransaction.Action to caRollBack.  Is this all to auto-start transaction and rollback? But when is it rolled back? I'd like to use one transaction for select only purpose -- so I'd like it rolled back as soon as the dataset is opened. But if it is rolled back as soon as the opening operation is over, the dataset (TSQLQuery) must be closed, which is not.
« Last Edit: August 06, 2021, 11:59:26 am by egsuh »

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: What to specify for Transaction auto-start and commit/rollback?
« Reply #1 on: August 05, 2021, 08:18:06 am »
TSQLTransaction.Action is used when TSQLTransaction.EndTransaction is called.
And TSQLTransaction.EndTransaction is called by TDatabase.CloseTransactions which is called when database is to be closed.

So in short TSQLTransaction.Action does not play role when dataset is opened.

If you want commit transaction just after dataset is opened you can use TSQLQuery.Options:
sqoKeepOpenOnCommit and commit transaction manually.

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: What to specify for Transaction auto-start and commit/rollback?
« Reply #2 on: August 05, 2021, 09:18:27 am »
Same thing with transactional IBX datasets - which also descend from TDataset - as said @LacaK (thus, consistency among transactional component solutions): the TSQLTransaction.Action (caRollback, caCommit, and possibly caRollbackRetaining or caCommitRetaining) is called when all the datasets managed inside the transaction are closed (so, either explicitly, or when their container - TForm or even TDatamodule - is destroyed).

In fact, the transaction that becomes useless when no dataset is open within itself (the transaction detects this context through its dataset pointers list, and concludes that), "closes" \ "deactivates" itself (=~ TSQLTransaction.InTransaction:= False;) after having applied its Action (caRollback, ...) on the server-side. Could be seen as a kind of smart "garbage collector" of the transactional layer.
« Last Edit: August 05, 2021, 09:56:46 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: What to specify for Transaction auto-start and commit/rollback?
« Reply #3 on: August 06, 2021, 11:59:08 am »
Thank you for your replies.
I think I should start / stop transactions explicitly, especially if operation is not selecting records.   

 

TinyPortal © 2005-2018