Closing Transactions
Go Up to Application Requirements
Every transaction should be closed when it completes its tasks, or when an error occurs that prevents it from completing its tasks. Failure to close a transaction before a program ends can cause limbo transactions, where records are entered into the database, but are neither committed or rolled back. Limbo transactions can be cleaned up using the database administration tools provided with InterBase.
Accepting Changes
The COMMIT
statement ends a transaction, makes the transaction’s changes available to other users, and closes cursors. A COMMIT
is used to preserve changes when all of a transaction’s operations are successful. To end a transaction with COMMIT
, use the following syntax:
EXEC SQL COMMIT TRANSACTION name;
For example, the following statement commits a transaction named MYTRANS
:
EXEC SQL COMMIT TRANSACTION MYTRANS;
For a complete discussion of SQL transaction control, see Working with Transactions.
Undoing Changes
The ROLLBACK
statement undoes a transaction’s changes, ends the current transaction, and closes open cursors. Use ROLLBACK
when an error occurs that prevents all of a transaction’s operations from being successful. To end a transaction with ROLLBACK
, use the following syntax:
EXEC SQL ROLLBACK TRANSACTION name;
For example, the following statement rolls back a transaction named MYTRANS
:
EXEC SQL ROLLBACK TRANSACTION MYTRANS;
To roll back an unnamed transaction (i.e., the default transaction), use the following statement:
EXEC SQL ROLLBACK;
For a complete discussion of SQL transaction control, see Working with Transactions.