Subject | Re: [firebird-support] Problem with double precision in UDFs |
---|---|
Author | Ivan Prenosil |
Post date | 2008-12-23T19:37:35Z |
> I have written a simple UDF, which gets a double value and shouldWhen using descriptors, input parameters are passed using the type
> return it:
>
> DECLARE EXTERNAL FUNCTION RETURN_DOUBLE
> DOUBLE PRECISION BY DESCRIPTOR
> RETURNS DOUBLE PRECISION FREE_IT
> ENTRY_POINT 'udf_return_double' MODULE_NAME 'my_udf_lib';
>
> double* udf_return_double(PARAMDSC* par)
> {
> if(!par || (par->dsc_flags & DSC_null)) return 0;
> double* value = (double*) par->dsc_address;
> double* result = ib_util_malloc(8);
>
> *result = *value;
>
> return result;
> }
>
> Now I am trying to call it like this:
>
> select return_double(1.0) from RDB$CHARACTER_SETS
>
> And the result I get is 0. Why is that?
of parameter value, not using declared Double Precision (that part
of declaration is actually ignored!).
I.e. "1.0" is passed to udf as NUMERIC(18,1)
Also, it is easier to return simple datatypes (integers, double precision, ...)
by value (then you do not need ib_util_malloc), i.e.
RETURNS DOUBLE PRECISION BY VALUE
Ivan
http://www.volny.cz/iprenosil/interbase/