1/* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14Without limiting anything contained in the foregoing, this file,
15which is part of C Driver for MySQL (Connector/C), is also subject to the
16Universal FOSS Exception, version 1.0, a copy of which can be found at
17http://oss.oracle.com/licenses/universal-foss-exception.
18
19This program is distributed in the hope that it will be useful,
20but WITHOUT ANY WARRANTY; without even the implied warranty of
21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22GNU General Public License, version 2.0, for more details.
23
24You should have received a copy of the GNU General Public License
25along with this program; if not, write to the Free Software
26Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
27
28#ifndef UDF_REGISTRATION_TYPES_H
29#define UDF_REGISTRATION_TYPES_H
30
31#ifndef MYSQL_ABI_CHECK
32#include <stdbool.h>
33#endif
34
35/**
36Type of the user defined function return slot and arguments
37*/
38enum Item_result {
39 INVALID_RESULT = -1, /** not valid for UDFs */
40 STRING_RESULT = 0, /** char * */
41 REAL_RESULT, /** double */
42 INT_RESULT, /** long long */
43 ROW_RESULT, /** not valid for UDFs */
44 DECIMAL_RESULT /** char *, to be converted to/from a decimal */
45};
46
47typedef struct UDF_ARGS {
48 unsigned int arg_count; /**< Number of arguments */
49 enum Item_result *arg_type; /**< Pointer to item_results */
50 char **args; /**< Pointer to argument */
51 unsigned long *lengths; /**< Length of string arguments */
52 char *maybe_null; /**< Set to 1 for all maybe_null args */
53 char **attributes; /**< Pointer to attribute name */
54 unsigned long *attribute_lengths; /**< Length of attribute arguments */
55 void *extension;
56} UDF_ARGS;
57
58/**
59Information about the result of a user defined function
60
61@todo add a notion for determinism of the UDF.
62
63@sa Item_udf_func::update_used_tables()
64*/
65typedef struct UDF_INIT {
66 bool maybe_null; /** 1 if function can return NULL */
67 unsigned int decimals; /** for real functions */
68 unsigned long max_length; /** For string functions */
69 char *ptr; /** free pointer for function data */
70 bool const_item; /** 1 if function always returns the same value */
71 void *extension;
72} UDF_INIT;
73
74enum Item_udftype { UDFTYPE_FUNCTION = 1, UDFTYPE_AGGREGATE };
75
76typedef void (*Udf_func_clear)(UDF_INIT *, unsigned char *, unsigned char *);
77typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, unsigned char *,
78 unsigned char *);
79typedef void (*Udf_func_deinit)(UDF_INIT *);
80typedef bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *);
81typedef void (*Udf_func_any)(void);
82typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, unsigned char *,
83 unsigned char *);
84typedef long long (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, unsigned char *,
85 unsigned char *);
86typedef char *(*Udf_func_string)(UDF_INIT *, UDF_ARGS *, char *,
87 unsigned long *, unsigned char *,
88 unsigned char *);
89
90#endif /* UDF_REGISTRATION_TYPES_H */
91

source code of include/mysql/udf_registration_types.h