mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
Fixed BUG#5287: Stored procedure crash if leave outside loop.
Bug in diff_handlers and diff_cursors made it attempt to pop the wrong number at jumps sometimes. mysql-test/r/sp.result: New testcase for BUG#5287. mysql-test/t/sp.test: New testcase for BUG#5287. sql/sp_pcontext.cc: Fixed diff_handlers and diff_cursors methods, they miscounted. sql/sp_pcontext.h: Made m_handlers available for diff_handlers.
This commit is contained in:
parent
711e887905
commit
339859d261
4 changed files with 33 additions and 7 deletions
|
@ -1764,6 +1764,18 @@ call bug5251()|
|
||||||
Table Checksum
|
Table Checksum
|
||||||
test.t1 0
|
test.t1 0
|
||||||
drop procedure bug5251|
|
drop procedure bug5251|
|
||||||
|
create procedure bug5287(param1 int)
|
||||||
|
label1:
|
||||||
|
begin
|
||||||
|
declare c cursor for select 5;
|
||||||
|
loop
|
||||||
|
if param1 >= 0 then
|
||||||
|
leave label1;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
end|
|
||||||
|
call bug5287(1)|
|
||||||
|
drop procedure bug5287|
|
||||||
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)
|
||||||
|
|
|
@ -1924,6 +1924,23 @@ call bug5251()|
|
||||||
call bug5251()|
|
call bug5251()|
|
||||||
drop procedure bug5251|
|
drop procedure bug5251|
|
||||||
|
|
||||||
|
#
|
||||||
|
# BUG#5287: Stored procedure crash if leave outside loop
|
||||||
|
#
|
||||||
|
create procedure bug5287(param1 int)
|
||||||
|
label1:
|
||||||
|
begin
|
||||||
|
declare c cursor for select 5;
|
||||||
|
|
||||||
|
loop
|
||||||
|
if param1 >= 0 then
|
||||||
|
leave label1;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
end|
|
||||||
|
call bug5287(1)|
|
||||||
|
drop procedure bug5287|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Some "real" examples
|
# Some "real" examples
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
sp_pcontext::sp_pcontext(sp_pcontext *prev)
|
sp_pcontext::sp_pcontext(sp_pcontext *prev)
|
||||||
: Sql_alloc(), m_psubsize(0), m_csubsize(0), m_hsubsize(0),
|
: Sql_alloc(), m_psubsize(0), m_csubsize(0), m_hsubsize(0),
|
||||||
m_parent(prev), m_handlers(0)
|
m_handlers(0), m_parent(prev)
|
||||||
{
|
{
|
||||||
VOID(my_init_dynamic_array(&m_pvar, sizeof(sp_pvar_t *), 16, 8));
|
VOID(my_init_dynamic_array(&m_pvar, sizeof(sp_pvar_t *), 16, 8));
|
||||||
VOID(my_init_dynamic_array(&m_cond, sizeof(sp_cond_type_t *), 16, 8));
|
VOID(my_init_dynamic_array(&m_cond, sizeof(sp_cond_type_t *), 16, 8));
|
||||||
|
@ -94,7 +94,7 @@ sp_pcontext::diff_handlers(sp_pcontext *ctx)
|
||||||
|
|
||||||
while (pctx && pctx != ctx)
|
while (pctx && pctx != ctx)
|
||||||
{
|
{
|
||||||
n+= pctx->max_handlers();
|
n+= pctx->m_handlers;
|
||||||
pctx= pctx->parent_context();
|
pctx= pctx->parent_context();
|
||||||
}
|
}
|
||||||
if (pctx)
|
if (pctx)
|
||||||
|
@ -109,12 +109,9 @@ sp_pcontext::diff_cursors(sp_pcontext *ctx)
|
||||||
sp_pcontext *pctx= this;
|
sp_pcontext *pctx= this;
|
||||||
|
|
||||||
while (pctx && pctx != ctx)
|
while (pctx && pctx != ctx)
|
||||||
{
|
|
||||||
n+= pctx->max_cursors();
|
|
||||||
pctx= pctx->parent_context();
|
pctx= pctx->parent_context();
|
||||||
}
|
|
||||||
if (pctx)
|
if (pctx)
|
||||||
return n;
|
return ctx->current_cursors() - pctx->current_cursors();
|
||||||
return 0; // Didn't find ctx
|
return 0; // Didn't find ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,7 @@ protected:
|
||||||
uint m_psubsize;
|
uint m_psubsize;
|
||||||
uint m_csubsize;
|
uint m_csubsize;
|
||||||
uint m_hsubsize;
|
uint m_hsubsize;
|
||||||
|
uint m_handlers; // No. of handlers in this context
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -282,7 +283,6 @@ private:
|
||||||
|
|
||||||
uint m_poffset; // Variable offset for this context
|
uint m_poffset; // Variable offset for this context
|
||||||
uint m_coffset; // Cursor offset for this context
|
uint m_coffset; // Cursor offset for this context
|
||||||
uint m_handlers; // No. of handlers in this context
|
|
||||||
|
|
||||||
DYNAMIC_ARRAY m_pvar; // Parameters/variables
|
DYNAMIC_ARRAY m_pvar; // Parameters/variables
|
||||||
DYNAMIC_ARRAY m_cond; // Conditions
|
DYNAMIC_ARRAY m_cond; // Conditions
|
||||||
|
|
Loading…
Reference in a new issue