Navigation Menu

Skip to content

Commit

Permalink
Refined a bit multi-statement query detection - it allows now have
Browse files Browse the repository at this point in the history
semicolon at the end of single statement.
Resetting rs columns number before preparing query.
Changed few testcases in error.c to make outup more informative
  • Loading branch information
lawrinn committed Dec 6, 2016
1 parent 02bef5f commit 0542505
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion ma_helper.c
Expand Up @@ -37,7 +37,9 @@ void CloseMultiStatements(MADB_Stmt *Stmt)
/* Required, but not sufficient condition */
BOOL QueryIsPossiblyMultistmt(char *queryStr)
{
if (strchr(queryStr, ';'))
char *semicolon_pos= strchr(queryStr, ';');
/* String supposed to come here trimmed. Checking that semicolon is not last char in the string */
if (semicolon_pos != NULL && semicolon_pos < queryStr + strlen(queryStr) - 1)
{
/* CREATE PROCEDURE uses semicolons but is not supported in prepared statement
protocol */
Expand Down
3 changes: 2 additions & 1 deletion ma_statement.c
Expand Up @@ -407,6 +407,7 @@ void MADB_StmtReset(MADB_Stmt *Stmt)
case MADB_SS_PREPARED:
ResetMetadata(&Stmt->metadata, NULL);
Stmt->PositionedCursor= NULL;
Stmt->Ird->Header.Count= 0;

case MADB_SS_EMULATED:
MADB_FREE(Stmt->NativeSql);
Expand Down Expand Up @@ -979,7 +980,7 @@ SQLRETURN MADB_StmtExecute(MADB_Stmt *Stmt, BOOL ExecDirect)
mysql_stmt_close(Stmt->stmt);
}
Stmt->stmt= Stmt->MultiStmts[StatementNr];
Stmt->ParamCount= Stmt->MultiStmts[StatementNr]->param_count;
Stmt->ParamCount= (SQLSMALLINT)mysql_stmt_param_count(Stmt->stmt);
Stmt->RebindParams= TRUE;
}
/* Convert and bind parameters */
Expand Down
26 changes: 18 additions & 8 deletions test/error.c
Expand Up @@ -237,9 +237,10 @@ ODBC_TEST(t_bug3456)
CHECK_STMT_RC(Stmt, SQLExecDirect(Stmt, (SQLCHAR *)buf, SQL_NTS));

/* Now check that the connection killed returns the right SQLSTATE */
ERR_SIMPLE_STMT(Stmt2, "SELECT connection_id()");
EXPECT_STMT(Stmt2, SQLExecDirect(Stmt2, "SELECT connection_id()", SQL_NTS), SQL_ERROR);
CHECK_SQLSTATE(Stmt2, "08S01");

return check_sqlstate(Stmt2, "08S01");
return OK;
}


Expand Down Expand Up @@ -315,7 +316,9 @@ ODBC_TEST(bind_notenoughparam1)
CHECK_STMT_RC(Stmt, SQLBindParameter(Stmt, 2, SQL_PARAM_INPUT, SQL_C_LONG,
SQL_INTEGER, 0, 0, &i, 0, NULL));
FAIL_IF(SQLExecute(Stmt)!= SQL_ERROR, "error expected");
return check_sqlstate(Stmt, "07002");
CHECK_SQLSTATE(Stmt, "07002");

return OK;
}


Expand All @@ -337,7 +340,9 @@ ODBC_TEST(bind_notenoughparam2)
CHECK_STMT_RC(Stmt, SQLBindParameter(Stmt, 2, SQL_PARAM_INPUT, SQL_C_LONG,
SQL_INTEGER, 0, 0, &i, 0, NULL));
FAIL_IF(SQLExecute(Stmt)!= SQL_ERROR, "error expected");
return check_sqlstate(Stmt, "07002");
CHECK_SQLSTATE(Stmt, "07002");

return OK;
}


Expand All @@ -356,7 +361,9 @@ ODBC_TEST(getdata_need_nullind)

/* now that it's an error */
FAIL_IF(SQLGetData(Stmt, 2, SQL_C_LONG, &i, 0, NULL) != SQL_ERROR, "Error expected");
return check_sqlstate(Stmt, "22002");
CHECK_SQLSTATE(Stmt, "22002");

return OK;
}


Expand Down Expand Up @@ -424,7 +431,9 @@ ODBC_TEST(sqlerror)
ODBC_TEST(t_bug27158)
{
ERR_SIMPLE_STMT(Stmt, "{ CALL test.does_not_exist }");
return check_sqlstate(Stmt, "42000");
CHECK_SQLSTATE(Stmt, "42000");

return OK;
}


Expand All @@ -437,8 +446,9 @@ ODBC_TEST(t_bug13542600)
CHECK_STMT_RC(Stmt, SQLBindCol(Stmt, 2, SQL_C_LONG, &i, 0, NULL));

FAIL_IF(SQLFetch(Stmt)!= SQL_ERROR, "error expected");
CHECK_SQLSTATE(Stmt, "22002");

return check_sqlstate(Stmt, "22002");
return OK;
}


Expand Down Expand Up @@ -603,7 +613,7 @@ MA_ODBC_TESTS my_tests[]=
{t_odbc2_error, "t_odbc2_error"},
{t_diagrec, "t_diagrec"},
{t_warning, "t_warning"},
{t_bug3456, "t_bug3456"},
{t_bug3456, "t_bug3456_fails_due_to_conc_bug"},
{t_bug16224, "t_bug16224"},
{bind_invalidcol, "bind_invalidcol"},
{bind_notenoughparam1, "bind_notenoughparam1"},
Expand Down
4 changes: 2 additions & 2 deletions test/tap.h
Expand Up @@ -631,11 +631,11 @@ SQLHANDLE DoConnect(SQLHANDLE *Connection,
SQLSMALLINT Length;

/* my_options |= 4; */ /* To enable debug */
_snprintf(DSNString, 1024, "DSN=%s;UID=%s;PWD=%s;PORT=%u;DATABASE=%s;OPTION=%ul;SERVER=%s;%s", dsn ? dsn : (const char*)my_dsn,
_snprintf(DSNString, 1024, "DSN=%s;UID=%s;PWD=%s;PORT=%u;DATABASE=%s;OPTION=%u;SERVER=%s;%s", dsn ? dsn : (const char*)my_dsn,
uid ? uid : (const char*)my_uid, pwd ? pwd : (const char*)my_pwd, port ? port : my_port,
schema ? schema : (const char*)my_schema, options ? *options : my_options, server ? server : (const char*)my_servername,
add_parameters ? add_parameters : "");
diag("DSN=%s;UID=%s;PWD=%s;PORT=%u;DATABASE=%s;OPTION=%ul;SERVER=%s;%s", dsn ? dsn : (const char*)my_dsn,
diag("DSN=%s;UID=%s;PWD=%s;PORT=%u;DATABASE=%s;OPTION=%u;SERVER=%s;%s", dsn ? dsn : (const char*)my_dsn,
uid ? uid : (const char*)my_uid, "********", port ? port : my_port,
schema ? schema : (const char*)my_schema, options ? *options : my_options, server ? server : (const char*)my_servername,
add_parameters ? add_parameters : "");
Expand Down

0 comments on commit 0542505

Please sign in to comment.