Skip to content

MvCOMMIT#


When altering multiple related database records, it’s important that all transactions proceed. manual commits to writing database records.

Synax
<MvCOMMIT NAME = "string: {  expression } | literal"> 

Use <MvCOMMIT> to write all changes made within a transaction to the data files at once. If used outside of a transaction, it has no effect.


Attributes#

Attribute Description
NAME (Optional) Database alias. When a database is opened with <MvOPEN>, it is referenced in all other database commands by this alias. If omitted, the operation is performed on the primary database. The database must be open.

Normally database operations take place immediately when a database tag is executed.

Use <MvTRANSACT> to begin a new transaction when you want to save or cancel a series of changes made to data sources as a single unit. For example, to transfer money between accounts, you subtract an amount from one and add the same amount to the other. If either update fails, the accounts no longer balance. Making these changes within an open transaction ensures that either all or none of the changes go through.

If any errors are encountered, use <MvROLLBACK> to cancel all the changes; otherwise use <MvCOMMIT> to write the changes to the files at once.


Example#

In this example, a product is deleted that has relationships with other tables. If any of the delete functions fail the transaction is rolled back using <MvROLLBACK> to the previous state. The transaction is completed using <MvCOMMIT> only if all the deletions occur successfully.

<MvTRANSACT NAME="Merchant">

    <MvIF EXPR="{ NOT CategoryXProduct_Delete_All_Product( l.product:id ) }">
        <MvROLLBACK NAME="Merchant">
        <MvFUNCTIONRETURN VALUE="0">
    </MvIF>

    <MvIF EXPR="{ NOT Attribute_Delete_All_Product( l.product:id ) }">
        <MvROLLBACK NAME="Merchant">
        <MvFUNCTIONRETURN VALUE="0">
    </MvIF>

    <MvIF EXPR="{ NOT Product_Delete_ID( l.product:id ) }">
        <MvROLLBACK NAME="Merchant">
        <MvFUNCTIONRETURN VALUE="0">
    </MvIF>

<MvCOMMIT NAME="Merchant">