21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example:<br />

DDL statements<br />

create trigger biu_books<br />

active before insert or update position 3<br />

on books<br />

as<br />

begin<br />

if (new.id is null)<br />

then new.id = next value for gen_bookids;<br />

end<br />

Database triggers<br />

Added in: <strong>2.1</strong><br />

Description: Since <strong>Firebird</strong> <strong>2.1</strong>, triggers can be defined to fire upon the database events CONNECT, DISCON-<br />

NECT, TRANSACTION START, TRANSACTION COMMIT and TRANSACTION ROLLBACK. Only the database<br />

owner and SYSDBA can create, alter and drop these triggers.<br />

Syntax:<br />

Example:<br />

CREATE TRIGGER name<br />

[ACTIVE | INACTIVE]<br />

ON db_event<br />

[POSITION number]<br />

AS<br />

[]<br />

BEGIN<br />

[]<br />

END<br />

db_event ::= CONNECT | DISCONNECT | TRANSACTION START<br />

| TRANSACTION COMMIT | TRANSACTION ROLLBACK<br />

number ::= 0..32767 (default is 0)<br />

::= See PSQL::DECLARE for the exact syntax<br />

create trigger tr_connect<br />

on connect<br />

as<br />

begin<br />

insert into dblog (wie, wanneer, wat)<br />

values (current_user, current_timestamp, 'verbind');<br />

end<br />

Execution of database triggers and handling of exceptions:<br />

• CONNECT and DISCONNECT triggers are executed in a transaction created specifically for this purpose. If<br />

all goes well, the transaction is committed. Uncaught exceptions roll back the transaction, and:<br />

- In the case of a CONNECT trigger, the connection is then broken and the exception returned to the client.<br />

- With a DISCONNECT trigger, exceptions are not reported and the connection is broken as foreseen.<br />

47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!