Firebird Documentation IndexFirebird 2.5 Release NotesProcedural SQL (PSQL) → Autonomous Transactions
Firebird Home Firebird Home Prev: Procedural SQL (PSQL)Firebird Documentation IndexUp: Procedural SQL (PSQL)Next: Borrow Database Column Type for a PSQL Variable

Autonomous Transactions

Adriano dos Santos Fernandes

Tracker reference CORE-1409.

This new implementation allows a piece of code to run in an autonomous transaction within a PSQL module. It can be handy for a situation where you need to raise an exception but do not want the database changes to be rolled back.

The new transaction is initiated with the same isolation level as the one from which it is launched. Any exception raised in a block within the autonomous transaction will cause changes to be rolled back. If the block runs through until its end, the transaction is committed.

Warning

Because the autonomous transaction is independent from the one from which is launched, you need to use this feature with caution to avoid deadlocks.

Syntax Pattern

IN AUTONOMOUS TRANSACTION
DO
  <simple statement | compound statement>
    

Example of Use

create table log (
  logdate timestamp,
  msg varchar(60)
);

create exception e_conn 'Connection rejected';

set term !;

create trigger t_conn on connect
as
begin
  if (current_user = 'BAD_USER') then
  begin
    in autonomous transaction
    do
    begin
      insert into log (logdate, msg) values (current_timestamp, 'Connection rejected');
    end

    exception e_conn;
  end
end!

set term ;!
    
Prev: Procedural SQL (PSQL)Firebird Documentation IndexUp: Procedural SQL (PSQL)Next: Borrow Database Column Type for a PSQL Variable
Firebird Documentation IndexFirebird 2.5 Release NotesProcedural SQL (PSQL) → Autonomous Transactions