Hi,
I finally could get MySql UDF functions to work under win32 (VC++). The
only thing that concerns me is that it nevers returns any error message.
It works fine, but none error message is displayed.
The function expects 2 strings, if one, more or none is passed, I should get
the error message "Wrong arguments to rateStrings", but I dont, seems like
rateString_init() doesn't get called at all.
Any help will be appreciated.
Please see a sample code:
my_bool rateStrings_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void rateStrings_deinit(UDF_INIT *initid);
double rateStrings(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char
*error);
my_bool rateStrings_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (args->arg_count != 2 || args->arg_type[0] != STRING_RESULT ||
args->arg_type[1] != STRING_RESULT)
{
strcpy(message,"Wrong arguments to rateStrings; Use the source");
return 1;
}
return 0;
}
void rateStrings_deinit(UDF_INIT *initid)
{
}
double rateStrings(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char
*error)
{
double r;
long l1, l2;
char* tmpStr1;
char* tmpStr2;
if (args->args[0] == NULL || args->args[1] == NULL) {
*is_null = 1;
*error = 1;
return 0;
}
l1 = strlen(args->args[0]);
l2 = strlen(args->args[1]);
tmpStr1 = new char[l1+1];
tmpStr2 = new char[l2+1];
strcpy(tmpStr1, args->args[0]);
strcpy(tmpStr2, args->args[1]);
tmpStr1[l1] = '\0';
tmpStr2[l2] = '\0';
char* sourceStr1 = tmpStr1;
char* sourceStr2 = tmpStr2;
while(*sourceStr1)
*sourceStr1++ = toupper(*sourceStr1);
while(*sourceStr2)
*sourceStr2++ = toupper(*sourceStr2);
if (l1 == 0 || l2 == 0)
return 0;
if (strcmp(tmpStr1, tmpStr2) == 0)
return 1;
r = (double)subSim(1, l1, 1, l2, tmpStr1, tmpStr2) / (l1 + l2) * 2;
//subSim is not included in this message.
delete[] tmpStr1;
delete[] tmpStr2;
return r;
}
Regards,
Fabian von Romberg
_________________________________________________________________
Join the world�s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php