Improvements in Firebird 2
Firebird 2 comes with a somewhat improved calling mechanism for old-style UDFs.The engine will now pass NULL input as a null pointer to the function, if the function has been declared to the database with a NULL keyword after the argument(s) in question, e.g. like this:
declare external function ltrim
cstring(255) null
returns cstring(255) free_it
entry_point 'IB_UDF_ltrim' module_name 'ib_udf';
This requirement ensures that existing databases and their applications can continue to function like before.Leave out the NULL keyword and the function will behave like it did under Firebird 1.5 and earlier.
Please note that you can’t just add NULL keywords to your declarations and then expect every function to handle NULL input correctly.Each function has to be (re)written in such a way that NULLs are dealt with correctly.Always look at the declarations provided by the function implementor.For the functions in the ib_udf library, consult ib_udf2.sql in the Firebird UDF directory.Notice the 2 in the file name;the old-style declarations are in ib_udf.sql.
These are the ib_udf functions that have been updated to recognise NULL input and handle it properly:
-
ascii_char -
lower -
lpadandrpad -
ltrimandrtrim -
substrandsubstrlen
Most ib_udf functions remain as they were;in any case, passing NULL to an old-style UDF is never possible if the argument isn’t of a referenced type.
On a side note: don’t use lower, *trim and substr* in new code;use the internal functions LOWER, TRIM and SUBSTRING instead.
“Upgrading” ib_udf functions in an existing database
If you are using an existing database with one or more of the functions listed above under Firebird 2, and you want to benefit from the improved NULL handling, run the script ib_udf_upgrade.sql against your database.It is located in the Firebird misc\upgrade\ib_udf directory.