PointBase
Version 4.8 PointBase Developer 148
<trigger action> ::=
[ FOR EACH { ROW |
STATEMENT } ]
[ WHEN (<search condition> )]
<triggered SQL statement>
<triggered SQL statement> ::=
<SQL procedure statement> |
BEGIN ATOMIC { <SQL
procedure
statement><semicolon> }...
END
<Trigger action> allows you to specify ROW trigger or
STATEMENT trigger. If you specify a ROW trigger, PointBase
fires the trigger once for each row on which the defined <trigger
event> occurs. A STATEMENT trigger will be fired once for
each SQL statement on which causes the defined trigger event to
occur.
ROW triggers may not work on self-referencing tables. In this
case, referential constraint may go into recursion and may lead to
a wrong row value while executing triggers.
If you do not specify a STATEMENT or ROW trigger, PointBase
uses the STATEMENT trigger for the default.
<Trigger action> allows you to specify a WHEN clause which
defines the search condition to evaluate if the trigger will fire.
You can define one or more predicates. If these predicates are
evaluated TRUE, then the trigger will be fired; otherwise, it will
not be fired.
<Triggered SQL statement> allows you to specify the action for
the trigger. You can specify one SQL statement or, a compound
SQL statement embraced by the BEGIN ATOMIC and END
keywords. The size of each SQL statement is limited to 900
bytes. See trigger-related SQL statements: SET assignment,
VALUE, and SIGNAL on page 182.
No transaction control statements are allowed for the <triggered
SQL statement>. (Transaction control statements include
commit, rollback, savepoint, etc. See section Transaction Control
in Appendix A in this guide for further details on transaction
control statements.) If you violate this rule, PointBase throws an
error. If an error occurs during the execution of <triggered SQL
statement>, PointBase throws an error and the execution of the
<triggering SQL statement> is interrupted, and all the changes
are rolled back.
Since <triggered SQL statement> can contain any SQL
statement, it is possible that an INSERT, UDPATE or DELETE
SQL statement could cause the same trigger to be executed
again. This is called a recursive trigger. PointBase allows
recursive triggers. But, you should avoid writing recursive
triggers, because they can lead to infinite loops.
It is possible for recursive triggers to modify the same row
multiple times. In this case, the latest row value or new row value
may be seen in the subsequent trigger execution.
PointBase sets a limit of 16 levels for recursive trigger execution
context. For example, if one trigger is fired, it is counted as level
one, if this trigger causes another trigger to be fired before it is
finished, the second trigger is counted as level two, and so on. An
exception will be thrown if trigger level exceeds the limit.