Triggers as Event Alerters

From InterBase

Go Up to Using Triggers


Triggers can be used to post events when a specific change to the database occurs. For example, the following trigger, POST_NEW_ORDER, posts an event named “NEW_ORDER” whenever a new record is inserted in the SALES table:

CREATE TRIGGER POST_NEW_ORDER FOR SALES
AFTER INSERT AS
BEGIN
POST_EVENT 'NEW_ORDER';
END ;

In general, a trigger can use a variable for the event name:

POST_EVENT :EVENT_NAME;

The parameter <>EVENT_NAME is declared as a string variable, the statement could post different events, depending on the value of the string variable, EVENT_NAME. Then, for example, an application can wait for the event to occur, if the event has been declared with EVENT INIT and then instructed to wait for it with ­EVENT WAIT:

EXEC SQL
 EVENT INIT ORDER_WAIT EMPDB ('NEW_ORDER');
EXEC SQL
 EVENT WAIT ORDER_WAIT;

For more information on event alerters, see the Embedded SQL Guide.

Advance To: