MySQL Forums
Forum List  »  UDF

UDF with char* arguments problem - overriding arguments during same connection in a query
Posted by: Piotr Kaczorowski
Date: November 05, 2013 11:56AM

Hello!

My mysql is: Server version: 5.5.34-0ubuntu0.13.10.1

I wrote "white_similarity" UDF function and call it from a query:

select name,white_similarity(name,"Straight Checkn 'em") as score from album_external.


The UDF function is:
double white_similarity(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* is_null __attribute__((unused)), char* error __attribute__((unused))) {
char* str1 = args->args[0];
char* str2 = args->args[1];

fprintf(stderr, "white_similarity str1: %s\n", str1);
fprintf(stderr, "white_similarity str2: %s\n", str2);

fflush(stderr);

return 0;
}

In album_external I have following data:
Music To Gang Bang
Represent
Music To Driveby
Music To Driveby
Straight Checkn' Em
It's A Compton Thang!
When We Wuz Bangin
Boyz N The Hood Motion Picture Sound Track
The Best of MC Eiht
Boyz N The Hood
Boyz N The Hood


After first call in mysql.log:

white_similarity str1: Music To Gang Bang
white_similarity str2: Straight Checkn 'em
white_similarity str1: RepresentGang Bang
white_similarity str2: Straight Checkn 'em
white_similarity str1: Music To Drivebyng
white_similarity str2: Straight Checkn 'em
white_similarity str1: Music To Drivebyng
white_similarity str2: Straight Checkn 'em
white_similarity str1: Straight Checkn' Em
white_similarity str2: Straight Checkn 'em
white_similarity str1: It's A Compton Thang!
white_similarity str2: Straight Checkn 'em
white_similarity str1: When We Wuz Banginng!
white_similarity str2: Straight Checkn 'em
white_similarity str1: Boyz N The Hood Motion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: The Best of MC Eihtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Boyz N The HoodEihtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Boyz N The HoodEihtion Picture Sound Track
white_similarity str2: Straight Checkn 'em

After second call:
white_similarity str1: Music To Gang Bangtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: RepresentGang Bangtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Music To Drivebyngtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Music To Drivebyngtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Straight Checkn' Emion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: It's A Compton Thang!n Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: When We Wuz Banginng!n Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Boyz N The Hood Motion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: The Best of MC Eihtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Boyz N The HoodEihtion Picture Sound Track
white_similarity str2: Straight Checkn 'em
white_similarity str1: Boyz N The HoodEihtion Picture Sound Track
white_similarity str2: Straight Checkn 'em


The problem is that every argument is overwritten in the same place without '\0' on the end. Is it possible or I've done a mistake?

Options: ReplyQuote


Subject
Views
Written By
Posted
UDF with char* arguments problem - overriding arguments during same connection in a query
2456
November 05, 2013 11:56AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.