Subject Re: [firebird-support] UDF with string functions
Author Helen Borrie
At 04:45 PM 19/07/2004 +0000, you wrote:
>Hi, all.
>
>I need an UDF which returns me a substring and the
>string length of a VARCHAR.

UDFs can't return multiple values.


>The SUBSTR function in ib_udf.dl doesn't support
>VARCHARs longer than 80 chars (though it is suposed
>in the documentation).

Declare string UDFs with cstring sizes that are long enough to accommodate
your varchars (up to a limit of 32,765 bytes).


>What I wan't to do is extracting PKs from a string
>which is delivered by my app.

If you're using Firebird, don't use a UDF for substring, use the
SUBSTRING() internal function.

You can use the ib_udf function strlen() to get the length of a string.


>Any ideas or a link to a UDF which has the described
>functionality?
With any string UDFs, declare UDFs with the max. string sizes that you
need. For example, here's the standard declaration for LTRIM in ib_udf.sql:

DECLARE EXTERNAL FUNCTION ltrim
CSTRING(80)
RETURNS CSTRING(80) FREE_IT
ENTRY_POINT 'IB_UDF_ltrim' MODULE_NAME 'ib_udf';

If 80 is ok for your purposes, declare it "as is". Then, later, you find
you need a longer string for a certain stored procedure. Just add another
declaration:

DECLARE EXTERNAL FUNCTION ltrim200
CSTRING(200)
RETURNS CSTRING(200) FREE_IT
ENTRY_POINT 'IB_UDF_ltrim' MODULE_NAME 'ib_udf';

Now you have two ltrim functions in your database: one (ltrim) with an
80-byte max. size and the other (ltrim200) with a 200-byte max.

/heLen