Hello,
I'm trying to build a UDF for MySQL 4.1.12. I'm running on Linux
(FedoraFC1). My UDF function seemed to blow up the server so I went to the
source and tried to build udf_example.cc.
Using the precompiled binaries for Linux and using the source distribution
for the same version (4.1.12) I was unable to build udf_example.cc as a
shared object (I followed the instructions in the source -- they didnt work
so I used what seemed to make the most sense for building my object). When
building the shared object the compiler spits out a warning from
asm/atomic.h (#warning Using kernel header in userland program. BAD!)
I'm using gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1) on a Fedore
Core 1 machine. I built the shared object with gcc -I/usr/include/mysql
-shared -o udf_example.so udf_example.cc
When attempting to load a new function with the mysql cli client the client
complains that the server has gone away and reconnects with connection id of
1. Nothing is listed in mysql.funcs either.
There needs to be better documentation of the process for building UDF's.
The code I need to run can be run nicely by MySQL but I can't declare a
stored function as documented. The stored function is fairly simple:
DELIMITER //
CREATE FUNCTION distance(z1 VARCHAR(10), z2 VARCHAR(10)) RETURNS REAL
BEGIN
DECLARE x REAL;
DECLARE y REAL;
DECALRE miles REAL;
SET x = 69.1*(lat - lat2);
SET y = 69.1*(lon1 - lon2) * COS(lon1*57.3);
SET miles = SQRT(x*x+y*y);
RETURN miles;
END
//
The mysql client spits back :
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '(z1 VARCHAR(10), z2 VARCHAR(10)) RETURNS REAL
Using the example given in the documentation I get:
mysql> CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50)
-> RETURN CONCAT('Hello, ',s,'!');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '(s CHAR(20)) RETURNS CHAR(50)
RETURN CONCAT('Hello, ',s,'!')' at line 1
DELIMITER ;
//
Can someone elucidate the mystery of either stored functions or UDF's?
Thanks, in advance,
Nic
--
Nic Stevens - [EMAIL PROTECTED]