diff options
author | Alexander Barkov <bar@mariadb.org> | 2017-02-07 13:32:55 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2017-04-05 15:02:56 +0400 |
commit | d836f52be520c3d9cf6c7041aa332cb8c43e3d79 (patch) | |
tree | 6e6f4bef950271d573bc02e5320e4e95241da428 /sql | |
parent | 72f43df623261d5fe579cb355451d84216c8882d (diff) | |
download | mariadb-git-d836f52be520c3d9cf6c7041aa332cb8c43e3d79.tar.gz |
MDEV-12007 Allow ROW variables as a cursor FETCH target
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.h | 6 | ||||
-rw-r--r-- | sql/sp_rcontext.cc | 36 | ||||
-rw-r--r-- | sql/sp_rcontext.h | 2 |
3 files changed, 40 insertions, 4 deletions
diff --git a/sql/field.h b/sql/field.h index 68327159a22..b3b8dcd703e 100644 --- a/sql/field.h +++ b/sql/field.h @@ -4037,6 +4037,12 @@ public: { return m_row_field_definitions != NULL; } + // Check if "this" defines a ROW variable with n elements + uint is_row(uint n) const + { + return m_row_field_definitions != NULL && + m_row_field_definitions->elements == n; + } Row_definition_list *row_field_definitions() const { return m_row_field_definitions; diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 17c91b09727..3ae455e00c9 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -572,6 +572,22 @@ int sp_rcontext::set_variable_row_field(THD *thd, uint var_idx, uint field_idx, } +int sp_rcontext::set_variable_row(THD *thd, uint var_idx, List<Item> &items) +{ + DBUG_ENTER("sp_rcontext::set_variable_row"); + DBUG_ASSERT(thd->spcont->get_item(var_idx)->cols() == items.elements); + List_iterator<Item> it(items); + Item *item; + for (uint i= 0 ; (item= it++) ; i++) + { + int rc; + if ((rc= thd->spcont->set_variable_row_field(thd, var_idx, i, &item))) + DBUG_RETURN(rc); + } + DBUG_RETURN(0); +} + + Item_cache *sp_rcontext::create_case_expr_holder(THD *thd, const Item *item) const { @@ -688,7 +704,9 @@ int sp_cursor::fetch(THD *thd, List<sp_variable> *vars) MYF(0)); return -1; } - if (vars->elements != result.get_field_count()) + if (vars->elements != result.get_field_count() && + (vars->elements != 1 || + !vars->head()->field_def.is_row(result.get_field_count()))) { my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS, ER_THD(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0)); @@ -743,15 +761,16 @@ int sp_cursor::Select_fetch_into_spvars::prepare(List<Item> &fields, } -int sp_cursor::Select_fetch_into_spvars::send_data(List<Item> &items) +bool sp_cursor::Select_fetch_into_spvars:: + send_data_to_variable_list(List<sp_variable> &vars, List<Item> &items) { - List_iterator_fast<sp_variable> spvar_iter(*spvar_list); + List_iterator_fast<sp_variable> spvar_iter(vars); List_iterator_fast<Item> item_iter(items); sp_variable *spvar; Item *item; /* Must be ensured by the caller */ - DBUG_ASSERT(spvar_list->elements == items.elements); + DBUG_ASSERT(vars.elements == items.elements); /* Assign the row fetched from a server side cursor to stored @@ -764,3 +783,12 @@ int sp_cursor::Select_fetch_into_spvars::send_data(List<Item> &items) } return false; } + + +int sp_cursor::Select_fetch_into_spvars::send_data(List<Item> &items) +{ + return (spvar_list->elements == 1 && + (spvar_list->head())->field_def.is_row(items.elements)) ? + thd->spcont->set_variable_row(thd, spvar_list->head()->offset, items) : + send_data_to_variable_list(*spvar_list, items); +} diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index 78cbfd9ec26..79d571faca7 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -190,6 +190,7 @@ public: void set_variable_row_field_to_null(THD *thd, uint var_idx, uint field_idx); int set_variable_row_field(THD *thd, uint var_idx, uint field_idx, Item **value); + int set_variable_row(THD *thd, uint var_idx, List<Item> &items); Item *get_item(uint var_idx) const { return m_var_items[var_idx]; } @@ -419,6 +420,7 @@ private: { List<sp_variable> *spvar_list; uint field_count; + bool send_data_to_variable_list(List<sp_variable> &vars, List<Item> &items); public: Select_fetch_into_spvars(THD *thd_arg): select_result_interceptor(thd_arg) {} uint get_field_count() { return field_count; } |