TRIGGER PROCEDURE statement
- Last Updated: October 18, 2024
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Defines a schema trigger.
Syntax
|
- event
-
The event for which the schema trigger is being defined. The valid events are
CREATE,DELETE,FIND,WRITE, andASSIGN. - object
-
The object on which the event is defined. If the event is
CREATE,DELETE,FIND, orWRITE, the object must be a reference to a database table. If the event isASSIGN, the object must be a reference to a database field qualified by a table name. - options
-
Optional parts of the trigger header.
Headers for
CREATE,DELETE, andFINDtriggers take no options. Their syntaxes are as follows:TRIGGER PROCEDURE FOR CREATE OF tableTRIGGER PROCEDURE FOR DELETE OF tableTRIGGER PROCEDURE FOR FIND OF tableIn the header for a
WRITEtrigger you can optionally include one or two buffer names.TRIGGER PROCEDURE FOR WRITE OF table [ NEW [ BUFFER ] buffer-name1 ] [ OLD [ BUFFER ] buffer-name2 ]For an
ASSIGNtrigger procedure, there are two ways you can specify the field/value for validation. The first way is to use theOFphrase and the second way is to use theNEW [VALUE]phrase. If you use theOFphrase, the value from theASSIGNhas been put into the buffer, so you can check it from there. However, the change has not been committed yet, so if this trigger returns error, the new value will be backed out. If you use theNEW VALUEphrase, then the new value is available for validation via the value1 variable. Each way accomplishes the same task; it's a matter of coding preference.TRIGGER PROCEDURE FOR ASSIGN { { OF table .field } | { NEW [ VALUE ] value1 { AS data-type | LIKE db-field } } } [ COLUMN-LABEL label ] [ FORMAT format-string ] [ INITIAL constant ] [ LABEL label-string ] [ NO-UNDO ] [ OLD [ VALUE ] value2 { AS data-type | LIKE db-field } [ COLUMN-LABEL label ] [ FORMAT format-string ] [ INITIAL constant ] [ LABEL label-string ] [ NO-UNDO ] ]
Examples
The following is a WRITE trigger for the Customer table.
It uses the OLD BUFFER option so that it can determine whether the CustNum value has changed. If the Customer's outstanding balance
exceeds its Credit Limit, the trigger returns the error condition (in which case the record
is not updated).
r-wrcust.p
|
The following is an example of an ASSIGN
trigger using the OF phrase.
|
The following is an example of an ASSIGN
trigger using the NEW [VALUE] phrase.
|
Notes
- Use the Data Dictionary to associate a trigger procedure with a table or field in the database.
- Some 3GL applications execute schema triggers. Triggers might also be executed in batch mode. Therefore, you should avoid any user-interface interactions within schema trigger procedures.
- For a
TRIGGER PROCEDURE FOR WRITEtheOLD BUFFERdoes not contain a before image for CLOB or BLOB columns. - For
WRITEandREPLICATION-WRITEtriggers, do not try to access any lob fields in theOLD BUFFERbuffer. If the value of the field was changed, the old buffer would not contain the old value of the lob field. This is because the actual data for the lob field does not reside in the record itself, and the lob field in the old buffer would possibly be pointing at random data or have the wrong data size.