MySQL  8.0.18
Source Code Documentation
item_create.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /* Functions to create an item. Used by sql/sql_yacc.yy */
24 
25 #ifndef ITEM_CREATE_H
26 #define ITEM_CREATE_H
27 
28 /**
29  @file sql/item_create.h
30  Builder for SQL functions.
31 */
32 
33 #include <stddef.h>
34 
35 #include "lex_string.h"
36 #include "m_ctype.h"
37 #include "sql/parse_tree_node_base.h" // POS
38 
39 /**
40  @addtogroup GROUP_PARSER
41  @{
42 */
43 
44 class Item;
45 class PT_item_list;
46 class THD;
47 struct Cast_type;
48 struct udf_func;
49 enum enum_field_types : int;
50 
51 /* For type casts */
52 
53 enum Cast_target : unsigned char {
64 };
65 
66 /**
67  Public function builder interface.
68  The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
69  construct an <code>Item</code> object for each function call.
70  All the concrete function builders implements this interface,
71  either directly or indirectly with some adapter helpers.
72  Keeping the function creation separated from the bison grammar allows
73  to simplify the parser, and avoid the need to introduce a new token
74  for each function, which has undesirable side effects in the grammar.
75 */
76 
77 class Create_func {
78  public:
79  /**
80  The builder create method.
81  Given the function name and list or arguments, this method creates
82  an <code>Item</code> that represents the function call.
83  In case or errors, a NULL item is returned, and an error is reported.
84  Note that the <code>thd</code> object may be modified by the builder.
85  In particular, the following members/methods can be set/called,
86  depending on the function called and the function possible side effects.
87  <ul>
88  <li><code>thd->lex->binlog_row_based_if_mixed</code></li>
89  <li><code>thd->lex->current_context()</code></li>
90  <li><code>thd->lex->safe_to_cache_query</code></li>
91  <li><code>thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT)</code></li>
92  <li><code>thd->lex->uncacheable(UNCACHEABLE_RAND)</code></li>
93  <li><code>thd->lex->add_time_zone_tables_to_query_tables(thd)</code></li>
94  </ul>
95  @param thd The current thread
96  @param name The function name
97  @param item_list The list of arguments to the function, can be NULL
98  @return An item representing the parsed function call, or NULL
99  */
100  virtual Item *create_func(THD *thd, LEX_STRING name,
101  PT_item_list *item_list) = 0;
102 
103  protected:
104  Create_func() = default;
105  virtual ~Create_func() {}
106 };
107 
108 /**
109  Function builder for qualified functions.
110  This builder is used with functions call using a qualified function name
111  syntax, as in <code>db.func(expr, expr, ...)</code>.
112 */
113 
114 class Create_qfunc : public Create_func {
115  public:
116  /**
117  The builder create method, for unqualified functions.
118  This builder will use the current database for the database name.
119  @param thd The current thread
120  @param name The function name
121  @param item_list The list of arguments to the function, can be NULL
122  @return An item representing the parsed function call
123  */
124  virtual Item *create_func(THD *thd, LEX_STRING name, PT_item_list *item_list);
125 
126  /**
127  The builder create method, for qualified functions.
128  @param thd The current thread
129  @param db The database name or NULL_STR to use the default db name
130  @param name The function name
131  @param use_explicit_name Should the function be represented as 'db.name'?
132  @param item_list The list of arguments to the function, can be NULL
133  @return An item representing the parsed function call
134  */
135  virtual Item *create(THD *thd, LEX_STRING db, LEX_STRING name,
136  bool use_explicit_name, PT_item_list *item_list) = 0;
137 
138  protected:
139  /** Constructor. */
141  /** Destructor. */
142  virtual ~Create_qfunc() {}
143 };
144 
145 /**
146  Find the native function builder associated with a given function name.
147 
148  @param name The native function name
149  @return The native function builder associated with the name, or NULL
150 */
152 
153 /**
154  Find the function builder for qualified functions.
155  @param thd The current thread
156  @return A function builder for qualified functions
157 */
159 
160 /**
161  Function builder for User Defined Functions.
162 */
163 
164 class Create_udf_func : public Create_func {
165  public:
166  virtual Item *create_func(THD *thd, LEX_STRING name, PT_item_list *item_list);
167 
168  /**
169  The builder create method, for User Defined Functions.
170  @param thd The current thread
171  @param fct The User Defined Function metadata
172  @param item_list The list of arguments to the function, can be NULL
173  @return An item representing the parsed function call
174  */
175  Item *create(THD *thd, udf_func *fct, PT_item_list *item_list);
176 
177  /** Singleton. */
179 
180  protected:
181  /** Constructor. */
183  /** Destructor. */
184  virtual ~Create_udf_func() {}
185 };
186 
187 /**
188  Builder for cast expressions.
189  @param thd The current thread
190  @param pos Location of casting expression
191  @param a The item to cast
192  @param type the type casted into
193  @param as_array Cast to array
194 */
195 Item *create_func_cast(THD *thd, const POS &pos, Item *a, const Cast_type *type,
196  bool as_array = false);
197 Item *create_func_cast(THD *thd, const POS &pos, Item *a,
198  Cast_target cast_target, const CHARSET_INFO *cs_arg);
199 
200 Item *create_temporal_literal(THD *thd, const char *str, size_t length,
202  bool send_error);
203 
204 /**
205  Load the hash table for native functions.
206  Note: this code is not thread safe, and is intended to be used at server
207  startup only (before going multi-threaded)
208 
209  @retval false OK.
210  @retval true An exception was caught.
211 */
212 bool item_create_init();
213 
214 /**
215  Empty the hash table for native functions.
216  Note: this code is not thread safe, and is intended to be used at server
217  shutdown only (after thread requests have been executed).
218 */
219 void item_create_cleanup();
220 
221 /**
222  @} (end of group GROUP_PARSER)
223 */
224 
225 #endif
Definition: sql_udf.h:42
Definition: item_create.h:55
Create_func()=default
Create_udf_func()
Constructor.
Definition: item_create.h:182
Definition: item_create.h:60
Definition: item_create.h:63
Definition: mysql_lex_string.h:34
const string name("\ame\)
static Create_udf_func s_singleton
Singleton.
Definition: item_create.h:178
Definition: item_create.h:56
Item * create_func_cast(THD *thd, const POS &pos, Item *a, Cast_target cast_target, const CHARSET_INFO *cs)
Definition: item_create.cc:1762
Definition: item_create.h:57
Function builder for qualified functions.
Definition: item_create.h:114
Definition: item_create.h:61
Wrapper class for an Item list head, used to allocate Item lists in the parser in a context-independe...
Definition: parse_tree_helpers.h:96
virtual Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list)
The builder create method, for unqualified functions.
Definition: item_create.cc:1119
Definition: item_create.h:58
virtual ~Create_qfunc()
Destructor.
Definition: item_create.h:142
char * pos
Definition: do_ctype.cc:76
Bison "location" class.
Definition: parse_location.h:43
virtual Item * create(THD *thd, LEX_STRING db, LEX_STRING name, bool use_explicit_name, PT_item_list *item_list)=0
The builder create method, for qualified functions.
Create_qfunc * find_qualified_function_builder(THD *)
Find the function builder for qualified functions.
Definition: item_create.cc:1758
virtual ~Create_func()
Definition: item_create.h:105
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
Definition: item.h:668
Definition: m_ctype.h:359
Function builder for User Defined Functions.
Definition: item_create.h:164
Definition: parser_yystype.h:85
virtual ~Create_udf_func()
Destructor.
Definition: item_create.h:184
virtual Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list)
The builder create method.
Definition: item_create.cc:1126
Item * create_temporal_literal(THD *thd, const char *str, size_t length, const CHARSET_INFO *cs, enum_field_types type, bool send_error)
Builder for datetime literals: TIME&#39;00:00:00&#39;, DATE&#39;2001-01-01&#39;, TIMESTAMP&#39;2001-01-01 00:00:00&#39;...
Definition: item_create.cc:1999
int type
Definition: http_common.h:411
A better implementation of the UNIX ctype(3) library.
Item * create(THD *thd, udf_func *fct, PT_item_list *item_list)
The builder create method, for User Defined Functions.
Definition: item_create.cc:1133
void item_create_cleanup()
Empty the hash table for native functions.
Definition: item_create.cc:1742
Create_qfunc()
Constructor.
Definition: item_create.h:140
Definition: item_create.h:59
bool item_create_init()
Load the hash table for native functions.
Definition: item_create.cc:1731
Definition: item_create.h:54
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Public function builder interface.
Definition: item_create.h:77
Cast_target
Definition: item_create.h:53
Definition: item_create.h:62
Create_func * find_native_function_builder(const LEX_STRING &lex_name)
Find the native function builder associated with a given function name.
Definition: item_create.cc:1744
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
virtual Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list)=0
The builder create method.