8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 17:23:03 +01:00
firebird-mirror/doc/sql.extensions/README.autonomous_transactions.txt

55 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

=======================
Autonomous Transactions
=======================
Function:
Runs a piece of code in an autonomous (independent) transaction. It's useful in cases where you
need to raise an exception but do not want the database changes to be rolled-back.
If exceptions are raised inside the body of an autonomous transaction block, the changes are
rolled-back. If the block runs till the end, the transaction is committed.
2020-02-13 00:47:14 +01:00
The new transaction is initiated with the same isolation level and lock timeout of the existing one.
2020-03-28 11:20:04 +01:00
The only exception is that if existing transaction run in READ COMMITTED READ CONSISTENCY mode, then
new autonomous transaction will run in CONCURRENCY mode.
Should be used with caution to avoid deadlocks.
Author:
Adriano dos Santos Fernandes <adrianosf@uol.com.br>
Syntax:
in autonomous transaction
do
<simple statement | compound statement>
Example:
create table log (
"date" 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 ("date", msg) values (current_timestamp, 'Connection rejected');
end
exception e_conn;
end
end!
set term ;!