From 79258e4480bfacd94384263240feba68f83a9a79 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Feb 2006 17:11:24 +0100 Subject: [PATCH 1/6] Bug#17261 Passing a variable from a stored procedure to UDF crashes mysqld - Pass "buffers[i]" to val_str() in udf_handler::fix_fields insteead of NULL. - Add testcase for UDF that will load and run the udf_example functions if available sql/item_func.cc: Instead of passing a NULL pointer into val_str, use the "buffers" array to provide a temp string buffer. sql/udf_example.cc: Spelling error"on"->"one" mysql-test/include/have_udf.inc: New BitKeeper file ``mysql-test/include/have_udf.inc'' mysql-test/r/have_udf.require: New BitKeeper file ``mysql-test/r/have_udf.require'' mysql-test/r/udf.result: New BitKeeper file ``mysql-test/r/udf.result'' mysql-test/t/udf.test: New BitKeeper file ``mysql-test/t/udf.test'' --- mysql-test/include/have_udf.inc | 12 +++++ mysql-test/r/have_udf.require | 1 + mysql-test/r/udf.result | 86 ++++++++++++++++++++++++++++++ mysql-test/t/udf.test | 94 +++++++++++++++++++++++++++++++++ sql/item_func.cc | 2 +- sql/udf_example.cc | 2 +- 6 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 mysql-test/include/have_udf.inc create mode 100644 mysql-test/r/have_udf.require create mode 100644 mysql-test/r/udf.result create mode 100644 mysql-test/t/udf.test 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 a186b4fbf6c..6ce66157101 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -518,7 +518,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; } /* From 81858c0efa0079ff1320ba097f32a3c6657ddcef Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Mar 2006 09:51:08 +0100 Subject: [PATCH 2/6] Bug#11835 CREATE FUNCTION crashes server - Don't look for 'dl_open' if mysqld is compiled with "-all-static" configure.in: No need to check for dlopen when mysqld is linked with -all-static as it won't be able to load any functions (and in some cases segfaults) --- configure.in | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/configure.in b/configure.in index b230b7f042e..9749833f635 100644 --- a/configure.in +++ b/configure.in @@ -1632,16 +1632,35 @@ else fi #---END: -# Check for dlopen, needed for user definable functions -# This must be checked after threads on AIX -# We only need this for mysqld, not for the clients. +# dlopen, dlerror +case $with_mysqld_ldflags in + + *-all-static*) + # No need to check for dlopen when mysqld is linked with + # -all-static as it won't be able to load any functions. + + ;; + + *) + # Check for dlopen, needed for user definable functions + # This must be checked after threads on AIX + # We only need this for mysqld, not for the clients. + + my_save_LIBS="$LIBS" + LIBS="" + AC_CHECK_LIB(dl,dlopen) + LIBDL=$LIBS + LIBS="$my_save_LIBS" + AC_SUBST(LIBDL) + + my_save_LIBS="$LIBS" + LIBS="$LIBS $LIBDL" + AC_CHECK_FUNCS(dlopen dlerror) + LIBS="$my_save_LIBS" + + ;; +esac -my_save_LIBS="$LIBS" -LIBS="" -AC_CHECK_LIB(dl,dlopen) -LIBDL=$LIBS -LIBS="$my_save_LIBS" -AC_SUBST(LIBDL) # System characteristics case $SYSTEM_TYPE in @@ -2005,11 +2024,6 @@ then fi] ) -my_save_LIBS="$LIBS" -LIBS="$LIBS $LIBDL" -AC_CHECK_FUNCS(dlopen dlerror) -LIBS="$my_save_LIBS" - # Check definition of gethostbyaddr_r (glibc2 defines this with 8 arguments) ac_save_CXXFLAGS="$CXXFLAGS" AC_CACHE_CHECK([style of gethost* routines], mysql_cv_gethost_style, From e52ff5557cbf67e678fc0e429b338dee73e7b241 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Mar 2006 10:41:04 +0100 Subject: [PATCH 3/6] Bug#17261 Passing a variable from a stored procedure to UDF crashes mysqld - Update of test toolsand Makefiles to make it possible to test always test udf's as part of the mysql test suite mysql-test/mysql-test-run.pl: Add the path where mysqld will udf_example.so used by the udf test mysql-test/r/udf.result: Update test results mysql-test/t/udf.test: Update tests The "--error 0" directives should actually be changed to the correct error number returned but that error number is lost. W e do however get the right error message and that is checked in the .result file. sql/Makefile.am: Build shared library udf_example.so sql/share/errmsg.txt: Update the max length of %s string from 64 to 128 sql/sql_udf.cc: Add DBUG_PRINT just before dl_open sql/udf_example.cc: Use isalpha instade of my_isalpha --- mysql-test/mysql-test-run.pl | 8 ++++ mysql-test/r/udf.result | 10 ++--- mysql-test/t/udf.test | 30 ++++++++------ sql/Makefile.am | 10 +++-- sql/share/errmsg.txt | 76 ++++++++++++++++++------------------ sql/sql_udf.cc | 1 + sql/udf_example.cc | 10 +++-- 7 files changed, 83 insertions(+), 62 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index c708b0e92ce..222d3465a01 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1104,6 +1104,14 @@ sub environment_setup () { ($ENV{'DYLD_LIBRARY_PATH'} ? ":$ENV{'DYLD_LIBRARY_PATH'}" : ""); } + # -------------------------------------------------------------------------- + # Add the path where mysqld will find udf_example.so + # -------------------------------------------------------------------------- + $ENV{'LD_LIBRARY_PATH'}= + "$glob_basedir/sql/.libs" . + ($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : ""); + + # -------------------------------------------------------------------------- # Also command lines in .opt files may contain env vars # -------------------------------------------------------------------------- diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result index d6f58d35fb7..19f67eda429 100644 --- a/mysql-test/r/udf.result +++ b/mysql-test/r/udf.result @@ -10,7 +10,7 @@ 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 +ERROR HY000: myfunc_double must have at least one argument select myfunc_double(1); myfunc_double(1) 49.00 @@ -59,18 +59,18 @@ select metaphon('hello'); metaphon('hello') HL CREATE PROCEDURE `XXX1`(in testval varchar(10)) -begin -select metaphon(testval); +begin +select metaphon(testval); end// call XXX1('hello'); metaphon(testval) HL drop procedure xxx1; CREATE PROCEDURE `XXX2`() -begin +begin declare testval varchar(10); set testval = 'hello'; -select metaphon(testval); +select metaphon(testval); end// call XXX2(); metaphon(testval) diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index 98eecd3a737..ebe21d20362 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -1,7 +1,7 @@ --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 +# 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 # the library are. # @@ -10,7 +10,7 @@ drop table if exists t1; --enable_warnings -# +# # Create the example functions from udf_example # @@ -19,7 +19,7 @@ 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 +--error ER_CANT_FIND_DL_ENTRY 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'; @@ -28,19 +28,27 @@ CREATE FUNCTION reverse_lookup CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME 'udf_example.so'; +--error 0 select myfunc_double(); select myfunc_double(1); select myfunc_double(78654); +--error 1305 select myfunc_int(); +--error 0 select lookup(); select lookup("127.0.0.1"); +--error 0 select lookup(127,0,0,1); select lookup("localhost"); +--error 0 select reverse_lookup(); select reverse_lookup("127.0.0.1"); +--error 0 select reverse_lookup(127,0,0,1); select reverse_lookup("localhost"); +--error 0 select avgcost(); +--error 0 select avgcost(100,23.76); create table t1(sum int, price float(24)); insert into t1 values(100, 50.00), (100, 100.00); @@ -54,12 +62,12 @@ drop table t1; # BUG#17261 Passing a variable from a stored procedure to UDF crashes mysqld #------------------------------------------------------------------------ -select metaphon('hello'); +select metaphon('hello'); delimiter //; CREATE PROCEDURE `XXX1`(in testval varchar(10)) -begin -select metaphon(testval); +begin +select metaphon(testval); end// delimiter ;// @@ -68,10 +76,10 @@ drop procedure xxx1; delimiter //; CREATE PROCEDURE `XXX2`() -begin +begin declare testval varchar(10); set testval = 'hello'; -select metaphon(testval); +select metaphon(testval); end// delimiter ;// @@ -79,13 +87,13 @@ call XXX2(); drop procedure xxx2; -# +# # Drop the example functions from udf_example # DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; ---error 1305 +--error ER_SP_DOES_NOT_EXIST DROP FUNCTION myfunc_int; DROP FUNCTION sequence; DROP FUNCTION lookup; diff --git a/sql/Makefile.am b/sql/Makefile.am index d701c18a4d7..9b818f7c389 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -153,10 +153,12 @@ sql_yacc.o: sql_yacc.cc sql_yacc.h $(HEADERS) lex_hash.h: gen_lex_hash$(EXEEXT) ./gen_lex_hash$(EXEEXT) > $@ -# For testing of udf_example.so; Works on platforms with gcc -# (This is not part of our build process but only provided as an example) -udf_example.so: udf_example.cc - $(CXXCOMPILE) -shared -o $@ $< +# For testing of udf_example.so +noinst_LTLIBRARIES= udf_example.la +udf_example_la_SOURCES= udf_example.cc +udf_example_la_CXXFLAGS= -DSTANDARD +udf_example_la_LDFLAGS= -module -rpath $(pkglibdir) + # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 8017ba3ef9f..18ddee86c50 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -2978,23 +2978,23 @@ ER_UDF_EXISTS swe "Funktionen '%-.64s' finns redan" ukr "æÕÎËÃ¦Ñ '%-.64s' ×ÖÅ ¦ÓÎÕ¤" ER_CANT_OPEN_LIBRARY - cze "Nemohu otev-Bøít sdílenou knihovnu '%-.64s' (errno: %d %s)" - dan "Kan ikke åbne delt bibliotek '%-.64s' (errno: %d %s)" - nla "Kan shared library '%-.64s' niet openen (Errcode: %d %s)" - eng "Can't open shared library '%-.64s' (errno: %d %-.64s)" - jps "shared library '%-.64s' ‚ðŠJ‚­Ž–‚ª‚Å‚«‚Ü‚¹‚ñ (errno: %d %s)", - est "Ei suuda avada jagatud teeki '%-.64s' (veakood: %d %-.64s)" - fre "Impossible d'ouvrir la bibliothèque partagée '%-.64s' (errno: %d %s)" - ger "Kann Shared Library '%-.64s' nicht öffnen (Fehler: %d %-.64s)" - greek "Äåí åßíáé äõíáôÞ ç áíÜãíùóç ôçò shared library '%-.64s' (êùäéêüò ëÜèïõò: %d %s)" - hun "A(z) '%-.64s' megosztott konyvtar nem hasznalhato (hibakod: %d %s)" - ita "Impossibile aprire la libreria condivisa '%-.64s' (errno: %d %s)" - jpn "shared library '%-.64s' ¤ò³«¤¯»ö¤¬¤Ç¤­¤Þ¤»¤ó (errno: %d %s)" - kor "'%-.64s' °øÀ¯ ¶óÀ̹ö·¯¸®¸¦ ¿­¼ö ¾ø½À´Ï´Ù.(¿¡·¯¹øÈ£: %d %s)" - nor "Can't open shared library '%-.64s' (errno: %d %s)" - norwegian-ny "Can't open shared library '%-.64s' (errno: %d %s)" - pol "Can't open shared library '%-.64s' (errno: %d %s)" - por "Não pode abrir biblioteca compartilhada '%-.64s' (erro no. '%d' - '%-.64s')" + cze "Nemohu otev-Bøít sdílenou knihovnu '%-.64s' (errno: %d %-.128s)" + dan "Kan ikke åbne delt bibliotek '%-.64s' (errno: %d %-.128s)" + nla "Kan shared library '%-.64s' niet openen (Errcode: %d %-.128s)" + eng "Can't open shared library '%-.64s' (errno: %d %-.128s)" + jps "shared library '%-.64s' ‚ðŠJ‚­Ž–‚ª‚Å‚«‚Ü‚¹‚ñ (errno: %d %-.128s)", + est "Ei suuda avada jagatud teeki '%-.64s' (veakood: %d %-.128s)" + fre "Impossible d'ouvrir la bibliothèque partagée '%-.64s' (errno: %d %-.128s)" + ger "Kann Shared Library '%-.64s' nicht öffnen (Fehler: %d %-.128s)" + greek "Äåí åßíáé äõíáôÞ ç áíÜãíùóç ôçò shared library '%-.64s' (êùäéêüò ëÜèïõò: %d %-.128s)" + hun "A(z) '%-.64s' megosztott konyvtar nem hasznalhato (hibakod: %d %-.128s)" + ita "Impossibile aprire la libreria condivisa '%-.64s' (errno: %d %-.128s)" + jpn "shared library '%-.64s' ¤ò³«¤¯»ö¤¬¤Ç¤­¤Þ¤»¤ó (errno: %d %-.128s)" + kor "'%-.64s' °øÀ¯ ¶óÀ̹ö·¯¸®¸¦ ¿­¼ö ¾ø½À´Ï´Ù.(¿¡·¯¹øÈ£: %d %-.128s)" + nor "Can't open shared library '%-.64s' (errno: %d %-.128s)" + norwegian-ny "Can't open shared library '%-.64s' (errno: %d %-.128s)" + pol "Can't open shared library '%-.64s' (errno: %d %-.128s)" + por "Não pode abrir biblioteca compartilhada '%-.64s' (erro no. '%d' - '%-.128s')" rum "Nu pot deschide libraria shared '%-.64s' (Eroare: %d %-.64s)" rus "îÅ×ÏÚÍÏÖÎÏ ÏÔËÒÙÔØ ÄÉÎÁÍÉÞÅÓËÕÀ ÂÉÂÌÉÏÔÅËÕ '%-.64s' (ÏÛÉÂËÁ: %d %-.64s)" serbian "Ne mogu da otvorim share-ovanu biblioteku '%-.64s' (errno: %d %-.64s)" @@ -3003,27 +3003,27 @@ ER_CANT_OPEN_LIBRARY swe "Kan inte öppna det dynamiska biblioteket '%-.64s' (Felkod: %d %s)" ukr "îÅ ÍÏÖÕ ×¦ÄËÒÉÔÉ ÒÏÚĦÌÀ×ÁÎÕ Â¦Â̦ÏÔÅËÕ '%-.64s' (ÐÏÍÉÌËÁ: %d %-.64s)" ER_CANT_FIND_DL_ENTRY - cze "Nemohu naj-Bít funkci '%-.64s' v knihovnì" - dan "Kan ikke finde funktionen '%-.64s' i bibliotek" - nla "Kan functie '%-.64s' niet in library vinden" - eng "Can't find function '%-.64s' in library" - jps "function '%-.64s' ‚ðƒ‰ƒCƒuƒ‰ƒŠ[’†‚ÉŒ©•t‚¯‚鎖‚ª‚Å‚«‚Ü‚¹‚ñ", - est "Ei leia funktsiooni '%-.64s' antud teegis" - fre "Impossible de trouver la fonction '%-.64s' dans la bibliothèque" - ger "Kann Funktion '%-.64s' in der Library nicht finden" - greek "Äåí åßíáé äõíáôÞ ç áíåýñåóç ôçò óõíÜñôçóçò '%-.64s' óôçí âéâëéïèÞêç" - hun "A(z) '%-.64s' fuggveny nem talalhato a konyvtarban" - ita "Impossibile trovare la funzione '%-.64s' nella libreria" - jpn "function '%-.64s' ¤ò¥é¥¤¥Ö¥é¥ê¡¼Ãæ¤Ë¸«ÉÕ¤±¤ë»ö¤¬¤Ç¤­¤Þ¤»¤ó" - kor "¶óÀ̹ö·¯¸®¿¡¼­ '%-.64s' ÇÔ¼ö¸¦ ãÀ» ¼ö ¾ø½À´Ï´Ù." - por "Não pode encontrar a função '%-.64s' na biblioteca" - rum "Nu pot gasi functia '%-.64s' in libraria" - rus "îÅ×ÏÚÍÏÖÎÏ ÏÔÙÓËÁÔØ ÆÕÎËÃÉÀ '%-.64s' × ÂÉÂÌÉÏÔÅËÅ" - serbian "Ne mogu da pronadjem funkciju '%-.64s' u biblioteci" - slo "Nemô¾em nájs» funkciu '%-.64s' v kni¾nici" - spa "No puedo encontrar función '%-.64s' en libraria" - swe "Hittar inte funktionen '%-.64s' in det dynamiska biblioteket" - ukr "îÅ ÍÏÖÕ ÚÎÁÊÔÉ ÆÕÎËæÀ '%-.64s' Õ Â¦Â̦ÏÔÅæ" + cze "Nemohu naj-Bít funkci '%-.128s' v knihovnì" + dan "Kan ikke finde funktionen '%-.128s' i bibliotek" + nla "Kan functie '%-.128s' niet in library vinden" + eng "Can't find function '%-.128s' in library" + jps "function '%-.128s' ‚ðƒ‰ƒCƒuƒ‰ƒŠ[’†‚ÉŒ©•t‚¯‚鎖‚ª‚Å‚«‚Ü‚¹‚ñ", + est "Ei leia funktsiooni '%-.128s' antud teegis" + fre "Impossible de trouver la fonction '%-.128s' dans la bibliothèque" + ger "Kann Funktion '%-.128s' in der Library nicht finden" + greek "Äåí åßíáé äõíáôÞ ç áíåýñåóç ôçò óõíÜñôçóçò '%-.128s' óôçí âéâëéïèÞêç" + hun "A(z) '%-.128s' fuggveny nem talalhato a konyvtarban" + ita "Impossibile trovare la funzione '%-.128s' nella libreria" + jpn "function '%-.128s' ¤ò¥é¥¤¥Ö¥é¥ê¡¼Ãæ¤Ë¸«ÉÕ¤±¤ë»ö¤¬¤Ç¤­¤Þ¤»¤ó" + kor "¶óÀ̹ö·¯¸®¿¡¼­ '%-.128s' ÇÔ¼ö¸¦ ãÀ» ¼ö ¾ø½À´Ï´Ù." + por "Não pode encontrar a função '%-.128s' na biblioteca" + rum "Nu pot gasi functia '%-.128s' in libraria" + rus "îÅ×ÏÚÍÏÖÎÏ ÏÔÙÓËÁÔØ ÆÕÎËÃÉÀ '%-.128s' × ÂÉÂÌÉÏÔÅËÅ" + serbian "Ne mogu da pronadjem funkciju '%-.128s' u biblioteci" + slo "Nemô¾em nájs» funkciu '%-.128s' v kni¾nici" + spa "No puedo encontrar función '%-.128s' en libraria" + swe "Hittar inte funktionen '%-.128s' in det dynamiska biblioteket" + ukr "îÅ ÍÏÖÕ ÚÎÁÊÔÉ ÆÕÎËæÀ '%-.128s' Õ Â¦Â̦ÏÔÅæ" ER_FUNCTION_NOT_DEFINED cze "Funkce '%-.64s' nen-Bí definována" dan "Funktionen '%-.64s' er ikke defineret" diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 40e5a9a00cf..c5badd85a6a 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -432,6 +432,7 @@ int mysql_create_function(THD *thd,udf_func *udf) } if (!(dl = find_udf_dl(udf->dl))) { + DBUG_PRINT("info", ("Calling dlopen, udf->dl: %s", udf->dl)); if (!(dl = dlopen(udf->dl, RTLD_NOW))) { DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)", diff --git a/sql/udf_example.cc b/sql/udf_example.cc index 6ce66157101..03ce76f68dd 100644 --- a/sql/udf_example.cc +++ b/sql/udf_example.cc @@ -113,6 +113,8 @@ */ #ifdef STANDARD +/* STANDARD is defined, don't use any mysql functions */ +#include #include #include #ifdef __WIN__ @@ -125,10 +127,10 @@ typedef long long longlong; #else #include #include +#include // To get strmov() #endif #include -#include -#include // To get strmov() +#include static pthread_mutex_t LOCK_hostname; @@ -289,8 +291,8 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, for (n = ntrans + 1, n_end = ntrans + sizeof(ntrans)-2; word != w_end && n < n_end; word++ ) - if ( my_isalpha ( &my_charset_latin1, *word )) - *n++ = my_toupper ( &my_charset_latin1, *word ); + if ( isalpha ( *word )) + *n++ = toupper ( *word ); if ( n == ntrans + 1 ) /* return empty string if 0 bytes */ { From f53afa23e6d5ac33a733dc1bf07344dc59c79098 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Mar 2006 12:08:53 +0100 Subject: [PATCH 4/6] Improve mysqltest Add comment's for enable/disable_query_log and enable/disable_result_log Update comment for "check_result" Add check in "handle_error" that detects if the server crashed when running a "require" query to check if a certain feature is available client/mysqltest.c: Add comment's for enable/disable_query_log and enable/disable_result_log Update comment for "check_result" Add check in "handle_error" that detects if the server crashed when running a "require" query to check if a certain feature is available --- client/mysqltest.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index beb76317f40..715bca853cb 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -393,8 +393,10 @@ const char *command_names[]= "enable_rpl_parse", "disable_rpl_parse", "eval_result", + /* Enable/disable that the _query_ is logged to result file */ "enable_query_log", "disable_query_log", + /* Enable/disable that the _result_ from a query is logged to result file */ "enable_result_log", "disable_result_log", "server_start", @@ -753,8 +755,8 @@ err: check_result ds - content to be checked fname - name of file to check against - require_option - if set and check fails, the test will be aborted with the special - exit code "not supported test" + require_option - if set and check fails, the test will be aborted + with the special exit code "not supported test" RETURN VALUES error - the function will not return @@ -3481,7 +3483,17 @@ static void handle_error(const char *query, struct st_query *q, DBUG_ENTER("handle_error"); if (q->require_file) + { + /* + The query after a "--require" failed. This is fine as long the server + returned a valid reponse. Don't allow 2013 or 2006 to trigger an + abort_not_supported_test + */ + if (err_errno == CR_SERVER_LOST || + err_errno == CR_SERVER_GONE_ERROR) + die("require query '%s' failed: %d: %s", query, err_errno, err_error); abort_not_supported_test(); + } if (q->abort_on_error) die("query '%s' failed: %d: %s", query, err_errno, err_error); From 4fb909838b9eadbb9fc0b13772487b118bbc7f77 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Mar 2006 12:12:08 +0100 Subject: [PATCH 5/6] Update test results for udf Remove STANDARD define when compile udf_example.so mysql-test/r/udf.result: Update results mysql-test/t/udf.test: Update test try to create, use and drop a non existing function Disable the result from "reverse_lookup" as it is config dependent sql/Makefile.am: Remove the "STANDARD" define when compiling udf_example.so --- mysql-test/r/udf.result | 15 ++++++++------- mysql-test/t/udf.test | 12 +++++++++--- sql/Makefile.am | 1 - 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result index 19f67eda429..ce9271224dc 100644 --- a/mysql-test/r/udf.result +++ b/mysql-test/r/udf.result @@ -1,8 +1,9 @@ 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_nonexist RETURNS INTEGER SONAME 'udf_example.so'; +ERROR HY000: Can't find function 'myfunc_nonexist' in library 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 @@ -17,8 +18,11 @@ myfunc_double(1) select myfunc_double(78654); myfunc_double(78654) 54.00 +select myfunc_nonexist(); +ERROR 42000: FUNCTION test.myfunc_nonexist does not exist select myfunc_int(); -ERROR 42000: FUNCTION test.myfunc_int does not exist +myfunc_int() +0 select lookup(); ERROR HY000: Wrong arguments to lookup; Use the source select lookup("127.0.0.1"); @@ -32,11 +36,7 @@ lookup("localhost") 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 @@ -78,8 +78,9 @@ HL drop procedure xxx2; DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; +DROP FUNCTION myfunc_nonexist; +ERROR 42000: FUNCTION test.myfunc_nonexist does not exist DROP FUNCTION myfunc_int; -ERROR 42000: FUNCTION test.myfunc_int does not exist DROP FUNCTION sequence; DROP FUNCTION lookup; DROP FUNCTION reverse_lookup; diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index ebe21d20362..c9f22cf410b 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -17,9 +17,8 @@ drop table if exists t1; 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 ER_CANT_FIND_DL_ENTRY +CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME 'udf_example.so'; 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'; @@ -33,6 +32,7 @@ select myfunc_double(); select myfunc_double(1); select myfunc_double(78654); --error 1305 +select myfunc_nonexist(); select myfunc_int(); --error 0 select lookup(); @@ -42,9 +42,14 @@ select lookup(127,0,0,1); select lookup("localhost"); --error 0 select reverse_lookup(); + +# 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 select reverse_lookup("127.0.0.1"); ---error 0 select reverse_lookup(127,0,0,1); +--enable_result_log + select reverse_lookup("localhost"); --error 0 select avgcost(); @@ -94,6 +99,7 @@ drop procedure xxx2; DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; --error ER_SP_DOES_NOT_EXIST +DROP FUNCTION myfunc_nonexist; DROP FUNCTION myfunc_int; DROP FUNCTION sequence; DROP FUNCTION lookup; diff --git a/sql/Makefile.am b/sql/Makefile.am index 9b818f7c389..1597ad2c4a8 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -156,7 +156,6 @@ lex_hash.h: gen_lex_hash$(EXEEXT) # For testing of udf_example.so noinst_LTLIBRARIES= udf_example.la udf_example_la_SOURCES= udf_example.cc -udf_example_la_CXXFLAGS= -DSTANDARD udf_example_la_LDFLAGS= -module -rpath $(pkglibdir) From 680ba0b7d93a2429cc24ae6e397e0a789b4e269d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Mar 2006 19:55:38 +0100 Subject: [PATCH 6/6] Don't look for "dlopen" if server linked with -static or -all-static flag. Update after review configure.in: Don't look for "dlopen" if server linked with -static or -all-static flag --- configure.in | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index e8e2bdb7951..7fe92ad1467 100644 --- a/configure.in +++ b/configure.in @@ -1545,11 +1545,13 @@ fi #---END: # dlopen, dlerror -case $with_mysqld_ldflags in +case "$with_mysqld_ldflags " in - *-all-static*) + *"-static "*) # No need to check for dlopen when mysqld is linked with - # -all-static as it won't be able to load any functions. + # -all-static or -static as it won't be able to load any functions. + # NOTE! It would be better if it was possible to test if dlopen + # can be used, but a good way to test it couldn't be found ;;