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