I am having a problem using a User Defined Function in mysql 5.7.13 (Linux) :
This function is defined in mysql using :
CREATE FUNCTION PHPParse RETURNS STRING SONAME 'php_parser.so'
The C (& C++) file are the following :
my_bool PHPParse_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void PHPParse_deinit(UDF_INIT *initid);
char* PHPParse(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error);
my_bool PHPParse_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
initid->maybe_null = 1;
if (args->arg_count != 2 || args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)
{
strcpy(message,"PHPParse (p_field_name, p_php_parser_string)");
return 1;
}
initid->max_length=256;
return 0;
}
char* PHPParse(UDF_INIT *initid MY_ATTRIBUTE((unused)), UDF_ARGS *args, char *result, unsigned long *length,char *is_null, char *error MY_ATTRIBUTE((unused)))
{
*is_null = 0;
memcpy(result,"begginning",10);
*length= (unsigned long)(10);
return result;
}
If I use the following SQL Query :
SELECT PHPParse('hello','222') as `date` FROM invoices ;
I get this result :
date:
62656767696e6e696e67
62656767696e6e696e67
62656767696e6e696e67
62656767696e6e696e67
etc...
While it would be supposed to return begginning
Where am i wrong ?
P.S Compile command :
g++ -std=c++11 -fPIC -shared -I/usr/include/mysql -o /usr/lib64/mysql/plugin/php_parser.so include/PHPSerializedDataLoader.cpp PHPParse.cc