diff options
Diffstat (limited to 'sql/item.cc')
-rw-r--r-- | sql/item.cc | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/sql/item.cc b/sql/item.cc index d3345f69a40..9f0280b678c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1789,13 +1789,16 @@ void Item_sp_variable::make_field(THD *thd, Send_field *field) Item_splocal methods *****************************************************************************/ -Item_splocal::Item_splocal(THD *thd, const LEX_CSTRING *sp_var_name, +Item_splocal::Item_splocal(THD *thd, + const Sp_rcontext_handler *rh, + const LEX_CSTRING *sp_var_name, uint sp_var_idx, const Type_handler *handler, uint pos_in_q, uint len_in_q): Item_sp_variable(thd, sp_var_name), Rewritable_query_parameter(pos_in_q, len_in_q), Type_handler_hybrid_field_type(handler), + m_rcontext_handler(rh), m_var_idx(sp_var_idx) { maybe_null= TRUE; @@ -1803,9 +1806,21 @@ Item_splocal::Item_splocal(THD *thd, const LEX_CSTRING *sp_var_name, } +sp_rcontext *Item_splocal::get_rcontext(sp_rcontext *local_ctx) const +{ + return m_rcontext_handler->get_rcontext(local_ctx); +} + + +Item_field *Item_splocal::get_variable(sp_rcontext *ctx) const +{ + return get_rcontext(ctx)->get_variable(m_var_idx); +} + + bool Item_splocal::fix_fields(THD *thd, Item **ref) { - Item_field *item= thd->spcont->get_variable(m_var_idx); + Item *item= get_variable(thd->spcont); set_handler(item->type_handler()); return fix_fields_from_item(thd, ref, item); } @@ -1816,7 +1831,7 @@ Item_splocal::this_item() { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_variable(m_var_idx); + return get_variable(m_thd->spcont); } const Item * @@ -1824,7 +1839,7 @@ Item_splocal::this_item() const { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_variable(m_var_idx); + return get_variable(m_thd->spcont); } @@ -1833,13 +1848,15 @@ Item_splocal::this_item_addr(THD *thd, Item **) { DBUG_ASSERT(m_sp == thd->spcont->m_sp); DBUG_ASSERT(fixed); - return thd->spcont->get_variable_addr(m_var_idx); + return get_rcontext(thd->spcont)->get_variable_addr(m_var_idx); } void Item_splocal::print(String *str, enum_query_type) { - str->reserve(m_name.length+8); + const LEX_CSTRING *prefix= m_rcontext_handler->get_name_prefix(); + str->reserve(m_name.length + 8 + prefix->length); + str->append(prefix); str->append(&m_name); str->append('@'); str->qs_append(m_var_idx); @@ -1848,7 +1865,7 @@ void Item_splocal::print(String *str, enum_query_type) bool Item_splocal::set_value(THD *thd, sp_rcontext *ctx, Item **it) { - return ctx->set_variable(thd, get_var_idx(), it); + return get_rcontext(ctx)->set_variable(thd, get_var_idx(), it); } @@ -1930,7 +1947,7 @@ bool Item_splocal::check_cols(uint n) bool Item_splocal_row_field::fix_fields(THD *thd, Item **ref) { - Item *item= thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); + Item *item= get_variable(thd->spcont)->element_index(m_field_idx); return fix_fields_from_item(thd, ref, item); } @@ -1940,7 +1957,7 @@ Item_splocal_row_field::this_item() { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); + return get_variable(m_thd->spcont)->element_index(m_field_idx); } @@ -1949,7 +1966,7 @@ Item_splocal_row_field::this_item() const { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); + return get_variable(m_thd->spcont)->element_index(m_field_idx); } @@ -1958,13 +1975,15 @@ Item_splocal_row_field::this_item_addr(THD *thd, Item **) { DBUG_ASSERT(m_sp == thd->spcont->m_sp); DBUG_ASSERT(fixed); - return thd->spcont->get_variable(m_var_idx)->addr(m_field_idx); + return get_variable(thd->spcont)->addr(m_field_idx); } void Item_splocal_row_field::print(String *str, enum_query_type) { - str->reserve(m_name.length + m_field_name.length + 8); + const LEX_CSTRING *prefix= m_rcontext_handler->get_name_prefix(); + str->reserve(m_name.length + m_field_name.length + 8 + prefix->length); + str->append(prefix); str->append(&m_name); str->append('.'); str->append(&m_field_name); @@ -1978,18 +1997,19 @@ void Item_splocal_row_field::print(String *str, enum_query_type) bool Item_splocal_row_field::set_value(THD *thd, sp_rcontext *ctx, Item **it) { - return ctx->set_variable_row_field(thd, m_var_idx, m_field_idx, it); + return get_rcontext(ctx)->set_variable_row_field(thd, m_var_idx, m_field_idx, + it); } bool Item_splocal_row_field_by_name::fix_fields(THD *thd, Item **it) { m_thd= thd; - if (thd->spcont->find_row_field_by_name_or_error(&m_field_idx, - m_var_idx, - m_field_name)) + if (get_rcontext(thd->spcont)->find_row_field_by_name_or_error(&m_field_idx, + m_var_idx, + m_field_name)) return true; - Item *item= thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); + Item *item= get_variable(thd->spcont)->element_index(m_field_idx); set_handler(item->type_handler()); return fix_fields_from_item(thd, it, item); } @@ -1997,9 +2017,12 @@ bool Item_splocal_row_field_by_name::fix_fields(THD *thd, Item **it) void Item_splocal_row_field_by_name::print(String *str, enum_query_type) { + const LEX_CSTRING *prefix= m_rcontext_handler->get_name_prefix(); // +16 should be enough for .NNN@[""] - if (str->reserve(m_name.length + 2 * m_field_name.length + 16)) + if (str->reserve(m_name.length + 2 * m_field_name.length + + prefix->length + 16)) return; + str->qs_append(prefix); str->qs_append(&m_name); str->qs_append('.'); str->qs_append(&m_field_name); |