Skip to content
Permalink
Browse files
Remove the side effect of setting m_sp from Item_sp::init_result_field
Item_sp::init_result_field no longer takes sp_head* parameter. It
expects the m_sp member to be already set to something valid.
  • Loading branch information
cvicentiu committed Dec 4, 2017
1 parent c12d1ed commit 7448b01
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
@@ -2915,21 +2915,14 @@ Item_sp::execute_impl(THD *thd, Item **args, uint arg_count)
*/

bool
Item_sp::init_result_field(THD *thd, sp_head *sp, uint max_length,
uint maybe_null, bool *null_value, LEX_CSTRING *name)
Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null,
bool *null_value, LEX_CSTRING *name)
{
DBUG_ENTER("Item_sp::init_result_field");

DBUG_ASSERT(m_sp == NULL);
DBUG_ASSERT(m_sp != NULL);
DBUG_ASSERT(sp_result_field == NULL);

if (!(m_sp= sp))
{
my_missing_function_error (m_name->m_name, ErrConvDQName(m_name).ptr());
context->process_error(thd);
DBUG_RETURN(TRUE);
}

/*
A Field needs to be attached to a Table.
Below we "create" a dummy table by initializing
@@ -4496,8 +4496,8 @@ class Item_sp
bool sp_check_access(THD *thd);
bool execute(THD *thd, bool *null_value, Item **args, uint arg_count);
bool execute_impl(THD *thd, Item **args, uint arg_count);
bool init_result_field(THD *thd, sp_head *sp, uint max_length,
uint maybe_null, bool *null_value, LEX_CSTRING *name);
bool init_result_field(THD *thd, uint max_length, uint maybe_null,
bool *null_value, LEX_CSTRING *name);
};

class Item_ref :public Item_ident
@@ -6415,12 +6415,28 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
}
}


/* Custom aggregates are transformed into an Item_sum_sp. We can not do this
earlier as we have no way of knowing what kind of Item we should create
when parsing the query.
TODO(cvicentiu): See if this limitation can be lifted.
*/

DBUG_ASSERT(m_sp == NULL);
if (!(m_sp= sp))
{
my_missing_function_error(m_name->m_name, ErrConvDQName(m_name).ptr());
context->process_error(thd);
DBUG_RETURN(TRUE);
}

/*
We must call init_result_field before Item_func::fix_fields()
We must call init_result_field before Item_func::fix_fields()
to make m_sp and result_field members available to fix_length_and_dec(),
which is called from Item_func::fix_fields().
*/
res= init_result_field(thd, sp, max_length, maybe_null, &null_value, &name);
res= init_result_field(thd, max_length, maybe_null, &null_value, &name);

if (res)
DBUG_RETURN(TRUE);

0 comments on commit 7448b01

Please sign in to comment.