Is it safe to assume EVENT_PARAMETER ( 'context-name' ) returns NULL if context-name doesn't apply / doesn't exist? The docs in V11 and V12 are silent on the subject.
In particular, is the following a safe technique for determining if a scheduled event has been fired because of the schedule or because of an explicit TRIGGER EVENT statement?
...and, is there an easier way to answer that question?
I want to be able to turn the schedule on and off at runtime but still allow TRIGGER EVENT (ALTER EVENT doesn't help, and I don't want to use it anyway).
CREATE EVENT ev_every_10_seconds SCHEDULE START TIME '00:00' EVERY 10 SECONDS HANDLER BEGIN MESSAGE STRING ( CURRENT TIMESTAMP, ' ev_every_10_seconds @explicitly_triggered = "', COALESCE ( EVENT_PARAMETER ( '@explicitly_triggered' ), 'No' ), '"' ) TO CONSOLE; END; TRIGGER EVENT ev_every_10_seconds ( @explicitly_triggered = 'Yes' ); 2010-10-31 14:39:30.031 ev_every_10_seconds @explicitly_triggered = "No" 2010-10-31 14:39:40.093 ev_every_10_seconds @explicitly_triggered = "No" 2010-10-31 14:39:49.437 ev_every_10_seconds @explicitly_triggered = "Yes"
asked 31 Oct '10, 18:50
The event_parameter function will return NULL if the parameter is not a recognized value.
Another way to distinguish events fired via a schedule versus ones fired via TRIGGER EVENT is to test the value of event_parameter('ScheduleName'). If the event was fired via a schedule, the value will be a non-empty string representing the name of the schedule. If fired via TRIGGER EVENT, the value will be an empty string.
answered 01 Nov '10, 13:58