Page 1 of 1

Transaction Problems

Posted: Fri 04 Apr 2014 21:22
by andrewsvaz
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

Re: Transaction Problems

Posted: Mon 07 Apr 2014 10:42
by ZEuS
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.

Re: Transaction Problems

Posted: Mon 07 Apr 2014 13:20
by andrewsvaz
Interesting way to work with it.

Thanks.

Re: Transaction Problems

Posted: Tue 08 Apr 2014 08:19
by ZEuS
We thank you for your interest in our products.
Feel free to contact us if you have any further questions about UniDAC.