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

    Brian Paige
    Participating Frequently
    May 16, 2022 4:47 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!

    In Universe, it's actually two words - CREATE TRIGGER.

    Try HELP SQL CREATE for more info.

    Brian
    Manu Fernandes
    Inspiring
    May 16, 2022 4:48 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

    Yes on UV, triggers are documented/part of SQL engine. 

    look at HELP SQL CREATE TRIGGER / DROP TRIGGER. 

    You can use it against standard non SQL  uv datafile. 

    be carefull, if you change the subr after create trigger you must drop/create. 

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------
    KathleenHambrick
    Participating Frequently
    May 16, 2022 5:37 PM UTC
    Hi

    Yes on UV, triggers are documented/part of SQL engine. 

    look at HELP SQL CREATE TRIGGER / DROP TRIGGER. 

    You can use it against standard non SQL  uv datafile. 

    be carefull, if you change the subr after create trigger you must drop/create. 

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------
    SO... cant find the catalog table - im used to CTLGTB.... if there a table of catalogued programs in universe?


    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    KathleenHambrick
    Participating Frequently
    May 16, 2022 5:49 PM UTC
    SO... cant find the catalog table - im used to CTLGTB.... if there a table of catalogued programs in universe?


    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    The only example in the manuals i see is specific to an sql file. Trying this at tcl gives me an 'SQL+' prompt. Can someone show me the syntax to put a trigger on a non sql file please?


    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    Manu Fernandes
    Inspiring
    May 17, 2022 3:27 AM UTC
    The only example in the manuals i see is specific to an sql file. Trying this at tcl gives me an 'SQL+' prompt. Can someone show me the syntax to put a trigger on a non sql file please?


    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    hello kathleen,

    yes, triggers are member of universe 'SQL engine'... you miss the semi-colon at then end of the phrase ... 
    CREATE TRIGGER TRIGGER1 AFTER INSERT OR UPDATE OR DELETE ON MYFILE FOR EACH ROW CALLING '*MYTRIGGER' ; ​

    i'm used to create a VOC PARAGRAPH to set/update a trigger on a file 

    first, basic/catalog globally 

    BASIC BP TRIG.LOG.b
    CATALOGI BP *TRIG.LOG TRIG.LOG.b FORCE
    

    next, define the paragraph

    ED VOC SET.TRIG.LOG
    PA 
    DROP TRIGGER <<I2,filename>> TRIGLOG ;
    CREATE TRIGGER TRIGLOG AFTER INSERT OR UPDATE OR DELETE ON <<I2,filename>> FOR EACH ROW CALLING '*TRIG.LOG';
    
    next, use on file 
    SET.TRIG.LOG MYFILE 


    ------------------------------
    Manu Fernandes
    ------------------------------
    Manu Fernandes
    Inspiring
    May 17, 2022 3:30 AM UTC
    hello kathleen,

    yes, triggers are member of universe 'SQL engine'... you miss the semi-colon at then end of the phrase ... 
    CREATE TRIGGER TRIGGER1 AFTER INSERT OR UPDATE OR DELETE ON MYFILE FOR EACH ROW CALLING '*MYTRIGGER' ; ​

    i'm used to create a VOC PARAGRAPH to set/update a trigger on a file 

    first, basic/catalog globally 

    BASIC BP TRIG.LOG.b
    CATALOGI BP *TRIG.LOG TRIG.LOG.b FORCE
    

    next, define the paragraph

    ED VOC SET.TRIG.LOG
    PA 
    DROP TRIGGER <<I2,filename>> TRIGLOG ;
    CREATE TRIGGER TRIGLOG AFTER INSERT OR UPDATE OR DELETE ON <<I2,filename>> FOR EACH ROW CALLING '*TRIG.LOG';
    
    next, use on file 
    SET.TRIG.LOG MYFILE 


    ------------------------------
    Manu Fernandes
    ------------------------------
    oops do not forget semin-colon at the end of DROP TRIGGER filename triggername ;

    ------------------------------
    Manu Fernandes
    ------------------------------
    Manu Fernandes
    Inspiring
    May 17, 2022 3:57 AM UTC
    hello kathleen,

    yes, triggers are member of universe 'SQL engine'... you miss the semi-colon at then end of the phrase ... 
    CREATE TRIGGER TRIGGER1 AFTER INSERT OR UPDATE OR DELETE ON MYFILE FOR EACH ROW CALLING '*MYTRIGGER' ; ​

    i'm used to create a VOC PARAGRAPH to set/update a trigger on a file 

    first, basic/catalog globally 

    BASIC BP TRIG.LOG.b
    CATALOGI BP *TRIG.LOG TRIG.LOG.b FORCE
    

    next, define the paragraph

    ED VOC SET.TRIG.LOG
    PA 
    DROP TRIGGER <<I2,filename>> TRIGLOG ;
    CREATE TRIGGER TRIGLOG AFTER INSERT OR UPDATE OR DELETE ON <<I2,filename>> FOR EACH ROW CALLING '*TRIG.LOG';
    
    next, use on file 
    SET.TRIG.LOG MYFILE 


    ------------------------------
    Manu Fernandes
    ------------------------------
    some notes : 

    1/ Trigger must be dropped and created again. 
    Problem
    If trigger program is changed after creation, the trigger must be dropped and created again. This presents problems, for example, when a new release of application software is deployed. Typically, program libraries will be reloaded and recataloged. If trigger programs have changed, all files will need to be checked, triggers dropped and recreated.
    Cause
    The pointer to the trigger program object code resides in the SICA of the file header. 
    Solution
    Workaround: Make the trigger program a simple call to an external subroutine. The external subroutine may now be modified without affecting the trigger

    2/ triggers execution are part of  an implicit  'TRANSACTION' processing
    2.1/ the TRANSACTION BEGin is started by the 'WRITE' verb of the parent execution.  Then all BEGIN TRANSACTION restriction occurs inside triggers.
    2.2 / you must get the lock (READU / RECORDLOCKU) before update another file 
    2.3/ you can't execute verb which require a new level. 
    2.4/ be carefull if the parent already have the lock of a record, the on-file record can be wrong value 
    2.5/ if the parent start a explicit BEGIN TRANSACTION, all locks set by the triggers are held by the session (as part of the parent TRANSACTION)  until TRANSACTION COMMIT/ROLLBACK ... 
    2.6/ if the parent use explicit BEGIN TRANSACTION and perform ROLLBACK triggers update are ROLLBACK'ed too, the only way to have the trace of the triggers call is via OPENSEQ/WRITESEQ which are not part of TRANSACTION processing.

    3/ check trigger infinite loop
    sometime, you can create infinite loop, if triggers update file where triggers are fired.
    you can use the system(9001) to check if the trigger is in the parent call stack. 

    4/ triggers must be created on 'closed file' 
    if  session-A have the file opened on  runtime filevariable/common and session-B CREATE TRIGGER on the file, the session-A does not known the trigger, session-A must reopen the file.  because, as for indices, triggers info/p-code are in the header of the file - loaded on the filevariable. 

    I hope this help



    ------------------------------
    Manu Fernandes
    ------------------------------
    Harold Hambrick
    Participating Frequently
    May 17, 2022 8:39 AM 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
    ------------------------------
    Kathleen,

    We use them very sparingly but I've have good success using the methods defined on this post.
    https://www.intl-spectrum.com/Article/r310/Auditing_Database_Changes_with_UniVerse_Indexing_Subroutines

    Harry

    ------------------------------
    Harry Hambrick
    Senior Software Developer
    Rooms To Go Inc
    Seffner FL US
    ------------------------------
    Jonathan Smith
    Rocketeer
    May 17, 2022 9:07 AM UTC
    Kathleen,

    We use them very sparingly but I've have good success using the methods defined on this post.
    https://www.intl-spectrum.com/Article/r310/Auditing_Database_Changes_with_UniVerse_Indexing_Subroutines

    Harry

    ------------------------------
    Harry Hambrick
    Senior Software Developer
    Rooms To Go Inc
    Seffner FL US
    ------------------------------
    Kathleen,

    One difference that has not been mentioned in relation to triggers with UniVerse and UniData. When you use a trigger it will be treated as though it was part of a transaction. On UniData you will never have noticed this as UniData does not enforce isolation levels of a transaction, you have to code to an isolation level. In UniVerse isolation levels can be enforced and by default the UniVerse tuneable ISOMODE is set to 1, which enforces protection against UnCommitted Reads.

    In short for someone coming from UniData to UniVerse and wanting to use Triggers (or transactions) then every record that you are going to update should have an exclusive lock set on it and if you are going to just read a record in a Trigger (or transaction) you should read the record with a shared lock (see READL).

    Failure to follow these rules in UniVerse you may see an error stating that the locks are not set to the required level to perform an operation. As I said these rules are not enforced in UniData (but should be).

    Thanks,


    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    Chuck Stevenson
    Participating Frequently
    May 17, 2022 10:17 AM 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
    ------------------------------
    I have played with UV triggers in the pastand have ended up avoiding them.
    At first, iirc, they were slow.  I don't think that is a problem now,  but the RAID debugger doesn't play nicely with them the last time I checked.
    Does anyone know if that is still true?  (I've always found the debugger the buggiest part of most programming languages.)

    When Prime Information first introduced indexing decades ago,  I was a beta site.   I recognized that, with a little work, one could effect a trigger by indexing NO.NULLS, letting your subroutine do whatever you need, then always returning null.  The tricky part was knowing if your subroutine were being called for an add, delete, or change.  (An index gets called once for an add, 2x for a change (evaluate the old version, then the new & see if it has changed), and 1x for a delete of the record being indexed.)   I suggested inventing an @-variable flag for that. Finally, at UV 11.x we have @IDX.IOTYPE so you can do that more easily.
    ​​
    I was going to write up how to do that, but earlier in this thread Harry Hambrick already pointed to a Spectrum by Clif Oliver:  www.intl-spectrum.com/Article/r310/Auditing_Database_Changes_with_UniVerse_Indexing_Subroutines.   Kudos, Clif.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    San Ignacio BZ
    ------------------------------