Alin wrote:
I'm using Firebird 2.1.0.17798.
I declared in a database the following function:
DECLARE EXTERNAL FUNCTION RTRIM CSTRING (255) RETURNS CSTRING (255) FREE_IT ENTRY_POINT 'IB_UDF_rtrim' MODULE_NAME 'ib_udf';
and it worked!
I can't understand why the next one doesn't work!
DECLARE EXTERNAL FUNCTION lpad CSTRING(255) NULL, INTEGER, CSTRING(1) NULL RETURNS CSTRING(255) FREE_IT ENTRY_POINT 'IB_UDF_lpad' MODULE_NAME 'ib_udf';
Can somebody help me to declare this function?
Helen Borrie answers:
Firebird 2.1 has an internal function named LPAD (name is case-insensitive). So, if you want to keep using the external function, you will have to drop the current declaration and declare it with the same name in upper case enclosed in double quotes. The engine will then choose the UDF and not call the internal function. This is documented.
DECLARE EXTERNAL FUNCTION "LPAD" CSTRING(255) NULL, INTEGER, CSTRING(1) NULL RETURNS CSTRING(255) FREE_IT ENTRY_POINT 'IB_UDF_lpad' MODULE_NAME 'ib_udf';
But this is not a great idea, IMO, if you can avoid it. The internal function will work with your existing function calls if you simply drop the UDF declaration altogether.
The only gotcha with this is if you are calling this UDF from legacy compiled PSQL code modules (triggers or procedures). In that case you will have (a) dependencies and (b) old compiled code that didn't know about the internal function. The solution here is to recompile the modules (using ALTER TRIGGER or ALTER PROCEDURE with the entire source in the statement). Do I need to remind you to do this in exclusive mode after a complete database shutdown.....?