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