Rollback

Rollback is used to end a database transaction and comes back to the situation before the beginning of the transaction (Trbegin).

Syntax

 Rollback

Examples

# This subprogram debits an account ACCOUNT1 and credits and account ACCOUNT2 with an AMOUNT value# It manages a transaction except if a transaction is already in progress# OPERATION_STATUS returns [V]CST_AOK if the operation was successful, otherwise it returns [V]CST_AERROR.# If a fatal error happens, OPERATION_STATUS returns [V]CST_AFATALSubprog TRANSFER(ACCOUNT1, ACCOUNT2, AMOUNT, RATE, OPERATION_STATUS)Value Char ACCOUNT1(), ACCOUNT2()Value Decimal AMOUNT,RATEVariable Integer OPERATION_STATUSLocal Integer IF_TRANS# Manage the exceptionsOnerrgo ABORT_TRANS# Start the transaction if no transaction is in progressLocal File ACCOUNTIf adxlogTrbegin ACCOUNTIF_TRANS=0Else# The transaction has been started by the calling programIF_TRANS=1Endif# Debit operation (CODE is a unique index so only one database line is updated)Update ACCOUNT Where CODE=ACCOUNT1 With BALANCE=BALANCE-ar2(AMOUNT/RATE)If fstat# If IF_TRANS=1, the transaction must been aborted by the calling programIf IF_TRANS=0 : Rollback : EndifOPERATION_STATUS=[V]CST_AERROREndEndif# Credit operationUpdate ACCOUNT Where CODE=ACCOUNT2 With BALANCE=BALANCE+ar2(AMOUNT/RATE)If fstat# If IF_TRANS=1, the transaction must been aborted by the calling programIf IF_TRANS=0 : Rollback : EndifOPERATION_STATUS=[V]CST_AERROREndEndif# The operation is successful. If IF_TRANS=1, the transaction must been committed by the calling programIf IF_TRANS=0 : Commit : EndifOPERATION_STATUS=[V]CST_AOKEnd# Error management# This may happen for instance when RATE is 0 (division by zero)$ABORT_TRANSIf IF_TRANS=0 : Rollback : EndifOPERATION_STATUS=[V]CST_AERROREnd

Description and comments

Associated errors

CodeDescription
32Transaction started at a higher level of the nesting call.
48No transaction in progress.

See also

File, Trbegin, Commit, Onerrgo, Read, Write, Writeb, Rewrite, RewriteByKey, Delete, DeleteBykey, Lock, adxlog.