* marc.alff@stripped <marc.alff@stripped> [07/10/16 05:59]:
> ChangeSet@stripped, 2007-10-15 19:15:38-06:00, malff@stripped. +6 -0
> Bug#28318 (CREATE FUNCTION (UDF) requires a schema) -- part II
>
> The root cause of the issue was that the CREATE FUNCTION grammar,
> for User Defined Functions, was using the sp_name rule.
> The sp_name rule is intended for fully qualified stored procedure names,
> like either ident.ident, or just ident but with a default database
> implicitly selected.
OK to push, please see comments below (as agreed on IRC).
> A UDF does not have a fully qualified name, only a name (ident), and should
> not use the sp_name grammar fragment during parsing.
>
> The fix is to re-organize the CREATE FUNCTION grammar, to better separate:
> - creating UDF (no definer, can have AGGREGATE, simple ident)
> - creating Stored Functions (definer, no AGGREGATE, fully qualified name)
>
> @@ -1570,15 +1569,14 @@ sp_name:
> | ident
> {
> LEX *lex= Lex;
> - LEX_STRING db= {0,0};
> - THD *thd= YYTHD;
> + LEX_STRING db;
>
> if (check_routine_name($1))
> {
> my_error(ER_SP_WRONG_NAME, MYF(0), $1.str);
> MYSQL_YYABORT;
> }
> - if (thd->db && thd->copy_db_to(&db.str,
> &db.length))
> + if (lex->copy_db_to(&db.str, &db.length))
> MYSQL_YYABORT;
> $$= new sp_name(db, $1, false);
> if ($$)
Could you please add the following test case to cover the fixed
problem with a test:
CREATE DATABASE db1;
CREATE PROCEDURE db1.t1 SELECT "db1.t1";
CREATE DATABASE db2;
CREATE PROCEDURE db2.t2 CALL t1();
USE db1;
CALL db2.t2();
-- it should return "no such procedure".
> + | DROP FUNCTION_SYM if_exists ident
> + {
> + THD *thd= YYTHD;
> + LEX *lex= thd->lex;
> + LEX_STRING db= {0, 0};
> + sp_name *spname;
> + if (lex->sphead)
> + {
> + my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION");
> + MYSQL_YYABORT;
> + }
> + if (thd->db && lex->copy_db_to(&db.str,
> &db.length))
> + MYSQL_YYABORT;
> + lex->sql_command = SQLCOM_DROP_FUNCTION;
> + lex->drop_if_exists= $3;
> + spname= new sp_name(db, $4, false);
> + spname->init_qname(thd);
> + lex->spname= spname;
OK for now, since we agreed to report a separate bug for the wrong
name resolution order here.
--
-- Konstantin Osipov Software Developer, Moscow, Russia
-- MySQL AB, www.mysql.com The best DATABASE COMPANY in the GALAXY