summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <msvensson@neptunus.(none)>2006-03-10 10:16:50 +0100
committerunknown <msvensson@neptunus.(none)>2006-03-10 10:16:50 +0100
commitd1f1c383c651a9affd6eb6d456ad9c392e458ce5 (patch)
tree3940c88311ab4cdd429694ae60a4ec6d782dc958
parent31b260c3c2b20e4e52b0590001ed03363a397df1 (diff)
parent79258e4480bfacd94384263240feba68f83a9a79 (diff)
downloadmariadb-git-d1f1c383c651a9affd6eb6d456ad9c392e458ce5.tar.gz
Merge msvensson@devsrv-b:/space/magnus/bug17261/my50-bug17261
into neptunus.(none):/home/msvensson/mysql/bug11835/my50-bug11835 sql/udf_example.cc: Auto merged
-rw-r--r--mysql-test/include/have_udf.inc12
-rw-r--r--mysql-test/r/have_udf.require1
-rw-r--r--mysql-test/r/udf.result86
-rw-r--r--mysql-test/t/udf.test94
-rw-r--r--sql/item_func.cc2
-rw-r--r--sql/udf_example.cc2
6 files changed, 195 insertions, 2 deletions
diff --git a/mysql-test/include/have_udf.inc b/mysql-test/include/have_udf.inc
new file mode 100644
index 00000000000..a22b2a52e61
--- /dev/null
+++ b/mysql-test/include/have_udf.inc
@@ -0,0 +1,12 @@
+#
+# To check if the udf_example.so is available,
+# try to load one function from it.
+#
+#
+--require r/have_udf.require
+--disable_abort_on_error
+CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
+--disable_query_log
+DROP FUNCTION metaphon;
+--enable_query_log
+--enable_abort_on_error
diff --git a/mysql-test/r/have_udf.require b/mysql-test/r/have_udf.require
new file mode 100644
index 00000000000..869d1b254fd
--- /dev/null
+++ b/mysql-test/r/have_udf.require
@@ -0,0 +1 @@
+CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result
new file mode 100644
index 00000000000..d6f58d35fb7
--- /dev/null
+++ b/mysql-test/r/udf.result
@@ -0,0 +1,86 @@
+drop table if exists t1;
+CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
+CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so';
+CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so';
+ERROR HY000: Can't find function 'myfunc_int_init' in library
+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';
+select myfunc_double();
+ERROR HY000: myfunc_double must have at least on argument
+select myfunc_double(1);
+myfunc_double(1)
+49.00
+select myfunc_double(78654);
+myfunc_double(78654)
+54.00
+select myfunc_int();
+ERROR 42000: FUNCTION test.myfunc_int does not exist
+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");
+reverse_lookup("127.0.0.1")
+localhost
+select reverse_lookup(127,0,0,1);
+reverse_lookup(127,0,0,1)
+localhost
+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;
+DROP FUNCTION metaphon;
+DROP FUNCTION myfunc_double;
+DROP FUNCTION myfunc_int;
+ERROR 42000: FUNCTION test.myfunc_int does not exist
+DROP FUNCTION sequence;
+DROP FUNCTION lookup;
+DROP FUNCTION reverse_lookup;
+DROP FUNCTION avgcost;
diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test
new file mode 100644
index 00000000000..98eecd3a737
--- /dev/null
+++ b/mysql-test/t/udf.test
@@ -0,0 +1,94 @@
+--source include/have_udf.inc
+#
+# To run this tests you need to compile "sql/udf_example.cc" into
+# udf_example.so and setup LD_LIBRARY_PATH to point out where
+# the library are.
+#
+
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# 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';
+
+# myfunc_int does not have a myfunc_int_init function and can
+# not be loaded unless server is started with --allow-suspicious-udfs
+--error 1127
+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';
+
+select myfunc_double();
+select myfunc_double(1);
+select myfunc_double(78654);
+select myfunc_int();
+select lookup();
+select lookup("127.0.0.1");
+select lookup(127,0,0,1);
+select lookup("localhost");
+select reverse_lookup();
+select reverse_lookup("127.0.0.1");
+select reverse_lookup(127,0,0,1);
+select reverse_lookup("localhost");
+select avgcost();
+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
+#------------------------------------------------------------------------
+
+select metaphon('hello');
+
+delimiter //;
+CREATE PROCEDURE `XXX1`(in testval varchar(10))
+begin
+select metaphon(testval);
+end//
+delimiter ;//
+
+call XXX1('hello');
+drop procedure xxx1;
+
+delimiter //;
+CREATE PROCEDURE `XXX2`()
+begin
+declare testval varchar(10);
+set testval = 'hello';
+select metaphon(testval);
+end//
+delimiter ;//
+
+call XXX2();
+drop procedure xxx2;
+
+
+#
+# Drop the example functions from udf_example
+#
+
+DROP FUNCTION metaphon;
+DROP FUNCTION myfunc_double;
+--error 1305
+DROP FUNCTION myfunc_int;
+DROP FUNCTION sequence;
+DROP FUNCTION lookup;
+DROP FUNCTION reverse_lookup;
+DROP FUNCTION avgcost;
+
diff --git a/sql/item_func.cc b/sql/item_func.cc
index a85f05c2e22..f27e7edd284 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2606,7 +2606,7 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func,
switch(arguments[i]->type()) {
case Item::STRING_ITEM: // Constant string !
{
- String *res=arguments[i]->val_str((String *) 0);
+ String *res=arguments[i]->val_str(&buffers[i]);
if (arguments[i]->null_value)
continue;
f_args.args[i]= (char*) res->ptr();
diff --git a/sql/udf_example.cc b/sql/udf_example.cc
index 35833e63fab..c94af5cd6ee 100644
--- a/sql/udf_example.cc
+++ b/sql/udf_example.cc
@@ -519,7 +519,7 @@ my_bool myfunc_double_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (!args->arg_count)
{
- strcpy(message,"myfunc_double must have at least on argument");
+ strcpy(message,"myfunc_double must have at least one argument");
return 1;
}
/*