diff options
author | unknown <malff/marcsql@weblab.(none)> | 2006-12-01 19:16:03 -0700 |
---|---|---|
committer | unknown <malff/marcsql@weblab.(none)> | 2006-12-01 19:16:03 -0700 |
commit | b92081cdea7f1b3c9050fe539b213787647ce07f (patch) | |
tree | dbc37abc8cf65f975fabf5b333c736277ff21297 /mysql-test/t | |
parent | 06ac5d2f05eba0ddd6763ae88ae630816aa91502 (diff) | |
download | mariadb-git-b92081cdea7f1b3c9050fe539b213787647ce07f.tar.gz |
Bug#24736: UDF functions parsed as Stored Functions
Before this fix, a call to a User Defined Function (UDF) could,
under some circumstances, be interpreted as a call to a Stored function
instead. This occurred if a native function was invoked in the parameters
for the UDF, as in "select my_udf(abs(x))".
The root cause of this defect is the introduction, by the fix for Bug 21809,
of st_select_lex::udf_list, and it's usage in the parser in sql_yacc.yy
in the rule function_call_generic (in 5.1).
While the fix itself for Bug 21809 is correct in 5.0, the code change
merged into the 5.1 release created the issue, because the calls in 5.1 to :
- lex->current_select->udf_list.push_front(udf)
- lex->current_select->udf_list.pop()
are not balanced in case of native functions, causing the udf_list,
which is really a stack, to be out of sync with the internal stack
maintained by the bison parser.
Instead of moving the call to udf_list.pop(), which would have fixed the
symptom, this patch goes further and removes the need for udf_list.
This is motivated by two reasons:
a) Maintaining a stack in the MySQL code in sync with the stack maintained
internally in sql_yacc.cc (not .yy) is extremely dependent of the
implementation of yacc/bison, and extremely difficult to maintain.
It's also totally dependent of the structure of the grammar, and has a risk
to break with regression defects each time the grammar itself is changed.
b) The previous code did report construct like "foo(expr AS name)" as
syntax errors (ER_PARSER_ERROR), which is incorrect, and misleading.
The syntax is perfectly valid, as this expression is valid when "foo" is
a UDF. Whether this syntax is legal or not depends of the semantic of "foo".
With this change:
a) There is only one stack (in bison), and no List<udf_func> to maintain.
b) "foo(expr AS name)", when used incorrectly, is reported as semantic error:
- ER_WRONG_PARAMETERS_TO_NATIVE_FCT (for native functions)
- ER_WRONG_PARAMETERS_TO_STORED_FCT (for stored functions)
This is achieved by the changes implemented in item_create.cc
mysql-test/r/parser.result:
New tests
mysql-test/r/udf.result:
New tests
mysql-test/t/parser.test:
New tests
mysql-test/t/udf.test:
New tests
sql/item_create.cc:
Semantic checks for named parameters, as in "foo(expr AS name)".
sql/share/errmsg.txt:
New error message
sql/sql_lex.cc:
Remove usage of udf_list.
sql/sql_lex.h:
Remove usage of udf_list.
sql/sql_yacc.yy:
Remove usage of udf_list.
Diffstat (limited to 'mysql-test/t')
-rw-r--r-- | mysql-test/t/parser.test | 110 | ||||
-rw-r--r-- | mysql-test/t/udf.test | 20 |
2 files changed, 128 insertions, 2 deletions
diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test index 11af7c691d8..63e5137b3a3 100644 --- a/mysql-test/t/parser.test +++ b/mysql-test/t/parser.test @@ -508,3 +508,113 @@ select yearweek(); -- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT select yearweek(1, 2, 3); +# +# Bug#24736: UDF functions parsed as Stored Functions +# + +# Verify that the syntax for calling UDF : foo(expr AS param, ...) +# can not be used when calling native functions + +# Native function with 1 argument + +select abs(3); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select abs(3 AS three); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select abs(3 three); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select abs(3 AS "three"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select abs(3 "three"); + +# Native function with 2 arguments + +set @bar="bar"; +set @foobar="foobar"; + +select instr("foobar", "bar"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar" AS p1, "bar"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar" p1, "bar"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar" AS "p1", "bar"); +## String concatenation, valid syntax +select instr("foobar" "p1", "bar"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr(@foobar "p1", "bar"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar", "bar" AS p2); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar", "bar" p2); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar", "bar" AS "p2"); +## String concatenation, valid syntax +select instr("foobar", "bar" "p2"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar", @bar "p2"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select instr("foobar" AS p1, "bar" AS p2); + +# Native function with 3 arguments + +select conv(255, 10, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255 AS p1, 10, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255 p1, 10, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255 AS "p1", 10, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255 "p1", 10, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10 AS p2, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10 p2, 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10 AS "p2", 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10 "p2", 16); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10, 16 AS p3); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10, 16 p3); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10, 16 AS "p3"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255, 10, 16 "p3"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select conv(255 AS p1, 10 AS p2, 16 AS p3); + +# Native function with a variable number of arguments + +select atan(10); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 AS p1); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 p1); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 AS "p1"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 "p1"); + +select atan(10, 20); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 AS p1, 20); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 p1, 20); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 AS "p1", 20); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 "p1", 20); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10, 20 AS p2); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10, 20 p2); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10, 20 AS "p2"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10, 20 "p2"); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select atan(10 AS p1, 20 AS p2); + diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index 52ae424e423..24ddc1d44bc 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -149,9 +149,9 @@ EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1; EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1; SELECT a,c FROM v1; ---error ER_PARSE_ERROR +--error ER_WRONG_PARAMETERS_TO_STORED_FCT SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a; ---error ER_PARSE_ERROR +--error ER_WRONG_PARAMETERS_TO_STORED_FCT SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a; --error ER_PARSE_ERROR SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a; @@ -174,6 +174,22 @@ DROP FUNCTION fn; --echo End of 5.0 tests. # +# Bug#24736: UDF functions parsed as Stored Functions +# + +select myfunc_double(3); +select myfunc_double(3 AS three); +select myfunc_double(abs(3)); +select myfunc_double(abs(3) AS named_param); +select abs(myfunc_double(3)); +select abs(myfunc_double(3 AS three)); + +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select myfunc_double(abs(3 AS wrong)); +-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT +select abs(myfunc_double(3) AS wrong); + +# # Drop the example functions from udf_example # |