Defines an event and its associated handler for automating predefined actions. Also defines scheduled actions.
CREATE EVENT event-name [ TYPE event-type [ WHERE trigger-condition [ AND trigger-condition ], ...] | SCHEDULE schedule-spec, … ] …[ ENABLE | DISABLE ] …[ AT { CONSOLIDATED | REMOTE | ALL } ] …[ HANDLER BEGIN … END ] event-type - (back to Syntax) BackupEnd | “Connect” | ConnectFailed | DatabaseStart | DBDiskSpace | “Disconnect” | GlobalAutoincrement | GrowDB | GrowLog | GrowTemp | IQMainDBSpaceFree | IQTempDBSpaceFree | LogDiskSpace | “RAISERROR” | ServerIdle | TempDiskSpace trigger-condition - (back to Syntax) event_condition( condition-name ) { = | < | > | != | <= | >= } value schedule-spec - (back to Syntax) [ schedule-name ] { START TIME start-time | BETWEEN start-time AND end-time } [ EVERY period { HOURS | MINUTES | SECONDS } ] [ ON { ( day-of-week, … ) | ( day-of-month, … ) } ] [ START DATE start-date ]
SELECT event_id, event_name FROM SYS.SYSEVENT
In the event the database has more than one dbspace, on separate drives, DBDiskSpace checks each drive and acts depending on the lowest available space.
You can use the EVENT_CONDITION function with RemainingValues as an argument for this event type.
... WHERE event_condition( 'LogDiskSpacePercentFree' ) < 20 ...The argument to the EVENT_CONDITION function must be valid for the event type. You can use multiple AND conditions to make up the WHERE clause, but you cannot use OR conditions or other conditions.
You can list schedule names by querying the system table SYSSCHEDULE. For example:
SELECT event_id, sched_name FROM SYS.SYSSCHEDULE
Each event has a unique event ID. Use the event_id columns of SYSEVENT and SYSSCHEDULE to match the event to the associated schedule.
When a nonrecurring scheduled event has passed, its schedule is deleted, but the event handler is not deleted.
Scheduled event times are calculated when the schedules are created, and again when the event handler completes execution. The next event time is computed by inspecting the schedule or schedules for the event, and finding the next schedule time that is in the future. If an event handler is instructed to run every hour between 9:00 and 5:00, and it takes 65 minutes to execute, it runs at 9:00, 11:00, 1:00, 3:00, and 5:00. If you want execution to overlap, you must create more than one event.
Days of the week are Monday, Tuesday, and so on. The abbreviated forms of the day, such as Mon, Tue, and so on, may also be used. The database server recognizes both full-length and abbreviated day names in any of the languages supported by SAP Sybase IQ.
Days of the month are integers from 0 to 31. A value of 0 represents the last day of any month.
CREATE EVENT IncrementalBackup SCHEDULE START TIME '1:00AM' EVERY 24 HOURS HANDLER BEGIN BACKUP DATABASE INCREMENTAL TO 'backups/daily.incr' END
CREATE TABLE mysummary(dt DATETIME, users INT, mainKB UNSIGNED BIGINT, mainPC UNSIGNED INT, tempKB UNSIGNED BIGINT, tempPC UNSIGNED INT) ;
CREATE EVENT mysummary SCHEDULE sched_mysummary START TIME '00:01 AM' EVERY 10 MINUTES HANDLER BEGIN DECLARE mt UNSIGNED BIGINT; DECLARE mu UNSIGNED BIGINT; DECLARE tt UNSIGNED BIGINT; DECLARE tu UNSIGNED BIGINT; DECLARE conncount UNSIGNED INT; SET conncount = DB_PROPERTY('ConnCount'); CALL SP_IQSPACEUSED(mt,mu,tt,tu); INSERT INTO mysummary VALUES( NOW(), conncount, mu, (mu*100)/mt, tu, (tu*100)/tt ); END;
CREATE EVENT LowTxnLogDiskSpace TYPE DBDiskSpace WHERE event_condition( 'DBFreePercent' ) < 30 AND event_condition( 'Interval' ) >= 300 HANDLER BEGIN message 'Disk space for Transaction Log is low.'; END;
An event definition includes two distinct pieces. The trigger condition can be an occurrence, such as a disk filling up beyond a defined threshold. A schedule is a set of times, each of which acts as a trigger condition. When a trigger condition is satisfied, the event handler executes. The event handler includes one or more actions specified inside a compound statement (BEGIN... END).
If no trigger condition or schedule specification is supplied, only an explicit TRIGGER EVENT statement can trigger the event. During development, you might want to develop and test event handlers using TRIGGER EVENT and add the schedule or WHERE clause once testing is complete.
Event errors are logged to the database server console.
When event handlers are triggered, the server makes context information, such as the connection ID that caused the event to be triggered, available to the event handler using the EVENT_PARAMETER function.
Event handlers execute on a separate connection, with the privileges of the event owner. To execute with privileges other than MANAGE ANY EVENT system privilege, you can call a procedure from within the event handler: the procedure executes with the permissions of its owner. The separate connection does not count towards the ten-connection limit of the personal database server.