Add support for TRIGGER events that can fire for one or many of
INSERT, UPDATE and DELETE
The current syntax for triggers are:
CREATE [OR REPLACE]
|
[DEFINER = { user | CURRENT_USER }]
|
TRIGGER [IF NOT EXISTS] trigger_name trigger_time trigger_event
|
ON tbl_name FOR EACH ROW trigger_stmt
|
The task is to replace trigger_event with:
Oracle and PostgreSQL both support this extension to CREATE TRIGGER.
PostgreSQL solves the issue witth information schema by duplicating the trigger for as many times as there are events.The primary key of the view triggers is because of this trigger_catalog, trigger_schema, event_object_table, trigger_name, event.
To distinguish which event fired the trigger, Oracle supports event flags:
CREATE TRIGGER tr1
|
BEFORE DELETE OR INSERT OR UPDATE ON t1
|
FOR EACH ROW
|
BEGIN
|
IF INSERTING THEN ...
|
ELSIF DELETING THEN ...
|
ELSIF UPDATING THEN ...
|
ENDIF;
|
END;
|
We should also support this.
If the clause INSERTING specified inside a trigger's body and the trigger event is not associated with INSERT, then the error ER_INCOMPATIBLE_EVENT_FLAG be produced. The same is true for the relating clauses: UPDATING or DELETING inside a trigger body not associated correspondingly with UPDATE event and DELETE event will produce the error ER_INCOMPATIBLE_EVENT_FLAG
Oracle DBMS has the following semantic on accessing old and new values of columns being affected by the trigger, quoting:
"Depending on the type of triggering statement, certain correlation names might not have any meaning.
A trigger fired by an INSERT statement has meaningful access to new column values only. Because the row is being created by the INSERT, the old values are null.
A trigger fired by an UPDATE statement has access to both old and new column values for both BEFORE and AFTER row triggers.
A trigger fired by a DELETE statement has meaningful access to :old column values only. Because the row no longer exists after the row is deleted, the :new values are NULL. However, you cannot modify :new values: ORA-4084 is raised if you try to modify :new values."
This semantic is also applied to triggers in MariaDB.