Subject Re: [firebird-support] Transaction number discrepancy
Author Helen Borrie
At 02:44 AM 26/09/2007, you wrote:
>In order to try and track stuck programs/transactions I have started
>to include a small timer routine that is intended to identify and
>record the oldest transaction used by a program every few minutes.
>
>procedure TfMRP.Timer3Timer(Sender: TObject);
>var
> i,t,j : integer;
> tstr,s : string;
> tTrans: TIBTransaction;
> tsql : TIBQuery;
>begin
> t := 0;
> tstr := '';
> for i := 0 to Database.ComponentCount -1 do
> if Database.Components[i].ClassType = TIBTransaction then
> begin
> try
> tTrans := TIBTransaction(LoaderData.Components[i]);
> if tTrans.Intransaction then
> begin
> j := tTrans.TransactionID;
> if (t = 0) or (t > j) then
> begin
> t := j;
> tstr := tTrans.Name;
> end;
> end;
> except
> end;
> end;
> etc - where Database is the Delphi form with all my database components.
>
>If I use IBExpert (or another program) to get the header page
>statistics from firebird (v2.0.0.12748) I can compare the lowest
>transaction on each program with the oldest active transaction
>reported by the database.
>
>Unfortunately the above program gives me transaction ID's which are
>lower (older) that any of the numbers reported by the database in its
>header page. whilst I can understand this might happen in classic
>server if what is reported only relates to the curent thread - I also
>get it testing on a single PC where there is only IBExpert and one
>program running.
>
>I'm obviously missing something ?

Or not explaining something?

A transaction can get its own server-side transaction ID via the
context variable CURRENT_TRANSACTION but otherwise it won't know
it. It can't get the IDs of other transactions.

CURRENT_TRANSACTION was introduced by Firebird so it's doubtful that
TIBTransaction has a way to deliver it as a property. I can't even
find any reference to a property called TransactionID in the IBX
help, at least at D7 (the latest I have). Should we conclude that
you have a reimplemented TIBTransaction class to which you have added
a TransactionID property whose Get* function that is doing that
somehow, e.g., with a statement like SELECT CURRENT_TRANSACTION FROM
RDB$DATABASE?

If any transaction is doing CommitRetaining or RollbackRetaining then
CURRENT_TRANSACTION will continue to return the same result until
after a hard COMMIT has been called.

./heLen