mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 12:01:42 +01:00
6e29099d43
Bug#21025 (misleading error message when creating functions named 'x', or 'y') Bug#22619 (Spaces considered harmful) This change contains a fix to report warnings or errors, and multiple tests cases. Before this fix, name collisions between: - Native functions - User Defined Functions - Stored Functions were not systematically reported, leading to confusing behavior. I) Native / User Defined Function Before this fix, is was possible to create a UDF named "foo", with the same name as a native function "foo", but it was impossible to invoke the UDF, since the syntax "foo()" always refer to the native function. After this fix, creating a UDF fails with an error if there is a name collision with a native function. II) Native / Stored Function Before this fix, is was possible to create a SF named "db.foo", with the same name as a native function "foo", but this was confusing since the syntax "foo()" would refer to the native function. To refer to the Stored Function, the user had to use the "db.foo()" syntax. After this fix, creating a Stored Function reports a warning if there is a name collision with a native function. III) User Defined Function / Stored Function Before this fix, creating a User Defined Function "foo" and a Stored Function "db.foo" are mutually exclusive operations. Whenever the second function is created, an error is reported. However, the test suite did not cover this behavior. After this fix, the behavior is unchanged, and is now covered by test cases. Note that the code change in this patch depends on the fix for Bug 21114.
133 lines
4 KiB
Text
133 lines
4 KiB
Text
drop table if exists t1;
|
|
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
|
|
ERROR HY000: Can't find symbol 'myfunc_nonexist' in library
|
|
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE FUNCTION sequence RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE FUNCTION lookup RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE FUNCTION reverse_lookup
|
|
RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE AGGREGATE FUNCTION avgcost
|
|
RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
|
|
select myfunc_double();
|
|
ERROR HY000: myfunc_double must have at least one argument
|
|
select myfunc_double(1);
|
|
myfunc_double(1)
|
|
49.00
|
|
select myfunc_double(78654);
|
|
myfunc_double(78654)
|
|
54.00
|
|
select myfunc_nonexist();
|
|
ERROR 42000: FUNCTION test.myfunc_nonexist does not exist
|
|
select myfunc_int();
|
|
myfunc_int()
|
|
0
|
|
select lookup();
|
|
ERROR HY000: Wrong arguments to lookup; Use the source
|
|
select lookup("127.0.0.1");
|
|
lookup("127.0.0.1")
|
|
127.0.0.1
|
|
select lookup(127,0,0,1);
|
|
ERROR HY000: Wrong arguments to lookup; Use the source
|
|
select lookup("localhost");
|
|
lookup("localhost")
|
|
127.0.0.1
|
|
select reverse_lookup();
|
|
ERROR HY000: Wrong number of arguments to reverse_lookup; Use the source
|
|
select reverse_lookup("127.0.0.1");
|
|
select reverse_lookup(127,0,0,1);
|
|
select reverse_lookup("localhost");
|
|
reverse_lookup("localhost")
|
|
NULL
|
|
select avgcost();
|
|
ERROR HY000: wrong number of arguments: AVGCOST() requires two arguments
|
|
select avgcost(100,23.76);
|
|
ERROR HY000: wrong argument type: AVGCOST() requires an INT and a REAL
|
|
create table t1(sum int, price float(24));
|
|
insert into t1 values(100, 50.00), (100, 100.00);
|
|
select avgcost(sum, price) from t1;
|
|
avgcost(sum, price)
|
|
75.0000
|
|
delete from t1;
|
|
insert into t1 values(100, 54.33), (200, 199.99);
|
|
select avgcost(sum, price) from t1;
|
|
avgcost(sum, price)
|
|
151.4367
|
|
drop table t1;
|
|
select metaphon('hello');
|
|
metaphon('hello')
|
|
HL
|
|
CREATE PROCEDURE `XXX1`(in testval varchar(10))
|
|
begin
|
|
select metaphon(testval);
|
|
end//
|
|
call XXX1('hello');
|
|
metaphon(testval)
|
|
HL
|
|
drop procedure xxx1;
|
|
CREATE PROCEDURE `XXX2`()
|
|
begin
|
|
declare testval varchar(10);
|
|
set testval = 'hello';
|
|
select metaphon(testval);
|
|
end//
|
|
call XXX2();
|
|
metaphon(testval)
|
|
HL
|
|
drop procedure xxx2;
|
|
CREATE TABLE bug19904(n INT, v varchar(10));
|
|
INSERT INTO bug19904 VALUES (1,'one'),(2,'two'),(NULL,NULL),(3,'three'),(4,'four');
|
|
SELECT myfunc_double(n) AS f FROM bug19904;
|
|
f
|
|
49.00
|
|
50.00
|
|
NULL
|
|
51.00
|
|
52.00
|
|
SELECT metaphon(v) AS f FROM bug19904;
|
|
f
|
|
ON
|
|
TW
|
|
NULL
|
|
0R
|
|
FR
|
|
DROP TABLE bug19904;
|
|
CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse
|
|
RETURNS STRING SONAME "should_not_parse.so";
|
|
ERROR HY000: Incorrect usage of SONAME and DEFINER
|
|
CREATE DEFINER=someone@somewhere FUNCTION should_not_parse
|
|
RETURNS STRING SONAME "should_not_parse.so";
|
|
ERROR HY000: Incorrect usage of SONAME and DEFINER
|
|
create table t1(f1 int);
|
|
insert into t1 values(1),(2);
|
|
explain select myfunc_int(f1) from t1 order by 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
|
drop table t1;
|
|
End of 5.0 tests.
|
|
drop function if exists pi;
|
|
CREATE FUNCTION pi RETURNS STRING SONAME "should_not_parse.so";
|
|
ERROR HY000: This function 'pi' has the same name as a native function.
|
|
DROP FUNCTION IF EXISTS metaphon;
|
|
CREATE FUNCTION metaphon(a int) RETURNS int
|
|
return 0;
|
|
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
|
|
ERROR HY000: Function 'metaphon' already exists
|
|
DROP FUNCTION metaphon;
|
|
CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
|
|
CREATE FUNCTION metaphon(a int) RETURNS int
|
|
return 0;
|
|
ERROR HY000: Function 'metaphon' already exists
|
|
CREATE FUNCTION test.metaphon(a int) RETURNS int
|
|
return 0;
|
|
ERROR HY000: Function 'metaphon' already exists
|
|
DROP FUNCTION metaphon;
|
|
DROP FUNCTION myfunc_double;
|
|
DROP FUNCTION myfunc_nonexist;
|
|
ERROR 42000: FUNCTION test.myfunc_nonexist does not exist
|
|
DROP FUNCTION myfunc_int;
|
|
DROP FUNCTION sequence;
|
|
DROP FUNCTION lookup;
|
|
DROP FUNCTION reverse_lookup;
|
|
DROP FUNCTION avgcost;
|