Question

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

In Firebird 2.0.4, we used a ASCII as both the default database character set and the 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 the value with

SELECT CREATEBINARY() FROM RDB$DATABASE

returns the expected value.

In Firebird 2.5.2, we are using UTF8 as both the default database character set and the connection character set. Trying to call our UDF with the above select statement now results in a an error:

Context: Statement::Fetch
Message: idx_dsql_fetch failed.

SQL Message: -104
Invalid Token

Engine Code: 335544849
Engine Message:
Malformed string

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

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

but I still receive the same error result.

I have tested this in FlameRobin 0.9.3.1870, and in our application using Delphi XE2 Update 4 and IBObjects 4.9 Release 14. Both fail in the same way.

Was it helpful?

Solution

The problem appears to be the incorrect size specified for the return result. Changing the declaration to

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

makes the function work correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top