Commit aef0b9a7 authored by unknown's avatar unknown

fix for bug #1946:

"You can always mysql_real_query a query with placeholders 
after mysql_prepare()"


sql/sql_class.cc:
  prepare_command removed
sql/sql_class.h:
  prepare_command removed
sql/sql_prepare.cc:
  prepare_command removed
sql/sql_yacc.yy:
  prepare_command removed
tests/client_test.c:
  added test for bug #1946: "You can always
  mysql_real_query a query with placeholders after mysql_prepare()"
parent 7d6479cc
...@@ -90,8 +90,8 @@ THD::THD():user_time(0), is_fatal_error(0), ...@@ -90,8 +90,8 @@ THD::THD():user_time(0), is_fatal_error(0),
{ {
host=user=priv_user=db=query=ip=0; host=user=priv_user=db=query=ip=0;
host_or_ip= "connecting host"; host_or_ip= "connecting host";
locked=killed=some_tables_deleted=no_errors=password= locked=killed=some_tables_deleted=no_errors=password= 0;
query_start_used=prepare_command=0; query_start_used= 0;
count_cuted_fields= CHECK_FIELD_IGNORE; count_cuted_fields= CHECK_FIELD_IGNORE;
db_length=query_length=col_access=0; db_length=query_length=col_access=0;
query_error= tmp_table_used= 0; query_error= tmp_table_used= 0;
......
...@@ -606,7 +606,6 @@ class THD :public ilink ...@@ -606,7 +606,6 @@ class THD :public ilink
bool system_thread,in_lock_tables,global_read_lock; bool system_thread,in_lock_tables,global_read_lock;
bool query_error, bootstrap, cleanup_done; bool query_error, bootstrap, cleanup_done;
bool volatile killed; bool volatile killed;
bool prepare_command;
bool tmp_table_used; bool tmp_table_used;
bool charset_is_system_charset, charset_is_collation_connection; bool charset_is_system_charset, charset_is_collation_connection;
bool slow_command; bool slow_command;
......
...@@ -785,7 +785,6 @@ static bool parse_prepare_query(PREP_STMT *stmt, ...@@ -785,7 +785,6 @@ static bool parse_prepare_query(PREP_STMT *stmt,
mysql_init_query(thd); mysql_init_query(thd);
LEX *lex=lex_start(thd, (uchar*) packet, length); LEX *lex=lex_start(thd, (uchar*) packet, length);
lex->safe_to_cache_query= 0; lex->safe_to_cache_query= 0;
thd->prepare_command= TRUE;
thd->lex.param_count= 0; thd->lex.param_count= 0;
if (!yyparse((void *)thd) && !thd->is_fatal_error) if (!yyparse((void *)thd) && !thd->is_fatal_error)
error= send_prepare_results(stmt); error= send_prepare_results(stmt);
......
...@@ -4355,7 +4355,7 @@ param_marker: ...@@ -4355,7 +4355,7 @@ param_marker:
'?' '?'
{ {
LEX *lex=Lex; LEX *lex=Lex;
if (YYTHD->prepare_command) if (YYTHD->command == COM_PREPARE)
{ {
lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query))); lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query)));
lex->param_count++; lex->param_count++;
......
...@@ -8065,6 +8065,32 @@ static void test_bug1500() ...@@ -8065,6 +8065,32 @@ static void test_bug1500()
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
} }
static void test_bug1946()
{
MYSQL_STMT *stmt;
int rc;
myheader("test_bug1946");
const char *query= "INSERT INTO prepare_command VALUES (?)";
rc = mysql_query(mysql, "DROP TABLE IF EXISTS prepare_command");
myquery(rc);
rc= mysql_query(mysql,"CREATE TABLE prepare_command(ID INT)");
myquery(rc);
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
rc= mysql_real_query(mysql, query, strlen(query));
assert(rc != 0);
fprintf(stdout, "Got error (as expected):\n");
myerror(NULL);
mysql_stmt_close(stmt);
rc= mysql_query(mysql,"DROP TABLE prepare_command");
}
/* /*
Read and parse arguments and MySQL options from my.cnf Read and parse arguments and MySQL options from my.cnf
*/ */
...@@ -8208,6 +8234,8 @@ int main(int argc, char **argv) ...@@ -8208,6 +8234,8 @@ int main(int argc, char **argv)
/* Used for internal new development debugging */ /* Used for internal new development debugging */
test_drop_temp(); /* to test DROP TEMPORARY TABLE Access checks */ test_drop_temp(); /* to test DROP TEMPORARY TABLE Access checks */
#endif #endif
test_bug1946(); /* test that placeholders are allowed only in
prepared queries */
test_fetch_seek(); /* to test stmt seek() functions */ test_fetch_seek(); /* to test stmt seek() functions */
test_fetch_nobuffs(); /* to fecth without prior bound buffers */ test_fetch_nobuffs(); /* to fecth without prior bound buffers */
test_open_direct(); /* direct execution in the middle of open stmts */ test_open_direct(); /* direct execution in the middle of open stmts */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment