I am trying to create a simple UDF for firebird on Linux (in C compiled with GCC). The problem is that when I set the "return mechanism" as "by reference", when I call the function, the server crashes. When it is "by value," there is no problem.
Here are the functions I'm trying to write in C:
It works:
double round(double *);
double round(val)
double *val;
{
*val = *val * 100;
*val = (*val>= 0) ? (long)(*val + 0.5) : (long)(*val - 0.5);
*val = *val / 100;
return *val;
}
But this causes a server crash on a call:
char * proper_case(str)
char * str;
{
return str;
}
Here is the DDL:
DECLARE EXTERNAL FUNCTION "ROUND"
DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'round' MODULE_NAME 'my_udfs.so';
DECLARE EXTERNAL FUNCTION PROPCASE
CSTRING(10000)
RETURNS CSTRING(10000) FREE_IT
ENTRY_POINT 'proper_case' MODULE_NAME 'my_udfs.so';
I call the second function:
select propcase('abrakadabra') from rdb$database;
Firebird server crashes and the only error message I have is:
Statement failed, SQLSTATE = -902
Error reading data from the connection.
Can anyone advise? Any help would be appreciated!
The only information I forgot to provide is how I compile the .so file (maybe the key is here):
gcc -c -O -fpic my_udf.c
ld -G my_udf.o -lm -lc -o my_udf.so
cp my_udf.so /usr/lib/firebird/2.1/UDF/my_udfs.so