ROLLBACK statement
Syntax
ROLLBACK [ WORK ] [ THEN statements ] [ ELSE statements ]
Description
Use the ROLLBACK statement to cancel all file I/O changes made during a transaction. The WORK keyword provides compatibility with SQL syntax conventions; it is ignored by the compiler.
A transaction includes all statements executed since the most recent BEGIN TRANSACTION statement. The ROLLBACK statement rolls back all changes made to files during the active transaction. If a subordinate transaction rolls back, none of the changes resulting from the active subordinate transaction affect the parent transaction. If the top-level transaction rolls back, none of the changes made are committed to disk, and the database remains unaffected by the transaction.
Use the ROLLBACK statement in a transaction without a COMMIT statement to review the results of a possible change. Doing so does not affect the parent transaction or the database. Executing a ROLLBACK statement ends the current transaction. After the transaction ends, execution continues with the statement following the next END TRANSACTION statement.
If no transaction is active, the ROLLBACK statement generates a run-time warning, and the ELSE statements are executed.
Example
This example begins a transaction that applies locks to rec1 and rec2. If errors occur (such as a failed or a failed WRITE statements), the ROLLBACK statements ensure that no changes are written to the file.
BEGIN TRANSACTION
READU data1 FROM file1,rec1 ELSE ROLLBACK
READU data2 FROM file2,rec2 ELSE ROLLBACK
.
.
.
WRITE new.data1 ON file1,rec1 ELSE ROLLBACK
WRITE new.data2 ON file2,rec2 ELSE ROLLBACK
COMMIT WORK
END TRANSACTION
The update record lock on rec1 is not released on successful completion of the first WRITE statement.