From: Alexander Nozdrin Date: October 31 2011 11:55am Subject: bzr push into mysql-trunk branch (alexander.nozdrin:3538 to 3539) Bug#12652873 List-Archive: http://lists.mysql.com/commits/141673 X-Bug: 12652873 Message-Id: <201110311155.p9VBtUna022553@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3539 Alexander Nozdrin 2011-10-31 Fix for Bug#12652873 - 61392: CONTINUE HANDLER FOR NOT FOUND BEING TRIGGERED FROM INTERNAL STORED FUNCTION. The problem was that RETURN statement in stored programs did not clear the Diagnostics Area, as it should have done according to the SQL Standard. The user-visible problem was that in some cases an SQL-condition, raised in the nested function call, would be visible in the outer scope, which in turn would lead to incorrect handler activation. The fix is to clear the Diagnostics Area before executing RETURN statement. Note, that after the patch, there is no way to throw an SQL-warning out of a stored function. From the user's view point, he/she will not get any warning, even if there were warnings, raised during the function execution. This change is backward incompatible, but it makes the behaviour of stored programs more in line with The Standard. modified: mysql-test/r/func_rollback.result mysql-test/r/signal.result mysql-test/r/sp-error.result mysql-test/r/sp.result mysql-test/r/view_grant.result mysql-test/suite/funcs_1/r/storedproc.result mysql-test/t/signal.test mysql-test/t/sp-error.test sql/sp_head.cc 3538 Tor Didriksen 2011-10-31 [merge] empty merge 5.5 => trunk === modified file 'mysql-test/r/func_rollback.result' --- a/mysql-test/r/func_rollback.result 2011-02-21 02:57:30 +0000 +++ b/mysql-test/r/func_rollback.result 2011-10-31 11:52:20 +0000 @@ -190,8 +190,6 @@ END; SELECT f1_insert_select(2); f1_insert_select(2) 1 -Warnings: -Warning 1048 Column 'f2' cannot be null SELECT * FROM t1_not_null ORDER BY f1,f2; f1 f2 2 0 @@ -267,8 +265,6 @@ END; SELECT f1_insert_with_two_rows(); f1_insert_with_two_rows() 1 -Warnings: -Warning 1048 Column 'f2' cannot be null SELECT * FROM t1_not_null ORDER BY f1,f2; f1 f2 10 0 === modified file 'mysql-test/r/signal.result' --- a/mysql-test/r/signal.result 2011-09-20 12:13:07 +0000 +++ b/mysql-test/r/signal.result 2011-10-31 11:52:20 +0000 @@ -1313,19 +1313,25 @@ drop procedure test_signal $$ # # 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 begin +DECLARE v INT; DECLARE warn CONDITION FOR SQLSTATE "01XXX"; SIGNAL warn SET MESSAGE_TEXT = "This function SIGNAL a warning", MYSQL_ERRNO = 1012; -return 5; +SELECT @@warning_count INTO v; +return v; end $$ select test_signal_func() $$ test_signal_func() -5 -Warnings: -Warning 1012 This function SIGNAL a warning +1 drop function test_signal_func $$ create function test_signal_func() returns integer begin === modified file 'mysql-test/r/sp-error.result' --- a/mysql-test/r/sp-error.result 2011-10-27 09:26:31 +0000 +++ b/mysql-test/r/sp-error.result 2011-10-31 11:52:20 +0000 @@ -2846,3 +2846,50 @@ CALL p2(); SET SESSION max_error_count= @old_max_error_count; DROP PROCEDURE p1; DROP PROCEDURE p2; + +# Bug#12652873: 61392: Continue handler for NOT FOUND being triggered +# from internal stored function. + +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP TABLE IF EXISTS t1; + +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1, 2); + +# f1() raises NOT_FOUND condition. +# Raising NOT_FOUND can not be simulated by SIGNAL, +# because SIGNAL would raise SQL-error in that case. + +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN +DECLARE v VARCHAR(5) DEFAULT -1; +SELECT b FROM t1 WHERE a = 2 INTO v; +RETURN v; +END| + +# Here we check that the NOT_FOUND condition raised in f1() +# is not visible in the outer function (f2), i.e. the continue +# handler in f2() will not be called. + +CREATE FUNCTION f2() RETURNS INTEGER +BEGIN +DECLARE v INTEGER; +DECLARE CONTINUE HANDLER FOR NOT FOUND +SET @msg = 'Handler activated.'; +SELECT f1() INTO v; +RETURN v; +END| +SET @msg = ''; + +SELECT f2(); +f2() +-1 + +SELECT @msg; +@msg + + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP TABLE t1; === modified file 'mysql-test/r/sp.result' --- a/mysql-test/r/sp.result 2011-10-14 15:38:24 +0000 +++ b/mysql-test/r/sp.result 2011-10-31 11:52:20 +0000 @@ -5425,13 +5425,9 @@ end| select func_20028_a()| func_20028_a() 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select func_20028_b()| func_20028_b() 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select func_20028_c()| ERROR 22012: Division by 0 call proc_20028_a()| @@ -5484,13 +5480,9 @@ end| select func_20028_a()| func_20028_a() 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select func_20028_b()| func_20028_b() 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select func_20028_c()| func_20028_c() NULL @@ -6110,8 +6102,6 @@ END| SELECT bug5274_f2()| bug5274_f2() x -Warnings: -Warning 1265 Data truncated for column 'bug5274_f1' at row 1 DROP FUNCTION bug5274_f1| DROP FUNCTION bug5274_f2| drop procedure if exists proc_21513| @@ -6204,19 +6194,13 @@ c1 SELECT f1(2); f1(2) 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed PREPARE s1 FROM 'SELECT f1(2)'; EXECUTE s1; f1(2) 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed EXECUTE s1; f1(2) 0 -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed DROP PROCEDURE p1; DROP PROCEDURE p2; DROP FUNCTION f1; === modified file 'mysql-test/r/view_grant.result' --- a/mysql-test/r/view_grant.result 2011-09-14 15:03:55 +0000 +++ b/mysql-test/r/view_grant.result 2011-10-31 11:52:20 +0000 @@ -341,13 +341,9 @@ use mysqltest; select * from v1; f2() NULL -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select * from v2; f2() NULL -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select * from v3; ERROR HY000: View 'mysqltest.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them select * from v4; @@ -387,13 +383,9 @@ ERROR HY000: View 'mysqltest.v2' referen select * from v3; f2() NULL -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select * from v4; f2() NULL -Warnings: -Warning 1329 No data - zero rows fetched, selected, or processed select * from v5; ERROR HY000: View 'mysqltest.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them drop view v1, v2, v3, v4, v5; === modified file 'mysql-test/suite/funcs_1/r/storedproc.result' --- a/mysql-test/suite/funcs_1/r/storedproc.result 2011-09-20 12:13:07 +0000 +++ b/mysql-test/suite/funcs_1/r/storedproc.result 2011-10-31 11:52:20 +0000 @@ -16344,7 +16344,6 @@ fn7(99999999999) 9999999999 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn8; CREATE FUNCTION fn8( f1 decimal (0) unsigned zerofill) returns decimal (0) unsigned zerofill BEGIN @@ -16354,8 +16353,6 @@ END// SELECT fn8(999999999); fn8(999999999) 1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn9; CREATE FUNCTION fn9( f1 decimal (0) zerofill) returns decimal (0) zerofill BEGIN @@ -16367,7 +16364,6 @@ fn9(-1.00e+09) 0000000010 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn10; CREATE FUNCTION fn10( f1 decimal (0, 0)) returns decimal (0, 0) BEGIN @@ -16388,7 +16384,6 @@ fn11(99999999999) 9999999999 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn12; CREATE FUNCTION fn12( f1 decimal (0, 0) unsigned zerofill) returns decimal (0, 0) unsigned zerofill BEGIN @@ -16398,8 +16393,6 @@ END// SELECT fn12(999999999); fn12(999999999) 1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn13; CREATE FUNCTION fn13( f1 decimal (0, 0) zerofill) returns decimal (0, 0) zerofill BEGIN @@ -16411,7 +16404,6 @@ fn13(-1.00e+09) 0000000010 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn14; CREATE FUNCTION fn14( f1 decimal (63, 30)) returns decimal (63, 30) BEGIN @@ -16450,7 +16442,6 @@ fn17(-1.00e+21) 000000000000000000000000000000010.000000000000000000000000000000 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn18_d; CREATE FUNCTION fn18_d( f1 decimal (64)) returns decimal (64) BEGIN @@ -16487,8 +16478,6 @@ END// SELECT fn21_d_z(1.00e+00); fn21_d_z(1.00e+00) 0000000000000000000000000000000000000000000000000000000000000010 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn22; CREATE FUNCTION fn22( f1 decimal unsigned) returns decimal unsigned BEGIN @@ -16498,8 +16487,6 @@ END// SELECT fn22(1.00e+00); fn22(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn23; CREATE FUNCTION fn23( f1 decimal unsigned zerofill) returns decimal unsigned zerofill BEGIN @@ -16509,8 +16496,6 @@ END// SELECT fn23(1.00e+00); fn23(1.00e+00) 0000000010 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn24; CREATE FUNCTION fn24( f1 decimal zerofill) returns decimal zerofill BEGIN @@ -16522,7 +16507,6 @@ fn24(-1.00e+09) 0000000010 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn25; CREATE FUNCTION fn25( f1 double) returns double BEGIN @@ -16541,8 +16525,6 @@ END// SELECT fn26(1.00e+00); fn26(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn27; CREATE FUNCTION fn27( f1 double unsigned zerofill) returns double unsigned zerofill BEGIN @@ -16552,8 +16534,6 @@ END// SELECT fn27(1.00e+00); fn27(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn28; CREATE FUNCTION fn28( f1 double zerofill) returns double zerofill BEGIN @@ -16563,8 +16543,6 @@ END// SELECT fn28(1.00e+00); fn28(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn29; CREATE FUNCTION fn29( f1 float) returns float BEGIN @@ -16583,8 +16561,6 @@ END// SELECT fn30(1.00e+00); fn30(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn31; CREATE FUNCTION fn31( f1 float unsigned zerofill) returns float unsigned zerofill BEGIN @@ -16594,8 +16570,6 @@ END// SELECT fn31(1.00e+00); fn31(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn32; CREATE FUNCTION fn32( f1 float zerofill) returns float zerofill BEGIN @@ -16605,8 +16579,6 @@ END// SELECT fn32(1.00e+00); fn32(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn33; CREATE FUNCTION fn33( f1 float(0)) returns float(0) BEGIN @@ -16625,8 +16597,6 @@ END// SELECT fn34(1.00e+00); fn34(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn35; CREATE FUNCTION fn35( f1 float(0) unsigned zerofill) returns float(0) unsigned zerofill BEGIN @@ -16636,8 +16606,6 @@ END// SELECT fn35(1.00e+00); fn35(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn36; CREATE FUNCTION fn36( f1 float(0) zerofill) returns float(0) zerofill BEGIN @@ -16647,8 +16615,6 @@ END// SELECT fn36(1.00e+00); fn36(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn37; CREATE FUNCTION fn37( f1 float(23)) returns float(23) BEGIN @@ -16667,8 +16633,6 @@ END// SELECT fn38(1.00e+00); fn38(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn39; CREATE FUNCTION fn39( f1 float(23) unsigned zerofill) returns float(23) unsigned zerofill BEGIN @@ -16678,8 +16642,6 @@ END// SELECT fn39(1.00e+00); fn39(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn40; CREATE FUNCTION fn40( f1 float(23) zerofill) returns float(23) zerofill BEGIN @@ -16689,8 +16651,6 @@ END// SELECT fn40(1.00e+00); fn40(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn41; CREATE FUNCTION fn41( f1 float(24)) returns float(24) BEGIN @@ -16709,8 +16669,6 @@ END// SELECT fn42(1.00e+00); fn42(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn43; CREATE FUNCTION fn43( f1 float(24) unsigned zerofill) returns float(24) unsigned zerofill BEGIN @@ -16720,8 +16678,6 @@ END// SELECT fn43(1.00e+00); fn43(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn44; CREATE FUNCTION fn44( f1 float(24) zerofill) returns float(24) zerofill BEGIN @@ -16731,8 +16687,6 @@ END// SELECT fn44(1.00e+00); fn44(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn45; CREATE FUNCTION fn45( f1 float(53)) returns float(53) BEGIN @@ -16751,8 +16705,6 @@ END// SELECT fn46(1.00e+00); fn46(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn47; CREATE FUNCTION fn47( f1 float(53) unsigned zerofill) returns float(53) unsigned zerofill BEGIN @@ -16762,8 +16714,6 @@ END// SELECT fn47(1.00e+00); fn47(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn48; CREATE FUNCTION fn48( f1 float(53) zerofill) returns float(53) zerofill BEGIN @@ -16773,8 +16723,6 @@ END// SELECT fn48(1.00e+00); fn48(1.00e+00) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn49; CREATE FUNCTION fn49( f1 int) returns int BEGIN @@ -16786,7 +16734,6 @@ fn49(-2.15e+09) -2147483638 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn50; CREATE FUNCTION fn50( f1 int unsigned) returns int unsigned BEGIN @@ -16823,8 +16770,6 @@ END// SELECT fn53(-8388600); fn53(-8388600) -8388598 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn54; CREATE FUNCTION fn54( f1 mediumint unsigned) returns mediumint unsigned BEGIN @@ -16860,8 +16805,6 @@ END// SELECT fn57(-999999999); fn57(-999999999) -1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn58; CREATE FUNCTION fn58( f1 numeric (0)) returns numeric (0) BEGIN @@ -16871,8 +16814,6 @@ END// SELECT fn58(-999999999); fn58(-999999999) -1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn59; CREATE FUNCTION fn59( f1 numeric (0) unsigned) returns numeric (0) unsigned BEGIN @@ -16882,8 +16823,6 @@ END// SELECT fn59(9999999999); fn59(9999999999) 9999999999 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn60; CREATE FUNCTION fn60( f1 numeric (0) unsigned zerofill) returns numeric (0) unsigned zerofill BEGIN @@ -16893,8 +16832,6 @@ END// SELECT fn60(99999999); fn60(99999999) 0100000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn61; CREATE FUNCTION fn61( f1 numeric (0) zerofill) returns numeric (0) zerofill BEGIN @@ -16906,7 +16843,6 @@ fn61(-99999999) 0000000010 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn62; CREATE FUNCTION fn62( f1 numeric (0, 0)) returns numeric (0, 0) BEGIN @@ -16916,8 +16852,6 @@ END// SELECT fn62(-999999999); fn62(-999999999) -1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn63; CREATE FUNCTION fn63( f1 numeric (0, 0) unsigned) returns numeric (0, 0) unsigned BEGIN @@ -16927,8 +16861,6 @@ END// SELECT fn63(9999999999); fn63(9999999999) 9999999999 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn64; CREATE FUNCTION fn64( f1 numeric (0, 0) unsigned zerofill) returns numeric (0, 0) unsigned zerofill BEGIN @@ -16938,8 +16870,6 @@ END// SELECT fn64(99999999); fn64(99999999) 0100000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn65; CREATE FUNCTION fn65( f1 numeric (0, 0) zerofill) returns numeric (0, 0) zerofill BEGIN @@ -16951,7 +16881,6 @@ fn65(-99999999) 0000000010 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn66; CREATE FUNCTION fn66( f1 numeric (63, 30)) returns numeric (63, 30) BEGIN @@ -16963,7 +16892,6 @@ fn66(-1e+36) -999999999999999999999999999999989.999999999999999999999999999999 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn67; CREATE FUNCTION fn67( f1 numeric (63, 30) unsigned) returns numeric (63, 30) unsigned BEGIN @@ -16975,7 +16903,6 @@ fn67(1e+36) 999999999999999999999999999999999.999999999999999999999999999999 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn68; CREATE FUNCTION fn68( f1 numeric (63, 30) unsigned zerofill) returns numeric (63, 30) unsigned zerofill BEGIN @@ -16987,7 +16914,6 @@ fn68(1e+36) 999999999999999999999999999999999.999999999999999999999999999999 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn69; CREATE FUNCTION fn69( f1 numeric (63, 30) zerofill) returns numeric (63, 30) zerofill BEGIN @@ -16999,7 +16925,6 @@ fn69(-1e+36) 000000000000000000000000000000010.000000000000000000000000000000 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn70_n; CREATE FUNCTION fn70_n( f1 numeric (64)) returns numeric (64) BEGIN @@ -17048,8 +16973,6 @@ END// SELECT fn74(999999999); fn74(999999999) 1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn75; CREATE FUNCTION fn75( f1 numeric unsigned zerofill) returns numeric unsigned zerofill BEGIN @@ -17059,8 +16982,6 @@ END// SELECT fn75(999999999); fn75(999999999) 1000000000 -Warnings: -Note 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn76; CREATE FUNCTION fn76( f1 numeric zerofill) returns numeric zerofill BEGIN @@ -17072,7 +16993,6 @@ fn76(-999999999) 0000000010 Warnings: Warning 1264 Out of range value for column 'f1' at row 1 -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn77; CREATE FUNCTION fn77( f1 real) returns real BEGIN @@ -17091,8 +17011,6 @@ END// SELECT fn78(1.1); fn78(1.1) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn79; CREATE FUNCTION fn79( f1 real unsigned zerofill) returns real unsigned zerofill BEGIN @@ -17102,8 +17020,6 @@ END// SELECT fn79(1.1); fn79(1.1) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn80; CREATE FUNCTION fn80( f1 real zerofill) returns real zerofill BEGIN @@ -17113,8 +17029,6 @@ END// SELECT fn80(1.1); fn80(1.1) 10 -Warnings: -Warning 1264 Out of range value for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn81; CREATE FUNCTION fn81( f1 smallint) returns smallint BEGIN @@ -17247,8 +17161,6 @@ END// SELECT fn94( 'h'); fn94( 'h') a -Warnings: -Warning 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn95; CREATE FUNCTION fn95( f1 char ascii) returns char ascii BEGIN @@ -17258,8 +17170,6 @@ END// SELECT fn95('h'); fn95('h') a -Warnings: -Warning 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn96; CREATE FUNCTION fn96( f1 binary) returns binary(2) BEGIN @@ -17269,8 +17179,6 @@ END// SELECT fn96( 'h'); fn96( 'h') a -Warnings: -Warning 1265 Data truncated for column 'f1' at row 1 DROP FUNCTION IF EXISTS fn97; CREATE FUNCTION fn97( f1 longtext) returns longtext BEGIN === modified file 'mysql-test/t/signal.test' --- a/mysql-test/t/signal.test 2011-10-19 21:44:17 +0000 +++ b/mysql-test/t/signal.test 2011-10-31 11:52:20 +0000 @@ -1548,15 +1548,24 @@ drop procedure test_signal $$ --echo # Test where SIGNAL can be used --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 begin + DECLARE v INT; DECLARE warn CONDITION FOR SQLSTATE "01XXX"; SIGNAL warn SET MESSAGE_TEXT = "This function SIGNAL a warning", MYSQL_ERRNO = 1012; - return 5; + SELECT @@warning_count INTO v; + return v; end $$ select test_signal_func() $$ === modified file 'mysql-test/t/sp-error.test' --- a/mysql-test/t/sp-error.test 2011-10-27 09:26:31 +0000 +++ b/mysql-test/t/sp-error.test 2011-10-31 11:52:20 +0000 @@ -3811,3 +3811,66 @@ SET SESSION max_error_count= @old_max_er DROP PROCEDURE p1; DROP PROCEDURE p2; + +--echo +--echo # Bug#12652873: 61392: Continue handler for NOT FOUND being triggered +--echo # from internal stored function. +--echo + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP TABLE IF EXISTS t1; +--enable_warnings + +--echo + +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1, 2); + +delimiter |; + +--echo +--echo # f1() raises NOT_FOUND condition. +--echo # Raising NOT_FOUND can not be simulated by SIGNAL, +--echo # because SIGNAL would raise SQL-error in that case. +--echo + +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN + DECLARE v VARCHAR(5) DEFAULT -1; + SELECT b FROM t1 WHERE a = 2 INTO v; + RETURN v; +END| + +--echo +--echo # Here we check that the NOT_FOUND condition raised in f1() +--echo # is not visible in the outer function (f2), i.e. the continue +--echo # handler in f2() will not be called. +--echo + +CREATE FUNCTION f2() RETURNS INTEGER +BEGIN + DECLARE v INTEGER; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET @msg = 'Handler activated.'; + + SELECT f1() INTO v; + + RETURN v; +END| + +delimiter ;| + +SET @msg = ''; + +--echo +SELECT f2(); +--echo +SELECT @msg; +--echo + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP TABLE t1; === modified file 'sql/sp_head.cc' --- a/sql/sp_head.cc 2011-10-27 12:13:46 +0000 +++ b/sql/sp_head.cc 2011-10-31 11:52:20 +0000 @@ -3398,6 +3398,14 @@ int 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 , so that this will be the last instruction in the stored function. */ No bundle (reason: useless for push emails).