Commits all changes made during the current transaction.
COMMIT [TRANSACTION | WORK] [THEN statements] [ELSE statements]
statement ends the current transaction initiated by a BEGIN TRANSACTION
statement. All file changes issued during the transaction are committed, and cannot be subsequently reverted.
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 commit is successful, the THEN clause is executed. If the transaction commit 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 revert the changes made during the current transaction, issue a ROLLBACK
statement, rather than a COMMIT
After the transaction is closed, program execution continues at the END TRANSACTION
Caché MVBasic supports two sets of transaction statements:
These two sets of transaction statements should not be combined.
Please refer to the documentation for BEGIN TRANSACTION
for notes on important differences regarding the isolation level of transactions within Caché vs the that generally found in MV systems.
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
operation. Locks are described in the LOCK
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"
THEN PRINT "Commit successful"
ELSE PRINT "Commit failed"
PRINT "This should not print"
PRINT "Transaction resolved"