From 923af04fc1598cdbbe006b2995dfba5fd5de2ff8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 23 Dec 2003 15:38:19 +0300 Subject: [PATCH 1/3] short patch for bug #2184 'Prepared statements in embedded library was broken with recent changes' (attempt 2). Adding Statement_core is better because: - set_statement() code is shorter and you don't need to modify it when adding new members to Statement_core - a bit faster (you don't have virtual call and don't free_root() twice) Do that short patch instead in hope that set_statement() will be sooner or later removed entirely sql/sql_class.cc: short patch for bug #2184 'Prepared statements in embedded library was broken with recent changes' sql/sql_class.h: short patch for bug #2184 'Prepared statements in embedded library was broken with recent changes' --- sql/sql_class.cc | 2 ++ sql/sql_class.h | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 12f0cc4ca72..60220ffc889 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -336,6 +336,8 @@ THD::~THD() #ifndef DBUG_OFF dbug_sentry = THD_SENTRY_GONE; #endif + /* Reset stmt_backup.mem_root to not double-free memory from thd.mem_root */ + init_alloc_root(&stmt_backup.mem_root, 0, 0); DBUG_VOID_RETURN; } diff --git a/sql/sql_class.h b/sql/sql_class.h index c1cd65edf76..5390e8a4ac4 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -582,8 +582,7 @@ public: Statement_map stmt_map; /* keeps THD state while it is used for active statement - Note, that double free_root() is safe, so we don't need to do any - special cleanup for it in THD destructor. + Note: we perform special cleanup for it in THD destructor. */ Statement stmt_backup; /* From 7136e3866ca001f636e9288c51c61f8759f1eab5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 23 Dec 2003 17:17:45 +0400 Subject: [PATCH 2/3] Fix for #2184 (Prepared statements if embedded library broken) There was an error with same function/class member names sql/sql_prepare.cc: Name scope specified --- sql/sql_prepare.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index a513e445db9..5d6ab165641 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1193,7 +1193,7 @@ Prepared_statement::Prepared_statement(THD *thd_arg) #ifndef EMBEDDED_LIBRARY setup_params= insert_params; // not fully qualified query #else - setup_params_data= setup_params_data; + setup_params_data= ::setup_params_data; #endif } From 02531752eb4930c0568996a00d16483325f81206 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 23 Dec 2003 18:24:33 +0400 Subject: [PATCH 3/3] Fix for #2181 (mysql_execute crashed instead of returning error on embedded server) We didn't perform the check for the error for embedded server libmysql/libmysql.c: error checking moved to the mysql_execute level --- libmysql/libmysql.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 728454a50fb..9d084879fc8 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2035,14 +2035,6 @@ int cli_stmt_execute(MYSQL_STMT *stmt) uint null_count; my_bool result; -#ifdef CHECK_EXTRA_ARGUMENTS - if (!stmt->param_buffers) - { - /* Parameters exists, but no bound buffers */ - set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND, unknown_sqlstate); - DBUG_RETURN(1); - } -#endif net_clear(net); /* Sets net->write_pos */ /* Reserve place for null-marker bytes */ null_count= (stmt->param_count+7) /8; @@ -2099,6 +2091,14 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate); DBUG_RETURN(1); } +#ifdef CHECK_EXTRA_ARGUMENTS + if (stmt->param_count && !stmt->param_buffers) + { + /* Parameters exists, but no bound buffers */ + set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND, unknown_sqlstate); + DBUG_RETURN(1); + } +#endif if ((*stmt->mysql->methods->stmt_execute)(stmt)) DBUG_RETURN(1);