Transaction Problems

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
andrewsvaz
Posts: 12
Joined: Fri 04 Apr 2014 18:50

Transaction Problems

Post by andrewsvaz » Fri 04 Apr 2014 21:22

Hello all,

I have bought UniDAC a few days ago and I am migrating a FibPlus aplication.

As I am working with Firebird I am using two transactions, a ReadOnly one for the Transaction Property and a ReadWrite one for the UpdateTransaction Property of a TUniQuery.

I've set the RefreshOptions as [roAfterInsert,roAfterUpdate,roBeforeEdit] so I believe that after a Post the data will be updated correctly.

But then I have a slight problem, as I am working with two transactions I do a commit on the UpdateTransaction and a CommitRetaining on the Transaction, but how can I detect that they are InTransaction? The Intransaction Property exists only in the UniConnection object, not in the UniTransaction Object. So when I try something like (as a simple Example)

(I have set the RW Transaction as the Default Transaction for the UniConnection).

Function DoCommit : Boolean
var
OkTrans : boolean;
begin
OkTrans := True;
if DbConnection.InTransaction then
try
TrGrv.Commit;
except
TrGrv.Rollback;
OkTrans := False;
end;

if TrRO.InTransaction then
try
TrRO.CommitRetaining;
except
TrRO.RollbackRetaining;
OkTrans := False;
end;

Result := OkTrans;
end;

the first transaction condition can be detected and will work properly, the second is not possible. I saw in the sources that there is a DetectInTransaction function that is protected in the UniTransaction, why is this so? In situations when one is working with double transactions it is necessary to be able to detect if the transaction is InTransation so the code can work properly.

How can this be done?

Thank you
Andrew S. Vaz

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Transaction Problems

Post by ZEuS » Mon 07 Apr 2014 10:42

In UniDAC, the TUniConnection.InTransaction value is True when the default connection transaction is active. In your case, TUniConnection.InTransaction = True means that UpdateTransaction is active.
To determine whether a particular TUniTransaction is in transaction, you can check the value of the TUniTransaction.Active property.

andrewsvaz
Posts: 12
Joined: Fri 04 Apr 2014 18:50

Re: Transaction Problems

Post by andrewsvaz » Mon 07 Apr 2014 13:20

Interesting way to work with it.

Thanks.

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Transaction Problems

Post by ZEuS » Tue 08 Apr 2014 08:19

We thank you for your interest in our products.
Feel free to contact us if you have any further questions about UniDAC.

Post Reply