From 971d65059a63fa4b584ca6851fe3681c1a0e6b13 Mon Sep 17 00:00:00 2001 From: Nick Gorham Date: Mon, 2 Apr 2001 15:18:47 +0000 Subject: Added small change to php_odbc module, to check for failed SQLDisconnects and to close any outstanding transactions if the call fails, then disconnect again. This can cause chaos with SQL Server, this regards a SELECT as starting a transaction, and will leave it open if the result set is not all read. --- ext/odbc/php_odbc.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'ext/odbc/php_odbc.c') diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index ac65d0ee30..cb7a1cfe0e 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -169,17 +169,29 @@ static void _free_odbc_result(zend_rsrc_list_entry *rsrc) } } +/* + * disconnect, and if it fails, then issue a rollback for any pending transaction (lurcher) + */ + +static void safe_odbc_disconnect( void *handle ) +{ + int ret; + + ret = SQLDisconnect( handle ); + if ( ret == SQL_ERROR ) + { + SQLTransact( NULL, handle, SQL_ROLLBACK ); + SQLDisconnect( handle ); + } +} + static void _close_odbc_conn(zend_rsrc_list_entry *rsrc) { odbc_connection *conn = (odbc_connection *)rsrc->ptr; - /* FIXME - * Closing a connection will fail if there are - * pending transactions. It is in the responsibility - * of the user to avoid this. - */ + ODBCLS_FETCH(); - SQLDisconnect(conn->hdbc); + safe_odbc_disconnect(conn->hdbc); SQLFreeConnect(conn->hdbc); SQLFreeEnv(conn->henv); efree(conn); @@ -191,7 +203,7 @@ static void _close_odbc_pconn(zend_rsrc_list_entry *rsrc) odbc_connection *conn = (odbc_connection *)rsrc->ptr; ODBCLS_FETCH(); - SQLDisconnect(conn->hdbc); + safe_odbc_disconnect(conn->hdbc); SQLFreeConnect(conn->hdbc); SQLFreeEnv(conn->henv); free(conn); @@ -2092,7 +2104,7 @@ try_and_get_another_connection: if(ret != SQL_SUCCESS){ zend_hash_del(&EG(persistent_list), hashed_details, hashed_len + 1); - SQLDisconnect(db_conn->hdbc); + safe_odbc_disconnect(db_conn->hdbc); SQLFreeConnect(db_conn->hdbc); goto try_and_get_another_connection; } -- cgit v1.2.1