1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Functions to create an item. Used by sql/sql_yacc.yy */
22
Public function builder interface.
23
The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
24
construct an <code>Item</code> object for each function call.
25
All the concrete function builders implements this interface,
26
either directly or indirectly with some adapter helpers.
27
Keeping the function creation separated from the bison grammar allows
28
to simplify the parser, and avoid the need to introduce a new token
29
for each function, which has undesirable side effects in the grammar.
36
The builder create method.
37
Given the function name and list or arguments, this method creates
38
an <code>Item</code> that represents the function call.
39
In case or errors, a NULL item is returned, and an error is reported.
40
Note that the <code>thd</code> object may be modified by the builder.
41
In particular, the following members/methods can be set/called,
42
depending on the function called and the function possible side effects.
44
<li><code>thd->lex->binlog_row_based_if_mixed</code></li>
45
<li><code>thd->lex->current_context()</code></li>
46
<li><code>thd->lex->safe_to_cache_query</code></li>
47
<li><code>thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT)</code></li>
48
<li><code>thd->lex->uncacheable(UNCACHEABLE_RAND)</code></li>
49
<li><code>thd->lex->add_time_zone_tables_to_query_tables(thd)</code></li>
51
@param thd The current thread
52
@param name The function name
53
@param item_list The list of arguments to the function, can be NULL
54
@return An item representing the parsed function call, or NULL
56
virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list) = 0;
62
virtual ~Create_func() {}
67
Function builder for qualified functions.
68
This builder is used with functions call using a qualified function name
69
syntax, as in <code>db.func(expr, expr, ...)</code>.
72
class Create_qfunc : public Create_func
76
The builder create method, for unqualified functions.
77
This builder will use the current database for the database name.
78
@param thd The current thread
79
@param name The function name
80
@param item_list The list of arguments to the function, can be NULL
81
@return An item representing the parsed function call
83
virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
86
The builder create method, for qualified functions.
87
@param thd The current thread
88
@param db The database name
89
@param name The function name
90
@param use_explicit_name Should the function be represented as 'db.name'?
91
@param item_list The list of arguments to the function, can be NULL
92
@return An item representing the parsed function call
94
virtual Item* create(THD *thd, LEX_STRING db, LEX_STRING name,
95
bool use_explicit_name, List<Item> *item_list) = 0;
101
virtual ~Create_qfunc() {}
106
Find the native function builder associated with a given function name.
107
@param thd The current thread
108
@param name The native function name
109
@return The native function builder associated with the name, or NULL
111
extern Create_func * find_native_function_builder(THD *thd, LEX_STRING name);
115
Find the function builder for qualified functions.
116
@param thd The current thread
117
@return A function builder for qualified functions
119
extern Create_qfunc * find_qualified_function_builder(THD *thd);
124
Function builder for User Defined Functions.
127
class Create_udf_func : public Create_func
130
virtual Item *create(THD *thd, LEX_STRING name, List<Item> *item_list);
133
The builder create method, for User Defined Functions.
134
@param thd The current thread
135
@param fct The User Defined Function metadata
136
@param item_list The list of arguments to the function, can be NULL
137
@return An item representing the parsed function call
139
Item *create(THD *thd, udf_func *fct, List<Item> *item_list);
142
static Create_udf_func s_singleton;
148
virtual ~Create_udf_func() {}
154
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs);
157
Builder for cast expressions.
158
@param thd The current thread
159
@param a The item to cast
160
@param cast_type the type casted into
163
@param cs The character set
166
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
167
const char *len, const char *dec,