Skip to content

Commit

Permalink
MDEV-33428 Error messages ER_PACKAGE_ROUTINE_* are not good enough
Browse files Browse the repository at this point in the history
Changing the format in error messages:
- ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
- ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED

from
  "Subroutine 'db.pkg.f1' ..."

to a more clear:
  "FUNCTION `db.pkg.f1` ..."
  "PROCEDURE `db.pkg.p1` ..."
  • Loading branch information
abarkov committed Feb 8, 2024
1 parent 9b1ea69 commit 9500575
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 14 deletions.
72 changes: 72 additions & 0 deletions mysql-test/main/sp-package.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#
# Start of 11.4 tests
#
SET sql_mode='';
CREATE OR REPLACE PACKAGE pkg
PROCEDURE p1();
Expand Down Expand Up @@ -49,3 +52,72 @@ SELECT pkg.f1();
pkg.f1()
1
DROP PACKAGE pkg;
#
# MDEV-33428 Error messages ER_PACKAGE_ROUTINE_* are not good enough
#
#
# Routines declared in CREATE PACKAGE missing in CREATE PACKAGE BODY
#
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
CREATE PACKAGE BODY test2
PROCEDURE p2() BEGIN SELECT 0; END;
END;
$$
ERROR HY000: PROCEDURE `test.test2.p1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
CREATE PACKAGE test2
FUNCTION f1() RETURNS INT;
END;
$$
CREATE PACKAGE BODY test2
FUNCTION f2() RETURNS INT BEGIN RETURN 10; END;
END;
$$
ERROR HY000: FUNCTION `test.test2.f1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
CREATE PACKAGE BODY test2
FUNCTION p1() RETURNS INT BEGIN RETURN 10; END;
END;
$$
ERROR HY000: PROCEDURE `test.test2.p1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
CREATE PACKAGE BODY test2
PROCEDURE p1(a INT) BEGIN SELECT 0; END; -- Notice different prototype
END;
$$
ERROR HY000: PROCEDURE `test.test2.p1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
#
# Forward declarations in CREATE PACKAGE BODY with missing implementations
#
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
CREATE PACKAGE BODY test2
PROCEDURE p1() BEGIN SELECT 0; END;
PROCEDURE p2();
END;
$$
ERROR HY000: PROCEDURE `test.test2.p2` has a forward declaration but is not defined
CREATE PACKAGE BODY test2
FUNCTION f1() RETURNS INT;
PROCEDURE p1() BEGIN SELECT 0; END;
END;
$$
ERROR HY000: FUNCTION `test.test2.f1` has a forward declaration but is not defined
DROP PACKAGE test2;
#
# End of 11.4 tests
#
94 changes: 94 additions & 0 deletions mysql-test/main/sp-package.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
--echo #
--echo # Start of 11.4 tests
--echo #

#
# CREATE PACKAGE for sql_mode='';
# Resebmles SQL Standard 'CREATE MODULE'.
Expand Down Expand Up @@ -44,3 +48,93 @@ CALL pkg.p1();
SELECT pkg.f1();

DROP PACKAGE pkg;


--echo #
--echo # MDEV-33428 Error messages ER_PACKAGE_ROUTINE_* are not good enough
--echo #

--echo #
--echo # Routines declared in CREATE PACKAGE missing in CREATE PACKAGE BODY
--echo #

DELIMITER $$;
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
CREATE PACKAGE BODY test2
PROCEDURE p2() BEGIN SELECT 0; END;
END;
$$
DELIMITER ;$$
DROP PACKAGE test2;

DELIMITER $$;
CREATE PACKAGE test2
FUNCTION f1() RETURNS INT;
END;
$$
--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
CREATE PACKAGE BODY test2
FUNCTION f2() RETURNS INT BEGIN RETURN 10; END;
END;
$$
DELIMITER ;$$
DROP PACKAGE test2;

DELIMITER $$;
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
CREATE PACKAGE BODY test2
FUNCTION p1() RETURNS INT BEGIN RETURN 10; END;
END;
$$
DELIMITER ;$$
DROP PACKAGE test2;

DELIMITER $$;
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
CREATE PACKAGE BODY test2
PROCEDURE p1(a INT) BEGIN SELECT 0; END; -- Notice different prototype
END;
$$
DELIMITER ;$$
DROP PACKAGE test2;

--echo #
--echo # Forward declarations in CREATE PACKAGE BODY with missing implementations
--echo #

DELIMITER $$;
CREATE PACKAGE test2
PROCEDURE p1();
END;
$$
--error ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED
CREATE PACKAGE BODY test2
PROCEDURE p1() BEGIN SELECT 0; END;
PROCEDURE p2();
END;
$$
--error ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED
CREATE PACKAGE BODY test2
FUNCTION f1() RETURNS INT;
PROCEDURE p1() BEGIN SELECT 0; END;
END;
$$
DELIMITER ;$$
DROP PACKAGE test2;


--echo #
--echo # End of 11.4 tests
--echo #
12 changes: 6 additions & 6 deletions mysql-test/suite/compat/oracle/r/sp-package.result
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ CREATE PACKAGE BODY test2 AS
PROCEDURE p2 AS BEGIN NULL; END;
END;
$$
ERROR HY000: Subroutine 'test.test2.p1' is declared in the package specification but is not defined in the package body
ERROR HY000: PROCEDURE `test.test2.p1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
CREATE PACKAGE test2 AS
FUNCTION f1 RETURN INT;
Expand All @@ -454,7 +454,7 @@ CREATE PACKAGE BODY test2 AS
FUNCTION f2 RETURN INT AS BEGIN RETURN 10; END;
END;
$$
ERROR HY000: Subroutine 'test.test2.f1' is declared in the package specification but is not defined in the package body
ERROR HY000: FUNCTION `test.test2.f1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
CREATE PACKAGE test2 AS
PROCEDURE p1;
Expand All @@ -464,7 +464,7 @@ CREATE PACKAGE BODY test2 AS
FUNCTION p1 RETURN INT AS BEGIN RETURN 10; END;
END;
$$
ERROR HY000: Subroutine 'test.test2.p1' is declared in the package specification but is not defined in the package body
ERROR HY000: PROCEDURE `test.test2.p1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
CREATE PACKAGE test2 AS
PROCEDURE p1;
Expand All @@ -474,7 +474,7 @@ CREATE PACKAGE BODY test2 AS
PROCEDURE p1(a INT) AS BEGIN NULL; END; -- Notice different prototype
END;
$$
ERROR HY000: Subroutine 'test.test2.p1' is declared in the package specification but is not defined in the package body
ERROR HY000: PROCEDURE `test.test2.p1` is declared in the package specification but is not defined in the package body
DROP PACKAGE test2;
#
# Forward declarations in CREATE PACKAGE BODY with missing implementations
Expand All @@ -488,13 +488,13 @@ PROCEDURE p1 AS BEGIN NULL; END;
PROCEDURE p2;
END;
$$
ERROR HY000: Subroutine 'test.test2.p2' has a forward declaration but is not defined
ERROR HY000: PROCEDURE `test.test2.p2` has a forward declaration but is not defined
CREATE PACKAGE BODY test2 AS
FUNCTION f1 RETURN INT;
PROCEDURE p1 AS BEGIN NULL; END;
END;
$$
ERROR HY000: Subroutine 'test.test2.f1' has a forward declaration but is not defined
ERROR HY000: FUNCTION `test.test2.f1` has a forward declaration but is not defined
DROP PACKAGE test2;
#
# Creating a new package
Expand Down
16 changes: 8 additions & 8 deletions sql/share/errmsg-utf8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11782,15 +11782,15 @@ ER_SP_STACK_TRACE
spa "En la línea %u en %s"
sw "Kwenye mstari %u katika %s"
ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
chi "在包规范中声明子程序'%-.192s',但未在包主体中定义"
eng "Subroutine '%-.192s' is declared in the package specification but is not defined in the package body"
spa "La subrutina '%-.192s' está declarada en la especificación del paquete pero no está definida en el cuerpo del paquete"
sw "Utaratibu mdogo '%-.192s' umetangazwa katika ubainisho wa kifurushi lakini haijafafanuliwa kwenye mwili wa kifurushi"
chi "在包规范中声明子程序%s %`s,但未在包主体中定义"
eng "%s %`s is declared in the package specification but is not defined in the package body"
spa "La %s %`s está declarada en la especificación del paquete pero no está definida en el cuerpo del paquete"
sw "Utaratibu mdogo %s %`s umetangazwa katika ubainisho wa kifurushi lakini haijafafanuliwa kwenye mwili wa kifurushi"
ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED
chi "子程序'%-.192s'具有前向声明但未定义"
eng "Subroutine '%-.192s' has a forward declaration but is not defined"
spa "La subrutina '%-.192s' tiene una declaración adelantada pero no está definida"
sw "Utaratibu mdogo '%-.192s' una tamko la mbele lakini haijafafanuliwa"
chi "子程序%s %`s 具有前向声明但未定义"
eng "%s %`s has a forward declaration but is not defined"
spa "La %s %`s tiene una declaración adelantada pero no está definida"
sw "Utaratibu mdogo %s %`s una tamko la mbele lakini haijafafanuliwa"
ER_COMPRESSED_COLUMN_USED_AS_KEY
chi "压缩列'%-.192s'不能用于索引规范"
eng "Compressed column '%-.192s' can't be used in key specification"
Expand Down
2 changes: 2 additions & 0 deletions sql/sp_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ bool sp_package::validate_public_routines(THD *thd, sp_package *spec)
if (!found)
{
my_error(ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY, MYF(0),
lex->sphead->m_handler->type_str(),
ErrConvDQName(lex->sphead).ptr());
return true;
}
Expand Down Expand Up @@ -742,6 +743,7 @@ bool sp_package::validate_private_routines(THD *thd)
if (!found)
{
my_error(ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED, MYF(0),
lex->sphead->m_handler->type_str(),
ErrConvDQName(lex->sphead).ptr());
return true;
}
Expand Down

0 comments on commit 9500575

Please sign in to comment.