From 0fd784928c340968967a104dd0191837549ee8a3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Feb 2006 13:00:32 +0100 Subject: [PATCH] Fixed BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION Check if AGGREGATE was given with a stored (non-UDF) function, and return error in that case. Also made udf_example/udf_test work again, by adding a missing *_init() function. (_init() functions required unless --allow_suspicious_udfs is given to the server, since March 2005 - it seems udf_example wasn't updated at the time.) mysql-test/r/sp-error.result: Updated results for BUG#16896. mysql-test/t/sp-error.test: Added test case for BUG#16896. sql/share/errmsg.txt: New error message: ER_SP_NO_AGGREGATE sql/sql_yacc.yy: Check if AGGREGATE was used when creating a stored function (i.e. not an UDF). sql/udf_example.cc: Added myfunc_int_init() function to make it work when the server is running without --allow_suspicious_udfs. --- mysql-test/r/sp-error.result | 3 +++ mysql-test/t/sp-error.test | 12 ++++++++++++ sql/share/errmsg.txt | 2 ++ sql/sql_yacc.yy | 10 ++++++++++ sql/udf_example.cc | 9 +++++++++ 5 files changed, 36 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 2766dca5845..c0e02cbeb6f 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1176,3 +1176,6 @@ end| call bug15091(); ERROR 42S02: Unknown table 'c' in field list drop procedure bug15091; +drop function if exists bug16896; +create aggregate function bug16896() returns int return 1; +ERROR 42000: AGGREGATE is not supported for stored functions diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index e1839b4b98f..c4745537de3 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1703,6 +1703,17 @@ call bug15091(); drop procedure bug15091; +# +# BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION +# +--disable_warnings +drop function if exists bug16896; +--enable_warnings + +--error ER_SP_NO_AGGREGATE +create aggregate function bug16896() returns int return 1; + + # # BUG#NNNN: New bug synopsis # @@ -1710,3 +1721,4 @@ drop procedure bug15091; #drop procedure if exists bugNNNN| #--enable_warnings #create procedure bugNNNN... + diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 8017ba3ef9f..1315de6528a 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5607,3 +5607,5 @@ ER_SP_PROC_TABLE_CORRUPT eng "Failed to load routine %s. The table mysql.proc is missing, corrupt, or contains bad data (internal code %d)" ER_SP_WRONG_NAME 42000 eng "Incorrect routine name '%-.64s'" +ER_SP_NO_AGGREGATE 42000 + eng "AGGREGATE is not supported for stored functions" diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ebb97cde3e4..4f4ec5e92de 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1326,6 +1326,16 @@ create_function_tail: LEX *lex= Lex; sp_head *sp; + /* + First check if AGGREGATE was used, in that case it's a + syntax error. + */ + if (lex->udf.type == UDFTYPE_AGGREGATE) + { + my_error(ER_SP_NO_AGGREGATE, MYF(0)); + YYABORT; + } + if (lex->sphead) { my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION"); diff --git a/sql/udf_example.cc b/sql/udf_example.cc index a186b4fbf6c..35833e63fab 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -144,6 +144,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, my_bool myfunc_double_init(UDF_INIT *, UDF_ARGS *args, char *message); double myfunc_double(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); +my_bool myfunc_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message); longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); my_bool sequence_init(UDF_INIT *initid, UDF_ARGS *args, char *message); @@ -597,6 +598,14 @@ longlong myfunc_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, return val; } +/* + At least one of _init/_deinit is needed unless the server is started + with --allow_suspicious_udfs. +*/ +my_bool myfunc_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + return 0; +} /* Simple example of how to get a sequences starting from the first argument