Skip to content

Commit

Permalink
ODBC-395 The fix and the testcase
Browse files Browse the repository at this point in the history
There was some old mess with connection object properties for isolation
level, and for setting initial level on connection was used the worng
one, that did not get the value of the attribute. The patch removed that
bogus field and left only one of them.
  • Loading branch information
lawrinn committed Jul 20, 2023
1 parent a7ba72d commit abb23df
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ma_connection.c
Expand Up @@ -816,11 +816,11 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,
}

/* Set isolation level */
if (Connection->IsolationLevel)
if (Connection->TxnIsolation)
{
for (i = 0; i < 4; i++)
{
if (MADB_IsolationLevel[i].SqlIsolation == Connection->IsolationLevel)
if (MADB_IsolationLevel[i].SqlIsolation == Connection->TxnIsolation)
{
_snprintf(StmtStr, sizeof(StmtStr), "SET SESSION TRANSACTION ISOLATION LEVEL %s",
MADB_IsolationLevel[i].StrIsolation);
Expand Down
1 change: 0 additions & 1 deletion ma_odbc.h
Expand Up @@ -380,7 +380,6 @@ struct st_ma_odbc_connection
SQLUINTEGER WriteTimeout;
SQLUINTEGER PacketSize;
SQLINTEGER AccessMode;
SQLINTEGER IsolationLevel; /* tx_isolation */
SQLUINTEGER Trace;
unsigned int LoginTimeout; /* The attribute is SQLUINTEGER, that is unsigned long, that technically can be 8bytes
(not sure how does other DM define it) But C/C option is unsigned int */
Expand Down
4 changes: 2 additions & 2 deletions test/basic.c
Expand Up @@ -1118,11 +1118,11 @@ ODBC_TEST(t_bug31959)

if (ServerNotOlderThan(Connection, 11, 1, 1))
{
CHECK_STMT_RC(Stmt, SQLPrepare(Stmt, (SQLCHAR *)"select @@transaction_isolation", SQL_NTS));
CHECK_STMT_RC(Stmt, SQLPrepare(Stmt, (SQLCHAR *)"SELECT @@transaction_isolation", SQL_NTS));
}
else
{
CHECK_STMT_RC(Stmt, SQLPrepare(Stmt, (SQLCHAR *)"select @@tx_isolation", SQL_NTS));
CHECK_STMT_RC(Stmt, SQLPrepare(Stmt, (SQLCHAR *)"SELECT @@tx_isolation", SQL_NTS));
}

/* check all 4 valid isolation levels */
Expand Down
41 changes: 41 additions & 0 deletions test/tran.c
Expand Up @@ -208,13 +208,54 @@ ODBC_TEST(t_isolation2)
return OK;
}

/* Testing, that setting of isolation level before connection establishing works
* This covers also the case of ODBC-395
*/
ODBC_TEST(t_isolation3)
{
SQLINTEGER isolation= 0;
SQLHANDLE dbc= NULL, Stmt1= NULL;
char buffer[32];

IS(AllocEnvConn(&Env, &dbc));

/* Setting different level(SQL_TXN_READ_COMMITTED) */
CHECK_DBC_RC(dbc, SQLSetConnectAttr(dbc, SQL_ATTR_TXN_ISOLATION,
(SQLPOINTER)SQL_TXN_READ_COMMITTED, 0));
/* We don't need statement, but it's easier to connect this way :), let's neglect, that the error may be in fact stmt allocation error */
Stmt1= DoConnect(dbc, FALSE, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL);
FAIL_IF(Stmt1 == NULL, "Could not connect and/or allocate statement");

/* Checking that after connection we have that isolation level */
CHECK_DBC_RC(dbc, SQLGetConnectAttr(dbc, SQL_ATTR_TXN_ISOLATION, &isolation,
SQL_IS_POINTER, NULL));
is_num(isolation, SQL_TXN_READ_COMMITTED);

if (ServerNotOlderThan(Connection, 11, 1, 1))
{
OK_SIMPLE_STMT(Stmt1, "SELECT @@transaction_isolation");
}
else
{
OK_SIMPLE_STMT(Stmt1, "SELECT @@tx_isolation");
}

CHECK_STMT_RC(Stmt1, SQLFetch(Stmt1));
IS_STR("READ-COMMITTED", my_fetch_str(Stmt1, buffer, 1), sizeof("READ-COMMITTED"));
CHECK_STMT_RC(Stmt1, SQLFreeStmt(Stmt1, SQL_DROP));
CHECK_DBC_RC(dbc, SQLDisconnect(dbc));
CHECK_DBC_RC(dbc, SQLFreeConnect(dbc));

return OK;
}

MA_ODBC_TESTS my_tests[]=
{
{my_transaction,"my_transaction"},
{t_tran, "t_tran"},
{t_isolation, "t_isolation"},
{t_isolation2, "t_isolation2_value_change_tracking"},
{t_isolation3, "t_isolation3_set_before_connect"},
{NULL, NULL}
};

Expand Down

0 comments on commit abb23df

Please sign in to comment.