7. OpenSQL Features : Database Events : Database Event Statements : Using WHENEVER DBEVENT
 
Share this page                  
Using WHENEVER DBEVENT
To specify an action to occur whenever a DBEvent is raised, use the WHENEVER statement:
EXEC SQL WHENEVER DBEVENT action;
The action can be one of the following: CONTINUE, STOP, or GO TO label.
To use the WHENEVER DBEVENT statement, your application must include an SQLCA. When a database event is added to the database event queue, the sqlcode variable in the SQLCA is set to 710 (as will the standalone SQLCODE variable; SQLSTATE is not affected). However, if a query results in an error that resets sqlcode, the WHENEVER statement will not trap the database event. The database event will still be queued, and your error-handling code can use the GET DBEVENT statement to check for queued database events. To avoid inadvertently (and recursively) triggering the WHENEVER mechanism from within a routine called as the result of a WHENEVER DBEVENT statement, your database event-handling routine should turn off trapping:
main program:
exec sql whenever dbevent call event_handler;
...
event_handler:
/* turn off the whenever event trapping */
exec sql whenever dbevent continue;
exec sql inquire_sql(:evname=dbeventname...);
process events
return