Progress
Programming
Handbook


Schema Triggers

You create schema triggers through the Table or Field Properties dialog box in the Data Dictionary. When you use the Data Dictionary to define a schema trigger for a table or field, the trigger is automatically added to the table or field’s data definitions. Progress allows you to define the trigger while you are creating or modifying a table or field. This trigger definition is stored in a trigger procedure. A trigger procedure is a Progress procedure file that begins with a trigger header statement. When defining the trigger, you have the option to specify CRC checking. Thus Progress can verify that the trigger procedure is valid before running it.

When application procedures are compiled against a database, schema triggers are not compiled into the application r-code, unlike delete or field validation in the Data Dictionary.

For information on using the Data Dictionary to create and delete triggers, see the Progress Basic Database Tools manual (character only), and for graphical interfaces, the on-line help for the Data Dictionary. For more information on CRCs and schema triggers, see "R-code Features and Functions."

CREATE, DELETE, and FIND Headers

This is the syntax for the trigger header for a CREATE, DELETE, FIND, REPLICATION–CREATE, or REPLICATION–DELETE trigger:

SYNTAX
TRIGGER PROCEDURE FOR 
  {   FIND 
   | CREATE 
   | DELETE 
   | REPLICATION-CREATE 
   | REPLICATION-DELETE 
   } OF table 

References to the record can be made through an automatic buffer defined as part of the trigger header. Its name is the same as the table name.

WRITE Header

This is the syntax for the trigger header for a WRITE or REPLICATION–WRITE event:

SYNTAX
TRIGGER PROCEDURE FOR { WRITE | REPLICATION-WRITE } OF table 
  [ NEW [ BUFFER ] buffer-name1 ] 
  [ OLD [ BUFFER ] buffer-name2 ] 

When executing a WRITE trigger, or a REPLICATION–WRITE trigger, Progress makes two record buffers available to the trigger procedure. The NEW buffer contains the modified record that is being validated. The OLD buffer contains the most recent version of the record before the latest set of changes were made (this is the template record if it is a newly created record, the record from the DB if it is not been validated, or the most recently validated record if it has been validated). You can modify the contents of the NEW buffer, but the OLD buffer is read-only. You can compare the contents of these two buffers and perform actions based on the results.

If you do not specify a NEW buffer, you can use the table name to make any comparisons to the OLD buffer. If you specify neither OLD or NEW buffers, you may reference the new record via the automatically created buffer named for the table itself.

You can determine whether the record being written is newly created by using the Progress NEW function. This function returns TRUE if Progress has not written the record to the database; otherwise, it returns FALSE. However, the NEW function continues to return TRUE even if Progress has validated the record but has not written it to the database.

ASSIGN Header

This is the syntax for the trigger header for an ASSIGN event:

SYNTAX
TRIGGER PROCEDURE FOR ASSIGN 
  {    OF table.field 
    | NEW [ VALUE ]parameter1 { AS data-type | LIKE field  
  } 
      [    COLUMN-LABEL label 
         | FORMAT string 
         | INITIAL constant 
         | LABEL string 
         | NO-UNDO 
      ] 
  [ OLD [ VALUE ]parameter2 { AS data-type | LIKE field } 
  ] 
      [   COLUMN-LABEL label 
         | FORMAT string 
         | INITIAL constant 
         | LABEL string 
         | NO-UNDO 
  ] 

You can obtain the newly assigned value from the record buffer if you specify the OF option (this gives you access to the rest of the record also; whereas NEW and OLD give access to the fields only), or you can obtain the value from parameter1 if you specify the NEW option. If you want to access the value stored in the database, use the OLD option. The value of the field before the assignment is stored in parameter2. You can use the NEW and OLD options to compare the value being written to the existing value. Progress treats the old value as an input run time parameter; you can modify it, but this modification has no effect on the triggering procedure.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095