ROLLBACK

From Recital Documentation Wiki
Jump to: navigation, search

Purpose

Restore tables to their condition at the beginning of a transaction


Syntax

ROLLBACK [<workarea | alias> | (<expC>)]


See Also

BEGIN TRANSACTION, COMPLETED(), END TRANSACTION, ISMARKED(), RESET IN, SET ROLLBACK


Description

The ROLLBACK command is used in a BEGIN TRANSACTION ... END TRANSACTION block to roll back changes made to tables by any transaction performed between the two statements. ROLLBACK used by itself affects all open tables, but can be directed to a single table by specifying the <.dbf filename>. The filename can be substituted with an <expC>, enclosed in round brackets, which returns a valid filename. A 'transaction' is considered to be all the file modifications that occur within the commands BEGIN TRANSACTION and END TRANSACTION.

This command is particularly useful if an error occurs during a program modifying files. When BEGIN TRANSACTION is issued, all currently open files and all files opened between BEGIN and END TRANSACTION will have Before Image Journaling (BIJ) invoked automatically. The journals are stored in a log file <.log> that the Recital/4GL generates automatically. You can optionally specify the disk and directory path if you include them after the BEGIN TRANSACTION statement. If BIJ is not required on a particular file, then the command RESET IN <workarea> should be issued and journaling will no longer occur in that workarea.

The ROLLBACK() function returns .T. if a rollback succeeds. The COMPLETED() function can be used after the END TRANSACTION command to determine if any errors occurred during processing of the commands between BEGIN and END TRANSACTION. It returns .F. if errors occurred and .T. otherwise. If the command SET ROLLBACK is OFF, the COMPLETED() function can be used in conjunction with the ROLLBACK command to force a manual rollback. If SET ROLLBACK is ON and an error is encountered, any modifications to files within the transaction will be rolled back automatically to their state before the BEGIN TRANSACTION was executed.

Please note the following commands are not allowed during a transaction:

  • CLEAR ALL
  • CLOSE ALL
  • CLOSE DATABASE
  • CLOSE INDEX
  • MODIFY STRUCTURE
  • PACK
  • ZAP

If users do not have a specific reason for setting up manual error trapping and rollback routines using the ROLLBACK command, Recital Corporation recommends the use of the SET ROLLBACK ON command to perform automatic Before Image Journaling and rollback.


Example

procedure  recovery
  rollback
  if rollback()
      dialog box "Rollback was ok."
  else
    dialog box "Rollback not completed."
  endif
return
 
use setcomm
on error do recovery
begin transaction
    delete first 15
    replace all t1 with (t2*t3)/100
    list
end transaction
if completed()
    dialog box "Transaction completed
else
    dialog box "Errors occurred during transaction"
endif


Products

Recital Server, Recital