Writing Firebird UDFs Returning OCTETS

We use a binary value that is stored in tables as CHAR (18) CHARACTER SET OCTETS.

In Firebird 2.0.4, we used ASCII as the default database character set and connection character set. We have a UDF that can generate the required data, which is defined as:

DECLARE EXTERNAL FUNCTION CREATEBINARY
RETURNS CSTRING(76) 
ENTRY_POINT 'CREATEBINARY'
MODULE_NAME 'CustomUDF';

      

Retrieving a value using

SELECT CREATEBINARY() FROM RDB$DATABASE

      

returns the expected value.

In Firebird 2.5.2, we use UTF8 as both the default database character set and the connection character set. When trying to call our UDF with the above select clause, now an error occurs:

Context: Statement::Fetch
Message: idx_dsql_fetch failed.

SQL Message: -104
Invalid Token

Engine Code: 335544849
Engine Message:
Malformed string

      

I've tried modifying the function declaration to specify the character set of the result as OCTETS and NONE:

DECLARE EXTERNAL FUNCTION CREATEBINARY
RETURNS CSTRING(76) CHARACTER SET OCTETS
ENTRY_POINT 'CREATEBINARY'
MODULE_NAME 'CustomUDF';

      

but I still get the same result.

I've tested this in FlameRobin 0.9.3.1870 and in our application using Delphi XE2 Update 4 and IBObjects 4.9 Release 14. Both don't work the same.

+3


source to share


1 answer


The problem is the wrong size specified for the return result. Change ad to

DECLARE EXTERNAL FUNCTION CREATEBINARY
RETURNS CSTRING(18) CHARACTER SET OCTETS
ENTRY_POINT 'CREATEBINARY'
MODULE_NAME 'CustomUDF';

      



the function works correctly.

+2


source







All Articles