How Transactions Are Committed
Transactions are composed of one or more OpenSQL statements. In general, a transaction begins with the first statement after connection to the database or the first statement following a commit or rollback. The precise starting point of a transaction depends on the DBMS to which you are connected. Subsequent statements are part of the transaction until a commit or rollback is executed. By default, an explicit commit or rollback must be issued to close a transaction.
To direct the DBMS to commit each database statement individually, use the SET AUTOCOMMIT ON statement. (This statement cannot be issued in an open transaction.) When autocommit is set on, a commit occurs automatically after every statement, except PREPARE and DESCRIBE.
If autocommit is on and a cursor is opened, the server or Enterprise Access product does not issue a commit until the CLOSE CURSOR statement is executed, because cursors are logically a single statement. A ROLLBACK statement can be issued when a cursor is open. To restore the default behavior (and enable multiquery transactions), issue the SET AUTOCOMMIT OFF statement.
To determine whether you are in a transaction, use the INQUIRE_SQL statement. For information about INQUIRE_SQL, see
Status Information and Inquire_sql in the “OpenSQL Statements” chapter. To find out if autocommit is on or off, use dbmsinfo. For information about dbmsinfo, see
The Dbmsinfo Function—Retrieve Information on Current Session.
Last modified date: 08/28/2024