~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* sql_yacc.yy */
17
18
/**
19
  @defgroup Parser Parser
20
  @{
21
*/
22
23
%{
520.1.22 by Brian Aker
Second pass of thd cleanup
24
/* session is passed as an argument to yyparse(), and subsequently to yylex().
25
** The type will be void*, so it must be  cast to (Session*) when used.
26
** Use the YYSession macro for this.
1 by brian
clean slate
27
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
28
#define YYPARSE_PARAM yysession
29
#define YYLEX_PARAM yysession
1101.2.4 by Monty Taylor
Fixed some small errors in previous patches.
30
#define YYSession (static_cast<Session *>(yysession))
1 by brian
clean slate
31
77.1.45 by Monty Taylor
Warning fixes.
32
#define YYENABLE_NLS 0
33
#define YYLTYPE_IS_TRIVIAL 0
34
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
35
#define DRIZZLE_YACC
1 by brian
clean slate
36
#define YYINITDEPTH 100
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
520.1.22 by Brian Aker
Second pass of thd cleanup
38
#define Lex (YYSession->lex)
1285 by Brian Aker
Remove giant include header to its own file.
39
1286.1.3 by Brian Aker
Modify to remove config.h from parser.h
40
#include "config.h"
1530.5.10 by Monty Taylor
Fixed build errors on FreeBSD.
41
#include <cstdio>
1285 by Brian Aker
Remove giant include header to its own file.
42
#include "drizzled/parser.h"
1100.3.1 by Padraig O'Sullivan
Beginnings of reworking the mysql_execute_command() method.
43
520.1.22 by Brian Aker
Second pass of thd cleanup
44
int yylex(void *yylval, void *yysession);
1 by brian
clean slate
45
46
#define yyoverflow(A,B,C,D,E,F)               \
47
  {                                           \
48
    ulong val= *(F);                          \
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
1 by brian
clean slate
50
    {                                         \
51
      yyerror((char*) (A));                   \
52
      return 2;                               \
53
    }                                         \
54
    else                                      \
55
    {                                         \
56
      *(F)= (YYSIZE_T)val;                    \
57
    }                                         \
58
  }
59
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
60
#define DRIZZLE_YYABORT                         \
1 by brian
clean slate
61
  do                                          \
62
  {                                           \
520.1.22 by Brian Aker
Second pass of thd cleanup
63
    LEX::cleanup_lex_after_parse_error(YYSession);\
1 by brian
clean slate
64
    YYABORT;                                  \
65
  } while (0)
66
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
1 by brian
clean slate
68
  if (!(A))                             \
69
  {                                     \
1578.6.11 by Brian Aker
Additional removal of current_session
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
71
    my_parse_error(&pass);\
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
72
    DRIZZLE_YYABORT;                      \
1 by brian
clean slate
73
  }
74
779.4.5 by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!!
75
1 by brian
clean slate
76
#define YYDEBUG 0
77
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
78
namespace drizzled
79
{
80
81
class Table_ident;
82
class Item;
83
class Item_num;
84
85
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
86
static bool check_reserved_words(LEX_STRING *name)
87
{
88
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
89
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
90
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
91
    return true;
92
  return false;
93
}
94
1 by brian
clean slate
95
/**
96
  @brief Push an error message into MySQL error stack with line
97
  and position information.
98
99
  This function provides semantic action implementers with a way
100
  to push the famous "You have a syntax error near..." error
101
  message into the error stack, which is normally produced only if
102
  a parse error is discovered internally by the Bison generated
103
  parser.
104
*/
105
1578.6.11 by Brian Aker
Additional removal of current_session
106
struct my_parse_error_st {
107
  const char *s;
108
  Session *session;
109
};
110
111
static void my_parse_error(void *arg)
1 by brian
clean slate
112
{
1578.6.11 by Brian Aker
Additional removal of current_session
113
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
114
115
  const char *s= ptr->s;
116
  Session *session= ptr->session;
117
520.1.22 by Brian Aker
Second pass of thd cleanup
118
  Lex_input_stream *lip= session->m_lip;
1 by brian
clean slate
119
120
  const char *yytext= lip->get_tok_start();
121
  /* Push an error into the error stack */
122
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
123
                  (yytext ? yytext : ""),
124
                  lip->yylineno);
125
}
126
127
/**
128
  @brief Bison callback to report a syntax/OOM error
129
130
  This function is invoked by the bison-generated parser
131
  when a syntax error, a parse error or an out-of-memory
132
  condition occurs. This function is not invoked when the
133
  parser is requested to abort by semantic action code
134
  by means of YYABORT or YYACCEPT macros. This is why these
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
135
  macros should not be used (use DRIZZLE_YYABORT/DRIZZLE_YYACCEPT
1 by brian
clean slate
136
  instead).
137
138
  The parser will abort immediately after invoking this callback.
139
140
  This function is not for use in semantic actions and is internal to
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
141
  the parser, as it performs some pre-return cleanup.
1 by brian
clean slate
142
  In semantic actions, please use my_parse_error or my_error to
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
143
  push an error into the error stack and DRIZZLE_YYABORT
1 by brian
clean slate
144
  to abort from the parser.
145
*/
146
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
147
static void DRIZZLEerror(const char *s)
1 by brian
clean slate
148
{
520.1.22 by Brian Aker
Second pass of thd cleanup
149
  Session *session= current_session;
1 by brian
clean slate
150
151
  /*
152
    Restore the original LEX if it was replaced when parsing
153
    a stored procedure. We must ensure that a parsing error
520.1.22 by Brian Aker
Second pass of thd cleanup
154
    does not leave any side effects in the Session.
1 by brian
clean slate
155
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
156
  LEX::cleanup_lex_after_parse_error(session);
1 by brian
clean slate
157
158
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
159
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
160
    s= ER(ER_SYNTAX_ERROR);
1578.6.11 by Brian Aker
Additional removal of current_session
161
162
  struct my_parse_error_st pass= { s, session };
163
  my_parse_error(&pass);
1 by brian
clean slate
164
}
165
166
/**
167
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
168
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
169
  This function returns the proper item for the SQL expression
170
  <code>left [NOT] IN ( expr )</code>
520.1.22 by Brian Aker
Second pass of thd cleanup
171
  @param session the current thread
1 by brian
clean slate
172
  @param left the in predicand
173
  @param equal true for IN predicates, false for NOT IN predicates
174
  @param expr first and only expression of the in value list
175
  @return an expression representing the IN predicate.
176
*/
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
177
static Item* handle_sql2003_note184_exception(Session *session,
178
                                              Item* left, bool equal,
179
                                              Item *expr)
1 by brian
clean slate
180
{
181
  /*
182
    Relevant references for this issue:
183
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
184
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
185
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
186
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
187
    - SQL:2003 Feature F561, "Full value expressions".
188
189
    The exception in SQL:2003 Note 184 means:
190
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
191
    should be re-interpreted as an Item_in_subselect, which corresponds
192
    to a <table subquery> when used inside an <in predicate>.
193
194
    Our reading of Note 184 is reccursive, so that all:
195
    - IN (( <subquery> ))
196
    - IN ((( <subquery> )))
197
    - IN '('^N <subquery> ')'^N
198
    - etc
199
    should be interpreted as a <table subquery>, no matter how deep in the
200
    expression the <subquery> is.
201
  */
202
203
  Item *result;
204
205
  if (expr->type() == Item::SUBSELECT_ITEM)
206
  {
207
    Item_subselect *expr2 = (Item_subselect*) expr;
208
209
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
210
    {
211
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
846 by Brian Aker
Removing on typedeffed class.
212
      Select_Lex *subselect;
1 by brian
clean slate
213
214
      /*
215
        Implement the mandated change, by altering the semantic tree:
216
          left IN Item_singlerow_subselect(subselect)
217
        is modified to
218
          left IN (subselect)
219
        which is represented as
220
          Item_in_subselect(left, subselect)
221
      */
222
      subselect= expr3->invalidate_and_restore_select_lex();
520.1.22 by Brian Aker
Second pass of thd cleanup
223
      result= new (session->mem_root) Item_in_subselect(left, subselect);
1 by brian
clean slate
224
225
      if (! equal)
520.1.22 by Brian Aker
Second pass of thd cleanup
226
        result = negate_expression(session, result);
1 by brian
clean slate
227
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
228
      return(result);
1 by brian
clean slate
229
    }
230
  }
231
232
  if (equal)
520.1.22 by Brian Aker
Second pass of thd cleanup
233
    result= new (session->mem_root) Item_func_eq(left, expr);
1 by brian
clean slate
234
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
235
    result= new (session->mem_root) Item_func_ne(left, expr);
1 by brian
clean slate
236
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
237
  return(result);
1 by brian
clean slate
238
}
239
240
/**
846 by Brian Aker
Removing on typedeffed class.
241
   @brief Creates a new Select_Lex for a UNION branch.
1 by brian
clean slate
242
846 by Brian Aker
Removing on typedeffed class.
243
   Sets up and initializes a Select_Lex structure for a query once the parser
244
   discovers a UNION token. The current Select_Lex is pushed on the stack and
245
   the new Select_Lex becomes the current one..=
1 by brian
clean slate
246
247
   @lex The parser state.
248
249
   @is_union_distinct True if the union preceding the new select statement
250
   uses UNION DISTINCT.
251
252
   @return <code>false</code> if successful, <code>true</code> if an error was
253
   reported. In the latter case parsing should stop.
254
 */
1578.6.11 by Brian Aker
Additional removal of current_session
255
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
1 by brian
clean slate
256
{
257
  if (lex->result)
258
  {
259
    /* Only the last SELECT can have  INTO...... */
260
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
261
    return true;
1 by brian
clean slate
262
  }
263
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
264
  {
1578.6.11 by Brian Aker
Additional removal of current_session
265
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
266
    my_parse_error(&pass);
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
267
    return true;
1 by brian
clean slate
268
  }
269
  /* This counter shouldn't be incremented for UNION parts */
270
  lex->nest_level--;
271
  if (mysql_new_select(lex, 0))
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
272
    return true;
1 by brian
clean slate
273
  mysql_init_select(lex);
274
  lex->current_select->linkage=UNION_TYPE;
275
  if (is_union_distinct) /* UNION DISTINCT - remember position */
276
    lex->current_select->master_unit()->union_distinct=
277
      lex->current_select;
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
278
  return false;
1 by brian
clean slate
279
}
280
281
/**
846 by Brian Aker
Removing on typedeffed class.
282
   @brief Initializes a Select_Lex for a query within parentheses (aka
1 by brian
clean slate
283
   braces).
284
285
   @return false if successful, true if an error was reported. In the latter
286
   case parsing should stop.
287
 */
1578.6.11 by Brian Aker
Additional removal of current_session
288
static bool setup_select_in_parentheses(Session *session, LEX *lex)
1 by brian
clean slate
289
{
846 by Brian Aker
Removing on typedeffed class.
290
  Select_Lex * sel= lex->current_select;
1 by brian
clean slate
291
  if (sel->set_braces(1))
292
  {
1578.6.11 by Brian Aker
Additional removal of current_session
293
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
294
    my_parse_error(&pass);
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
295
    return true;
1 by brian
clean slate
296
  }
297
  if (sel->linkage == UNION_TYPE &&
298
      !sel->master_unit()->first_select()->braces &&
299
      sel->master_unit()->first_select()->linkage ==
300
      UNION_TYPE)
301
  {
1578.6.11 by Brian Aker
Additional removal of current_session
302
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
303
    my_parse_error(&pass);
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
304
    return true;
1 by brian
clean slate
305
  }
306
  if (sel->linkage == UNION_TYPE &&
307
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
308
      sel->master_unit()->fake_select_lex)
309
  {
310
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
311
    return true;
1 by brian
clean slate
312
  }
313
  /* select in braces, can't contain global parameters */
314
  if (sel->master_unit()->fake_select_lex)
315
    sel->master_unit()->global_parameters=
316
      sel->master_unit()->fake_select_lex;
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
317
  return false;
1 by brian
clean slate
318
}
319
1578.6.12 by Brian Aker
Additional current_session removal
320
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
321
{
322
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
323
  Item *item= NULL;
324
325
  if (udf)
326
  {
1578.6.12 by Brian Aker
Additional current_session removal
327
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
328
  } else {
329
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
330
  }
331
332
  return item;
333
}
334
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
335
} /* namespace drizzled; */
336
337
using namespace drizzled;
1 by brian
clean slate
338
%}
339
%union {
340
  int  num;
341
  ulong ulong_num;
151 by Brian Aker
Ulonglong to uint64_t
342
  uint64_t ulonglong_number;
154 by Brian Aker
Removed oddball types in my_global.h
343
  int64_t longlong_number;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
344
  drizzled::LEX_STRING lex_str;
345
  drizzled::LEX_STRING *lex_str_ptr;
346
  drizzled::LEX_SYMBOL symbol;
347
  drizzled::Table_ident *table;
1 by brian
clean slate
348
  char *simple_string;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
349
  drizzled::Item *item;
350
  drizzled::Item_num *item_num;
351
  drizzled::List<drizzled::Item> *item_list;
352
  drizzled::List<drizzled::String> *string_list;
353
  drizzled::String *string;
354
  drizzled::Key_part_spec *key_part;
355
  const drizzled::plugin::Function *udf;
356
  drizzled::TableList *table_list;
357
  struct drizzled::sys_var_with_base variable;
1273.14.5 by Monty Taylor
Merged trunk.
358
  enum drizzled::sql_var_t var_type;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
359
  drizzled::Key::Keytype key_type;
360
  enum drizzled::ha_key_alg key_alg;
361
  enum drizzled::column_format_type column_format_type;
362
  enum drizzled::ha_rkey_function ha_rkey_mode;
363
  enum drizzled::enum_tx_isolation tx_isolation;
364
  enum drizzled::Cast_target cast_type;
365
  const drizzled::CHARSET_INFO *charset;
366
  drizzled::thr_lock_type lock_type;
367
  drizzled::interval_type interval, interval_time_st;
368
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
369
  drizzled::Select_Lex *select_lex;
370
  drizzled::chooser_compare_func_creator boolfunc2creator;
371
  struct drizzled::st_lex *lex;
372
  enum drizzled::index_hint_type index_hint;
373
  enum drizzled::enum_filetype filetype;
374
  enum drizzled::ha_build_method build_method;
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
375
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
1 by brian
clean slate
376
}
377
378
%{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
379
namespace drizzled
380
{
1 by brian
clean slate
381
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
382
}
1 by brian
clean slate
383
%}
384
385
%pure_parser                                    /* We have threads */
386
/*
1108.1.1 by Brian Aker
Remove multi-update from parser/tests.
387
  Currently there are 88 shift/reduce conflicts.
1 by brian
clean slate
388
  We should not introduce new conflicts any more.
389
*/
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
390
%expect 94
1 by brian
clean slate
391
392
/*
393
   Comments for TOKENS.
394
   For each token, please include in the same line a comment that contains
395
   the following tags:
396
   SQL-2003-R : Reserved keyword as per SQL-2003
397
   SQL-2003-N : Non Reserved keyword as per SQL-2003
398
   SQL-1999-R : Reserved keyword as per SQL-1999
399
   SQL-1999-N : Non Reserved keyword as per SQL-1999
400
   MYSQL      : MySQL extention (unspecified)
401
   MYSQL-FUNC : MySQL extention, function
402
   INTERNAL   : Not a real token, lex optimization
403
   OPERATOR   : SQL operator
404
   FUTURE-USE : Reserved for futur use
405
406
   This makes the code grep-able, and helps maintenance.
407
*/
408
409
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
410
%token  ACTION                        /* SQL-2003-N */
411
%token  ADD                           /* SQL-2003-R */
412
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
413
%token  AFTER_SYM                     /* SQL-2003-N */
414
%token  AGGREGATE_SYM
415
%token  ALL                           /* SQL-2003-R */
416
%token  ALTER                         /* SQL-2003-R */
417
%token  ANALYZE_SYM
418
%token  AND_SYM                       /* SQL-2003-R */
419
%token  ANY_SYM                       /* SQL-2003-R */
420
%token  AS                            /* SQL-2003-R */
421
%token  ASC                           /* SQL-2003-N */
422
%token  ASENSITIVE_SYM                /* FUTURE-USE */
423
%token  AT_SYM                        /* SQL-2003-R */
424
%token  AUTO_INC
425
%token  AVG_ROW_LENGTH
426
%token  AVG_SYM                       /* SQL-2003-N */
427
%token  BEFORE_SYM                    /* SQL-2003-N */
428
%token  BEGIN_SYM                     /* SQL-2003-R */
429
%token  BETWEEN_SYM                   /* SQL-2003-R */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
430
%token  BIGINT_SYM                    /* SQL-2003-R */
1 by brian
clean slate
431
%token  BINARY                        /* SQL-2003-R */
432
%token  BIN_NUM
433
%token  BIT_SYM                       /* MYSQL-FUNC */
434
%token  BLOB_SYM                      /* SQL-2003-R */
435
%token  BOOLEAN_SYM                   /* SQL-2003-R */
436
%token  BOOL_SYM
437
%token  BOTH                          /* SQL-2003-R */
438
%token  BTREE_SYM
439
%token  BY                            /* SQL-2003-R */
440
%token  BYTE_SYM
441
%token  CALL_SYM                      /* SQL-2003-R */
442
%token  CASCADE                       /* SQL-2003-N */
443
%token  CASCADED                      /* SQL-2003-R */
444
%token  CASE_SYM                      /* SQL-2003-R */
445
%token  CAST_SYM                      /* SQL-2003-R */
446
%token  CHAIN_SYM                     /* SQL-2003-N */
447
%token  CHANGE
448
%token  CHAR_SYM                      /* SQL-2003-R */
449
%token  CHECKSUM_SYM
450
%token  CHECK_SYM                     /* SQL-2003-R */
451
%token  CLOSE_SYM                     /* SQL-2003-R */
452
%token  COALESCE                      /* SQL-2003-N */
453
%token  COLLATE_SYM                   /* SQL-2003-R */
454
%token  COLLATION_SYM                 /* SQL-2003-N */
455
%token  COLUMNS
456
%token  COLUMN_SYM                    /* SQL-2003-R */
457
%token  COMMENT_SYM
458
%token  COMMITTED_SYM                 /* SQL-2003-N */
459
%token  COMMIT_SYM                    /* SQL-2003-R */
460
%token  COMPACT_SYM
461
%token  COMPRESSED_SYM
462
%token  CONCURRENT
463
%token  CONDITION_SYM                 /* SQL-2003-N */
464
%token  CONNECTION_SYM
465
%token  CONSISTENT_SYM
466
%token  CONSTRAINT                    /* SQL-2003-R */
467
%token  CONTAINS_SYM                  /* SQL-2003-N */
468
%token  CONTINUE_SYM                  /* SQL-2003-R */
469
%token  CONVERT_SYM                   /* SQL-2003-N */
470
%token  COUNT_SYM                     /* SQL-2003-N */
471
%token  CREATE                        /* SQL-2003-R */
472
%token  CROSS                         /* SQL-2003-R */
473
%token  CUBE_SYM                      /* SQL-2003-R */
474
%token  CURDATE                       /* MYSQL-FUNC */
475
%token  CURRENT_USER                  /* SQL-2003-R */
476
%token  CURSOR_SYM                    /* SQL-2003-R */
477
%token  DATABASE
478
%token  DATABASES
479
%token  DATAFILE_SYM
480
%token  DATA_SYM                      /* SQL-2003-N */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
481
%token  DATETIME_SYM
1 by brian
clean slate
482
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
483
%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
484
%token  DATE_SYM                      /* SQL-2003-R */
485
%token  DAY_HOUR_SYM
486
%token  DAY_MICROSECOND_SYM
487
%token  DAY_MINUTE_SYM
488
%token  DAY_SECOND_SYM
489
%token  DAY_SYM                       /* SQL-2003-R */
490
%token  DEALLOCATE_SYM                /* SQL-2003-R */
491
%token  DECIMAL_NUM
492
%token  DECIMAL_SYM                   /* SQL-2003-R */
493
%token  DECLARE_SYM                   /* SQL-2003-R */
494
%token  DEFAULT                       /* SQL-2003-R */
495
%token  DELETE_SYM                    /* SQL-2003-R */
496
%token  DESC                          /* SQL-2003-N */
497
%token  DESCRIBE                      /* SQL-2003-R */
498
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
499
%token  DISABLE_SYM
500
%token  DISCARD
501
%token  DISTINCT                      /* SQL-2003-R */
502
%token  DIV_SYM
503
%token  DOUBLE_SYM                    /* SQL-2003-R */
504
%token  DROP                          /* SQL-2003-R */
505
%token  DUMPFILE
506
%token  DUPLICATE_SYM
507
%token  DYNAMIC_SYM                   /* SQL-2003-R */
508
%token  EACH_SYM                      /* SQL-2003-R */
509
%token  ELSE                          /* SQL-2003-R */
510
%token  ELSEIF_SYM
511
%token  ENABLE_SYM
512
%token  ENCLOSED
513
%token  END                           /* SQL-2003-R */
514
%token  ENDS_SYM
515
%token  END_OF_INPUT                  /* INTERNAL */
516
%token  ENGINE_SYM
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
517
%token  ENUM_SYM
1 by brian
clean slate
518
%token  EQ                            /* OPERATOR */
519
%token  EQUAL_SYM                     /* OPERATOR */
520
%token  ERRORS
521
%token  ESCAPED
522
%token  ESCAPE_SYM                    /* SQL-2003-R */
523
%token  EXCLUSIVE_SYM
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
524
%token  EXECUTE_SYM
1 by brian
clean slate
525
%token  EXISTS                        /* SQL-2003-R */
526
%token  EXTENDED_SYM
527
%token  EXTRACT_SYM                   /* SQL-2003-N */
528
%token  FALSE_SYM                     /* SQL-2003-R */
529
%token  FETCH_SYM                     /* SQL-2003-R */
530
%token  COLUMN_FORMAT_SYM
531
%token  FILE_SYM
532
%token  FIRST_SYM                     /* SQL-2003-N */
533
%token  FIXED_SYM
534
%token  FLOAT_NUM
535
%token  FLUSH_SYM
536
%token  FORCE_SYM
537
%token  FOREIGN                       /* SQL-2003-R */
538
%token  FOR_SYM                       /* SQL-2003-R */
539
%token  FOUND_SYM                     /* SQL-2003-R */
540
%token  FRAC_SECOND_SYM
541
%token  FROM
542
%token  FULL                          /* SQL-2003-R */
543
%token  GE
544
%token  GLOBAL_SYM                    /* SQL-2003-R */
545
%token  GROUP_SYM                     /* SQL-2003-R */
546
%token  GROUP_CONCAT_SYM
547
%token  GT_SYM                        /* OPERATOR */
548
%token  HASH_SYM
549
%token  HAVING                        /* SQL-2003-R */
550
%token  HEX_NUM
551
%token  HOUR_MICROSECOND_SYM
552
%token  HOUR_MINUTE_SYM
553
%token  HOUR_SECOND_SYM
554
%token  HOUR_SYM                      /* SQL-2003-R */
555
%token  IDENT
556
%token  IDENTIFIED_SYM
557
%token  IDENT_QUOTED
558
%token  IF
559
%token  IGNORE_SYM
560
%token  IMPORT
561
%token  INDEXES
562
%token  INDEX_SYM
563
%token  INFILE
564
%token  INNER_SYM                     /* SQL-2003-R */
565
%token  INOUT_SYM                     /* SQL-2003-R */
566
%token  INSENSITIVE_SYM               /* SQL-2003-R */
567
%token  INSERT                        /* SQL-2003-R */
568
%token  INTERVAL_SYM                  /* SQL-2003-R */
569
%token  INTO                          /* SQL-2003-R */
570
%token  INT_SYM                       /* SQL-2003-R */
571
%token  IN_SYM                        /* SQL-2003-R */
572
%token  IS                            /* SQL-2003-R */
573
%token  ISOLATION                     /* SQL-2003-R */
574
%token  ITERATE_SYM
575
%token  JOIN_SYM                      /* SQL-2003-R */
576
%token  KEYS
577
%token  KEY_BLOCK_SIZE
578
%token  KEY_SYM                       /* SQL-2003-N */
579
%token  KILL_SYM
580
%token  LAST_SYM                      /* SQL-2003-N */
581
%token  LE                            /* OPERATOR */
582
%token  LEADING                       /* SQL-2003-R */
583
%token  LEFT                          /* SQL-2003-R */
584
%token  LEVEL_SYM
585
%token  LEX_HOSTNAME
586
%token  LIKE                          /* SQL-2003-R */
587
%token  LIMIT
588
%token  LINES
589
%token  LIST_SYM
590
%token  LOAD
591
%token  LOCAL_SYM                     /* SQL-2003-R */
592
%token  LOCATOR_SYM                   /* SQL-2003-N */
593
%token  LOCKS_SYM
594
%token  LOCK_SYM
595
%token  LOGS_SYM
596
%token  LONG_NUM
597
%token  LONG_SYM
598
%token  LOOP_SYM
599
%token  LT                            /* OPERATOR */
600
%token  MATCH                         /* SQL-2003-R */
601
%token  MAX_ROWS
602
%token  MAX_SIZE_SYM
603
%token  MAX_SYM                       /* SQL-2003-N */
604
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
605
%token  MEDIUM_SYM
606
%token  MERGE_SYM                     /* SQL-2003-R */
607
%token  MICROSECOND_SYM               /* MYSQL-FUNC */
608
%token  MINUTE_MICROSECOND_SYM
609
%token  MINUTE_SECOND_SYM
610
%token  MINUTE_SYM                    /* SQL-2003-R */
611
%token  MIN_ROWS
612
%token  MIN_SYM                       /* SQL-2003-N */
613
%token  MODE_SYM
614
%token  MODIFIES_SYM                  /* SQL-2003-R */
615
%token  MODIFY_SYM
616
%token  MOD_SYM                       /* SQL-2003-N */
617
%token  MONTH_SYM                     /* SQL-2003-R */
618
%token  NAMES_SYM                     /* SQL-2003-N */
619
%token  NAME_SYM                      /* SQL-2003-N */
620
%token  NATIONAL_SYM                  /* SQL-2003-R */
621
%token  NATURAL                       /* SQL-2003-R */
622
%token  NE                            /* OPERATOR */
623
%token  NEG
624
%token  NEW_SYM                       /* SQL-2003-R */
625
%token  NEXT_SYM                      /* SQL-2003-N */
626
%token  NONE_SYM                      /* SQL-2003-R */
627
%token  NOT_SYM                       /* SQL-2003-R */
628
%token  NOW_SYM
629
%token  NO_SYM                        /* SQL-2003-R */
630
%token  NULL_SYM                      /* SQL-2003-R */
631
%token  NUM
632
%token  NUMERIC_SYM                   /* SQL-2003-R */
633
%token  OFFLINE_SYM
634
%token  OFFSET_SYM
635
%token  ON                            /* SQL-2003-R */
636
%token  ONE_SHOT_SYM
637
%token  ONE_SYM
638
%token  ONLINE_SYM
639
%token  OPEN_SYM                      /* SQL-2003-R */
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
640
%token  OPTIMIZE                      /* Leave assuming we might add it back */
1 by brian
clean slate
641
%token  OPTION                        /* SQL-2003-N */
642
%token  OPTIONALLY
643
%token  ORDER_SYM                     /* SQL-2003-R */
644
%token  OR_SYM                        /* SQL-2003-R */
645
%token  OUTER
646
%token  OUTFILE
647
%token  OUT_SYM                       /* SQL-2003-R */
648
%token  PAGE_SYM
649
%token  PARTIAL                       /* SQL-2003-N */
650
%token  PHASE_SYM
651
%token  POSITION_SYM                  /* SQL-2003-N */
652
%token  PRECISION                     /* SQL-2003-R */
653
%token  PREV_SYM
654
%token  PRIMARY_SYM                   /* SQL-2003-R */
655
%token  PROCESS
656
%token  PROCESSLIST_SYM
657
%token  QUARTER_SYM
658
%token  QUERY_SYM
659
%token  RANGE_SYM                     /* SQL-2003-R */
660
%token  READS_SYM                     /* SQL-2003-R */
661
%token  READ_ONLY_SYM
662
%token  READ_SYM                      /* SQL-2003-N */
663
%token  READ_WRITE_SYM
664
%token  REAL                          /* SQL-2003-R */
665
%token  REDUNDANT_SYM
666
%token  REFERENCES                    /* SQL-2003-R */
667
%token  RELEASE_SYM                   /* SQL-2003-R */
668
%token  RENAME
669
%token  REPEATABLE_SYM                /* SQL-2003-N */
670
%token  REPEAT_SYM                    /* MYSQL-FUNC */
671
%token  REPLACE                       /* MYSQL-FUNC */
672
%token  RESTRICT
673
%token  RETURNS_SYM                   /* SQL-2003-R */
674
%token  RETURN_SYM                    /* SQL-2003-R */
675
%token  REVERSE_SYM
676
%token  REVOKE                        /* SQL-2003-R */
677
%token  RIGHT                         /* SQL-2003-R */
678
%token  ROLLBACK_SYM                  /* SQL-2003-R */
679
%token  ROLLUP_SYM                    /* SQL-2003-R */
680
%token  ROUTINE_SYM                   /* SQL-2003-N */
681
%token  ROWS_SYM                      /* SQL-2003-R */
682
%token  ROW_FORMAT_SYM
683
%token  ROW_SYM                       /* SQL-2003-R */
684
%token  SAVEPOINT_SYM                 /* SQL-2003-R */
685
%token  SECOND_MICROSECOND_SYM
686
%token  SECOND_SYM                    /* SQL-2003-R */
687
%token  SECURITY_SYM                  /* SQL-2003-N */
688
%token  SELECT_SYM                    /* SQL-2003-R */
689
%token  SENSITIVE_SYM                 /* FUTURE-USE */
690
%token  SEPARATOR_SYM
691
%token  SERIALIZABLE_SYM              /* SQL-2003-N */
692
%token  SERIAL_SYM
693
%token  SESSION_SYM                   /* SQL-2003-N */
694
%token  SERVER_SYM
695
%token  SERVER_OPTIONS
696
%token  SET                           /* SQL-2003-R */
697
%token  SET_VAR
698
%token  SHARE_SYM
699
%token  SHOW
700
%token  SIMPLE_SYM                    /* SQL-2003-N */
701
%token  SNAPSHOT_SYM
702
%token  SPECIFIC_SYM                  /* SQL-2003-R */
703
%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
704
%token  SQLSTATE_SYM                  /* SQL-2003-R */
705
%token  SQLWARNING_SYM                /* SQL-2003-R */
706
%token  SQL_BIG_RESULT
707
%token  SQL_BUFFER_RESULT
708
%token  SQL_CALC_FOUND_ROWS
709
%token  SQL_SMALL_RESULT
710
%token  SQL_SYM                       /* SQL-2003-R */
711
%token  STARTING
712
%token  START_SYM                     /* SQL-2003-R */
713
%token  STATUS_SYM
714
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
715
%token  STD_SYM
716
%token  STOP_SYM
717
%token  STORAGE_SYM
383.7.1 by Andrey Zhakov
Initial submit of code and tests
718
%token  STORED_SYM
1 by brian
clean slate
719
%token  STRAIGHT_JOIN
720
%token  STRING_SYM
721
%token  SUBDATE_SYM
722
%token  SUBJECT_SYM
723
%token  SUBSTRING                     /* SQL-2003-N */
724
%token  SUM_SYM                       /* SQL-2003-N */
725
%token  SUSPEND_SYM
726
%token  SWAPS_SYM
727
%token  SWITCHES_SYM
728
%token  SYSDATE
729
%token  TABLES
108 by Brian Aker
Removed unwanted ALTER TABLESPACE, left in valuable bits.
730
%token  TABLESPACE
1 by brian
clean slate
731
%token  TABLE_REF_PRIORITY
732
%token  TABLE_SYM                     /* SQL-2003-R */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
733
%token  TEMPORARY_SYM                 /* SQL-2003-N */
1 by brian
clean slate
734
%token  TERMINATED
735
%token  TEXT_STRING
736
%token  TEXT_SYM
737
%token  THEN_SYM                      /* SQL-2003-R */
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
738
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
1 by brian
clean slate
739
%token  TIMESTAMP_ADD
740
%token  TIMESTAMP_DIFF
741
%token  TO_SYM                        /* SQL-2003-R */
742
%token  TRAILING                      /* SQL-2003-R */
743
%token  TRANSACTION_SYM
744
%token  TRIM                          /* SQL-2003-N */
745
%token  TRUE_SYM                      /* SQL-2003-R */
746
%token  TRUNCATE_SYM
747
%token  TYPES_SYM
748
%token  TYPE_SYM                      /* SQL-2003-N */
749
%token  ULONGLONG_NUM
750
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
751
%token  UNDOFILE_SYM
752
%token  UNDO_SYM                      /* FUTURE-USE */
753
%token  UNION_SYM                     /* SQL-2003-R */
754
%token  UNIQUE_SYM
755
%token  UNKNOWN_SYM                   /* SQL-2003-R */
756
%token  UNLOCK_SYM
757
%token  UPDATE_SYM                    /* SQL-2003-R */
758
%token  USAGE                         /* SQL-2003-N */
759
%token  USER                          /* SQL-2003-R */
760
%token  USE_SYM
761
%token  USING                         /* SQL-2003-R */
762
%token  UTC_DATE_SYM
763
%token  UTC_TIMESTAMP_SYM
764
%token  VALUES                        /* SQL-2003-R */
765
%token  VALUE_SYM                     /* SQL-2003-R */
766
%token  VARBINARY
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
767
%token  VARCHAR_SYM                   /* SQL-2003-R */
1 by brian
clean slate
768
%token  VARIABLES
769
%token  VARIANCE_SYM
770
%token  VARYING                       /* SQL-2003-R */
771
%token  VAR_SAMP_SYM
772
%token  WARNINGS
773
%token  WEEK_SYM
774
%token  WHEN_SYM                      /* SQL-2003-R */
775
%token  WHERE                         /* SQL-2003-R */
776
%token  WITH                          /* SQL-2003-R */
777
%token  WITH_ROLLUP_SYM               /* INTERNAL */
778
%token  WORK_SYM                      /* SQL-2003-N */
779
%token  WRITE_SYM                     /* SQL-2003-N */
780
%token  XOR
781
%token  YEAR_MONTH_SYM
782
%token  YEAR_SYM                      /* SQL-2003-R */
783
784
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
785
/* A dummy token to force the priority of table_ref production in a join. */
786
%left   TABLE_REF_PRIORITY
787
%left   SET_VAR
788
%left   OR_SYM
789
%left   XOR
256 by Brian Aker
Remove BIT operations, replace with functions.
790
%left   AND_SYM
1 by brian
clean slate
791
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
792
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
793
%left   '-' '+'
794
%left   '*' '/' '%' DIV_SYM MOD_SYM
256 by Brian Aker
Remove BIT operations, replace with functions.
795
%left   NEG
1 by brian
clean slate
796
%right  NOT_SYM
797
%right  BINARY COLLATE_SYM
798
%left  INTERVAL_SYM
799
800
%type <lex_str>
801
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
802
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
803
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
1106.4.1 by Brian Aker
Remove user level key_cache
804
        opt_component
1 by brian
clean slate
805
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
806
        execute_var_or_string
1 by brian
clean slate
807
        opt_constraint constraint opt_ident
808
809
%type <lex_str_ptr>
810
        opt_table_alias
811
812
%type <table>
813
        table_ident references
814
815
%type <simple_string>
816
        remember_name remember_end opt_db
817
818
%type <string>
819
        text_string opt_gconcat_separator
820
821
%type <num>
383.7.1 by Andrey Zhakov
Initial submit of code and tests
822
        type int_type real_type order_dir field_def
1222.2.2 by Brian Aker
Remove last ofl HA_CREATE_INFO being involved with temporary tables (always
823
        if_exists opt_table_options
824
        opt_if_not_exists
1 by brian
clean slate
825
        opt_temporary all_or_any opt_distinct
59 by Brian Aker
Removed preload from parser.
826
        union_option
1 by brian
clean slate
827
        start_transaction_opts opt_chain opt_release
828
        union_opt select_derived_init option_type2
829
830
%type <m_fk_option>
831
        delete_option
832
833
%type <ulong_num>
1296 by Brian Aker
Remove WEIGHT_STRING() from parser (where it does not belong). If someone
834
        ulong_num
1 by brian
clean slate
835
836
%type <ulonglong_number>
837
        ulonglong_num
838
839
%type <lock_type>
1008.1.5 by Brian Aker
Remove LOW_PRIORITY call.
840
        load_data_lock
1 by brian
clean slate
841
842
%type <item>
843
        literal text_literal insert_ident order_ident
844
        simple_ident expr opt_expr opt_else sum_expr in_sum_expr
845
        variable variable_aux bool_pri
846
        predicate bit_expr
847
        table_wild simple_expr udf_expr
848
        expr_or_default set_expr_or_default
849
        signed_literal now_or_signed_literal opt_escape
850
        simple_ident_nospvar simple_ident_q
851
        field_or_var limit_option
852
        function_call_keyword
853
        function_call_nonkeyword
854
        function_call_generic
855
        function_call_conflict
856
857
%type <item_num>
858
        NUM_literal
859
860
%type <item_list>
861
        expr_list opt_udf_expr_list udf_expr_list when_list
862
863
%type <var_type>
864
        option_type opt_var_type opt_var_ident_type
865
866
%type <key_type>
867
        key_type opt_unique constraint_key_type
868
869
%type <key_alg>
870
        btree_or_rtree
871
872
%type <string_list>
873
        using_list
874
875
%type <key_part>
876
        key_part
877
878
%type <table_list>
879
        join_table_list  join_table
880
        table_factor table_ref esc_table_ref
881
        select_derived derived_table_list
882
        select_derived_union
883
884
%type <interval> interval
885
886
%type <interval_time_st> interval_time_st
887
888
%type <interval_time_st> interval_time_stamp
889
890
%type <column_format_type> column_format_types
891
892
%type <tx_isolation> isolation_types
893
894
%type <cast_type> cast_type
895
896
%type <symbol> keyword keyword_sp
897
898
%type <charset>
899
        collation_name
900
        collation_name_or_default
901
902
%type <variable> internal_variable_name
903
904
%type <select_lex> subselect
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
905
        get_select_lex query_specification
1 by brian
clean slate
906
        query_expression_body
907
908
%type <boolfunc2creator> comp_op
909
910
%type <build_method> build_method
911
912
%type <NONE>
798.2.4 by Brian Aker
Removed CHANGE
913
        query verb_clause create select drop insert replace insert2
1 by brian
clean slate
914
        insert_values update delete truncate rename
1222.1.14 by Brian Aker
Remove OPTIMIZE, place in ALTER TABLE (which does the same thing).
915
        show describe load alter flush
798.2.2 by Brian Aker
Removed purge
916
        begin commit rollback savepoint release
1455.1.1 by Stewart Smith
remove CHECKSUM TABLE
917
        analyze check start
1 by brian
clean slate
918
        field_list field_list_item field_spec kill column_def key_def
919
        select_item_list select_item values_list no_braces
920
        opt_limit_clause delete_limit_clause fields opt_values values
184 by Brian Aker
Dead debug code removal (and a compatible "never used") bit in the
921
        opt_precision opt_ignore opt_column
1054.1.1 by Brian Aker
Remove guts in parser for LOCK TABLE.
922
        set unlock string_list
1 by brian
clean slate
923
        ref_list opt_match_clause opt_on_update_delete use
234 by Brian Aker
More National gone.
924
        opt_delete_options opt_delete_option varchar
1108.1.1 by Brian Aker
Remove multi-update from parser/tests.
925
        opt_outer table_list table_name
1 by brian
clean slate
926
        opt_option opt_place
927
        opt_attribute opt_attribute_list attribute
928
        flush_options flush_option
929
        equal optional_braces
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
930
        normal_join
1 by brian
clean slate
931
        table_to_table_list table_to_table opt_table_list opt_as
1108.1.1 by Brian Aker
Remove multi-update from parser/tests.
932
        single_multi
1 by brian
clean slate
933
        union_clause union_list
520.1.1 by Brian Aker
Removed dead variables/dead parser piece.
934
        precision subselect_start
1 by brian
clean slate
935
        subselect_end select_var_list select_var_list_init opt_len
936
        opt_extended_describe
937
        statement
938
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
939
        init_key_options key_options key_opts key_opt key_using_alg
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
940
        execute
1 by brian
clean slate
941
END_OF_INPUT
942
943
%type <index_hint> index_hint_type
944
%type <num> index_hint_clause
266.1.23 by Monty Taylor
Removed load xml infile. Hope nobody liked it. Now the only thing we need xml.c
945
%type <filetype> data_file
1 by brian
clean slate
946
947
%type <NONE>
948
        '-' '+' '*' '/' '%' '(' ')'
256 by Brian Aker
Remove BIT operations, replace with functions.
949
        ',' '!' '{' '}' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
950
        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM DELETE_SYM
1 by brian
clean slate
951
%%
952
953
/*
954
  Indentation of grammar rules:
955
956
rule: <-- starts at col 1
957
          rule1a rule1b rule1c <-- starts at col 11
958
          { <-- starts at col 11
959
            code <-- starts at col 13, indentation is 2 spaces
960
          }
961
        | rule2a rule2b
962
          {
963
            code
964
          }
965
        ; <-- on a line by itself, starts at col 9
966
967
  Also, please do not use any <TAB>, but spaces.
968
  Having a uniform indentation in this file helps
969
  code reviews, patches, merges, and make maintenance easier.
970
  Tip: grep [[:cntrl:]] sql_yacc.yy
971
  Thanks.
972
*/
973
974
query:
975
          END_OF_INPUT
976
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
977
            Session *session= YYSession;
978
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
1 by brian
clean slate
979
            {
980
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
981
              DRIZZLE_YYABORT;
1 by brian
clean slate
982
            }
983
            else
984
            {
520.1.22 by Brian Aker
Second pass of thd cleanup
985
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
1222.1.14 by Brian Aker
Remove OPTIMIZE, place in ALTER TABLE (which does the same thing).
986
              session->lex->statement=
1100.3.28 by Padraig O'Sullivan
Renamed the command namespace where I was declaring all of these commands to
987
                new(std::nothrow) statement::EmptyQuery(YYSession);
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
988
              if (session->lex->statement == NULL)
1100.3.8 by Padraig O'Sullivan
Extracting the empty query case label from the switch statement in
989
                DRIZZLE_YYABORT;
1 by brian
clean slate
990
            }
991
          }
992
        | verb_clause END_OF_INPUT {}
993
        ;
994
995
verb_clause:
996
          statement
997
        | begin
998
        ;
999
1000
/* Verb clauses, except begin */
1001
statement:
1002
          alter
1003
        | analyze
1004
        | check
1005
        | commit
1006
        | create
1007
        | delete
1008
        | describe
1009
        | drop
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
1010
        | execute
1 by brian
clean slate
1011
        | flush
1012
        | insert
1013
        | kill
1014
        | load
1015
        | release
1016
        | rename
1017
        | replace
1018
        | rollback
1019
        | savepoint
1020
        | select
1021
        | set
1022
        | show
1023
        | start
1024
        | truncate
1025
        | unlock
1026
        | update
1027
        | use
1028
        ;
1029
1030
/* create a table */
1031
1032
create:
1033
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1034
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
1035
            Session *session= YYSession;
1036
            LEX *lex= session->lex;
1 by brian
clean slate
1037
            lex->sql_command= SQLCOM_CREATE_TABLE;
1128.2.2 by Brian Aker
Refactor to remove Proto from global.
1038
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1039
            lex->statement= statement;
1100.3.65 by Padraig O'Sullivan
Extracted the CREATE TABLE command into its own class and implementation
1040
            if (lex->statement == NULL)
1041
              DRIZZLE_YYABORT;
520.1.22 by Brian Aker
Second pass of thd cleanup
1042
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1 by brian
clean slate
1043
                                                   TL_OPTION_UPDATING,
1044
                                                   TL_WRITE))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1045
              DRIZZLE_YYABORT;
1 by brian
clean slate
1046
            lex->col_list.empty();
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1047
            statement->change=NULL;
1222.2.3 by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO.
1048
            statement->is_if_not_exists= $4;
1160.1.5 by Brian Aker
Final parser SE removal.
1049
            statement->create_info.db_type= NULL;
1128.2.3 by Brian Aker
Remove create_info from global
1050
            statement->create_info.default_table_charset= NULL;
1 by brian
clean slate
1051
            lex->name.str= 0;
1008.3.21 by Stewart Smith
add table type to table proto generated in parser
1052
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
1053
	    message::Table &proto= statement->create_table_message;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1054
	   
1273.19.9 by Brian Aker
Minor style fix.
1055
	    proto.set_name($5->table.str);
1395.1.9 by Brian Aker
Small cleanup around how we do types internally.
1056
	    if ($2)
1273.19.9 by Brian Aker
Minor style fix.
1057
	      proto.set_type(message::Table::TEMPORARY);
1008.3.21 by Stewart Smith
add table type to table proto generated in parser
1058
	    else
1273.19.9 by Brian Aker
Minor style fix.
1059
	      proto.set_type(message::Table::STANDARD);
1 by brian
clean slate
1060
          }
1061
          create2
1062
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
1063
            LEX *lex= YYSession->lex;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1064
            lex->current_select= &lex->select_lex;
1 by brian
clean slate
1065
          }
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
1066
        | CREATE build_method
1 by brian
clean slate
1067
          {
1068
            LEX *lex=Lex;
1069
            lex->sql_command= SQLCOM_CREATE_INDEX;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1070
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1071
            lex->statement= statement;
1100.3.56 by Padraig O'Sullivan
Extracted the CREATE INDEX and DROP INDEX command into an individual class
1072
            if (lex->statement == NULL)
1073
              DRIZZLE_YYABORT;
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
1074
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1075
            statement->alter_info.build_method= $2;
1076
            lex->col_list.empty();
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1077
            statement->change=NULL;
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
1078
          }
1079
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
1080
          {
1081
            LEX *lex=Lex;
1082
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1083
1084
            if (!lex->current_select->add_table_to_list(lex->session, $9,
1 by brian
clean slate
1085
                                                        NULL,
1086
                                                        TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1087
              DRIZZLE_YYABORT;
1 by brian
clean slate
1088
            Key *key;
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
1089
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1090
            statement->alter_info.key_list.push_back(key);
1 by brian
clean slate
1091
            lex->col_list.empty();
1092
          }
1093
        | CREATE DATABASE opt_if_not_exists ident
1094
          {
1128.2.3 by Brian Aker
Remove create_info from global
1095
            LEX *lex=Lex;
1096
1097
            lex->sql_command=SQLCOM_CREATE_DB;
1098
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1099
            lex->statement= statement;
1100
            if (lex->statement == NULL)
1101
              DRIZZLE_YYABORT;
1222.2.3 by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO.
1102
            statement->is_if_not_exists= $3;
1 by brian
clean slate
1103
          }
1104
          opt_create_database_options
1105
          {
1128.2.3 by Brian Aker
Remove create_info from global
1106
            Lex->name= $4;
1 by brian
clean slate
1107
          }
1108
        ;
1109
1110
create2:
1111
          '(' create2a {}
1112
        | opt_create_table_options
1113
          create3 {}
1172.1.1 by Brian Aker
Add in support for ENGINE= in create table like.
1114
        | LIKE table_ident opt_create_table_options
1 by brian
clean slate
1115
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
1116
            Session *session= YYSession;
1117
            LEX *lex= session->lex;
1128.2.3 by Brian Aker
Remove create_info from global
1118
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1 by brian
clean slate
1119
1222.2.3 by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO.
1120
            statement->is_create_table_like= true;
520.1.22 by Brian Aker
Second pass of thd cleanup
1121
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1122
              DRIZZLE_YYABORT;
1 by brian
clean slate
1123
          }
1124
        | '(' LIKE table_ident ')'
1125
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
1126
            Session *session= YYSession;
1127
            LEX *lex= session->lex;
1128.2.3 by Brian Aker
Remove create_info from global
1128
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1 by brian
clean slate
1129
1222.2.3 by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO.
1130
            statement->is_create_table_like= true;
520.1.22 by Brian Aker
Second pass of thd cleanup
1131
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1132
              DRIZZLE_YYABORT;
1 by brian
clean slate
1133
          }
1134
        ;
1135
1136
create2a:
1137
          field_list ')' opt_create_table_options
1138
          create3 {}
1139
        |  create_select ')'
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
1140
           { Lex->current_select->set_braces(1);}
1 by brian
clean slate
1141
           union_opt {}
1142
        ;
1143
1144
create3:
1145
          /* empty */ {}
1146
        | opt_duplicate opt_as create_select
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
1147
          { Lex->current_select->set_braces(0);}
1 by brian
clean slate
1148
          union_clause {}
1149
        | opt_duplicate opt_as '(' create_select ')'
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
1150
          { Lex->current_select->set_braces(1);}
1 by brian
clean slate
1151
          union_opt {}
1152
        ;
1153
1154
create_select:
1155
          SELECT_SYM
1156
          {
1157
            LEX *lex=Lex;
604 by Brian Aker
Remove lock condition needed (we do row based replication, so... lock is
1158
            lex->lock_option= TL_READ;
1 by brian
clean slate
1159
            if (lex->sql_command == SQLCOM_INSERT)
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
1160
            {
1 by brian
clean slate
1161
              lex->sql_command= SQLCOM_INSERT_SELECT;
1149.1.3 by Stewart Smith
whitespace fixes... damn lack of good yacc emacs mode
1162
              delete lex->statement;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1163
              lex->statement=
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
1164
                new(std::nothrow) statement::InsertSelect(YYSession);
1165
              if (lex->statement == NULL)
1166
                DRIZZLE_YYABORT;
1167
            }
1 by brian
clean slate
1168
            else if (lex->sql_command == SQLCOM_REPLACE)
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
1169
            {
1 by brian
clean slate
1170
              lex->sql_command= SQLCOM_REPLACE_SELECT;
1149.1.3 by Stewart Smith
whitespace fixes... damn lack of good yacc emacs mode
1171
              delete lex->statement;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1172
              lex->statement=
1100.3.66 by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch
1173
                new(std::nothrow) statement::ReplaceSelect(YYSession);
1174
              if (lex->statement == NULL)
1175
                DRIZZLE_YYABORT;
1176
            }
1 by brian
clean slate
1177
            /*
1178
              The following work only with the local list, the global list
1179
              is created correctly in this case
1180
            */
1181
            lex->current_select->table_list.save_and_clear(&lex->save_list);
1182
            mysql_init_select(lex);
1183
            lex->current_select->parsing_place= SELECT_LIST;
1184
          }
1185
          select_options select_item_list
1186
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
1187
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
1188
          }
1189
          opt_select_from
1190
          {
1191
            /*
1192
              The following work only with the local list, the global list
1193
              is created correctly in this case
1194
            */
1195
            Lex->current_select->table_list.push_front(&Lex->save_list);
1196
          }
1197
        ;
1198
1199
opt_as:
1200
          /* empty */ {}
1201
        | AS {}
1202
        ;
1203
1204
opt_create_database_options:
1205
          /* empty */ {}
1128.2.7 by Brian Aker
Cleanup previous issues in create sql_yacc
1206
        | default_collation_schema {}
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
1207
        | opt_database_custom_options {}
1208
        ;
1209
1210
opt_database_custom_options:
1211
        custom_database_option
1212
        | custom_database_option ',' opt_database_custom_options
1213
        ;
1214
1215
custom_database_option:
1216
          ident_or_text
1217
        {
1218
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1502.1.31 by Brian Aker
Merge engine options for schema/table.
1219
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1220
1221
          opt->set_name($1.str);
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
1222
        }
1223
        | ident_or_text equal ident_or_text
1224
        {
1225
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1502.1.31 by Brian Aker
Merge engine options for schema/table.
1226
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1227
1228
          opt->set_name($1.str);
1229
          opt->set_state($3.str);
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
1230
        }
1231
        | ident_or_text equal ulonglong_num
1232
        {
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1233
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
1234
          char number_as_string[22];
1235
1236
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
1237
1502.1.31 by Brian Aker
Merge engine options for schema/table.
1238
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1239
1240
          opt->set_name($1.str);
1241
          opt->set_state(number_as_string);
1241.17.1 by Stewart Smith
simple key,value options for CREATE DATABASE. All options are currently unknown.
1242
        }
1 by brian
clean slate
1243
        ;
1244
1245
opt_table_options:
1222.2.2 by Brian Aker
Remove last ofl HA_CREATE_INFO being involved with temporary tables (always
1246
          /* empty */ { $$= false; }
1247
        | TEMPORARY_SYM { $$= true; }
1 by brian
clean slate
1248
        ;
1249
1250
opt_if_not_exists:
1222.2.3 by Brian Aker
Remove a few more options, from options in HA_CREATE_INFO.
1251
          /* empty */ { $$= false; }
1252
        | IF not EXISTS { $$= true; }
1 by brian
clean slate
1253
        ;
1254
1255
opt_create_table_options:
1256
          /* empty */
1257
        | create_table_options
1258
        ;
1259
1260
create_table_options_space_separated:
1261
          create_table_option
1262
        | create_table_option create_table_options_space_separated
1263
        ;
1264
1265
create_table_options:
1266
          create_table_option
1267
        | create_table_option     create_table_options
1268
        | create_table_option ',' create_table_options
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1269
1 by brian
clean slate
1270
create_table_option:
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1271
          custom_engine_option;
1 by brian
clean slate
1272
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1273
custom_engine_option:
1245.3.4 by Stewart Smith
make the equals of KEY=VALUE required for CREATE TABLE options
1274
        ENGINE_SYM equal ident_or_text
1 by brian
clean slate
1275
          {
1128.2.3 by Brian Aker
Remove create_info from global
1276
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1222.1.3 by Brian Aker
Remove used flag for engine.
1277
1278
            statement->is_engine_set= true;
1279
1502.1.31 by Brian Aker
Merge engine options for schema/table.
1280
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1 by brian
clean slate
1281
          }
1282
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1283
          {
1118.2.1 by Stewart Smith
fix drizzled::message::Table usage so that in kernel .cc files we are 'using namespace drizzled'
1284
	    message::Table::TableOptions *tableopts;
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
1285
	    tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
1286
1287
	    tableopts->set_comment($3.str);
1 by brian
clean slate
1288
          }
1289
        | AUTO_INC opt_equal ulonglong_num
1290
          {
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
1291
	    message::Table::TableOptions *tableopts;
1128.2.3 by Brian Aker
Remove create_info from global
1292
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1293
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
1294
	    tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
1295
1128.2.3 by Brian Aker
Remove create_info from global
1296
            statement->create_info.auto_increment_value=$3;
1297
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1222.1.5 by Brian Aker
Remove dependency in engines for auto_increment primer to be passed in by
1298
	    tableopts->set_auto_increment_value($3);
1 by brian
clean slate
1299
          }
1245.3.3 by Stewart Smith
convert builtin table options to use key,value code in parser
1300
        |  ident_or_text equal ident_or_text
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1301
          {
1502.1.31 by Brian Aker
Merge engine options for schema/table.
1302
	    drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1303
1304
            opt->set_name($1.str);
1305
            opt->set_state($3.str);
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1306
          }
1307
        | ident_or_text equal ulonglong_num
1308
          {
1309
            char number_as_string[22];
1310
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
1311
1502.1.31 by Brian Aker
Merge engine options for schema/table.
1312
	    drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
1313
            opt->set_name($1.str);
1314
            opt->set_state(number_as_string);
1 by brian
clean slate
1315
          }
1316
        | default_collation
1317
        ;
1318
1319
default_collation:
1320
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1321
          {
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1322
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1323
1128.2.3 by Brian Aker
Remove create_info from global
1324
            HA_CREATE_INFO *cinfo= &statement->create_info;
1 by brian
clean slate
1325
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1326
                 cinfo->default_table_charset && $4 &&
1327
                 !my_charset_same(cinfo->default_table_charset,$4))
1328
              {
1329
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1330
                         $4->name, cinfo->default_table_charset->csname);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1331
                DRIZZLE_YYABORT;
1 by brian
clean slate
1332
              }
1128.2.3 by Brian Aker
Remove create_info from global
1333
              statement->create_info.default_table_charset= $4;
1334
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1245.3.2 by Stewart Smith
small addition of custom engine options in parser and statement/create_table. No error checking performed yet (although the list is constructed). We are parsing them in () after ENGINE=FOO in CREATE TABLE and not as first class options to CREATE TABLE (like ENGINE=) currently due to shift/reduce conflicts in parser if we do. We must first reimpliment the existing CREATE TABLE options as these options before we can have this.
1335
          }
1336
        ;
1337
1128.2.3 by Brian Aker
Remove create_info from global
1338
default_collation_schema:
1339
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1340
          {
1341
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1342
1235.4.14 by Stewart Smith
use message::Schema in mysql_create_db instead of HA_CREATE_INFO
1343
            message::Schema &schema_message= statement->schema_message;
1344
            schema_message.set_collation($4->name);
1128.2.3 by Brian Aker
Remove create_info from global
1345
          }
1346
        ;
1347
1 by brian
clean slate
1348
column_format_types:
1349
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
1350
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
1351
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
1352
1353
1354
opt_select_from:
1355
          opt_limit_clause {}
1356
        | select_from select_lock_type
1357
        ;
1358
1359
field_list:
1360
          field_list_item
1361
        | field_list ',' field_list_item
1362
        ;
1363
1364
field_list_item:
1365
          column_def
1366
        | key_def
1367
        ;
1368
1369
column_def:
1370
          field_spec opt_check_constraint
1371
        | field_spec references
1372
          {
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
1373
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1374
          }
1375
        ;
1376
1377
key_def:
1378
          key_type opt_ident key_alg '(' key_list ')' key_options
1379
          {
1380
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1381
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
1382
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1 by brian
clean slate
1383
                              lex->col_list);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1384
            statement->alter_info.key_list.push_back(key);
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
1385
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1386
          }
1387
        | opt_constraint constraint_key_type opt_ident key_alg
1388
          '(' key_list ')' key_options
1389
          {
1390
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1391
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
1392
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1 by brian
clean slate
1393
                              lex->col_list);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1394
            statement->alter_info.key_list.push_back(key);
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
1395
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1396
          }
1397
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1398
          {
1399
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1400
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1638.10.118 by Stewart Smith
fix naming of constraints to be more standards compliant and correct. the index_name part of it just doesn't exist in SQL-99
1401
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
1 by brian
clean slate
1402
                                      $8,
1403
                                      lex->ref_list,
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
1404
                                      statement->fk_delete_opt,
1405
                                      statement->fk_update_opt,
1406
                                      statement->fk_match_option);
1638.10.78 by Stewart Smith
separate out adding the foreign key to the table protobuf message from mysql_prepare_create_table and call a function to do it directly from the parser where we set up the foreign key structures
1407
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1408
            statement->alter_info.key_list.push_back(key);
1 by brian
clean slate
1409
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1410
                         &default_key_create_info, 1,
1411
                         lex->col_list);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1412
            statement->alter_info.key_list.push_back(key);
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
1413
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1414
            /* Only used for ALTER TABLE. Ignored otherwise. */
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1415
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1 by brian
clean slate
1416
          }
1417
        | constraint opt_check_constraint
1418
          {
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
1419
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1420
          }
1421
        | opt_constraint check_constraint
1422
          {
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
1423
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1 by brian
clean slate
1424
          }
1425
        ;
1426
1427
opt_check_constraint:
1428
          /* empty */
1429
        | check_constraint
1430
        ;
1431
1432
check_constraint:
1433
          CHECK_SYM expr
1434
        ;
1435
1436
opt_constraint:
1437
          /* empty */ { $$= null_lex_str; }
1438
        | constraint { $$= $1; }
1439
        ;
1440
1441
constraint:
1442
          CONSTRAINT opt_ident { $$=$2; }
1443
        ;
1444
1445
field_spec:
1446
          field_ident
1447
          {
1448
            LEX *lex=Lex;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1449
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1 by brian
clean slate
1450
            lex->length=lex->dec=0;
1451
            lex->type=0;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1452
            statement->default_value= statement->on_update_value= 0;
1453
            statement->comment= null_lex_str;
1 by brian
clean slate
1454
            lex->charset=NULL;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1455
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1215.1.1 by stewart at flamingspork
[patch 01/17] horrible hack to have one lonely codepath produce Fields in the table proto
1456
1457
            message::AlterTable &alter_proto=
1458
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1459
            statement->current_proto_field= alter_proto.add_added_field();
1 by brian
clean slate
1460
          }
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1461
          field_def
1 by brian
clean slate
1462
          {
1463
            LEX *lex=Lex;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1464
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1215.1.3 by stewart at flamingspork
[patch 03/17] set field name in parser, assert that its correct when filling out the rest of the table proto
1465
1466
            if (statement->current_proto_field)
1467
              statement->current_proto_field->set_name($1.str);
1468
520.1.22 by Brian Aker
Second pass of thd cleanup
1469
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1 by brian
clean slate
1470
                                  lex->length,lex->dec,lex->type,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1471
                                  statement->column_format,
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1472
                                  statement->default_value, statement->on_update_value,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1473
                                  &statement->comment,
1474
                                  statement->change, &lex->interval_list, lex->charset))
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1475
              DRIZZLE_YYABORT;
1215.1.1 by stewart at flamingspork
[patch 01/17] horrible hack to have one lonely codepath produce Fields in the table proto
1476
1477
            statement->current_proto_field= NULL;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
1478
          }
1479
        ;
1480
field_def:
1481
          type opt_attribute {}
1 by brian
clean slate
1482
        ;
1483
1484
type:
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1485
        int_type
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1486
        {
1487
          $$=$1;
223 by Brian Aker
Cleanup int() work.
1488
          Lex->length=(char*) 0; /* use default length */
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1489
          statement::CreateTable *statement=
1490
            (statement::CreateTable *)Lex->statement;
1491
1492
          if (statement->current_proto_field)
1493
          {
1494
            if ($1 == DRIZZLE_TYPE_LONG)
1495
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1496
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
1497
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1498
            else
1499
              abort();
1500
          }
1501
          }
1502
        | real_type opt_precision
1503
          {
1504
            $$=$1;
1505
1506
            statement::CreateTable *statement=
1507
              (statement::CreateTable *)Lex->statement;
1508
1509
            if (statement->current_proto_field)
1510
            {
1511
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
1512
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1513
            }
1514
          }
1220.1.11 by Brian Aker
Committing Stewart's work
1515
          | char '(' NUM ')'
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1516
            {
1517
              Lex->length=$3.str;
1518
              $$=DRIZZLE_TYPE_VARCHAR;
1519
1520
            statement::CreateTable *statement=
1521
              (statement::CreateTable *)Lex->statement;
1522
1523
            if (statement->current_proto_field)
1215.1.14 by stewart at flamingspork
[patch 14/17] add length of CHAR column to proto in parser
1524
            {
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1525
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1215.1.14 by stewart at flamingspork
[patch 14/17] add length of CHAR column to proto in parser
1526
              message::Table::Field::StringFieldOptions *string_field_options;
1527
1528
              string_field_options= statement->current_proto_field->mutable_string_options();
1529
1530
              string_field_options->set_length(atoi($3.str));
1531
            }
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1532
            }
1220.1.11 by Brian Aker
Committing Stewart's work
1533
          | char
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1534
            {
1535
              Lex->length=(char*) "1";
1536
              $$=DRIZZLE_TYPE_VARCHAR;
1537
1538
            statement::CreateTable *statement=
1539
              (statement::CreateTable *)Lex->statement;
1540
1541
            if (statement->current_proto_field)
1542
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1543
            }
1220.1.11 by Brian Aker
Committing Stewart's work
1544
          | varchar '(' NUM ')'
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1545
            {
1546
              Lex->length=$3.str;
1547
              $$= DRIZZLE_TYPE_VARCHAR;
1548
1549
            statement::CreateTable *statement=
1550
              (statement::CreateTable *)Lex->statement;
1551
1552
            if (statement->current_proto_field)
1215.1.15 by stewart at flamingspork
[patch 15/17] add length of VARCHAR colmun to proto in parser
1553
	    {
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1554
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1215.1.15 by stewart at flamingspork
[patch 15/17] add length of VARCHAR colmun to proto in parser
1555
1556
              message::Table::Field::StringFieldOptions *string_field_options;
1557
1558
              string_field_options= statement->current_proto_field->mutable_string_options();
1559
1560
              string_field_options->set_length(atoi($3.str));
1561
            }
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1562
            }
1563
          | VARBINARY '(' NUM ')'
1564
            {
1565
              Lex->length=$3.str;
1566
              Lex->charset=&my_charset_bin;
1567
              $$= DRIZZLE_TYPE_VARCHAR;
1568
1569
            statement::CreateTable *statement=
1570
              (statement::CreateTable *)Lex->statement;
1571
1572
            if (statement->current_proto_field)
1215.1.16 by stewart at flamingspork
[patch 16/17] VARBINARY length in proto in parser
1573
	    {
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1574
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1215.1.16 by stewart at flamingspork
[patch 16/17] VARBINARY length in proto in parser
1575
              message::Table::Field::StringFieldOptions *string_field_options;
1576
1577
              string_field_options= statement->current_proto_field->mutable_string_options();
1578
1579
              string_field_options->set_length(atoi($3.str));
1215.1.17 by stewart at flamingspork
[patch 17/17] set varbinary charset in parser
1580
              string_field_options->set_collation_id(my_charset_bin.number);
1581
              string_field_options->set_collation(my_charset_bin.name);
1215.1.16 by stewart at flamingspork
[patch 16/17] VARBINARY length in proto in parser
1582
            }
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1583
            }
1584
          | DATE_SYM
1585
          {
1586
            $$=DRIZZLE_TYPE_DATE;
1587
1588
            statement::CreateTable *statement=
1589
              (statement::CreateTable *)Lex->statement;
1590
1591
            if (statement->current_proto_field)
1592
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1593
          }
1594
          | TIMESTAMP_SYM
1595
          {
1596
            $$=DRIZZLE_TYPE_TIMESTAMP;
1597
1598
            statement::CreateTable *statement=
1599
              (statement::CreateTable *)Lex->statement;
1600
1601
            if (statement->current_proto_field)
1602
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1603
          }
1604
          | DATETIME_SYM
1605
          {
1606
            $$=DRIZZLE_TYPE_DATETIME;
1607
1608
            statement::CreateTable *statement=
1609
              (statement::CreateTable *)Lex->statement;
1610
1611
            if (statement->current_proto_field)
1612
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1613
          }
1614
          | BLOB_SYM
1615
            {
1616
              Lex->charset=&my_charset_bin;
1617
              $$=DRIZZLE_TYPE_BLOB;
1618
              Lex->length=(char*) 0; /* use default length */
1619
1382 by Brian Aker
We were printing out info on charset (which we don't need to do... and don't
1620
              statement::CreateTable *statement=
1621
                (statement::CreateTable *)Lex->statement;
1622
1623
              if (statement->current_proto_field)
1624
              {
1625
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
1626
                message::Table::Field::StringFieldOptions *string_field_options;
1627
1628
                string_field_options= statement->current_proto_field->mutable_string_options();
1629
                string_field_options->set_collation_id(my_charset_bin.number);
1630
                string_field_options->set_collation(my_charset_bin.name);
1631
              }
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1632
            }
1220.1.11 by Brian Aker
Committing Stewart's work
1633
          | TEXT_SYM
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1634
            {
1635
              $$=DRIZZLE_TYPE_BLOB;
1636
              Lex->length=(char*) 0; /* use default length */
1637
1638
            statement::CreateTable *statement=
1639
              (statement::CreateTable *)Lex->statement;
1640
1641
            if (statement->current_proto_field)
1642
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
1643
            }
1644
          | DECIMAL_SYM float_options
1645
          {
1646
            $$=DRIZZLE_TYPE_DECIMAL;
1647
1648
            statement::CreateTable *statement=
1649
              (statement::CreateTable *)Lex->statement;
1650
1651
            if (statement->current_proto_field)
1652
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1653
          }
1654
          | NUMERIC_SYM float_options
1655
          {
1656
            $$=DRIZZLE_TYPE_DECIMAL;
1657
1658
            statement::CreateTable *statement=
1659
              (statement::CreateTable *)Lex->statement;
1660
1661
            if (statement->current_proto_field)
1662
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1663
          }
1664
          | FIXED_SYM float_options
1665
          {
1666
            $$=DRIZZLE_TYPE_DECIMAL;
1667
1668
            statement::CreateTable *statement=
1669
              (statement::CreateTable *)Lex->statement;
1670
1671
            if (statement->current_proto_field)
1672
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1673
          }
1674
          | ENUM_SYM
1675
            {Lex->interval_list.empty();}
1220.1.11 by Brian Aker
Committing Stewart's work
1676
            '(' string_list ')'
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1677
          {
1678
            $$=DRIZZLE_TYPE_ENUM;
1679
1680
            statement::CreateTable *statement=
1681
              (statement::CreateTable *)Lex->statement;
1682
1683
            if (statement->current_proto_field)
1684
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1685
          }
1 by brian
clean slate
1686
        | SERIAL_SYM
1687
          {
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
1688
            $$=DRIZZLE_TYPE_LONGLONG;
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1689
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1690
1691
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1692
            if (statement->current_proto_field)
1693
            {
1694
              message::Table::Field::FieldConstraints *constraints;
1695
              constraints= statement->current_proto_field->mutable_constraints();
1696
              constraints->set_is_nullable(false);
1215.1.5 by stewart at flamingspork
[patch 05/17] Set Field type in proto in parser.
1697
1698
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1699
            }
1 by brian
clean slate
1700
          }
1701
        ;
1702
1703
char:
1704
          CHAR_SYM {}
1705
        ;
1706
1707
varchar:
1708
          char VARYING {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
1709
        | VARCHAR_SYM {}
1 by brian
clean slate
1710
        ;
1711
1712
int_type:
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
1713
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
1714
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1 by brian
clean slate
1715
        ;
1716
1717
real_type:
1718
          REAL
1719
          {
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
1720
            $$= DRIZZLE_TYPE_DOUBLE;
1 by brian
clean slate
1721
          }
1722
        | DOUBLE_SYM
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
1723
          { $$=DRIZZLE_TYPE_DOUBLE; }
1 by brian
clean slate
1724
        | DOUBLE_SYM PRECISION
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
1725
          { $$=DRIZZLE_TYPE_DOUBLE; }
1 by brian
clean slate
1726
        ;
1727
1728
float_options:
1729
          /* empty */
1730
          { Lex->dec=Lex->length= (char*)0; }
1731
        | '(' NUM ')'
1732
          { Lex->length=$2.str; Lex->dec= (char*)0; }
1733
        | precision
1734
          {}
1735
        ;
1736
1737
precision:
1738
          '(' NUM ',' NUM ')'
1739
          {
1740
            LEX *lex=Lex;
1741
            lex->length=$2.str;
1742
            lex->dec=$4.str;
1743
          }
1744
        ;
1745
1746
opt_len:
1747
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
1748
        | '(' NUM ')' { Lex->length= $2.str; }
1749
        ;
1750
1751
opt_precision:
1752
          /* empty */ {}
1753
        | precision {}
1754
        ;
1755
1756
opt_attribute:
1757
          /* empty */ {}
1758
        | opt_attribute_list {}
1759
        ;
1760
1761
opt_attribute_list:
1762
          opt_attribute_list attribute {}
1763
        | attribute
1764
        ;
1765
1766
attribute:
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1767
          NULL_SYM
1768
          {
1769
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1770
            Lex->type&= ~ NOT_NULL_FLAG;
1771
1772
            if (statement->current_proto_field)
1773
            {
1774
              message::Table::Field::FieldConstraints *constraints;
1775
              constraints= statement->current_proto_field->mutable_constraints();
1776
              constraints->set_is_nullable(true);
1777
            }
1778
          }
1 by brian
clean slate
1779
        | COLUMN_FORMAT_SYM column_format_types
1780
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1781
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1782
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1783
            statement->column_format= $2;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1784
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1 by brian
clean slate
1785
          }
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1786
        | not NULL_SYM
1787
          {
1788
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1789
            Lex->type|= NOT_NULL_FLAG;
1790
1791
            if (statement->current_proto_field)
1792
            {
1793
              message::Table::Field::FieldConstraints *constraints;
1794
              constraints= statement->current_proto_field->mutable_constraints();
1795
              constraints->set_is_nullable(false);
1796
            }
1797
          }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1798
        | DEFAULT now_or_signed_literal
1799
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1800
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1801
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1802
            statement->default_value=$2;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1803
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1 by brian
clean slate
1804
          }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1805
        | ON UPDATE_SYM NOW_SYM optional_braces
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
1806
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1807
        | AUTO_INC
1808
          {
1809
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1810
1811
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1812
            if (statement->current_proto_field)
1813
            {
1814
              message::Table::Field::FieldConstraints *constraints;
1815
1816
              constraints= statement->current_proto_field->mutable_constraints();
1817
              constraints->set_is_nullable(false);
1818
            }
1819
          }
1 by brian
clean slate
1820
        | SERIAL_SYM DEFAULT VALUE_SYM
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1821
          {
1 by brian
clean slate
1822
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1823
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1824
1 by brian
clean slate
1825
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1826
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1827
1828
            if (statement->current_proto_field)
1829
            {
1830
              message::Table::Field::FieldConstraints *constraints;
1831
              constraints= statement->current_proto_field->mutable_constraints();
1832
              constraints->set_is_nullable(false);
1833
            }
1 by brian
clean slate
1834
          }
1835
        | opt_primary KEY_SYM
1836
          {
1837
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1838
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1839
1 by brian
clean slate
1840
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1841
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
1842
1843
            if (statement->current_proto_field)
1844
            {
1845
              message::Table::Field::FieldConstraints *constraints;
1846
              constraints= statement->current_proto_field->mutable_constraints();
1847
              constraints->set_is_nullable(false);
1848
            }
1 by brian
clean slate
1849
          }
1850
        | UNIQUE_SYM
1851
          {
1852
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1853
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1854
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1855
            lex->type|= UNIQUE_FLAG;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1856
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1 by brian
clean slate
1857
          }
1858
        | UNIQUE_SYM KEY_SYM
1859
          {
1860
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1861
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1862
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
1863
            lex->type|= UNIQUE_KEY_FLAG;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
1864
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1 by brian
clean slate
1865
          }
1215.1.4 by stewart at flamingspork
[patch 04/17] field comment set in table proto in parser
1866
        | COMMENT_SYM TEXT_STRING_sys
1867
          {
1868
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1869
            statement->comment= $2;
1870
1871
            if (statement->current_proto_field)
1872
              statement->current_proto_field->set_comment($2.str);
1873
          }
1 by brian
clean slate
1874
        | COLLATE_SYM collation_name
1875
          {
1876
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
1877
            {
1878
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1879
                       $2->name,Lex->charset->csname);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1880
              DRIZZLE_YYABORT;
1 by brian
clean slate
1881
            }
1882
            else
1883
            {
1884
              Lex->charset=$2;
1885
            }
1886
          }
1887
        ;
1888
1889
now_or_signed_literal:
1890
          NOW_SYM optional_braces
1891
          { $$= new Item_func_now_local(); }
1892
        | signed_literal
1893
          { $$=$1; }
1894
        ;
1895
1896
collation_name:
1897
          ident_or_text
1898
          {
862 by Brian Aker
Remove charset directory code.
1899
            if (!($$=get_charset_by_name($1.str)))
1 by brian
clean slate
1900
            {
1901
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1902
              DRIZZLE_YYABORT;
1 by brian
clean slate
1903
            }
1904
          }
1905
        ;
1906
1907
collation_name_or_default:
1908
          collation_name { $$=$1; }
1909
        | DEFAULT    { $$=NULL; }
1910
        ;
1911
1912
opt_default:
1913
          /* empty */ {}
1914
        | DEFAULT {}
1915
        ;
1916
1917
opt_primary:
1918
          /* empty */
1919
        | PRIMARY_SYM
1920
        ;
1921
1922
references:
1923
          REFERENCES
1924
          table_ident
1925
          opt_ref_list
1926
          opt_match_clause
1927
          opt_on_update_delete
1928
          {
1929
            $$=$2;
1930
          }
1931
        ;
1932
1933
opt_ref_list:
1934
          /* empty */
1935
          { Lex->ref_list.empty(); }
1936
        | '(' ref_list ')'
1937
        ;
1938
1939
ref_list:
1940
          ref_list ',' ident
1941
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1942
        | ident
1943
          {
1944
            LEX *lex= Lex;
1945
            lex->ref_list.empty();
1946
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1947
          }
1948
        ;
1949
1950
opt_match_clause:
1951
          /* empty */
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1952
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
1 by brian
clean slate
1953
        | MATCH FULL
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1954
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
1 by brian
clean slate
1955
        | MATCH PARTIAL
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1956
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
1 by brian
clean slate
1957
        | MATCH SIMPLE_SYM
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1958
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
1 by brian
clean slate
1959
        ;
1960
1961
opt_on_update_delete:
1962
          /* empty */
1963
          {
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1964
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1965
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1 by brian
clean slate
1966
          }
1967
        | ON UPDATE_SYM delete_option
1968
          {
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
1969
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1970
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1 by brian
clean slate
1971
          }
1972
        | ON DELETE_SYM delete_option
1973
          {
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1974
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
1975
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1 by brian
clean slate
1976
          }
1977
        | ON UPDATE_SYM delete_option
1978
          ON DELETE_SYM delete_option
1979
          {
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
1980
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1981
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
1 by brian
clean slate
1982
          }
1983
        | ON DELETE_SYM delete_option
1984
          ON UPDATE_SYM delete_option
1985
          {
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
1986
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
1987
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1 by brian
clean slate
1988
          }
1989
        ;
1990
1991
delete_option:
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
1992
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1993
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1994
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1995
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1996
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_DEFAULT;  }
1 by brian
clean slate
1997
        ;
1998
1999
key_type:
2000
          key_or_index { $$= Key::MULTIPLE; }
2001
        ;
2002
2003
constraint_key_type:
2004
          PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
2005
        | UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; }
2006
        ;
2007
2008
key_or_index:
2009
          KEY_SYM {}
2010
        | INDEX_SYM {}
2011
        ;
2012
2013
opt_key_or_index:
2014
          /* empty */ {}
2015
        | key_or_index
2016
        ;
2017
2018
keys_or_index:
2019
          KEYS {}
2020
        | INDEX_SYM {}
2021
        | INDEXES {}
2022
        ;
2023
2024
opt_unique:
2025
          /* empty */  { $$= Key::MULTIPLE; }
2026
        | UNIQUE_SYM   { $$= Key::UNIQUE; }
2027
        ;
2028
2029
init_key_options:
2030
          {
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
2031
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
1 by brian
clean slate
2032
          }
2033
        ;
2034
2035
/*
2036
  For now, key_alg initializies lex->key_create_info.
2037
  In the future, when all key options are after key definition,
2038
  we can remove key_alg and move init_key_options to key_options
2039
*/
2040
2041
key_alg:
2042
          init_key_options
2043
        | init_key_options key_using_alg
2044
        ;
2045
2046
key_options:
2047
          /* empty */ {}
2048
        | key_opts
2049
        ;
2050
2051
key_opts:
2052
          key_opt
2053
        | key_opts key_opt
2054
        ;
2055
2056
key_using_alg:
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
2057
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2058
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1 by brian
clean slate
2059
        ;
2060
2061
key_opt:
2062
          key_using_alg
2063
        | KEY_BLOCK_SIZE opt_equal ulong_num
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
2064
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
1 by brian
clean slate
2065
        | COMMENT_SYM TEXT_STRING_sys
1128.2.9 by Brian Aker
Remove KEY_CREATE_INFO from global lex.
2066
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
1 by brian
clean slate
2067
        ;
2068
2069
btree_or_rtree:
2070
          BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
2071
        | HASH_SYM  { $$= HA_KEY_ALG_HASH; }
2072
        ;
2073
2074
key_list:
2075
          key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
2076
        | key_part order_dir { Lex->col_list.push_back($1); }
2077
        ;
2078
2079
key_part:
2080
          ident { $$=new Key_part_spec($1, 0); }
2081
        | ident '(' NUM ')'
2082
          {
2083
            int key_part_len= atoi($3.str);
2084
            if (!key_part_len)
2085
            {
2086
              my_error(ER_KEY_PART_0, MYF(0), $1.str);
2087
            }
2088
            $$=new Key_part_spec($1, (uint) key_part_len);
2089
          }
2090
        ;
2091
2092
opt_ident:
2093
          /* empty */ { $$= null_lex_str; }
2094
        | field_ident { $$= $1; }
2095
        ;
2096
2097
opt_component:
2098
          /* empty */    { $$= null_lex_str; }
2099
        | '.' ident      { $$= $2; }
2100
        ;
2101
2102
string_list:
2103
          text_string { Lex->interval_list.push_back($1); }
2104
        | string_list ',' text_string { Lex->interval_list.push_back($3); };
2105
2106
/*
2107
** Alter table
2108
*/
2109
2110
alter:
2111
          ALTER build_method opt_ignore TABLE_SYM table_ident
2112
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2113
            Session *session= YYSession;
2114
            LEX *lex= session->lex;
1 by brian
clean slate
2115
            lex->name.str= 0;
2116
            lex->name.length= 0;
2117
            lex->sql_command= SQLCOM_ALTER_TABLE;
1128.2.3 by Brian Aker
Remove create_info from global
2118
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
2119
            lex->statement= statement;
1100.3.63 by Padraig O'Sullivan
Extracted the ALTER TABLE command into its own class and implementation
2120
            if (lex->statement == NULL)
2121
              DRIZZLE_YYABORT;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2122
            lex->duplicates= DUP_ERROR;
520.1.22 by Brian Aker
Second pass of thd cleanup
2123
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1 by brian
clean slate
2124
                                                   TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2125
              DRIZZLE_YYABORT;
1 by brian
clean slate
2126
            lex->col_list.empty();
2127
            lex->select_lex.init_order();
2128
            lex->select_lex.db=
327.2.5 by Brian Aker
Refactoring show command
2129
              ((TableList*) lex->select_lex.table_list.first)->db;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2130
            statement->alter_info.build_method= $2;
1 by brian
clean slate
2131
          }
2132
          alter_commands
2133
          {}
2134
        | ALTER DATABASE ident_or_empty
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2135
          {
1 by brian
clean slate
2136
            LEX *lex=Lex;
2137
            lex->sql_command=SQLCOM_ALTER_DB;
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
2138
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
2139
            if (lex->statement == NULL)
2140
              DRIZZLE_YYABORT;
1128.2.3 by Brian Aker
Remove create_info from global
2141
          }
1128.2.7 by Brian Aker
Cleanup previous issues in create sql_yacc
2142
          default_collation_schema
1128.2.3 by Brian Aker
Remove create_info from global
2143
          {
2144
            LEX *lex=Lex;
1 by brian
clean slate
2145
            lex->name= $3;
2146
            if (lex->name.str == NULL &&
2147
                lex->copy_db_to(&lex->name.str, &lex->name.length))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2148
              DRIZZLE_YYABORT;
1 by brian
clean slate
2149
          }
2150
        ;
2151
2152
ident_or_empty:
2153
          /* empty */ { $$.str= 0; $$.length= 0; }
2154
        | ident { $$= $1; }
2155
        ;
2156
2157
alter_commands:
2158
          /* empty */
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2159
        | DISCARD TABLESPACE
2160
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2161
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2162
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2163
          }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2164
        | IMPORT TABLESPACE
2165
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2166
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2167
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2168
          }
1 by brian
clean slate
2169
        | alter_list
2170
        ;
2171
2172
build_method:
2173
        /* empty */
2174
          {
2175
            $$= HA_BUILD_DEFAULT;
2176
          }
2177
        | ONLINE_SYM
2178
          {
2179
            $$= HA_BUILD_ONLINE;
2180
          }
2181
        | OFFLINE_SYM
2182
          {
2183
            $$= HA_BUILD_OFFLINE;
2184
          }
2185
        ;
2186
2187
alter_list:
2188
          alter_list_item
2189
        | alter_list ',' alter_list_item
2190
        ;
2191
2192
add_column:
2193
          ADD opt_column
2194
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2195
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2196
2197
            statement->change=0;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2198
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1 by brian
clean slate
2199
          }
2200
        ;
2201
2202
alter_list_item:
2203
          add_column column_def opt_place { }
2204
        | ADD key_def
2205
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2206
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2207
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2208
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1 by brian
clean slate
2209
          }
2210
        | add_column '(' field_list ')'
2211
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2212
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2213
2214
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2215
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1 by brian
clean slate
2216
          }
2217
        | CHANGE opt_column field_ident
2218
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2219
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2220
            statement->change= $3.str;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2221
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1 by brian
clean slate
2222
          }
2223
          field_spec opt_place
2224
        | MODIFY_SYM opt_column field_ident
2225
          {
2226
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2227
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1 by brian
clean slate
2228
            lex->length=lex->dec=0; lex->type=0;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2229
            statement->default_value= statement->on_update_value= 0;
2230
            statement->comment= null_lex_str;
1 by brian
clean slate
2231
            lex->charset= NULL;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2232
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2233
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1215.1.2 by stewart at flamingspork
[patch 02/17] field NULL | NOT NULL in proto in parser. Only for CREATE TABLE. Change default in proto to reflect default in SQL.
2234
2235
            statement->current_proto_field= NULL;
1 by brian
clean slate
2236
          }
383.7.1 by Andrey Zhakov
Initial submit of code and tests
2237
          field_def
1 by brian
clean slate
2238
          {
2239
            LEX *lex=Lex;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2240
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2241
520.1.22 by Brian Aker
Second pass of thd cleanup
2242
            if (add_field_to_list(lex->session,&$3,
1 by brian
clean slate
2243
                                  (enum enum_field_types) $5,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2244
                                  lex->length, lex->dec, lex->type,
2245
                                  statement->column_format,
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2246
                                  statement->default_value,
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2247
                                  statement->on_update_value,
2248
                                  &statement->comment,
998.1.2 by Brian Aker
First pass on removing virt columns
2249
                                  $3.str, &lex->interval_list, lex->charset))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2250
              DRIZZLE_YYABORT;
1 by brian
clean slate
2251
          }
2252
          opt_place
184 by Brian Aker
Dead debug code removal (and a compatible "never used") bit in the
2253
        | DROP opt_column field_ident
1 by brian
clean slate
2254
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2255
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2256
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
2257
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN, $3.str));
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2258
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
1 by brian
clean slate
2259
          }
2260
        | DROP FOREIGN KEY_SYM opt_ident
2261
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2262
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1638.10.80 by Stewart Smith
fix storing and manipulating foreign keys in the proto around ALTER TABLE, CREATE TABLE and ALTER TABLE ADD/DROP FOREIGN KEY. We also (mostly) emulate the naming of innodb foreign keys in the upper layer.
2263
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY,
2264
                                                                    $4.str));
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2265
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2266
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1 by brian
clean slate
2267
          }
2268
        | DROP PRIMARY_SYM KEY_SYM
2269
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2270
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2271
2272
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
590.1.1 by Stewart Smith
begin moving from global const char* primary_key_name to methods is_primary_key() and is_primary_key_name()
2273
                                                               "PRIMARY"));
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2274
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1 by brian
clean slate
2275
          }
2276
        | DROP key_or_index field_ident
2277
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2278
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2279
2280
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
2281
                                                                    $3.str));
2282
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1 by brian
clean slate
2283
          }
2284
        | DISABLE_SYM KEYS
2285
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2286
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2287
2288
            statement->alter_info.keys_onoff= DISABLE;
2289
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1 by brian
clean slate
2290
          }
2291
        | ENABLE_SYM KEYS
2292
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2293
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2294
2295
            statement->alter_info.keys_onoff= ENABLE;
2296
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1 by brian
clean slate
2297
          }
2298
        | ALTER opt_column field_ident SET DEFAULT signed_literal
2299
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2300
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2301
2302
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
2303
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1 by brian
clean slate
2304
          }
2305
        | ALTER opt_column field_ident DROP DEFAULT
2306
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2307
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2308
2309
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str, (Item*) 0));
2310
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1 by brian
clean slate
2311
          }
2312
        | RENAME opt_to table_ident
2313
          {
2314
            LEX *lex=Lex;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2315
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1 by brian
clean slate
2316
            size_t dummy;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2317
1 by brian
clean slate
2318
            lex->select_lex.db=$3->db.str;
2319
            if (lex->select_lex.db == NULL &&
2320
                lex->copy_db_to(&lex->select_lex.db, &dummy))
2321
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2322
              DRIZZLE_YYABORT;
1 by brian
clean slate
2323
            }
1235.4.9 by Stewart Smith
remove check_db_name() from sql_yacc.yy and replace with NormalisedDatabaseName and friends. This check should really be down a layer... but let's not change everything at once
2324
2325
            if (check_table_name($3->table.str,$3->table.length))
1 by brian
clean slate
2326
            {
2327
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2328
              DRIZZLE_YYABORT;
1 by brian
clean slate
2329
            }
1235.4.9 by Stewart Smith
remove check_db_name() from sql_yacc.yy and replace with NormalisedDatabaseName and friends. This check should really be down a layer... but let's not change everything at once
2330
1 by brian
clean slate
2331
            lex->name= $3->table;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2332
            statement->alter_info.flags.set(ALTER_RENAME);
1 by brian
clean slate
2333
          }
383.1.27 by Brian Aker
Next pass in the unending saga of UTF-8.. now we can set in SQL collation
2334
        | CONVERT_SYM TO_SYM collation_name_or_default
1 by brian
clean slate
2335
          {
1128.2.3 by Brian Aker
Remove create_info from global
2336
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2337
2338
            statement->create_info.table_charset=
2339
            statement->create_info.default_table_charset= $3;
2340
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1 by brian
clean slate
2341
              HA_CREATE_USED_DEFAULT_CHARSET);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2342
            statement->alter_info.flags.set(ALTER_CONVERT);
1 by brian
clean slate
2343
          }
2344
        | create_table_options_space_separated
2345
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2346
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2347
2348
            statement->alter_info.flags.set(ALTER_OPTIONS);
1 by brian
clean slate
2349
          }
2350
        | FORCE_SYM
2351
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2352
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2353
2354
            statement->alter_info.flags.set(ALTER_FORCE);
1 by brian
clean slate
2355
          }
2356
        | alter_order_clause
2357
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2358
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2359
2360
            statement->alter_info.flags.set(ALTER_ORDER);
1 by brian
clean slate
2361
          }
2362
        ;
2363
2364
opt_column:
2365
          /* empty */ {}
2366
        | COLUMN_SYM {}
2367
        ;
2368
2369
opt_ignore:
2370
          /* empty */ { Lex->ignore= 0;}
2371
        | IGNORE_SYM { Lex->ignore= 1;}
2372
        ;
2373
2374
opt_place:
2375
          /* empty */ {}
2376
        | AFTER_SYM ident
2377
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2378
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2379
1 by brian
clean slate
2380
            store_position_for_column($2.str);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2381
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1 by brian
clean slate
2382
          }
2383
        | FIRST_SYM
2384
          {
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2385
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2386
1 by brian
clean slate
2387
            store_position_for_column(first_keyword);
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
2388
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1 by brian
clean slate
2389
          }
2390
        ;
2391
2392
opt_to:
2393
          /* empty */ {}
2394
        | TO_SYM {}
2395
        | EQ {}
2396
        | AS {}
2397
        ;
2398
2399
start:
2400
          START_SYM TRANSACTION_SYM start_transaction_opts
2401
          {
2402
            LEX *lex= Lex;
2403
            lex->sql_command= SQLCOM_BEGIN;
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
2404
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
1100.3.55 by Padraig O'Sullivan
Extracted the BEGIN command into its own class and implementation files.
2405
            if (lex->statement == NULL)
2406
              DRIZZLE_YYABORT;
1 by brian
clean slate
2407
          }
2408
        ;
2409
2410
start_transaction_opts:
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
2411
          /*empty*/ { $$ = START_TRANS_NO_OPTIONS; }
1 by brian
clean slate
2412
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
2413
          {
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
2414
            $$= START_TRANS_OPT_WITH_CONS_SNAPSHOT;
1 by brian
clean slate
2415
          }
2416
        ;
2417
2418
analyze:
383.1.26 by Brian Aker
Removed option for single command replication and have now left disable of
2419
          ANALYZE_SYM table_or_tables
1 by brian
clean slate
2420
          {
2421
            LEX *lex=Lex;
2422
            lex->sql_command = SQLCOM_ANALYZE;
1100.3.38 by Padraig O'Sullivan
Extracted the ANALYZE command into its own class and implementation files.
2423
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
2424
            if (lex->statement == NULL)
2425
              DRIZZLE_YYABORT;
1 by brian
clean slate
2426
          }
2427
          table_list
2428
          {}
2429
        ;
2430
2431
check:
2432
          CHECK_SYM table_or_tables
2433
          {
2434
            LEX *lex=Lex;
2435
2436
            lex->sql_command = SQLCOM_CHECK;
1100.3.37 by Padraig O'Sullivan
Extracted the CHECK command into its own class.
2437
            lex->statement= new(std::nothrow) statement::Check(YYSession);
2438
            if (lex->statement == NULL)
2439
              DRIZZLE_YYABORT;
1 by brian
clean slate
2440
          }
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
2441
          table_list
1 by brian
clean slate
2442
          {}
2443
        ;
2444
2445
rename:
2446
          RENAME table_or_tables
2447
          {
2448
            Lex->sql_command= SQLCOM_RENAME_TABLE;
1100.3.57 by Padraig O'Sullivan
Extracted the RENAME TABLE command into its own class and implementation
2449
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
2450
            if (Lex->statement == NULL)
2451
              DRIZZLE_YYABORT;
1 by brian
clean slate
2452
          }
2453
          table_to_table_list
2454
          {}
2455
        ;
2456
2457
table_to_table_list:
2458
          table_to_table
2459
        | table_to_table_list ',' table_to_table
2460
        ;
2461
2462
table_to_table:
2463
          table_ident TO_SYM table_ident
2464
          {
2465
            LEX *lex=Lex;
846 by Brian Aker
Removing on typedeffed class.
2466
            Select_Lex *sl= lex->current_select;
520.1.22 by Brian Aker
Second pass of thd cleanup
2467
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1 by brian
clean slate
2468
                                       TL_IGNORE) ||
520.1.22 by Brian Aker
Second pass of thd cleanup
2469
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1 by brian
clean slate
2470
                                       TL_IGNORE))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2471
              DRIZZLE_YYABORT;
1 by brian
clean slate
2472
          }
2473
        ;
2474
2475
/*
2476
  Select : retrieve data from table
2477
*/
2478
2479
2480
select:
2481
          select_init
2482
          {
2483
            LEX *lex= Lex;
2484
            lex->sql_command= SQLCOM_SELECT;
1128.2.5 by Brian Aker
Remove legacy enum
2485
            lex->statement= new(std::nothrow) statement::Select(YYSession);
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
2486
            if (lex->statement == NULL)
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
2487
              DRIZZLE_YYABORT;
1 by brian
clean slate
2488
          }
2489
        ;
2490
2491
/* Need select_init2 for subselects. */
2492
select_init:
2493
          SELECT_SYM select_init2
2494
        | '(' select_paren ')' union_opt
2495
        ;
2496
2497
select_paren:
2498
          SELECT_SYM select_part2
2499
          {
1578.6.11 by Brian Aker
Additional removal of current_session
2500
            if (setup_select_in_parentheses(YYSession, Lex))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2501
              DRIZZLE_YYABORT;
1 by brian
clean slate
2502
          }
2503
        | '(' select_paren ')'
2504
        ;
2505
2506
/* The equivalent of select_paren for nested queries. */
2507
select_paren_derived:
2508
          SELECT_SYM select_part2_derived
2509
          {
1578.6.11 by Brian Aker
Additional removal of current_session
2510
            if (setup_select_in_parentheses(YYSession, Lex))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2511
              DRIZZLE_YYABORT;
1 by brian
clean slate
2512
          }
2513
        | '(' select_paren_derived ')'
2514
        ;
2515
2516
select_init2:
2517
          select_part2
2518
          {
2519
            LEX *lex= Lex;
846 by Brian Aker
Removing on typedeffed class.
2520
            Select_Lex * sel= lex->current_select;
1 by brian
clean slate
2521
            if (lex->current_select->set_braces(0))
2522
            {
1578.6.11 by Brian Aker
Additional removal of current_session
2523
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2524
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2525
              DRIZZLE_YYABORT;
1 by brian
clean slate
2526
            }
2527
            if (sel->linkage == UNION_TYPE &&
2528
                sel->master_unit()->first_select()->braces)
2529
            {
1578.6.11 by Brian Aker
Additional removal of current_session
2530
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2531
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2532
              DRIZZLE_YYABORT;
1 by brian
clean slate
2533
            }
2534
          }
2535
          union_clause
2536
        ;
2537
2538
select_part2:
2539
          {
2540
            LEX *lex= Lex;
846 by Brian Aker
Removing on typedeffed class.
2541
            Select_Lex *sel= lex->current_select;
1 by brian
clean slate
2542
            if (sel->linkage != UNION_TYPE)
2543
              mysql_init_select(lex);
2544
            lex->current_select->parsing_place= SELECT_LIST;
2545
          }
2546
          select_options select_item_list
2547
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2548
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
2549
          }
2550
          select_into select_lock_type
2551
        ;
2552
2553
select_into:
2554
          opt_order_clause opt_limit_clause {}
2555
        | into
2556
        | select_from
2557
        | into select_from
2558
        | select_from into
2559
        ;
2560
2561
select_from:
2562
          FROM join_table_list where_clause group_clause having_clause
2563
          opt_order_clause opt_limit_clause
2564
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2565
            Lex->current_select->context.table_list=
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2566
              Lex->current_select->context.first_name_resolution_table=
1101.2.4 by Monty Taylor
Fixed some small errors in previous patches.
2567
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
1 by brian
clean slate
2568
          }
2569
        ;
2570
2571
select_options:
2572
          /* empty*/
2573
        | select_option_list
2574
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2575
            if (Lex->current_select->options & SELECT_DISTINCT &&
2576
                Lex->current_select->options & SELECT_ALL)
1 by brian
clean slate
2577
            {
2578
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2579
              DRIZZLE_YYABORT;
1 by brian
clean slate
2580
            }
2581
          }
2582
        ;
2583
2584
select_option_list:
2585
          select_option_list select_option
2586
        | select_option
2587
        ;
2588
2589
select_option:
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2590
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
2591
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
2592
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
2593
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
1 by brian
clean slate
2594
        | SQL_BUFFER_RESULT
2595
          {
2596
            if (check_simple_select())
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2597
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2598
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
1 by brian
clean slate
2599
          }
2600
        | SQL_CALC_FOUND_ROWS
2601
          {
2602
            if (check_simple_select())
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2603
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2604
            Lex->current_select->options|= OPTION_FOUND_ROWS;
1 by brian
clean slate
2605
          }
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
2606
        | ALL { Lex->current_select->options|= SELECT_ALL; }
1 by brian
clean slate
2607
        ;
2608
2609
select_lock_type:
2610
          /* empty */
2611
        | FOR_SYM UPDATE_SYM
2612
          {
2613
            LEX *lex=Lex;
2614
            lex->current_select->set_lock_for_tables(TL_WRITE);
2615
          }
2616
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2617
          {
2618
            LEX *lex=Lex;
2619
            lex->current_select->
2620
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2621
          }
2622
        ;
2623
2624
select_item_list:
2625
          select_item_list ',' select_item
2626
        | select_item
2627
        | '*'
2628
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2629
            Session *session= YYSession;
838 by Brian Aker
More class adoption/method
2630
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
2631
                                                          context,
2632
                                                          NULL, NULL, "*")))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2633
              DRIZZLE_YYABORT;
520.1.22 by Brian Aker
Second pass of thd cleanup
2634
            (session->lex->current_select->with_wild)++;
1 by brian
clean slate
2635
          }
2636
        ;
2637
2638
select_item:
2639
          remember_name table_wild remember_end
2640
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2641
            Session *session= YYSession;
1 by brian
clean slate
2642
838 by Brian Aker
More class adoption/method
2643
            if (session->add_item_to_list($2))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2644
              DRIZZLE_YYABORT;
1 by brian
clean slate
2645
          }
2646
        | remember_name expr remember_end select_alias
2647
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2648
            Session *session= YYSession;
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
2649
            assert($1 < $3);
1 by brian
clean slate
2650
838 by Brian Aker
More class adoption/method
2651
            if (session->add_item_to_list($2))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2652
              DRIZZLE_YYABORT;
1 by brian
clean slate
2653
            if ($4.str)
2654
            {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
2655
              $2->is_autogenerated_name= false;
1 by brian
clean slate
2656
              $2->set_name($4.str, $4.length, system_charset_info);
2657
            }
2658
            else if (!$2->name)
2659
            {
520.1.22 by Brian Aker
Second pass of thd cleanup
2660
              $2->set_name($1, (uint) ($3 - $1), session->charset());
1 by brian
clean slate
2661
            }
2662
          }
2663
        ;
2664
2665
remember_name:
2666
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2667
            Session *session= YYSession;
2668
            Lex_input_stream *lip= session->m_lip;
1 by brian
clean slate
2669
            $$= (char*) lip->get_cpp_tok_start();
2670
          }
2671
        ;
2672
2673
remember_end:
2674
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2675
            Session *session= YYSession;
2676
            Lex_input_stream *lip= session->m_lip;
1 by brian
clean slate
2677
            $$= (char*) lip->get_cpp_tok_end();
2678
          }
2679
        ;
2680
2681
select_alias:
2682
          /* empty */ { $$=null_lex_str;}
2683
        | AS ident { $$=$2; }
2684
        | AS TEXT_STRING_sys { $$=$2; }
2685
        | ident { $$=$1; }
2686
        | TEXT_STRING_sys { $$=$1; }
2687
        ;
2688
2689
optional_braces:
2690
          /* empty */ {}
2691
        | '(' ')' {}
2692
        ;
2693
2694
/* all possible expressions */
2695
expr:
2696
          expr or expr %prec OR_SYM
2697
          {
2698
            /*
2699
              Design notes:
520.1.22 by Brian Aker
Second pass of thd cleanup
2700
              Do not use a manually maintained stack like session->lex->xxx_list,
1 by brian
clean slate
2701
              but use the internal bison stack ($$, $1 and $3) instead.
2702
              Using the bison stack is:
2703
              - more robust to changes in the grammar,
2704
              - guaranteed to be in sync with the parser state,
2705
              - better for performances (no memory allocation).
2706
            */
2707
            Item_cond_or *item1;
2708
            Item_cond_or *item3;
2709
            if (is_cond_or($1))
2710
            {
2711
              item1= (Item_cond_or*) $1;
2712
              if (is_cond_or($3))
2713
              {
2714
                item3= (Item_cond_or*) $3;
2715
                /*
2716
                  (X1 OR X2) OR (Y1 OR Y2) ==> OR (X1, X2, Y1, Y2)
2717
                */
2718
                item3->add_at_head(item1->argument_list());
2719
                $$ = $3;
2720
              }
2721
              else
2722
              {
2723
                /*
2724
                  (X1 OR X2) OR Y ==> OR (X1, X2, Y)
2725
                */
2726
                item1->add($3);
2727
                $$ = $1;
2728
              }
2729
            }
2730
            else if (is_cond_or($3))
2731
            {
2732
              item3= (Item_cond_or*) $3;
2733
              /*
2734
                X OR (Y1 OR Y2) ==> OR (X, Y1, Y2)
2735
              */
2736
              item3->add_at_head($1);
2737
              $$ = $3;
2738
            }
2739
            else
2740
            {
2741
              /* X OR Y */
520.1.22 by Brian Aker
Second pass of thd cleanup
2742
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
1 by brian
clean slate
2743
            }
2744
          }
2745
        | expr XOR expr %prec XOR
2746
          {
2747
            /* XOR is a proprietary extension */
520.1.22 by Brian Aker
Second pass of thd cleanup
2748
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
1 by brian
clean slate
2749
          }
2750
        | expr and expr %prec AND_SYM
2751
          {
2752
            /* See comments in rule expr: expr or expr */
2753
            Item_cond_and *item1;
2754
            Item_cond_and *item3;
2755
            if (is_cond_and($1))
2756
            {
2757
              item1= (Item_cond_and*) $1;
2758
              if (is_cond_and($3))
2759
              {
2760
                item3= (Item_cond_and*) $3;
2761
                /*
2762
                  (X1 AND X2) AND (Y1 AND Y2) ==> AND (X1, X2, Y1, Y2)
2763
                */
2764
                item3->add_at_head(item1->argument_list());
2765
                $$ = $3;
2766
              }
2767
              else
2768
              {
2769
                /*
2770
                  (X1 AND X2) AND Y ==> AND (X1, X2, Y)
2771
                */
2772
                item1->add($3);
2773
                $$ = $1;
2774
              }
2775
            }
2776
            else if (is_cond_and($3))
2777
            {
2778
              item3= (Item_cond_and*) $3;
2779
              /*
2780
                X AND (Y1 AND Y2) ==> AND (X, Y1, Y2)
2781
              */
2782
              item3->add_at_head($1);
2783
              $$ = $3;
2784
            }
2785
            else
2786
            {
2787
              /* X AND Y */
520.1.22 by Brian Aker
Second pass of thd cleanup
2788
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
1 by brian
clean slate
2789
            }
2790
          }
2791
        | NOT_SYM expr %prec NOT_SYM
520.1.22 by Brian Aker
Second pass of thd cleanup
2792
          { $$= negate_expression(YYSession, $2); }
1 by brian
clean slate
2793
        | bool_pri IS TRUE_SYM %prec IS
520.1.22 by Brian Aker
Second pass of thd cleanup
2794
          { $$= new (YYSession->mem_root) Item_func_istrue($1); }
1 by brian
clean slate
2795
        | bool_pri IS not TRUE_SYM %prec IS
520.1.22 by Brian Aker
Second pass of thd cleanup
2796
          { $$= new (YYSession->mem_root) Item_func_isnottrue($1); }
1 by brian
clean slate
2797
        | bool_pri IS FALSE_SYM %prec IS
520.1.22 by Brian Aker
Second pass of thd cleanup
2798
          { $$= new (YYSession->mem_root) Item_func_isfalse($1); }
1 by brian
clean slate
2799
        | bool_pri IS not FALSE_SYM %prec IS
520.1.22 by Brian Aker
Second pass of thd cleanup
2800
          { $$= new (YYSession->mem_root) Item_func_isnotfalse($1); }
1 by brian
clean slate
2801
        | bool_pri IS UNKNOWN_SYM %prec IS
2802
          { $$= new Item_func_isnull($1); }
2803
        | bool_pri IS not UNKNOWN_SYM %prec IS
2804
          { $$= new Item_func_isnotnull($1); }
2805
        | bool_pri
2806
        ;
2807
2808
bool_pri:
2809
          bool_pri IS NULL_SYM %prec IS
2810
          { $$= new Item_func_isnull($1); }
2811
        | bool_pri IS not NULL_SYM %prec IS
2812
          { $$= new Item_func_isnotnull($1); }
2813
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
2814
          { $$= new Item_func_equal($1,$3); }
2815
        | bool_pri comp_op predicate %prec EQ
2816
          { $$= (*$2)(0)->create($1,$3); }
2817
        | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
2818
          { $$= all_any_subquery_creator($1, $2, $3, $5); }
2819
        | predicate
2820
        ;
2821
2822
predicate:
2823
          bit_expr IN_SYM '(' subselect ')'
2824
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2825
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
1 by brian
clean slate
2826
          }
2827
        | bit_expr not IN_SYM '(' subselect ')'
2828
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2829
            Session *session= YYSession;
2830
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
2831
            $$= negate_expression(session, item);
1 by brian
clean slate
2832
          }
2833
        | bit_expr IN_SYM '(' expr ')'
2834
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2835
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
1 by brian
clean slate
2836
          }
2837
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2838
          {
1 by brian
clean slate
2839
            $6->push_front($4);
2840
            $6->push_front($1);
520.1.22 by Brian Aker
Second pass of thd cleanup
2841
            $$= new (YYSession->mem_root) Item_func_in(*$6);
1 by brian
clean slate
2842
          }
2843
        | bit_expr not IN_SYM '(' expr ')'
2844
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2845
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
1 by brian
clean slate
2846
          }
2847
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2848
          {
2849
            $7->push_front($5);
2850
            $7->push_front($1);
520.1.22 by Brian Aker
Second pass of thd cleanup
2851
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
1 by brian
clean slate
2852
            item->negate();
2853
            $$= item;
2854
          }
2855
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2856
          { $$= new Item_func_between($1,$3,$5); }
2857
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2858
          {
2859
            Item_func_between *item= new Item_func_between($1,$4,$6);
2860
            item->negate();
2861
            $$= item;
2862
          }
2863
        | bit_expr LIKE simple_expr opt_escape
2864
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2865
        | bit_expr not LIKE simple_expr opt_escape
2866
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2867
        | bit_expr
2868
        ;
2869
2870
bit_expr:
256 by Brian Aker
Remove BIT operations, replace with functions.
2871
          bit_expr '+' bit_expr %prec '+'
1 by brian
clean slate
2872
          { $$= new Item_func_plus($1,$3); }
2873
        | bit_expr '-' bit_expr %prec '-'
2874
          { $$= new Item_func_minus($1,$3); }
2875
        | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
2876
          { $$= new Item_date_add_interval($1,$4,$5,0); }
2877
        | bit_expr '-' INTERVAL_SYM expr interval %prec '-'
2878
          { $$= new Item_date_add_interval($1,$4,$5,1); }
2879
        | bit_expr '*' bit_expr %prec '*'
2880
          { $$= new Item_func_mul($1,$3); }
2881
        | bit_expr '/' bit_expr %prec '/'
1578.6.7 by Brian Aker
Removed current_session for use to find out current session divide value.
2882
          { $$= new Item_func_div(YYSession,$1,$3); }
1 by brian
clean slate
2883
        | bit_expr '%' bit_expr %prec '%'
2884
          { $$= new Item_func_mod($1,$3); }
2885
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2886
          { $$= new Item_func_int_div($1,$3); }
2887
        | bit_expr MOD_SYM bit_expr %prec MOD_SYM
2888
          { $$= new Item_func_mod($1,$3); }
2889
        | simple_expr
2890
        ;
2891
2892
or:
2893
          OR_SYM
2894
       ;
2895
2896
and:
2897
          AND_SYM
2898
       ;
2899
2900
not:
2901
          NOT_SYM
2902
        ;
2903
2904
comp_op:
2905
          EQ     { $$ = &comp_eq_creator; }
2906
        | GE     { $$ = &comp_ge_creator; }
2907
        | GT_SYM { $$ = &comp_gt_creator; }
2908
        | LE     { $$ = &comp_le_creator; }
2909
        | LT     { $$ = &comp_lt_creator; }
2910
        | NE     { $$ = &comp_ne_creator; }
2911
        ;
2912
2913
all_or_any:
2914
          ALL     { $$ = 1; }
2915
        | ANY_SYM { $$ = 0; }
2916
        ;
2917
2918
simple_expr:
2919
          simple_ident
2920
        | function_call_keyword
2921
        | function_call_nonkeyword
2922
        | function_call_generic
2923
        | function_call_conflict
2924
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2925
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2926
            Session *session= YYSession;
2927
            Item *i1= new (session->mem_root) Item_string($3.str,
1 by brian
clean slate
2928
                                                      $3.length,
520.1.22 by Brian Aker
Second pass of thd cleanup
2929
                                                      session->charset());
2930
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
1 by brian
clean slate
2931
          }
2932
        | literal
2933
        | variable
2934
        | sum_expr
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
2935
          {
2936
            Lex->setSumExprUsed();
2937
          }
1 by brian
clean slate
2938
        | '+' simple_expr %prec NEG { $$= $2; }
2939
        | '-' simple_expr %prec NEG
520.1.22 by Brian Aker
Second pass of thd cleanup
2940
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
1 by brian
clean slate
2941
        | '(' subselect ')'
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
2942
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2943
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
1 by brian
clean slate
2944
          }
2945
        | '(' expr ')' { $$= $2; }
2946
        | '(' expr ',' expr_list ')'
2947
          {
2948
            $4->push_front($2);
520.1.22 by Brian Aker
Second pass of thd cleanup
2949
            $$= new (YYSession->mem_root) Item_row(*$4);
1 by brian
clean slate
2950
          }
2951
        | ROW_SYM '(' expr ',' expr_list ')'
2952
          {
2953
            $5->push_front($3);
520.1.22 by Brian Aker
Second pass of thd cleanup
2954
            $$= new (YYSession->mem_root) Item_row(*$5);
1 by brian
clean slate
2955
          }
2956
        | EXISTS '(' subselect ')'
2957
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2958
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
1 by brian
clean slate
2959
          }
2960
        | '{' ident expr '}' { $$= $3; }
2961
        | BINARY simple_expr %prec NEG
2962
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2963
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
1 by brian
clean slate
2964
                                 &my_charset_bin);
2965
          }
2966
        | CAST_SYM '(' expr AS cast_type ')'
2967
          {
2968
            LEX *lex= Lex;
520.1.22 by Brian Aker
Second pass of thd cleanup
2969
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
1 by brian
clean slate
2970
                                 lex->charset);
2971
            if (!$$)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2972
              DRIZZLE_YYABORT;
1 by brian
clean slate
2973
          }
2974
        | CASE_SYM opt_expr when_list opt_else END
520.1.22 by Brian Aker
Second pass of thd cleanup
2975
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
1 by brian
clean slate
2976
        | CONVERT_SYM '(' expr ',' cast_type ')'
2977
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2978
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
1 by brian
clean slate
2979
                                 Lex->charset);
2980
            if (!$$)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2981
              DRIZZLE_YYABORT;
1 by brian
clean slate
2982
          }
2983
        | DEFAULT '(' simple_ident ')'
2984
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2985
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
1 by brian
clean slate
2986
                                                         $3);
2987
          }
2988
        | VALUES '(' simple_ident_nospvar ')'
2989
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
2990
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
1 by brian
clean slate
2991
                                                        $3);
2992
          }
2993
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
2994
          /* we cannot put interval before - */
520.1.22 by Brian Aker
Second pass of thd cleanup
2995
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
1 by brian
clean slate
2996
        ;
2997
2998
/*
2999
  Function call syntax using official SQL 2003 keywords.
3000
  Because the function name is an official token,
3001
  a dedicated grammar rule is needed in the parser.
3002
  There is no potential for conflicts
3003
*/
3004
function_call_keyword:
3005
          CHAR_SYM '(' expr_list ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3006
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
1 by brian
clean slate
3007
        | CURRENT_USER optional_braces
3008
          {
1351.2.1 by Stewart Smith
move USER() function into a plugin (loaded by default). Also, remove the special case (and completely untested) CURRENT_USER() function and just have it also point to USER(). If somebody wants CURRENT_USER() style behaviour they can add it back in with a test.
3009
            std::string user_str("user");
1578.6.12 by Brian Aker
Additional current_session removal
3010
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
1351.2.1 by Stewart Smith
move USER() function into a plugin (loaded by default). Also, remove the special case (and completely untested) CURRENT_USER() function and just have it also point to USER(). If somebody wants CURRENT_USER() style behaviour they can add it back in with a test.
3011
            {
3012
              DRIZZLE_YYABORT;
3013
            }
1643.6.13 by Djellel E. Difallah
adding tests
3014
            Lex->setCacheable(false);
1 by brian
clean slate
3015
          }
3016
        | DATE_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3017
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
1 by brian
clean slate
3018
        | DAY_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3019
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
1 by brian
clean slate
3020
        | HOUR_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3021
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
1 by brian
clean slate
3022
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
1633.4.5 by Brian Aker
More current_session.
3023
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
1 by brian
clean slate
3024
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3025
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3026
            Session *session= YYSession;
3027
            List<Item> *list= new (session->mem_root) List<Item>;
1 by brian
clean slate
3028
            list->push_front($5);
3029
            list->push_front($3);
520.1.22 by Brian Aker
Second pass of thd cleanup
3030
            Item_row *item= new (session->mem_root) Item_row(*list);
3031
            $$= new (session->mem_root) Item_func_interval(item);
1 by brian
clean slate
3032
          }
3033
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3034
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3035
            Session *session= YYSession;
1 by brian
clean slate
3036
            $7->push_front($5);
3037
            $7->push_front($3);
520.1.22 by Brian Aker
Second pass of thd cleanup
3038
            Item_row *item= new (session->mem_root) Item_row(*$7);
3039
            $$= new (session->mem_root) Item_func_interval(item);
1 by brian
clean slate
3040
          }
3041
        | LEFT '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3042
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
1 by brian
clean slate
3043
        | MINUTE_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3044
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
1 by brian
clean slate
3045
        | MONTH_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3046
          { $$= new (YYSession->mem_root) Item_func_month($3); }
1 by brian
clean slate
3047
        | RIGHT '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3048
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
1 by brian
clean slate
3049
        | SECOND_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3050
          { $$= new (YYSession->mem_root) Item_func_second($3); }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
3051
        | TIMESTAMP_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3052
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
1 by brian
clean slate
3053
        | TRIM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3054
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
1 by brian
clean slate
3055
        | TRIM '(' LEADING expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3056
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
1 by brian
clean slate
3057
        | TRIM '(' TRAILING expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3058
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
1 by brian
clean slate
3059
        | TRIM '(' BOTH expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3060
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
1 by brian
clean slate
3061
        | TRIM '(' LEADING FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3062
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
1 by brian
clean slate
3063
        | TRIM '(' TRAILING FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3064
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
1 by brian
clean slate
3065
        | TRIM '(' BOTH FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3066
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
1 by brian
clean slate
3067
        | TRIM '(' expr FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3068
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
1 by brian
clean slate
3069
        | USER '(' ')'
3070
          {
1351.2.1 by Stewart Smith
move USER() function into a plugin (loaded by default). Also, remove the special case (and completely untested) CURRENT_USER() function and just have it also point to USER(). If somebody wants CURRENT_USER() style behaviour they can add it back in with a test.
3071
            std::string user_str("user");
1578.6.12 by Brian Aker
Additional current_session removal
3072
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
1351.2.1 by Stewart Smith
move USER() function into a plugin (loaded by default). Also, remove the special case (and completely untested) CURRENT_USER() function and just have it also point to USER(). If somebody wants CURRENT_USER() style behaviour they can add it back in with a test.
3073
            {
3074
              DRIZZLE_YYABORT;
3075
            }
1643.6.13 by Djellel E. Difallah
adding tests
3076
            Lex->setCacheable(false);
1 by brian
clean slate
3077
          }
3078
        | YEAR_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3079
          { $$= new (YYSession->mem_root) Item_func_year($3); }
1 by brian
clean slate
3080
        ;
3081
3082
/*
3083
  Function calls using non reserved keywords, with special syntaxic forms.
3084
  Dedicated grammar rules are needed because of the syntax,
3085
  but also have the potential to cause incompatibilities with other
3086
  parts of the language.
3087
  MAINTAINER:
3088
  The only reasons a function should be added here are:
3089
  - for compatibility reasons with another SQL syntax (CURDATE),
3090
  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
3091
  discouraged.
3092
*/
3093
function_call_nonkeyword:
3094
          ADDDATE_SYM '(' expr ',' expr ')'
3095
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3096
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
1 by brian
clean slate
3097
                                                             INTERVAL_DAY, 0);
3098
          }
3099
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3100
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
1 by brian
clean slate
3101
        | CURDATE optional_braces
3102
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3103
            $$= new (YYSession->mem_root) Item_func_curdate_local();
1643.6.13 by Djellel E. Difallah
adding tests
3104
            Lex->setCacheable(false);
1 by brian
clean slate
3105
          }
3106
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
520.1.22 by Brian Aker
Second pass of thd cleanup
3107
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
1 by brian
clean slate
3108
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
520.1.22 by Brian Aker
Second pass of thd cleanup
3109
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
1 by brian
clean slate
3110
        | EXTRACT_SYM '(' interval FROM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3111
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
1 by brian
clean slate
3112
        | NOW_SYM optional_braces
3113
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3114
            $$= new (YYSession->mem_root) Item_func_now_local();
1643.6.13 by Djellel E. Difallah
adding tests
3115
            Lex->setCacheable(false);
1 by brian
clean slate
3116
          }
3117
        | NOW_SYM '(' expr ')'
3118
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3119
            $$= new (YYSession->mem_root) Item_func_now_local($3);
1643.6.13 by Djellel E. Difallah
adding tests
3120
            Lex->setCacheable(false);
1 by brian
clean slate
3121
          }
3122
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3123
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
1 by brian
clean slate
3124
        | SUBDATE_SYM '(' expr ',' expr ')'
3125
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3126
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
1 by brian
clean slate
3127
                                                             INTERVAL_DAY, 1);
3128
          }
3129
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3130
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
1 by brian
clean slate
3131
        | SUBSTRING '(' expr ',' expr ',' expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3132
          {
3133
            std::string reverse_str("substr");
3134
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3135
            args->push_back($3);
3136
            args->push_back($5);
3137
            args->push_back($7);
1578.6.12 by Brian Aker
Additional current_session removal
3138
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3139
            {
3140
              DRIZZLE_YYABORT;
3141
            }
3142
          }
1 by brian
clean slate
3143
        | SUBSTRING '(' expr ',' expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3144
          {
3145
            std::string reverse_str("substr");
3146
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3147
            args->push_back($3);
3148
            args->push_back($5);
1578.6.12 by Brian Aker
Additional current_session removal
3149
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3150
            {
3151
              DRIZZLE_YYABORT;
3152
            }
3153
          }
1 by brian
clean slate
3154
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3155
          {
3156
            std::string reverse_str("substr");
3157
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3158
            args->push_back($3);
3159
            args->push_back($5);
3160
            args->push_back($7);
1578.6.12 by Brian Aker
Additional current_session removal
3161
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3162
            {
3163
              DRIZZLE_YYABORT;
3164
            }
3165
          }
1 by brian
clean slate
3166
        | SUBSTRING '(' expr FROM expr ')'
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3167
          {
3168
            std::string reverse_str("substr");
3169
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3170
            args->push_back($3);
3171
            args->push_back($5);
1578.6.12 by Brian Aker
Additional current_session removal
3172
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
1300.4.4 by Stewart Smith
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.
3173
            {
3174
              DRIZZLE_YYABORT;
3175
            }
3176
          }
1 by brian
clean slate
3177
        | SYSDATE optional_braces
1643.6.13 by Djellel E. Difallah
adding tests
3178
          { 
3179
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
3180
            Lex->setCacheable(false);
3181
          }
1 by brian
clean slate
3182
        | SYSDATE '(' expr ')'
1643.6.13 by Djellel E. Difallah
adding tests
3183
          { 
3184
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
3185
            Lex->setCacheable(false);
3186
          }
1 by brian
clean slate
3187
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3188
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
1 by brian
clean slate
3189
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3190
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
1 by brian
clean slate
3191
        | UTC_DATE_SYM optional_braces
3192
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3193
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
1643.6.13 by Djellel E. Difallah
adding tests
3194
            Lex->setCacheable(false);
1 by brian
clean slate
3195
          }
3196
        | UTC_TIMESTAMP_SYM optional_braces
3197
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3198
            $$= new (YYSession->mem_root) Item_func_now_utc();
1643.6.13 by Djellel E. Difallah
adding tests
3199
            Lex->setCacheable(false);
1 by brian
clean slate
3200
          }
3201
        ;
3202
3203
/*
3204
  Functions calls using a non reserved keyword, and using a regular syntax.
3205
  Because the non reserved keyword is used in another part of the grammar,
3206
  a dedicated rule is needed here.
3207
*/
3208
function_call_conflict:
1030.2.5 by devananda
refactored functin/ascii into plugin/ascii
3209
        COALESCE '(' expr_list ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3210
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
1 by brian
clean slate
3211
        | COLLATION_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3212
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
1 by brian
clean slate
3213
        | DATABASE '(' ')'
3214
          {
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
3215
            std::string database_str("database");
1578.6.12 by Brian Aker
Additional current_session removal
3216
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
1300.4.1 by Stewart Smith
move DATABASE() to function plugin. modify parser so that it looks for a function named 'database' when DATABASE() is called. Special case still needed in parser due to hilarity of not-really-reserved words.
3217
            {
3218
              DRIZZLE_YYABORT;
3219
            }
1643.6.13 by Djellel E. Difallah
adding tests
3220
            Lex->setCacheable(false);
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
3221
	  }
1 by brian
clean slate
3222
        | IF '(' expr ',' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3223
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
1 by brian
clean slate
3224
        | MICROSECOND_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3225
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
1 by brian
clean slate
3226
        | MOD_SYM '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3227
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
1 by brian
clean slate
3228
        | QUARTER_SYM '(' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3229
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
1 by brian
clean slate
3230
        | REPEAT_SYM '(' expr ',' expr ')'
1633.4.5 by Brian Aker
More current_session.
3231
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
1 by brian
clean slate
3232
        | REPLACE '(' expr ',' expr ',' expr ')'
1633.4.4 by Brian Aker
Remove more of current_session
3233
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
1 by brian
clean slate
3234
        | REVERSE_SYM '(' expr ')'
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
3235
          {
3236
            std::string reverse_str("reverse");
3237
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3238
            args->push_back($3);
1578.6.12 by Brian Aker
Additional current_session removal
3239
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
1300.4.2 by Stewart Smith
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.
3240
            {
3241
              DRIZZLE_YYABORT;
3242
            }
3243
          }
1 by brian
clean slate
3244
        | TRUNCATE_SYM '(' expr ',' expr ')'
520.1.22 by Brian Aker
Second pass of thd cleanup
3245
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
1 by brian
clean slate
3246
        ;
3247
3248
/*
3249
  Regular function calls.
3250
  The function name is *not* a token, and therefore is guaranteed to not
3251
  introduce side effects to the language in general.
3252
  MAINTAINER:
3253
  All the new functions implemented for new features should fit into
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
3254
  this category.
1 by brian
clean slate
3255
*/
3256
function_call_generic:
3257
          IDENT_sys '('
3258
          {
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
3259
            const plugin::Function *udf= plugin::Function::get($1.str, $1.length);
139.1.8 by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot.
3260
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
3261
            /* Temporary placing the result of getFunction in $3 */
1 by brian
clean slate
3262
            $<udf>$= udf;
3263
          }
3264
          opt_udf_expr_list ')'
3265
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3266
            Session *session= YYSession;
1 by brian
clean slate
3267
            Create_func *builder;
3268
            Item *item= NULL;
3269
3270
            /*
3271
              Implementation note:
3272
              names are resolved with the following order:
3273
              - MySQL native functions,
3274
              - User Defined Functions,
3275
              - Stored Functions (assuming the current <use> database)
3276
3277
              This will be revised with WL#2128 (SQL PATH)
3278
            */
873.2.19 by Monty Taylor
Removed another HASH and another set of useless utf8 hashing.
3279
            builder= find_native_function_builder($1);
1 by brian
clean slate
3280
            if (builder)
3281
            {
520.1.22 by Brian Aker
Second pass of thd cleanup
3282
              item= builder->create(session, $1, $4);
1 by brian
clean slate
3283
            }
3284
            else
3285
            {
1130.1.10 by Monty Taylor
Renamed namespace slot to namespace service.
3286
              /* Retrieving the result of service::Function::get */
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
3287
              const plugin::Function *udf= $<udf>3;
134.1.1 by Mark Atwood
more hackery to get plugin UDFs working
3288
              if (udf)
1 by brian
clean slate
3289
              {
520.1.22 by Brian Aker
Second pass of thd cleanup
3290
                item= Create_udf_func::s_singleton.create(session, udf, $4);
1014.4.7 by Jay Pipes
More documentation of LEX member variables and removal of slave_session_opt unused member variable.
3291
              } else {
258.1.1 by Mark Atwood
fix for bug 250065 from Andrew Garner <muzazzi@gmail.com>
3292
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3293
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
1 by brian
clean slate
3294
              }
3295
            }
3296
3297
            if (! ($$= item))
3298
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3299
              DRIZZLE_YYABORT;
1 by brian
clean slate
3300
            }
1643.6.13 by Djellel E. Difallah
adding tests
3301
            Lex->setCacheable(false);
1 by brian
clean slate
3302
          }
3303
        ;
3304
3305
opt_udf_expr_list:
3306
        /* empty */     { $$= NULL; }
3307
        | udf_expr_list { $$= $1; }
3308
        ;
3309
3310
udf_expr_list:
3311
          udf_expr
3312
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3313
            $$= new (YYSession->mem_root) List<Item>;
1 by brian
clean slate
3314
            $$->push_back($1);
3315
          }
3316
        | udf_expr_list ',' udf_expr
3317
          {
3318
            $1->push_back($3);
3319
            $$= $1;
3320
          }
3321
        ;
3322
3323
udf_expr:
3324
          remember_name expr remember_end select_alias
3325
          {
3326
            /*
3327
             Use Item::name as a storage for the attribute value of user
3328
             defined function argument. It is safe to use Item::name
3329
             because the syntax will not allow having an explicit name here.
3330
             See WL#1017 re. udf attributes.
3331
            */
3332
            if ($4.str)
3333
            {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
3334
              $2->is_autogenerated_name= false;
1 by brian
clean slate
3335
              $2->set_name($4.str, $4.length, system_charset_info);
3336
            }
3337
            else
520.1.22 by Brian Aker
Second pass of thd cleanup
3338
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
1 by brian
clean slate
3339
            $$= $2;
3340
          }
3341
        ;
3342
3343
sum_expr:
3344
          AVG_SYM '(' in_sum_expr ')'
3345
          { $$=new Item_sum_avg($3); }
3346
        | AVG_SYM '(' DISTINCT in_sum_expr ')'
3347
          { $$=new Item_sum_avg_distinct($4); }
3348
        | COUNT_SYM '(' opt_all '*' ')'
205 by Brian Aker
uint32 -> uin32_t
3349
          { $$=new Item_sum_count(new Item_int((int32_t) 0L,1)); }
1 by brian
clean slate
3350
        | COUNT_SYM '(' in_sum_expr ')'
3351
          { $$=new Item_sum_count($3); }
3352
        | COUNT_SYM '(' DISTINCT
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3353
          { Lex->current_select->in_sum_expr++; }
1 by brian
clean slate
3354
          expr_list
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3355
          { Lex->current_select->in_sum_expr--; }
1 by brian
clean slate
3356
          ')'
3357
          { $$=new Item_sum_count_distinct(* $5); }
3358
        | MIN_SYM '(' in_sum_expr ')'
3359
          { $$=new Item_sum_min($3); }
3360
        /*
3361
          According to ANSI SQL, DISTINCT is allowed and has
3362
          no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
3363
          is processed like an ordinary MIN | MAX()
3364
        */
3365
        | MIN_SYM '(' DISTINCT in_sum_expr ')'
3366
          { $$=new Item_sum_min($4); }
3367
        | MAX_SYM '(' in_sum_expr ')'
3368
          { $$=new Item_sum_max($3); }
3369
        | MAX_SYM '(' DISTINCT in_sum_expr ')'
3370
          { $$=new Item_sum_max($4); }
3371
        | STD_SYM '(' in_sum_expr ')'
3372
          { $$=new Item_sum_std($3, 0); }
3373
        | VARIANCE_SYM '(' in_sum_expr ')'
3374
          { $$=new Item_sum_variance($3, 0); }
3375
        | STDDEV_SAMP_SYM '(' in_sum_expr ')'
3376
          { $$=new Item_sum_std($3, 1); }
3377
        | VAR_SAMP_SYM '(' in_sum_expr ')'
3378
          { $$=new Item_sum_variance($3, 1); }
3379
        | SUM_SYM '(' in_sum_expr ')'
3380
          { $$=new Item_sum_sum($3); }
3381
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3382
          { $$=new Item_sum_sum_distinct($4); }
3383
        | GROUP_CONCAT_SYM '(' opt_distinct
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3384
          { Lex->current_select->in_sum_expr++; }
1 by brian
clean slate
3385
          expr_list opt_gorder_clause
3386
          opt_gconcat_separator
3387
          ')'
3388
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3389
            Select_Lex *sel= Lex->current_select;
1 by brian
clean slate
3390
            sel->in_sum_expr--;
3391
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3392
                                          sel->gorder_list, $7);
3393
            $5->empty();
3394
          }
3395
        ;
3396
3397
variable:
3398
          '@'
736 by Brian Aker
Remove dead variables.
3399
          { }
1 by brian
clean slate
3400
          variable_aux
3401
          {
3402
            $$= $3;
3403
          }
3404
        ;
3405
3406
variable_aux:
3407
          ident_or_text SET_VAR expr
3408
          {
3409
            $$= new Item_func_set_user_var($1, $3);
1643.6.13 by Djellel E. Difallah
adding tests
3410
            Lex->setCacheable(false);
1 by brian
clean slate
3411
          }
3412
        | ident_or_text
3413
          {
1633.4.3 by Brian Aker
Remove session usage.
3414
            $$= new Item_func_get_user_var(*YYSession, $1);
1643.6.13 by Djellel E. Difallah
adding tests
3415
            Lex->setCacheable(false);
1 by brian
clean slate
3416
          }
3417
        | '@' opt_var_ident_type ident_or_text opt_component
3418
          {
3419
            /* disallow "SELECT @@global.global.variable" */
3420
            if ($3.str && $4.str && check_reserved_words(&$3))
3421
            {
1578.6.11 by Brian Aker
Additional removal of current_session
3422
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3423
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3424
              DRIZZLE_YYABORT;
1 by brian
clean slate
3425
            }
520.1.22 by Brian Aker
Second pass of thd cleanup
3426
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3427
              DRIZZLE_YYABORT;
1 by brian
clean slate
3428
          }
3429
        ;
3430
3431
opt_distinct:
3432
          /* empty */ { $$ = 0; }
3433
        | DISTINCT    { $$ = 1; }
3434
        ;
3435
3436
opt_gconcat_separator:
3437
          /* empty */
3438
            {
520.1.22 by Brian Aker
Second pass of thd cleanup
3439
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
1 by brian
clean slate
3440
            }
3441
        | SEPARATOR_SYM text_string { $$ = $2; }
3442
        ;
3443
3444
opt_gorder_clause:
3445
          /* empty */
3446
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3447
            Lex->current_select->gorder_list = NULL;
1 by brian
clean slate
3448
          }
3449
        | order_clause
3450
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3451
            Select_Lex *select= Lex->current_select;
1 by brian
clean slate
3452
            select->gorder_list=
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
3453
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
1 by brian
clean slate
3454
                                     sizeof(st_sql_list));
3455
            select->order_list.empty();
3456
          }
3457
        ;
3458
3459
in_sum_expr:
3460
          opt_all
3461
          {
3462
            LEX *lex= Lex;
3463
            if (lex->current_select->inc_in_sum_expr())
3464
            {
1578.6.11 by Brian Aker
Additional removal of current_session
3465
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3466
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3467
              DRIZZLE_YYABORT;
1 by brian
clean slate
3468
            }
3469
          }
3470
          expr
3471
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3472
            Lex->current_select->in_sum_expr--;
1 by brian
clean slate
3473
            $$= $3;
3474
          }
3475
        ;
3476
3477
cast_type:
3478
          BINARY opt_len
3479
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
1217 by Brian Aker
Removed bits of charset support from the parser.
3480
        | CHAR_SYM opt_len
1 by brian
clean slate
3481
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3482
        | DATE_SYM
3483
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
3484
        | DATETIME_SYM
1 by brian
clean slate
3485
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3486
        | DECIMAL_SYM float_options
3487
          { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
3488
        ;
3489
3490
expr_list:
3491
          expr
3492
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
3493
            $$= new (YYSession->mem_root) List<Item>;
1 by brian
clean slate
3494
            $$->push_back($1);
3495
          }
3496
        | expr_list ',' expr
3497
          {
3498
            $1->push_back($3);
3499
            $$= $1;
3500
          }
3501
        ;
3502
3503
opt_expr:
3504
          /* empty */    { $$= NULL; }
3505
        | expr           { $$= $1; }
3506
        ;
3507
3508
opt_else:
3509
          /* empty */  { $$= NULL; }
3510
        | ELSE expr    { $$= $2; }
3511
        ;
3512
3513
when_list:
3514
          WHEN_SYM expr THEN_SYM expr
3515
          {
3516
            $$= new List<Item>;
3517
            $$->push_back($2);
3518
            $$->push_back($4);
3519
          }
3520
        | when_list WHEN_SYM expr THEN_SYM expr
3521
          {
3522
            $1->push_back($3);
3523
            $1->push_back($5);
3524
            $$= $1;
3525
          }
3526
        ;
3527
3528
/* Equivalent to <table reference> in the SQL:2003 standard. */
3529
/* Warning - may return NULL in case of incomplete SELECT */
3530
table_ref:
3531
          table_factor { $$=$1; }
3532
        | join_table
3533
          {
3534
            LEX *lex= Lex;
520.1.22 by Brian Aker
Second pass of thd cleanup
3535
            if (!($$= lex->current_select->nest_last_join(lex->session)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3536
              DRIZZLE_YYABORT;
1 by brian
clean slate
3537
          }
3538
        ;
3539
3540
join_table_list:
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3541
          derived_table_list { DRIZZLE_YYABORT_UNLESS($$=$1); }
1 by brian
clean slate
3542
        ;
3543
3544
/*
3545
  The ODBC escape syntax for Outer Join is: '{' OJ join_table '}'
3546
  The parser does not define OJ as a token, any ident is accepted
3547
  instead in $2 (ident). Also, all productions from table_ref can
3548
  be escaped, not only join_table. Both syntax extensions are safe
3549
  and are ignored.
3550
*/
3551
esc_table_ref:
3552
        table_ref { $$=$1; }
3553
      | '{' ident table_ref '}' { $$=$3; }
3554
      ;
3555
3556
/* Equivalent to <table reference list> in the SQL:2003 standard. */
3557
/* Warning - may return NULL in case of incomplete SELECT */
3558
derived_table_list:
3559
          esc_table_ref { $$=$1; }
3560
        | derived_table_list ',' esc_table_ref
3561
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3562
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
1 by brian
clean slate
3563
          }
3564
        ;
3565
3566
/*
3567
  Notice that JOIN is a left-associative operation, and it must be parsed
3568
  as such, that is, the parser must process first the left join operand
3569
  then the right one. Such order of processing ensures that the parser
3570
  produces correct join trees which is essential for semantic analysis
3571
  and subsequent optimization phases.
3572
*/
3573
join_table:
3574
          /* INNER JOIN variants */
3575
          /*
3576
            Use %prec to evaluate production 'table_ref' before 'normal_join'
3577
            so that [INNER | CROSS] JOIN is properly nested as other
3578
            left-associative joins.
3579
          */
3580
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3581
          { 
3582
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
3583
            Lex->is_cross= false;
3584
          }
1 by brian
clean slate
3585
        | table_ref STRAIGHT_JOIN table_factor
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3586
          { 
3587
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
3588
          }
1 by brian
clean slate
3589
        | table_ref normal_join table_ref
3590
          ON
3591
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3592
            DRIZZLE_YYABORT_UNLESS($1 && $3);
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3593
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
1 by brian
clean slate
3594
            /* Change the current name resolution context to a local context. */
520.1.22 by Brian Aker
Second pass of thd cleanup
3595
            if (push_new_name_resolution_context(YYSession, $1, $3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3596
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3597
            Lex->current_select->parsing_place= IN_ON;
1 by brian
clean slate
3598
          }
3599
          expr
3600
          {
3601
            add_join_on($3,$6);
3602
            Lex->pop_context();
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3603
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3604
          }
3605
        | table_ref STRAIGHT_JOIN table_factor
3606
          ON
3607
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3608
            DRIZZLE_YYABORT_UNLESS($1 && $3);
1 by brian
clean slate
3609
            /* Change the current name resolution context to a local context. */
520.1.22 by Brian Aker
Second pass of thd cleanup
3610
            if (push_new_name_resolution_context(YYSession, $1, $3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3611
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3612
            Lex->current_select->parsing_place= IN_ON;
1 by brian
clean slate
3613
          }
3614
          expr
3615
          {
3616
            $3->straight=1;
3617
            add_join_on($3,$6);
3618
            Lex->pop_context();
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3619
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3620
          }
3621
        | table_ref normal_join table_ref
3622
          USING
3623
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3624
            DRIZZLE_YYABORT_UNLESS($1 && $3);
1 by brian
clean slate
3625
          }
3626
          '(' using_list ')'
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3627
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
1 by brian
clean slate
3628
        | table_ref NATURAL JOIN_SYM table_factor
3629
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3630
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3631
            add_join_natural($1,$4,NULL,Lex->current_select);
1 by brian
clean slate
3632
          }
3633
3634
          /* LEFT JOIN variants */
3635
        | table_ref LEFT opt_outer JOIN_SYM table_ref
3636
          ON
3637
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3638
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3639
            /* Change the current name resolution context to a local context. */
520.1.22 by Brian Aker
Second pass of thd cleanup
3640
            if (push_new_name_resolution_context(YYSession, $1, $5))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3641
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3642
            Lex->current_select->parsing_place= IN_ON;
1 by brian
clean slate
3643
          }
3644
          expr
3645
          {
3646
            add_join_on($5,$8);
3647
            Lex->pop_context();
3648
            $5->outer_join|=JOIN_TYPE_LEFT;
3649
            $$=$5;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3650
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3651
          }
3652
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3653
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3654
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3655
          }
3656
          USING '(' using_list ')'
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3657
          {
3658
            add_join_natural($1,$5,$9,Lex->current_select);
3659
            $5->outer_join|=JOIN_TYPE_LEFT;
3660
            $$=$5;
1 by brian
clean slate
3661
          }
3662
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3663
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3664
            DRIZZLE_YYABORT_UNLESS($1 && $6);
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3665
            add_join_natural($1,$6,NULL,Lex->current_select);
1 by brian
clean slate
3666
            $6->outer_join|=JOIN_TYPE_LEFT;
3667
            $$=$6;
3668
          }
3669
3670
          /* RIGHT JOIN variants */
3671
        | table_ref RIGHT opt_outer JOIN_SYM table_ref
3672
          ON
3673
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3674
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3675
            /* Change the current name resolution context to a local context. */
520.1.22 by Brian Aker
Second pass of thd cleanup
3676
            if (push_new_name_resolution_context(YYSession, $1, $5))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3677
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3678
            Lex->current_select->parsing_place= IN_ON;
1 by brian
clean slate
3679
          }
3680
          expr
3681
          {
3682
            LEX *lex= Lex;
3683
            if (!($$= lex->current_select->convert_right_join()))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3684
              DRIZZLE_YYABORT;
1 by brian
clean slate
3685
            add_join_on($$, $8);
3686
            Lex->pop_context();
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3687
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3688
          }
3689
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3690
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3691
            DRIZZLE_YYABORT_UNLESS($1 && $5);
1 by brian
clean slate
3692
          }
3693
          USING '(' using_list ')'
3694
          {
3695
            LEX *lex= Lex;
3696
            if (!($$= lex->current_select->convert_right_join()))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3697
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3698
            add_join_natural($$,$5,$9,Lex->current_select);
1 by brian
clean slate
3699
          }
3700
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3701
          {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3702
            DRIZZLE_YYABORT_UNLESS($1 && $6);
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3703
            add_join_natural($6,$1,NULL,Lex->current_select);
1 by brian
clean slate
3704
            LEX *lex= Lex;
3705
            if (!($$= lex->current_select->convert_right_join()))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3706
              DRIZZLE_YYABORT;
1 by brian
clean slate
3707
          }
3708
        ;
3709
3710
normal_join:
3711
          JOIN_SYM {}
3712
        | INNER_SYM JOIN_SYM {}
1637.1.3 by Brian Aker
This fixes the parser to no longer do the bad syntax around the cross join
3713
        | CROSS JOIN_SYM { Lex->is_cross= true; }
1 by brian
clean slate
3714
        ;
3715
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3716
/*
1 by brian
clean slate
3717
   This is a flattening of the rules <table factor> and <table primary>
3718
   in the SQL:2003 standard, since we don't have <sample clause>
3719
3720
   I.e.
3721
   <table factor> ::= <table primary> [ <sample clause> ]
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3722
*/  
1 by brian
clean slate
3723
/* Warning - may return NULL in case of incomplete SELECT */
3724
table_factor:
3725
          {
3726
          }
3727
          table_ident opt_table_alias opt_key_definition
3728
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3729
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
1858.1.2 by Padraig O'Sullivan
Converted another uint8_t type to be a bitset.
3730
                             0,
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3731
                             Lex->lock_option,
3732
                             Lex->current_select->pop_index_hints())))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3733
              DRIZZLE_YYABORT;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3734
            Lex->current_select->add_joined_table($$);
1 by brian
clean slate
3735
          }
3736
        | select_derived_init get_select_lex select_derived2
3737
          {
3738
            LEX *lex= Lex;
846 by Brian Aker
Removing on typedeffed class.
3739
            Select_Lex *sel= lex->current_select;
1 by brian
clean slate
3740
            if ($1)
3741
            {
3742
              if (sel->set_braces(1))
3743
              {
1578.6.11 by Brian Aker
Additional removal of current_session
3744
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3745
                my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3746
                DRIZZLE_YYABORT;
1 by brian
clean slate
3747
              }
3748
              /* select in braces, can't contain global parameters */
3749
              if (sel->master_unit()->fake_select_lex)
3750
                sel->master_unit()->global_parameters=
3751
                   sel->master_unit()->fake_select_lex;
3752
            }
520.1.22 by Brian Aker
Second pass of thd cleanup
3753
            if ($2->init_nested_join(lex->session))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3754
              DRIZZLE_YYABORT;
1 by brian
clean slate
3755
            $$= 0;
3756
            /* incomplete derived tables return NULL, we must be
3757
               nested in select_derived rule to be here. */
3758
          }
3759
          /*
3760
            Represents a flattening of the following rules from the SQL:2003
3761
            standard. This sub-rule corresponds to the sub-rule
3762
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3763
           
1 by brian
clean slate
3764
            The following rules have been flattened into query_expression_body
3765
            (since we have no <with clause>).
3766
3767
            <derived table> ::= <table subquery>
3768
            <table subquery> ::= <subquery>
3769
            <subquery> ::= <left paren> <query expression> <right paren>
3770
            <query expression> ::= [ <with clause> ] <query expression body>
3771
3772
            For the time being we use the non-standard rule
3773
            select_derived_union which is a compromise between the standard
3774
            and our parser. Possibly this rule could be replaced by our
3775
            query_expression_body.
3776
          */
3777
        | '(' get_select_lex select_derived_union ')' opt_table_alias
3778
          {
3779
            /* Use $2 instead of Lex->current_select as derived table will
3780
               alter value of Lex->current_select. */
3781
            if (!($3 || $5) && $2->embedding &&
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
3782
                !$2->embedding->getNestedJoin()->join_list.elements)
1 by brian
clean slate
3783
            {
3784
              /* we have a derived table ($3 == NULL) but no alias,
3785
                 Since we are nested in further parentheses so we
3786
                 can pass NULL to the outer level parentheses
3787
                 Permits parsing of "((((select ...))) as xyz)" */
3788
              $$= 0;
3789
            }
3790
            else if (!$3)
3791
            {
3792
              /* Handle case of derived table, alias may be NULL if there
3793
                 are no outer parentheses, add_table_to_list() will throw
3794
                 error in this case */
3795
              LEX *lex=Lex;
846 by Brian Aker
Removing on typedeffed class.
3796
              Select_Lex *sel= lex->current_select;
849 by Brian Aker
Remove dead keywords.
3797
              Select_Lex_Unit *unit= sel->master_unit();
1 by brian
clean slate
3798
              lex->current_select= sel= unit->outer_select();
520.1.22 by Brian Aker
Second pass of thd cleanup
3799
              if (!($$= sel->add_table_to_list(lex->session,
1 by brian
clean slate
3800
                                               new Table_ident(unit), $5, 0,
3801
                                               TL_READ)))
3802
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3803
                DRIZZLE_YYABORT;
1 by brian
clean slate
3804
              sel->add_joined_table($$);
3805
              lex->pop_context();
3806
            }
3807
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3808
            {
3809
              /* simple nested joins cannot have aliases or unions */
1578.6.11 by Brian Aker
Additional removal of current_session
3810
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3811
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3812
              DRIZZLE_YYABORT;
1 by brian
clean slate
3813
            }
3814
            else
3815
              $$= $3;
3816
          }
3817
        ;
3818
3819
select_derived_union:
3820
          select_derived opt_order_clause opt_limit_clause
3821
        | select_derived_union
3822
          UNION_SYM
3823
          union_option
3824
          {
1578.6.11 by Brian Aker
Additional removal of current_session
3825
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3826
              DRIZZLE_YYABORT;
1 by brian
clean slate
3827
          }
3828
          query_specification
3829
          {
3830
            /*
3831
              Remove from the name resolution context stack the context of the
3832
              last select in the union.
3833
             */
3834
            Lex->pop_context();
3835
          }
3836
          opt_order_clause opt_limit_clause
3837
        ;
3838
3839
/* The equivalent of select_init2 for nested queries. */
3840
select_init2_derived:
3841
          select_part2_derived
3842
          {
3843
            LEX *lex= Lex;
846 by Brian Aker
Removing on typedeffed class.
3844
            Select_Lex * sel= lex->current_select;
1 by brian
clean slate
3845
            if (lex->current_select->set_braces(0))
3846
            {
1578.6.11 by Brian Aker
Additional removal of current_session
3847
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3848
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3849
              DRIZZLE_YYABORT;
1 by brian
clean slate
3850
            }
3851
            if (sel->linkage == UNION_TYPE &&
3852
                sel->master_unit()->first_select()->braces)
3853
            {
1578.6.11 by Brian Aker
Additional removal of current_session
3854
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3855
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3856
              DRIZZLE_YYABORT;
1 by brian
clean slate
3857
            }
3858
          }
3859
        ;
3860
3861
/* The equivalent of select_part2 for nested queries. */
3862
select_part2_derived:
3863
          {
3864
            LEX *lex= Lex;
846 by Brian Aker
Removing on typedeffed class.
3865
            Select_Lex *sel= lex->current_select;
1 by brian
clean slate
3866
            if (sel->linkage != UNION_TYPE)
3867
              mysql_init_select(lex);
3868
            lex->current_select->parsing_place= SELECT_LIST;
3869
          }
3870
          select_options select_item_list
3871
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3872
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3873
          }
3874
          opt_select_from select_lock_type
3875
        ;
3876
3877
/* handle contents of parentheses in join expression */
3878
select_derived:
3879
          get_select_lex
3880
          {
3881
            LEX *lex= Lex;
520.1.22 by Brian Aker
Second pass of thd cleanup
3882
            if ($1->init_nested_join(lex->session))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3883
              DRIZZLE_YYABORT;
1 by brian
clean slate
3884
          }
3885
          derived_table_list
3886
          {
3887
            LEX *lex= Lex;
3888
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3889
               for derived tables, both must equal NULL */
3890
520.1.22 by Brian Aker
Second pass of thd cleanup
3891
            if (!($$= $1->end_nested_join(lex->session)) && $3)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3892
              DRIZZLE_YYABORT;
1 by brian
clean slate
3893
            if (!$3 && $$)
3894
            {
1578.6.11 by Brian Aker
Additional removal of current_session
3895
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3896
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3897
              DRIZZLE_YYABORT;
1 by brian
clean slate
3898
            }
3899
          }
3900
        ;
3901
3902
select_derived2:
3903
          {
3904
            LEX *lex= Lex;
3905
            lex->derived_tables|= DERIVED_SUBQUERY;
798.2.10 by Brian Aker
Remove COM bits for replication
3906
            if (!lex->expr_allows_subselect)
1 by brian
clean slate
3907
            {
1578.6.11 by Brian Aker
Additional removal of current_session
3908
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3909
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3910
              DRIZZLE_YYABORT;
1 by brian
clean slate
3911
            }
3912
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
3913
                mysql_new_select(lex, 1))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3914
              DRIZZLE_YYABORT;
1 by brian
clean slate
3915
            mysql_init_select(lex);
3916
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
3917
            lex->current_select->parsing_place= SELECT_LIST;
3918
          }
3919
          select_options select_item_list
3920
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3921
            Lex->current_select->parsing_place= NO_MATTER;
1 by brian
clean slate
3922
          }
3923
          opt_select_from
3924
        ;
3925
3926
get_select_lex:
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3927
          /* Empty */ { $$= Lex->current_select; }
1 by brian
clean slate
3928
        ;
3929
3930
select_derived_init:
3931
          SELECT_SYM
3932
          {
3933
            LEX *lex= Lex;
3934
846 by Brian Aker
Removing on typedeffed class.
3935
            Select_Lex *sel= lex->current_select;
327.2.5 by Brian Aker
Refactoring show command
3936
            TableList *embedding;
520.1.22 by Brian Aker
Second pass of thd cleanup
3937
            if (!sel->embedding || sel->end_nested_join(lex->session))
1 by brian
clean slate
3938
            {
3939
              /* we are not in parentheses */
1578.6.11 by Brian Aker
Additional removal of current_session
3940
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3941
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3942
              DRIZZLE_YYABORT;
1 by brian
clean slate
3943
            }
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3944
            embedding= Lex->current_select->embedding;
1 by brian
clean slate
3945
            $$= embedding &&
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
3946
                !embedding->getNestedJoin()->join_list.elements;
1 by brian
clean slate
3947
            /* return true if we are deeply nested */
3948
          }
3949
        ;
3950
3951
opt_outer:
3952
          /* empty */ {}
3953
        | OUTER {}
3954
        ;
3955
3956
index_hint_clause:
3957
          /* empty */
3958
          {
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3959
            $$= INDEX_HINT_MASK_ALL;
1 by brian
clean slate
3960
          }
3961
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
3962
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
3963
        | FOR_SYM GROUP_SYM BY  { $$= INDEX_HINT_MASK_GROUP; }
3964
        ;
3965
3966
index_hint_type:
3967
          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
3968
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
1 by brian
clean slate
3969
        ;
3970
3971
index_hint_definition:
3972
          index_hint_type key_or_index index_hint_clause
3973
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3974
            Lex->current_select->set_index_hint_type($1, $3);
1 by brian
clean slate
3975
          }
3976
          '(' key_usage_list ')'
3977
        | USE_SYM key_or_index index_hint_clause
3978
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3979
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
1 by brian
clean slate
3980
          }
3981
          '(' opt_key_usage_list ')'
3982
       ;
3983
3984
index_hints_list:
3985
          index_hint_definition
3986
        | index_hints_list index_hint_definition
3987
        ;
3988
3989
opt_index_hints_list:
3990
          /* empty */
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3991
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
1 by brian
clean slate
3992
        ;
3993
3994
opt_key_definition:
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
3995
          {  Lex->current_select->clear_index_hints(); }
1 by brian
clean slate
3996
          opt_index_hints_list
3997
        ;
3998
3999
opt_key_usage_list:
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4000
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
1 by brian
clean slate
4001
        | key_usage_list {}
4002
        ;
4003
4004
key_usage_element:
4005
          ident
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4006
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
1 by brian
clean slate
4007
        | PRIMARY_SYM
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4008
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
1 by brian
clean slate
4009
        ;
4010
4011
key_usage_list:
4012
          key_usage_element
4013
        | key_usage_list ',' key_usage_element
4014
        ;
4015
4016
using_list:
4017
          ident
4018
          {
4019
            if (!($$= new List<String>))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4020
              DRIZZLE_YYABORT;
520.1.22 by Brian Aker
Second pass of thd cleanup
4021
            $$->push_back(new (YYSession->mem_root)
1 by brian
clean slate
4022
                              String((const char *) $1.str, $1.length,
4023
                                      system_charset_info));
4024
          }
4025
        | using_list ',' ident
4026
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
4027
            $1->push_back(new (YYSession->mem_root)
1 by brian
clean slate
4028
                              String((const char *) $3.str, $3.length,
4029
                                      system_charset_info));
4030
            $$= $1;
4031
          }
4032
        ;
4033
4034
interval:
4035
          interval_time_st {}
4036
        | DAY_HOUR_SYM           { $$=INTERVAL_DAY_HOUR; }
4037
        | DAY_MICROSECOND_SYM    { $$=INTERVAL_DAY_MICROSECOND; }
4038
        | DAY_MINUTE_SYM         { $$=INTERVAL_DAY_MINUTE; }
4039
        | DAY_SECOND_SYM         { $$=INTERVAL_DAY_SECOND; }
4040
        | HOUR_MICROSECOND_SYM   { $$=INTERVAL_HOUR_MICROSECOND; }
4041
        | HOUR_MINUTE_SYM        { $$=INTERVAL_HOUR_MINUTE; }
4042
        | HOUR_SECOND_SYM        { $$=INTERVAL_HOUR_SECOND; }
4043
        | MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
4044
        | MINUTE_SECOND_SYM      { $$=INTERVAL_MINUTE_SECOND; }
4045
        | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
4046
        | YEAR_MONTH_SYM         { $$=INTERVAL_YEAR_MONTH; }
4047
        ;
4048
4049
interval_time_stamp:
4050
	interval_time_st	{}
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4051
	| FRAC_SECOND_SYM	{
4052
                                  $$=INTERVAL_MICROSECOND;
1 by brian
clean slate
4053
                                  /*
4054
                                    FRAC_SECOND was mistakenly implemented with
4055
                                    a wrong resolution. According to the ODBC
4056
                                    standard it should be nanoseconds, not
4057
                                    microseconds. Changing it to nanoseconds
4058
                                    in MySQL would mean making TIMESTAMPDIFF
4059
                                    and TIMESTAMPADD to return DECIMAL, since
4060
                                    the return value would be too big for BIGINT
4061
                                    Hence we just deprecate the incorrect
4062
                                    implementation without changing its
4063
                                    resolution.
4064
                                  */
4065
                                }
4066
	;
4067
4068
interval_time_st:
4069
          DAY_SYM         { $$=INTERVAL_DAY; }
4070
        | WEEK_SYM        { $$=INTERVAL_WEEK; }
4071
        | HOUR_SYM        { $$=INTERVAL_HOUR; }
4072
        | MINUTE_SYM      { $$=INTERVAL_MINUTE; }
4073
        | MONTH_SYM       { $$=INTERVAL_MONTH; }
4074
        | QUARTER_SYM     { $$=INTERVAL_QUARTER; }
4075
        | SECOND_SYM      { $$=INTERVAL_SECOND; }
4076
        | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
4077
        | YEAR_SYM        { $$=INTERVAL_YEAR; }
4078
        ;
4079
4080
table_alias:
4081
          /* empty */
4082
        | AS
4083
        | EQ
4084
        ;
4085
4086
opt_table_alias:
4087
          /* empty */ { $$=0; }
4088
        | table_alias ident
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
4089
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
1 by brian
clean slate
4090
        ;
4091
4092
opt_all:
4093
          /* empty */
4094
        | ALL
4095
        ;
4096
4097
where_clause:
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4098
          /* empty */  { Lex->current_select->where= 0; }
1 by brian
clean slate
4099
        | WHERE
4100
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4101
            Lex->current_select->parsing_place= IN_WHERE;
1 by brian
clean slate
4102
          }
4103
          expr
4104
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4105
            Select_Lex *select= Lex->current_select;
1 by brian
clean slate
4106
            select->where= $3;
4107
            select->parsing_place= NO_MATTER;
4108
            if ($3)
4109
              $3->top_level_item();
4110
          }
4111
        ;
4112
4113
having_clause:
4114
          /* empty */
4115
        | HAVING
4116
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4117
            Lex->current_select->parsing_place= IN_HAVING;
1 by brian
clean slate
4118
          }
4119
          expr
4120
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4121
            Select_Lex *sel= Lex->current_select;
1 by brian
clean slate
4122
            sel->having= $3;
4123
            sel->parsing_place= NO_MATTER;
4124
            if ($3)
4125
              $3->top_level_item();
4126
          }
4127
        ;
4128
4129
opt_escape:
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4130
          ESCAPE_SYM simple_expr
1 by brian
clean slate
4131
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
4132
            Lex->escape_used= true;
1 by brian
clean slate
4133
            $$= $2;
4134
          }
4135
        | /* empty */
4136
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
4137
            Lex->escape_used= false;
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
4138
            $$= new Item_string("\\", 1, &my_charset_utf8_general_ci);
1 by brian
clean slate
4139
          }
4140
        ;
4141
4142
/*
4143
   group by statement in select
4144
*/
4145
4146
group_clause:
4147
          /* empty */
4148
        | GROUP_SYM BY group_list olap_opt
4149
        ;
4150
4151
group_list:
4152
          group_list ',' order_ident order_dir
838 by Brian Aker
More class adoption/method
4153
          { if (YYSession->add_group_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
1 by brian
clean slate
4154
        | order_ident order_dir
838 by Brian Aker
More class adoption/method
4155
          { if (YYSession->add_group_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
1 by brian
clean slate
4156
        ;
4157
4158
olap_opt:
4159
          /* empty */ {}
4160
        | WITH_ROLLUP_SYM
4161
          {
4162
            /*
4163
              'WITH ROLLUP' is needed for backward compatibility,
4164
              and cause LALR(2) conflicts.
4165
              This syntax is not standard.
4166
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
4167
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
4168
            */
4169
            LEX *lex= Lex;
4170
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4171
            {
4172
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
4173
                       "global union parameters");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4174
              DRIZZLE_YYABORT;
1 by brian
clean slate
4175
            }
4176
            lex->current_select->olap= ROLLUP_TYPE;
4177
          }
4178
        ;
4179
4180
/*
4181
  Order by statement in ALTER TABLE
4182
*/
4183
4184
alter_order_clause:
4185
          ORDER_SYM BY alter_order_list
4186
        ;
4187
4188
alter_order_list:
4189
          alter_order_list ',' alter_order_item
4190
        | alter_order_item
4191
        ;
4192
4193
alter_order_item:
4194
          simple_ident_nospvar order_dir
4195
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
4196
            Session *session= YYSession;
1 by brian
clean slate
4197
            bool ascending= ($2 == 1) ? true : false;
838 by Brian Aker
More class adoption/method
4198
            if (session->add_order_to_list($1, ascending))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4199
              DRIZZLE_YYABORT;
1 by brian
clean slate
4200
          }
4201
        ;
4202
4203
/*
4204
   Order by statement in select
4205
*/
4206
4207
opt_order_clause:
4208
          /* empty */
4209
        | order_clause
4210
        ;
4211
4212
order_clause:
4213
          ORDER_SYM BY
4214
          {
4215
            LEX *lex=Lex;
846 by Brian Aker
Removing on typedeffed class.
4216
            Select_Lex *sel= lex->current_select;
849 by Brian Aker
Remove dead keywords.
4217
            Select_Lex_Unit *unit= sel-> master_unit();
1 by brian
clean slate
4218
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4219
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
4220
                (sel->linkage != UNION_TYPE || sel->braces))
4221
            {
4222
              my_error(ER_WRONG_USAGE, MYF(0),
4223
                       "CUBE/ROLLUP", "ORDER BY");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4224
              DRIZZLE_YYABORT;
1 by brian
clean slate
4225
            }
4226
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
4227
            {
4228
              /*
4229
                A query of the of the form (SELECT ...) ORDER BY order_list is
4230
                executed in the same way as the query
4231
                SELECT ... ORDER BY order_list
4232
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
846 by Brian Aker
Removing on typedeffed class.
4233
                Otherwise we create a fake Select_Lex if it has not been created
1 by brian
clean slate
4234
                yet.
4235
              */
846 by Brian Aker
Removing on typedeffed class.
4236
              Select_Lex *first_sl= unit->first_select();
1 by brian
clean slate
4237
              if (!unit->is_union() &&
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4238
                  (first_sl->order_list.elements ||
4239
                   first_sl->select_limit) &&           
520.1.22 by Brian Aker
Second pass of thd cleanup
4240
                  unit->add_fake_select_lex(lex->session))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4241
                DRIZZLE_YYABORT;
1 by brian
clean slate
4242
            }
4243
          }
4244
          order_list
4245
        ;
4246
4247
order_list:
4248
          order_list ',' order_ident order_dir
838 by Brian Aker
More class adoption/method
4249
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
1 by brian
clean slate
4250
        | order_ident order_dir
838 by Brian Aker
More class adoption/method
4251
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
1 by brian
clean slate
4252
        ;
4253
4254
order_dir:
4255
          /* empty */ { $$ =  1; }
4256
        | ASC  { $$ =1; }
4257
        | DESC { $$ =0; }
4258
        ;
4259
4260
opt_limit_clause_init:
4261
          /* empty */
4262
          {
4263
            LEX *lex= Lex;
846 by Brian Aker
Removing on typedeffed class.
4264
            Select_Lex *sel= lex->current_select;
1 by brian
clean slate
4265
            sel->offset_limit= 0;
4266
            sel->select_limit= 0;
4267
          }
4268
        | limit_clause {}
4269
        ;
4270
4271
opt_limit_clause:
4272
          /* empty */ {}
4273
        | limit_clause {}
4274
        ;
4275
4276
limit_clause:
4277
          LIMIT limit_options {}
4278
        ;
4279
4280
limit_options:
4281
          limit_option
4282
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4283
            Select_Lex *sel= Lex->current_select;
1 by brian
clean slate
4284
            sel->select_limit= $1;
4285
            sel->offset_limit= 0;
4286
            sel->explicit_limit= 1;
4287
          }
4288
        | limit_option ',' limit_option
4289
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4290
            Select_Lex *sel= Lex->current_select;
1 by brian
clean slate
4291
            sel->select_limit= $3;
4292
            sel->offset_limit= $1;
4293
            sel->explicit_limit= 1;
4294
          }
4295
        | limit_option OFFSET_SYM limit_option
4296
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4297
            Select_Lex *sel= Lex->current_select;
1 by brian
clean slate
4298
            sel->select_limit= $1;
4299
            sel->offset_limit= $3;
4300
            sel->explicit_limit= 1;
4301
          }
4302
        ;
4303
4304
limit_option:
177.1.5 by brian
Removed dead ? operator.
4305
          ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
1 by brian
clean slate
4306
        | LONG_NUM      { $$= new Item_uint($1.str, $1.length); }
4307
        | NUM           { $$= new Item_uint($1.str, $1.length); }
4308
        ;
4309
4310
delete_limit_clause:
4311
          /* empty */
4312
          {
4313
            LEX *lex=Lex;
4314
            lex->current_select->select_limit= 0;
4315
          }
4316
        | LIMIT limit_option
4317
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4318
            Select_Lex *sel= Lex->current_select;
1 by brian
clean slate
4319
            sel->select_limit= $2;
4320
            sel->explicit_limit= 1;
4321
          }
4322
        ;
4323
4324
ulong_num:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
4325
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
1 by brian
clean slate
4326
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
4327
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4328
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4329
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4330
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
1 by brian
clean slate
4331
        ;
4332
4333
ulonglong_num:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
4334
          NUM           { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4335
        | ULONGLONG_NUM { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4336
        | LONG_NUM      { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4337
        | DECIMAL_NUM   { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4338
        | FLOAT_NUM     { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
1 by brian
clean slate
4339
        ;
4340
4341
select_var_list_init:
4342
          {
4343
            LEX *lex=Lex;
4344
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4345
              DRIZZLE_YYABORT;
1 by brian
clean slate
4346
          }
4347
          select_var_list
4348
          {}
4349
        ;
4350
4351
select_var_list:
4352
          select_var_list ',' select_var_ident
4353
        | select_var_ident {}
4354
        ;
4355
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4356
select_var_ident: 
1 by brian
clean slate
4357
          '@' ident_or_text
4358
          {
4359
            LEX *lex=Lex;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4360
            if (lex->result)
1410.3.4 by Djellel E. Difallah
update references to old my_'s
4361
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
1 by brian
clean slate
4362
            else
4363
              /*
4364
                The parser won't create select_result instance only
4365
                if it's an EXPLAIN.
4366
              */
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
4367
              assert(lex->describe);
1 by brian
clean slate
4368
          }
4369
        ;
4370
4371
into:
4372
          INTO
736 by Brian Aker
Remove dead variables.
4373
          { }
1 by brian
clean slate
4374
          into_destination
4375
        ;
4376
4377
into_destination:
4378
          OUTFILE TEXT_STRING_filesystem
4379
          {
4380
            LEX *lex= Lex;
1643.6.13 by Djellel E. Difallah
adding tests
4381
            lex->setCacheable(false);
831.1.2 by Brian Aker
Rename class file_exchange
4382
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
1 by brian
clean slate
4383
                !(lex->result= new select_export(lex->exchange)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4384
              DRIZZLE_YYABORT;
1 by brian
clean slate
4385
          }
4386
          opt_field_term opt_line_term
4387
        | DUMPFILE TEXT_STRING_filesystem
4388
          {
4389
            LEX *lex=Lex;
4390
            if (!lex->describe)
4391
            {
1643.6.13 by Djellel E. Difallah
adding tests
4392
              lex->setCacheable(false);
831.1.2 by Brian Aker
Rename class file_exchange
4393
              if (!(lex->exchange= new file_exchange($2.str,1)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4394
                DRIZZLE_YYABORT;
1 by brian
clean slate
4395
              if (!(lex->result= new select_dump(lex->exchange)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4396
                DRIZZLE_YYABORT;
1 by brian
clean slate
4397
            }
4398
          }
4399
        | select_var_list_init
1643.6.13 by Djellel E. Difallah
adding tests
4400
          {Lex->setCacheable(false);}
1 by brian
clean slate
4401
        ;
4402
4403
/*
4404
  Drop : delete tables or index or user
4405
*/
4406
4407
drop:
184 by Brian Aker
Dead debug code removal (and a compatible "never used") bit in the
4408
          DROP opt_temporary table_or_tables if_exists table_list
1 by brian
clean slate
4409
          {
4410
            LEX *lex=Lex;
4411
            lex->sql_command = SQLCOM_DROP_TABLE;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
4412
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
4413
            lex->statement= statement;
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
4414
            if (lex->statement == NULL)
4415
              DRIZZLE_YYABORT;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
4416
            statement->drop_temporary= $2;
4417
            statement->drop_if_exists= $4;
1 by brian
clean slate
4418
          }
4419
        | DROP build_method INDEX_SYM ident ON table_ident {}
4420
          {
4421
            LEX *lex=Lex;
4422
            lex->sql_command= SQLCOM_DROP_INDEX;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
4423
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
4424
            lex->statement= statement;
1100.3.56 by Padraig O'Sullivan
Extracted the CREATE INDEX and DROP INDEX command into an individual class
4425
            if (lex->statement == NULL)
4426
              DRIZZLE_YYABORT;
1128.2.4 by Brian Aker
AlterInfo refactor back to class.
4427
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4428
            statement->alter_info.build_method= $2;
4429
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
520.1.22 by Brian Aker
Second pass of thd cleanup
4430
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
1 by brian
clean slate
4431
                                                        TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4432
              DRIZZLE_YYABORT;
1 by brian
clean slate
4433
          }
4434
        | DROP DATABASE if_exists ident
4435
          {
4436
            LEX *lex=Lex;
4437
            lex->sql_command= SQLCOM_DROP_DB;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
4438
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
4439
            lex->statement= statement;
1100.3.45 by Padraig O'Sullivan
Extracted the DROP DATABASE command into its own class and implementation
4440
            if (lex->statement == NULL)
4441
              DRIZZLE_YYABORT;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
4442
            statement->drop_if_exists=$3;
1 by brian
clean slate
4443
            lex->name= $4;
4444
          }
4445
table_list:
4446
          table_name
4447
        | table_list ',' table_name
4448
        ;
4449
4450
table_name:
4451
          table_ident
4452
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4453
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4454
              DRIZZLE_YYABORT;
1 by brian
clean slate
4455
          }
4456
        ;
4457
4458
if_exists:
4459
          /* empty */ { $$= 0; }
4460
        | IF EXISTS { $$= 1; }
4461
        ;
4462
4463
opt_temporary:
4464
          /* empty */ { $$= 0; }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
4465
        | TEMPORARY_SYM { $$= 1; }
1 by brian
clean slate
4466
        ;
1835.1.6 by Brian Aker
This patch returns dynamic SQL into the core (through SQL-Server syntax).
4467
4468
/*
4469
  Execute a string as dynamic SQL.
4470
  */
4471
4472
execute:
4473
       EXECUTE_SYM
4474
       {
4475
          LEX *lex= Lex;
4476
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession);
4477
          lex->statement= statement;
4478
          if (lex->statement == NULL)
4479
            DRIZZLE_YYABORT;
4480
       }
4481
       execute_var_or_string
4482
4483
4484
execute_var_or_string:
4485
         ident_or_text
4486
         {
4487
          statement::Execute *statement= (statement::Execute *)Lex->statement;
4488
          statement->setQuery($1);
4489
         }
4490
        | '@' ident_or_text
4491
        {
4492
          statement::Execute *statement= (statement::Execute *)Lex->statement;
4493
          statement->setVar();
4494
          statement->setQuery($2);
4495
        }
4496
1 by brian
clean slate
4497
/*
4498
** Insert : add new data to table
4499
*/
4500
4501
insert:
4502
          INSERT
4503
          {
4504
            LEX *lex= Lex;
4505
            lex->sql_command= SQLCOM_INSERT;
1100.3.64 by Padraig O'Sullivan
Extracted the REPLACE and INSERT commands into their own classes and
4506
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
4507
            if (lex->statement == NULL)
4508
              DRIZZLE_YYABORT;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4509
            lex->duplicates= DUP_ERROR;
1 by brian
clean slate
4510
            mysql_init_select(lex);
4511
            /* for subselects */
604 by Brian Aker
Remove lock condition needed (we do row based replication, so... lock is
4512
            lex->lock_option= TL_READ;
1 by brian
clean slate
4513
          }
4514
          opt_ignore insert2
4515
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4516
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
1 by brian
clean slate
4517
            Lex->current_select= &Lex->select_lex;
4518
          }
4519
          insert_field_spec opt_insert_update
4520
          {}
4521
        ;
4522
4523
replace:
4524
          REPLACE
4525
          {
1100.3.64 by Padraig O'Sullivan
Extracted the REPLACE and INSERT commands into their own classes and
4526
            LEX *lex= Lex;
4527
            lex->sql_command= SQLCOM_REPLACE;
4528
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
4529
            if (lex->statement == NULL)
4530
              DRIZZLE_YYABORT;
1 by brian
clean slate
4531
            lex->duplicates= DUP_REPLACE;
4532
            mysql_init_select(lex);
4533
          }
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
4534
          insert2
1 by brian
clean slate
4535
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4536
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
1 by brian
clean slate
4537
            Lex->current_select= &Lex->select_lex;
4538
          }
4539
          insert_field_spec
4540
          {}
4541
        ;
4542
4543
insert2:
4544
          INTO insert_table {}
4545
        | insert_table {}
4546
        ;
4547
4548
insert_table:
4549
          table_name
4550
          {
4551
            LEX *lex=Lex;
4552
            lex->field_list.empty();
4553
            lex->many_values.empty();
4554
            lex->insert_list=0;
4555
          };
4556
4557
insert_field_spec:
4558
          insert_values {}
4559
        | '(' ')' insert_values {}
4560
        | '(' fields ')' insert_values {}
4561
        | SET
4562
          {
4563
            LEX *lex=Lex;
4564
            if (!(lex->insert_list = new List_item) ||
4565
                lex->many_values.push_back(lex->insert_list))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4566
              DRIZZLE_YYABORT;
1 by brian
clean slate
4567
          }
4568
          ident_eq_list
4569
        ;
4570
4571
fields:
4572
          fields ',' insert_ident { Lex->field_list.push_back($3); }
4573
        | insert_ident { Lex->field_list.push_back($1); }
4574
        ;
4575
4576
insert_values:
4577
          VALUES values_list {}
4578
        | VALUE_SYM values_list {}
4579
        | create_select
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4580
          { Lex->current_select->set_braces(0);}
1 by brian
clean slate
4581
          union_clause {}
4582
        | '(' create_select ')'
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4583
          { Lex->current_select->set_braces(1);}
1 by brian
clean slate
4584
          union_opt {}
4585
        ;
4586
4587
values_list:
4588
          values_list ','  no_braces
4589
        | no_braces
4590
        ;
4591
4592
ident_eq_list:
4593
          ident_eq_list ',' ident_eq_value
4594
        | ident_eq_value
4595
        ;
4596
4597
ident_eq_value:
4598
          simple_ident_nospvar equal expr_or_default
4599
          {
4600
            LEX *lex=Lex;
4601
            if (lex->field_list.push_back($1) ||
4602
                lex->insert_list->push_back($3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4603
              DRIZZLE_YYABORT;
1 by brian
clean slate
4604
          }
4605
        ;
4606
4607
equal:
4608
          EQ {}
4609
        | SET_VAR {}
4610
        ;
4611
4612
opt_equal:
4613
          /* empty */ {}
4614
        | equal {}
4615
        ;
4616
4617
no_braces:
4618
          '('
4619
          {
4620
              if (!(Lex->insert_list = new List_item))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4621
                DRIZZLE_YYABORT;
1 by brian
clean slate
4622
          }
4623
          opt_values ')'
4624
          {
4625
            LEX *lex=Lex;
4626
            if (lex->many_values.push_back(lex->insert_list))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4627
              DRIZZLE_YYABORT;
1 by brian
clean slate
4628
          }
4629
        ;
4630
4631
opt_values:
4632
          /* empty */ {}
4633
        | values
4634
        ;
4635
4636
values:
4637
          values ','  expr_or_default
4638
          {
4639
            if (Lex->insert_list->push_back($3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4640
              DRIZZLE_YYABORT;
1 by brian
clean slate
4641
          }
4642
        | expr_or_default
4643
          {
4644
            if (Lex->insert_list->push_back($1))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4645
              DRIZZLE_YYABORT;
1 by brian
clean slate
4646
          }
4647
        ;
4648
4649
expr_or_default:
4650
          expr { $$= $1;}
4651
        | DEFAULT {$$= new Item_default_value(Lex->current_context()); }
4652
        ;
4653
4654
opt_insert_update:
4655
          /* empty */
4656
        | ON DUPLICATE_SYM { Lex->duplicates= DUP_UPDATE; }
4657
          KEY_SYM UPDATE_SYM insert_update_list
4658
        ;
4659
4660
/* Update rows in a table */
4661
4662
update:
1108.1.2 by Brian Aker
Removal multi-update/delete
4663
          UPDATE_SYM opt_ignore table_ident
1 by brian
clean slate
4664
          {
4665
            LEX *lex= Lex;
4666
            mysql_init_select(lex);
4667
            lex->sql_command= SQLCOM_UPDATE;
1100.3.40 by Padraig O'Sullivan
Extracted the UPDATE command into its own class and implementation files.
4668
            lex->statement= new(std::nothrow) statement::Update(YYSession);
4669
            if (lex->statement == NULL)
4670
              DRIZZLE_YYABORT;
1 by brian
clean slate
4671
            lex->lock_option= TL_UNLOCK; /* Will be set later */
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4672
            lex->duplicates= DUP_ERROR;
1108.1.2 by Brian Aker
Removal multi-update/delete
4673
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4674
              DRIZZLE_YYABORT;
1 by brian
clean slate
4675
          }
4676
          SET update_list
4677
          {
4678
            LEX *lex= Lex;
1108.1.2 by Brian Aker
Removal multi-update/delete
4679
            if (lex->select_lex.get_table_list()->derived)
1 by brian
clean slate
4680
            {
4681
              /* it is single table update and it is update of derived table */
4682
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4683
                       lex->select_lex.get_table_list()->alias, "UPDATE");
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4684
              DRIZZLE_YYABORT;
1 by brian
clean slate
4685
            }
4686
            /*
4687
              In case of multi-update setting write lock for all tables may
4688
              be too pessimistic. We will decrease lock level if possible in
4689
              mysql_multi_update().
4690
            */
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4691
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
1 by brian
clean slate
4692
          }
4693
          where_clause opt_order_clause delete_limit_clause {}
4694
        ;
4695
4696
update_list:
4697
          update_list ',' update_elem
4698
        | update_elem
4699
        ;
4700
4701
update_elem:
4702
          simple_ident_nospvar equal expr_or_default
4703
          {
838 by Brian Aker
More class adoption/method
4704
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4705
              DRIZZLE_YYABORT;
1 by brian
clean slate
4706
          }
4707
        ;
4708
4709
insert_update_list:
4710
          insert_update_list ',' insert_update_elem
4711
        | insert_update_elem
4712
        ;
4713
4714
insert_update_elem:
4715
          simple_ident_nospvar equal expr_or_default
4716
          {
4717
          LEX *lex= Lex;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4718
          if (lex->update_list.push_back($1) ||
1 by brian
clean slate
4719
              lex->value_list.push_back($3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4720
              DRIZZLE_YYABORT;
1 by brian
clean slate
4721
          }
4722
        ;
4723
4724
/* Delete rows from a table */
4725
4726
delete:
4727
          DELETE_SYM
4728
          {
4729
            LEX *lex= Lex;
4730
            lex->sql_command= SQLCOM_DELETE;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
4731
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
4732
            if (lex->statement == NULL)
1100.3.26 by Padraig O'Sullivan
Extracted the DELETE command into its own class and implementation files and
4733
              DRIZZLE_YYABORT;
1 by brian
clean slate
4734
            mysql_init_select(lex);
4735
            lex->lock_option= TL_WRITE_DEFAULT;
4736
            lex->ignore= 0;
4737
            lex->select_lex.init_order();
4738
          }
4739
          opt_delete_options single_multi
4740
        ;
4741
4742
single_multi:
4743
          FROM table_ident
4744
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
4745
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
1 by brian
clean slate
4746
                                           Lex->lock_option))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4747
              DRIZZLE_YYABORT;
1 by brian
clean slate
4748
          }
4749
          where_clause opt_order_clause
4750
          delete_limit_clause {}
4751
        ;
4752
4753
opt_delete_options:
4754
          /* empty */ {}
4755
        | opt_delete_option opt_delete_options {}
4756
        ;
4757
4758
opt_delete_option:
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
4759
         IGNORE_SYM   { Lex->ignore= 1; }
1 by brian
clean slate
4760
        ;
4761
4762
truncate:
4763
          TRUNCATE_SYM opt_table_sym table_name
4764
          {
4765
            LEX* lex= Lex;
4766
            lex->sql_command= SQLCOM_TRUNCATE;
1100.3.41 by Padraig O'Sullivan
Extracted the TRUNCATE command into its own class and implementation files.
4767
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
4768
            if (lex->statement == NULL)
4769
              DRIZZLE_YYABORT;
1 by brian
clean slate
4770
            lex->select_lex.options= 0;
4771
            lex->select_lex.init_order();
4772
          }
4773
        ;
4774
4775
opt_table_sym:
4776
          /* empty */
4777
        | TABLE_SYM
4778
        ;
4779
4780
/* Show things */
4781
4782
show:
4783
          SHOW
4784
          {
4785
            LEX *lex=Lex;
4786
            lex->wild=0;
4787
            lex->lock_option= TL_READ;
4788
            mysql_init_select(lex);
4789
            lex->current_select->parsing_place= SELECT_LIST;
4790
          }
4791
          show_param
4792
          {}
4793
        ;
4794
4795
show_param:
327.2.5 by Brian Aker
Refactoring show command
4796
           DATABASES show_wild
1 by brian
clean slate
4797
           {
4798
             LEX *lex= Lex;
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4799
             Session *session= YYSession;
4800
1273.13.38 by Brian Aker
Add in new show work.
4801
             lex->sql_command= SQLCOM_SELECT;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
4802
             lex->statement=
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
4803
               new(std::nothrow) statement::Show(session);
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
4804
             if (lex->statement == NULL)
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
4805
               DRIZZLE_YYABORT;
1273.13.38 by Brian Aker
Add in new show work.
4806
4807
             std::string column_name= "Database";
4808
             if (Lex->wild)
4809
             {
4810
               column_name.append(" (");
1273.13.65 by Brian Aker
Lint fixes.
4811
               column_name.append(Lex->wild->ptr());
1273.13.38 by Brian Aker
Add in new show work.
4812
               column_name.append(")");
4813
             }
4814
4815
             if (Lex->current_select->where)
4816
             {
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4817
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
1273.13.38 by Brian Aker
Add in new show work.
4818
                 DRIZZLE_YYABORT;
4819
             }
4820
             else
4821
             {
1420 by Brian Aker
Updated to use show schemas specific table.
4822
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
1273.13.38 by Brian Aker
Add in new show work.
4823
                 DRIZZLE_YYABORT;
4824
             }
4825
4826
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4827
             my_field->is_autogenerated_name= false;
4828
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4829
4830
             if (session->add_item_to_list(my_field))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4831
               DRIZZLE_YYABORT;
1643.3.12 by Brian Aker
Remove the sort() that is directly done on the list in favor of doing it in
4832
4833
              if (session->add_order_to_list(my_field, true))
4834
                DRIZZLE_YYABORT;
1 by brian
clean slate
4835
           }
1273.13.37 by Brian Aker
Remove "full" syntax.
4836
         | TABLES opt_db show_wild
1 by brian
clean slate
4837
           {
4838
             LEX *lex= Lex;
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4839
             Session *session= YYSession;
4840
1273.13.38 by Brian Aker
Add in new show work.
4841
             lex->sql_command= SQLCOM_SELECT;
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4842
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
4843
             statement::Show *select=
4844
               new(std::nothrow) statement::Show(YYSession);
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4845
4846
             lex->statement= select;
4847
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
4848
             if (lex->statement == NULL)
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
4849
               DRIZZLE_YYABORT;
1273.13.38 by Brian Aker
Add in new show work.
4850
4851
4852
              std::string column_name= "Tables_in_";
4853
4854
              if ($2)
4855
              {
1415 by Brian Aker
Mass overhaul to use schema_identifier.
4856
		SchemaIdentifier identifier($2);
1273.13.38 by Brian Aker
Add in new show work.
4857
                column_name.append($2);
4858
                lex->select_lex.db= $2;
1415 by Brian Aker
Mass overhaul to use schema_identifier.
4859
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
1273.13.38 by Brian Aker
Add in new show work.
4860
                {
4861
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4862
                }
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4863
                select->setShowPredicate($2, "");
1273.13.38 by Brian Aker
Add in new show work.
4864
              }
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4865
              else if (not session->db.empty())
1273.13.38 by Brian Aker
Add in new show work.
4866
              {
4867
                column_name.append(session->db);
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4868
                select->setShowPredicate(session->db, "");
4869
              }
4870
              else
4871
              {
4872
                 my_error(ER_NO_DB_ERROR, MYF(0));
4873
              }
4874
1273.13.38 by Brian Aker
Add in new show work.
4875
4876
             if (Lex->wild)
4877
             {
4878
               column_name.append(" (");
1273.13.65 by Brian Aker
Lint fixes.
4879
               column_name.append(Lex->wild->ptr());
1273.13.38 by Brian Aker
Add in new show work.
4880
               column_name.append(")");
4881
             }
4882
1385.1.2 by Brian Aker
This works, but there is a cheat in it to get around bugs in rename table
4883
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4884
               DRIZZLE_YYABORT;
1273.13.38 by Brian Aker
Add in new show work.
4885
4886
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4887
             my_field->is_autogenerated_name= false;
4888
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4889
4890
             if (session->add_item_to_list(my_field))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
4891
               DRIZZLE_YYABORT;
1643.3.12 by Brian Aker
Remove the sort() that is directly done on the list in favor of doing it in
4892
4893
              if (session->add_order_to_list(my_field, true))
4894
                DRIZZLE_YYABORT;
1 by brian
clean slate
4895
           }
1429.1.2 by Brian Aker
Update for show temporary tables;
4896
         | TEMPORARY_SYM TABLES show_wild
4897
           {
4898
             LEX *lex= Lex;
4899
             Session *session= YYSession;
4900
4901
             lex->sql_command= SQLCOM_SELECT;
4902
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
4903
             statement::Show *select=
4904
               new(std::nothrow) statement::Show(YYSession);
1429.1.2 by Brian Aker
Update for show temporary tables;
4905
4906
             lex->statement= select;
4907
4908
             if (lex->statement == NULL)
4909
               DRIZZLE_YYABORT;
4910
4911
4912
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4913
               DRIZZLE_YYABORT;
4914
4915
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4916
                                                           context,
4917
                                                           NULL, NULL, "*")))
4918
               DRIZZLE_YYABORT;
4919
             (session->lex->current_select->with_wild)++;
4920
4921
           }
327.2.5 by Brian Aker
Refactoring show command
4922
         | TABLE_SYM STATUS_SYM opt_db show_wild
1 by brian
clean slate
4923
           {
4924
             LEX *lex= Lex;
1273.13.40 by Brian Aker
Updates for show table status.
4925
             lex->sql_command= SQLCOM_SELECT;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
4926
             statement::Show *select=
4927
               new(std::nothrow) statement::Show(YYSession);
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
4928
4929
             lex->statement= select;
4930
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
4931
             if (lex->statement == NULL)
1101.1.22 by Monty Taylor
Reverted my stupid hacky fix now that Padraig has it fixed for real.
4932
               DRIZZLE_YYABORT;
1273.13.40 by Brian Aker
Updates for show table status.
4933
4934
             Session *session= YYSession;
4935
4936
             std::string column_name= "Tables_in_";
4937
4938
             if ($3)
4939
             {
4940
               lex->select_lex.db= $3;
4941
1415 by Brian Aker
Mass overhaul to use schema_identifier.
4942
	       SchemaIdentifier identifier($3);
4943
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
1273.13.40 by Brian Aker
Updates for show table status.
4944
               {
4945
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4946
               }
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
4947
4948
               select->setShowPredicate($3, "");
4949
             }
4950
             else
4951
             {
4952
               select->setShowPredicate(session->db, "");
1273.13.40 by Brian Aker
Updates for show table status.
4953
             }
4954
1309.2.5 by Brian Aker
Reworked the code (split classes).
4955
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
1273.13.40 by Brian Aker
Updates for show table status.
4956
               DRIZZLE_YYABORT;
4957
4958
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4959
                                                           context,
4960
                                                           NULL, NULL, "*")))
4961
               DRIZZLE_YYABORT;
4962
             (session->lex->current_select->with_wild)++;
1 by brian
clean slate
4963
           }
1273.13.37 by Brian Aker
Remove "full" syntax.
4964
        | COLUMNS from_or_in table_ident opt_db show_wild
1 by brian
clean slate
4965
          {
1273.19.1 by Brian Aker
Update for show fields.
4966
             LEX *lex= Lex;
4967
             Session *session= YYSession;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
4968
             statement::Show *select;
1273.19.1 by Brian Aker
Update for show fields.
4969
4970
             lex->sql_command= SQLCOM_SELECT;
4971
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
4972
             select= new(std::nothrow) statement::Show(session);
1273.19.1 by Brian Aker
Update for show fields.
4973
4974
             lex->statement= select;
4975
4976
             if (lex->statement == NULL)
4977
               DRIZZLE_YYABORT;
4978
4979
             if ($4)
4980
              select->setShowPredicate($4, $3->table.str);
4981
             else if ($3->db.str)
4982
              select->setShowPredicate($3->db.str, $3->table.str);
4983
             else
4984
              select->setShowPredicate(session->db, $3->table.str);
4985
4986
             {
4987
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
1309.4.4 by Brian Aker
Column changing.
4988
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
1273.19.1 by Brian Aker
Update for show fields.
4989
               {
4990
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
4991
                            select->getShowSchema().c_str(), 
4992
                            $3->table.str);
4993
               }
4994
             }
4995
1309.2.4 by Brian Aker
New version of show columns code.
4996
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
4997
               DRIZZLE_YYABORT;
4998
4999
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5000
                                                           context,
5001
                                                           NULL, NULL, "*")))
5002
               DRIZZLE_YYABORT;
5003
             (session->lex->current_select->with_wild)++;
5004
1 by brian
clean slate
5005
          }
5006
        | keys_or_index from_or_in table_ident opt_db where_clause
5007
          {
1273.19.2 by Brian Aker
First pass through show indexs.
5008
             LEX *lex= Lex;
5009
             Session *session= YYSession;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5010
             statement::Show *select;
1273.19.2 by Brian Aker
First pass through show indexs.
5011
5012
             lex->sql_command= SQLCOM_SELECT;
5013
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5014
             select= new(std::nothrow) statement::Show(session);
1273.19.2 by Brian Aker
First pass through show indexs.
5015
5016
             lex->statement= select;
5017
5018
             if (lex->statement == NULL)
5019
               DRIZZLE_YYABORT;
5020
5021
             if ($4)
5022
              select->setShowPredicate($4, $3->table.str);
5023
             else if ($3->db.str)
5024
              select->setShowPredicate($3->db.str, $3->table.str);
5025
             else
5026
              select->setShowPredicate(session->db, $3->table.str);
5027
5028
             {
5029
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
1309.4.4 by Brian Aker
Column changing.
5030
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
1273.19.2 by Brian Aker
First pass through show indexs.
5031
               {
5032
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5033
                            select->getShowSchema().c_str(), 
5034
                            $3->table.str);
5035
               }
5036
             }
5037
1385.1.3 by Brian Aker
Split of tables from being a part of show (we jsut use customized functions
5038
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
1309.2.3 by Brian Aker
Update the code so use a faster index lookup method.
5039
               DRIZZLE_YYABORT;
5040
5041
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5042
                                                           context,
5043
                                                           NULL, NULL, "*")))
5044
               DRIZZLE_YYABORT;
5045
             (session->lex->current_select->with_wild)++;
1 by brian
clean slate
5046
          }
5047
        | COUNT_SYM '(' '*' ')' WARNINGS
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5048
          {
5049
            (void) create_select_for_variable("warning_count");
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
5050
            LEX *lex= Lex;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5051
            lex->statement= new(std::nothrow) statement::Show(YYSession);
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
5052
            if (lex->statement == NULL)
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
5053
              DRIZZLE_YYABORT;
5054
          }
1 by brian
clean slate
5055
        | COUNT_SYM '(' '*' ')' ERRORS
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5056
          {
5057
            (void) create_select_for_variable("error_count");
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
5058
            LEX *lex= Lex;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5059
            lex->statement= new(std::nothrow) statement::Show(YYSession);
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
5060
            if (lex->statement == NULL)
1100.3.3 by Padraig O'Sullivan
Forgot one of the SHOW commands that I should have included in the last
5061
              DRIZZLE_YYABORT;
5062
          }
1 by brian
clean slate
5063
        | WARNINGS opt_limit_clause_init
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5064
          {
1100.3.10 by Padraig O'Sullivan
Extracted the SHOW WARNINGS command from the huge switch statement into its
5065
            Lex->sql_command = SQLCOM_SHOW_WARNS;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
5066
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5067
            if (Lex->statement == NULL)
1100.3.10 by Padraig O'Sullivan
Extracted the SHOW WARNINGS command from the huge switch statement into its
5068
              DRIZZLE_YYABORT;
5069
          }
1 by brian
clean slate
5070
        | ERRORS opt_limit_clause_init
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5071
          {
1100.3.11 by Padraig O'Sullivan
Extracted the SHOW ERRORS command into its own class and removed the
5072
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
5073
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5074
            if (Lex->statement == NULL)
1100.3.11 by Padraig O'Sullivan
Extracted the SHOW ERRORS command into its own class and removed the
5075
              DRIZZLE_YYABORT;
5076
          }
327.2.5 by Brian Aker
Refactoring show command
5077
        | opt_var_type STATUS_SYM show_wild
1273.16.1 by Brian Aker
More removal of show code.
5078
           {
5079
             LEX *lex= Lex;
5080
             lex->sql_command= SQLCOM_SELECT;
5081
             lex->statement=
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5082
               new(std::nothrow) statement::Show(YYSession);
1273.16.1 by Brian Aker
More removal of show code.
5083
             if (lex->statement == NULL)
5084
               DRIZZLE_YYABORT;
5085
5086
             Session *session= YYSession;
5087
5088
             if ($1 == OPT_GLOBAL)
5089
             {
5090
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5091
                 DRIZZLE_YYABORT;
5092
             }
5093
             else
5094
             {
5095
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5096
                 DRIZZLE_YYABORT;
5097
             }
5098
5099
             std::string key("Variable_name");
5100
             std::string value("Value");
5101
5102
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5103
             my_field->is_autogenerated_name= false;
5104
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5105
5106
             if (session->add_item_to_list(my_field))
5107
               DRIZZLE_YYABORT;
5108
5109
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5110
             my_field->is_autogenerated_name= false;
5111
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5112
5113
             if (session->add_item_to_list(my_field))
5114
               DRIZZLE_YYABORT;
5115
           }
1812.5.1 by Brian Aker
This removes the caller for show create table to be a derived table.
5116
        | CREATE TABLE_SYM table_ident
5117
           {
5118
             LEX *lex= Lex;
5119
             lex->sql_command= SQLCOM_SELECT;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5120
             statement::Show *select=
5121
               new(std::nothrow) statement::Show(YYSession);
1812.5.1 by Brian Aker
This removes the caller for show create table to be a derived table.
5122
5123
             lex->statement= select;
5124
5125
             if (lex->statement == NULL)
5126
               DRIZZLE_YYABORT;
5127
5128
             Session *session= YYSession;
5129
5130
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5131
               DRIZZLE_YYABORT;
5132
5133
             if ($3->db.str)
5134
              select->setShowPredicate($3->db.str, $3->table.str);
5135
             else
5136
              select->setShowPredicate(session->db, $3->table.str);
5137
5138
             std::string key("Table");
5139
             std::string value("Create Table");
5140
5141
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5142
             my_field->is_autogenerated_name= false;
5143
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5144
5145
             if (session->add_item_to_list(my_field))
5146
               DRIZZLE_YYABORT;
5147
5148
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5149
             my_field->is_autogenerated_name= false;
5150
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5151
5152
             if (session->add_item_to_list(my_field))
5153
               DRIZZLE_YYABORT;
5154
           }
1279 by Brian Aker
Remove show engine status, and show open tables (which no longer applies in
5155
        | PROCESSLIST_SYM
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5156
          {
1273.13.54 by Brian Aker
Update to use processlist code from plugin.
5157
           {
5158
             LEX *lex= Lex;
5159
             lex->sql_command= SQLCOM_SELECT;
5160
             lex->statement=
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5161
               new(std::nothrow) statement::Show(YYSession);
1273.13.54 by Brian Aker
Update to use processlist code from plugin.
5162
             if (lex->statement == NULL)
5163
               DRIZZLE_YYABORT;
5164
5165
             Session *session= YYSession;
5166
5167
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5168
               DRIZZLE_YYABORT;
5169
5170
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5171
                                                           context,
5172
                                                           NULL, NULL, "*")))
5173
               DRIZZLE_YYABORT;
5174
             (session->lex->current_select->with_wild)++;
5175
           }
1100.3.16 by Padraig O'Sullivan
Extracted the show processlist command into a class with its own
5176
          }
327.2.5 by Brian Aker
Refactoring show command
5177
        | opt_var_type  VARIABLES show_wild
1273.13.59 by Brian Aker
Updates for VARIABLES
5178
           {
5179
             LEX *lex= Lex;
5180
             lex->sql_command= SQLCOM_SELECT;
5181
             lex->statement=
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5182
               new(std::nothrow) statement::Show(YYSession);
1273.13.59 by Brian Aker
Updates for VARIABLES
5183
             if (lex->statement == NULL)
5184
               DRIZZLE_YYABORT;
5185
5186
             Session *session= YYSession;
5187
5188
             if ($1 == OPT_GLOBAL)
5189
             {
5190
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5191
                 DRIZZLE_YYABORT;
5192
             }
5193
             else
5194
             {
5195
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5196
                 DRIZZLE_YYABORT;
5197
             }
5198
5199
             std::string key("Variable_name");
5200
             std::string value("Value");
5201
5202
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5203
             my_field->is_autogenerated_name= false;
5204
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5205
5206
             if (session->add_item_to_list(my_field))
5207
               DRIZZLE_YYABORT;
5208
5209
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5210
             my_field->is_autogenerated_name= false;
5211
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5212
5213
             if (session->add_item_to_list(my_field))
5214
               DRIZZLE_YYABORT;
5215
           }
1 by brian
clean slate
5216
        | CREATE DATABASE opt_if_not_exists ident
1812.5.9 by Brian Aker
First pass on moving show create schema out.
5217
           {
5218
             LEX *lex= Lex;
5219
             lex->sql_command= SQLCOM_SELECT;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5220
             statement::Show *select=
5221
               new(std::nothrow) statement::Show(YYSession);
1812.5.9 by Brian Aker
First pass on moving show create schema out.
5222
5223
             lex->statement= select;
5224
5225
             if (lex->statement == NULL)
5226
               DRIZZLE_YYABORT;
5227
5228
             Session *session= YYSession;
5229
5230
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5231
               DRIZZLE_YYABORT;
5232
5233
             if ($4.str)
5234
              select->setShowPredicate($4.str);
5235
             else
5236
              select->setShowPredicate(session->db);
5237
5238
             std::string key("Database");
5239
             std::string value("Create Database");
5240
5241
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5242
             my_field->is_autogenerated_name= false;
5243
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5244
5245
             if (session->add_item_to_list(my_field))
5246
               DRIZZLE_YYABORT;
5247
5248
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5249
             my_field->is_autogenerated_name= false;
5250
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5251
5252
             if (session->add_item_to_list(my_field))
5253
               DRIZZLE_YYABORT;
5254
           }
1 by brian
clean slate
5255
5256
opt_db:
5257
          /* empty */  { $$= 0; }
5258
        | from_or_in ident { $$= $2.str; }
5259
        ;
5260
5261
from_or_in:
5262
          FROM
5263
        | IN_SYM
5264
        ;
5265
327.2.5 by Brian Aker
Refactoring show command
5266
show_wild:
1 by brian
clean slate
5267
          /* empty */
5268
        | LIKE TEXT_STRING_sys
5269
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5270
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
1 by brian
clean slate
5271
                                                    system_charset_info);
1055.1.1 by Padraig O'Sullivan
Modified the show_wild rule to also support WHERE clauses.
5272
            if (Lex->wild == NULL)
5273
              DRIZZLE_YYABORT;
5274
          }
5275
        | WHERE expr
5276
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5277
            Lex->current_select->where= $2;
1055.1.1 by Padraig O'Sullivan
Modified the show_wild rule to also support WHERE clauses.
5278
            if ($2)
5279
              $2->top_level_item();
1 by brian
clean slate
5280
          }
5281
        ;
5282
5283
/* A Oracle compatible synonym for show */
5284
describe:
5285
          describe_command table_ident
5286
          {
1273.19.4 by Brian Aker
Updates for DESC.
5287
            Session *session= YYSession;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5288
            statement::Show *select;
1 by brian
clean slate
5289
            LEX *lex= Lex;
5290
            lex->lock_option= TL_READ;
5291
            mysql_init_select(lex);
5292
            lex->current_select->parsing_place= SELECT_LIST;
1273.19.4 by Brian Aker
Updates for DESC.
5293
            lex->sql_command= SQLCOM_SELECT;
1874.2.2 by Brian Aker
What was once old, is now new again. Seperated out show from select.
5294
            select= new(std::nothrow) statement::Show(session);
1273.19.4 by Brian Aker
Updates for DESC.
5295
            lex->statement= select;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
5296
            if (lex->statement == NULL)
1100.3.7 by Padraig O'Sullivan
Corrected how memory is freed for each command. This involved suring memory
5297
              DRIZZLE_YYABORT;
1 by brian
clean slate
5298
            lex->select_lex.db= 0;
1273.19.4 by Brian Aker
Updates for DESC.
5299
5300
             if ($2->db.str)
5301
              select->setShowPredicate($2->db.str, $2->table.str);
5302
             else
5303
              select->setShowPredicate(session->db, $2->table.str);
5304
5305
             {
5306
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
1309.4.4 by Brian Aker
Column changing.
5307
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
1273.19.4 by Brian Aker
Updates for DESC.
5308
               {
5309
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5310
                            select->getShowSchema().c_str(), 
5311
                            $2->table.str);
5312
               }
5313
             }
5314
1309.4.3 by Brian Aker
Refactor DESC to use new table.
5315
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5316
               DRIZZLE_YYABORT;
5317
5318
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5319
                                                           context,
5320
                                                           NULL, NULL, "*")))
5321
               DRIZZLE_YYABORT;
5322
             (session->lex->current_select->with_wild)++;
5323
1 by brian
clean slate
5324
          }
5325
          opt_describe_column {}
5326
        | describe_command opt_extended_describe
5327
          { Lex->describe|= DESCRIBE_NORMAL; }
5328
          select
5329
          {
5330
            LEX *lex=Lex;
5331
            lex->select_lex.options|= SELECT_DESCRIBE;
5332
          }
5333
        ;
5334
5335
describe_command:
5336
          DESC
5337
        | DESCRIBE
5338
        ;
5339
5340
opt_extended_describe:
5341
          /* empty */ {}
5342
        | EXTENDED_SYM   { Lex->describe|= DESCRIBE_EXTENDED; }
5343
        ;
5344
5345
opt_describe_column:
5346
          /* empty */ {}
5347
        | text_string { Lex->wild= $1; }
5348
        | ident
5349
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5350
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
1 by brian
clean slate
5351
                                                    $1.length,
5352
                                                    system_charset_info);
5353
          }
5354
        ;
5355
5356
5357
/* flush things */
5358
5359
flush:
383.1.26 by Brian Aker
Removed option for single command replication and have now left disable of
5360
          FLUSH_SYM
1 by brian
clean slate
5361
          {
5362
            LEX *lex=Lex;
5363
            lex->sql_command= SQLCOM_FLUSH;
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
5364
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
5365
            if (lex->statement == NULL)
5366
              DRIZZLE_YYABORT;
1 by brian
clean slate
5367
            lex->type= 0;
5368
          }
5369
          flush_options
5370
          {}
5371
        ;
5372
5373
flush_options:
5374
          flush_options ',' flush_option
5375
        | flush_option
5376
        ;
5377
5378
flush_option:
5379
          table_or_tables
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
5380
          {
5381
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5382
            statement->setFlushTables(true);
5383
          }
1 by brian
clean slate
5384
          opt_table_list {}
5385
        | TABLES WITH READ_SYM LOCK_SYM
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
5386
          {
5387
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5388
            statement->setFlushTablesWithReadLock(true);
5389
          }
1 by brian
clean slate
5390
        | LOGS_SYM
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
5391
          {
5392
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5393
            statement->setFlushLog(true);
5394
          }
1 by brian
clean slate
5395
        | STATUS_SYM
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
5396
          {
5397
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5398
            statement->setFlushStatus(true);
5399
          }
1 by brian
clean slate
5400
        ;
5401
5402
opt_table_list:
5403
          /* empty */  {}
5404
        | table_list {}
5405
        ;
5406
5407
/* kill threads */
5408
5409
kill:
5410
          KILL_SYM kill_option expr
5411
          {
5412
            LEX *lex=Lex;
5413
            lex->value_list.empty();
5414
            lex->value_list.push_front($3);
5415
            lex->sql_command= SQLCOM_KILL;
1100.3.49 by Padraig O'Sullivan
Extracted the KILL command into its own class and implementation files.
5416
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
5417
            if (lex->statement == NULL)
5418
              DRIZZLE_YYABORT;
1 by brian
clean slate
5419
          }
5420
        ;
5421
5422
kill_option:
5423
          /* empty */ { Lex->type= 0; }
5424
        | CONNECTION_SYM { Lex->type= 0; }
5425
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
5426
        ;
5427
5428
/* change database */
5429
5430
use:
5431
          USE_SYM ident
5432
          {
5433
            LEX *lex=Lex;
5434
            lex->sql_command=SQLCOM_CHANGE_DB;
1100.3.43 by Padraig O'Sullivan
Extracted the CHANGE DB command into its own class and implementation files.
5435
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
5436
            if (lex->statement == NULL)
5437
              DRIZZLE_YYABORT;
1 by brian
clean slate
5438
            lex->select_lex.db= $2.str;
5439
          }
5440
        ;
5441
5442
/* import, export of files */
5443
5444
load:
266.1.23 by Monty Taylor
Removed load xml infile. Hope nobody liked it. Now the only thing we need xml.c
5445
          LOAD data_file
1 by brian
clean slate
5446
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5447
            Session *session= YYSession;
5448
            LEX *lex= session->lex;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
5449
5450
            lex->sql_command= SQLCOM_LOAD;
5451
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
5452
            lex->statement= statement;
5453
            if (lex->statement == NULL)
5454
              DRIZZLE_YYABORT;
5455
520.1.22 by Brian Aker
Second pass of thd cleanup
5456
            Lex_input_stream *lip= session->m_lip;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
5457
            statement->fname_start= lip->get_ptr();
1 by brian
clean slate
5458
          }
919.1.1 by Brian Aker
Remove LOAD DATA "LOCAL" INFILE
5459
          load_data_lock INFILE TEXT_STRING_filesystem
1 by brian
clean slate
5460
          {
5461
            LEX *lex=Lex;
5462
            lex->lock_option= $4;
5463
            lex->duplicates= DUP_ERROR;
5464
            lex->ignore= 0;
919.1.1 by Brian Aker
Remove LOAD DATA "LOCAL" INFILE
5465
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5466
              DRIZZLE_YYABORT;
1 by brian
clean slate
5467
          }
5468
          opt_duplicate INTO
5469
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5470
            Session *session= YYSession;
5471
            Lex_input_stream *lip= session->m_lip;
1128.2.11 by Brian Aker
More rework of Lex for "how tiny can she be..."
5472
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
1 by brian
clean slate
5473
          }
5474
          TABLE_SYM table_ident
5475
          {
5476
            LEX *lex=Lex;
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5477
            if (!Lex->current_select->add_table_to_list(YYSession,
5478
                    $12, NULL, TL_OPTION_UPDATING,
5479
                    lex->lock_option))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5480
              DRIZZLE_YYABORT;
1 by brian
clean slate
5481
            lex->field_list.empty();
5482
            lex->update_list.empty();
5483
            lex->value_list.empty();
5484
          }
5485
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5486
          opt_load_data_set_spec
5487
          {}
5488
        ;
5489
266.1.23 by Monty Taylor
Removed load xml infile. Hope nobody liked it. Now the only thing we need xml.c
5490
data_file:
5491
        DATA_SYM  { $$= FILETYPE_CSV; };
1 by brian
clean slate
5492
5493
load_data_lock:
5494
          /* empty */ { $$= TL_WRITE_DEFAULT; }
5495
        | CONCURRENT
5496
          {
5497
              $$= TL_WRITE_CONCURRENT_INSERT;
5498
          }
5499
        ;
5500
5501
opt_duplicate:
5502
          /* empty */ { Lex->duplicates=DUP_ERROR; }
5503
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
5504
        | IGNORE_SYM { Lex->ignore= 1; }
5505
        ;
5506
5507
opt_field_term:
5508
          /* empty */
5509
        | COLUMNS field_term_list
5510
        ;
5511
5512
field_term_list:
5513
          field_term_list field_term
5514
        | field_term
5515
        ;
5516
5517
field_term:
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5518
          TERMINATED BY text_string
1 by brian
clean slate
5519
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5520
            assert(Lex->exchange != 0);
1 by brian
clean slate
5521
            Lex->exchange->field_term= $3;
5522
          }
5523
        | OPTIONALLY ENCLOSED BY text_string
5524
          {
5525
            LEX *lex= Lex;
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5526
            assert(lex->exchange != 0);
1 by brian
clean slate
5527
            lex->exchange->enclosed= $4;
5528
            lex->exchange->opt_enclosed= 1;
5529
          }
5530
        | ENCLOSED BY text_string
5531
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5532
            assert(Lex->exchange != 0);
1 by brian
clean slate
5533
            Lex->exchange->enclosed= $3;
5534
          }
5535
        | ESCAPED BY text_string
5536
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5537
            assert(Lex->exchange != 0);
1 by brian
clean slate
5538
            Lex->exchange->escaped= $3;
5539
          }
5540
        ;
5541
5542
opt_line_term:
5543
          /* empty */
5544
        | LINES line_term_list
5545
        ;
5546
5547
line_term_list:
5548
          line_term_list line_term
5549
        | line_term
5550
        ;
5551
5552
line_term:
5553
          TERMINATED BY text_string
5554
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5555
            assert(Lex->exchange != 0);
1 by brian
clean slate
5556
            Lex->exchange->line_term= $3;
5557
          }
5558
        | STARTING BY text_string
5559
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5560
            assert(Lex->exchange != 0);
1 by brian
clean slate
5561
            Lex->exchange->line_start= $3;
5562
          }
5563
        ;
5564
5565
opt_ignore_lines:
5566
          /* empty */
5567
        | IGNORE_SYM NUM lines_or_rows
5568
          {
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
5569
            assert(Lex->exchange != 0);
1 by brian
clean slate
5570
            Lex->exchange->skip_lines= atol($2.str);
5571
          }
5572
        ;
5573
5574
lines_or_rows:
5575
        LINES { }
5576
        | ROWS_SYM { }
5577
        ;
5578
5579
opt_field_or_var_spec:
5580
          /* empty */ {}
5581
        | '(' fields_or_vars ')' {}
5582
        | '(' ')' {}
5583
        ;
5584
5585
fields_or_vars:
5586
          fields_or_vars ',' field_or_var
5587
          { Lex->field_list.push_back($3); }
5588
        | field_or_var
5589
          { Lex->field_list.push_back($1); }
5590
        ;
5591
5592
field_or_var:
5593
          simple_ident_nospvar {$$= $1;}
5594
        | '@' ident_or_text
5595
          { $$= new Item_user_var_as_out_param($2); }
5596
        ;
5597
5598
opt_load_data_set_spec:
5599
          /* empty */ {}
5600
        | SET insert_update_list {}
5601
        ;
5602
5603
/* Common definitions */
5604
5605
text_literal:
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
5606
        TEXT_STRING_literal
5607
        {
5608
          Session *session= YYSession;
5609
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
5610
        }
1 by brian
clean slate
5611
        | text_literal TEXT_STRING_literal
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
5612
          {
5613
            ((Item_string*) $1)->append($2.str, $2.length);
1 by brian
clean slate
5614
          }
5615
        ;
5616
5617
text_string:
5618
          TEXT_STRING_literal
5619
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5620
            $$= new (YYSession->mem_root) String($1.str,
1 by brian
clean slate
5621
                                             $1.length,
748 by Brian Aker
Removal of client side collation.
5622
                                             YYSession->variables.getCollation());
1 by brian
clean slate
5623
          }
5624
        | HEX_NUM
5625
          {
5626
            Item *tmp= new Item_hex_string($1.str, $1.length);
5627
            /*
5628
              it is OK only emulate fix_fields, because we need only
5629
              value of constant
5630
            */
5631
            $$= tmp ?
5632
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
5633
              (String*) 0;
5634
          }
5635
        | BIN_NUM
5636
          {
5637
            Item *tmp= new Item_bin_string($1.str, $1.length);
5638
            /*
5639
              it is OK only emulate fix_fields, because we need only
5640
              value of constant
5641
            */
5642
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str((String*) 0) :
5643
              (String*) 0;
5644
          }
5645
        ;
5646
5647
signed_literal:
5648
          literal { $$ = $1; }
5649
        | '+' NUM_literal { $$ = $2; }
5650
        | '-' NUM_literal
5651
          {
5652
            $2->max_length++;
5653
            $$= $2->neg();
5654
          }
5655
        ;
5656
5657
literal:
5658
          text_literal { $$ = $1; }
5659
        | NUM_literal { $$ = $1; }
5660
        | NULL_SYM
5661
          {
5662
            $$ = new Item_null();
520.1.22 by Brian Aker
Second pass of thd cleanup
5663
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
1 by brian
clean slate
5664
          }
5665
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5666
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
5667
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
5668
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
5669
        | DATE_SYM text_literal { $$ = $2; }
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
5670
        | TIMESTAMP_SYM text_literal { $$ = $2; }
1 by brian
clean slate
5671
        ;
5672
5673
NUM_literal:
5674
          NUM
5675
          {
5676
            int error;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
5677
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
1 by brian
clean slate
5678
          }
5679
        | LONG_NUM
5680
          {
5681
            int error;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
5682
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
1 by brian
clean slate
5683
          }
5684
        | ULONGLONG_NUM
5685
          { $$ = new Item_uint($1.str, $1.length); }
5686
        | DECIMAL_NUM
5687
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5688
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
5689
            if (YYSession->is_error())
1 by brian
clean slate
5690
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5691
              DRIZZLE_YYABORT;
1 by brian
clean slate
5692
            }
5693
          }
5694
        | FLOAT_NUM
5695
          {
5696
            $$ = new Item_float($1.str, $1.length);
520.1.22 by Brian Aker
Second pass of thd cleanup
5697
            if (YYSession->is_error())
1 by brian
clean slate
5698
            {
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5699
              DRIZZLE_YYABORT;
1 by brian
clean slate
5700
            }
5701
          }
5702
        ;
5703
5704
/**********************************************************************
5705
** Creating different items.
5706
**********************************************************************/
5707
5708
insert_ident:
5709
          simple_ident_nospvar { $$=$1; }
5710
        | table_wild { $$=$1; }
5711
        ;
5712
5713
table_wild:
5714
          ident '.' '*'
5715
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5716
            Select_Lex *sel= Lex->current_select;
461 by Monty Taylor
Removed NullS. bu-bye.
5717
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
1 by brian
clean slate
5718
            sel->with_wild++;
5719
          }
5720
        | ident '.' ident '.' '*'
5721
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5722
            Select_Lex *sel= Lex->current_select;
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
5723
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
1 by brian
clean slate
5724
            sel->with_wild++;
5725
          }
5726
        ;
5727
5728
order_ident:
5729
          expr { $$=$1; }
5730
        ;
5731
5732
simple_ident:
5733
          ident
5734
          {
5735
            {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5736
              Select_Lex *sel=Lex->current_select;
1 by brian
clean slate
5737
              $$= (sel->parsing_place != IN_HAVING ||
5738
                  sel->get_in_sum_expr() > 0) ?
461 by Monty Taylor
Removed NullS. bu-bye.
5739
                  (Item*) new Item_field(Lex->current_context(),
5740
                                         (const char *)NULL, NULL, $1.str) :
5741
                  (Item*) new Item_ref(Lex->current_context(),
5742
                                       (const char *)NULL, NULL, $1.str);
1 by brian
clean slate
5743
            }
5744
          }
5745
        | simple_ident_q { $$= $1; }
5746
        ;
5747
5748
simple_ident_nospvar:
5749
          ident
5750
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5751
            Select_Lex *sel=Lex->current_select;
1 by brian
clean slate
5752
            $$= (sel->parsing_place != IN_HAVING ||
5753
                sel->get_in_sum_expr() > 0) ?
461 by Monty Taylor
Removed NullS. bu-bye.
5754
                (Item*) new Item_field(Lex->current_context(),
5755
                                       (const char *)NULL, NULL, $1.str) :
5756
                (Item*) new Item_ref(Lex->current_context(),
5757
                                     (const char *)NULL, NULL, $1.str);
1 by brian
clean slate
5758
          }
5759
        | simple_ident_q { $$= $1; }
5760
        ;
5761
5762
simple_ident_q:
5763
          ident '.' ident
5764
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5765
            Session *session= YYSession;
5766
            LEX *lex= session->lex;
1 by brian
clean slate
5767
5768
            {
846 by Brian Aker
Removing on typedeffed class.
5769
              Select_Lex *sel= lex->current_select;
1 by brian
clean slate
5770
              if (sel->no_table_names_allowed)
5771
              {
5772
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
520.1.22 by Brian Aker
Second pass of thd cleanup
5773
                         MYF(0), $1.str, session->where);
1 by brian
clean slate
5774
              }
5775
              $$= (sel->parsing_place != IN_HAVING ||
5776
                  sel->get_in_sum_expr() > 0) ?
461 by Monty Taylor
Removed NullS. bu-bye.
5777
                  (Item*) new Item_field(Lex->current_context(),
5778
                                         (const char *)NULL, $1.str, $3.str) :
5779
                  (Item*) new Item_ref(Lex->current_context(),
5780
                                       (const char *)NULL, $1.str, $3.str);
1 by brian
clean slate
5781
            }
5782
          }
5783
        | '.' ident '.' ident
5784
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5785
            Session *session= YYSession;
5786
            LEX *lex= session->lex;
846 by Brian Aker
Removing on typedeffed class.
5787
            Select_Lex *sel= lex->current_select;
1 by brian
clean slate
5788
            if (sel->no_table_names_allowed)
5789
            {
5790
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
520.1.22 by Brian Aker
Second pass of thd cleanup
5791
                       MYF(0), $2.str, session->where);
1 by brian
clean slate
5792
            }
5793
            $$= (sel->parsing_place != IN_HAVING ||
5794
                sel->get_in_sum_expr() > 0) ?
461 by Monty Taylor
Removed NullS. bu-bye.
5795
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
5796
                (Item*) new Item_ref(Lex->current_context(),
5797
                                     (const char *)NULL, $2.str, $4.str);
1 by brian
clean slate
5798
          }
5799
        | ident '.' ident '.' ident
5800
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5801
            Session *session= YYSession;
5802
            LEX *lex= session->lex;
846 by Brian Aker
Removing on typedeffed class.
5803
            Select_Lex *sel= lex->current_select;
1 by brian
clean slate
5804
            if (sel->no_table_names_allowed)
5805
            {
5806
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
520.1.22 by Brian Aker
Second pass of thd cleanup
5807
                       MYF(0), $3.str, session->where);
1 by brian
clean slate
5808
            }
5809
            $$= (sel->parsing_place != IN_HAVING ||
5810
                sel->get_in_sum_expr() > 0) ?
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
5811
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
5812
                                       $5.str) :
5813
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
5814
                                     $5.str);
1 by brian
clean slate
5815
          }
5816
        ;
5817
5818
field_ident:
5819
          ident { $$=$1;}
5820
        | ident '.' ident '.' ident
5821
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5822
            TableList *table=
1101.2.4 by Monty Taylor
Fixed some small errors in previous patches.
5823
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
1 by brian
clean slate
5824
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5825
            {
5826
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5827
              DRIZZLE_YYABORT;
1 by brian
clean slate
5828
            }
5829
            if (my_strcasecmp(table_alias_charset, $3.str,
5830
                              table->table_name))
5831
            {
5832
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5833
              DRIZZLE_YYABORT;
1 by brian
clean slate
5834
            }
5835
            $$=$5;
5836
          }
5837
        | ident '.' ident
5838
          {
1101.2.2 by Monty Taylor
Removed the Select define in sql_yacc.yy. Bad general global define.
5839
            TableList *table=
1101.2.4 by Monty Taylor
Fixed some small errors in previous patches.
5840
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
1 by brian
clean slate
5841
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5842
            {
5843
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
5844
              DRIZZLE_YYABORT;
1 by brian
clean slate
5845
            }
5846
            $$=$3;
5847
          }
5848
        | '.' ident { $$=$2;} /* For Delphi */
5849
        ;
5850
5851
table_ident:
5852
          ident { $$=new Table_ident($1); }
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
5853
        | ident '.' ident { $$=new Table_ident($1,$3);}
1 by brian
clean slate
5854
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
5855
        ;
5856
5857
IDENT_sys:
5858
          IDENT { $$= $1; }
5859
        | IDENT_QUOTED
5860
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5861
            const CHARSET_INFO * const cs= system_charset_info;
5862
            int dummy_error;
5863
            uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
5864
                                                 $1.str+$1.length,
5865
                                                 $1.length, &dummy_error);
5866
            if (wlen < $1.length)
1 by brian
clean slate
5867
            {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5868
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
5869
                       cs->csname, $1.str + wlen);
5870
              DRIZZLE_YYABORT;
1 by brian
clean slate
5871
            }
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5872
            $$= $1;
1 by brian
clean slate
5873
          }
5874
        ;
5875
5876
TEXT_STRING_sys:
5877
          TEXT_STRING
5878
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5879
            $$= $1;
1 by brian
clean slate
5880
          }
5881
        ;
5882
5883
TEXT_STRING_literal:
5884
          TEXT_STRING
5885
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5886
            $$= $1;
1 by brian
clean slate
5887
          }
5888
        ;
5889
5890
TEXT_STRING_filesystem:
5891
          TEXT_STRING
5892
          {
929.1.2 by Brian Aker
Remove line conversions (it is all coming over the wire as UTf8)
5893
            $$= $1;
1 by brian
clean slate
5894
          }
5895
        ;
5896
5897
ident:
5898
          IDENT_sys    { $$=$1; }
5899
        | keyword
5900
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
5901
            Session *session= YYSession;
5902
            $$.str= session->strmake($1.str, $1.length);
1 by brian
clean slate
5903
            $$.length= $1.length;
5904
          }
5905
        ;
5906
5907
ident_or_text:
5908
          ident           { $$=$1;}
5909
        | TEXT_STRING_sys { $$=$1;}
5910
        | LEX_HOSTNAME { $$=$1;}
5911
        ;
5912
5913
/* Keyword that we allow for identifiers (except SP labels) */
5914
keyword:
5915
          keyword_sp            {}
5916
        | BEGIN_SYM             {}
5917
        | BYTE_SYM              {}
5918
        | CHECKSUM_SYM          {}
5919
        | CLOSE_SYM             {}
5920
        | COMMENT_SYM           {}
5921
        | COMMIT_SYM            {}
5922
        | CONTAINS_SYM          {}
5923
        | DEALLOCATE_SYM        {}
5924
        | END                   {}
5925
        | FLUSH_SYM             {}
5926
        | NO_SYM                {}
5927
        | OPEN_SYM              {}
5928
        | ROLLBACK_SYM          {}
5929
        | SAVEPOINT_SYM         {}
5930
        | SECURITY_SYM          {}
5931
        | SERVER_SYM            {}
5932
        | START_SYM             {}
5933
        | STOP_SYM              {}
5934
        | TRUNCATE_SYM          {}
5935
        ;
5936
5937
/*
5938
 * Keywords that we allow for labels in SPs.
5939
 * Anything that's the beginning of a statement or characteristics
5940
 * must be in keyword above, otherwise we get (harmful) shift/reduce
5941
 * conflicts.
5942
 */
5943
keyword_sp:
5944
          ACTION                   {}
5945
        | ADDDATE_SYM              {}
5946
        | AFTER_SYM                {}
5947
        | AGGREGATE_SYM            {}
5948
        | ANY_SYM                  {}
5949
        | AT_SYM                   {}
5950
        | AUTO_INC                 {}
5951
        | AVG_ROW_LENGTH           {}
5952
        | AVG_SYM                  {}
5953
        | BIT_SYM                  {}
5954
        | BOOL_SYM                 {}
5955
        | BOOLEAN_SYM              {}
5956
        | BTREE_SYM                {}
5957
        | CASCADED                 {}
5958
        | CHAIN_SYM                {}
5959
        | COALESCE                 {}
5960
        | COLLATION_SYM            {}
5961
        | COLUMN_FORMAT_SYM        {}
5962
        | COLUMNS                  {}
5963
        | COMMITTED_SYM            {}
5964
        | COMPACT_SYM              {}
5965
        | COMPRESSED_SYM           {}
5966
        | CONCURRENT               {}
5967
        | CONNECTION_SYM           {}
5968
        | CONSISTENT_SYM           {}
5969
        | CUBE_SYM                 {}
5970
        | DATA_SYM                 {}
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
5971
        | DATABASES                {}
1 by brian
clean slate
5972
        | DATAFILE_SYM             {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
5973
        | DATETIME_SYM             {}
1 by brian
clean slate
5974
        | DATE_SYM                 {}
5975
        | DAY_SYM                  {}
5976
        | DISABLE_SYM              {}
5977
        | DISCARD                  {}
5978
        | DUMPFILE                 {}
5979
        | DUPLICATE_SYM            {}
5980
        | DYNAMIC_SYM              {}
5981
        | ENDS_SYM                 {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
5982
        | ENUM_SYM                 {}
1 by brian
clean slate
5983
        | ENGINE_SYM               {}
5984
        | ERRORS                   {}
5985
        | ESCAPE_SYM               {}
5986
        | EXCLUSIVE_SYM            {}
5987
        | EXTENDED_SYM             {}
5988
        | FOUND_SYM                {}
5989
        | ENABLE_SYM               {}
5990
        | FULL                     {}
5991
        | FILE_SYM                 {}
5992
        | FIRST_SYM                {}
5993
        | FIXED_SYM                {}
5994
        | FRAC_SECOND_SYM          {}
5995
        | GLOBAL_SYM               {}
5996
        | HASH_SYM                 {}
5997
        | HOUR_SYM                 {}
5998
        | IDENTIFIED_SYM           {}
5999
        | IMPORT                   {}
6000
        | INDEXES                  {}
6001
        | ISOLATION                {}
6002
        | KEY_BLOCK_SIZE           {}
6003
        | LAST_SYM                 {}
6004
        | LEVEL_SYM                {}
6005
        | LIST_SYM                 {}
6006
        | LOCAL_SYM                {}
6007
        | LOCKS_SYM                {}
6008
        | LOGS_SYM                 {}
6009
        | MAX_ROWS                 {}
6010
        | MAX_SIZE_SYM             {}
6011
        | MAX_VALUE_SYM            {}
6012
        | MEDIUM_SYM               {}
6013
        | MERGE_SYM                {}
6014
        | MICROSECOND_SYM          {}
6015
        | MINUTE_SYM               {}
6016
        | MIN_ROWS                 {}
6017
        | MODIFY_SYM               {}
6018
        | MODE_SYM                 {}
6019
        | MONTH_SYM                {}
6020
        | NAME_SYM                 {}
6021
        | NAMES_SYM                {}
6022
        | NATIONAL_SYM             {}
6023
        | NEXT_SYM                 {}
6024
        | NEW_SYM                  {}
6025
        | NONE_SYM                 {}
6026
        | OFFLINE_SYM              {}
6027
        | OFFSET_SYM               {}
6028
        | ONE_SHOT_SYM             {}
6029
        | ONE_SYM                  {}
6030
        | ONLINE_SYM               {}
6031
        | PAGE_SYM                 {}
6032
        | PARTIAL                  {}
6033
        | PHASE_SYM                {}
6034
        | PREV_SYM                 {}
6035
        | PROCESS                  {}
6036
        | PROCESSLIST_SYM          {}
6037
        | QUARTER_SYM              {}
6038
        | QUERY_SYM                {}
6039
        | READ_ONLY_SYM            {}
6040
        | REDUNDANT_SYM            {}
6041
        | REPEATABLE_SYM           {}
6042
        | RETURNS_SYM              {}
6043
        | REVERSE_SYM              {}
6044
        | ROLLUP_SYM               {}
6045
        | ROUTINE_SYM              {}
6046
        | ROWS_SYM                 {}
6047
        | ROW_FORMAT_SYM           {}
6048
        | ROW_SYM                  {}
6049
        | SECOND_SYM               {}
6050
        | SERIAL_SYM               {}
6051
        | SERIALIZABLE_SYM         {}
6052
        | SESSION_SYM              {}
6053
        | SIMPLE_SYM               {}
6054
        | SHARE_SYM                {}
6055
        | SNAPSHOT_SYM             {}
6056
        | SQL_BUFFER_RESULT        {}
6057
        | STATUS_SYM               {}
6058
        | STORAGE_SYM              {}
6059
        | STRING_SYM               {}
6060
        | SUBDATE_SYM              {}
6061
        | SUBJECT_SYM              {}
6062
        | SUSPEND_SYM              {}
6063
        | SWAPS_SYM                {}
6064
        | SWITCHES_SYM             {}
6065
        | TABLES                   {}
108 by Brian Aker
Removed unwanted ALTER TABLESPACE, left in valuable bits.
6066
        | TABLESPACE               {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
6067
        | TEMPORARY_SYM            {}
1 by brian
clean slate
6068
        | TEXT_SYM                 {}
6069
        | TRANSACTION_SYM          {}
1008.3.17 by Stewart Smith
Start work to construct table proto in parser:
6070
        | TIMESTAMP_SYM            {}
1 by brian
clean slate
6071
        | TIMESTAMP_ADD            {}
6072
        | TIMESTAMP_DIFF           {}
6073
        | TYPES_SYM                {}
6074
        | TYPE_SYM                 {}
6075
        | UNCOMMITTED_SYM          {}
6076
        | UNDOFILE_SYM             {}
6077
        | UNKNOWN_SYM              {}
6078
        | USER                     {}
6079
        | VARIABLES                {}
6080
        | VALUE_SYM                {}
6081
        | WARNINGS                 {}
6082
        | WEEK_SYM                 {}
6083
        | WORK_SYM                 {}
6084
        | YEAR_SYM                 {}
6085
        ;
6086
6087
/* Option functions */
6088
6089
set:
6090
          SET opt_option
6091
          {
6092
            LEX *lex=Lex;
6093
            lex->sql_command= SQLCOM_SET_OPTION;
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
6094
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
6095
            lex->statement= statement;
1100.3.46 by Padraig O'Sullivan
Extracted the SET OPTION command into its own class and implementation
6096
            if (lex->statement == NULL)
6097
              DRIZZLE_YYABORT;
1 by brian
clean slate
6098
            mysql_init_select(lex);
6099
            lex->option_type=OPT_SESSION;
6100
            lex->var_list.empty();
6101
          }
6102
          option_value_list
6103
          {}
6104
        ;
6105
6106
opt_option:
6107
          /* empty */ {}
6108
        | OPTION {}
6109
        ;
6110
6111
option_value_list:
6112
          option_type_value
6113
        | option_value_list ',' option_type_value
6114
        ;
6115
6116
option_type_value:
6117
          {
6118
          }
6119
          ext_option_value
6120
          {
6121
          }
6122
        ;
6123
6124
option_type:
6125
          option_type2    {}
6126
        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
6127
        | LOCAL_SYM   { $$=OPT_SESSION; }
6128
        | SESSION_SYM { $$=OPT_SESSION; }
6129
        ;
6130
6131
option_type2:
6132
          /* empty */ { $$= OPT_DEFAULT; }
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
6133
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
1 by brian
clean slate
6134
        ;
6135
6136
opt_var_type:
6137
          /* empty */ { $$=OPT_SESSION; }
6138
        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
6139
        | LOCAL_SYM   { $$=OPT_SESSION; }
6140
        | SESSION_SYM { $$=OPT_SESSION; }
6141
        ;
6142
6143
opt_var_ident_type:
6144
          /* empty */     { $$=OPT_DEFAULT; }
6145
        | GLOBAL_SYM '.'  { $$=OPT_GLOBAL; }
6146
        | LOCAL_SYM '.'   { $$=OPT_SESSION; }
6147
        | SESSION_SYM '.' { $$=OPT_SESSION; }
6148
        ;
6149
6150
ext_option_value:
6151
          sys_option_value
6152
        | option_type2 option_value
6153
        ;
6154
6155
sys_option_value:
6156
          option_type internal_variable_name equal set_expr_or_default
6157
          {
6158
            LEX *lex=Lex;
6159
6160
            if ($2.var)
6161
            { /* System variable */
6162
              if ($1)
6163
                lex->option_type= $1;
6164
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
6165
                                      &$2.base_name, $4));
6166
            }
6167
          }
6168
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
6169
          {
6170
            LEX *lex=Lex;
6171
            lex->option_type= $1;
6172
            lex->var_list.push_back(new set_var(lex->option_type,
520.1.22 by Brian Aker
Second pass of thd cleanup
6173
                                                find_sys_var(YYSession, "tx_isolation"),
1 by brian
clean slate
6174
                                                &null_lex_str,
205 by Brian Aker
uint32 -> uin32_t
6175
                                                new Item_int((int32_t) $5)));
1 by brian
clean slate
6176
          }
6177
        ;
6178
6179
option_value:
6180
          '@' ident_or_text equal expr
6181
          {
6182
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
6183
          }
6184
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6185
          {
6186
            LEX *lex=Lex;
6187
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6188
          }
6189
        ;
6190
6191
internal_variable_name:
6192
          ident
6193
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
6194
            Session *session= YYSession;
1 by brian
clean slate
6195
6196
            /* We have to lookup here since local vars can shadow sysvars */
6197
            {
6198
              /* Not an SP local variable */
520.1.22 by Brian Aker
Second pass of thd cleanup
6199
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
1 by brian
clean slate
6200
              if (!tmp)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
6201
                DRIZZLE_YYABORT;
1 by brian
clean slate
6202
              $$.var= tmp;
6203
              $$.base_name= null_lex_str;
6204
            }
6205
          }
6206
        ;
6207
6208
isolation_types:
6209
          READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
6210
        | READ_SYM COMMITTED_SYM   { $$= ISO_READ_COMMITTED; }
6211
        | REPEATABLE_SYM READ_SYM  { $$= ISO_REPEATABLE_READ; }
6212
        | SERIALIZABLE_SYM         { $$= ISO_SERIALIZABLE; }
6213
        ;
6214
6215
set_expr_or_default:
6216
          expr { $$=$1; }
6217
        | DEFAULT { $$=0; }
6218
        | ON     { $$=new Item_string("ON",  2, system_charset_info); }
6219
        | ALL    { $$=new Item_string("ALL", 3, system_charset_info); }
6220
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
6221
        ;
6222
6223
table_or_tables:
6224
          TABLE_SYM
6225
        | TABLES
6226
        ;
6227
6228
unlock:
6229
          UNLOCK_SYM
6230
          {
6231
            LEX *lex= Lex;
6232
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
1100.3.31 by Padraig O'Sullivan
Extracted unlock tables into its own class and implementation files. Removed
6233
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
6234
            if (lex->statement == NULL)
6235
              DRIZZLE_YYABORT;
1 by brian
clean slate
6236
          }
6237
          table_or_tables
6238
          {}
6239
        ;
6240
6241
begin:
6242
          BEGIN_SYM
6243
          {
6244
            LEX *lex=Lex;
6245
            lex->sql_command = SQLCOM_BEGIN;
1100.3.60 by Padraig O'Sullivan
Changed the command Begin to StartTransaction based on code review comments
6246
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
1100.3.55 by Padraig O'Sullivan
Extracted the BEGIN command into its own class and implementation files.
6247
            if (lex->statement == NULL)
6248
              DRIZZLE_YYABORT;
1 by brian
clean slate
6249
          }
6250
          opt_work {}
6251
        ;
6252
6253
opt_work:
6254
          /* empty */ {}
6255
        | WORK_SYM  {}
6256
        ;
6257
6258
opt_chain:
6259
          /* empty */
520.1.22 by Brian Aker
Second pass of thd cleanup
6260
          { $$= (YYSession->variables.completion_type == 1); }
1 by brian
clean slate
6261
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
6262
        | AND_SYM CHAIN_SYM        { $$=1; }
6263
        ;
6264
6265
opt_release:
6266
          /* empty */
520.1.22 by Brian Aker
Second pass of thd cleanup
6267
          { $$= (YYSession->variables.completion_type == 2); }
1 by brian
clean slate
6268
        | RELEASE_SYM        { $$=1; }
6269
        | NO_SYM RELEASE_SYM { $$=0; }
6270
;
6271
6272
opt_savepoint:
6273
          /* empty */ {}
6274
        | SAVEPOINT_SYM {}
6275
        ;
6276
6277
commit:
6278
          COMMIT_SYM opt_work opt_chain opt_release
6279
          {
6280
            LEX *lex=Lex;
6281
            lex->sql_command= SQLCOM_COMMIT;
1128.2.12 by Brian Aker
A few more cleanups.
6282
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
6283
            lex->statement= statement;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
6284
            if (lex->statement == NULL)
1100.3.20 by Padraig O'Sullivan
Extracted the COMMIT command into its own class and implementation files.
6285
              DRIZZLE_YYABORT;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6286
            statement->tx_chain= $3;
1128.2.12 by Brian Aker
A few more cleanups.
6287
            statement->tx_release= $4;
1 by brian
clean slate
6288
          }
6289
        ;
6290
6291
rollback:
6292
          ROLLBACK_SYM opt_work opt_chain opt_release
6293
          {
6294
            LEX *lex=Lex;
6295
            lex->sql_command= SQLCOM_ROLLBACK;
1128.2.12 by Brian Aker
A few more cleanups.
6296
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
6297
            lex->statement= statement;
1100.3.30 by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to
6298
            if (lex->statement == NULL)
1100.3.21 by Padraig O'Sullivan
Extracted the ROLLBACK command into a class with its own implementation
6299
              DRIZZLE_YYABORT;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6300
            statement->tx_chain= $3;
1128.2.12 by Brian Aker
A few more cleanups.
6301
            statement->tx_release= $4;
1 by brian
clean slate
6302
          }
6303
        | ROLLBACK_SYM opt_work
6304
          TO_SYM opt_savepoint ident
6305
          {
6306
            LEX *lex=Lex;
6307
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
1100.3.52 by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and
6308
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
6309
            if (lex->statement == NULL)
6310
              DRIZZLE_YYABORT;
1 by brian
clean slate
6311
            lex->ident= $5;
6312
          }
6313
        ;
6314
6315
savepoint:
6316
          SAVEPOINT_SYM ident
6317
          {
6318
            LEX *lex=Lex;
6319
            lex->sql_command= SQLCOM_SAVEPOINT;
1100.3.51 by Padraig O'Sullivan
Extracted the SAVEPOINT command into its own class and implementation files.
6320
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
6321
            if (lex->statement == NULL)
6322
              DRIZZLE_YYABORT;
1 by brian
clean slate
6323
            lex->ident= $2;
6324
          }
6325
        ;
6326
6327
release:
6328
          RELEASE_SYM SAVEPOINT_SYM ident
6329
          {
6330
            LEX *lex=Lex;
6331
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
1100.3.54 by Padraig O'Sullivan
Extracted the RELEASE SAVEPOINT command into its own class and
6332
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
6333
            if (lex->statement == NULL)
6334
              DRIZZLE_YYABORT;
1 by brian
clean slate
6335
            lex->ident= $3;
6336
          }
6337
        ;
6338
6339
/*
6340
   UNIONS : glue selects together
6341
*/
6342
6343
6344
union_clause:
6345
          /* empty */ {}
6346
        | union_list
6347
        ;
6348
6349
union_list:
6350
          UNION_SYM union_option
6351
          {
1578.6.11 by Brian Aker
Additional removal of current_session
6352
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
6353
              DRIZZLE_YYABORT;
1 by brian
clean slate
6354
          }
6355
          select_init
6356
          {
6357
            /*
6358
              Remove from the name resolution context stack the context of the
6359
              last select in the union.
6360
            */
6361
            Lex->pop_context();
6362
          }
6363
        ;
6364
6365
union_opt:
6366
          /* Empty */ { $$= 0; }
6367
        | union_list { $$= 1; }
6368
        | union_order_or_limit { $$= 1; }
6369
        ;
6370
6371
union_order_or_limit:
6372
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
6373
            Session *session= YYSession;
6374
            LEX *lex= session->lex;
51.1.74 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
6375
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
846 by Brian Aker
Removing on typedeffed class.
6376
            Select_Lex *sel= lex->current_select;
849 by Brian Aker
Remove dead keywords.
6377
            Select_Lex_Unit *unit= sel->master_unit();
846 by Brian Aker
Removing on typedeffed class.
6378
            Select_Lex *fake= unit->fake_select_lex;
1 by brian
clean slate
6379
            if (fake)
6380
            {
6381
              unit->global_parameters= fake;
6382
              fake->no_table_names_allowed= 1;
6383
              lex->current_select= fake;
6384
            }
520.1.22 by Brian Aker
Second pass of thd cleanup
6385
            session->where= "global ORDER clause";
1 by brian
clean slate
6386
          }
6387
          order_or_limit
6388
          {
520.1.22 by Brian Aker
Second pass of thd cleanup
6389
            Session *session= YYSession;
6390
            session->lex->current_select->no_table_names_allowed= 0;
6391
            session->where= "";
1 by brian
clean slate
6392
          }
6393
        ;
6394
6395
order_or_limit:
6396
          order_clause opt_limit_clause_init
6397
        | limit_clause
6398
        ;
6399
6400
union_option:
6401
          /* empty */ { $$=1; }
6402
        | DISTINCT  { $$=1; }
6403
        | ALL       { $$=0; }
6404
        ;
6405
6406
query_specification:
6407
          SELECT_SYM select_init2_derived
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6408
          {
1 by brian
clean slate
6409
            $$= Lex->current_select->master_unit()->first_select();
6410
          }
6411
        | '(' select_paren_derived ')'
6412
          {
6413
            $$= Lex->current_select->master_unit()->first_select();
6414
          }
6415
        ;
6416
6417
query_expression_body:
6418
          query_specification
6419
        | query_expression_body
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6420
          UNION_SYM union_option
1 by brian
clean slate
6421
          {
1578.6.11 by Brian Aker
Additional removal of current_session
6422
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
6423
              DRIZZLE_YYABORT;
1 by brian
clean slate
6424
          }
6425
          query_specification
6426
          {
6427
            Lex->pop_context();
6428
            $$= $1;
6429
          }
6430
        ;
6431
6432
/* Corresponds to <query expression> in the SQL:2003 standard. */
6433
subselect:
6434
          subselect_start query_expression_body subselect_end
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6435
          {
1 by brian
clean slate
6436
            $$= $2;
6437
          }
6438
        ;
6439
6440
subselect_start:
6441
          {
6442
            LEX *lex=Lex;
798.2.10 by Brian Aker
Remove COM bits for replication
6443
            if (!lex->expr_allows_subselect)
1 by brian
clean slate
6444
            {
1578.6.11 by Brian Aker
Additional removal of current_session
6445
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
6446
              my_parse_error(&pass);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
6447
              DRIZZLE_YYABORT;
1 by brian
clean slate
6448
            }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6449
            /*
1 by brian
clean slate
6450
              we are making a "derived table" for the parenthesis
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
6451
              as we need to have a lex level to fit the union
6452
              after the parenthesis, e.g.
6453
              (SELECT .. ) UNION ...  becomes
1 by brian
clean slate
6454
              SELECT * FROM ((SELECT ...) UNION ...)
6455
            */
6456
            if (mysql_new_select(Lex, 1))
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
6457
              DRIZZLE_YYABORT;
1 by brian
clean slate
6458
          }
6459
        ;
6460
6461
subselect_end:
6462
          {
6463
            LEX *lex=Lex;
6464
            lex->pop_context();
846 by Brian Aker
Removing on typedeffed class.
6465
            Select_Lex *child= lex->current_select;
1 by brian
clean slate
6466
            lex->current_select = lex->current_select->return_after_parsing();
6467
            lex->nest_level--;
6468
            lex->current_select->n_child_sum_items += child->n_sum_items;
6469
            /*
6470
              A subselect can add fields to an outer select. Reserve space for
6471
              them.
6472
            */
6473
            lex->current_select->select_n_where_fields+=
6474
            child->select_n_where_fields;
6475
          }
6476
        ;
6477
/**
6478
  @} (end of group Parser)
6479
*/