Oracle 5.0 Reference Manual page 2831

Table of Contents

Advertisement

The deinitialization function for xxx(). If present, it should deallocate any memory allocated by the
initialization function.
When an SQL statement invokes XXX(), MySQL calls the initialization function
it perform any required setup, such as argument checking or memory allocation. If
returns an error, MySQL aborts the SQL statement with an error message and does not call the main
or deinitialization functions. Otherwise, MySQL calls the main function
all rows have been processed, MySQL calls the deinitialization function
perform any required cleanup.
For aggregate functions that work like
xxx_clear()
Reset the current aggregate value but do not insert the argument as the initial aggregate value for a
new group.
xxx_add()
Add the argument to the current aggregate value.
MySQL handles aggregate UDFs as follows:
1. Call
xxx_init()
2. Sort the table according to the
3. Call
xxx_clear()
4. Call
xxx_add()
5. Call
xxx()
been processed.
6. Repeat steps 3 to 5 until all rows has been processed
7. Call
xxx_deinit()
All functions must be thread-safe. This includes not just the main function, but the initialization and
deinitialization functions as well, and also the additional functions required by aggregate functions. A
consequence of this requirement is that you are not permitted to allocate any global or static variables
that change! If you need memory, you should allocate it in
21.2.2.1. UDF Calling Sequences for Simple Functions
This section describes the different functions that you need to define when you create a simple UDF.
Section 21.2.2, "Adding a New User-Defined
these functions.
The main
xxx()
parameters differ, depending on whether you declare the SQL function
INTEGER, or
For
STRING
char *xxx(UDF_INIT *initid, UDF_ARGS *args,
char *result, unsigned long *length,
char *is_null, char *error);
For
INTEGER
long long xxx(UDF_INIT *initid, UDF_ARGS *args,
For
functions:
REAL
Adding a New User-Defined Function
to let the aggregate function allocate any memory it needs for storing results.
GROUP BY
for the first row in each new group.
for each row that belongs in the same group.
to get the result for the aggregate when the group changes or after the last row has
to let the UDF free any memory it has allocated.
function should be declared as shown in this section. Note that the return type and
in the
REAL
CREATE FUNCTION
functions:
functions:
char *is_null, char *error);
[972], you must also provide the following functions:
SUM()
expression.
xxx_init()
Function", describes the order in which MySQL calls
statement:
2811
xxx_init()
xxx_init()
once for each row. After
xxx()
so that it can
xxx_deinit()
and free it in xxx_deinit().
to return STRING,
XXX()
to let

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents