From aef0b9a7c77ea1ca3feafa486575bf564b1d4ce7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Nov 2003 17:41:12 +0300 Subject: [PATCH] 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()" --- sql/sql_class.cc | 4 ++-- sql/sql_class.h | 1 - sql/sql_prepare.cc | 1 - sql/sql_yacc.yy | 2 +- tests/client_test.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 4fcd6504a2f..1041c21ef30 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -90,8 +90,8 @@ THD::THD():user_time(0), is_fatal_error(0), { host=user=priv_user=db=query=ip=0; host_or_ip= "connecting host"; - locked=killed=some_tables_deleted=no_errors=password= - query_start_used=prepare_command=0; + locked=killed=some_tables_deleted=no_errors=password= 0; + query_start_used= 0; count_cuted_fields= CHECK_FIELD_IGNORE; db_length=query_length=col_access=0; query_error= tmp_table_used= 0; diff --git a/sql/sql_class.h b/sql/sql_class.h index 36faeae8f57..6be517d42d0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -606,7 +606,6 @@ public: bool system_thread,in_lock_tables,global_read_lock; bool query_error, bootstrap, cleanup_done; bool volatile killed; - bool prepare_command; bool tmp_table_used; bool charset_is_system_charset, charset_is_collation_connection; bool slow_command; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 69517b171cb..e76ff833e20 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -785,7 +785,6 @@ static bool parse_prepare_query(PREP_STMT *stmt, mysql_init_query(thd); LEX *lex=lex_start(thd, (uchar*) packet, length); lex->safe_to_cache_query= 0; - thd->prepare_command= TRUE; thd->lex.param_count= 0; if (!yyparse((void *)thd) && !thd->is_fatal_error) error= send_prepare_results(stmt); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 0dbe14fd2ab..b944dc3955c 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4355,7 +4355,7 @@ param_marker: '?' { 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_count++; diff --git a/tests/client_test.c b/tests/client_test.c index 637f6c4ede1..d2d77c9965c 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -8065,6 +8065,32 @@ static void test_bug1500() 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 */ @@ -8208,6 +8234,8 @@ int main(int argc, char **argv) /* Used for internal new development debugging */ test_drop_temp(); /* to test DROP TEMPORARY TABLE Access checks */ #endif + test_bug1946(); /* test that placeholders are allowed only in + prepared queries */ test_fetch_seek(); /* to test stmt seek() functions */ test_fetch_nobuffs(); /* to fecth without prior bound buffers */ test_open_direct(); /* direct execution in the middle of open stmts */