2006-02-15 17:11:24 +01:00
|
|
|
--source include/have_udf.inc
|
|
|
|
#
|
2006-03-10 10:41:04 +01:00
|
|
|
# To run this tests the "sql/udf_example.cc" need to be compiled into
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
|
|
|
|
CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so';
|
|
|
|
|
2006-03-10 10:41:04 +01:00
|
|
|
--error ER_CANT_FIND_DL_ENTRY
|
2006-03-10 12:12:08 +01:00
|
|
|
CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME 'udf_example.so';
|
2006-02-15 17:11:24 +01:00
|
|
|
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so';
|
|
|
|
CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so";
|
|
|
|
CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so';
|
|
|
|
CREATE FUNCTION reverse_lookup
|
|
|
|
RETURNS STRING SONAME 'udf_example.so';
|
|
|
|
CREATE AGGREGATE FUNCTION avgcost
|
|
|
|
RETURNS REAL SONAME 'udf_example.so';
|
|
|
|
|
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-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;
|
|
|
|
|