Commit or Rollback Transactions


Transaction control is handled on the os_db_connection class. All statement objects attached to a connection object are controlled by that connection object's transaction commit mode.

Automatic Transaction Control

By default os_db_connection objects are created in automatic commit mode. This means transaction are implicitly initiated and are automatically committed as they are completed.

Manual Transaction Control

In manual commit mode transactions are initiated implicitly but must be committed or rolled back explicitly. To gain manual control of transactions specify txn_manual in the set_commit_mode() method of the connection object.

For connection objects set to manual commit mode appropriate calls to commit() or rollback() must be made by the client. Note that the commit or rollback affects all uncommitted statements attached to connection object.

The excerpt below illustrates an os_db_connection object being set for manual commit mode.

Excerpt from <ospace/database/examples/connect1.cpp>
  // ...

  os_db_connection connection2( os_socket_address(iaddr, 3006),
                                  connect_info );

  //
  // Take manual control of transactions.
  // We will call commit() or rollback() as needed for this connection.
  //
  connection2.set_commit_mode( os_db_connection::txn_manual );

  // ...



Copyright©2005-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.