understand transaction

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
calou
Posts: 116
Joined: Tue 27 May 2008 12:46

understand transaction

Post by calou » Tue 01 Jul 2008 15:36

Hello,

There is something that i don't really understand in transactions.

Here is my code :

frmMain.IBCQry.AutoCommit:=FALSE;
frmMain.IBCQry.Transaction:=frmMain.IBCTrnsctn;
if frmMain.IBCTrnsctn.Active=true then
showMessage('active1');

frmMain.IBCQry.sql.Text:='INSERT INTO ENREGISTREMENTS ' +
'(NUM, REF_DAT, NOM_SITE, DATE_ENREG, HEURE, VE, VS, K, PHASE, TYP) ' +
'VALUES (:NUM, :REF_DAT, :NOM_SITE, :DATE_ENREG, :HEURE, :VE, :VS, :K, :PHASE, :TYP)';
frmMain.IBCQry.Prepare;
if frmMain.IBCTrnsctn.Active=true then
showMessage('active2');
frmMain.IBCTrnsctn.StartTransaction;

I don't understant why the showMessage('active2') appears?
Why is the transaction active whereas the starttransaction is after?
How can i solve the problem because when i call starttransaction i have an error message

Thank you for help

Regards

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 02 Jul 2008 08:53

Interbase requires an active transaction to perform Prepare or Open operation. So after you call Prepare or Open method of TIBCQuery, transaction is active.

If you need to execute your query without commiting changes, just set AutoCommit property of TIBCQuery to False. After you execute the query, the transaction is active, and changes are not commited. You can call Commit or CommitRetaining later to commit the changes.

Post Reply