Commit 5c44e1ac authored by unknown's avatar unknown
Browse files

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
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -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;
+12 −11
Original line number Diff line number Diff line
@@ -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
+4 −6
Original line number Diff line number Diff line
@@ -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);
}
+1 −1
Original line number Diff line number Diff line
@@ -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 
+1 −1
Original line number Diff line number Diff line
@@ -4052,7 +4052,7 @@ mysql_execute_command(THD *thd)
	{
	  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