If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What´s wrong with this C UDF?? (VARCHAR FOR BIT DATA)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-04, 21:19
buckfast buckfast is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
What´s wrong with this C UDF?? (VARCHAR FOR BIT DATA)

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;
Attached Files
File Type: txt hextobin.aix.txt (320 Bytes, 31 views)
File Type: txt hextobin.c.txt (733 Bytes, 36 views)
File Type: txt hextobin.exp.txt (14 Bytes, 35 views)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On