此页面为机器翻译。请阅读英文原文。 English

IBSurgeon 文库

Firebird 2.5: Autonomous Transactions

功能

在自治(独立)事务中执行一段代码。这在需要引发异常但又不希望数据库更改被回滚的情况下非常有用。

如果在自治事务块内部引发了异常,则更改会被回滚。如果块一直执行到结束,则事务会被提交。

新事务以与现有事务相同的隔离级别启动。

应谨慎使用,以避免死锁。

作者

Adriano dos Santos Fernandes

语法

in autonomous transaction

do

示例

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 ;!