Strange behavior with IBDac Transactions ?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
abak
Posts: 29
Joined: Sat 18 Oct 2014 18:42

Strange behavior with IBDac Transactions ?

Post by abak » Sat 18 Oct 2014 18:49

Strange behavior with IBDAC 5.4.11 Transactions !
"Delphi XE3 Update2 17.0.4770.56661 win 7 Pro - 32/64 bits"

Hi,

It has been 10 years, i have worked with dbExpress.
I have just baught, last week, the great IBDAC Components for it's very very fast speed ! Thanks to DevArt Team :)

I have somme difficulties to understand Transactions with IBDAC.
(Sorry for this topic : I could'nt find the solution on your Forum).

So, let see the problem :

1. Transactions with dbExpress are simple :
Just Start one Global Transaction, work with it, then Commit (or RollBack) :

SQLConnection1.StartTransaction;
try
_____________________________

Any Select Queries;
Any Execute Queries;
....
_____________________________
SQLConnection1.commit;
except
SQLConnection1.RollBack;
exit;
end;


After commiting/ Rollbacking, the Connection (SQLConnection1) will not be in Transacion Yet (this is the correct beahvior).



2. With IBDAC the story is different !
Here is what I found in my great confusion :

Put an :
- IBCConnection1, with Autocommit = False
- IBCTransaction1
- IBCQuery1 with Autocommit = False and Transaction = IBCTransaction1


Exmple 1 :
=======
if you start this Explicit Transaction :


IBCTransaction1.StartTransaction;
try
_____________________________

Any Select Queries;
Any Execute Queries;
....
_____________________________
IBCTransaction1.commit;
except
IBCTransaction1.RollBack;
exit;
end;

the IBCConnection1.InTransaction steel True until you kill the Connection WOW !!!
I found that any IBCQuery1.Open Forces IBCConnection1.InTransaction = True

if I do : if IBCConnection1.InTransaction then IBCConnection1.RollBack
this rise an exception : "Can't perform operation on inactive transaction" ???
Stoped on --> VCL.Controls --> procedure TControl.Click;




Exmple 2 :
=======

I can'nt use IBCConnection1 like dbExpress :

IBCConnection1.StartTransaction;
try
_____________________________

Any Select Queries;
Any Execute Queries;
....

_____________________________
IBCConnection1.commit;
except
IBCConnection1.RollBack;
exit;
end;


Because IBCConnection1 steel also, in Transaction after commiting !!!

Can you solve my confusion ?
How can I use a Global Transaction like dbExpress (Starting, Commiting, Rollbacking) that's all ?
(Not talking here, about strategy of modifying manually a DBGrid with its explicit transaction. No, just somme SQL queries).

Thx.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Strange behavior with IBDac Transactions ?

Post by ViktorV » Mon 20 Oct 2014 08:46

Since IBDAC supports multiple transactions, the TIBCConnection.InTransaction property points not to a global transaction state, and will be True while there is at least one active transaction. InterBase/Firebird requires an active transaction for any operation with data, even for dataset opening. Therefore, while there is at least one open dataset, TIBCConnection.InTransaction will always be True.

An attempt to execute IBCConnection1.RollBack raises an exception, because this method attempts to execute Rollback for the IBCConnection1 default transaction, and IBCQuery1 uses a separate transaction in your sample.

In order to work with the transaction correctly in your sample, you should use the methods:

Code: Select all

IBCQuery1.Transaction.Active
IBCQuery1.Transaction.Commit
IBCQuery1.Transaction.RollBack

abak
Posts: 29
Joined: Sat 18 Oct 2014 18:42

Re: Strange behavior with IBDac Transactions ?

Post by abak » Mon 20 Oct 2014 20:34

Thank you ViktorV,

Now, i understand.

In fact, i solve my enigme by using 2 explicits ibTransactions :
One, for opening dbgrids (ibTr_Grid), and one for Working with queries (ibTr_SQL).
And instead of working with Ibconection.intransaction, i am doing :
ibTr_SQL.StartTrasaction;
Try
...
...
ibTr_SQL.commit;
Except
ibTr_SQL.Rollback;
End;

It works fine and i can take control of my ibTr_SQL "Global".
All the best.

IBDac = very very fast :P

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Strange behavior with IBDac Transactions ?

Post by ViktorV » Tue 21 Oct 2014 09:14

Feel free to contact us if you have any further questions.

Post Reply