~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
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 as published by
5
   the Free Software Foundation; version 2 of the License.
6
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.
11
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
16
#include <config.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
17
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
18
#define DRIZZLE_LEX 1
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <drizzled/item/num.h>
21
#include <drizzled/abort_exception.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/error.h>
553.1.3 by Monty Taylor
Split out nested_join.h.
23
#include <drizzled/nested_join.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <drizzled/transaction_services.h>
520.8.2 by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes.
25
#include <drizzled/sql_parse.h>
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
26
#include <drizzled/data_home.h>
575.4.7 by Monty Taylor
More header cleanup.
27
#include <drizzled/sql_base.h>
28
#include <drizzled/show.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
29
#include <drizzled/function/time/unix_timestamp.h>
30
#include <drizzled/function/get_system_var.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
31
#include <drizzled/item/cmpfunc.h>
642.1.20 by Lee
header file clean up
32
#include <drizzled/item/null.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
33
#include <drizzled/session.h>
2148.7.11 by Brian Aker
Remove some of the dependencies from session.h so that we make the include
34
#include <drizzled/session/cache.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
35
#include <drizzled/sql_load.h>
670.2.4 by Monty Taylor
Removed more stuff from the headers.
36
#include <drizzled/lock.h>
837 by Brian Aker
Reworked some classes out of session.h
37
#include <drizzled/select_send.h>
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
38
#include <drizzled/plugin/client.h>
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
39
#include <drizzled/statement.h>
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
40
#include <drizzled/statement/alter_table.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
41
#include <drizzled/probes.h>
2281.5.1 by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file.
42
#include <drizzled/charset.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
43
#include <drizzled/plugin/logging.h>
44
#include <drizzled/plugin/query_rewrite.h>
45
#include <drizzled/plugin/query_cache.h>
46
#include <drizzled/plugin/authorization.h>
47
#include <drizzled/optimizer/explain_plan.h>
48
#include <drizzled/pthread_globals.h>
49
#include <drizzled/plugin/event_observer.h>
2191.1.1 by Brian Aker
Add in KILL protocol support.
50
#include <drizzled/display.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
51
#include <drizzled/visibility.h>
2191.1.1 by Brian Aker
Add in KILL protocol support.
52
#include <drizzled/kill.h>
2159.2.5 by Brian Aker
Merge in move of schema.
53
#include <drizzled/schema.h>
2198.1.2 by Olaf van der Spek
Refactor includes
54
#include <drizzled/item/subselect.h>
2239.1.5 by Olaf van der Spek
Refactor includes
55
#include <drizzled/diagnostics_area.h>
2239.1.9 by Olaf van der Spek
Refactor includes
56
#include <drizzled/table_ident.h>
2241.3.1 by Olaf van der Spek
Refactor Session::status_var
57
#include <drizzled/statistics_variables.h>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
58
#include <drizzled/system_variables.h>
2269.1.6 by Olaf van der Spek
Session Times
59
#include <drizzled/session/times.h>
2241.3.4 by Olaf van der Spek
Refactor Session::transaction
60
#include <drizzled/session/transactions.h>
2318.8.3 by Olaf van der Spek
CreateField includes
61
#include <drizzled/create_field.h>
2318.8.7 by Olaf van der Spek
Add const
62
#include <drizzled/lex_input_stream.h>
2159.2.5 by Brian Aker
Merge in move of schema.
63
1241.9.59 by Monty Taylor
Removed the first mystrings header.
64
#include <limits.h>
65
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
66
#include <bitset>
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
67
#include <algorithm>
1878.10.1 by Billy Earney
removed my_micro_time, my_micro_time_and_time, along with my_getsystime and replaced with boost:date_time for compatibility between OS.
68
#include <boost/date_time.hpp>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
69
#include <drizzled/internal/my_sys.h>
1241.9.62 by Monty Taylor
Removed plugin/myisam/myisam.h from session.h
70
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
71
using namespace std;
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
72
2172.3.8 by Brian Aker
Modernize our call to the parser, no more casting required.
73
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
74
2241.3.1 by Olaf van der Spek
Refactor Session::status_var
75
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
76
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
77
/* Prototypes */
2172.3.10 by Brian Aker
Fix parser type to not be a void.
78
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
1165.1.48 by Stewart Smith
make parse_sql static to sql_parse.cc
79
static bool parse_sql(Session *session, Lex_input_stream *lip);
2269.1.7 by Olaf van der Spek
Use util::string::ptr
80
void parse(Session&, const char *inBuf, uint32_t length);
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
81
1 by brian
clean slate
82
/**
83
  @defgroup Runtime_Environment Runtime Environment
84
  @{
85
*/
86
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
87
extern size_t my_thread_stack_size;
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
88
extern const charset_info_st *character_set_filesystem;
1 by brian
clean slate
89
2465.3.1 by Olaf van der Spek
Refactor
90
static atomic<uint64_t> g_query_id;
91
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
92
namespace
93
{
2385.3.15 by Olaf van der Spek
Refactor
94
  static const std::string command_name[]=
95
  {
96
    "Sleep",
97
    "Quit",
98
    "Init DB",
99
    "Query",
100
    "Shutdown",
101
    "Connect",
102
    "Ping",
103
    "Kill",
104
    "Error"  // Last command number
105
  };
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
106
}
107
2385.3.15 by Olaf van der Spek
Refactor
108
const char *xa_state_names[]=
109
{
1 by brian
clean slate
110
  "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
111
};
112
2385.3.15 by Olaf van der Spek
Refactor
113
1 by brian
clean slate
114
/**
115
  Mark all commands that somehow changes a table.
116
117
  This is used to check number of updates / hour.
118
119
  sql_command is actually set to SQLCOM_END sometimes
120
  so we need the +1 to include it in the array.
121
122
  See COMMAND_FLAG_xxx for different type of commands
123
     2  - query that returns meaningful ROW_COUNT() -
124
          a number of modified rows
125
*/
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
126
bitset<CF_BIT_SIZE> sql_command_flags[SQLCOM_END+1];
1 by brian
clean slate
127
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
128
const std::string &getCommandName(const enum_server_command& command)
129
{
130
  return command_name[command];
131
}
132
1 by brian
clean slate
133
void init_update_queries(void)
134
{
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
135
  for (uint32_t x= uint32_t(SQLCOM_SELECT); 
136
       x <= uint32_t(SQLCOM_END); x++)
137
  {
610 by Brian Aker
Merge of Monty's (plus fix for increment style/useless +1)
138
    sql_command_flags[x].reset();
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
139
  }
1 by brian
clean slate
140
141
  sql_command_flags[SQLCOM_CREATE_TABLE]=   CF_CHANGES_DATA;
142
  sql_command_flags[SQLCOM_CREATE_INDEX]=   CF_CHANGES_DATA;
143
  sql_command_flags[SQLCOM_ALTER_TABLE]=    CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND;
144
  sql_command_flags[SQLCOM_TRUNCATE]=       CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND;
145
  sql_command_flags[SQLCOM_DROP_TABLE]=     CF_CHANGES_DATA;
146
  sql_command_flags[SQLCOM_LOAD]=           CF_CHANGES_DATA;
147
  sql_command_flags[SQLCOM_CREATE_DB]=      CF_CHANGES_DATA;
148
  sql_command_flags[SQLCOM_DROP_DB]=        CF_CHANGES_DATA;
149
  sql_command_flags[SQLCOM_RENAME_TABLE]=   CF_CHANGES_DATA;
150
  sql_command_flags[SQLCOM_DROP_INDEX]=     CF_CHANGES_DATA;
151
152
  sql_command_flags[SQLCOM_UPDATE]=	    CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
153
  sql_command_flags[SQLCOM_INSERT]=	    CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
154
  sql_command_flags[SQLCOM_INSERT_SELECT]=  CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
155
  sql_command_flags[SQLCOM_DELETE]=         CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
156
  sql_command_flags[SQLCOM_REPLACE]=        CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
157
  sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
158
159
  sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND;
160
  sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND;
161
  sql_command_flags[SQLCOM_SHOW_CREATE_DB]=  CF_STATUS_COMMAND;
162
  sql_command_flags[SQLCOM_SHOW_CREATE]=  CF_STATUS_COMMAND;
163
164
  /*
165
    The following admin table operations are allowed
166
    on log tables.
167
  */
168
  sql_command_flags[SQLCOM_ANALYZE]=          CF_WRITE_LOGS_COMMAND;
169
}
170
171
/**
172
  Perform one connection-level (COM_XXXX) command.
173
174
  @param command         type of command to perform
520.1.22 by Brian Aker
Second pass of thd cleanup
175
  @param session             connection handle
1 by brian
clean slate
176
  @param packet          data for the command, packet is always null-terminated
177
  @param packet_length   length of packet + 1 (to show that data is
178
                         null-terminated) except for COM_SLEEP, where it
179
                         can be zero.
180
181
  @todo
2227.4.8 by Olaf van der Spek
Session::lex()
182
    set session->lex().sql_command to SQLCOM_END here.
1 by brian
clean slate
183
  @todo
184
    The following has to be changed to an 8 byte integer
185
186
  @retval
187
    0   ok
188
  @retval
189
    1   request of thread shutdown, i. e. if command is
190
        COM_QUIT/COM_SHUTDOWN
191
*/
2191.1.1 by Brian Aker
Add in KILL protocol support.
192
bool dispatch_command(enum_server_command command, Session *session,
2312.1.5 by Brian Aker
const the packet
193
                      const char* packet, uint32_t packet_length)
1 by brian
clean slate
194
{
2312.1.3 by Brian Aker
Merge in formatting.
195
  bool error= false;
1 by brian
clean slate
196
1932.2.3 by Brian Aker
Updates for D-trace
197
  DRIZZLE_COMMAND_START(session->thread_id, command);
1126.10.2 by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes.
198
199
  session->command= command;
2227.4.8 by Olaf van der Spek
Session::lex()
200
  session->lex().sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
2269.1.6 by Olaf van der Spek
Session Times
201
  session->times.set_time();
2465.3.1 by Olaf van der Spek
Refactor
202
  session->setQueryId(g_query_id.increment());
1 by brian
clean slate
203
2385.3.18 by Olaf van der Spek
Refactor
204
  if (command != COM_PING)
2312.1.3 by Brian Aker
Merge in formatting.
205
  {
2385.3.18 by Olaf van der Spek
Refactor
206
    // Increase id and count all other statements
1689.5.1 by Joseph Daly
remove increment calls
207
    session->status_var.questions++;
1 by brian
clean slate
208
  }
209
2227.4.8 by Olaf van der Spek
Session::lex()
210
  /* @todo set session->lex().sql_command to SQLCOM_END here */
1 by brian
clean slate
211
1130.1.16 by Monty Taylor
Fixed naming issue.
212
  plugin::Logging::preDo(session);
1836 by Brian Aker
Added support for pre/post triggers (this removes the need for the current
213
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
214
  {
215
    // We should do something about an error...
216
  }
383.6.4 by Mark Atwood
more make plug logging work
217
2385.3.18 by Olaf van der Spek
Refactor
218
  session->server_status&= ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
2191.1.1 by Brian Aker
Add in KILL protocol support.
219
2312.1.3 by Brian Aker
Merge in formatting.
220
  switch (command)
221
  {
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
222
  case COM_USE_SCHEMA:
1302.4.8 by Eric Day
Added prototest test case for mysql_protocol.
223
    {
2312.1.3 by Brian Aker
Merge in formatting.
224
      if (packet_length == 0)
225
      {
226
        my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
227
        break;
228
      }
229
      if (not schema::change(*session, identifier::Schema(string(packet, packet_length))))
230
      {
231
        session->my_ok();
232
      }
1302.4.8 by Eric Day
Added prototest test case for mysql_protocol.
233
      break;
234
    }
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
235
1 by brian
clean slate
236
  case COM_QUERY:
2312.1.3 by Brian Aker
Merge in formatting.
237
    {
238
      session->readAndStoreQuery(packet, packet_length);
239
      DRIZZLE_QUERY_START(session->getQueryString()->c_str(), session->thread_id, session->schema()->c_str());
240
      parse(*session, session->getQueryString()->c_str(), session->getQueryString()->length());
241
      break;
242
    }
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
243
1 by brian
clean slate
244
  case COM_QUIT:
245
    /* We don't calculate statistics for this command */
2239.1.4 by Olaf van der Spek
Refactor includes
246
    session->main_da().disable_status();              // Don't send anything back
2191.1.1 by Brian Aker
Add in KILL protocol support.
247
    error= true;					// End server
1 by brian
clean slate
248
    break;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
249
2191.1.1 by Brian Aker
Add in KILL protocol support.
250
  case COM_KILL:
251
    {
252
      if (packet_length != 4)
253
      {
254
        my_error(ER_NO_SUCH_THREAD, MYF(0), 0);
255
        break;
256
      }
257
      else
258
      {
259
        uint32_t kill_id;
260
        memcpy(&kill_id, packet, sizeof(uint32_t));
2227.4.9 by Olaf van der Spek
Session::lex()
261
2191.1.1 by Brian Aker
Add in KILL protocol support.
262
        kill_id= ntohl(kill_id);
263
        (void)drizzled::kill(*session->user(), kill_id, true);
264
      }
265
      session->my_ok();
266
      break;
267
    }
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
268
1 by brian
clean slate
269
  case COM_SHUTDOWN:
2312.1.3 by Brian Aker
Merge in formatting.
270
    {
271
      session->status_var.com_other++;
272
      session->my_eof();
273
      session->close_thread_tables();			// Free before kill
274
      kill_drizzle();
275
      error= true;
276
      break;
277
    }
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
278
1 by brian
clean slate
279
  case COM_PING:
1689.5.1 by Joseph Daly
remove increment calls
280
    session->status_var.com_other++;
836 by Brian Aker
Fixed session call from function to method.
281
    session->my_ok();				// Tell client we are alive
1 by brian
clean slate
282
    break;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
283
1 by brian
clean slate
284
  case COM_SLEEP:
285
  case COM_CONNECT:				// Impossible here
286
  case COM_END:
287
  default:
288
    my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
289
    break;
290
  }
291
292
  /* If commit fails, we should be able to reset the OK status. */
2239.1.4 by Olaf van der Spek
Refactor includes
293
  session->main_da().can_overwrite_status= true;
2318.6.62 by Olaf van der Spek
Refactor
294
  TransactionServices::autocommitOrRollback(*session, session->is_error());
2239.1.4 by Olaf van der Spek
Refactor includes
295
  session->main_da().can_overwrite_status= false;
1 by brian
clean slate
296
520.1.22 by Brian Aker
Second pass of thd cleanup
297
  session->transaction.stmt.reset();
1 by brian
clean slate
298
299
300
  /* report error issued during command execution */
520.1.22 by Brian Aker
Second pass of thd cleanup
301
  if (session->killed_errno())
302
  {
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
303
    if (not session->main_da().is_set())
520.1.22 by Brian Aker
Second pass of thd cleanup
304
      session->send_kill_message();
305
  }
1910.2.8 by Brian Aker
Enapsulate Kill.
306
  if (session->getKilled() == Session::KILL_QUERY || session->getKilled() == Session::KILL_BAD_DATA)
520.1.22 by Brian Aker
Second pass of thd cleanup
307
  {
1910.2.8 by Brian Aker
Enapsulate Kill.
308
    session->setKilled(Session::NOT_KILLED);
1689.2.26 by Brian Aker
More encapsulation of the thread var.
309
    session->setAbort(false);
520.1.22 by Brian Aker
Second pass of thd cleanup
310
  }
311
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
312
  /* Can not be true, but do not take chances in production. */
2239.1.4 by Olaf van der Spek
Refactor includes
313
  assert(! session->main_da().is_sent);
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
314
2239.1.4 by Olaf van der Spek
Refactor includes
315
  switch (session->main_da().status())
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
316
  {
317
  case Diagnostics_area::DA_ERROR:
318
    /* The query failed, send error to log and abort bootstrap. */
2239.1.4 by Olaf van der Spek
Refactor includes
319
    session->getClient()->sendError(session->main_da().sql_errno(),
320
                               session->main_da().message());
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
321
    break;
322
323
  case Diagnostics_area::DA_EOF:
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
324
    session->getClient()->sendEOF();
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
325
    break;
326
327
  case Diagnostics_area::DA_OK:
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
328
    session->getClient()->sendOK();
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
329
    break;
330
331
  case Diagnostics_area::DA_DISABLED:
332
    break;
333
334
  case Diagnostics_area::DA_EMPTY:
335
  default:
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
336
    session->getClient()->sendOK();
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
337
    break;
338
  }
339
2239.1.4 by Olaf van der Spek
Refactor includes
340
  session->main_da().is_sent= true;
520.1.22 by Brian Aker
Second pass of thd cleanup
341
342
  session->set_proc_info("closing tables");
1 by brian
clean slate
343
  /* Free tables */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
344
  session->close_thread_tables();
520.1.22 by Brian Aker
Second pass of thd cleanup
345
1130.1.16 by Monty Taylor
Fixed naming issue.
346
  plugin::Logging::postDo(session);
1836 by Brian Aker
Added support for pre/post triggers (this removes the need for the current
347
  if (unlikely(plugin::EventObserver::afterStatement(*session)))
348
  {
349
    // We should do something about an error...
350
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
351
961.1.4 by Brian Aker
Remove another lock for processlist.
352
  /* Store temp state for processlist */
520.1.22 by Brian Aker
Second pass of thd cleanup
353
  session->set_proc_info("cleaning up");
1126.10.2 by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes.
354
  session->command= COM_SLEEP;
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
355
  session->resetQueryString();
961.1.4 by Brian Aker
Remove another lock for processlist.
356
357
  session->set_proc_info(NULL);
1487 by Brian Aker
More updates for memory::Root
358
  session->mem_root->free_root(MYF(memory::KEEP_PREALLOC));
1126.10.2 by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes.
359
360
  if (DRIZZLE_QUERY_DONE_ENABLED() || DRIZZLE_COMMAND_DONE_ENABLED())
361
  {
362
    if (command == COM_QUERY)
363
    {
1126.10.21 by Padraig O'Sullivan
Whoops, simple fix for a build warning that happens if the build is not
364
      DRIZZLE_QUERY_DONE(session->is_error());
1126.10.2 by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes.
365
    }
1126.10.21 by Padraig O'Sullivan
Whoops, simple fix for a build warning that happens if the build is not
366
    DRIZZLE_COMMAND_DONE(session->is_error());
1126.10.2 by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes.
367
  }
368
369
  return error;
1 by brian
clean slate
370
}
371
372
373
/**
327.2.4 by Brian Aker
Refactoring table.h
374
  Create a TableList object for an INFORMATION_SCHEMA table.
1 by brian
clean slate
375
376
    This function is used in the parser to convert a SHOW or DESCRIBE
377
    table_name command to a SELECT from INFORMATION_SCHEMA.
846 by Brian Aker
Removing on typedeffed class.
378
    It prepares a Select_Lex and a TableList object to represent the
1 by brian
clean slate
379
    given command as a SELECT parse tree.
380
1079.2.9 by Padraig O'Sullivan
Removed the dependency on knowing the position of an I_S table in the
381
  @param session           thread handle
382
  @param lex               current lex
383
  @param table_ident       table alias if it's used
384
  @param schema_table_name the name of the INFORMATION_SCHEMA table to be
385
                           created
1 by brian
clean slate
386
387
  @note
388
    Due to the way this function works with memory and LEX it cannot
389
    be used outside the parser (parse tree transformations outside
390
    the parser break PS and SP).
391
392
  @retval
393
    0                 success
394
  @retval
395
    1                 out of memory or SHOW commands are not allowed
396
                      in this version of the server.
397
*/
2318.6.32 by Olaf van der Spek
Refactor
398
static bool _schema_select(Session& session, Select_Lex& sel, const string& schema_table_name)
1273.13.38 by Brian Aker
Add in new show work.
399
{
2371.1.2 by Brian Aker
Remove the typedef on lexkey
400
  lex_string_t db, table;
1858.1.2 by Padraig O'Sullivan
Converted another uint8_t type to be a bitset.
401
  bitset<NUM_OF_TABLE_OPTIONS> table_options;
1273.13.38 by Brian Aker
Add in new show work.
402
  /*
403
     We have to make non const db_name & table_name
404
     because of lower_case_table_names
405
  */
2385.2.7 by Olaf van der Spek
Use str_ref
406
  session.make_lex_string(&db, str_ref("data_dictionary"));
407
  session.make_lex_string(&table, schema_table_name);
2318.6.32 by Olaf van der Spek
Refactor
408
  return not sel.add_table_to_list(&session, new Table_ident(db, table), NULL, table_options, TL_READ);
1273.13.38 by Brian Aker
Add in new show work.
409
}
410
2318.6.32 by Olaf van der Spek
Refactor
411
int prepare_new_schema_table(Session *session, LEX& lex0, const string& schema_table_name)
1273.13.38 by Brian Aker
Add in new show work.
412
{
2318.6.32 by Olaf van der Spek
Refactor
413
  Select_Lex& lex= *lex0.current_select;
414
  if (_schema_select(*session, lex, schema_table_name))
415
    return 1;
416
  TableList *table_list= (TableList*)lex.table_list.first;
417
  table_list->schema_select_lex= NULL;
1273.13.38 by Brian Aker
Add in new show work.
418
  return 0;
419
}
1 by brian
clean slate
420
421
/**
520.1.22 by Brian Aker
Second pass of thd cleanup
422
  Execute command saved in session and lex->sql_command.
1 by brian
clean slate
423
424
    Before every operation that can request a write lock for a table
425
    wait if a global read lock exists. However do not wait if this
426
    thread has locked tables already. No new locks can be requested
427
    until the other locks are released. The thread that requests the
428
    global read lock waits for write locked tables to become unlocked.
429
430
    Note that wait_if_global_read_lock() sets a protection against a new
431
    global read lock when it succeeds. This needs to be released by
432
    start_waiting_global_read_lock() after the operation.
433
520.1.22 by Brian Aker
Second pass of thd cleanup
434
  @param session                       Thread handle
1 by brian
clean slate
435
436
  @todo
437
    - Invalidate the table in the query cache if something changed
438
    after unlocking when changes become visible.
439
    TODO: this is workaround. right way will be move invalidating in
440
    the unlock procedure.
441
    - TODO: use check_change_password()
442
    - JOIN is not supported yet. TODO
443
    - SUSPEND and FOR MIGRATE are not supported yet. TODO
444
445
  @retval
55 by brian
Update for using real bool types.
446
    false       OK
1 by brian
clean slate
447
  @retval
55 by brian
Update for using real bool types.
448
    true        Error
1 by brian
clean slate
449
*/
450
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
451
static int execute_command(Session *session)
1 by brian
clean slate
452
{
846 by Brian Aker
Removing on typedeffed class.
453
  /* first Select_Lex (have special meaning for many of non-SELECTcommands) */
2227.4.8 by Olaf van der Spek
Session::lex()
454
  Select_Lex *select_lex= &session->lex().select_lex;
2187.2.2 by Brian Aker
getLex() usage and fix for table_name creation during admin commands.
455
1 by brian
clean slate
456
  /*
846 by Brian Aker
Removing on typedeffed class.
457
    In many cases first table of main Select_Lex have special meaning =>
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
458
    check that it is first table in global list and relink it first in
1 by brian
clean slate
459
    queries_tables list if it is necessary (we need such relinking only
460
    for queries with subqueries in select list, in this case tables of
461
    subqueries will go to global list first)
462
846 by Brian Aker
Removing on typedeffed class.
463
    all_tables will differ from first_table only if most upper Select_Lex
1 by brian
clean slate
464
    do not contain tables.
465
466
    Because of above in place where should be at least one table in most
846 by Brian Aker
Removing on typedeffed class.
467
    outer Select_Lex we have following check:
51.1.61 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
468
    assert(first_table == all_tables);
469
    assert(first_table == all_tables && first_table != 0);
1 by brian
clean slate
470
  */
2227.4.8 by Olaf van der Spek
Session::lex()
471
  session->lex().first_lists_tables_same();
2187.2.2 by Brian Aker
getLex() usage and fix for table_name creation during admin commands.
472
2440.2.3 by Olaf van der Spek
Refactor
473
  /* list of all tables in query */
1 by brian
clean slate
474
  /* should be assigned after making first tables same */
2440.2.3 by Olaf van der Spek
Refactor
475
  TableList* all_tables= session->lex().query_tables;
2187.2.2 by Brian Aker
getLex() usage and fix for table_name creation during admin commands.
476
1 by brian
clean slate
477
  /* set context for commands which do not use setup_tables */
2187.2.2 by Brian Aker
getLex() usage and fix for table_name creation during admin commands.
478
  select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
1 by brian
clean slate
479
480
  /*
481
    Reset warning count for each query that uses tables
482
    A better approach would be to reset this for any commands
483
    that is not a SHOW command or a select that only access local
484
    variables, but for now this is probably good enough.
485
    Don't reset warnings when executing a stored routine.
486
  */
2227.4.8 by Olaf van der Spek
Session::lex()
487
  if (all_tables || ! session->lex().is_single_level_stmt())
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
488
  {
2318.6.104 by Olaf van der Spek
Refactor
489
    drizzle_reset_errors(*session, 0);
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
490
  }
1 by brian
clean slate
491
2318.6.65 by Olaf van der Spek
Refactor
492
  assert(not session->transaction.stmt.hasModifiedNonTransData());
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
493
2440.2.3 by Olaf van der Spek
Refactor
494
  if (not (session->server_status & SERVER_STATUS_AUTOCOMMIT)
495
      && not session->inTransaction()
2227.4.8 by Olaf van der Spek
Session::lex()
496
      && session->lex().statement->isTransactional())
2140.2.6 by Stewart Smith
be sure to start a transaction with a startTransaction call on the first statement when autocommit is OFF. The only statements that DO NOT do this are a) DDL and b) SELECT without a table (e.g. SELECT DATABASE() and SHOW STATUS.
497
  {
2318.6.65 by Olaf van der Spek
Refactor
498
    if (not session->startTransaction())
2140.2.6 by Stewart Smith
be sure to start a transaction with a startTransaction call on the first statement when autocommit is OFF. The only statements that DO NOT do this are a) DDL and b) SELECT without a table (e.g. SELECT DATABASE() and SHOW STATUS.
499
    {
500
      my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
501
      return true;
502
    }
503
  }
504
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
505
  /* now we are ready to execute the statement */
2440.2.3 by Olaf van der Spek
Refactor
506
  bool res= session->lex().statement->execute();
520.1.22 by Brian Aker
Second pass of thd cleanup
507
  session->set_proc_info("query end");
1 by brian
clean slate
508
  /*
509
    The return value for ROW_COUNT() is "implementation dependent" if the
510
    statement is not DELETE, INSERT or UPDATE, but -1 is what JDBC and ODBC
511
    wants. We also keep the last value in case of SQLCOM_CALL or
512
    SQLCOM_EXECUTE.
513
  */
2440.2.3 by Olaf van der Spek
Refactor
514
  if (not sql_command_flags[session->lex().sql_command].test(CF_BIT_HAS_ROW_COUNT))
1100.3.49 by Padraig O'Sullivan
Extracted the KILL command into its own class and implementation files.
515
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
516
    session->row_count_func= -1;
1100.3.49 by Padraig O'Sullivan
Extracted the KILL command into its own class and implementation files.
517
  }
1 by brian
clean slate
518
2440.2.3 by Olaf van der Spek
Refactor
519
  return res || session->is_error();
1 by brian
clean slate
520
}
2440.2.3 by Olaf van der Spek
Refactor
521
520.1.22 by Brian Aker
Second pass of thd cleanup
522
bool execute_sqlcom_select(Session *session, TableList *all_tables)
1 by brian
clean slate
523
{
2227.4.10 by Olaf van der Spek
Session::lex()
524
  LEX	*lex= &session->lex();
1 by brian
clean slate
525
  select_result *result=lex->result;
873.1.9 by Jay Pipes
This patch fixes the following functions to properly error out
526
  bool res= false;
1 by brian
clean slate
527
  /* assign global limit variable if limit is not given */
528
  {
846 by Brian Aker
Removing on typedeffed class.
529
    Select_Lex *param= lex->unit.global_parameters;
1 by brian
clean slate
530
    if (!param->explicit_limit)
531
      param->select_limit=
520.1.22 by Brian Aker
Second pass of thd cleanup
532
        new Item_int((uint64_t) session->variables.select_limit);
1 by brian
clean slate
533
  }
2140.2.6 by Stewart Smith
be sure to start a transaction with a startTransaction call on the first statement when autocommit is OFF. The only statements that DO NOT do this are a) DDL and b) SELECT without a table (e.g. SELECT DATABASE() and SHOW STATUS.
534
535
  if (all_tables
536
      && ! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
537
      && ! session->inTransaction()
538
      && ! lex->statement->isShow())
539
  {
2318.6.65 by Olaf van der Spek
Refactor
540
    if (not session->startTransaction())
2140.2.6 by Stewart Smith
be sure to start a transaction with a startTransaction call on the first statement when autocommit is OFF. The only statements that DO NOT do this are a) DDL and b) SELECT without a table (e.g. SELECT DATABASE() and SHOW STATUS.
541
    {
542
      my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
543
      return true;
544
    }
545
  }
546
1415 by Brian Aker
Mass overhaul to use schema_identifier.
547
  if (not (res= session->openTablesLock(all_tables)))
1 by brian
clean slate
548
  {
549
    if (lex->describe)
550
    {
551
      /*
552
        We always use select_send for EXPLAIN, even if it's an EXPLAIN
553
        for SELECT ... INTO OUTFILE: a user application should be able
554
        to prepend EXPLAIN to any query and receive output for it,
555
        even if the query itself redirects the output.
556
      */
2318.3.11 by Olaf van der Spek
Refactor
557
      result= new select_send();
520.1.22 by Brian Aker
Second pass of thd cleanup
558
      session->send_explain_fields(result);
1240.7.1 by Padraig O'Sullivan
Created an ExplainPlan class in the optimizer namespace. All printing of an explain in drizzle goes
559
      optimizer::ExplainPlan planner;
2227.4.8 by Olaf van der Spek
Session::lex()
560
      res= planner.explainUnion(session, &session->lex().unit, result);
1 by brian
clean slate
561
      if (lex->describe & DESCRIBE_EXTENDED)
562
      {
563
        char buff[1024];
205 by Brian Aker
uint32 -> uin32_t
564
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
1 by brian
clean slate
565
        str.length(0);
2227.4.8 by Olaf van der Spek
Session::lex()
566
        session->lex().unit.print(&str);
1 by brian
clean slate
567
        str.append('\0');
520.1.22 by Brian Aker
Second pass of thd cleanup
568
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1 by brian
clean slate
569
                     ER_YES, str.ptr());
570
      }
571
      if (res)
572
        result->abort();
573
      else
574
        result->send_eof();
2172.3.22 by Brian Aker
This patch adds safe_delete(). All of these locations in the code should be
575
1 by brian
clean slate
576
      delete result;
577
    }
578
    else
579
    {
2318.3.11 by Olaf van der Spek
Refactor
580
      if (not result)
581
        result= new select_send();
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
582
583
      /* Init the Query Cache plugin */
2227.4.9 by Olaf van der Spek
Session::lex()
584
      plugin::QueryCache::prepareResultset(session);
520.1.22 by Brian Aker
Second pass of thd cleanup
585
      res= handle_select(session, lex, result, 0);
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
586
      /* Send the Resultset to the cache */
2227.4.9 by Olaf van der Spek
Session::lex()
587
      plugin::QueryCache::setResultset(session);
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
588
1 by brian
clean slate
589
      if (result != lex->result)
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
590
        delete result;
1 by brian
clean slate
591
    }
592
  }
593
  return res;
594
}
595
596
597
#define MY_YACC_INIT 1000			// Start with big alloc
598
#define MY_YACC_MAX  32000			// Because of 'short'
599
2172.3.10 by Brian Aker
Fix parser type to not be a void.
600
bool my_yyoverflow(short **yyss, ParserType **yyvs, ulong *yystacksize)
1 by brian
clean slate
601
{
2227.4.10 by Olaf van der Spek
Session::lex()
602
  LEX	*lex= &current_session->lex();
1 by brian
clean slate
603
  ulong old_info=0;
438.1.13 by Brian Aker
uint cleanup.
604
  if ((uint32_t) *yystacksize >= MY_YACC_MAX)
1 by brian
clean slate
605
    return 1;
606
  if (!lex->yacc_yyvs)
607
    old_info= *yystacksize;
608
  *yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX);
656.1.46 by Monty Taylor
More malloc return cleanups.
609
  unsigned char *tmpptr= NULL;
610
  if (!(tmpptr= (unsigned char *)realloc(lex->yacc_yyvs,
611
                                         *yystacksize* sizeof(**yyvs))))
612
      return 1;
613
  lex->yacc_yyvs= tmpptr;
614
  tmpptr= NULL;
615
  if (!(tmpptr= (unsigned char*)realloc(lex->yacc_yyss,
616
                                        *yystacksize* sizeof(**yyss))))
617
      return 1;
618
  lex->yacc_yyss= tmpptr;
1 by brian
clean slate
619
  if (old_info)
620
  {						// Copy old info from stack
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
621
    memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
622
    memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
1 by brian
clean slate
623
  }
624
  *yyss=(short*) lex->yacc_yyss;
2172.3.10 by Brian Aker
Fix parser type to not be a void.
625
  *yyvs=(ParserType*) lex->yacc_yyvs;
1 by brian
clean slate
626
  return 0;
627
}
628
629
630
void
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
631
init_select(LEX *lex)
1 by brian
clean slate
632
{
846 by Brian Aker
Removing on typedeffed class.
633
  Select_Lex *select_lex= lex->current_select;
1 by brian
clean slate
634
  select_lex->init_select();
635
  lex->wild= 0;
636
  if (select_lex == &lex->select_lex)
637
  {
51.1.61 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
638
    assert(lex->result == 0);
1 by brian
clean slate
639
    lex->exchange= 0;
640
  }
641
}
642
643
2318.6.90 by Olaf van der Spek
Refactor
644
bool new_select(LEX *lex, bool move_down)
1 by brian
clean slate
645
{
2318.6.90 by Olaf van der Spek
Refactor
646
  Session* session= lex->session;
647
  Select_Lex* select_lex= new (session->mem_root) Select_Lex;
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
648
520.1.22 by Brian Aker
Second pass of thd cleanup
649
  select_lex->select_number= ++session->select_number;
1 by brian
clean slate
650
  select_lex->parent_lex= lex; /* Used in init_query. */
651
  select_lex->init_query();
652
  select_lex->init_select();
653
  lex->nest_level++;
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
654
1 by brian
clean slate
655
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
656
  {
657
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
2318.6.77 by Olaf van der Spek
Refactor
658
    return 1;
1 by brian
clean slate
659
  }
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
660
1 by brian
clean slate
661
  select_lex->nest_level= lex->nest_level;
662
  if (move_down)
663
  {
664
    /* first select_lex of subselect or derived table */
2318.6.90 by Olaf van der Spek
Refactor
665
    Select_Lex_Unit* unit= new (session->mem_root) Select_Lex_Unit();
1 by brian
clean slate
666
667
    unit->init_query();
668
    unit->init_select();
520.1.22 by Brian Aker
Second pass of thd cleanup
669
    unit->session= session;
1 by brian
clean slate
670
    unit->include_down(lex->current_select);
671
    unit->link_next= 0;
672
    unit->link_prev= 0;
673
    unit->return_to= lex->current_select;
674
    select_lex->include_down(unit);
675
    /*
676
      By default we assume that it is usual subselect and we have outer name
677
      resolution context, if no we will assign it to 0 later
678
    */
679
    select_lex->context.outer_context= &select_lex->outer_select()->context;
680
  }
681
  else
682
  {
683
    if (lex->current_select->order_list.first && !lex->current_select->braces)
684
    {
327.2.3 by Brian Aker
Refactoring of class Table
685
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
686
      return true;
1 by brian
clean slate
687
    }
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
688
1 by brian
clean slate
689
    select_lex->include_neighbour(lex->current_select);
848 by Brian Aker
typdef class removal (just... use the name of the class).
690
    Select_Lex_Unit *unit= select_lex->master_unit();
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
691
692
    if (not unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
693
      return true;
694
2420.2.1 by Olaf van der Spek
Refactor
695
    select_lex->context.outer_context= unit->first_select()->context.outer_context;
1 by brian
clean slate
696
  }
697
698
  select_lex->master_unit()->global_parameters= select_lex;
847 by Brian Aker
More typdef class removal.
699
  select_lex->include_global((Select_Lex_Node**)&lex->all_selects_list);
1 by brian
clean slate
700
  lex->current_select= select_lex;
701
  /*
702
    in subquery is SELECT query and we allow resolution of names in SELECT
703
    list
704
  */
55 by brian
Update for using real bool types.
705
  select_lex->context.resolve_in_select_list= true;
2104.3.7 by Brian Aker
Minor cleanup, drop one of two needs for current session during parsing.
706
707
  return false;
1 by brian
clean slate
708
}
709
710
/**
711
  Create a select to return the same output as 'SELECT @@var_name'.
712
713
  Used for SHOW COUNT(*) [ WARNINGS | ERROR].
714
715
  This will crash with a core dump if the variable doesn't exists.
716
717
  @param var_name		Variable name
718
*/
719
2137.1.12 by Brian Aker
Remove current_session in building the error count.
720
void create_select_for_variable(Session *session, const char *var_name)
1 by brian
clean slate
721
{
2269.1.7 by Olaf van der Spek
Use util::string::ptr
722
  LEX& lex= session->lex();
723
  init_select(&lex);
724
  lex.sql_command= SQLCOM_SELECT;
2371.1.2 by Brian Aker
Remove the typedef on lexkey
725
  lex_string_t tmp;
2433.1.6 by Olaf van der Spek
USe data() and size()
726
  tmp.assign(var_name, strlen(var_name));
1 by brian
clean slate
727
  /*
728
    We set the name of Item to @@session.var_name because that then is used
729
    as the column name in the output.
730
  */
2420.2.1 by Olaf van der Spek
Refactor
731
  if (Item* var= get_system_var(session, OPT_SESSION, tmp, null_lex_string()))
1 by brian
clean slate
732
  {
2269.1.7 by Olaf van der Spek
Use util::string::ptr
733
    char buff[MAX_SYS_VAR_LENGTH*2+4+8];
734
    char *end= buff;
1366.1.10 by Siddharth Prakash Singh
sprintf->snprintf in drizzled/sql_parse.cc
735
    end+= snprintf(buff, sizeof(buff), "@@session.%s", var_name);
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
736
    var->set_name(buff, end-buff);
838 by Brian Aker
More class adoption/method
737
    session->add_item_to_list(var);
1 by brian
clean slate
738
  }
739
}
740
741
742
/**
743
  Parse a query.
744
520.1.22 by Brian Aker
Second pass of thd cleanup
745
  @param       session     Current thread
1 by brian
clean slate
746
  @param       inBuf   Begining of the query text
747
  @param       length  Length of the query text
748
*/
749
2269.1.7 by Olaf van der Spek
Use util::string::ptr
750
void parse(Session& session, const char *inBuf, uint32_t length)
1 by brian
clean slate
751
{
2269.1.7 by Olaf van der Spek
Use util::string::ptr
752
  session.lex().start(&session);
753
  session.reset_for_next_command();
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
754
  /* Check if the Query is Cached if and return true if yes
755
   * TODO the plugin has to make sure that the query is cacheble
756
   * by setting the query_safe_cache param to TRUE
757
   */
2269.1.7 by Olaf van der Spek
Use util::string::ptr
758
  if (plugin::QueryCache::isCached(&session) && not plugin::QueryCache::sendCachedResultset(&session))
2420.2.1 by Olaf van der Spek
Refactor
759
    return;
2269.1.7 by Olaf van der Spek
Use util::string::ptr
760
  Lex_input_stream lip(&session, inBuf, length);
761
  if (parse_sql(&session, &lip))
762
    assert(session.is_error());
763
  else if (not session.is_error())
2269.1.6 by Olaf van der Spek
Session Times
764
  {
2420.2.1 by Olaf van der Spek
Refactor
765
    DRIZZLE_QUERY_EXEC_START(session.getQueryString()->c_str(), session.thread_id, session.schema()->c_str());
2269.1.6 by Olaf van der Spek
Session Times
766
    // Implement Views here --Brian
767
    /* Actually execute the query */
768
    try
769
    {
2269.1.7 by Olaf van der Spek
Use util::string::ptr
770
      execute_command(&session);
2269.1.6 by Olaf van der Spek
Session Times
771
    }
772
    catch (...)
773
    {
774
      // Just try to catch any random failures that could have come
775
      // during execution.
776
      DRIZZLE_ABORT;
777
    }
778
    DRIZZLE_QUERY_EXEC_DONE(0);
1643.6.4 by Djellel E. Difallah
Added data dictionary view 'Query_cache_entries' to list current cached queries. Added a UDF print_query_cache_meta(key) to display a text representation of the metadata
779
  }
2269.1.7 by Olaf van der Spek
Use util::string::ptr
780
  session.lex().unit.cleanup();
781
  session.set_proc_info("freeing items");
782
  session.end_statement();
783
  session.cleanup_after_query();
784
  session.times.set_end_timer(session);
1 by brian
clean slate
785
}
786
787
788
/**
789
  Store field definition for create.
790
791
  @return
792
    Return 0 if ok
793
*/
794
2445.1.11 by Olaf van der Spek
Use str_ref
795
bool add_field_to_list(Session *session, str_ref field_name, enum_field_types type,
2318.8.6 by Olaf van der Spek
Add const
796
		       const char *length, const char *decimals,
2420.2.1 by Olaf van der Spek
Refactor
797
		       uint32_t type_modifier, column_format_type column_format,
2440.2.9 by Olaf van der Spek
Refactor
798
		       Item *default_value, Item *on_update_value, str_ref comment,
2420.2.1 by Olaf van der Spek
Refactor
799
		       const char *change, List<String> *interval_list, const charset_info_st* cs)
1 by brian
clean slate
800
{
2227.4.10 by Olaf van der Spek
Session::lex()
801
  LEX  *lex= &session->lex();
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
802
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
1 by brian
clean slate
803
2445.1.11 by Olaf van der Spek
Use str_ref
804
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
1135 by Brian Aker
Merge of Lex -> Statement refactoring
805
    return true;
1 by brian
clean slate
806
807
  if (type_modifier & PRI_KEY_FLAG)
808
  {
2445.1.11 by Olaf van der Spek
Use str_ref
809
    lex->col_list.push_back(new Key_part_spec(field_name, 0));
2420.2.1 by Olaf van der Spek
Refactor
810
    statement->alter_info.key_list.push_back(new Key(Key::PRIMARY, null_lex_string(), &default_key_create_info, 0, lex->col_list));
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
811
    lex->col_list.clear();
1 by brian
clean slate
812
  }
813
  if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
814
  {
2445.1.11 by Olaf van der Spek
Use str_ref
815
    lex->col_list.push_back(new Key_part_spec(field_name, 0));
2420.2.1 by Olaf van der Spek
Refactor
816
    statement->alter_info.key_list.push_back(new Key(Key::UNIQUE, null_lex_string(), &default_key_create_info, 0, lex->col_list));
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
817
    lex->col_list.clear();
1 by brian
clean slate
818
  }
819
820
  if (default_value)
821
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
822
    /*
1 by brian
clean slate
823
      Default value should be literal => basic constants =>
824
      no need fix_fields()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
825
826
      We allow only one function as part of default value -
1 by brian
clean slate
827
      NOW() as default for TIMESTAMP type.
828
    */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
829
    if (default_value->type() == Item::FUNC_ITEM &&
1 by brian
clean slate
830
        !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
2046.2.1 by Brian Aker
First pass on micro timestamp.
831
         (type == DRIZZLE_TYPE_TIMESTAMP or type == DRIZZLE_TYPE_MICROTIME)))
1 by brian
clean slate
832
    {
2445.1.11 by Olaf van der Spek
Use str_ref
833
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
834
      return true;
1 by brian
clean slate
835
    }
836
    else if (default_value->type() == Item::NULL_ITEM)
837
    {
838
      default_value= 0;
2064.2.2 by Brian Aker
Formattting, etc.
839
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG)
1 by brian
clean slate
840
      {
2445.1.11 by Olaf van der Spek
Use str_ref
841
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
2420.2.4 by Olaf van der Spek
Refactor
842
        return true;
1 by brian
clean slate
843
      }
844
    }
845
    else if (type_modifier & AUTO_INCREMENT_FLAG)
846
    {
2445.1.11 by Olaf van der Spek
Use str_ref
847
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
848
      return true;
1 by brian
clean slate
849
    }
850
  }
851
2046.2.1 by Brian Aker
First pass on micro timestamp.
852
  if (on_update_value && (type != DRIZZLE_TYPE_TIMESTAMP and type != DRIZZLE_TYPE_MICROTIME))
1 by brian
clean slate
853
  {
2445.1.11 by Olaf van der Spek
Use str_ref
854
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name.data());
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
855
    return true;
1 by brian
clean slate
856
  }
857
2420.2.1 by Olaf van der Spek
Refactor
858
  CreateField* new_field= new CreateField;
2445.1.11 by Olaf van der Spek
Use str_ref
859
  if (new_field->init(session, field_name.data(), type, length, decimals, type_modifier, comment, change, interval_list, cs, 0, column_format)
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
860
      || new_field->setDefaultValue(default_value, on_update_value))
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
861
    return true;
1 by brian
clean slate
862
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
863
  statement->alter_info.create_list.push_back(new_field);
1 by brian
clean slate
864
  lex->last_field=new_field;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
865
866
  return false;
1 by brian
clean slate
867
}
868
869
870
/**
871
  Add a table to list of used tables.
872
873
  @param table		Table to add
874
  @param alias		alias for table (or null if no alias)
875
  @param table_options	A set of the following bits:
876
                         - TL_OPTION_UPDATING : Table will be updated
877
                         - TL_OPTION_FORCE_INDEX : Force usage of index
878
                         - TL_OPTION_ALIAS : an alias in multi table DELETE
879
  @param lock_type	How table should be locked
880
  @param use_index	List of indexed used in USE INDEX
881
  @param ignore_index	List of indexed used in IGNORE INDEX
882
883
  @retval
884
      0		Error
885
  @retval
327.2.4 by Brian Aker
Refactoring table.h
886
    \#	Pointer to TableList element added to the total table list
1 by brian
clean slate
887
*/
888
846 by Brian Aker
Removing on typedeffed class.
889
TableList *Select_Lex::add_table_to_list(Session *session,
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
890
                                         Table_ident *table,
2371.1.2 by Brian Aker
Remove the typedef on lexkey
891
                                         lex_string_t *alias,
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
892
                                         const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
893
                                         thr_lock_type lock_type,
894
                                         List<Index_hint> *index_hints_arg,
2371.1.2 by Brian Aker
Remove the typedef on lexkey
895
                                         lex_string_t *option)
1 by brian
clean slate
896
{
327.2.4 by Brian Aker
Refactoring table.h
897
  TableList *previous_table_ref; /* The table preceding the current one. */
2227.4.10 by Olaf van der Spek
Session::lex()
898
  LEX *lex= &session->lex();
1 by brian
clean slate
899
900
  if (!table)
1054.1.5 by Brian Aker
Formatting/remove dead variables.
901
    return NULL;				// End of memory
2430.1.4 by Olaf van der Spek
Use data()
902
  const char* alias_str= alias ? alias->data() : table->table.data();
2445.1.1 by Olaf van der Spek
Refactor
903
  if (not table_options.test(TL_OPTION_ALIAS) && check_table_name(table->table))
1 by brian
clean slate
904
  {
2430.1.3 by Olaf van der Spek
Use data()
905
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.data());
1054.1.5 by Brian Aker
Formatting/remove dead variables.
906
    return NULL;
1 by brian
clean slate
907
  }
908
2430.1.3 by Olaf van der Spek
Use data()
909
  if (not table->is_derived_table() && table->db.data())
1 by brian
clean slate
910
  {
2456.1.4 by Olaf van der Spek
Refactor
911
    files_charset_info->casedn_str(table->db.str_);
2440.2.13 by Olaf van der Spek
Refactor
912
    if (not schema::check(*session, identifier::Schema(table->db)))
1415 by Brian Aker
Mass overhaul to use schema_identifier.
913
    {
2430.1.3 by Olaf van der Spek
Use data()
914
      my_error(ER_WRONG_DB_NAME, MYF(0), table->db.data());
1415 by Brian Aker
Mass overhaul to use schema_identifier.
915
      return NULL;
916
    }
1 by brian
clean slate
917
  }
918
919
  if (!alias)					/* Alias is case sensitive */
920
  {
921
    if (table->sel)
922
    {
2385.1.1 by Olaf van der Spek
Refactor lex_string_t
923
      my_message(ER_DERIVED_MUST_HAVE_ALIAS, ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
1054.1.5 by Brian Aker
Formatting/remove dead variables.
924
      return NULL;
1 by brian
clean slate
925
    }
2433.1.6 by Olaf van der Spek
USe data() and size()
926
    alias_str= (char*) session->mem.memdup(alias_str, table->table.size() + 1);
1 by brian
clean slate
927
  }
2318.6.20 by Olaf van der Spek
Refactor
928
  TableList *ptr = (TableList *) session->mem.calloc(sizeof(TableList));
1672.3.5 by Brian Aker
This replaces the allocation we do for insert/update.
929
2430.1.3 by Olaf van der Spek
Use data()
930
  if (table->db.data())
1 by brian
clean slate
931
  {
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
932
    ptr->setIsFqtn(true);
2430.1.3 by Olaf van der Spek
Use data()
933
    ptr->setSchemaName(table->db.data());
1 by brian
clean slate
934
  }
2430.1.9 by Olaf van der Spek
Add const
935
  else 
2385.1.7 by Olaf van der Spek
Rename set_db to set_schema
936
  {
2430.1.9 by Olaf van der Spek
Add const
937
    str_ref schema = lex->session->copy_db_to();
938
    if (schema.empty())
939
      return NULL;
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
940
    ptr->setIsFqtn(false);
2430.1.9 by Olaf van der Spek
Add const
941
    ptr->setSchemaName(schema.data());
2385.1.7 by Olaf van der Spek
Rename set_db to set_schema
942
  }
1 by brian
clean slate
943
944
  ptr->alias= alias_str;
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
945
  ptr->setIsAlias(alias ? true : false);
2430.1.3 by Olaf van der Spek
Use data()
946
  ptr->setTableName(table->table.data());
1 by brian
clean slate
947
  ptr->lock_type=   lock_type;
1858.1.2 by Padraig O'Sullivan
Converted another uint8_t type to be a bitset.
948
  ptr->force_index= table_options.test(TL_OPTION_FORCE_INDEX);
949
  ptr->ignore_leaves= table_options.test(TL_OPTION_IGNORE_LEAVES);
1 by brian
clean slate
950
  ptr->derived=	    table->sel;
951
  ptr->select_lex=  lex->current_select;
952
  ptr->index_hints= index_hints_arg;
2430.1.4 by Olaf van der Spek
Use data()
953
  ptr->option= option ? option->data() : NULL;
1 by brian
clean slate
954
  /* check that used name is unique */
955
  if (lock_type != TL_IGNORE)
956
  {
327.2.4 by Brian Aker
Refactoring table.h
957
    TableList *first_table= (TableList*) table_list.first;
2318.8.4 by Olaf van der Spek
Refactor copy_db_to
958
    for (TableList *tables= first_table; tables; tables= tables->next_local)
1 by brian
clean slate
959
    {
2456.1.4 by Olaf van der Spek
Refactor
960
      if (not table_alias_charset->strcasecmp(alias_str, tables->alias) &&
961
        not system_charset_info->strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1 by brian
clean slate
962
      {
2318.8.4 by Olaf van der Spek
Refactor copy_db_to
963
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
964
        return NULL;
1 by brian
clean slate
965
      }
966
    }
967
  }
968
  /* Store the table reference preceding the current one. */
2183.2.19 by Olaf van der Spek
Use List::size()
969
  if (table_list.size() > 0)
1 by brian
clean slate
970
  {
971
    /*
327.2.4 by Brian Aker
Refactoring table.h
972
      table_list.next points to the last inserted TableList->next_local'
1 by brian
clean slate
973
      element
974
      We don't use the offsetof() macro here to avoid warnings from gcc
975
    */
2456.1.4 by Olaf van der Spek
Refactor
976
    previous_table_ref= (TableList*) ((char*) table_list.next - ((char*) &(ptr->next_local) - (char*) ptr));
1 by brian
clean slate
977
    /*
978
      Set next_name_resolution_table of the previous table reference to point
979
      to the current table reference. In effect the list
327.2.4 by Brian Aker
Refactoring table.h
980
      TableList::next_name_resolution_table coincides with
981
      TableList::next_local. Later this may be changed in
1 by brian
clean slate
982
      store_top_level_join_columns() for NATURAL/USING joins.
983
    */
984
    previous_table_ref->next_name_resolution_table= ptr;
985
  }
986
987
  /*
988
    Link the current table reference in a local list (list for current select).
989
    Notice that as a side effect here we set the next_local field of the
990
    previous table reference to 'ptr'. Here we also add one element to the
991
    list 'table_list'.
992
  */
481 by Brian Aker
Remove all of uchar.
993
  table_list.link_in_list((unsigned char*) ptr, (unsigned char**) &ptr->next_local);
1 by brian
clean slate
994
  ptr->next_name_resolution_table= NULL;
995
  /* Link table in global list (all used tables) */
996
  lex->add_to_query_tables(ptr);
1054.1.5 by Brian Aker
Formatting/remove dead variables.
997
  return ptr;
1 by brian
clean slate
998
}
999
1000
1001
/**
1002
  Initialize a new table list for a nested join.
1003
327.2.4 by Brian Aker
Refactoring table.h
1004
    The function initializes a structure of the TableList type
1 by brian
clean slate
1005
    for a nested join. It sets up its nested join list as empty.
1006
    The created structure is added to the front of the current
846 by Brian Aker
Removing on typedeffed class.
1007
    join list in the Select_Lex object. Then the function
1 by brian
clean slate
1008
    changes the current nest level for joins to refer to the newly
1009
    created empty list after having saved the info on the old level
1010
    in the initialized structure.
1011
520.1.22 by Brian Aker
Second pass of thd cleanup
1012
  @param session         current thread
1 by brian
clean slate
1013
1014
  @retval
1015
    0   if success
1016
  @retval
1017
    1   otherwise
1018
*/
1019
2318.6.26 by Olaf van der Spek
Refactor
1020
void Select_Lex::init_nested_join(Session& session)
1 by brian
clean slate
1021
{
2318.6.26 by Olaf van der Spek
Refactor
1022
  TableList* ptr= (TableList*) session.mem.calloc(ALIGN_SIZE(sizeof(TableList)) + sizeof(NestedJoin));
2141.3.3 by vjsamuel1990 at gmail
Merge change nested_join_st to NestedJoin
1023
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
2318.6.20 by Olaf van der Spek
Refactor
1024
  NestedJoin* nested_join= ptr->getNestedJoin();
1 by brian
clean slate
1025
  join_list->push_front(ptr);
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1026
  ptr->setEmbedding(embedding);
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
1027
  ptr->setJoinList(join_list);
1 by brian
clean slate
1028
  ptr->alias= (char*) "(nested_join)";
1029
  embedding= ptr;
1030
  join_list= &nested_join->join_list;
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
1031
  join_list->clear();
1 by brian
clean slate
1032
}
1033
1034
1035
/**
1036
  End a nested join table list.
1037
1038
    The function returns to the previous join nest level.
1039
    If the current level contains only one member, the function
1040
    moves it one level up, eliminating the nest.
1041
520.1.22 by Brian Aker
Second pass of thd cleanup
1042
  @param session         current thread
1 by brian
clean slate
1043
1044
  @return
327.2.4 by Brian Aker
Refactoring table.h
1045
    - Pointer to TableList element added to the total table list, if success
1 by brian
clean slate
1046
    - 0, otherwise
1047
*/
1048
2456.1.4 by Olaf van der Spek
Refactor
1049
TableList *Select_Lex::end_nested_join()
1 by brian
clean slate
1050
{
51.1.61 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1051
  assert(embedding);
2456.1.4 by Olaf van der Spek
Refactor
1052
  TableList* ptr= embedding;
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
1053
  join_list= ptr->getJoinList();
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1054
  embedding= ptr->getEmbedding();
2456.1.4 by Olaf van der Spek
Refactor
1055
  NestedJoin* nested_join= ptr->getNestedJoin();
2183.2.19 by Olaf van der Spek
Use List::size()
1056
  if (nested_join->join_list.size() == 1)
1 by brian
clean slate
1057
  {
2183.2.21 by Olaf van der Spek
Use List::front()
1058
    TableList *embedded= &nested_join->join_list.front();
1 by brian
clean slate
1059
    join_list->pop();
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
1060
    embedded->setJoinList(join_list);
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1061
    embedded->setEmbedding(embedding);
1 by brian
clean slate
1062
    join_list->push_front(embedded);
2456.1.4 by Olaf van der Spek
Refactor
1063
    return embedded;
1 by brian
clean slate
1064
  }
2456.1.4 by Olaf van der Spek
Refactor
1065
  else if (not nested_join->join_list.size())
1 by brian
clean slate
1066
  {
1067
    join_list->pop();
2456.1.4 by Olaf van der Spek
Refactor
1068
    return NULL;
1 by brian
clean slate
1069
  }
1054.1.5 by Brian Aker
Formatting/remove dead variables.
1070
  return ptr;
1 by brian
clean slate
1071
}
1072
1073
1074
/**
1075
  Nest last join operation.
1076
1077
    The function nest last join operation as if it was enclosed in braces.
1078
520.1.22 by Brian Aker
Second pass of thd cleanup
1079
  @param session         current thread
1 by brian
clean slate
1080
1081
  @retval
1082
    0  Error
1083
  @retval
327.2.4 by Brian Aker
Refactoring table.h
1084
    \#  Pointer to TableList element created for the new nested join
1 by brian
clean slate
1085
*/
1086
846 by Brian Aker
Removing on typedeffed class.
1087
TableList *Select_Lex::nest_last_join(Session *session)
1 by brian
clean slate
1088
{
2318.6.20 by Olaf van der Spek
Refactor
1089
  TableList* ptr= (TableList*) session->mem.calloc(ALIGN_SIZE(sizeof(TableList)) + sizeof(NestedJoin));
2141.3.3 by vjsamuel1990 at gmail
Merge change nested_join_st to NestedJoin
1090
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
2318.6.20 by Olaf van der Spek
Refactor
1091
  NestedJoin* nested_join= ptr->getNestedJoin();
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1092
  ptr->setEmbedding(embedding);
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
1093
  ptr->setJoinList(join_list);
1 by brian
clean slate
1094
  ptr->alias= (char*) "(nest_last_join)";
2318.6.20 by Olaf van der Spek
Refactor
1095
  List<TableList>* embedded_list= &nested_join->join_list;
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
1096
  embedded_list->clear();
1 by brian
clean slate
1097
438.1.13 by Brian Aker
uint cleanup.
1098
  for (uint32_t i=0; i < 2; i++)
1 by brian
clean slate
1099
  {
327.2.4 by Brian Aker
Refactoring table.h
1100
    TableList *table= join_list->pop();
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
1101
    table->setJoinList(embedded_list);
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1102
    table->setEmbedding(ptr);
1 by brian
clean slate
1103
    embedded_list->push_back(table);
1104
    if (table->natural_join)
1105
    {
55 by brian
Update for using real bool types.
1106
      ptr->is_natural_join= true;
1 by brian
clean slate
1107
      /*
1108
        If this is a JOIN ... USING, move the list of joined fields to the
1109
        table reference that describes the join.
1110
      */
1111
      if (prev_join_using)
1112
        ptr->join_using_fields= prev_join_using;
1113
    }
1114
  }
1115
  join_list->push_front(ptr);
1116
  nested_join->used_tables= nested_join->not_null_tables= (table_map) 0;
1054.1.5 by Brian Aker
Formatting/remove dead variables.
1117
  return ptr;
1 by brian
clean slate
1118
}
1119
1120
1121
/**
1122
  Add a table to the current join list.
1123
1124
    The function puts a table in front of the current join list
846 by Brian Aker
Removing on typedeffed class.
1125
    of Select_Lex object.
1 by brian
clean slate
1126
    Thus, joined tables are put into this list in the reverse order
1127
    (the most outer join operation follows first).
1128
1129
  @param table       the table to add
1130
1131
  @return
1132
    None
1133
*/
1134
846 by Brian Aker
Removing on typedeffed class.
1135
void Select_Lex::add_joined_table(TableList *table)
1 by brian
clean slate
1136
{
1137
  join_list->push_front(table);
1637.2.6 by Vijay Samuel
Merge encapsulate TableList-1.
1138
  table->setJoinList(join_list);
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1139
  table->setEmbedding(embedding);
1 by brian
clean slate
1140
}
1141
1142
1143
/**
1144
  Convert a right join into equivalent left join.
1145
1146
    The function takes the current join list t[0],t[1] ... and
1147
    effectively converts it into the list t[1],t[0] ...
1148
    Although the outer_join flag for the new nested table contains
1149
    JOIN_TYPE_RIGHT, it will be handled as the inner table of a left join
1150
    operation.
1151
1152
  EXAMPLES
1153
  @verbatim
1154
    SELECT * FROM t1 RIGHT JOIN t2 ON on_expr =>
1155
      SELECT * FROM t2 LEFT JOIN t1 ON on_expr
1156
1157
    SELECT * FROM t1,t2 RIGHT JOIN t3 ON on_expr =>
1158
      SELECT * FROM t1,t3 LEFT JOIN t2 ON on_expr
1159
1160
    SELECT * FROM t1,t2 RIGHT JOIN (t3,t4) ON on_expr =>
1161
      SELECT * FROM t1,(t3,t4) LEFT JOIN t2 ON on_expr
1162
1163
    SELECT * FROM t1 LEFT JOIN t2 ON on_expr1 RIGHT JOIN t3  ON on_expr2 =>
1164
      SELECT * FROM t3 LEFT JOIN (t1 LEFT JOIN t2 ON on_expr2) ON on_expr1
1165
   @endverbatim
1166
520.1.22 by Brian Aker
Second pass of thd cleanup
1167
  @param session         current thread
1 by brian
clean slate
1168
1169
  @return
1170
    - Pointer to the table representing the inner table, if success
1171
    - 0, otherwise
1172
*/
1173
846 by Brian Aker
Removing on typedeffed class.
1174
TableList *Select_Lex::convert_right_join()
1 by brian
clean slate
1175
{
327.2.4 by Brian Aker
Refactoring table.h
1176
  TableList *tab2= join_list->pop();
1177
  TableList *tab1= join_list->pop();
1 by brian
clean slate
1178
1179
  join_list->push_front(tab2);
1180
  join_list->push_front(tab1);
1181
  tab1->outer_join|= JOIN_TYPE_RIGHT;
1182
1054.1.5 by Brian Aker
Formatting/remove dead variables.
1183
  return tab1;
1 by brian
clean slate
1184
}
1185
1186
/**
1187
  Set lock for all tables in current select level.
1188
1189
  @param lock_type			Lock to set for tables
1190
1191
  @note
1192
    If lock is a write lock, then tables->updating is set 1
1193
    This is to get tables_ok to know that the table is updated by the
1194
    query
1195
*/
1196
846 by Brian Aker
Removing on typedeffed class.
1197
void Select_Lex::set_lock_for_tables(thr_lock_type lock_type)
1 by brian
clean slate
1198
{
2456.1.4 by Olaf van der Spek
Refactor
1199
  for (TableList *tables= (TableList*) table_list.first; tables; tables= tables->next_local)
1 by brian
clean slate
1200
  {
1201
    tables->lock_type= lock_type;
1202
  }
1203
}
1204
1205
1206
/**
846 by Brian Aker
Removing on typedeffed class.
1207
  Create a fake Select_Lex for a unit.
1 by brian
clean slate
1208
846 by Brian Aker
Removing on typedeffed class.
1209
    The method create a fake Select_Lex object for a unit.
1 by brian
clean slate
1210
    This object is created for any union construct containing a union
1211
    operation and also for any single select union construct of the form
1212
    @verbatim
1273.2.9 by Stewart Smith
fix accidental mangling of comment: s/order_st BY/ORDER BY/. in sql_parse.cc
1213
    (SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ...
1 by brian
clean slate
1214
    @endvarbatim
1215
    or of the form
1216
    @varbatim
1273.2.9 by Stewart Smith
fix accidental mangling of comment: s/order_st BY/ORDER BY/. in sql_parse.cc
1217
    (SELECT ... ORDER BY LIMIT n) ORDER BY ...
1 by brian
clean slate
1218
    @endvarbatim
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1219
520.1.22 by Brian Aker
Second pass of thd cleanup
1220
  @param session_arg		   thread handle
1 by brian
clean slate
1221
1222
  @note
1223
    The object is used to retrieve rows from the temporary table
1224
    where the result on the union is obtained.
1225
1226
  @retval
1227
    1     on failure to create the object
1228
  @retval
1229
    0     on success
1230
*/
1231
848 by Brian Aker
typdef class removal (just... use the name of the class).
1232
bool Select_Lex_Unit::add_fake_select_lex(Session *session_arg)
1 by brian
clean slate
1233
{
846 by Brian Aker
Removing on typedeffed class.
1234
  Select_Lex *first_sl= first_select();
51.1.61 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1235
  assert(!fake_select_lex);
1 by brian
clean slate
1236
2318.6.90 by Olaf van der Spek
Refactor
1237
  fake_select_lex= new (session_arg->mem_root) Select_Lex();
1238
  fake_select_lex->include_standalone(this, (Select_Lex_Node**)&fake_select_lex);
1 by brian
clean slate
1239
  fake_select_lex->select_number= INT_MAX;
2227.4.10 by Olaf van der Spek
Session::lex()
1240
  fake_select_lex->parent_lex= &session_arg->lex(); /* Used in init_query. */
1 by brian
clean slate
1241
  fake_select_lex->make_empty_select();
1242
  fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
1243
  fake_select_lex->select_limit= 0;
1244
1245
  fake_select_lex->context.outer_context=first_sl->context.outer_context;
1273.2.9 by Stewart Smith
fix accidental mangling of comment: s/order_st BY/ORDER BY/. in sql_parse.cc
1246
  /* allow item list resolving in fake select for ORDER BY */
55 by brian
Update for using real bool types.
1247
  fake_select_lex->context.resolve_in_select_list= true;
1 by brian
clean slate
1248
  fake_select_lex->context.select_lex= fake_select_lex;
1249
1250
  if (!is_union())
1251
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1252
    /*
1253
      This works only for
1273.2.9 by Stewart Smith
fix accidental mangling of comment: s/order_st BY/ORDER BY/. in sql_parse.cc
1254
      (SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
1255
      (SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
1 by brian
clean slate
1256
      just before the parser starts processing order_list
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1257
    */
1 by brian
clean slate
1258
    global_parameters= fake_select_lex;
1259
    fake_select_lex->no_table_names_allowed= 1;
2227.4.8 by Olaf van der Spek
Session::lex()
1260
    session_arg->lex().current_select= fake_select_lex;
1 by brian
clean slate
1261
  }
2227.4.8 by Olaf van der Spek
Session::lex()
1262
  session_arg->lex().pop_context();
2318.6.58 by Olaf van der Spek
Refactor
1263
  return 0;
1 by brian
clean slate
1264
}
1265
1266
1267
/**
1268
  Push a new name resolution context for a JOIN ... ON clause to the
1269
  context stack of a query block.
1270
1271
    Create a new name resolution context for a JOIN ... ON clause,
1272
    set the first and last leaves of the list of table references
1273
    to be used for name resolution, and push the newly created
1274
    context to the stack of contexts of the query.
1275
520.1.22 by Brian Aker
Second pass of thd cleanup
1276
  @param session       pointer to current thread
1 by brian
clean slate
1277
  @param left_op   left  operand of the JOIN
1278
  @param right_op  rigth operand of the JOIN
1279
1280
  @retval
55 by brian
Update for using real bool types.
1281
    false  if all is OK
1 by brian
clean slate
1282
  @retval
55 by brian
Update for using real bool types.
1283
    true   if a memory allocation error occured
1 by brian
clean slate
1284
*/
1285
2241.2.13 by Olaf van der Spek
Refactor
1286
void push_new_name_resolution_context(Session& session, TableList& left_op, TableList& right_op)
1 by brian
clean slate
1287
{
2241.2.13 by Olaf van der Spek
Refactor
1288
  Name_resolution_context *on_context= new (session.mem_root) Name_resolution_context;
1 by brian
clean slate
1289
  on_context->init();
2241.2.13 by Olaf van der Spek
Refactor
1290
  on_context->first_name_resolution_table= left_op.first_leaf_for_name_resolution();
1291
  on_context->last_name_resolution_table= right_op.last_leaf_for_name_resolution();
1292
  session.lex().push_context(on_context);
1 by brian
clean slate
1293
}
1294
1295
1296
/**
1297
  Add an ON condition to the second operand of a JOIN ... ON.
1298
1299
    Add an ON condition to the right operand of a JOIN ... ON clause.
1300
1301
  @param b     the second operand of a JOIN ... ON
1302
  @param expr  the condition to be added to the ON clause
1303
1304
  @retval
55 by brian
Update for using real bool types.
1305
    false  if there was some error
1 by brian
clean slate
1306
  @retval
55 by brian
Update for using real bool types.
1307
    true   if all is OK
1 by brian
clean slate
1308
*/
1309
327.2.4 by Brian Aker
Refactoring table.h
1310
void add_join_on(TableList *b, Item *expr)
1 by brian
clean slate
1311
{
1312
  if (expr)
1313
  {
1314
    if (!b->on_expr)
1315
      b->on_expr= expr;
1316
    else
1317
    {
1318
      /*
1319
        If called from the parser, this happens if you have both a
1320
        right and left join. If called later, it happens if we add more
1321
        than one condition to the ON clause.
1322
      */
1323
      b->on_expr= new Item_cond_and(b->on_expr,expr);
1324
    }
1325
    b->on_expr->top_level_item();
1326
  }
1327
}
1328
1329
1330
/**
1331
  Mark that there is a NATURAL JOIN or JOIN ... USING between two
1332
  tables.
1333
1334
    This function marks that table b should be joined with a either via
1335
    a NATURAL JOIN or via JOIN ... USING. Both join types are special
1336
    cases of each other, so we treat them together. The function
1337
    setup_conds() creates a list of equal condition between all fields
1338
    of the same name for NATURAL JOIN or the fields in 'using_fields'
1339
    for JOIN ... USING. The list of equality conditions is stored
1340
    either in b->on_expr, or in JOIN::conds, depending on whether there
1341
    was an outer join.
1342
1343
  EXAMPLE
1344
  @verbatim
1345
    SELECT * FROM t1 NATURAL LEFT JOIN t2
1346
     <=>
1347
    SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
1348
1349
    SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
1350
     <=>
1351
    SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
1352
1353
    SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
1354
     <=>
1355
    SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
1356
   @endverbatim
1357
1358
  @param a		  Left join argument
1359
  @param b		  Right join argument
1360
  @param using_fields    Field names from USING clause
1361
*/
1362
327.2.4 by Brian Aker
Refactoring table.h
1363
void add_join_natural(TableList *a, TableList *b, List<String> *using_fields,
846 by Brian Aker
Removing on typedeffed class.
1364
                      Select_Lex *lex)
1 by brian
clean slate
1365
{
1366
  b->natural_join= a;
1367
  lex->prev_join_using= using_fields;
1368
}
1369
1370
1371
/**
1372
  Check if the select is a simple select (not an union).
1373
1374
  @retval
1375
    0	ok
1376
  @retval
1377
    1	error	; In this case the error messege is sent to the client
1378
*/
1379
2246.4.12 by Olaf van der Spek
Remove const_reference and reference from Session
1380
bool check_simple_select(Session* session)
1 by brian
clean slate
1381
{
2227.4.8 by Olaf van der Spek
Session::lex()
1382
  if (session->lex().current_select != &session->lex().select_lex)
1 by brian
clean slate
1383
  {
1384
    char command[80];
520.1.22 by Brian Aker
Second pass of thd cleanup
1385
    Lex_input_stream *lip= session->m_lip;
629.5.2 by Toru Maesaka
Second pass of replacing MySQL's strmake() with libc calls
1386
    strncpy(command, lip->yylval->symbol.str,
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
1387
            min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1)));
1388
    command[min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1))]=0;
1 by brian
clean slate
1389
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
1390
    return 1;
1391
  }
1392
  return 0;
1393
}
1394
1395
1396
/**
1397
  Construct ALL/ANY/SOME subquery Item.
1398
1399
  @param left_expr   pointer to left expression
1400
  @param cmp         compare function creator
1401
  @param all         true if we create ALL subquery
1402
  @param select_lex  pointer on parsed subquery structure
1403
1404
  @return
1405
    constructed Item (or 0 if out of memory)
1406
*/
1407
Item * all_any_subquery_creator(Item *left_expr,
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
1408
                                chooser_compare_func_creator cmp,
1409
                                bool all,
846 by Brian Aker
Removing on typedeffed class.
1410
                                Select_Lex *select_lex)
1 by brian
clean slate
1411
{
1412
  if ((cmp == &comp_eq_creator) && !all)       //  = ANY <=> IN
1413
    return new Item_in_subselect(left_expr, select_lex);
1414
1415
  if ((cmp == &comp_ne_creator) && all)        // <> ALL <=> NOT IN
1416
    return new Item_func_not(new Item_in_subselect(left_expr, select_lex));
1417
1418
  Item_allany_subselect *it=
1419
    new Item_allany_subselect(left_expr, cmp, select_lex, all);
1420
  if (all)
1421
    return it->upper_item= new Item_func_not_all(it);	/* ALL */
1422
1423
  return it->upper_item= new Item_func_nop_all(it);      /* ANY/SOME */
1424
}
1425
1426
1427
/**
826 by Brian Aker
Simplify update
1428
  Update query pre-check.
1 by brian
clean slate
1429
520.1.22 by Brian Aker
Second pass of thd cleanup
1430
  @param session		Thread handler
1 by brian
clean slate
1431
  @param tables	Global/local table list (have to be the same)
1432
1433
  @retval
55 by brian
Update for using real bool types.
1434
    false OK
1 by brian
clean slate
1435
  @retval
55 by brian
Update for using real bool types.
1436
    true  Error
1 by brian
clean slate
1437
*/
1438
826 by Brian Aker
Simplify update
1439
bool update_precheck(Session *session, TableList *)
1 by brian
clean slate
1440
{
1441
  const char *msg= 0;
2227.4.8 by Olaf van der Spek
Session::lex()
1442
  Select_Lex *select_lex= &session->lex().select_lex;
1 by brian
clean slate
1443
2227.4.8 by Olaf van der Spek
Session::lex()
1444
  if (session->lex().select_lex.item_list.size() != session->lex().value_list.size())
1 by brian
clean slate
1445
  {
1446
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
2318.6.55 by Olaf van der Spek
Refactor
1447
    return true;
1 by brian
clean slate
1448
  }
1449
2227.4.8 by Olaf van der Spek
Session::lex()
1450
  if (session->lex().select_lex.table_list.size() > 1)
1 by brian
clean slate
1451
  {
2183.2.19 by Olaf van der Spek
Use List::size()
1452
    if (select_lex->order_list.size())
826 by Brian Aker
Simplify update
1453
      msg= "ORDER BY";
1454
    else if (select_lex->select_limit)
1455
      msg= "LIMIT";
1456
    if (msg)
1457
    {
1458
      my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
2318.6.55 by Olaf van der Spek
Refactor
1459
      return true;
826 by Brian Aker
Simplify update
1460
    }
1 by brian
clean slate
1461
  }
2318.6.55 by Olaf van der Spek
Refactor
1462
  return false;
1 by brian
clean slate
1463
}
1464
1465
1466
/**
1467
  simple INSERT query pre-check.
1468
520.1.22 by Brian Aker
Second pass of thd cleanup
1469
  @param session		Thread handler
1 by brian
clean slate
1470
  @param tables	Global table list
1471
1472
  @retval
55 by brian
Update for using real bool types.
1473
    false  OK
1 by brian
clean slate
1474
  @retval
55 by brian
Update for using real bool types.
1475
    true   error
1 by brian
clean slate
1476
*/
1477
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1478
bool insert_precheck(Session *session, TableList *)
1 by brian
clean slate
1479
{
1480
  /*
1481
    Check that we have modify privileges for the first table and
1482
    select privileges for the rest
1483
  */
2227.4.8 by Olaf van der Spek
Session::lex()
1484
  if (session->lex().update_list.size() != session->lex().value_list.size())
1 by brian
clean slate
1485
  {
1486
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
2318.6.55 by Olaf van der Spek
Refactor
1487
    return true;
1 by brian
clean slate
1488
  }
2318.6.55 by Olaf van der Spek
Refactor
1489
  return false;
1 by brian
clean slate
1490
}
1491
1492
1493
/**
1494
  negate given expression.
1495
520.1.22 by Brian Aker
Second pass of thd cleanup
1496
  @param session  thread handler
1 by brian
clean slate
1497
  @param expr expression for negation
1498
1499
  @return
1500
    negated expression
1501
*/
1502
520.1.22 by Brian Aker
Second pass of thd cleanup
1503
Item *negate_expression(Session *session, Item *expr)
1 by brian
clean slate
1504
{
1505
  Item *negated;
1506
  if (expr->type() == Item::FUNC_ITEM &&
1507
      ((Item_func *) expr)->functype() == Item_func::NOT_FUNC)
1508
  {
1509
    /* it is NOT(NOT( ... )) */
1510
    Item *arg= ((Item_func *) expr)->arguments()[0];
2227.4.8 by Olaf van der Spek
Session::lex()
1511
    enum_parsing_place place= session->lex().current_select->parsing_place;
1 by brian
clean slate
1512
    if (arg->is_bool_func() || place == IN_WHERE || place == IN_HAVING)
1513
      return arg;
1514
    /*
1515
      if it is not boolean function then we have to emulate value of
1516
      not(not(a)), it will be a != 0
1517
    */
1518
    return new Item_func_ne(arg, new Item_int((char*) "0", 0, 1));
1519
  }
1520
520.1.22 by Brian Aker
Second pass of thd cleanup
1521
  if ((negated= expr->neg_transformer(session)) != 0)
1 by brian
clean slate
1522
    return negated;
1523
  return new Item_func_not(expr);
1524
}
1525
1526
1527
/*
1528
  Check that char length of a string does not exceed some limit.
1529
1530
  SYNOPSIS
1531
  check_string_char_length()
1532
      str              string to be checked
1533
      err_msg          error message to be displayed if the string is too long
1534
      max_char_length  max length in symbols
1535
      cs               string charset
1536
1537
  RETURN
55 by brian
Update for using real bool types.
1538
    false   the passed string is not longer than max_char_length
1539
    true    the passed string is longer than max_char_length
1 by brian
clean slate
1540
*/
1541
1542
2440.2.6 by Olaf van der Spek
Use str_ref
1543
bool check_string_char_length(str_ref str, const char *err_msg,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1544
                              uint32_t max_char_length, const charset_info_st * const cs,
1 by brian
clean slate
1545
                              bool no_error)
1546
{
1547
  int well_formed_error;
2440.2.14 by Olaf van der Spek
Refactor
1548
  uint32_t res= cs->cset->well_formed_len(*cs, str, max_char_length, &well_formed_error);
1 by brian
clean slate
1549
2445.1.19 by Olaf van der Spek
Refactor
1550
  if (!well_formed_error && str.size() == res)
55 by brian
Update for using real bool types.
1551
    return false;
1 by brian
clean slate
1552
2445.1.19 by Olaf van der Spek
Refactor
1553
  if (not no_error)
2440.2.6 by Olaf van der Spek
Use str_ref
1554
    my_error(ER_WRONG_STRING_LENGTH, MYF(0), str.data(), err_msg, max_char_length);
55 by brian
Update for using real bool types.
1555
  return true;
1 by brian
clean slate
1556
}
1557
1558
2440.2.5 by Olaf van der Spek
Use str_ref
1559
bool check_identifier_name(str_ref str, error_t err_code)
1 by brian
clean slate
1560
{
2440.2.3 by Olaf van der Spek
Refactor
1561
  uint32_t max_char_length= NAME_CHAR_LEN;
1 by brian
clean slate
1562
  /*
1563
    We don't support non-BMP characters in identifiers at the moment,
1564
    so they should be prohibited until such support is done.
1565
    This is why we use the 3-byte utf8 to check well-formedness here.
1566
  */
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1567
  const charset_info_st * const cs= &my_charset_utf8mb4_general_ci;
760 by Brian Aker
Cleanup around UTf8 code.
1568
1 by brian
clean slate
1569
  int well_formed_error;
2440.2.14 by Olaf van der Spek
Refactor
1570
  uint32_t res= cs->cset->well_formed_len(*cs, str, max_char_length, &well_formed_error);
1 by brian
clean slate
1571
1572
  if (well_formed_error)
1573
  {
2440.3.1 by Olaf van der Spek
Refactor
1574
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", str.data());
55 by brian
Update for using real bool types.
1575
    return true;
1 by brian
clean slate
1576
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1577
2440.3.1 by Olaf van der Spek
Refactor
1578
  if (str.size() == res)
55 by brian
Update for using real bool types.
1579
    return false;
1 by brian
clean slate
1580
1581
  switch (err_code)
1582
  {
2041.3.14 by Brian Aker
Additional error cleanup.
1583
  case EE_OK:
1 by brian
clean slate
1584
    break;
1585
  case ER_WRONG_STRING_LENGTH:
2440.2.3 by Olaf van der Spek
Refactor
1586
    my_error(err_code, MYF(0), str.data(), "", max_char_length);
1 by brian
clean slate
1587
    break;
1588
  case ER_TOO_LONG_IDENT:
2440.3.1 by Olaf van der Spek
Refactor
1589
    my_error(err_code, MYF(0), str.data());
1 by brian
clean slate
1590
    break;
1591
  default:
2433.1.5 by Olaf van der Spek
Use assign(), data() and size()
1592
    assert(false);
1 by brian
clean slate
1593
  }
2041.3.14 by Brian Aker
Additional error cleanup.
1594
55 by brian
Update for using real bool types.
1595
  return true;
1 by brian
clean slate
1596
}
1597
1598
1599
/**
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1600
  This is a wrapper of DRIZZLEparse(). All the code should call parse_sql()
1601
  instead of DRIZZLEparse().
1 by brian
clean slate
1602
520.1.22 by Brian Aker
Second pass of thd cleanup
1603
  @param session Thread context.
1 by brian
clean slate
1604
  @param lip Lexer context.
1605
1606
  @return Error status.
55 by brian
Update for using real bool types.
1607
    @retval false on success.
1608
    @retval true on parsing error.
1 by brian
clean slate
1609
*/
1610
1165.1.48 by Stewart Smith
make parse_sql static to sql_parse.cc
1611
static bool parse_sql(Session *session, Lex_input_stream *lip)
1 by brian
clean slate
1612
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1613
  assert(session->m_lip == NULL);
1 by brian
clean slate
1614
1932.2.3 by Brian Aker
Updates for D-trace
1615
  DRIZZLE_QUERY_PARSE_START(session->getQueryString()->c_str());
1126.10.15 by Padraig O'Sullivan
Added calls to the parsing related dtrace probes.
1616
1 by brian
clean slate
1617
  /* Set Lex_input_stream. */
1618
520.1.22 by Brian Aker
Second pass of thd cleanup
1619
  session->m_lip= lip;
1 by brian
clean slate
1620
1621
  /* Parse the query. */
1622
2172.3.6 by Brian Aker
Namespace the parser just a bit, and update our call for the type of parser
1623
  bool parse_status= base_sql_parse(session) != 0;
520.1.22 by Brian Aker
Second pass of thd cleanup
1624
520.4.50 by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE
1625
  /* Check that if DRIZZLEparse() failed, session->is_error() is set. */
520.1.22 by Brian Aker
Second pass of thd cleanup
1626
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
1627
  assert(!parse_status || session->is_error());
1 by brian
clean slate
1628
1629
  /* Reset Lex_input_stream. */
1630
520.1.22 by Brian Aker
Second pass of thd cleanup
1631
  session->m_lip= NULL;
1 by brian
clean slate
1632
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
1633
  DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
1126.10.15 by Padraig O'Sullivan
Added calls to the parsing related dtrace probes.
1634
1 by brian
clean slate
1635
  /* That's it. */
1636
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
1637
  return parse_status || session->is_fatal_error;
1 by brian
clean slate
1638
}
1639
1640
/**
1641
  @} (end of group Runtime_Environment)
1642
*/
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1643
1644
} /* namespace drizzled */