Working with Unrestricted Database Triggers

David MeegoI recently responded on a Newsgroup posting where the developer was wanting to identify a table delete event from a particular form. However, the delete event was happening in a function or procedure that did not pass a form's table buffer as a parameter and so did not use a form level table buffer belonging to any form. This means that it was not possible to use a form restricted database trigger, but using an un-restricted database trigger was picking up table delete events from multiple forms.

So how can I identify when the database event is being generated from the form I am interested in?

The truth is that you will not be able to identify an event from the form in question, but you can identify if the event has come from another form. The idea is that rather than identifying when it comes from our form, we can identify when it does not come from our form instead.

The suggestion I provided was to register form restricted triggers against the forms that you know the table record can be deleted from as well as a unrestricted trigger. Make sure that the form restricted triggers are registered first so that they fire first. Then you can set a global boolean flag variable to signify that this occurrence of the trigger comes from a form.

When the unrestricted trigger fires, it can check the flag to see if this event has already been picked up. Before exiting the handler script, clear the boolean flag ready for the next event.

Below is example code showing this technique using 'MBS Table Restricted Flag' of globals:

Startup Global Procedure

 pragma(disable warning LiteralStringUsed);

if Trigger_RegisterDatabase(anonymous(table RM_Customer_MSTR), form RM_Customer_Maintenance , 
  TRIGGER_ON_DB_DELETE, script MBS_RM_Customer_MSTR_Restricted) <> SY_NOERR then
        warning "Database trigger table RM_Customer_MSTR form RM_Customer_Maintenance failed.";
end if;

if Trigger_RegisterDatabase(anonymous(table RM_Customer_MSTR), form RM_Customer_Address , 
    TRIGGER_ON_DB_DELETE, script MBS_RM_Customer_MSTR_Restricted) <> SY_NOERR then
        warning "Database trigger table RM_Customer_MSTR form RM_Customer_Address failed.";
end if;

if Trigger_RegisterDatabase(anonymous(table RM_Customer_MSTR), 0 , 
   TRIGGER_ON_DB_DELETE, script MBS_RM_Customer_MSTR_Unrestricted) <> SY_NOERR then
      warning "Database trigger table RM_Customer_MSTR Unrestricted failed.";
end if;

pragma(enable warning LiteralStringUsed);

MBS_RM_Customer_MSTR_Restricted Global Procedure

 inout table RM_Customer_MSTR;
in integer IN_Operation;

{ Restricted Table Trigger Code here }
 

'MBS Table Restricted Flag' of globals = true;

MBS_RM_Customer_MSTR_Unrestricted Global Procedure

 inout table RM_Customer_MSTR;
in integer IN_Operation;

if not 'MBS Table Restricted Flag' of globals then
    { Unrestricted Table Trigger Code here }
    
end if;

'MBS Table Restricted Flag' of globals = false;

Hope you find this technique useful.

David

06-Mar-2009: Added example scripts.