From 97bfdc2a8922cad77ae88a199729cc7541008d10 Mon Sep 17 00:00:00 2001 From: Danil Onishchenko Date: Fri, 11 Jan 2013 13:31:31 +0800 Subject: Fix aotocommit for Oracle ODBC driver in Linux. Issue: Oracle ODBC driver for Linux ignores setup autocommit mode during driver initialization before a connection to database has been established. Whereas odbc module in erlang sets autocommit mode before a connection has been established and autocommit mode is true by default it is impossible to turn out autocommit mode for oracle connections. Sulution: This patch sets autocommit mode after a connection to database has been established. The patch changes only C source file odbcserver.c and don't change any erlang source files of odbc module. The patches for older versions of erlang/otp are here https://github.com/RubberCthulhu/erlang-odbc-oracle-fix --- lib/odbc/c_src/odbcserver.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lib') diff --git a/lib/odbc/c_src/odbcserver.c b/lib/odbc/c_src/odbcserver.c index 4a7a5224e5..b4ee20c3ee 100644 --- a/lib/odbc/c_src/odbcserver.c +++ b/lib/odbc/c_src/odbcserver.c @@ -431,6 +431,20 @@ static db_result_msg handle_db_request(byte *reqstring, db_state *state) , returns a message indicating the outcome. */ static db_result_msg db_connect(byte *args, db_state *state) { + /* + * Danil Onishchenko aka RubberCthulhu, alevandal@gmail.com. 2013.01.09. + * It's a fix for Oracle ODBC driver for Linux. + * The issue: Oracle ODBC driver for Linux ignores setup autocommit mode + * during driver initialization before a connection to database has been + * established. + * Solution: set autocommit mode after a connection to database has been + * established. + * + * BEGIN + */ + SQLLEN auto_commit_mode; + /* END */ + SQLCHAR connStrOut[MAX_CONN_STR_OUT + 1] = {0}; SQLRETURN result; SQLSMALLINT stringlength2ptr = 0, connlen; @@ -498,6 +512,42 @@ static db_result_msg db_connect(byte *args, db_state *state) return msg; } + /* + * Danil Onishchenko aka RubberCthulhu, alevandal@gmail.com. 2013.01.09. + * It's a fix for Oracle ODBC driver for Linux. + * The issue: Oracle ODBC driver for Linux ignores setup autocommit mode + * during driver initialization before a connection to database has been + * established. + * Solution: set autocommit mode after a connection to database has been + * established. + * + * BEGIN + */ + if(erl_auto_commit_mode == ON) { + auto_commit_mode = SQL_AUTOCOMMIT_ON; + } else { + auto_commit_mode = SQL_AUTOCOMMIT_OFF; + } + + if(!sql_success(SQLSetConnectAttr(connection_handle(state), + SQL_ATTR_AUTOCOMMIT, + (SQLPOINTER)auto_commit_mode, 0))) { + diagnos = get_diagnos(SQL_HANDLE_DBC, connection_handle(state), extended_errors(state)); + strcat((char *)diagnos.error_msg, " Set autocommit mode failed."); + + msg = encode_error_message(diagnos.error_msg, extended_error(state, diagnos.sqlState), diagnos.nativeError); + + if(!sql_success(SQLFreeHandle(SQL_HANDLE_DBC, + connection_handle(state)))) + DO_EXIT(EXIT_FREE); + if(!sql_success(SQLFreeHandle(SQL_HANDLE_ENV, + environment_handle(state)))) + DO_EXIT(EXIT_FREE); + + return msg; + } + /* END */ + msg = retrive_scrollable_cursor_support_info(state); return msg; -- cgit v1.2.3