|
When altering multiple related database records, it's important that all transactions proceed.
Attributes
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. ExampleIn 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 sucessfully. Example:<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">
|