Commit 5c44e1ac authored by unknown's avatar unknown

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.
parent 52cb1bc4
...@@ -594,8 +594,6 @@ alter function bug7047; ...@@ -594,8 +594,6 @@ alter function bug7047;
return 0; return 0;
end| end|
ERROR HY000: Can't drop or alter a FUNCTION from within another stored routine 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 create function bug8408() returns int
begin begin
select * from t1; select * from t1;
...@@ -615,19 +613,21 @@ select b; ...@@ -615,19 +613,21 @@ select b;
return b; return b;
end| end|
ERROR 0A000: Not allowed to return a result set from a function 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 begin
call bug8408(); call bug8408_p();
return 0; return 0;
end| end|
create procedure bug8408() create procedure bug8408_p()
select * from t1| select * from t1|
call bug8408()| call bug8408_p()|
val x val x
select bug8408()| select bug8408_f()|
ERROR 0A000: SELECT in a stored procedure must have INTO ERROR 0A000: PROCEDURE test.bug8408_p can't return a result set in the given context
drop procedure bug8408| drop procedure bug8408_p|
drop function bug8408| drop function bug8408_f|
create function bug8408() returns int create function bug8408() returns int
begin begin
declare n int default 0; declare n int default 0;
......
...@@ -835,10 +835,6 @@ end| ...@@ -835,10 +835,6 @@ end|
# BUG#8408: Stored procedure crash if function contains SHOW # BUG#8408: Stored procedure crash if function contains SHOW
# BUG#9058: Stored Procedures: Crash if function included SELECT # 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 # Some things are caught when parsing
--error ER_SP_NO_RETSET_IN_FUNC --error ER_SP_NO_RETSET_IN_FUNC
...@@ -861,21 +857,26 @@ begin ...@@ -861,21 +857,26 @@ begin
return b; return b;
end| 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 # Some things must be caught at invokation time
create function bug8408() returns int create function bug8408_f() returns int
begin begin
call bug8408(); call bug8408_p();
return 0; return 0;
end| end|
create procedure bug8408() create procedure bug8408_p()
select * from t1| select * from t1|
call bug8408()| call bug8408_p()|
--error ER_SP_BADSELECT --error ER_SP_BADSELECT
select bug8408()| select bug8408_f()|
drop procedure bug8408| drop procedure bug8408_p|
drop function bug8408| drop function bug8408_f|
# But this is ok # But this is ok
create function bug8408() returns int create function bug8408() returns int
......
...@@ -4554,7 +4554,7 @@ Item_func_sp::execute(Item **itp) ...@@ -4554,7 +4554,7 @@ Item_func_sp::execute(Item **itp)
{ {
DBUG_ENTER("Item_func_sp::execute"); DBUG_ENTER("Item_func_sp::execute");
THD *thd= current_thd; THD *thd= current_thd;
bool clcap_mr; ulong old_client_capabilites;
int res; int res;
#ifndef NO_EMBEDDED_ACCESS_CHECKS #ifndef NO_EMBEDDED_ACCESS_CHECKS
st_sp_security_context save_ctx; st_sp_security_context save_ctx;
...@@ -4568,7 +4568,7 @@ Item_func_sp::execute(Item **itp) ...@@ -4568,7 +4568,7 @@ Item_func_sp::execute(Item **itp)
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
clcap_mr= (thd->client_capabilities & CLIENT_MULTI_RESULTS); old_client_capabilites= thd->client_capabilities;
thd->client_capabilities &= ~CLIENT_MULTI_RESULTS; thd->client_capabilities &= ~CLIENT_MULTI_RESULTS;
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
...@@ -4586,8 +4586,7 @@ Item_func_sp::execute(Item **itp) ...@@ -4586,8 +4586,7 @@ Item_func_sp::execute(Item **itp)
m_sp->m_db.str, m_sp->m_name.str, 0)) m_sp->m_db.str, m_sp->m_name.str, 0))
{ {
sp_restore_security_context(thd, m_sp, &save_ctx); sp_restore_security_context(thd, m_sp, &save_ctx);
if (clcap_mr) thd->client_capabilities|= old_client_capabilites & CLIENT_MULTI_RESULTS;
thd->client_capabilities |= CLIENT_MULTI_RESULTS;
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
#endif #endif
...@@ -4602,8 +4601,7 @@ Item_func_sp::execute(Item **itp) ...@@ -4602,8 +4601,7 @@ Item_func_sp::execute(Item **itp)
thd->net.no_send_ok= nsok; thd->net.no_send_ok= nsok;
#endif #endif
if (clcap_mr) thd->client_capabilities|= old_client_capabilites & CLIENT_MULTI_RESULTS;
thd->client_capabilities |= CLIENT_MULTI_RESULTS;
DBUG_RETURN(res); DBUG_RETURN(res);
} }
......
...@@ -5090,7 +5090,7 @@ ER_SP_LABEL_MISMATCH 42000 ...@@ -5090,7 +5090,7 @@ ER_SP_LABEL_MISMATCH 42000
ER_SP_UNINIT_VAR 01000 ER_SP_UNINIT_VAR 01000
eng "Referring to uninitialized variable %s" eng "Referring to uninitialized variable %s"
ER_SP_BADSELECT 0A000 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 ER_SP_BADRETURN 42000
eng "RETURN is only allowed in a FUNCTION" eng "RETURN is only allowed in a FUNCTION"
ER_SP_BADSTATEMENT 0A000 ER_SP_BADSTATEMENT 0A000
......
...@@ -4052,7 +4052,7 @@ unsent_create_error: ...@@ -4052,7 +4052,7 @@ unsent_create_error:
{ {
if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS)) 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 #ifndef EMBEDDED_LIBRARY
thd->net.no_send_ok= nsok; thd->net.no_send_ok= nsok;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment