Commit bfe6ef9c authored by pem@mysql.comhem.se's avatar pem@mysql.comhem.se

Fix BUG#1656: Have to initialize OUT parameters too, in case they're not

later set by the procedure.
parent be26021b
...@@ -653,6 +653,17 @@ less 2 ...@@ -653,6 +653,17 @@ less 2
more 17 more 17
delete from t1; delete from t1;
drop procedure bug1547; drop procedure bug1547;
drop table if exists t70;
create table t70 (s1 int,s2 int);
insert into t70 values (1,2);
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70;
call bug1656(@1, @2);
select @1, @2;
@1 @2
2 NULL
drop table t70;
drop procedure bug1656;
drop table if exists fac; drop table if exists fac;
create table fac (n int unsigned not null primary key, f bigint unsigned); create table fac (n int unsigned not null primary key, f bigint unsigned);
create procedure ifac(n int unsigned) create procedure ifac(n int unsigned)
......
...@@ -764,6 +764,23 @@ select * from t1| ...@@ -764,6 +764,23 @@ select * from t1|
delete from t1| delete from t1|
drop procedure bug1547| drop procedure bug1547|
#
# BUG#1656
#
--disable_warnings
drop table if exists t70|
--enable_warnings
create table t70 (s1 int,s2 int)|
insert into t70 values (1,2)|
create procedure bug1656(out p1 int, out p2 int)
select * into p1, p1 from t70|
call bug1656(@1, @2)|
select @1, @2|
drop table t70|
drop procedure bug1656|
# #
# Some "real" examples # Some "real" examples
......
...@@ -373,6 +373,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) ...@@ -373,6 +373,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
if (csize > 0 || hmax > 0 || cmax > 0) if (csize > 0 || hmax > 0 || cmax > 0)
{ {
Item_null *nit= NULL; // Re-use this, and only create if needed
uint i; uint i;
List_iterator_fast<Item> li(*args); List_iterator_fast<Item> li(*args);
Item *it; Item *it;
...@@ -393,7 +394,11 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) ...@@ -393,7 +394,11 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
else else
{ {
if (pvar->mode == sp_param_out) if (pvar->mode == sp_param_out)
nctx->push_item(NULL); // OUT {
if (! nit)
nit= new Item_null();
nctx->push_item(nit); // OUT
}
else else
nctx->push_item(sp_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. // Note: If it's OUT or INOUT, it must be a variable.
...@@ -411,15 +416,12 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) ...@@ -411,15 +416,12 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
// The rest of the frame are local variables which are all IN. // The rest of the frame are local variables which are all IN.
// Default all variables to null (those with default clauses will // Default all variables to null (those with default clauses will
// be set by an set instruction). // be set by an set instruction).
{
Item_null *nit= NULL; // Re-use this, and only create if needed
for (; i < csize ; i++) for (; i < csize ; i++)
{ {
if (! nit) if (! nit)
nit= new Item_null(); nit= new Item_null();
nctx->push_item(nit); nctx->push_item(nit);
} }
}
thd->spcont= nctx; thd->spcont= nctx;
} }
......
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