Subject Setting VARCHAR length in a FB UDF
Author Fred P.
Hi,

Could someone please tell me the proper way to set the length of a
VARCHAR return value in a (FireBird 1.5 RC4) UDF function?

I've tried the obvious: a VARCHAR is represented as a unsigned short
followed by character array. So, just set the unsigned short to the
length in bytes and you're done--that's what isql is passing as an
input parameter to my UDF function. However, when I return a similarly
formatted return value, isql "appears" to see it as having a zero
length.

After much web searching, I found one source that suggested that one
should set the most significant byte of the unsigned short to
something other that 0x00. They suggested a space character (' ') of
all things. This sounded too strange not to give it a try. :-)

To my shock, this "sort of" works. Now isql sees the returned VARCHAR
characters. However, it sometimes truncates them. So, it is time to
ask for help!! Any informed suggestions would be greatly appreciated.


Thanks,
Fred
P.S. Below is my external function declaration, if that helps.

-----------------------
mylib.sql:
DECLARE EXTERNAL FUNCTION hextoraw
VARCHAR(256) CHARACTER SET ASCII
RETURNS VARCHAR (128) CHARACTER SET OCTETS FREE_IT
ENTRY_POINT 'fn_hextoraw' MODULE_NAME 'mylib';