(mysql.info) udf-return-values
Info Catalog
(mysql.info) udf-arguments
(mysql.info) adding-udf
(mysql.info) udf-compiling
24.2.4.4 UDF 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
is 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 function should return
a pointer to the result and set `*result' and `*length' to the contents
and length of the return value. For example:
memcpy(result, "result string", 13);
*length = 13;
The `result' buffer that is passed to the `xxx()' function is 255 bytes
long. If your result fits in this, you don't have to worry about memory
allocation for results.
If your string function 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. See
udf-calling.
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 `*error' 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()' is not even called
for subsequent rows.)
Info Catalog
(mysql.info) udf-arguments
(mysql.info) adding-udf
(mysql.info) udf-compiling
automatically generated byinfo2html