List:Commits« Previous MessageNext Message »
From:jwinstead Date:April 12 2007 6:17pm
Subject:Connector/ODBC 3.51 commit: r319 - in trunk: . driver test
View as plain text  
Modified:
   trunk/ChangeLog
   trunk/driver/connect.c
   trunk/driver/myodbc3.h
   trunk/driver/options.c
   trunk/test/my_tran.c
Log:
SQLGetConnectAttr() would report an incorrect isolation level if it
was not explicitly set using SQLSetConnectAttr(). (Bug #27589)


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-04-12 10:11:32 UTC (rev 318)
+++ trunk/ChangeLog	2007-04-12 16:17:01 UTC (rev 319)
@@ -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)
   * The last argument of SQLColAttribute() and SQLColAttributes() was
     always being treated as a pointer to an SQLINTEGER even though it is
     sometimes a pointer to an SQLLEN.

Modified: trunk/driver/connect.c
===================================================================
--- trunk/driver/connect.c	2007-04-12 10:11:32 UTC (rev 318)
+++ trunk/driver/connect.c	2007-04-12 16:17:01 UTC (rev 319)
@@ -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;

Modified: trunk/driver/myodbc3.h
===================================================================
--- trunk/driver/myodbc3.h	2007-04-12 10:11:32 UTC (rev 318)
+++ trunk/driver/myodbc3.h	2007-04-12 16:17:01 UTC (rev 319)
@@ -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*/

Modified: trunk/driver/options.c
===================================================================
--- trunk/driver/options.c	2007-04-12 10:11:32 UTC (rev 318)
+++ trunk/driver/options.c	2007-04-12 16:17:01 UTC (rev 319)
@@ -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)
     {

Modified: trunk/test/my_tran.c
===================================================================
--- trunk/test/my_tran.c	2007-04-12 10:11:32 UTC (rev 318)
+++ trunk/test/my_tran.c	2007-04-12 16:17:01 UTC (rev 319)
@@ -144,9 +144,43 @@
 }
 
 
+/**
+  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_tran)
+  ADD_TEST(t_isolation)
 END_TESTS
 
 

Thread
Connector/ODBC 3.51 commit: r319 - in trunk: . driver testjwinstead12 Apr