namespace mysql { #include #include } /*************************************************************************** * COSH * * This file was made by Roland Bouman in response to Valeriy Kravchuk's * request for feedback concerning bug 15439. * * This is a bogus implementation of the hyperbolic cosine function. * In the original file, it attempts to minimic the behaviour of Oracle's * COSH function. * During this process some bugs were encountered in the MySQL handling of * UDF definition. The exact same buggy behaviour can be observed using this * file. Below, a sequence of SQL statements is printed that were executed * with this file, not the original. * * Implementing it as a MySQL UDF has led to two different problems sofar. * * At first it was created as cosh (no capital H). * Whenever it was called, it always returned 1.0 * This is a truly bizarre result, because our UDF returns a constant 0.0 * It appeared as if our own function cosh never got called. * (I will file a separate bug report for that one) * * By coincidence, it was found that creating the function with a capital H * does work as expected. * However, it has to be created referring to cosH (with the capital H); * This holds true even if the function name is not quoted. * * The function can then be dropped referring to just cosh (no Capital) * From then on, the function cosH is no longer accessible. * For instance, it cannot be dropped again. * However, the corresponding entry in the mysql.func table remains. * As a result, recreating the function fails: * * ERROR 1026 (HY000): Error writing file 'mysql.func' (errno: 121) * * At this point, one can manually delete the offending entry from the * mysql.func table; after that, all's well again as far as could be observed. * * May the following script clarify the problem * use mysql; Database changed select * from func; Empty set (0.00 sec) create function cosh returns real soname 'MySQLUDFCosHBug.dll'; ERROR 1127 (HY000): Can't find function 'cosh' in library' create function cosH returns real soname 'MySQLUDFCosHBug.dll'; Query OK, 0 rows affected (0.00 sec) select * from func; +------+-----+---------------------+----------+ | name | ret | dl | type | +------+-----+---------------------+----------+ | cosH | 1 | MySQLUDFCosHBug.dll | function | +------+-----+---------------------+----------+ 1 row in set (0.00 sec) select cosh(); +------------------+ | cosh() | +------------------+ | 0.00000000000000 | +------------------+ 1 row in set (0.00 sec) drop function cosh; Query OK, 0 rows affected (0.00 sec) select cosh(); ERROR 1305 (42000): FUNCTION mysql.cosh does not exist select * from func; +------+-----+---------------------+----------+ | name | ret | dl | type | +------+-----+---------------------+----------+ | cosH | 1 | MySQLUDFCosHBug.dll | function | +------+-----+---------------------+----------+ 1 row in set (0.00 sec) drop function `cosH`; ERROR 1305 (42000): FUNCTION mysql.cosH does not exist create function cosH returns real soname 'MySQLUDFCosHBug.dll'; ERROR 1026 (HY000): Error writing file 'mysql.func' (errno: 121) delete from func where name = 'cosH'; Query OK, 1 row affected (0.00 sec) select * from func; Empty set (0.00 sec) * * ***************************************************************************/ extern "C" __declspec (dllexport) mysql::my_bool cosh_init( mysql::UDF_INIT* initid , mysql::UDF_ARGS* args , char *message ){ initid->decimals = 14; initid->max_length = 32; return 0; } extern "C" __declspec (dllexport) double cosh( mysql::UDF_INIT *initid , mysql::UDF_ARGS *args , char *is_null , char *error ){ return 12.0; }