Skip to main content
KathleenHambrick
Participating Frequently
May 16, 2022 4:37 PM UTC

TRIGGERS

Hi - as ive mentioned in previous threads, I just switched from unidata to universe.  A coworker mentioned a trigger but I do not see a version of my unidata commands:

CREATE-TRIGGER, LIST-TRIGGER, DELETE-TRIGGER

I do see the LIST.SICA command, which lists universe triggers on SQL files....do we not have triggers on regular PICK files in universe?

------------------------------
Kathleen Hambrick
Programmer at Colwell
------------------------------

    28 replies

    Peter Cheney
    Participating Frequently
    May 24, 2022 8:35 PM UTC
    Hi - as ive mentioned in previous threads, I just switched from unidata to universe.  A coworker mentioned a trigger but I do not see a version of my unidata commands:

    CREATE-TRIGGER, LIST-TRIGGER, DELETE-TRIGGER

    I do see the LIST.SICA command, which lists universe triggers on SQL files....do we not have triggers on regular PICK files in universe?

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    Hi @Kathleen Hambrick,
    If you haven't already found it, LIST.SICA filename will tell you some information
    LIST.SICA CUSTOMER 10:29:18am  25 May 2022   Page    1
    ==========================================
    Sica Region for Data File "CUSTOMER"
      Revision:        4
      Trigger "CUSTOMER.DELETE.FTRIG" is enabled, creator is "peter".
              calls "*FMC*SR.MASTER.FTRIG" for          Row After Delete
      Trigger "CUSTOMER.UPDATE.FTRIG" is enabled, creator is "peter".
              calls "*FMC*SR.MASTER.FTRIG" for          Row After Update
      Trigger "CUSTOMER.INSERT.FTRIG" is enabled, creator is "peter".
              calls "*FMC*SR.MASTER.FTRIG" for          Row After Insert
    >​


    ------------------------------
    Peter Cheney
    Developer and Systems Superstar
    Firstmac
    Brisbane Qld Australia
    ------------------------------
    Chuck Stevenson
    Participating Frequently
    May 24, 2022 8:45 PM UTC

    You can actually use a "master" globally cataloged subroutine that calls other subroutines based on how you activate the trigger.
    We have about a dozen or so triggers on all sorts of files. Each file that has a trigger has it's own trigger subroutine. So for a customer file you might name this trigger "SR.CUSTOMER.FTRIG" (cataloged locally) which is called by "SR.MASTER.FTRIG" (cataloged globally).

    We've found that you can actually re-compile these locally cataloged subroutines without having to drop/activate the trigger UNLESS your system is super busy AND the trigger is on a file that is being hit very hard, in which case you might end up having to bounce UniVerse. This may also be a feature of our old UV version too. I'm sure you'll find out soon enough - we did. Nowadays we arrange an outage to deploy trigger changes but thankfully this is not very often.

    @Kathleen Hambrick: Ken Ford, my former colleague here wrote a really nice utility to control the trigger enable/disable each trigger for each of the insert/modify/delete and before/after conditions for all the files that we run triggers on. It has a nice -DROPALL option but sadly no -STARTALL. Ken has posted this code publicly in the past so it has to be out there if you search for his name and/or the "MASTER.FTRIG.CONTROL" program name.

    Cheers,
    Peter

    ​

    ------------------------------
    Peter Cheney
    Developer and Systems Superstar
    Firstmac
    Brisbane Qld Australia
    ------------------------------
    Peter,
    What has been your experience using DEBUG or RAID on programs that write to files/tables having triggers?
    It was a problem a while back,  but I haven't tried it at UV11.
    tia,
    cds

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    San Ignacio BZ
    ------------------------------
    Peter Cheney
    Participating Frequently
    May 24, 2022 9:04 PM UTC
    Peter,
    What has been your experience using DEBUG or RAID on programs that write to files/tables having triggers?
    It was a problem a while back,  but I haven't tried it at UV11.
    tia,
    cds

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    San Ignacio BZ
    ------------------------------
    Hi @Chuck Stevenson,

    Debugging code that writes to files with triggers is a pain. We're on UV10.3.4 but have played with UV11.2 and it's still the same.
    Need to remember to always set a break point just beyond the write line. Sometimes I forget though haha.

    Cheers,
    Peter

    ------------------------------
    Peter Cheney
    Developer and Systems Superstar
    Firstmac
    Brisbane Qld Australia
    ------------------------------
    Chuck Stevenson
    Participating Frequently
    Jun 6, 2022 2:46 PM UTC
    Hi @Chuck Stevenson,

    Debugging code that writes to files with triggers is a pain. We're on UV10.3.4 but have played with UV11.2 and it's still the same.
    Need to remember to always set a break point just beyond the write line. Sometimes I forget though haha.

    Cheers,
    Peter

    ------------------------------
    Peter Cheney
    Developer and Systems Superstar
    Firstmac
    Brisbane Qld Australia
    ------------------------------
    Anyone,

    re. "Debugging code that writes to files with triggers is a pain. We're on UV10.3.4 but have played with UV11.2 and it's still the same."

    With the advent of @IDX.IOTYPE, is there any advantage to using formal UV Triggers instead of an index (usually with NO.NULLS) subroutine instead, as discussed earlier in this thread?
    ​

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Brian Paige
    Participating Frequently
    Jun 6, 2022 2:58 PM UTC
    Anyone,

    re. "Debugging code that writes to files with triggers is a pain. We're on UV10.3.4 but have played with UV11.2 and it's still the same."

    With the advent of @IDX.IOTYPE, is there any advantage to using formal UV Triggers instead of an index (usually with NO.NULLS) subroutine instead, as discussed earlier in this thread?
    ​

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Chuck,

    I am by no means a trigger or an indexing expert, so while I have found this discussion extremely educational, some if the items went a little beyond by skill level. I apologize ahead of time if the answer to my question was already covered and I either missed it or just plain didn’t understand.

    From what I can gather, a trigger-based program gets ‘fired’ when a file gets updated (or whatever condition is defined in the trigger), while an index-based program would get run when the index itself gets updated. What then happens when/if I have to clear the indices on a file and rebuild them? Won’t that rerun the program if it’s index-based and double-up on whatever that program was supposed to do?

    Brian
    Peter Cheney
    Participating Frequently
    Jun 7, 2022 5:36 PM UTC
    Anyone,

    re. "Debugging code that writes to files with triggers is a pain. We're on UV10.3.4 but have played with UV11.2 and it's still the same."

    With the advent of @IDX.IOTYPE, is there any advantage to using formal UV Triggers instead of an index (usually with NO.NULLS) subroutine instead, as discussed earlier in this thread?
    ​

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Hi Chuck,
    Thanks for the @IDX.IOTYPE tip. Looking forward to upgrade day when we can start using it.
    Cheers,
    Peter
    ------------------------------------------------------------------------------- Note: This email (inc all attachments) is for the use of the intended recipient(s) only. Privileged or confidential information may be contained in this communication. If you have received this email in error, please notify the sender immediately and then delete all copies of this message from your computer network. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this email without the author's prior permission. If you are the intended recipient and you do not wish to receive similar electronic messages from us in future, then please respond to the sender to this effect. We have taken precautions to minimise the risk of transmitting software viruses, but advise you to carry out your own virus checks on this email and its attachments. We do not accept liability for any loss or damage caused by software viruses and do not represent that this transmission is free from viruses or other defects. Firstmac Limited (ABN 59 094 145 963) (AFSL 290600)
    Chuck Stevenson
    Participating Frequently
    Jun 8, 2022 6:59 AM UTC
    Chuck,

    I am by no means a trigger or an indexing expert, so while I have found this discussion extremely educational, some if the items went a little beyond by skill level. I apologize ahead of time if the answer to my question was already covered and I either missed it or just plain didn’t understand.

    From what I can gather, a trigger-based program gets ‘fired’ when a file gets updated (or whatever condition is defined in the trigger), while an index-based program would get run when the index itself gets updated. What then happens when/if I have to clear the indices on a file and rebuild them? Won’t that rerun the program if it’s index-based and double-up on whatever that program was supposed to do?

    Brian
    For indexes the index-based program gets called whenever the record is updated.  It needs the subroutine's result to decide whether to update the index or not.
    For ADD it is called with the new version of the record & adds values to the index files accordingly.
    For DEL it is called with the old version of the record & deletes values from the index accordingly.
    For UPD it is called 2x,  once with the old, then with the new version of the record,  the results are compared to know if any index needs to be fixed.

    @IDX.IOTYPE lets the subroutine know which kind of operation is it currently being asked to perform.  That helps us programmers trick it into acting like a trigger (say spawning another phantom, or sending escalation notices,  logging something, whatever)  instead of actually indexing.

    One can envision performance problems,  but with modern hardware,  I have yet to hit that wall.​

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Chuck Stevenson
    Participating Frequently
    Jun 8, 2022 4:12 PM UTC
    Hi Chuck,
    Thanks for the @IDX.IOTYPE tip. Looking forward to upgrade day when we can start using it.
    Cheers,
    Peter
    ------------------------------------------------------------------------------- Note: This email (inc all attachments) is for the use of the intended recipient(s) only. Privileged or confidential information may be contained in this communication. If you have received this email in error, please notify the sender immediately and then delete all copies of this message from your computer network. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this email without the author's prior permission. If you are the intended recipient and you do not wish to receive similar electronic messages from us in future, then please respond to the sender to this effect. We have taken precautions to minimise the risk of transmitting software viruses, but advise you to carry out your own virus checks on this email and its attachments. We do not accept liability for any loss or damage caused by software viruses and do not represent that this transmission is free from viruses or other defects. Firstmac Limited (ABN 59 094 145 963) (AFSL 290600)
    One last thing I meant to mention earlier:
    The primary record's write, and any index updates and any updates explicitly made by a trigger or index subroutine are all under on logical transaction.  They either all happen,  or none of them.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------