ROLLBACK |
Rollback is used to quit a transaction.
Rollback
# Transaction: debits an account CPT_D and credits and account CPT_C
# with the same TRANSFERT value. On
return from the sub-programme,
# SUCCES=1 if the operation was
successful, otherwise SUCCES=0.
#
TRANSFERT_SOMME
#
# Start of transaction
Trbegin [CPT]
#
# The first account is debited
Readlock [CPT]NOCPT=CPT_D
If fstat : Goto
ABANDON : Endif
[CPT]SOLDE -=
TRANSFERT
Rewrite [CPT]
If fstat : Goto
ABANDON : Endif
#
# The second account is credited
Readlock [CPT]NOCPT = CPT_C
If fstat : Goto
ABANDON : Endif
[CPT]SOLDE +=
TRANSFERT
Rewrite [CPT]
If fstat : Goto
ABANDON : Endif
#
# Validation of the transaction and
return.
Commit : SUCCES = 1
Return
#
# Transaction cancelled and return
in the event of error
ABANDON
Rollback : SUCCES = 0
Return
Rollback is used to cancel a transaction, that is a set of operations to update files and/or counters as well as lock operations started by the Trbegin instruction.
The tables are restored to the state they were in before the transaction was initiated, then closed again and all locked removed. Only locks placed on symbols before the transactions started will be left in place. The transaction is not entered in the lock file – if required.
A Rollback can only be carried out by the routine or sub-programme that started the transaction. This applies in particular for error management, interrupt management or disconnection programmes.
If a programme or sub-programme that started a transaction is interrupted, a Rollback will be performed automatically. This is valid in the following cases:
· end of programme (End instruction or physical end of the programme)
· error detection and in the absence of the branching sub-programme (Onerrgo).
· interruption of routine made interruptible by the Inter instruction, and where there is no branching sub-programme (Onintgo).
· disconnection (click on the cross, or accidental line break)
· stop by pressing the <STOP> key.
The user will be warned of this cancellation.
While the Commit instruction is very quick, Rollback is an operation that may take a long time, since it involves "replaying" in reverse all the modifications made to the database. It should therefore not be used as a programming tool.
Rollback obviously does not affect the variables and sequential files open by Openo and Openio.
Example
:
$TR
: # Start of
the transaction
Trbegin
If [V]COMP = 0
[V]COMP = [C]CPT
Endif
[C]CPT += 1
If fstat = 1 : # In the event of lock
Rollback : Goto TR : # of [C]CPT by another
Endif : # adonix which increments it
Commit
....
Let us assume that [V]COMP is null at the outset and [C]CPT is set to 23. If there are no problems, in the end [V]COMP will be at 23 and [C]CPT at 24. If the same routine has been started from another station, at the end [V]COMP will be at 23 and [C]CPT at 25.
|
Error |
Description |
|
ERRET (32) |
The transaction was started at another level. |
|
PADTRAN (48) |
No transaction in progress. |
TRBEGIN - COMMIT - ONERRGO - ONINTGO - ACTIHGUP
|
|