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