![background image](http://html1.mh-extra.com/html/oracle/5-0/5-0_reference-manual_16461962833.webp)
Adding a New User-Defined Function
2813
•
my_bool const_item
xxx_init()
should set
const_item
to
1
if
xxx()
always returns the same value and to
0
otherwise.
21.2.2.2. UDF Calling Sequences for Aggregate Functions
This section describes the different functions that you need to define when you create an aggregate
UDF.
Section 21.2.2, “Adding a New User-Defined Function”
, describes the order in which MySQL calls
these functions.
•
xxx_reset()
This function is called when MySQL finds the first row in a new group. It should reset any internal
summary variables and then use the given
UDF_ARGS
argument as the first value in your internal
summary value for the group. Declare
xxx_reset()
as follows:
void xxx_reset(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error);
xxx_reset()
is not needed or used in MySQL 5.0, in which the UDF interface uses
xxx_clear()
instead. However, you can define both
xxx_reset()
and
xxx_clear()
if you want to have your
UDF work with older versions of the server. (If you do include both functions, the
xxx_reset()
function in many cases can be implemented internally by calling
xxx_clear()
to reset all variables,
and then calling
xxx_add()
to add the
UDF_ARGS
argument as the first value in the group.)
•
xxx_clear()
This function is called when MySQL needs to reset the summary results. It is called at the beginning
for each new group but can also be called to reset the values for a query where there were no
matching rows. Declare
xxx_clear()
as follows:
void xxx_clear(UDF_INIT *initid, char *is_null, char *error);
is_null
is set to point to
CHAR(0)
before calling
xxx_clear()
.
If something went wrong, you can store a value in the variable to which the
error
argument points.
error
points to a single-byte variable, not to a string buffer.
xxx_clear()
is required by MySQL 5.0.
•
xxx_add()
This function is called for all rows that belong to the same group. You should use it to add the value
in the
UDF_ARGS
argument to your internal summary variable.
void xxx_add(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error);
The
xxx()
function for an aggregate UDF should be declared the same way as for a nonaggregate
UDF. See
Section 21.2.2.1, “UDF Calling Sequences for Simple Functions”
.
For an aggregate UDF, MySQL calls the
xxx()
function after all rows in the group have been
processed. You should normally never access its
UDF_ARGS
argument here but instead return a value
based on your internal summary variables.
Return value handling in
xxx()
should be done the same way as for a nonaggregate UDF. See
Section 21.2.2.4, “UDF Return Values and Error Handling”
.
The
xxx_reset()
and
xxx_add()
functions handle their
UDF_ARGS
argument the same way as
functions for nonaggregate UDFs. See
Section 21.2.2.3, “UDF Argument Processing”
.
The pointer arguments to
is_null
and
error
are the same for all calls to
xxx_reset()
,
xxx_clear()
,
xxx_add()
and
xxx()
. You can use this to remember that you got an error or
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...