Commit 82e5115a authored by unknown's avatar unknown

Bugfix. Local variables are now initialized to null.


mysql-test/r/sp.result:
  New test case for bugfix (when a variable is not set due to an exception).
mysql-test/t/sp.test:
  New test case for bugfix (when a variable is not set due to an exception).
sql/item.h:
  Local variables are initialized to null.
sql/sp_head.cc:
  Local variables are initialized to null.
parent 12a0546d
...@@ -514,6 +514,22 @@ id data ...@@ -514,6 +514,22 @@ id data
hndlr3 13 hndlr3 13
delete from t1; delete from t1;
drop procedure hndlr3; drop procedure hndlr3;
create procedure hndlr4()
begin
declare x int default 0;
declare val int; # No default
declare continue handler for sqlexception set x=1;
select data into val from test.t1 where id='z' limit 1; # No hits
if val < 10 then
insert into test.t1 values ('z', 10);
end if;
end;
call hndlr4();
select * from t1;
id data
z 10
delete from t1;
drop procedure hndlr4;
create procedure cur1() create procedure cur1()
begin begin
declare done int default 0; declare done int default 0;
......
...@@ -604,6 +604,29 @@ select * from t1| ...@@ -604,6 +604,29 @@ select * from t1|
delete from t1| delete from t1|
drop procedure hndlr3| drop procedure hndlr3|
# Variables might be uninitialized when using handlers
# (Otherwise the compiler can detect if a variable is not set, but
# not in this case.)
create procedure hndlr4()
begin
declare x int default 0;
declare val int; # No default
declare continue handler for sqlexception set x=1;
select data into val from test.t1 where id='z' limit 1; # No hits
if val < 10 then
insert into test.t1 values ('z', 10);
end if;
end|
call hndlr4()|
select * from t1|
delete from t1|
drop procedure hndlr4|
# #
# Cursors # Cursors
# #
......
...@@ -229,7 +229,9 @@ public: ...@@ -229,7 +229,9 @@ public:
Item_splocal(uint offset) Item_splocal(uint offset)
: m_offset(offset) : m_offset(offset)
{} {
Item::maybe_null= TRUE;
}
Item *this_item(); Item *this_item();
Item *this_const_item() const; Item *this_const_item() const;
......
...@@ -401,11 +401,17 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) ...@@ -401,11 +401,17 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
close_thread_tables(thd); close_thread_tables(thd);
// The rest of the frame are local variables which are all IN. // The rest of the frame are local variables which are all IN.
// QQ We haven't found any hint of what the value is when unassigned, // Default all variables to null (those with default clauses will
// so we set it to NULL for now. It's an error to refer to an // be set by an set instruction).
// unassigned variable anyway (which should be detected by the parser). {
Item_null *nit= NULL; // Re-use this, and only create if needed
for (; i < csize ; i++) for (; i < csize ; i++)
nctx->push_item(NULL); {
if (! nit)
nit= new Item_null();
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