2006-02-15 17:11:24 +01:00
|
|
|
--source include/have_udf.inc
|
|
|
|
#
|
2006-07-29 04:41:50 +02:00
|
|
|
# To run this tests the "sql/udf_example.c" need to be compiled into
|
2006-03-10 10:41:04 +01:00
|
|
|
# udf_example.so and LD_LIBRARY_PATH should be setup to point out where
|
2006-02-15 17:11:24 +01:00
|
|
|
# the library are.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
drop table if exists t1;
|
|
|
|
--enable_warnings
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
#
|
2006-02-15 17:11:24 +01:00
|
|
|
# Create the example functions from udf_example
|
|
|
|
#
|
|
|
|
|
2006-04-27 16:32:40 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
|
2006-02-15 17:11:24 +01:00
|
|
|
|
2006-04-27 16:32:40 +02:00
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
2006-03-10 10:41:04 +01:00
|
|
|
--error ER_CANT_FIND_DL_ENTRY
|
2006-04-27 16:32:40 +02:00
|
|
|
eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION sequence RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION lookup RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION reverse_lookup
|
|
|
|
RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE AGGREGATE FUNCTION avgcost
|
|
|
|
RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
|
2006-02-15 17:11:24 +01:00
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 0
|
2006-02-15 17:11:24 +01:00
|
|
|
select myfunc_double();
|
|
|
|
select myfunc_double(1);
|
|
|
|
select myfunc_double(78654);
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 1305
|
2006-03-10 12:12:08 +01:00
|
|
|
select myfunc_nonexist();
|
2006-02-15 17:11:24 +01:00
|
|
|
select myfunc_int();
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 0
|
2006-02-15 17:11:24 +01:00
|
|
|
select lookup();
|
|
|
|
select lookup("127.0.0.1");
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 0
|
2006-02-15 17:11:24 +01:00
|
|
|
select lookup(127,0,0,1);
|
|
|
|
select lookup("localhost");
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 0
|
2006-02-15 17:11:24 +01:00
|
|
|
select reverse_lookup();
|
2006-03-10 12:12:08 +01:00
|
|
|
|
|
|
|
# These two functions should return "localhost", but it's
|
|
|
|
# depending on configuration, so just call them and don't log the result
|
|
|
|
--disable_result_log
|
2006-02-15 17:11:24 +01:00
|
|
|
select reverse_lookup("127.0.0.1");
|
|
|
|
select reverse_lookup(127,0,0,1);
|
2006-03-10 12:12:08 +01:00
|
|
|
--enable_result_log
|
|
|
|
|
2006-02-15 17:11:24 +01:00
|
|
|
select reverse_lookup("localhost");
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 0
|
2006-02-15 17:11:24 +01:00
|
|
|
select avgcost();
|
2006-03-10 10:41:04 +01:00
|
|
|
--error 0
|
2006-02-15 17:11:24 +01:00
|
|
|
select avgcost(100,23.76);
|
|
|
|
create table t1(sum int, price float(24));
|
|
|
|
insert into t1 values(100, 50.00), (100, 100.00);
|
|
|
|
select avgcost(sum, price) from t1;
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values(100, 54.33), (200, 199.99);
|
|
|
|
select avgcost(sum, price) from t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
# BUG#17261 Passing a variable from a stored procedure to UDF crashes mysqld
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
select metaphon('hello');
|
2006-02-15 17:11:24 +01:00
|
|
|
|
|
|
|
delimiter //;
|
|
|
|
CREATE PROCEDURE `XXX1`(in testval varchar(10))
|
2006-03-10 10:41:04 +01:00
|
|
|
begin
|
|
|
|
select metaphon(testval);
|
2006-02-15 17:11:24 +01:00
|
|
|
end//
|
|
|
|
delimiter ;//
|
|
|
|
|
|
|
|
call XXX1('hello');
|
|
|
|
drop procedure xxx1;
|
|
|
|
|
|
|
|
delimiter //;
|
|
|
|
CREATE PROCEDURE `XXX2`()
|
2006-03-10 10:41:04 +01:00
|
|
|
begin
|
2006-02-15 17:11:24 +01:00
|
|
|
declare testval varchar(10);
|
|
|
|
set testval = 'hello';
|
2006-03-10 10:41:04 +01:00
|
|
|
select metaphon(testval);
|
2006-02-15 17:11:24 +01:00
|
|
|
end//
|
|
|
|
delimiter ;//
|
|
|
|
|
|
|
|
call XXX2();
|
|
|
|
drop procedure xxx2;
|
|
|
|
|
2006-06-08 19:25:28 +02:00
|
|
|
#
|
|
|
|
# Bug#19904: UDF: not initialized *is_null per row
|
|
|
|
#
|
|
|
|
|
|
|
|
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;
|
|
|
|
SELECT metaphon(v) AS f FROM bug19904;
|
|
|
|
DROP TABLE bug19904;
|
|
|
|
|
2006-07-31 21:01:43 +02:00
|
|
|
#
|
|
|
|
# Bug#21269: DEFINER-clause is allowed for UDF-functions
|
|
|
|
#
|
|
|
|
|
|
|
|
--error ER_WRONG_USAGE
|
|
|
|
CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse
|
|
|
|
RETURNS STRING SONAME "should_not_parse.so";
|
|
|
|
|
|
|
|
--error ER_WRONG_USAGE
|
|
|
|
CREATE DEFINER=someone@somewhere FUNCTION should_not_parse
|
|
|
|
RETURNS STRING SONAME "should_not_parse.so";
|
2006-07-25 22:31:29 +02:00
|
|
|
#
|
|
|
|
# Bug#19862: Sort with filesort by function evaluates function twice
|
|
|
|
#
|
|
|
|
create table t1(f1 int);
|
|
|
|
insert into t1 values(1),(2);
|
|
|
|
explain select myfunc_int(f1) from t1 order by 1;
|
|
|
|
drop table t1;
|
2006-06-08 19:25:28 +02:00
|
|
|
--echo End of 5.0 tests.
|
2006-02-15 17:11:24 +01:00
|
|
|
|
Bug#18239 (Possible to overload internal functions with stored functions)
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.
2006-11-15 03:34:16 +01:00
|
|
|
#
|
|
|
|
# BUG#18239: Possible to overload internal functions with stored functions
|
|
|
|
#
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
drop function if exists pi;
|
|
|
|
--enable_warnings
|
|
|
|
|
|
|
|
--error ER_NATIVE_FCT_NAME_COLLISION
|
|
|
|
CREATE FUNCTION pi RETURNS STRING SONAME "should_not_parse.so";
|
|
|
|
|
|
|
|
# Verify that Stored Functions and UDF are mutually exclusive
|
|
|
|
DROP FUNCTION IF EXISTS metaphon;
|
|
|
|
|
|
|
|
CREATE FUNCTION metaphon(a int) RETURNS int
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
--error ER_UDF_EXISTS
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
|
|
|
|
DROP FUNCTION metaphon;
|
|
|
|
|
|
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
|
|
eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
|
|
|
|
|
|
|
|
--error ER_UDF_EXISTS
|
|
|
|
CREATE FUNCTION metaphon(a int) RETURNS int
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
--error ER_UDF_EXISTS
|
|
|
|
CREATE FUNCTION test.metaphon(a int) RETURNS int
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
# End of Bug#18239
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
#
|
2006-02-15 17:11:24 +01:00
|
|
|
# Drop the example functions from udf_example
|
|
|
|
#
|
|
|
|
|
|
|
|
DROP FUNCTION metaphon;
|
|
|
|
DROP FUNCTION myfunc_double;
|
2006-03-10 10:41:04 +01:00
|
|
|
--error ER_SP_DOES_NOT_EXIST
|
2006-03-10 12:12:08 +01:00
|
|
|
DROP FUNCTION myfunc_nonexist;
|
2006-02-15 17:11:24 +01:00
|
|
|
DROP FUNCTION myfunc_int;
|
|
|
|
DROP FUNCTION sequence;
|
|
|
|
DROP FUNCTION lookup;
|
|
|
|
DROP FUNCTION reverse_lookup;
|
|
|
|
DROP FUNCTION avgcost;
|
|
|
|
|
2006-06-08 19:25:28 +02:00
|
|
|
|