|
System Triggers | System Triggers |
The generic system trigger allows the owner of the SQL server to program a reaction for events concerning server operation. This events affect the server as a whole (e.g. database back-up), unlike the specific events in database applications.
The generic system trigger is a function:
FUNCTION _ON_SYSTEM_EVENT(IN event_num INT, IN ipar INT, IN spar CHAR(255)) RETURNS INT; BEGIN ... ENDbelonging to the _sysext scheme.
This function is called by the SQL server on certain events occurrences. The event_num parameter specifies the concerned event. The meaning of the rest of the parameters and the returned value depends on a specific event.
This trigger is run with Config_admin group (configuration administrator) privileges.
You can affect further SQL server operation by returning a certain value for some events.
This event occurs just before the server takes steps to create the backup copy of a database file. The event_num parameter has a value equal to 1. The ipar parameter equals 0 on automatic periodic backup or equals 1 on a backup called by client API (by button Backup now as well). The spar parameter value is not defined.
It the function returns -1, then the backup was recalled. The backup was made successfully for other return values.
Example:
User function Can_start_backup_test(), decides (someway...) if a backup can begin:
FUNCTION _on_system_event(IN event_num INT, IN ipar INT, IN spar CHAR(255)) RETURNS INT; BEGIN CASE WHEN event_num = 1 THEN // is it backup IF Can_start_backup_test() THEN CALL Log_write('backup started: par='+Int2str(ipar)); RETURN 1; ELSE RETURN -1; END IF; ELSE RETURN 1; // default for other events END CASE; END
System Triggers | System Triggers |