开发者

my_udf_init not called

开发者 https://www.devze.com 2023-04-04 02:06 出处:网络
This is my first time trying to create an udf for mysql. The docs state that my_func_init gets called prior to executing the main function, yet in my environment this does not seem to happen.

This is my first time trying to create an udf for mysql. The docs state that my_func_init gets called prior to executing the main function, yet in my environment this does not seem to happen.

long long charmatch(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
    return 42;
}

my_bool charmatch_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
    if (args->arg_count != 2)
    {
        strncpy(message, "charmatch() requires two arguments", 34);
        return EXIT_FAILURE;
        // was return EXIT_SUCCESS;
    }

    if(args->arg_type[0] != STRING_RESULT)
    {
        strncpy(message, "argument 1 must be a string"开发者_如何学C, 27);
        return EXIT_FAILURE;
        // was return EXIT_SUCCESS;
    }

    if(args->arg_type[0] != STRING_RESULT)
    {
        strncpy(message, "argument 2 must be a string", 27);
        return EXIT_FAILURE;
        // was return EXIT_SUCCESS;
    }

    return EXIT_SUCCESS;
}

As you can see, I'm checking whether there are two arguments. In theory SELECT CHARMATCH() should return a message saying I must set two arguments, but it's not: it return 42.

Why doesn't it return the message?

EDIT Seems like the problem was in my return values for errors being 0 instead of 1. I fixed it and now calling SELECT CHARMATCH() with the wrong number of arguments returns an empty set. Why are the errors not being displayed?


You always return EXIT_SUCCESS in charmatch_init(), but

"The initialization function should return 0 if no error occurred and 1 otherwise. If an error occurs, xxx_init() should store a null-terminated error message in the message parameter. "

http://dev.mysql.com/doc/refman/5.0/en/udf-return-values.html

I guess that's why your error messages are ignored.

0

精彩评论

暂无评论...
验证码 换一张
取 消