summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
authorkonstantin@mysql.com <>2004-10-14 02:53:59 +0400
committerkonstantin@mysql.com <>2004-10-14 02:53:59 +0400
commit5abc3de22bbef2e9818a890a61f840fb5daaf1b7 (patch)
tree27ce02a5ecb8610d69b81dc15a3d96a62126e80a /sql/sql_prepare.cc
parentcc57252bb76feab94caf3035a2ca083b0734222f (diff)
downloadmariadb-git-5abc3de22bbef2e9818a890a61f840fb5daaf1b7.tar.gz
A fix and test case for Bug#5985 ""prepare stmt from "select rand(?)"
crashes server." The fix makes Item_func_rand prepared-statements aware plus it fixes the case when RAND is used in prepared statements and replication is on (as well as several similar issues). Until now we did not reset THD before every execution of a prepared statement, so if some execution had set thd->time_zone_used or thd->rand_used they would not be reset until next mysql_parse. Some of post-review fixes done.
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index a638e74dc2f..27d98fdfeba 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1760,6 +1760,8 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
DBUG_VOID_RETURN;
}
+ DBUG_ASSERT(thd->free_list == NULL);
+ mysql_reset_thd_for_next_command(thd);
#ifndef EMBEDDED_LIBRARY
if (stmt->param_count)
{
@@ -1778,7 +1780,6 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
if (stmt->param_count && stmt->set_params_data(stmt, &expanded_query))
goto set_params_data_err;
#endif
- DBUG_ASSERT(thd->free_list == NULL);
thd->protocol= &thd->protocol_prep; // Switch to binary protocol
execute_stmt(thd, stmt, &expanded_query, true);
thd->protocol= &thd->protocol_simple; // Use normal protocol
@@ -1823,7 +1824,8 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
}
DBUG_ASSERT(thd->free_list == NULL);
-
+ /* Must go before setting variables, as it clears thd->user_var_events */
+ mysql_reset_thd_for_next_command(thd);
thd->set_n_backup_statement(stmt, &thd->stmt_backup);
if (stmt->set_params_from_vars(stmt,
thd->stmt_backup.lex->prepared_stmt_params,
@@ -1932,6 +1934,7 @@ void mysql_stmt_reset(THD *thd, char *packet)
*/
reset_stmt_params(stmt);
+ mysql_reset_thd_for_next_command(thd);
send_ok(thd);
DBUG_VOID_RETURN;