~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
20
/* Functions to create an item. Used by sql/sql_yacc.yy */
21
243.1.7 by Jay Pipes
* Moved the Item factory creation functions into the item_create.h header,
22
#ifndef DRIZZLE_SERVER_ITEM_CREATE_H
23
#define DRIZZLE_SERVER_ITEM_CREATE_H
1 by brian
clean slate
24
25
/**
26
  Public function builder interface.
27
  The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
28
  construct an <code>Item</code> object for each function call.
29
  All the concrete function builders implements this interface,
30
  either directly or indirectly with some adapter helpers.
31
  Keeping the function creation separated from the bison grammar allows
32
  to simplify the parser, and avoid the need to introduce a new token
33
  for each function, which has undesirable side effects in the grammar.
34
*/
35
36
class Create_func
37
{
38
public:
39
  /**
40
    The builder create method.
41
    Given the function name and list or arguments, this method creates
42
    an <code>Item</code> that represents the function call.
43
    In case or errors, a NULL item is returned, and an error is reported.
520.1.22 by Brian Aker
Second pass of thd cleanup
44
    Note that the <code>session</code> object may be modified by the builder.
1 by brian
clean slate
45
    In particular, the following members/methods can be set/called,
46
    depending on the function called and the function possible side effects.
47
    <ul>
520.1.22 by Brian Aker
Second pass of thd cleanup
48
      <li><code>session->lex->binlog_row_based_if_mixed</code></li>
49
      <li><code>session->lex->current_context()</code></li>
50
      <li><code>session->lex->safe_to_cache_query</code></li>
51
      <li><code>session->lex->uncacheable(UNCACHEABLE_SIDEEFFECT)</code></li>
52
      <li><code>session->lex->uncacheable(UNCACHEABLE_RAND)</code></li>
53
      <li><code>session->lex->add_time_zone_tables_to_query_tables(session)</code></li>
1 by brian
clean slate
54
    </ul>
520.1.22 by Brian Aker
Second pass of thd cleanup
55
    @param session The current thread
1 by brian
clean slate
56
    @param name The function name
57
    @param item_list The list of arguments to the function, can be NULL
58
    @return An item representing the parsed function call, or NULL
59
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
60
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list) = 0;
1 by brian
clean slate
61
62
protected:
63
  /** Constructor */
64
  Create_func() {}
65
  /** Destructor */
66
  virtual ~Create_func() {}
67
};
68
69
/**
70
  Function builder for qualified functions.
71
  This builder is used with functions call using a qualified function name
72
  syntax, as in <code>db.func(expr, expr, ...)</code>.
73
*/
74
75
class Create_qfunc : public Create_func
76
{
77
public:
78
  /**
79
    The builder create method, for unqualified functions.
80
    This builder will use the current database for the database name.
520.1.22 by Brian Aker
Second pass of thd cleanup
81
    @param session The current thread
1 by brian
clean slate
82
    @param name The function name
83
    @param item_list The list of arguments to the function, can be NULL
84
    @return An item representing the parsed function call
85
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
86
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
87
88
  /**
89
    The builder create method, for qualified functions.
520.1.22 by Brian Aker
Second pass of thd cleanup
90
    @param session The current thread
1 by brian
clean slate
91
    @param db The database name
92
    @param name The function name
93
    @param use_explicit_name Should the function be represented as 'db.name'?
94
    @param item_list The list of arguments to the function, can be NULL
95
    @return An item representing the parsed function call
96
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
97
  virtual Item* create(Session *session, LEX_STRING db, LEX_STRING name,
1 by brian
clean slate
98
                       bool use_explicit_name, List<Item> *item_list) = 0;
99
100
protected:
101
  /** Constructor. */
102
  Create_qfunc() {}
103
  /** Destructor. */
104
  virtual ~Create_qfunc() {}
105
};
106
107
108
/**
109
  Find the native function builder associated with a given function name.
520.1.22 by Brian Aker
Second pass of thd cleanup
110
  @param session The current thread
1 by brian
clean slate
111
  @param name The native function name
112
  @return The native function builder associated with the name, or NULL
113
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
114
extern Create_func * find_native_function_builder(Session *session, LEX_STRING name);
1 by brian
clean slate
115
116
117
/**
118
  Find the function builder for qualified functions.
520.1.22 by Brian Aker
Second pass of thd cleanup
119
  @param session The current thread
1 by brian
clean slate
120
  @return A function builder for qualified functions
121
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
122
extern Create_qfunc * find_qualified_function_builder(Session *session);
1 by brian
clean slate
123
124
125
/**
126
  Function builder for User Defined Functions.
127
*/
128
129
class Create_udf_func : public Create_func
130
{
131
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
132
  virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
1 by brian
clean slate
133
134
  /**
135
    The builder create method, for User Defined Functions.
520.1.22 by Brian Aker
Second pass of thd cleanup
136
    @param session The current thread
1 by brian
clean slate
137
    @param fct The User Defined Function metadata
138
    @param item_list The list of arguments to the function, can be NULL
139
    @return An item representing the parsed function call
140
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
141
  Item *create(Session *session, udf_func *fct, List<Item> *item_list);
1 by brian
clean slate
142
143
  /** Singleton. */
144
  static Create_udf_func s_singleton;
145
146
protected:
147
  /** Constructor. */
148
  Create_udf_func() {}
149
  /** Destructor. */
150
  virtual ~Create_udf_func() {}
151
};
152
153
Item*
520.1.22 by Brian Aker
Second pass of thd cleanup
154
create_func_char_cast(Session *session, Item *a, int len, const CHARSET_INFO * const cs);
1 by brian
clean slate
155
156
/**
157
  Builder for cast expressions.
520.1.22 by Brian Aker
Second pass of thd cleanup
158
  @param session The current thread
1 by brian
clean slate
159
  @param a The item to cast
160
  @param cast_type the type casted into
161
  @param len TODO
162
  @param dec TODO
163
  @param cs The character set
164
*/
165
Item *
520.1.22 by Brian Aker
Second pass of thd cleanup
166
create_func_cast(Session *session, Item *a, Cast_target cast_type,
1 by brian
clean slate
167
                 const char *len, const char *dec,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
168
                 const CHARSET_INFO * const cs);
243.1.7 by Jay Pipes
* Moved the Item factory creation functions into the item_create.h header,
169
170
int item_create_init();
171
void item_create_cleanup();
172
173
#endif /* DRIZZLE_SERVER_ITEM_CREATE_H */