1 | /* Copyright (c) 2017, 2023, Oracle and/or its affiliates. |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License, version 2.0, |
5 | as published by the Free Software Foundation. |
6 | |
7 | This program is also distributed with certain software (including |
8 | but not limited to OpenSSL) that is licensed under separate terms, |
9 | as designated in a particular file or component or in included license |
10 | documentation. The authors of MySQL hereby grant you an additional |
11 | permission to link the program and your derivative works with the |
12 | separately licensed software that they have included with MySQL. |
13 | |
14 | Without limiting anything contained in the foregoing, this file, |
15 | which is part of C Driver for MySQL (Connector/C), is also subject to the |
16 | Universal FOSS Exception, version 1.0, a copy of which can be found at |
17 | http://oss.oracle.com/licenses/universal-foss-exception. |
18 | |
19 | This program is distributed in the hope that it will be useful, |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | GNU General Public License, version 2.0, for more details. |
23 | |
24 | You should have received a copy of the GNU General Public License |
25 | along with this program; if not, write to the Free Software |
26 | Foundation, 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 | /** |
36 | Type of the user defined function return slot and arguments |
37 | */ |
38 | enum 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 | |
47 | typedef 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 | /** |
59 | Information 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 | */ |
65 | typedef 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 | |
74 | enum Item_udftype { UDFTYPE_FUNCTION = 1, UDFTYPE_AGGREGATE }; |
75 | |
76 | typedef void (*Udf_func_clear)(UDF_INIT *, unsigned char *, unsigned char *); |
77 | typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, unsigned char *, |
78 | unsigned char *); |
79 | typedef void (*Udf_func_deinit)(UDF_INIT *); |
80 | typedef bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *); |
81 | typedef void (*Udf_func_any)(void); |
82 | typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, unsigned char *, |
83 | unsigned char *); |
84 | typedef long long (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, unsigned char *, |
85 | unsigned char *); |
86 | typedef 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 | |