Skip to main content

ROLLBACK

Reverts all changes made during the current transaction.

Synopsis

ROLLBACK [TRANSACTION | WORK] [THEN statements] [ELSE statements]

Description

The ROLLBACK statement reverts all changes made during the current transaction initiated by a BEGIN TRANSACTION statement. All file changes issued during the transaction are undone, returning the data to the state prior to the BEGIN TRANSACTION.

The ROLLBACK must be specified between the BEGIN TRANSACTION and END TRANSACTION statements. Following a ROLLBACK, program execution skips to the line of code following the END TRANSACTION statement.

The TRANSACTION or WORK keywords are optional and provides no functionality. They are provided solely for compatibility with other MultiValue vendor products.

You can optionally specify a THEN clause, an ELSE clause, or both a THEN and an ELSE clause. If the transaction rollback is successful, the THEN clause is executed. If the transaction rollback fails, the ELSE clause is executed. The statements argument can be the NULL keyword, a single statement, or a block of statements terminated by the END keyword. A block of statements has specific line break requirements: each statement must be on its own line and cannot follow a THEN, ELSE, or END keyword on that line.

To commit the changes made during the current transaction, issue a COMMIT statement, rather than a ROLLBACK statement.

After the transaction is closed, program execution continues at the END TRANSACTION statement.

Note:

Caché MVBasic supports two sets of transaction statements:

  • UniVerse-style BEGIN TRANSACTION, COMMIT, ROLLBACK, and END TRANSACTION.

  • UniData-style TRANSACTION START, TRANSACTION COMMIT, and TRANSACTION ABORT.

These two sets of transaction statements should not be combined.

Locks and Transactions

File locks and record locks that were taken out during a transaction are released at the end of a transaction. If there are nested transactions, the release of locks taken out during the inner transactions is delayed until the completion of the outermost transaction. This release of locks is part of a successful COMMIT or ROLLBACK operation. Locks are described in the LOCK statement.

Unaffected by ROLLBACK

  • The contents of spooler and form queues, and any print jobs queued or in progress.

  • The contents of the &PH& file and any spawned PHANTOM (background) processes.

  • The contents of the &COMO& file used to keep an audit trail of terminal inputs.

Example

The following example performs database operations within a transaction. It sets a variable x, which determines whether the transaction should be committed or rolled back.

PRINT "Before the transaction"
BEGIN TRANSACTION
 .
 .
 .
IF x=0 
  THEN COMMIT
  END
  ELSE ROLLBACK
    THEN PRINT "Rollback successful"
    ELSE PRINT "Rollback failed"
  END
PRINT "This should not print"
END TRANSACTION
PRINT "Transaction resolved"

See Also

FeedbackOpens in a new tab