From 5c44e1acfeebe5e49b32add9a4a19aaf33892455 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 Apr 2005 16:35:49 +0200 Subject: [PATCH] Post-review fixes of the patch for BUG#8408: Stored procedure crash if function contains SHOW (Review on irc by monty) mysql-test/r/sp-error.result: Renamed a procedure and function to avoid confusion mysql-test/t/sp-error.test: Renamed a procedure and function to avoid confusion sql/item_func.cc: Corrected (and better) way to set/reset the client cap. flag in Item_func_sp::execute() sql/share/errmsg.txt: Changed the ER_SP_BADSELECT error; more accurate, and includes the procedure name. sql/sql_parse.cc: Include the procedure name in the new error message. --- mysql-test/r/sp-error.result | 20 ++++++++++---------- mysql-test/t/sp-error.test | 23 ++++++++++++----------- sql/item_func.cc | 10 ++++------ sql/share/errmsg.txt | 2 +- sql/sql_parse.cc | 2 +- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index a2478343806..683f3e12091 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -594,8 +594,6 @@ alter function bug7047; return 0; end| ERROR HY000: Can't drop or alter a FUNCTION from within another stored routine -drop function if exists bug8408| -drop procedure if exists bug8408| create function bug8408() returns int begin select * from t1; @@ -615,19 +613,21 @@ select b; return b; end| ERROR 0A000: Not allowed to return a result set from a function -create function bug8408() returns int +drop function if exists bug8408_f| +drop procedure if exists bug8408_p| +create function bug8408_f() returns int begin -call bug8408(); +call bug8408_p(); return 0; end| -create procedure bug8408() +create procedure bug8408_p() select * from t1| -call bug8408()| +call bug8408_p()| val x -select bug8408()| -ERROR 0A000: SELECT in a stored procedure must have INTO -drop procedure bug8408| -drop function bug8408| +select bug8408_f()| +ERROR 0A000: PROCEDURE test.bug8408_p can't return a result set in the given context +drop procedure bug8408_p| +drop function bug8408_f| create function bug8408() returns int begin declare n int default 0; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index b2d24167e49..ff317b4ac28 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -835,10 +835,6 @@ end| # BUG#8408: Stored procedure crash if function contains SHOW # BUG#9058: Stored Procedures: Crash if function included SELECT # ---disable_warnings -drop function if exists bug8408| -drop procedure if exists bug8408| ---enable_warnings # Some things are caught when parsing --error ER_SP_NO_RETSET_IN_FUNC @@ -861,21 +857,26 @@ begin return b; end| +--disable_warnings +drop function if exists bug8408_f| +drop procedure if exists bug8408_p| +--enable_warnings + # Some things must be caught at invokation time -create function bug8408() returns int +create function bug8408_f() returns int begin - call bug8408(); + call bug8408_p(); return 0; end| -create procedure bug8408() +create procedure bug8408_p() select * from t1| -call bug8408()| +call bug8408_p()| --error ER_SP_BADSELECT -select bug8408()| +select bug8408_f()| -drop procedure bug8408| -drop function bug8408| +drop procedure bug8408_p| +drop function bug8408_f| # But this is ok create function bug8408() returns int diff --git a/sql/item_func.cc b/sql/item_func.cc index 3472c0ab786..24a3f7927ae 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4554,7 +4554,7 @@ Item_func_sp::execute(Item **itp) { DBUG_ENTER("Item_func_sp::execute"); THD *thd= current_thd; - bool clcap_mr; + ulong old_client_capabilites; int res; #ifndef NO_EMBEDDED_ACCESS_CHECKS st_sp_security_context save_ctx; @@ -4568,7 +4568,7 @@ Item_func_sp::execute(Item **itp) DBUG_RETURN(-1); } - clcap_mr= (thd->client_capabilities & CLIENT_MULTI_RESULTS); + old_client_capabilites= thd->client_capabilities; thd->client_capabilities &= ~CLIENT_MULTI_RESULTS; #ifndef EMBEDDED_LIBRARY @@ -4586,8 +4586,7 @@ Item_func_sp::execute(Item **itp) m_sp->m_db.str, m_sp->m_name.str, 0)) { sp_restore_security_context(thd, m_sp, &save_ctx); - if (clcap_mr) - thd->client_capabilities |= CLIENT_MULTI_RESULTS; + thd->client_capabilities|= old_client_capabilites & CLIENT_MULTI_RESULTS; DBUG_RETURN(-1); } #endif @@ -4602,8 +4601,7 @@ Item_func_sp::execute(Item **itp) thd->net.no_send_ok= nsok; #endif - if (clcap_mr) - thd->client_capabilities |= CLIENT_MULTI_RESULTS; + thd->client_capabilities|= old_client_capabilites & CLIENT_MULTI_RESULTS; DBUG_RETURN(res); } diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 66986a884b3..3a311ff7917 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5090,7 +5090,7 @@ ER_SP_LABEL_MISMATCH 42000 ER_SP_UNINIT_VAR 01000 eng "Referring to uninitialized variable %s" ER_SP_BADSELECT 0A000 - eng "SELECT in a stored procedure must have INTO" + eng "PROCEDURE %s can't return a result set in the given context" ER_SP_BADRETURN 42000 eng "RETURN is only allowed in a FUNCTION" ER_SP_BADSTATEMENT 0A000 diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c5ef9f4e713..ccba268e18e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4052,7 +4052,7 @@ unsent_create_error: { if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS)) { - my_message(ER_SP_BADSELECT, ER(ER_SP_BADSELECT), MYF(0)); + my_error(ER_SP_BADSELECT, MYF(0), sp->m_qname.str); #ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; #endif