Fix small bug in udf_example.cc, it was processing one char too much and thus returning junk

Add more DBUG_PRINT's in udf_handler::val_str
Enable udf.test
parent b1c38010
...@@ -11,4 +11,3 @@ ...@@ -11,4 +11,3 @@
############################################################################## ##############################################################################
ndb_load : Bug#17233 ndb_load : Bug#17233
udf : Not yet
...@@ -2734,9 +2734,10 @@ String *udf_handler::val_str(String *str,String *save_str) ...@@ -2734,9 +2734,10 @@ String *udf_handler::val_str(String *str,String *save_str)
{ {
uchar is_null_tmp=0; uchar is_null_tmp=0;
ulong res_length; ulong res_length;
DBUG_ENTER("udf_handler::val_str");
if (get_arguments()) if (get_arguments())
return 0; DBUG_RETURN(0);
char * (*func)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *)= char * (*func)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *)=
(char* (*)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *)) (char* (*)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *))
u_d->func; u_d->func;
...@@ -2746,22 +2747,26 @@ String *udf_handler::val_str(String *str,String *save_str) ...@@ -2746,22 +2747,26 @@ String *udf_handler::val_str(String *str,String *save_str)
if (str->alloc(MAX_FIELD_WIDTH)) if (str->alloc(MAX_FIELD_WIDTH))
{ {
error=1; error=1;
return 0; DBUG_RETURN(0);
} }
} }
char *res=func(&initid, &f_args, (char*) str->ptr(), &res_length, char *res=func(&initid, &f_args, (char*) str->ptr(), &res_length,
&is_null_tmp, &error); &is_null_tmp, &error);
DBUG_PRINT("info", ("udf func returned, res_length: %lu", res_length));
if (is_null_tmp || !res || error) // The !res is for safety if (is_null_tmp || !res || error) // The !res is for safety
{ {
return 0; DBUG_PRINT("info", ("Null or error"));
DBUG_RETURN(0);
} }
if (res == str->ptr()) if (res == str->ptr())
{ {
str->length(res_length); str->length(res_length);
return str; DBUG_PRINT("exit", ("str: %s", str->ptr()));
DBUG_RETURN(str);
} }
save_str->set(res, res_length, str->charset()); save_str->set(res, res_length, str->charset());
return save_str; DBUG_PRINT("exit", ("save_str: %s", save_str->ptr()));
DBUG_RETURN(save_str);
} }
......
...@@ -344,7 +344,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -344,7 +344,7 @@ char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result,
KSflag = 0; /* state flag for KS translation */ KSflag = 0; /* state flag for KS translation */
for (metaph_end = result + MAXMETAPH, n_start = n; for (metaph_end = result + MAXMETAPH, n_start = n;
n <= n_end && result < metaph_end; n++ ) n < n_end && result < metaph_end; n++ )
{ {
if ( KSflag ) if ( KSflag )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment