Return Values and Error Handling
................................
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. The message
will be returned to the client. The message buffer is
`MYSQL_ERRMSG_SIZE' characters long, but you should try to keep the
message to less than 80 characters so that it fits the width of a
standard terminal screen.
The return value of the main function `xxx()' is the function value, for
`long long' and `double' functions. A string functions should return a
pointer to the result and store the length of the string in the
`length' arguments. `result' is a buffer at least 255 bytes long. Set
these to the contents and length of the return value. For example:
memcpy(result, "result string", 13);
*length = 13;
If your string functions that needs to return a string longer than 255
bytes, you must allocate the space for it with `malloc()' in your
`xxx_init()' function or your `xxx()' function and free it in your
`xxx_deinit()' function. You can store the allocated memory in the
`ptr' slot in the `UDF_INIT' structure for reuse by future `xxx()'
calls. Note:UDF calling sequences.
To indicate a return value of `NULL' in the main function, set
`is_null' to `1':
*is_null = 1;
To indicate an error return in the main function, set the `error'
parameter to `1':
*error = 1;
If `xxx()' sets `*error' to `1' for any row, the function value is
`NULL' for the current row and for any subsequent rows processed by the
statement in which `XXX()' was invoked. (`xxx()' will not even be
called for subsequent rows.) *NOTE:* In MySQL versions prior to
3.22.10, you should set both `*error' and `*is_null':
*error = 1;
*is_null = 1;