trigger erase

Trigger that deletes all occurrences currently in the component, both in the external structure, and in the database. This is a very dangerous trigger—use it with extreme care!

Declaration: trigger erase
Applies to: Form
Activation: Activated by the ^ERASE structure editor function.
Default behavior: None
Behavior upon completion: None

Description

The erase trigger can be used to delete retrieved data from the database. The actual deletion of data is activated by the erase statement, which should be placed in this trigger.

Caution: The erase trigger can delete all data that has been retrieved into the component, which makes it very dangerous to use. Consider disabling the erase trigger by omitting the erase statement, or use it with extreme care.

Note:  As an alternative to erasing data, you can clear data from the form. The ^CLEAR structure editor function is safer than ^ERASE because it removes data from the form, but does not delete data stored in the database.

The process flow for the erase trigger is as follows:

  1. The ^ERASE structure editor function activates the erase trigger.
  2. Uniface activates the delete trigger for each occurrence retrieved from the database.
  3. For each occurrence, the delete statement in the delete trigger deletes the occurrence from the database.

Using erase in the erase Trigger

The ^ERASE function can be quite drastic. It is common to disable the erase trigger by omitting the erase statement from it, or to ask for confirmation for the drastic action of erasing all occurrences. For example:

trigger erase ; of component

if ($totocc(CUSTOMER) >= 1)
   askmess "%%$totocc(CUSTOMER) occurrences. Erase them all?"
   if ($status = 0)
      return
   endif
endif

erase

if ($status <0)
   message "Erase error; see message frame"
   rollback
else
   if ($status = 1)
      message "Erase is not allowed"
   else
      message "Erase was successful"
      commit
      if($status < 0)
         rollback
      endif
   endif
endif

end ; erase 

Related Topics