From 5f006200d10542da309b9b8c21e810e9da8f637d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Apr 2005 16:05:16 +0200 Subject: [PATCH] Fixed BUG#7299: Stored procedures: exception handler catches not-found conditions mysql-test/r/sp-error.result: Added test case for BUG#7299. mysql-test/t/sp-error.test: Added test case for BUG#7299. sql/sp_rcontext.cc: Corrected cut&paste error; make sure we only catch actual errors with sqlexception. --- mysql-test/r/sp-error.result | 13 +++++++++++++ mysql-test/t/sp-error.test | 22 ++++++++++++++++++++++ sql/sp_rcontext.cc | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index ff7d71b3384..42e45f67d33 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -513,4 +513,17 @@ call bug9566()| ERROR HY000: Table 'proc' was not locked with LOCK TABLES unlock tables| drop procedure bug9566| +drop procedure if exists bug7299| +create procedure bug7299() +begin +declare v int; +declare c cursor for select val from t1; +declare exit handler for sqlexception select 'Error!'; +open c; +fetch c into v; +end| +delete from t1| +call bug7299()| +ERROR 02000: No data to FETCH +drop procedure bug7299| drop table t1| diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 51776453730..90c776a8b88 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -720,6 +720,28 @@ unlock tables| drop procedure bug9566| +# +# BUG#7299: Stored procedures: exception handler catches not-found conditions +# +--disable_warnings +drop procedure if exists bug7299| +--enable_warnings +create procedure bug7299() +begin + declare v int; + declare c cursor for select val from t1; + declare exit handler for sqlexception select 'Error!'; + + open c; + fetch c into v; +end| + +delete from t1| +--error ER_SP_FETCH_NO_DATA +call bug7299()| +drop procedure bug7299| + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 9b29c173856..e9271146cad 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -95,8 +95,8 @@ sp_rcontext::find_handler(uint sql_errno, found= i; break; case sp_cond_type_t::exception: - if ((sqlstate[0] != '0' || sqlstate[1] > '2' || - level == MYSQL_ERROR::WARN_LEVEL_ERROR) && + if ((sqlstate[0] != '0' || sqlstate[1] > '2') && + level == MYSQL_ERROR::WARN_LEVEL_ERROR && (found < 0 || m_handler[found].cond->type > sp_cond_type_t::state)) found= i; break;