From cc037976c3205a010d522c6318ba86cb67017c4e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 Jan 2006 17:19:54 +0100 Subject: [PATCH] Fixed BUGS#15011: error handler for mysql errno in nested block not activated For nested sql errno handlers (unlike sqlexception and other), we didn't stop searching when the innermost handler was found - now make sure we do. mysql-test/r/sp.result: Updated result for BUG#15011. mysql-test/t/sp.test: New testcase for BUG#15011. sql/sp_rcontext.cc: Make sure we stop at the innermost sql_errno handler. --- mysql-test/r/sp.result | 19 +++++++++++++++++++ mysql-test/t/sp.test | 31 +++++++++++++++++++++++++++++++ sql/sp_rcontext.cc | 3 ++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 904cd7d8642..90020573df3 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -4497,4 +4497,23 @@ drop procedure if exists bug15231_1| drop procedure if exists bug15231_2| drop procedure if exists bug15231_3| drop procedure if exists bug15231_4| +drop procedure if exists bug15011| +create table t3 (c1 int primary key)| +insert into t3 values (1)| +create procedure bug15011() +deterministic +begin +declare continue handler for 1062 +select 'Outer' as 'Handler'; +begin +declare continue handler for 1062 +select 'Inner' as 'Handler'; +insert into t3 values (1); +end; +end| +call bug15011()| +Handler +Inner +drop procedure bug15011| +drop table t3| drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 8235686a74a..32299ad7e0b 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5283,6 +5283,37 @@ drop procedure if exists bug15231_3| drop procedure if exists bug15231_4| +# +# BUG#15011: error handler in nested block not activated +# +--disable_warnings +drop procedure if exists bug15011| +--enable_warnings + +create table t3 (c1 int primary key)| + +insert into t3 values (1)| + +create procedure bug15011() + deterministic +begin + declare continue handler for 1062 + select 'Outer' as 'Handler'; + + begin + declare continue handler for 1062 + select 'Inner' as 'Handler'; + + insert into t3 values (1); + end; +end| + +call bug15011()| + +drop procedure bug15011| +drop table t3| + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 215de01e657..4818ffbbe31 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -188,7 +188,8 @@ sp_rcontext::find_handler(uint sql_errno, switch (cond->type) { case sp_cond_type_t::number: - if (sql_errno == cond->mysqlerr) + if (sql_errno == cond->mysqlerr && + (found < 0 || m_handler[found].cond->type > sp_cond_type_t::number)) found= i; // Always the most specific break; case sp_cond_type_t::state: