From: Wez Furlong Date: Sat, 11 Jun 2005 12:38:12 +0000 (+0000) Subject: Fix for PECL #3714: beginTransaction doesn't work if you're in auto-commit mode. X-Git-Tag: php-5.1.0b2~238 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=183c8aa287243d878bdd4b3dd8440ed50c75bb80;p=php Fix for PECL #3714: beginTransaction doesn't work if you're in auto-commit mode. --- diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index aa543360c8..9ab9cea6c7 100755 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -218,7 +218,17 @@ static int odbc_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquoted static int odbc_handle_begin(pdo_dbh_t *dbh TSRMLS_DC) { - /* with ODBC, there is nothing special to be done */ + if (dbh->auto_commit) { + /* we need to disable auto-commit now, to be able to initiate a transaction */ + RETCODE rc; + pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; + + rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_NTS); + if (rc != SQL_SUCCESS) { + pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = OFF"); + return 0; + } + } return 1; } @@ -236,6 +246,16 @@ static int odbc_handle_commit(pdo_dbh_t *dbh TSRMLS_DC) return 0; } } + + if (dbh->auto_commit) { + /* turn auto-commit back on again */ + RETCODE rc; + rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS); + if (rc != SQL_SUCCESS) { + pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = OFF"); + return 0; + } + } return 1; } @@ -253,6 +273,16 @@ static int odbc_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC) return 0; } } + if (dbh->auto_commit && H->dbc && dbh->in_txn) { + /* turn auto-commit back on again */ + RETCODE rc; + rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS); + if (rc != SQL_SUCCESS) { + pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = OFF"); + return 0; + } + } + return 1; } @@ -328,7 +358,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_D } if (!dbh->auto_commit) { - rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER); + rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_NTS); if (rc != SQL_SUCCESS) { pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = OFF"); odbc_handle_closer(dbh TSRMLS_CC);