Consultor Eletrônico



Kbase P9427: Can two session triggers fire for the same database event?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   17/03/2005
Status: Unverified

GOAL:

Can two session triggers fire for the same database event? If ProcA calls ProcB and each has a session WRITE event trigger. Is it possible to fire both?

FIX:

No, only one database SESSION trigger can be active at any one time. If ProcA calls ProcB and each has a session WRITE event trigger then it is possible to choose which trigger will be active at any given time. However, no one single database event will ever fire two database SESSION Triggers fire serially in response to the same event instance. The following code sample demonstrates one way to control which SESSION WRITE trigger will fire by restricting the transaction scope of each:

/*************ProcA.p*****************/
DEFINE VARIABLE h AS HANDLE NO-UNDO.

DO TRANSACTION
/* Activate the local version of the trigger */
ON WRITE OF test DO:
MESSAGE PROGRAM-NAME(1) "~t"
" SESSION WRITE TRIGGER" "~n"
"Field Value" "~t" test.test
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END /* ON WRITE */.
CREATE test.
ASSIGN test = "FirstWriteEvent".
END. /* TRANSACTION */.

DO TRANSACTION:
/* Activate the external version of the trigger */
RUN c:\wrk\procB.p persistent SET h.

CREATE test.
ASSIGN test = "SecondWriteEvent".
END /* TRANSACTION */.
/*************************************/

/*************ProcB.p*****************/
ON WRITE OF test DO:
MESSAGE PROGRAM-NAME(1) "~t"
" SESSION WRITE TRIGGER" "~n"
"Field Value" "~t" test.test
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END /* ON WRITE */.
/*************************************/
If a SCHEMA WRITE trigger is defined for the same table, then it will fire each time AFTER the active SESSION TRIGGER fires.