A constant integer output UDF
To show the basic construction of a UDF we will start with a simple constant function that returns an integer. The output of this UDF will be the same no matter what arguments are passed to the UDF. To make the example a little more complex and to demonstrate the initid->ptr
usage we will allocate a small amount of memory upon initialization to store our integer. This example will be called udf_staticexample:
#include <stdlib.h> #include <string.h> #include <mysql.h>
These are the standard includes needed for this example. The header mysql.h
contains the structures and constants that we will use.
my_bool udf_staticexample_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
We are calling this UDF udf_staticexample
so all functions need to be prefixed with this. We start with the udf_staticexample_init()
function, which as we have seen before, prepares the UDF for execution in the context of an SQL statement.
long long *staticint =...