<dbupdate>

Purpose The <dbupdate> statement is used to execute SQL UPDATE statements on a database via a created connection. This first implementation of the Superx++ run-time engine for Microsoft Windows uses an ODBC connection for this. The <dbupdate> statement traverses a tree beginning at a specified node. Every time it reaches a node specified in the <at> clause, the code to perform the SQL UPDATE executes. In this manner we are able to use XML data to drive a relational data modification. This is an hierarchical (XML) to relational data conversion. It is called traversal dumping because of the traversal of the XML nodes which drives the process.
Format <dbupdate name="{upd name}" connect="{conn name}">
   <src>
      {traversal object}
   </src>
   <at node="{exec node}">
      <parm type="{parm type}" name="{parm name}">
         {parm value}
      </parm>
      <sql>
         {upd stmt}
      </sql>
      <onfail>
         {fail statements}
      </onfail>
      <onsuccess />
         {success statements}
      </onsuccess>
   </at>
</dbupdate>

{upd name} the name of the update object
{conn name} the name of the connection object to be used for the execution of the SQL UPDATE
{traversal object} the node (XML, not the name) to be traversed and which will provide the triggers for the <at> clauses
{exec node} the node, which if found in the traversal, will trigger the execution of the code within the <at> clause
{parm type} (optional) the datatype of the parameter to be substituted into {upd stmt}
{parm name} (optional) the name of the parameter to be substituted into {upd stmt}
{parm value} (optional) the value of the parameter to be substituted into {upd stmt}
{upd stmt} the SQL UPDATE statement to be executed on the database
{fail statements} the Superx++ statements to be executed if the database returned an error after the execution of {upd stmt}
{success statements} the Superx++ statements to be executed if the database was successful in the execution of {upd stmt}
Example #1 <var type="string" name="DbErr">No</var>
<node name="MyDbXML">
   <Emps>
      <Emp var_int_Age="30">
         <EmpName>Sandr.ie</EmpName>
         <Age>25</Age>
         <Addresses>
            <Address>
               <Street>The Nice Road</Street>
               <City>Niceville</City>
               <Duration>10</Duration>
            </Address>
            <Address>
               <Street>56 Hope Road</Street>
               <City>Kingston</City>
               <Duration>20</Duration>
            </Address>
         </Addresses>
      </Emp>
      <Emp var_int_Age="77">
         <EmpName>Dedan</EmpName>
         <Age>34</Age>
         <Address>
            <Street>1 Kijabe Street</Street>
            <City>Some Place</City>
            <Duration>30</Duration>
         </Address>
      </Emp>
   </Emps>
</node>

<dbupdate name="MySQLObj" connect="MyDbConn">
   <src>
      <eval object="MyDbXML" />
   </src>
   <at node="Emp">
      <parm type="string" name="a"><eval object="EmpName" /></parm>
      <parm type="int" name="b"><eval object="Age" /></parm>
      <sql>
         update xppTbl set Age = b
         where EmpName = a;
      </sql>
      <onfail>
         <eval object="DbErr">Yes</eval>
         <xout><dberr connection="MyDbConn" /></xout>
      </onfail>
      <onsuccess>
         <xout>Success for Emp: </xout>
         <xout><eval object="EmpName" /></xout>
      </onsuccess>
   </at>
   <at node="Address">
      <parm type="string" name="a"><eval object="EmpName" /></parm>
      <parm type="string" name="b"><eval object="Street" /></parm>
      <parm type="string" name="c"><eval object="City" /></parm>
      <parm type="string" name="d">Superx++></parm>
      <sql>
         update xppChildTbl set LastUpdBy = d
         where EmpName = a
         and Street = b
         and City = c;
      </sql>
      <onfail>
         <eval object="DbErr">Yes</eval>
         <xout><dberr connection="MyDbConn" /></xout>
      </onfail>
      <onsuccess>
         <xout>Success updating Address for Emp: </xout>
         <xout><eval object="EmpName" /></xout>
      </onsuccess>
   </at>
</dbupdate>

performs a set of SQL UPDATE statements on a database via the connection MyDbConn that was created using the <dbconnect> statement. The tree of nodes starting with MyDbXML is traversed. Every time the node Emp or Address is reached, the UPDATE statement is sent to the database for processing. If the execution was successful then the <onsuccess> clause executes; else the <onfail> clause executes.