Accessing the Transaction ID - Firebird

From Firebird 1.5 forward, the transaction ID (TID) of the current transaction (as deduced from the stored transaction state data) is available as a context variable. It is available in DSQL, isql, triggers, and stored procedures. The variable is CURRENT_TRANSACTION.

For example, to get it in a query, you could request this:

SELECT CURRENT_TRANSACTION AS TRAN_ID FROM RDB$DATABASE;

To store it in a table:

INSERT INTO TASK_LOG (USER_NAME, TRAN_ID, START_TIMESTAMP) VALUES (CURRENT_USER, CURRENT_TRANSACTION, CURRENT_TIMESTAMP);

Firebird 1.0.x does not provide a mechanism for tracking transactions.

Using the TID in Applications

The TID from the server is not the same as the transaction handle that the Firebird client fetches back into your application. It is quite valid to associate a TID with a transaction handle, provided you remember to remap the relationship between TID and handle each time you reuse a handle. Every use of a handle should be atomic in your application.

The TID can be a useful asset for tracking down applications and users responsible for long-running transactions in a system that continually exhibits degrading performance. A completely cyclic tracking routine could record the server timestamps when transactions both start and finish (commit or roll back). In particular, missing finish times will help to find users who habitually use the “reset” button to terminate tasks or application workflows that are failing to commit work in a timely fashion.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Firebird Topics