mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fix for Bug#5034 "prepared "select 1 into @arg15", second
execute crashes server": we were deleting lex->result after each execute, but prepared statements assumed that it's left intact. The fix adds cleanup() method to select_result hierarchy, so that result objects can be reused. Plus we now need to delete result objects more wisely.
This commit is contained in:
@ -155,10 +155,10 @@ bool foreign_key_prefix(Key *a, Key *b)
|
||||
** Thread specific functions
|
||||
****************************************************************************/
|
||||
|
||||
THD::THD():user_time(0), current_arena(this), is_fatal_error(0),
|
||||
last_insert_id_used(0),
|
||||
THD::THD():user_time(0), current_arena(this), global_read_lock(0),
|
||||
is_fatal_error(0), last_insert_id_used(0),
|
||||
insert_id_used(0), rand_used(0), time_zone_used(0),
|
||||
in_lock_tables(0), global_read_lock(0), bootstrap(0)
|
||||
in_lock_tables(0), bootstrap(0)
|
||||
{
|
||||
host= user= priv_user= db= ip=0;
|
||||
host_or_ip= "connecting host";
|
||||
@ -703,6 +703,12 @@ void select_result::send_error(uint errcode,const char *err)
|
||||
::send_error(thd, errcode, err);
|
||||
}
|
||||
|
||||
|
||||
void select_result::cleanup()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
static String default_line_term("\n",default_charset_info);
|
||||
static String default_escaped("\\",default_charset_info);
|
||||
static String default_field_term("\t",default_charset_info);
|
||||
@ -808,6 +814,32 @@ void select_to_file::send_error(uint errcode,const char *err)
|
||||
}
|
||||
|
||||
|
||||
bool select_to_file::send_eof()
|
||||
{
|
||||
int error= test(end_io_cache(&cache));
|
||||
if (my_close(file,MYF(MY_WME)))
|
||||
error= 1;
|
||||
if (!error)
|
||||
::send_ok(thd,row_count);
|
||||
file= -1;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
void select_to_file::cleanup()
|
||||
{
|
||||
/* In case of error send_eof() may be not called: close the file here. */
|
||||
if (file >= 0)
|
||||
{
|
||||
(void) end_io_cache(&cache);
|
||||
(void) my_close(file,MYF(0));
|
||||
file= -1;
|
||||
}
|
||||
path[0]= '\0';
|
||||
row_count= 0;
|
||||
}
|
||||
|
||||
|
||||
select_to_file::~select_to_file()
|
||||
{
|
||||
if (file >= 0)
|
||||
@ -1058,18 +1090,6 @@ err:
|
||||
}
|
||||
|
||||
|
||||
bool select_export::send_eof()
|
||||
{
|
||||
int error=test(end_io_cache(&cache));
|
||||
if (my_close(file,MYF(MY_WME)))
|
||||
error=1;
|
||||
if (!error)
|
||||
::send_ok(thd,row_count);
|
||||
file= -1;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
** Dump of select to a binary file
|
||||
***************************************************************************/
|
||||
@ -1123,18 +1143,6 @@ err:
|
||||
}
|
||||
|
||||
|
||||
bool select_dump::send_eof()
|
||||
{
|
||||
int error=test(end_io_cache(&cache));
|
||||
if (my_close(file,MYF(MY_WME)))
|
||||
error=1;
|
||||
if (!error)
|
||||
::send_ok(thd,row_count);
|
||||
file= -1;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
select_subselect::select_subselect(Item_subselect *item_arg)
|
||||
{
|
||||
item= item_arg;
|
||||
@ -1301,6 +1309,13 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
|
||||
}
|
||||
|
||||
|
||||
void select_dumpvar::cleanup()
|
||||
{
|
||||
vars.empty();
|
||||
row_count=0;
|
||||
}
|
||||
|
||||
|
||||
Item_arena::Item_arena(THD* thd)
|
||||
:free_list(0),
|
||||
state(INITIALIZED)
|
||||
@ -1405,6 +1420,21 @@ void Statement::restore_backup_statement(Statement *stmt, Statement *backup)
|
||||
}
|
||||
|
||||
|
||||
void Statement::end_statement()
|
||||
{
|
||||
/* Cleanup SQL processing state to resuse this statement in next query. */
|
||||
lex_end(lex);
|
||||
delete lex->result;
|
||||
lex->result= 0;
|
||||
free_items(free_list);
|
||||
free_list= 0;
|
||||
/*
|
||||
Don't free mem_root, as mem_root is freed in the end of dispatch_command
|
||||
(once for any command).
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void Item_arena::set_n_backup_item_arena(Item_arena *set, Item_arena *backup)
|
||||
{
|
||||
backup->set_item_arena(this);
|
||||
|
Reference in New Issue
Block a user