COMMIT statement

Syntax

COMMIT [ WORK ] [ THEN statements  ] [ ELSE statements ]

Description

Use the COMMIT statement to commit all file I/O changes made during a transaction. The WORK keyword is provided for compatibility with SQL syntax conventions; it is ignored by the compiler.

A transaction includes all statements between a BEGIN TRANSACTION statement and the COMMIT or ROLLBACK statement that ends the transaction. Either a COMMIT or a ROLLBACK statement ends the current transaction.

The COMMIT statement can either succeed or fail.

When a subordinate transaction commits, it makes the results of its database operations accessible to its parent transaction. The subordinate transaction commits to the database only if all of its predecessors up to the top-level transaction are committed.

If a top-level transaction succeeds, all changes to files made during the active transaction are committed to disk.

If a subordinate transaction fails, all its changes are rolled back and do not affect the parent transaction. If the top-level transaction fails, none of the changes made during the active transaction are committed, and the database remains unaffected by the failed transaction. This ensures that the database is maintained in a consistent state.

If the COMMIT statement succeeds, the THEN statements are executed; any ELSE statements are ignored. If COMMIT fails, any ELSE statements are executed. After the THEN or the ELSE statements are executed, control is transferred to the statement following the next END TRANSACTION statement.

All Locks obtained during a transaction remain in effect for the duration of the active transaction; they are not released by a RELEASE statement, WRITE statements, , or MATWRITE statements statement that is part of the transaction. The parent transaction adopts the acquired or promoted locks. If a subordinate transaction rolls back, any locks that have been acquired or promoted within that transaction are demoted or released.

The COMMIT statement that ends the top-level transaction releases locks set during that transaction. Locks obtained outside the transaction are not affected by the COMMIT statement.

If no transaction is active, the COMMIT 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 no errors occur, the COMMIT statement ensures that the changes to rec1 and rec2 are written to the file. The locks on rec1 and rec2 are released, and control is transferred to the statement following the END TRANSACTION statement.

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 completion of the first WRITE statements statement but on completion of the COMMIT statement.