Subject Re: [firebird-support] UDF:s and nulls
Author Ivan Prenosil
> Thanks Ivan - your doc was very instructive! I have one question though
> (below).
>
> Ivan Prenosil wrote:
>> * NULL can be returned from UDF, provided the value
>> is passed by reference, not by value.
>
> How? Set the returned pointer to nil (nil in pascal terms = null in C
> terms).

Yes. Here is example:

function TestNull (i: PInteger): PInteger; cdecl;
begin
Result := nil;
if (i<>nil) and (i^ > 0)
then
begin
Result := ib_util_malloc(SizeOf(Integer));
Result^ := 10*i^;
end;
end;

DECLARE EXTERNAL FUNCTION TestNull
INTEGER
RETURNS INTEGER FREE_IT
ENTRY_POINT 'TestNull'
MODULE_NAME 'TestUDF';



select TestNull(456) from rdb$database;
TESTNULL
===========
4560

select TestNull(-456) from rdb$database;
TESTNULL
===========
<null>


Ivan
http://www.volny.cz/iprenosil/interbase/