Skip to content

Commit

Permalink
ODBC-378 The fix and the testcase
Browse files Browse the repository at this point in the history
The driver didn't recognize OPTIMIZE as a query returning a resultset
  • Loading branch information
lawrinn committed Mar 7, 2023
1 parent 5379a12 commit 854ecfe
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ma_parse.c
Expand Up @@ -342,6 +342,12 @@ enum enum_madb_query_type MADB_GetQueryType(const char *Token1, const char *Toke
{
return MADB_NOT_ATOMIC_BLOCK;
}
if (_strnicmp(Token1, "OPTIMIZE", 8) == 0
/*&& (_strnicmp(Token2, "LOCAL", 5) || _strnicmp(Token2, "NO_WRITE_TO_BINLOG ", 5) || _strnicmp(Token2, "TABLE", 5)) == 0*/)
{
return MADB_QUERY_OPTIMIZE;
}

return MADB_QUERY_NO_RESULT;
}

Expand Down
3 changes: 2 additions & 1 deletion ma_parse.h
Expand Up @@ -39,7 +39,8 @@ enum enum_madb_query_type { MADB_QUERY_NO_RESULT= 0, /* Default type for the que
MADB_QUERY_CHECK,
MADB_QUERY_EXECUTE,
MADB_QUERY_DESCRIBE,
MADB_NOT_ATOMIC_BLOCK
MADB_NOT_ATOMIC_BLOCK,
MADB_QUERY_OPTIMIZE
};

typedef struct {
Expand Down
48 changes: 47 additions & 1 deletion test/prepare.c
Expand Up @@ -1222,9 +1222,9 @@ ODBC_TEST(t_odbc141)
skip("Test user doesn't have enough privileges to run this test");
}
FAIL_IF(NativeError!=29 && NativeError != 13, "Expected 13 or 29 native error"); /* File not found or No such file or directory... */

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

OK_SIMPLE_STMT(Stmt, "DROP TABLE odbc141");
return OK;
}

Expand Down Expand Up @@ -1287,6 +1287,51 @@ ODBC_TEST(t_mdev16708)
}


ODBC_TEST(t_odbc378)
{
OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS t_odbc378");
OK_SIMPLE_STMT(Stmt, "CREATE TABLE t_odbc378(id int not null)");
OK_SIMPLE_STMT(Stmt, "INSERT INTO t_odbc378 VALUES(1)");

OK_SIMPLE_STMT(Stmt, "OPTIMIZE TABLE t_odbc378");
IS(my_print_non_format_result_ex(Stmt, FALSE) == 2);
EXPECT_STMT(Stmt, SQLMoreResults(Stmt), SQL_NO_DATA_FOUND);
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

/* Making sure protocol is not broken */
OK_SIMPLE_STMT(Stmt, "SELECT * FROM t_odbc378");
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

CHECK_STMT_RC(Stmt, SQLPrepare(Stmt, "OPTIMIZE LOCAL TABLE t_odbc378", SQL_NTS));
CHECK_STMT_RC(Stmt, SQLExecute(Stmt));
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA_FOUND);
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

/* Making sure protocol is not broken */
OK_SIMPLE_STMT(Stmt, "SELECT * FROM t_odbc378");
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

OK_SIMPLE_STMT(Stmt, "OPTIMIZE NO_WRITE_TO_BINLOG TABLE t_odbc378");
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA_FOUND);
EXPECT_STMT(Stmt, SQLMoreResults(Stmt), SQL_NO_DATA_FOUND);
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

/* Making sure protocol is not broken */
OK_SIMPLE_STMT(Stmt, "SELECT * FROM t_odbc378");
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

OK_SIMPLE_STMT(Stmt, "DROP TABLE t_odbc378");
return OK;
}


MA_ODBC_TESTS my_tests[]=
{
{t_prep_basic, "t_prep_basic"},
Expand All @@ -1309,6 +1354,7 @@ MA_ODBC_TESTS my_tests[]=
{t_odbc141, "odbc-141-load_data_infile"},
{t_odbc269, "odbc-269-begin_not_atomic"},
{t_mdev16708, "t_mdev16708-new_supported_statements"},
{t_odbc378, "t_odbc378-optimize_table"},
{NULL, NULL}
};

Expand Down

0 comments on commit 854ecfe

Please sign in to comment.