Commit 3cd1861a authored by Sergei Golubchik's avatar Sergei Golubchik

merge bugfuxes for sp-error.test

parent f0502cf8
...@@ -1315,19 +1315,25 @@ drop procedure test_signal $$ ...@@ -1315,19 +1315,25 @@ drop procedure test_signal $$
# #
# Test where SIGNAL can be used # Test where SIGNAL can be used
# #
# RETURN statement clears Diagnostics Area, thus
# the warnings raised in a stored function are not
# visible outsidef the stored function. So, we're using
# @@warning_count variable to check that SIGNAL succeeded.
create function test_signal_func() returns integer create function test_signal_func() returns integer
begin begin
DECLARE v INT;
DECLARE warn CONDITION FOR SQLSTATE "01XXX"; DECLARE warn CONDITION FOR SQLSTATE "01XXX";
SIGNAL warn SET SIGNAL warn SET
MESSAGE_TEXT = "This function SIGNAL a warning", MESSAGE_TEXT = "This function SIGNAL a warning",
MYSQL_ERRNO = 1012; MYSQL_ERRNO = 1012;
return 5; SELECT @@warning_count INTO v;
return v;
end $$ end $$
select test_signal_func() $$ select test_signal_func() $$
test_signal_func() test_signal_func()
5 1
Warnings:
Warning 1012 This function SIGNAL a warning
drop function test_signal_func $$ drop function test_signal_func $$
create function test_signal_func() returns integer create function test_signal_func() returns integer
begin begin
......
This diff is collapsed.
...@@ -1551,15 +1551,24 @@ drop procedure test_signal $$ ...@@ -1551,15 +1551,24 @@ drop procedure test_signal $$
--echo # Test where SIGNAL can be used --echo # Test where SIGNAL can be used
--echo # --echo #
--echo
--echo # RETURN statement clears Diagnostics Area, thus
--echo # the warnings raised in a stored function are not
--echo # visible outsidef the stored function. So, we're using
--echo # @@warning_count variable to check that SIGNAL succeeded.
--echo
create function test_signal_func() returns integer create function test_signal_func() returns integer
begin begin
DECLARE v INT;
DECLARE warn CONDITION FOR SQLSTATE "01XXX"; DECLARE warn CONDITION FOR SQLSTATE "01XXX";
SIGNAL warn SET SIGNAL warn SET
MESSAGE_TEXT = "This function SIGNAL a warning", MESSAGE_TEXT = "This function SIGNAL a warning",
MYSQL_ERRNO = 1012; MYSQL_ERRNO = 1012;
return 5; SELECT @@warning_count INTO v;
return v;
end $$ end $$
select test_signal_func() $$ select test_signal_func() $$
......
This diff is collapsed.
...@@ -3390,6 +3390,14 @@ sp_instr_freturn::execute(THD *thd, uint *nextp) ...@@ -3390,6 +3390,14 @@ sp_instr_freturn::execute(THD *thd, uint *nextp)
int int
sp_instr_freturn::exec_core(THD *thd, uint *nextp) sp_instr_freturn::exec_core(THD *thd, uint *nextp)
{ {
/*
RETURN is a "procedure statement" (in terms of the SQL standard).
That means, Diagnostics Area should be clean before its execution.
*/
Diagnostics_area *da= thd->get_stmt_da();
da->clear_warning_info(da->warning_info_id());
/* /*
Change <next instruction pointer>, so that this will be the last Change <next instruction pointer>, so that this will be the last
instruction in the stored function. instruction in the stored function.
......
...@@ -233,6 +233,23 @@ bool sp_rcontext::handle_sql_condition(THD *thd, ...@@ -233,6 +233,23 @@ bool sp_rcontext::handle_sql_condition(THD *thd,
if (found_handler) if (found_handler)
found_condition= da->get_error_condition(); found_condition= da->get_error_condition();
/*
Found condition can be NULL if the diagnostics area was full
when the error was raised. It can also be NULL if
Diagnostics_area::set_error_status(uint sql_error) was used.
In these cases, make a temporary Sql_condition here so the
error can be handled.
*/
if (!found_condition)
{
Sql_condition *condition=
new (callers_arena->mem_root) Sql_condition(callers_arena->mem_root);
condition->set(da->sql_errno(), da->get_sqlstate(),
Sql_condition::WARN_LEVEL_ERROR,
da->message());
found_condition= condition;
}
} }
else if (da->current_statement_warn_count()) else if (da->current_statement_warn_count())
{ {
......
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