MySQL  8.0.16
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 
63 };
64 
65 /**
66  Public function builder interface.
67  The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
68  construct an <code>Item</code> object for each function call.
69  All the concrete function builders implements this interface,
70  either directly or indirectly with some adapter helpers.
71  Keeping the function creation separated from the bison grammar allows
72  to simplify the parser, and avoid the need to introduce a new token
73  for each function, which has undesirable side effects in the grammar.
74 */
75 
76 class Create_func {
77  public:
78  /**
79  The builder create method.
80  Given the function name and list or arguments, this method creates
81  an <code>Item</code> that represents the function call.
82  In case or errors, a NULL item is returned, and an error is reported.
83  Note that the <code>thd</code> object may be modified by the builder.
84  In particular, the following members/methods can be set/called,
85  depending on the function called and the function possible side effects.
86  <ul>
87  <li><code>thd->lex->binlog_row_based_if_mixed</code></li>
88  <li><code>thd->lex->current_context()</code></li>
89  <li><code>thd->lex->safe_to_cache_query</code></li>
90  <li><code>thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT)</code></li>
91  <li><code>thd->lex->uncacheable(UNCACHEABLE_RAND)</code></li>
92  <li><code>thd->lex->add_time_zone_tables_to_query_tables(thd)</code></li>
93  </ul>
94  @param thd The current thread
95  @param name The function name
96  @param item_list The list of arguments to the function, can be NULL
97  @return An item representing the parsed function call, or NULL
98  */
99  virtual Item *create_func(THD *thd, LEX_STRING name,
100  PT_item_list *item_list) = 0;
101 
102  protected:
103  Create_func() = default;
104  virtual ~Create_func() {}
105 };
106 
107 /**
108  Function builder for qualified functions.
109  This builder is used with functions call using a qualified function name
110  syntax, as in <code>db.func(expr, expr, ...)</code>.
111 */
112 
113 class Create_qfunc : public Create_func {
114  public:
115  /**
116  The builder create method, for unqualified functions.
117  This builder will use the current database for the database name.
118  @param thd The current thread
119  @param name The function name
120  @param item_list The list of arguments to the function, can be NULL
121  @return An item representing the parsed function call
122  */
123  virtual Item *create_func(THD *thd, LEX_STRING name, PT_item_list *item_list);
124 
125  /**
126  The builder create method, for qualified functions.
127  @param thd The current thread
128  @param db The database name or NULL_STR to use the default db name
129  @param name The function name
130  @param use_explicit_name Should the function be represented as 'db.name'?
131  @param item_list The list of arguments to the function, can be NULL
132  @return An item representing the parsed function call
133  */
134  virtual Item *create(THD *thd, LEX_STRING db, LEX_STRING name,
135  bool use_explicit_name, PT_item_list *item_list) = 0;
136 
137  protected:
138  /** Constructor. */
140  /** Destructor. */
141  virtual ~Create_qfunc() {}
142 };
143 
144 /**
145  Find the native function builder associated with a given function name.
146 
147  @param name The native function name
148  @return The native function builder associated with the name, or NULL
149 */
151 
152 /**
153  Find the function builder for qualified functions.
154  @param thd The current thread
155  @return A function builder for qualified functions
156 */
158 
159 /**
160  Function builder for User Defined Functions.
161 */
162 
163 class Create_udf_func : public Create_func {
164  public:
165  virtual Item *create_func(THD *thd, LEX_STRING name, PT_item_list *item_list);
166 
167  /**
168  The builder create method, for User Defined Functions.
169  @param thd The current thread
170  @param fct The User Defined Function metadata
171  @param item_list The list of arguments to the function, can be NULL
172  @return An item representing the parsed function call
173  */
174  Item *create(THD *thd, udf_func *fct, PT_item_list *item_list);
175 
176  /** Singleton. */
178 
179  protected:
180  /** Constructor. */
182  /** Destructor. */
183  virtual ~Create_udf_func() {}
184 };
185 
186 /**
187  Builder for cast expressions.
188  @param thd The current thread
189  @param pos Location of casting expression
190  @param a The item to cast
191  @param type the type casted into
192 */
193 Item *create_func_cast(THD *thd, const POS &pos, Item *a,
194  const Cast_type *type);
195 Item *create_func_cast(THD *thd, const POS &pos, Item *a,
196  Cast_target cast_target, const CHARSET_INFO *cs_arg);
197 
198 Item *create_temporal_literal(THD *thd, const char *str, size_t length,
200  bool send_error);
201 
202 /**
203  Load the hash table for native functions.
204  Note: this code is not thread safe, and is intended to be used at server
205  startup only (before going multi-threaded)
206 
207  @retval false OK.
208  @retval true An exception was caught.
209 */
210 bool item_create_init();
211 
212 /**
213  Empty the hash table for native functions.
214  Note: this code is not thread safe, and is intended to be used at server
215  shutdown only (after thread requests have been executed).
216 */
217 void item_create_cleanup();
218 
219 /**
220  @} (end of group GROUP_PARSER)
221 */
222 
223 #endif
Definition: sql_udf.h:42
Create_func()=default
Create_udf_func()
Constructor.
Definition: item_create.h:181
t pos
Definition: dbug_analyze.cc:148
Definition: mysql_lex_string.h:34
const string name("\ame\)
static Create_udf_func s_singleton
Singleton.
Definition: item_create.h:177
Definition: item_create.h:60
Item * create_func_cast(THD *thd, const POS &pos, Item *a, Cast_target cast_target, const CHARSET_INFO *cs)
Definition: item_create.cc:1756
Cast_target
Definition: item_create.h:53
Definition: item_create.h:58
Definition: item_create.h:61
Function builder for qualified functions.
Definition: item_create.h:113
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
Definition: item_create.h:55
Definition: item_create.h:57
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:59
virtual ~Create_qfunc()
Destructor.
Definition: item_create.h:141
Definition: item_create.h:54
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:1752
virtual ~Create_func()
Definition: item_create.h:104
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
Definition: item.h:666
Definition: item_create.h:56
Definition: m_ctype.h:358
Function builder for User Defined Functions.
Definition: item_create.h:163
Definition: sql_lex.h:1912
virtual ~Create_udf_func()
Destructor.
Definition: item_create.h:183
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:1898
int type
Definition: http_common.h:411
Definition: item_create.h:62
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:1736
Create_qfunc()
Constructor.
Definition: item_create.h:139
bool item_create_init()
Load the hash table for native functions.
Definition: item_create.cc:1725
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:76
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:1738
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776
virtual Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list)=0
The builder create method.