summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorpem@mysql.telia.com <>2003-10-14 12:59:28 +0200
committerpem@mysql.telia.com <>2003-10-14 12:59:28 +0200
commit225aada6d68e1650e5adcab5abb6336be380ef6b (patch)
tree5342ed0c4c015e0b898fea83341b508e5d1d94e4 /sql
parented1b5c59f0a4b49a4dde12a90a7d38984d4565ba (diff)
downloadmariadb-git-225aada6d68e1650e5adcab5abb6336be380ef6b.tar.gz
Fix for BUG#1495: Evaluate items before setting a local variable with SELECT INTO.
Also copy and restore order_list and group_list for selects in SPs.
Diffstat (limited to 'sql')
-rw-r--r--sql/sp_head.cc47
-rw-r--r--sql/sp_rcontext.cc8
-rw-r--r--sql/sp_rcontext.h3
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_class.h5
-rw-r--r--sql/sql_parse.cc2
-rw-r--r--sql/sql_yacc.yy4
-rw-r--r--sql/table.h1
8 files changed, 56 insertions, 16 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index bea4d7a34be..521e5577577 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -47,10 +47,10 @@ sp_map_result_type(enum enum_field_types type)
/* Evaluate a (presumed) func item. Always returns an item, the parameter
** if nothing else.
*/
-static Item *
-eval_func_item(THD *thd, Item *it, enum enum_field_types type)
+Item *
+sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
{
- DBUG_ENTER("eval_func_item");
+ DBUG_ENTER("sp_eval_func_item");
it= it->this_item();
DBUG_PRINT("info", ("type: %d", type));
@@ -310,7 +310,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp)
{
sp_pvar_t *pvar = m_pcont->find_pvar(i);
- nctx->push_item(eval_func_item(thd, *argp++, pvar->type));
+ nctx->push_item(sp_eval_func_item(thd, *argp++, pvar->type));
}
// Close tables opened for subselect in argument list
close_thread_tables(thd);
@@ -387,7 +387,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
if (pvar->mode == sp_param_out)
nctx->push_item(NULL); // OUT
else
- nctx->push_item(eval_func_item(thd, it, pvar->type)); // IN or INOUT
+ nctx->push_item(sp_eval_func_item(thd, it,pvar->type)); // IN or INOUT
// Note: If it's OUT or INOUT, it must be a variable.
// QQ: Need to handle "global" user/host variables too!!!
if (pvar->mode == sp_param_in)
@@ -626,10 +626,10 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
sl ;
sl= sl->next_select_in_list())
{
- List_iterator_fast<Item> li(sl->item_list);
-
if (sl->with_wild)
{
+ List_iterator_fast<Item> li(sl->item_list);
+
// Copy item_list
sl->item_list_copy.empty();
while (Item *it= li++)
@@ -638,7 +638,18 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
sl->ref_pointer_array= 0;
if (sl->prep_where)
sl->where= sl->prep_where->copy_andor_structure(thd);
- DBUG_ASSERT(sl->join == 0);
+ for (ORDER *order= (ORDER *)sl->order_list.first ;
+ order ;
+ order= order->next)
+ {
+ order->item_copy= order->item;
+ }
+ for (ORDER *group= (ORDER *)sl->group_list.first ;
+ group ;
+ group= group->next)
+ {
+ group->item_copy= group->item;
+ }
}
res= mysql_execute_command(thd);
@@ -660,6 +671,18 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
while (Item *it= sl->item_list_copy.pop())
sl->item_list.push_back(it);
}
+ for (ORDER *order= (ORDER *)sl->order_list.first ;
+ order ;
+ order= order->next)
+ {
+ order->item= order->item_copy;
+ }
+ for (ORDER *group= (ORDER *)sl->group_list.first ;
+ group ;
+ group= group->next)
+ {
+ group->item= group->item_copy;
+ }
}
thd->lex= olex; // Restore the other lex
thd->free_list= freelist;
@@ -675,7 +698,7 @@ sp_instr_set::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_set::execute");
DBUG_PRINT("info", ("offset: %u", m_offset));
- thd->spcont->set_item(m_offset, eval_func_item(thd, m_value, m_type));
+ thd->spcont->set_item(m_offset, sp_eval_func_item(thd, m_value, m_type));
*nextp = m_ip+1;
DBUG_RETURN(0);
}
@@ -701,7 +724,7 @@ sp_instr_jump_if::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_jump_if::execute");
DBUG_PRINT("info", ("destination: %u", m_dest));
- Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
+ Item *it= sp_eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
if (it->val_int())
*nextp = m_dest;
@@ -718,7 +741,7 @@ sp_instr_jump_if_not::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_jump_if_not::execute");
DBUG_PRINT("info", ("destination: %u", m_dest));
- Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
+ Item *it= sp_eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
if (! it->val_int())
*nextp = m_dest;
@@ -734,7 +757,7 @@ int
sp_instr_freturn::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_freturn::execute");
- thd->spcont->set_result(eval_func_item(thd, m_value, m_type));
+ thd->spcont->set_result(sp_eval_func_item(thd, m_value, m_type));
*nextp= UINT_MAX;
DBUG_RETURN(0);
}
diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc
index d73f3ed6dd7..07fd08b0074 100644
--- a/sql/sp_rcontext.cc
+++ b/sql/sp_rcontext.cc
@@ -40,6 +40,14 @@ sp_rcontext::sp_rcontext(uint fsize, uint hmax, uint cmax)
m_saved.empty();
}
+void
+sp_rcontext::set_item_eval(uint idx, Item *i, enum_field_types type)
+{
+ extern Item *sp_eval_func_item(THD *thd, Item *it, enum_field_types type);
+
+ set_item(idx, sp_eval_func_item(current_thd, i, type));
+}
+
int
sp_rcontext::find_handler(uint sql_errno)
{
diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h
index 027f2f74789..e69ac9bf4b4 100644
--- a/sql/sp_rcontext.h
+++ b/sql/sp_rcontext.h
@@ -69,6 +69,9 @@ class sp_rcontext : public Sql_alloc
m_frame[idx] = i;
}
+ void
+ set_item_eval(uint idx, Item *i, enum_field_types type);
+
inline Item *
get_item(uint idx)
{
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index fcfbe661599..487ae14f4cd 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1137,7 +1137,7 @@ bool select_dumpvar::send_data(List<Item> &items)
{
if ((yy=var_li++))
{
- thd->spcont->set_item(yy->get_offset(), item);
+ thd->spcont->set_item_eval(yy->get_offset(), item, zz->type);
}
}
else
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 19bf451be22..f7c9fb58513 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1123,7 +1123,10 @@ public:
LEX_STRING s;
bool local;
uint offset;
- my_var (LEX_STRING& j, bool i, uint o) : s(j), local(i), offset(o) {}
+ enum_field_types type;
+ my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
+ :s(j), local(i), offset(o), type(t)
+ {}
~my_var() {}
};
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 5c61247136f..3299b73a49c 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3724,6 +3724,8 @@ mysql_init_query(THD *thd, bool lexonly)
lex->select_lex.prev= &lex->unit.slave;
lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
+ lex->select_lex.init_order();
+ lex->select_lex.group_list.empty();
lex->describe= 0;
lex->derived_tables= FALSE;
lex->lock_option= TL_READ;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 1b65b9e87c0..c488b43ee6b 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -4351,7 +4351,7 @@ select_var_ident:
{
LEX *lex=Lex;
if (lex->result)
- ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0));
+ ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
else
YYABORT;
}
@@ -4370,7 +4370,7 @@ select_var_ident:
YYABORT;
else
{
- ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset));
+ ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset,t->type));
t->isset= TRUE;
}
}
diff --git a/sql/table.h b/sql/table.h
index 7b4e5745732..afa6665c8cd 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -26,6 +26,7 @@ class st_select_lex_unit;
typedef struct st_order {
struct st_order *next;
Item **item; /* Point at item in select fields */
+ Item **item_copy; /* For SPs; the original item ptr */
bool asc; /* true if ascending */
bool free_me; /* true if item isn't shared */
bool in_field_list; /* true if in select field list */