Trigger Interaction

Pavan Yadav

Member
Hi All,

I just stuck with a basic understanding of trigger and needs to have some discussion on the same.
I don't have any real life scenario as of now, so trying to understand this with a basic example.

I defined Schema Level Find Trigger on my DB and Session Level Find trigger in my Program. While executing this, with no doubts, Schema Level will trigger first and then the Session Level. But, can you please assist if there is any way I can reverse this action and can execute Session level first and then Schema Level.

I tried using Override, but that triggers only session level and not schema Level.

Sample codes are as:
Schema Level:
Code:
TRIGGER PROCEDURE FOR FIND OF customer.
MESSAGE "Schema Trigger :: FIND"
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

Session Level:
Code:
ON FIND OF customer OVERRIDE
DO:
    MESSAGE "Session Trigger :: FIND"
        VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
  
FOR EACH customer exclusive-lock:
    UPDATE custnum NAME.
END.
 

Pavan Yadav

Member
So what can be the substitute for Triggers?
I just mentioned an example of FIND Trigger, it can be Create, Delete etc.
 

Cringer

ProgressTalk.com Moderator
Staff member
Ideally you probably want to handle all updates to records in a single location. In modern Progress releases you can do this with a class. That way you maintain consistency with your records, but you avoid triggers.
Part of the issue with triggers is that you lose the transparency of the code. Stuff happens and it's not clear why. Find triggers are the worst case because you find records being ignored, or weird stuff happening, 5 years down the line with a developer who didn't create the triggers and they have no idea why. There should be no valid use-case for find triggers.
 

Pavan Yadav

Member
But what the legacy applications then?
Leaving the FIND Trigger, I just put that as an example. What if I want to use Create Trigger and want to execute the Schema Trigger first and then session trigger. Is there anyway. Or does anyone here ever faced such requirement?
 

tamhas

ProgressTalk.com Sponsor
You only have a problem if you try to add triggers. Since the best practice is no triggers, this should not be a problem. Any issues you have about sequencing logic are better solved by writing a common object to handle persistence, put all the logic in there in whatever order you need it, and get rid of the existing trigger.
 

Pavan Yadav

Member
But schema trigger does have advantage if someone like:
Suppose I have written delete trigger on Schema Level, then if somebody tried to delete that record even without running the application, then that triggers get executed. So, that will an advantage to maintain consistency. Isn't it?
and this can't be substituted with some common object, as we need to call it before executing any such query. Am I missing something?
 

tamhas

ProgressTalk.com Sponsor
If you delete it from SQL, the ABL trigger won't fire. If you allow people into the procedure editor, they can do anything they want. I.e., the point is that the cure isn't delete triggers, but controlling access. Without that, you have nothing. The common Data Access object allows you to put all of the logic dealing with persistence in one place, makes it easy for people to interact with the data without understanding the schema, provides a point for access control, and anything you can do in any combination of triggers can be done there more clearly.
 

TomBascom

Curmudgeon
The point about SQL and the 4GL not respecting each other's triggers is, IMHO, the final nail in the coffin.

Quite aside from all of the architecture best practices issues triggers are utterly useless if you cannot count on them firing when the relevant event occurs.

Trigger's are a lot like the 4GL's SQL-89 syntax. It seemed like a good idea at the time but in today's world you are much better off forgetting that it exists.

Play around all you like -- but if you actually produce any code intended for production that uses triggers you should have your programming license revoked.
 

Pavan Yadav

Member
Thanks all for assistance.!!
I will try to workout on other better available option now. And will seek your further assistance if stuck somewhere.
 
Top