Skip to content

Commit

Permalink
MDEV-33386 Wrong error message on `GRANT .. ON PACKAGE no_such_packag…
Browse files Browse the repository at this point in the history
…e ..`

When displaying the ER_SP_DOES_NOT_EXIST error, use
Sp_handler::type_lex_cstring() to the the underlying
object type:
- PROCEDURE
- FUNCTION
- PACKAGE
- PACKAGE BODY
instead of hard-coded "FUNCTION or PROCEDURE".
  • Loading branch information
abarkov committed Feb 5, 2024
1 parent 2e83ab4 commit e30e9fc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions mysql-test/main/grant.result
Original file line number Diff line number Diff line change
Expand Up @@ -2662,9 +2662,9 @@ create database mysqltest_db1;
create user mysqltest_u1;
# Both GRANT statements below should fail with the same error.
grant execute on function mysqltest_db1.f1 to mysqltest_u1;
ERROR 42000: FUNCTION or PROCEDURE f1 does not exist
ERROR 42000: FUNCTION f1 does not exist
grant execute on procedure mysqltest_db1.p1 to mysqltest_u1;
ERROR 42000: FUNCTION or PROCEDURE p1 does not exist
ERROR 42000: PROCEDURE p1 does not exist
# Let us show that GRANT behaviour for routines is consistent
# with GRANT behaviour for tables. Attempt to grant privilege
# on non-existent table also results in an error.
Expand Down
13 changes: 13 additions & 0 deletions mysql-test/main/sp-package-security.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#
# Start of 11.4 tests
#
CREATE DATABASE db1;
CREATE USER u1@localhost IDENTIFIED BY '';
GRANT SELECT ON db1.* TO u1@localhost;
Expand Down Expand Up @@ -307,3 +310,13 @@ SESSION_USER() CURRENT_USER() msg
root@localhost root@localhost p1.p1
DROP PACKAGE p1;
DROP USER xxx@localhost;
#
# MDEV-33386 Wrong error message on `GRANT .. ON PACKAGE no_such_package ..`
#
GRANT EXECUTE ON PACKAGE no_such_package TO PUBLIC;
ERROR 42000: PACKAGE no_such_package does not exist
GRANT EXECUTE ON PACKAGE BODY no_such_package TO PUBLIC;
ERROR 42000: PACKAGE BODY no_such_package does not exist
#
# End of 11.4 tests
#
18 changes: 18 additions & 0 deletions mysql-test/main/sp-package-security.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
--source include/not_embedded.inc
--source include/default_charset.inc

--echo #
--echo # Start of 11.4 tests
--echo #

CREATE DATABASE db1;
CREATE USER u1@localhost IDENTIFIED BY '';
GRANT SELECT ON db1.* TO u1@localhost;
Expand Down Expand Up @@ -320,3 +324,17 @@ DELIMITER ;$$
CALL p1.p1;
DROP PACKAGE p1;
DROP USER xxx@localhost;


--echo #
--echo # MDEV-33386 Wrong error message on `GRANT .. ON PACKAGE no_such_package ..`
--echo #

--error ER_SP_DOES_NOT_EXIST
GRANT EXECUTE ON PACKAGE no_such_package TO PUBLIC;
--error ER_SP_DOES_NOT_EXIST
GRANT EXECUTE ON PACKAGE BODY no_such_package TO PUBLIC;

--echo #
--echo # End of 11.4 tests
--echo #
2 changes: 1 addition & 1 deletion sql/sp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ Sp_handler::sp_exist_routines(THD *thd, TABLE_LIST *routines) const
thd->get_stmt_da()->clear_warning_info(thd->query_id);
if (! sp_object_found)
{
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE",
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), type_lex_cstring().str,
routine->table_name.str);
DBUG_RETURN(TRUE);
}
Expand Down

0 comments on commit e30e9fc

Please sign in to comment.