Hi, Im experiencing some problems with strlen in a MySql UDF function.

My function takes 2 string parameters, when any of them is from a table 
field, strlen does not return the real length of the string, example:

long test(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
       long l1;

        if (args->args[0] == NULL || args->args[1] == NULL) {
                *is_null = 1;
                return 0;
        }

        l1 = strlen(args->args[0]);
        return l1;
}

assuming myTable has only 1 row and its value(field1) is "Test"

SELECT test(field1, 'somestring') FROM myTable;
it returns 311 when it should return 4;

but if do this:
SELECT test(CONCAT(field1, ' '), 'somestring') FROM myTable;
it returns 5 (4 + 1 space), which looks ok.

I dont know why, but seems like that field values passed to UDF functions 
are not NULL terminated.

Any help will be appreciated.

Thanks in advance.



_________________________________________________________________
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

Reply via email to