7. Understanding ODBC Connectivity : ODBC Programming : Transactions Handling : SQLSetConnectAttr()--Enable Autocommit
 
Share this page                  
SQLSetConnectAttr()--Enable Autocommit
The Ingres DBMS supports standard transaction sessions. Standard transaction sessions begin a transaction when the first query is issued, and end when a commit or rollback command is executed. By contrast, autocommit sessions commit each insert, delete or update query in the DBMS. Standard transaction sessions delete prepared statements and cursor declarations after a commit or rollback; autocommit sessions retain prepared statements and cursor declarations.
The SQLSetConnectAttr() function enables or disables autocommit. The ODBC driver default is to enable autocommit. The following example disables autocommit and manages the transaction manually.
Example: SQLSetConnectAttr() Function
SQLHDBC hdbc;              /* Connection handle */
 
/*
** Turn off autocommit.
*/
SQLSetConnectAttr( hdbc,   /* Connection Handle */
    SQL_ATTR_AUTOCOMMIT,   /* Autocommit attribute */
    SQL_AUTOCOMMIT_OFF,    /* Autocommit disabled */
    0 );                   /* String length (n/a) */
    
The function SQLEndTran() commits or rolls back the transaction:
/*
** Roll back the current transaction.
*/
SQLEndTran(SQL_HANDLE_DBC,   /* Handle type */
    hdbc,                    /* Connection handle */
    SQL_ROLLBACK);           /* Roll back the transaction */