Adding a New User-Defined Function
2815
•
char **args
args->args
communicates information to the initialization function about the general nature of
the arguments passed to your function. For a constant argument
i
,
args->args[i]
points to the
argument value. (See below for instructions on how to access the value properly.) For a nonconstant
argument,
args->args[i]
is
0
. A constant argument is an expression that uses only constants,
such as
3
or
4*7-2
or
SIN(3.14)
[914]
. A nonconstant argument is an expression that refers to
values that may change from row to row, such as column names or functions that are called with
nonconstant arguments.
For each invocation of the main function,
args->args
contains the actual arguments that are
passed for the row currently being processed.
If argument
i
represents
NULL
,
args->args[i]
is a null pointer (0). If the argument is not
NULL
,
functions can refer to it as follows:
• An argument of type
STRING_RESULT
is given as a string pointer plus a length, to enable handling
of binary data or data of arbitrary length. The string contents are available as
args->args[i]
and the string length is
args->lengths[i]
. Do not assume that the string is null-terminated.
• For an argument of type
INT_RESULT
, you must cast
args->args[i]
to a
long long
value:
long long int_val;
int_val = *((long long*) args->args[i]);
• For an argument of type
REAL_RESULT
, you must cast
args->args[i]
to a
double
value:
double real_val;
real_val = *((double*) args->args[i]);
• For an argument of type
DECIMAL_RESULT
, the value is passed as a string and should be
handled like a
STRING_RESULT
value.
•
ROW_RESULT
arguments are not implemented.
•
unsigned long *lengths
For the initialization function, the
lengths
array indicates the maximum string length for each
argument. You should not change these. For each invocation of the main function,
lengths
contains the actual lengths of any string arguments that are passed for the row currently being
processed. For arguments of types
INT_RESULT
or
REAL_RESULT
,
lengths
still contains the
maximum length of the argument (as for the initialization function).
•
char *maybe_null
For the initialization function, the
maybe_null
array indicates for each argument whether the
argument value might be null (0 if no, 1 if yes).
•
char **attributes
args->attributes
communicates information about the names of the UDF arguments. For
argument
i
, the attribute name is available as a string in
args->attributes[i]
and the attribute
length is
args->attribute_lengths[i]
. Do not assume that the string is null-terminated.
By default, the name of a UDF argument is the text of the expression used to specify the argument.
For UDFs, an argument may also have an optional
[AS] alias_name
clause, in which case the
argument name is
alias_name
. The
attributes
value for each argument thus depends on
whether an alias was given.
Suppose that a UDF
my_udf()
is invoked as follows:
SELECT my_udf(expr1, expr2 AS alias1, expr3 alias2);
Содержание 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 ...