Please, tell me: ¿what´s wrong with this C udf?
The SQLUDF_VARCHAR_FBD length member comes modified, but the data member comes in all NULLs.
The UDF can be tested and works fine in MS Visual C.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sqludf.h>
#include <sqlca.h>
#include <sqlda.h>
#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN hextobin(
SQLUDF_VARCHAR *sHexStrIn
, SQLUDF_VARCHAR_FBD *sBinStrOut
, SQLUDF_NULLIND *sHexStrInNullInd
, SQLUDF_NULLIND *sBinStrOutNullInd)
{
int pos = 0 ;
int lenInW = 0 ;
int lenIn = 0;
lenInW = strlen(sHexStrIn) ;
lenIn = (int) lenInW / 2 ;
if (lenInW % 2 == 0 && sBinStrOut->length >= lenIn)
{
for (pos = 0 ; pos < lenIn; pos = pos + 1)
{
sscanf ( &sHexStrIn[pos*2], "%2x", &sBinStrOut->data[pos]) ;
}
sBinStrOut->length = lenIn ;
}
else
sBinStrOut->length = 0;
return ;
}
CREATE FUNCTION hextobin(VARCHAR (32000))
RETURNS VARCHAR (32000) FOR BIT DATA
EXTERNAL NAME '/home/db2inst1/sqllib/function/hextobin!hextobin'
LANGUAGE C
PARAMETER STYLE DB2SQL
NOT FENCED
NOT NULL CALL
NOT VARIANT
NO SQL
NO EXTERNAL ACTION
NO SCRATCHPAD
NO FINAL CALL
ALLOW PARALLEL
NO DBINFO;