Commit 8be8ea54 authored by unknown's avatar unknown

Fixed crash bug when certain procedures are called from the top level.


sql/sp_head.cc:
  Fixed crash bug when certain procedures are called from the top level.
  Attempted to support global user vars as OUT/INOUT parameters too, but
  unfortunately we can't quite manage that yet.
parent c31a9d78
...@@ -117,6 +117,7 @@ sp_head::execute(THD *thd) ...@@ -117,6 +117,7 @@ sp_head::execute(THD *thd)
uint params = pctx->params(); uint params = pctx->params();
sp_rcontext *octx = thd->spcont; sp_rcontext *octx = thd->spcont;
sp_rcontext *nctx = NULL; sp_rcontext *nctx = NULL;
my_bool tmp_octx = FALSE; // True if we have allocated a temporary octx
if (csize > 0) if (csize > 0)
{ {
...@@ -125,6 +126,11 @@ sp_head::execute(THD *thd) ...@@ -125,6 +126,11 @@ sp_head::execute(THD *thd)
Item *it = li++; // Skip first one, it's the procedure name Item *it = li++; // Skip first one, it's the procedure name
nctx = new sp_rcontext(csize); nctx = new sp_rcontext(csize);
if (! octx)
{ // Create a temporary old context
octx = new sp_rcontext(csize);
tmp_octx = TRUE;
}
// QQ: No error checking whatsoever right now. Should do type checking? // QQ: No error checking whatsoever right now. Should do type checking?
for (i = 0 ; (it= li++) && i < params ; i++) for (i = 0 ; (it= li++) && i < params ; i++)
{ {
...@@ -172,15 +178,43 @@ sp_head::execute(THD *thd) ...@@ -172,15 +178,43 @@ sp_head::execute(THD *thd)
// Don't copy back OUT values if we got an error // Don't copy back OUT values if we got an error
if (ret == 0 && csize > 0) if (ret == 0 && csize > 0)
{ {
// Copy back all OUT or INOUT values to the previous frame List_iterator_fast<Item> li(m_call_lex->value_list);
for (uint i = 0 ; i < params ; i++) Item *it = li++; // Skip first one, it's the procedure name
// Copy back all OUT or INOUT values to the previous frame, or
// set global user variables
for (uint i = 0 ; (it= li++) && i < params ; i++)
{ {
int oi = nctx->get_oindex(i); int oi = nctx->get_oindex(i);
if (oi >= 0) if (oi >= 0)
{
if (! tmp_octx)
octx->set_item(nctx->get_oindex(i), nctx->get_item(i)); octx->set_item(nctx->get_oindex(i), nctx->get_item(i));
else
{ // A global user variable
#if 0
// QQ This works if the parameter really is a user variable, but
// for the moment we can't assure that, so it will crash if it's
// something else. So for now, we just do nothing, to avoid a crash.
// Note: This also assumes we have a get_name() method in
// the Item_func_get_user_var class.
Item *item= nctx->get_item(i);
Item_func_set_user_var *suv;
Item_func_get_user_var *guv= static_cast<Item_func_get_user_var*>(it);
suv= new Item_func_set_user_var(guv->get_name(), item);
suv->fix_fields(thd, NULL, &item);
suv->fix_length_and_dec();
suv->update();
#endif
}
}
} }
if (tmp_octx)
thd->spcont= NULL;
else
thd->spcont= octx; thd->spcont= octx;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment