Hi Everyone,
I am trying to build a DB2 UDB UDF which can perform regex over the
table data. The user defined function will call an external .dll file
to do the task. I am referring to the following link for doing so:
http://www.ibm.com/developerworks/db...301stolze.html
While linking the below mentioned code, I am facing some errors. I
have installed PCRE and am using Visual C++ 6.0 in 32-bit mode. The
compilation of the code happens fine without any errors, but the
linking does not happen.
############### ############### #############
#include <pcre.h>
#include <sqludf.h>
void regexpSimple(
// input parameters
SQLUDF_VARCHAR *pattern, SQLUDF_CLOB *str,
// output
SQLUDF_INTEGER *match,
// null indicators
SQLUDF_NULLIND *pattern_ind, SQLUDF_NULLIND *str_ind,
SQLUDF_NULLIND *match_ind,
SQLUDF_TRAIL_AR GS)
{
pcre *re = NULL;
const char *error = NULL;
int errOffset = 0;
int rc = 0;
// we assume successful return
*match_ind = 0;
// compile the pattern to its internal representation
re = pcre_compile(pa ttern, 0 /* default options */, &error,
&errOffset, NULL);
if (re == NULL) {
snprintf(SQLUDF _MSGTX, 70, "Regexp compilation failed at "
"offset %d: %s\n", errOffset, error);
strcpy(SQLUDF_S TATE, "38900");
(*pcre_free)(re );
return;
}
// match the string againts the pattern
rc = pcre_exec(re, NULL, str->data, str->length, 0,
0 /* default options */, NULL, 0);
switch (rc) {
case PCRE_ERROR_NOMA TCH:
*match = 0;
break;
case PCRE_ERROR_BADO PTION:
snprintf(SQLUDF _MSGTX, 70, "An unrecognized bit was set in the
"
"options argument");
strcpy(SQLUDF_S TATE, "38901");
break;
case PCRE_ERROR_NOME MORY:
snprintf(SQLUDF _MSGTX, 70, "Not enough memory available.");
strcpy(SQLUDF_S TATE, "38902");
break;
default:
if (rc < 0) {
snprintf(SQLUDF _MSGTX, 70, "A regexp match error "
"occured: %d", rc);
strcpy(SQLUDF_S TATE, "38903");
}
else {
*match = 1;
}
break;
}
// cleanup
(*pcre_free)(re );
return;
}
############### ############### ###########
Error Message:
--------------------Configuration: regextest2 - Win32
Debug--------------------
Compiling...
StdAfx.cpp
Linking...
regextest2.obj : error LNK2001: unresolved external symbol
__imp__pcre_exe c
regextest2.obj : error LNK2001: unresolved external symbol
__imp__pcre_fre e
regextest2.obj : error LNK2001: unresolved external symbol _snprintf
regextest2.obj : error LNK2001: unresolved external symbol
__imp__pcre_com pile
Debug/regextest2.dll : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
regextest2.dll - 5 error(s), 0 warning(s)
############### ############### ###########
My environment is:
Windows XP Professional SP2 32-bit
Visual C++ 6.0
PCRE 7.0
DB2 UDB 8.2 32-bit
Can some one point me in the right direction to debug it. I already
have the db2 and pcre libraries and headers included in the directory
paths. I am not a C developer, so if I am missing something which is
very obvious, then I would request you to be a bit soft on me.
Regards,
dotyet