473,507 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UDF call to C wrapper returning SQLUDF_VARCHAR fails

Hi,

I am trying to implement an MD5 checksum function using an UDF call to
C wrapper returning the MD5 checksum. I've downloaded a free (LGPL)
implementation in C of the MD5 algorithm from
http://xyssl.org/code/source/md5/. With help from our friends over at
comp.lang.c, I've managed to compile, link and run the code. However,
when I call it from DB2, I can invoke it once only.

I suspect the error has to do with freeing of memory, but my limited C
skills keep me from understanding why.

// md5.c
#include "md5.h"
#include <sqludf.h>
#include <stdio.h>
#include <string.h>

void md5 (
// input parameters
SQLUDF_VARCHAR_FBD *input,
// output
SQLUDF_VARCHAR *output,

// null indicators
SQLUDF_NULLIND *inputNull_ind,
SQLUDF_NULLIND *outputNull_ind,
SQLUDF_TRAIL_ARGS
)
{
int i;
unsigned char *uc_tmp;
char c[10];
char md5ascii[128];

if (*inputNull_ind == -1)
{
*outputNull_ind = -1;
}
else
{
// Compute binary checksum
md5_csum( (uchar *) input, input->length, uc_tmp );

// Convert binary checksum to ascii
memset(md5ascii, 0, sizeof(md5ascii));
for (i = 0; i < 16; i++) {
snprintf(c, sizeof(c), "%0x", uc_tmp[i]);
strncat(md5ascii, c, sizeof(md5ascii) - 1);
}

// Copy ascii checksum to output pointer
strcpy(output, md5ascii);

*outputNull_ind = 0;
return;
}
}

$ # compile, link and install
$ gcc -c -o md5.o -I../md5_xyssl -I/home/db2inst1/sqllib/include
md5.c ../md5_xyssl/md5.c -D_REENTRANT
$ gcc -o md5 -shared -fpic md5.o
$ sudo su
# cp md5 /home/db2inst1/sqllib/function

-- md5.sql
DROP FUNCTION MD5;
CREATE FUNCTION MD5
(HASH VARCHAR(32000))
RETURNS VARCHAR(32)
SPECIFIC MD5
EXTERNAL NAME 'md5!md5'
NOT FENCED
RETURNS NULL ON NULL INPUT
DETERMINISTIC
NO SQL
NO EXTERNAL ACTION
LANGUAGE C
PARAMETER STYLE SQL
ALLOW PARALLEL;

$ db2 "select FIRSTNME, MD5(FIRSTNME) AS MD5SUM from employee fetch
first 5 rows only"

FIRSTNME MD5SUM
------------ --------------------------------
CHRISTINE 86b83514912a7ff1386e522c5bfd7330
MICHAEL cce39636156586527630722a64883c7
SALLY 82ac3ac8667126e51494af39a97d1
JOHN c4baad2cbe78654d7902c726be7e2
IRVING b3c9701751a843882dde77fa165bb7f6

5 record(s) selected.

$ db2 "select FIRSTNME, MD5(FIRSTNME) AS MD5SUM from employee fetch
first 5 rows only"

FIRSTNME MD5SUM
------------ --------------------------------
SQL0444N Routine "DB2INST1.MD5" (specific name "MD5") is implemented
with
code in library or path "??p Q?C?-?w? [??qllib/function/md5", function
"md5"
which cannot be accessed. Reason code: "4". SQLSTATE=42724

--
Serman D.

Feb 26 '07 #1
0 1571

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1699
by: Nilsson Mats | last post by:
Hi! I have an intresting problem for our programming community on Solaris. I want to develop an environment where: 1) The developers shouldn't need to bother about which Perl version to use....
5
2655
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
1
1882
by: Lister Monocle | last post by:
Seemingly simple problem. I have a wrapper div with a border. Inside is a content div, which uses relative positioning to move it down a bit from the top of the wrapper border -- I used positioning...
3
1853
by: 4.spam | last post by:
Hello. v8.2.1, Windows. I have a default installation on Windows where instance owner has administrative rights in the system. In this case user with only CREATE_EXTERNAL_ROUTINE authority and...
2
5669
by: Serman D. | last post by:
Hi all, I'm trying to complete the samples from the excellent 2003 developerWorks article "Bringing the Power of Regular Expression Matching to SQL" by Knut Stolze: http://tinyurl.com/3bhrnn...
54
5135
by: Zytan | last post by:
I have a log class that makes a synchronized TextWriter like so, in the constructor: StreamWriter sw = new StreamWriter(filename); tw = TextWriter.Synchronized(sw); In the destructor,...
2
3005
by: 4.spam | last post by:
Hello, all. DB2 ESE v9.1.3, Windows XP. I want to change the application name of current connection. I have wrote such SP using sqleseti api call: --- #include <sqlenv.h> #include...
0
891
by: mugo4real | last post by:
I have used tlbimp.exe to create a wrapper dll for shell32.dll My code referencing this wrapper dll works perfectly when I use it in a console application. The exact same code fails...
0
11244
ashitpro
by: ashitpro | last post by:
Writing System Call Wrappers in User Space. Recently I saw a post in Linux/Unix section to know the user who deleted the file in linux. Currently there is nothing in linux which could achieve...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.