Commit de6d4059 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10411 Providing compatibility for basic PL/SQL constructs

An additional change for "Part 9: EXCEPTION handlers"

This construct:
  EXCEPTION WHEN OTHERS THEN ...;
now catches warning-alike conditions, e.g. NO_DATA_FOUND.
parent f7043858
......@@ -199,5 +199,24 @@ ERROR 24000: Cursor is not open
DROP PROCEDURE p1;
DROP TABLE t1;
#
# Testing that warning-alike errors are caught by OTHERS
#
CREATE TABLE t1 (a INT);
CREATE FUNCTION f1 RETURN VARCHAR
AS
a INT:=10;
BEGIN
SELECT a INTO a FROM t1;
RETURN 'OK';
EXCEPTION
WHEN OTHERS THEN RETURN 'Exception';
END;
$$
SELECT f1() FROM DUAL;
f1()
Exception
DROP FUNCTION f1;
DROP TABLE t1;
#
# End of MDEV-10840 sql_mode=ORACLE: RAISE statement for predefined exceptions
#
......@@ -239,6 +239,27 @@ CALL p1();
DROP PROCEDURE p1;
DROP TABLE t1;
--echo #
--echo # Testing that warning-alike errors are caught by OTHERS
--echo #
CREATE TABLE t1 (a INT);
DELIMITER $$;
CREATE FUNCTION f1 RETURN VARCHAR
AS
a INT:=10;
BEGIN
SELECT a INTO a FROM t1;
RETURN 'OK';
EXCEPTION
WHEN OTHERS THEN RETURN 'Exception';
END;
$$
DELIMITER ;$$
SELECT f1() FROM DUAL;
DROP FUNCTION f1;
DROP TABLE t1;
--echo #
--echo # End of MDEV-10840 sql_mode=ORACLE: RAISE statement for predefined exceptions
......
......@@ -410,8 +410,16 @@ sp_pcontext::find_handler(const char *sql_state,
break;
case sp_condition_value::EXCEPTION:
if (is_sqlstate_exception(sql_state) &&
level == Sql_condition::WARN_LEVEL_ERROR && !found_cv)
/*
In sql_mode=ORACLE this construct should catch errors and warnings:
EXCEPTION
WHEN OTHERS THEN ...;
E.g. NO_DATA_FOUND is more like a warning than an error,
and it should be caught.
*/
if (((current_thd->variables.sql_mode & MODE_ORACLE) ||
(is_sqlstate_exception(sql_state) &&
level == Sql_condition::WARN_LEVEL_ERROR)) && !found_cv)
{
found_cv= cv;
found_handler= h;
......
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