Commit 01df29fd authored by unknown's avatar unknown

A fix and test case for Bug#6102 "Server crash with prepared statement

and blank after function name".
Crop fruits of copy-paste programming: pre-caching of stored functions
wasn't performed for prepared statements just because implementation
of prepared statements is done as an add-on to the main execution flow, 
and the preload was originally implemented for main execution branch
only (mysql_execute_command).


mysql-test/r/ps.result:
  Test results fixed: bug#6102
mysql-test/t/ps.test:
  A test case for Bug#6102 "Server crash with prepared statement
   and blank after functionname"
sql/sql_prepare.cc:
  A fix for Bug#6102 "Server crash with prepared statement and blank 
  after functionname": we need to preload stored functions from system tables
   before we open any other tables.
parent f833dc81
......@@ -456,3 +456,8 @@ PREPARE stmt FROM 'UPDATE t1 AS P1 INNER JOIN (SELECT N FROM t1 GROUP BY N HAVIN
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
create table t1 (a varchar(20));
insert into t1 values ('foo');
prepare stmt FROM 'SELECT char_length (a) FROM t1';
ERROR 42000: FUNCTION test.char_length does not exist
drop table t1;
......@@ -462,3 +462,14 @@ EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
# Bug#6102 "Server crash with prepared statement and blank after
# function name"
# ensure that stored functions are cached when preparing a statement
# before we open tables
#
create table t1 (a varchar(20));
insert into t1 values ('foo');
--error 1305
prepare stmt FROM 'SELECT char_length (a) FROM t1';
drop table t1;
......@@ -72,6 +72,7 @@ Long data handling:
#include "sql_select.h" // for JOIN
#include <m_ctype.h> // for isspace()
#include "sp_head.h"
#include "sp.h"
#ifdef EMBEDDED_LIBRARY
/* include MYSQL_BIND headers */
#include <mysql.h>
......@@ -1409,6 +1410,20 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol)
lex->first_lists_tables_same();
tables= lex->query_tables;
/*
Preopen 'proc' system table and cache all functions used in this
statement. We must do that before we open ordinary tables to avoid
deadlocks. We can't open and lock any table once query tables were
opened.
*/
if (lex->sql_command != SQLCOM_CREATE_PROCEDURE &&
lex->sql_command != SQLCOM_CREATE_SPFUNCTION)
{
/* the error is print inside */
if (sp_cache_functions(thd, lex))
DBUG_RETURN(1);
}
switch (sql_command) {
case SQLCOM_REPLACE:
case SQLCOM_INSERT:
......
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