Using Save-Row-Changes not causing triggers to fire

Posted by kopfb on 26-Apr-2011 11:30

All,

I'm running into an issue where DB triggers are not firing when using Save-Row-Changes. We have trigger files (.t) where in this particular case a sequence is generated and added to the record during a create. The record is created but just not the sequence, timestamps or user name info. Here is a snippet of the code. I'm not sure what I am missing here?

IF VALID-HANDLE (hBeforeBuf) THEN DO:
    IF NOT VALID-HANDLE(hBeforeQry) THEN
        CREATE QUERY hBeforeQry.
   
    CREATE BUFFER hDBBuffer FOR TABLE hBuffer:NAME.
    CREATE DATA-SOURCE hDataSource.
    hDataSource:ADD-SOURCE-BUFFER(hDBBuffer:HANDLE,pcKeys).
    hSrcBuffer = phDataset:GET-BUFFER-HANDLE(1).
    hSrcBuffer:ATTACH-DATA-SOURCE(hDataSource).
    hSrcBuffer:DATA-SOURCE:QUERY:QUERY-PREPARE("FOR EACH " + hBuffer:NAME + " NO-LOCK").
   
    hBeforeQry:SET-BUFFERS(hBeforeBuf).
    hBeforeQry:QUERY-PREPARE("FOR EACH " + hBeforeBuf:NAME).
    hBeforeQry:QUERY-OPEN().
    hBeforeQry:GET-FIRST().
    DO TRANSACTION WHILE NOT hBeforeQry:QUERY-OFF-END:               
        hDataSource = hBuffer:DATA-SOURCE.
        IF NOT VALID-HANDLE(hDataSource) THEN
            RETURN ERROR SUBSTITUTE('Before image records found, but no data-source defined (&1)', hBuffer:NAME).
       
        hBuffer:FIND-BY-ROWID(hBeforeBuf:AFTER-ROWID) NO-ERROR.
       
        IF NOT hBeforeBuf:ERROR THEN DO:
            DO iBufferIndex = 1 TO hDataSource:NUM-SOURCE-BUFFERS :
                DO ON ERROR UNDO, LEAVE:
                    hBeforeBuf:SAVE-ROW-CHANGES(iBufferIndex) NO-ERROR.
                END.
               
                IF hBeforeBuf:ERROR AND hBeforeBuf:ERROR-STRING = ? THEN DO:
                    ASSIGN                      
                        hBeforeBuf:ERROR         = TRUE 
                        hBeforeBuf:REJECTED      = YES
                        hBeforeBuf:ERROR-STRING = ERROR-STATUS:GET-MESSAGE(1) + ERROR-STATUS:GET-MESSAGE(2) +
                        RETURN-VALUE.
                END. /* IF hBeforeBuf:ERROR */
            END. /* DO iBufferIndex */
        END. /* IF NOT hBeforeBuf:ERROR */
        hBuffer:ACCEPT-ROW-CHANGES () NO-ERROR.
       
        hBeforeQry:GET-NEXT().
    END. /* DO TRANSACTION */
END. /* IF VALID-HANDLE */

Thanks,

Brad

All Replies

Posted by rbf on 26-Apr-2011 13:51

You need to skip the fields that are being assigned in create triggers:

handle:SAVE-ROW-CHANGES( [ buffer-index | buffer-name 
                         [ , skip-list [ , no-lobs ] ] ] )

An optional character expression that  evaluates to a comma-separated list of field names for fields that should  not be assigned after a new row is created (that is, fields to skip). For  example, a key field or other fields assigned a value by a CREATE database  trigger.

-peter

Posted by kopfb on 26-Apr-2011 16:02

Thanks Peter...that worked!!

Posted by rbf on 26-Apr-2011 16:17

You need to skip the fields that are being assigned in create triggers:

I forgot to explain why:

Contrary to what you are/were thinking, your create triggers are firing and properly populating your fields.

But without the skip-list they are subsequently immediately overwritten with the initial values from your buffer.

-peter

Posted by Admin on 26-Apr-2011 16:30

Contrary to what you are/were thinking, your create triggers are firing and properly populating your fields.

Because due to the atomic nature of SAVE-ROW-CHANGES there is no place to populate the temp table with the result of the DB create trigger before the (not struck by the create trigger) values of the ProDataset temp-table buffer are all assigned to the DB - over the result of the create trigger.

This thread is closed