mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
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.
This commit is contained in:
@@ -514,6 +514,22 @@ id data
|
||||
hndlr3 13
|
||||
delete from t1;
|
||||
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()
|
||||
begin
|
||||
declare done int default 0;
|
||||
|
||||
@@ -604,6 +604,29 @@ select * from t1|
|
||||
delete from t1|
|
||||
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
|
||||
#
|
||||
|
||||
@@ -229,7 +229,9 @@ public:
|
||||
|
||||
Item_splocal(uint offset)
|
||||
: m_offset(offset)
|
||||
{}
|
||||
{
|
||||
Item::maybe_null= TRUE;
|
||||
}
|
||||
|
||||
Item *this_item();
|
||||
Item *this_const_item() const;
|
||||
|
||||
@@ -401,11 +401,17 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
|
||||
close_thread_tables(thd);
|
||||
|
||||
// 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,
|
||||
// so we set it to NULL for now. It's an error to refer to an
|
||||
// unassigned variable anyway (which should be detected by the parser).
|
||||
for (; i < csize ; i++)
|
||||
nctx->push_item(NULL);
|
||||
// Default all variables to null (those with default clauses will
|
||||
// be set by an set instruction).
|
||||
{
|
||||
Item_null *nit= NULL; // Re-use this, and only create if needed
|
||||
for (; i < csize ; i++)
|
||||
{
|
||||
if (! nit)
|
||||
nit= new Item_null();
|
||||
nctx->push_item(nit);
|
||||
}
|
||||
}
|
||||
thd->spcont= nctx;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user