11.4 Virtual Triggers

In the same way that database triggers can fire before or after a triggering statement, embedded SQL can be positioned before or after the triggering XDS event. The following examples show how you can embed SQL before or after an XDS event.

Virtual Before Trigger

<input xmlns:jdbc"urn:dirxml:jdbc">
     <jdbc:statement>
          <association>idu=1,table=usr,schema=indirect</association>
          <jdbc:sql>UPDATE indirect.usr SET fname = 'John' WHERE                     idu = {$idu}</jdbc:SQL>
    </jdbc:statement>
    <modify class-name="usr">
        <association>idu=1,table=usr,schema=indirect</association>
        <modify-attr name="lname">
            <remove-all-values/> 
            <add-value>
                <value>Doe</value>
            </add-value>
        </modify-attr>
    </modify>
</input>

This XML resolves to:

SET AUTOCOMMIT OFF
UPDATE indirect.usr SET fname = 'John' WHERE idu = 1;
COMMIT; --explicit commit
UPDATE indirect.usr SET lname = 'Doe'  WHERE idu = 1;
COMMIT; --explicit commit

Virtual After Trigger

<input xmlns:jdbc"urn:dirxml:jdbc">
    <modify class-name="usr">
        <association>idu=1,table=usr,schema=indirect</association>
        <modify-attr name="lname">
            <remove-all-values/> 
            <add-value>
                <value>Doe</value>
            </add-value>
        </modify-attr>
    </modify>
    <jdbc:statement>
        <jdbc:sql>UPDATE indirect.usr SET fname = 'John' WHERE          idu = {$idu}</jdbc:sql>
    </jdbc:statement>
</input>

This XML resolves to:

SET AUTOCOMMIT OFF
UPDATE indirect.usr SET lname = 'Doe' WHERE idu = 1;
COMMIT; --explicit commit
UPDATE indirect.usr SET fname = 'John' WHERE idu = 1;
COMMIT; --explicit commit