Index: driver/myodbc3.h =================================================================== --- driver/myodbc3.h (revision 264) +++ driver/myodbc3.h (working copy) @@ -158,8 +158,9 @@ #define FLAG_AUTO_RECONNECT (FLAG_SAFE << 5) #define FLAG_AUTO_IS_NULL (FLAG_SAFE << 6) /* 8388608 Enables SQL_AUTO_IS_NULL */ +/* We don't make any assumption about what the default may be. */ #ifndef DEFAULT_TXN_ISOLATION -#define DEFAULT_TXN_ISOLATION SQL_TXN_READ_COMMITTED +# define DEFAULT_TXN_ISOLATION 0 #endif /* Connection flags to validate after the connection*/ Index: driver/connect.c =================================================================== --- driver/connect.c (revision 264) +++ driver/connect.c (working copy) @@ -98,7 +98,7 @@ MYODBCDbgReturnReturn( SQL_ERROR ); } - if (!(dbc->txn_isolation & DEFAULT_TXN_ISOLATION))/* TXN_ISOLATION */ + if (dbc->txn_isolation != DEFAULT_TXN_ISOLATION)/* TXN_ISOLATION */ { char buff[80]; const char *level; Index: driver/options.c =================================================================== --- driver/options.c (revision 264) +++ driver/options.c (working copy) @@ -451,7 +451,7 @@ { DBC FAR *dbc= (DBC FAR*) hdbc; SQLRETURN result= SQL_SUCCESS; - SQLINTEGER strlen; + SQLINTEGER len; SQLPOINTER vparam= 0; MYODBCDbgEnter; @@ -465,7 +465,7 @@ ValuePtr= vparam; if (!StringLengthPtr) - StringLengthPtr= &strlen; + StringLengthPtr= &len; switch (Attribute) { @@ -544,6 +544,54 @@ break; case SQL_ATTR_TXN_ISOLATION: + /* + If we don't know the isolation level already, we need + to ask the server. + */ + if (!dbc->txn_isolation) + { + /* + Unless we're not connected yet, then we just assume it will + be REPEATABLE READ, which is the server default. + */ + if (!dbc->server) + { + *((SQLINTEGER *) ValuePtr)= SQL_TRANSACTION_REPEATABLE_READ; + break; + } + + if (odbc_stmt(dbc, "SELECT @@tx_isolation")) + { + MYODBCDbgReturnReturn(set_handle_error(SQL_HANDLE_DBC,hdbc, + MYERR_S1000, + "Failed to get " + "isolation level", 0)); + } + else + { + MYSQL_RES *res; + MYSQL_ROW row; + + if ((res= mysql_store_result(&dbc->mysql)) && + (row= mysql_fetch_row(res))) + { + if (strncmp(row[0], "READ-UNCOMMITTED", 16) == 0) { + dbc->txn_isolation= SQL_TRANSACTION_READ_UNCOMMITTED; + } + else if (strncmp(row[0], "READ-COMMITTED", 14) == 0) { + dbc->txn_isolation= SQL_TRANSACTION_READ_COMMITTED; + } + else if (strncmp(row[0], "REPEATABLE-READ", 15) == 0) { + dbc->txn_isolation= SQL_TRANSACTION_REPEATABLE_READ; + } + else if (strncmp(row[0], "SERIALIZABLE", 12) == 0) { + dbc->txn_isolation= SQL_TRANSACTION_SERIALIZABLE; + } + } + mysql_free_result(res); + } + } + *((SQLINTEGER *) ValuePtr)= dbc->txn_isolation; break; @@ -670,7 +718,7 @@ STMT FAR *stmt= (STMT FAR*) hstmt; STMT_OPTIONS *options= &stmt->stmt_options; SQLPOINTER vparam; - SQLINTEGER strlen; + SQLINTEGER len; MYODBCDbgEnter; MYODBCDbgInfo( "Atrr: %d", Attribute ); @@ -682,7 +730,7 @@ ValuePtr= &vparam; if (!StringLengthPtr) - StringLengthPtr= &strlen; + StringLengthPtr= &len; switch (Attribute) { Index: test/tran/my_tran.c =================================================================== --- test/tran/my_tran.c (revision 264) +++ test/tran/my_tran.c (working copy) @@ -111,9 +111,41 @@ return OK; } +/** + Test retrieval and setting of transaction isolation level. +*/ +DECLARE_TEST(t_isolation) +{ + SQLINTEGER isolation; + SQLCHAR tx_isolation[20]; + /* Check that the default is REPEATABLE READ. */ + ok_con(hdbc, SQLGetConnectAttr(hdbc, SQL_ATTR_TXN_ISOLATION, &isolation, + SQL_IS_POINTER, NULL)); + is_num(isolation, SQL_TXN_REPEATABLE_READ); + + /* Change it to READ UNCOMMITTED. */ + ok_con(hdbc, SQLSetConnectAttr(hdbc, SQL_ATTR_TXN_ISOLATION, + (SQLPOINTER)SQL_TXN_READ_UNCOMMITTED, 0)); + + /* Check that the driver has rmeembered the new value. */ + ok_con(hdbc, SQLGetConnectAttr(hdbc, SQL_ATTR_TXN_ISOLATION, &isolation, + SQL_IS_POINTER, NULL)); + is_num(isolation, SQL_TXN_READ_UNCOMMITTED); + + /* Check that it was actually changed on the server. */ + ok_sql(hstmt, "SELECT @@tx_isolation"); + ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_CHAR, tx_isolation, + sizeof(tx_isolation), NULL)); + ok_stmt(hstmt, SQLFetch(hstmt)); + is_str(tx_isolation, "READ-UNCOMMITTED", 16); + + return OK; +} + BEGIN_TESTS ADD_TEST(my_transaction) + ADD_TEST(t_isolation) END_TESTS Index: ChangeLog =================================================================== --- ChangeLog (revision 264) +++ ChangeLog (working copy) @@ -3,6 +3,8 @@ Functionality added or changed: Bugs fixed: + * SQLGetConnectAttr() would report an incorrect isolation level if it + was not explicitly set using SQLSetConnectAttr(). (Bug #27589) * SQLProcedures returned incomplete and incorrect information. (Bug #23033) * Statements that used "WHERE CURRENT OF" for positioned updates could not be re-executed or used with parameters that were provided using