Page 1 of 1

understand transaction

Posted: Tue 01 Jul 2008 15:36
by calou
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

Posted: Wed 02 Jul 2008 08:53
by Plash
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.