~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
/* sql_yacc.yy */
17
17
 
38
38
#define Lex (YYSession->lex)
39
39
 
40
40
#include "config.h"
 
41
#include <cstdio>
41
42
#include "drizzled/parser.h"
42
43
 
43
44
int yylex(void *yylval, void *yysession);
44
45
 
45
46
#define yyoverflow(A,B,C,D,E,F)               \
46
47
  {                                           \
47
 
    ulong val= *(F);                          \
 
48
    unsigned long val= *(F);                          \
48
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
49
50
    {                                         \
50
51
      yyerror((char*) (A));                   \
59
60
#define DRIZZLE_YYABORT                         \
60
61
  do                                          \
61
62
  {                                           \
62
 
    LEX::cleanup_lex_after_parse_error(YYSession);\
63
63
    YYABORT;                                  \
64
64
  } while (0)
65
65
 
66
66
#define DRIZZLE_YYABORT_UNLESS(A)         \
67
67
  if (!(A))                             \
68
68
  {                                     \
69
 
    my_parse_error(ER(ER_SYNTAX_ERROR));\
 
69
    parser::my_parse_error(YYSession->m_lip);\
70
70
    DRIZZLE_YYABORT;                      \
71
71
  }
72
72
 
80
80
class Item;
81
81
class Item_num;
82
82
 
83
 
 
84
 
static bool check_reserved_words(LEX_STRING *name)
85
 
{
86
 
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
87
 
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
88
 
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
89
 
    return true;
90
 
  return false;
91
 
}
92
 
 
93
 
/**
94
 
  @brief Push an error message into MySQL error stack with line
95
 
  and position information.
96
 
 
97
 
  This function provides semantic action implementers with a way
98
 
  to push the famous "You have a syntax error near..." error
99
 
  message into the error stack, which is normally produced only if
100
 
  a parse error is discovered internally by the Bison generated
101
 
  parser.
102
 
*/
103
 
 
104
 
static void my_parse_error(const char *s)
105
 
{
106
 
  Session *session= current_session;
107
 
  Lex_input_stream *lip= session->m_lip;
108
 
 
109
 
  const char *yytext= lip->get_tok_start();
110
 
  /* Push an error into the error stack */
111
 
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
112
 
                  (yytext ? yytext : ""),
113
 
                  lip->yylineno);
114
 
}
 
83
namespace item
 
84
{
 
85
class Boolean;
 
86
class True;
 
87
class False;
 
88
}
 
89
 
115
90
 
116
91
/**
117
92
  @brief Bison callback to report a syntax/OOM error
128
103
 
129
104
  This function is not for use in semantic actions and is internal to
130
105
  the parser, as it performs some pre-return cleanup.
131
 
  In semantic actions, please use my_parse_error or my_error to
 
106
  In semantic actions, please use parser::my_parse_error or my_error to
132
107
  push an error into the error stack and DRIZZLE_YYABORT
133
108
  to abort from the parser.
134
109
*/
135
110
 
136
111
static void DRIZZLEerror(const char *s)
137
112
{
138
 
  Session *session= current_session;
139
 
 
140
 
  /*
141
 
    Restore the original LEX if it was replaced when parsing
142
 
    a stored procedure. We must ensure that a parsing error
143
 
    does not leave any side effects in the Session.
144
 
  */
145
 
  LEX::cleanup_lex_after_parse_error(session);
146
 
 
147
 
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
148
 
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
149
 
    s= ER(ER_SYNTAX_ERROR);
150
 
  my_parse_error(s);
151
 
}
152
 
 
153
 
/**
154
 
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
155
 
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
156
 
  This function returns the proper item for the SQL expression
157
 
  <code>left [NOT] IN ( expr )</code>
158
 
  @param session the current thread
159
 
  @param left the in predicand
160
 
  @param equal true for IN predicates, false for NOT IN predicates
161
 
  @param expr first and only expression of the in value list
162
 
  @return an expression representing the IN predicate.
163
 
*/
164
 
static Item* handle_sql2003_note184_exception(Session *session,
165
 
                                              Item* left, bool equal,
166
 
                                              Item *expr)
167
 
{
168
 
  /*
169
 
    Relevant references for this issue:
170
 
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
171
 
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
172
 
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
173
 
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
174
 
    - SQL:2003 Feature F561, "Full value expressions".
175
 
 
176
 
    The exception in SQL:2003 Note 184 means:
177
 
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
178
 
    should be re-interpreted as an Item_in_subselect, which corresponds
179
 
    to a <table subquery> when used inside an <in predicate>.
180
 
 
181
 
    Our reading of Note 184 is reccursive, so that all:
182
 
    - IN (( <subquery> ))
183
 
    - IN ((( <subquery> )))
184
 
    - IN '('^N <subquery> ')'^N
185
 
    - etc
186
 
    should be interpreted as a <table subquery>, no matter how deep in the
187
 
    expression the <subquery> is.
188
 
  */
189
 
 
190
 
  Item *result;
191
 
 
192
 
  if (expr->type() == Item::SUBSELECT_ITEM)
193
 
  {
194
 
    Item_subselect *expr2 = (Item_subselect*) expr;
195
 
 
196
 
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
197
 
    {
198
 
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
199
 
      Select_Lex *subselect;
200
 
 
201
 
      /*
202
 
        Implement the mandated change, by altering the semantic tree:
203
 
          left IN Item_singlerow_subselect(subselect)
204
 
        is modified to
205
 
          left IN (subselect)
206
 
        which is represented as
207
 
          Item_in_subselect(left, subselect)
208
 
      */
209
 
      subselect= expr3->invalidate_and_restore_select_lex();
210
 
      result= new (session->mem_root) Item_in_subselect(left, subselect);
211
 
 
212
 
      if (! equal)
213
 
        result = negate_expression(session, result);
214
 
 
215
 
      return(result);
216
 
    }
217
 
  }
218
 
 
219
 
  if (equal)
220
 
    result= new (session->mem_root) Item_func_eq(left, expr);
221
 
  else
222
 
    result= new (session->mem_root) Item_func_ne(left, expr);
223
 
 
224
 
  return(result);
225
 
}
226
 
 
227
 
/**
228
 
   @brief Creates a new Select_Lex for a UNION branch.
229
 
 
230
 
   Sets up and initializes a Select_Lex structure for a query once the parser
231
 
   discovers a UNION token. The current Select_Lex is pushed on the stack and
232
 
   the new Select_Lex becomes the current one..=
233
 
 
234
 
   @lex The parser state.
235
 
 
236
 
   @is_union_distinct True if the union preceding the new select statement
237
 
   uses UNION DISTINCT.
238
 
 
239
 
   @return <code>false</code> if successful, <code>true</code> if an error was
240
 
   reported. In the latter case parsing should stop.
241
 
 */
242
 
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
243
 
{
244
 
  if (lex->result)
245
 
  {
246
 
    /* Only the last SELECT can have  INTO...... */
247
 
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
248
 
    return true;
249
 
  }
250
 
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
251
 
  {
252
 
    my_parse_error(ER(ER_SYNTAX_ERROR));
253
 
    return true;
254
 
  }
255
 
  /* This counter shouldn't be incremented for UNION parts */
256
 
  lex->nest_level--;
257
 
  if (mysql_new_select(lex, 0))
258
 
    return true;
259
 
  mysql_init_select(lex);
260
 
  lex->current_select->linkage=UNION_TYPE;
261
 
  if (is_union_distinct) /* UNION DISTINCT - remember position */
262
 
    lex->current_select->master_unit()->union_distinct=
263
 
      lex->current_select;
264
 
  return false;
265
 
}
266
 
 
267
 
/**
268
 
   @brief Initializes a Select_Lex for a query within parentheses (aka
269
 
   braces).
270
 
 
271
 
   @return false if successful, true if an error was reported. In the latter
272
 
   case parsing should stop.
273
 
 */
274
 
static bool setup_select_in_parentheses(LEX *lex)
275
 
{
276
 
  Select_Lex * sel= lex->current_select;
277
 
  if (sel->set_braces(1))
278
 
  {
279
 
    my_parse_error(ER(ER_SYNTAX_ERROR));
280
 
    return true;
281
 
  }
282
 
  if (sel->linkage == UNION_TYPE &&
283
 
      !sel->master_unit()->first_select()->braces &&
284
 
      sel->master_unit()->first_select()->linkage ==
285
 
      UNION_TYPE)
286
 
  {
287
 
    my_parse_error(ER(ER_SYNTAX_ERROR));
288
 
    return true;
289
 
  }
290
 
  if (sel->linkage == UNION_TYPE &&
291
 
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
292
 
      sel->master_unit()->fake_select_lex)
293
 
  {
294
 
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
295
 
    return true;
296
 
  }
297
 
  /* select in braces, can't contain global parameters */
298
 
  if (sel->master_unit()->fake_select_lex)
299
 
    sel->master_unit()->global_parameters=
300
 
      sel->master_unit()->fake_select_lex;
301
 
  return false;
302
 
}
303
 
 
304
 
static Item* reserved_keyword_function(const std::string &name, List<Item> *item_list)
305
 
{
306
 
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
307
 
  Item *item= NULL;
308
 
 
309
 
  if (udf)
310
 
  {
311
 
    item= Create_udf_func::s_singleton.create(current_session, udf, item_list);
312
 
  } else {
313
 
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
314
 
  }
315
 
 
316
 
  return item;
 
113
  parser::errorOn(s);
317
114
}
318
115
 
319
116
} /* namespace drizzled; */
321
118
using namespace drizzled;
322
119
%}
323
120
%union {
 
121
  bool boolean;
324
122
  int  num;
325
 
  ulong ulong_num;
 
123
  unsigned long ulong_num;
326
124
  uint64_t ulonglong_number;
327
125
  int64_t longlong_number;
328
126
  drizzled::LEX_STRING lex_str;
338
136
  drizzled::Key_part_spec *key_part;
339
137
  const drizzled::plugin::Function *udf;
340
138
  drizzled::TableList *table_list;
341
 
  struct drizzled::sys_var_with_base variable;
342
 
  enum drizzled::sql_var_t var_type;
 
139
  drizzled::enum_field_types field_val;
 
140
  drizzled::sys_var_with_base variable;
 
141
  drizzled::sql_var_t var_type;
343
142
  drizzled::Key::Keytype key_type;
344
 
  enum drizzled::ha_key_alg key_alg;
345
 
  enum drizzled::row_type row_type;
346
 
  enum drizzled::column_format_type column_format_type;
347
 
  enum drizzled::ha_rkey_function ha_rkey_mode;
348
 
  enum drizzled::enum_tx_isolation tx_isolation;
349
 
  enum drizzled::Cast_target cast_type;
 
143
  drizzled::ha_key_alg key_alg;
 
144
  drizzled::ha_rkey_function ha_rkey_mode;
 
145
  drizzled::enum_tx_isolation tx_isolation;
 
146
  drizzled::Cast_target cast_type;
350
147
  const drizzled::CHARSET_INFO *charset;
351
148
  drizzled::thr_lock_type lock_type;
352
149
  drizzled::interval_type interval, interval_time_st;
353
 
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
 
150
  drizzled::type::timestamp_t date_time_type;
354
151
  drizzled::Select_Lex *select_lex;
355
152
  drizzled::chooser_compare_func_creator boolfunc2creator;
356
 
  struct drizzled::st_lex *lex;
357
 
  enum drizzled::index_hint_type index_hint;
358
 
  enum drizzled::enum_filetype filetype;
359
 
  enum drizzled::ha_build_method build_method;
360
 
  enum drizzled::Foreign_key::fk_option m_fk_option;
 
153
  drizzled::st_lex *lex;
 
154
  drizzled::index_hint_type index_hint;
 
155
  drizzled::enum_filetype filetype;
 
156
  drizzled::ha_build_method build_method;
 
157
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
 
158
  drizzled::execute_string_t execute_string;
361
159
}
362
160
 
363
161
%{
364
162
namespace drizzled
365
163
{
366
 
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 
164
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
367
165
}
368
166
%}
369
167
 
 
168
%debug
370
169
%pure_parser                                    /* We have threads */
 
170
 
371
171
/*
372
 
  Currently there are 88 shift/reduce conflicts.
 
172
  Currently there are 70 shift/reduce conflicts.
373
173
  We should not introduce new conflicts any more.
374
174
*/
375
 
%expect 88
 
175
%expect 70
376
176
 
377
177
/*
378
178
   Comments for TOKENS.
393
193
 
394
194
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
395
195
%token  ACTION                        /* SQL-2003-N */
396
 
%token  ADD                           /* SQL-2003-R */
 
196
%token  ADD_SYM                           /* SQL-2003-R */
397
197
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
398
198
%token  AFTER_SYM                     /* SQL-2003-N */
399
199
%token  AGGREGATE_SYM
400
200
%token  ALL                           /* SQL-2003-R */
401
 
%token  ALTER                         /* SQL-2003-R */
 
201
%token  ALTER_SYM                         /* SQL-2003-R */
402
202
%token  ANALYZE_SYM
403
203
%token  AND_SYM                       /* SQL-2003-R */
404
204
%token  ANY_SYM                       /* SQL-2003-R */
407
207
%token  ASENSITIVE_SYM                /* FUTURE-USE */
408
208
%token  AT_SYM                        /* SQL-2003-R */
409
209
%token  AUTO_INC
410
 
%token  AVG_ROW_LENGTH
411
210
%token  AVG_SYM                       /* SQL-2003-N */
412
211
%token  BEFORE_SYM                    /* SQL-2003-N */
413
212
%token  BEGIN_SYM                     /* SQL-2003-R */
417
216
%token  BIN_NUM
418
217
%token  BIT_SYM                       /* MYSQL-FUNC */
419
218
%token  BLOB_SYM                      /* SQL-2003-R */
420
 
%token  BLOCK_SIZE_SYM
421
 
%token  BLOCK_SYM
422
219
%token  BOOLEAN_SYM                   /* SQL-2003-R */
423
220
%token  BOOL_SYM
424
221
%token  BOTH                          /* SQL-2003-R */
425
222
%token  BTREE_SYM
426
223
%token  BY                            /* SQL-2003-R */
427
 
%token  BYTE_SYM
428
224
%token  CALL_SYM                      /* SQL-2003-R */
429
225
%token  CASCADE                       /* SQL-2003-N */
430
226
%token  CASCADED                      /* SQL-2003-R */
431
227
%token  CASE_SYM                      /* SQL-2003-R */
432
228
%token  CAST_SYM                      /* SQL-2003-R */
 
229
%token  CATALOG_SYM
433
230
%token  CHAIN_SYM                     /* SQL-2003-N */
434
 
%token  CHANGE
 
231
%token  CHANGE_SYM
435
232
%token  CHAR_SYM                      /* SQL-2003-R */
436
233
%token  CHECKSUM_SYM
437
234
%token  CHECK_SYM                     /* SQL-2003-R */
452
249
%token  CONSISTENT_SYM
453
250
%token  CONSTRAINT                    /* SQL-2003-R */
454
251
%token  CONTAINS_SYM                  /* SQL-2003-N */
455
 
%token  CONTINUE_SYM                  /* SQL-2003-R */
456
252
%token  CONVERT_SYM                   /* SQL-2003-N */
457
253
%token  COUNT_SYM                     /* SQL-2003-N */
458
254
%token  CREATE                        /* SQL-2003-R */
463
259
%token  CURSOR_SYM                    /* SQL-2003-R */
464
260
%token  DATABASE
465
261
%token  DATABASES
466
 
%token  DATAFILE_SYM
467
262
%token  DATA_SYM                      /* SQL-2003-N */
468
263
%token  DATETIME_SYM
469
264
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
487
282
%token  DISCARD
488
283
%token  DISTINCT                      /* SQL-2003-R */
489
284
%token  DIV_SYM
 
285
%token  DO_SYM
490
286
%token  DOUBLE_SYM                    /* SQL-2003-R */
491
287
%token  DROP                          /* SQL-2003-R */
492
288
%token  DUMPFILE
494
290
%token  DYNAMIC_SYM                   /* SQL-2003-R */
495
291
%token  EACH_SYM                      /* SQL-2003-R */
496
292
%token  ELSE                          /* SQL-2003-R */
497
 
%token  ELSEIF_SYM
498
293
%token  ENABLE_SYM
499
294
%token  ENCLOSED
500
295
%token  END                           /* SQL-2003-R */
508
303
%token  ESCAPED
509
304
%token  ESCAPE_SYM                    /* SQL-2003-R */
510
305
%token  EXCLUSIVE_SYM
 
306
%token  EXECUTE_SYM                   /* SQL-2003-R */
511
307
%token  EXISTS                        /* SQL-2003-R */
512
308
%token  EXTENDED_SYM
513
309
%token  EXTRACT_SYM                   /* SQL-2003-N */
514
310
%token  FALSE_SYM                     /* SQL-2003-R */
515
 
%token  FETCH_SYM                     /* SQL-2003-R */
516
 
%token  COLUMN_FORMAT_SYM
517
311
%token  FILE_SYM
518
312
%token  FIRST_SYM                     /* SQL-2003-N */
519
313
%token  FIXED_SYM
540
334
%token  HOUR_SYM                      /* SQL-2003-R */
541
335
%token  IDENT
542
336
%token  IDENTIFIED_SYM
 
337
%token  IDENTITY_SYM                  /* SQL-2003-R */
543
338
%token  IDENT_QUOTED
544
339
%token  IF
545
340
%token  IGNORE_SYM
572
367
%token  LIKE                          /* SQL-2003-R */
573
368
%token  LIMIT
574
369
%token  LINES
575
 
%token  LIST_SYM
576
370
%token  LOAD
577
371
%token  LOCAL_SYM                     /* SQL-2003-R */
578
 
%token  LOCATOR_SYM                   /* SQL-2003-N */
579
372
%token  LOCKS_SYM
580
373
%token  LOCK_SYM
581
374
%token  LOGS_SYM
582
375
%token  LONG_NUM
583
376
%token  LONG_SYM
584
 
%token  LOOP_SYM
585
377
%token  LT                            /* OPERATOR */
586
378
%token  MATCH                         /* SQL-2003-R */
587
 
%token  MAX_ROWS
588
 
%token  MAX_SIZE_SYM
589
379
%token  MAX_SYM                       /* SQL-2003-N */
590
380
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
591
381
%token  MEDIUM_SYM
594
384
%token  MINUTE_MICROSECOND_SYM
595
385
%token  MINUTE_SECOND_SYM
596
386
%token  MINUTE_SYM                    /* SQL-2003-R */
597
 
%token  MIN_ROWS
598
387
%token  MIN_SYM                       /* SQL-2003-N */
599
388
%token  MODE_SYM
600
389
%token  MODIFIES_SYM                  /* SQL-2003-R */
631
420
%token  OUTER
632
421
%token  OUTFILE
633
422
%token  OUT_SYM                       /* SQL-2003-R */
634
 
%token  PAGE_SYM
635
423
%token  PARTIAL                       /* SQL-2003-N */
636
 
%token  PHASE_SYM
637
424
%token  POSITION_SYM                  /* SQL-2003-N */
638
425
%token  PRECISION                     /* SQL-2003-R */
639
426
%token  PREV_SYM
644
431
%token  QUERY_SYM
645
432
%token  RANGE_SYM                     /* SQL-2003-R */
646
433
%token  READS_SYM                     /* SQL-2003-R */
647
 
%token  READ_ONLY_SYM
648
434
%token  READ_SYM                      /* SQL-2003-N */
649
435
%token  READ_WRITE_SYM
650
436
%token  REAL                          /* SQL-2003-R */
651
437
%token  REDUNDANT_SYM
 
438
%token  REGEXP_SYM
652
439
%token  REFERENCES                    /* SQL-2003-R */
653
440
%token  RELEASE_SYM                   /* SQL-2003-R */
654
441
%token  RENAME
658
445
%token  RESTRICT
659
446
%token  RETURNS_SYM                   /* SQL-2003-R */
660
447
%token  RETURN_SYM                    /* SQL-2003-R */
661
 
%token  REVERSE_SYM
662
448
%token  REVOKE                        /* SQL-2003-R */
663
449
%token  RIGHT                         /* SQL-2003-R */
664
450
%token  ROLLBACK_SYM                  /* SQL-2003-R */
678
464
%token  SERIAL_SYM
679
465
%token  SESSION_SYM                   /* SQL-2003-N */
680
466
%token  SERVER_SYM
681
 
%token  SERVER_OPTIONS
682
 
%token  SET                           /* SQL-2003-R */
 
467
%token  SET_SYM                           /* SQL-2003-R */
683
468
%token  SET_VAR
684
469
%token  SHARE_SYM
685
470
%token  SHOW
686
 
%token  SHUTDOWN
 
471
%token  SIGNED_SYM
687
472
%token  SIMPLE_SYM                    /* SQL-2003-N */
688
473
%token  SNAPSHOT_SYM
689
474
%token  SPECIFIC_SYM                  /* SQL-2003-R */
701
486
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
702
487
%token  STD_SYM
703
488
%token  STOP_SYM
704
 
%token  STORAGE_SYM
705
489
%token  STORED_SYM
706
490
%token  STRAIGHT_JOIN
707
491
%token  STRING_SYM
710
494
%token  SUBSTRING                     /* SQL-2003-N */
711
495
%token  SUM_SYM                       /* SQL-2003-N */
712
496
%token  SUSPEND_SYM
713
 
%token  SWAPS_SYM
714
 
%token  SWITCHES_SYM
715
497
%token  SYSDATE
716
498
%token  TABLES
717
499
%token  TABLESPACE
722
504
%token  TEXT_STRING
723
505
%token  TEXT_SYM
724
506
%token  THEN_SYM                      /* SQL-2003-R */
 
507
%token  TIME_SYM                 /* SQL-2003-R */
725
508
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
726
509
%token  TIMESTAMP_ADD
727
510
%token  TIMESTAMP_DIFF
731
514
%token  TRIM                          /* SQL-2003-N */
732
515
%token  TRUE_SYM                      /* SQL-2003-R */
733
516
%token  TRUNCATE_SYM
734
 
%token  TYPES_SYM
735
517
%token  TYPE_SYM                      /* SQL-2003-N */
736
518
%token  ULONGLONG_NUM
737
519
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
741
523
%token  UNIQUE_SYM
742
524
%token  UNKNOWN_SYM                   /* SQL-2003-R */
743
525
%token  UNLOCK_SYM
 
526
%token  UNSIGNED_SYM
744
527
%token  UPDATE_SYM                    /* SQL-2003-R */
745
528
%token  USAGE                         /* SQL-2003-N */
746
529
%token  USER                          /* SQL-2003-R */
748
531
%token  USING                         /* SQL-2003-R */
749
532
%token  UTC_DATE_SYM
750
533
%token  UTC_TIMESTAMP_SYM
 
534
%token  UUID_SYM
751
535
%token  VALUES                        /* SQL-2003-R */
752
536
%token  VALUE_SYM                     /* SQL-2003-R */
753
537
%token  VARBINARY
756
540
%token  VARIANCE_SYM
757
541
%token  VARYING                       /* SQL-2003-R */
758
542
%token  VAR_SAMP_SYM
 
543
%token  WAIT_SYM
759
544
%token  WARNINGS
760
545
%token  WEEK_SYM
761
546
%token  WHEN_SYM                      /* SQL-2003-R */
767
552
%token  XOR
768
553
%token  YEAR_MONTH_SYM
769
554
%token  YEAR_SYM                      /* SQL-2003-R */
 
555
%token  ZEROFILL_SYM
770
556
 
771
557
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
772
558
/* A dummy token to force the priority of table_ref production in a join. */
776
562
%left   XOR
777
563
%left   AND_SYM
778
564
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
779
 
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
 
565
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP_SYM IN_SYM
780
566
%left   '-' '+'
781
567
%left   '*' '/' '%' DIV_SYM MOD_SYM
782
568
%left   NEG
786
572
 
787
573
%type <lex_str>
788
574
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
789
 
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
 
575
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
 
576
        ident
 
577
        ident_or_text
 
578
        internal_variable_ident
 
579
        user_variable_ident
 
580
        row_format_or_text
790
581
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
 
582
        schema_name
 
583
        catalog_name
791
584
        opt_component
792
 
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
585
        engine_option_value
 
586
        savepoint_ident
 
587
        BIN_NUM TEXT_STRING_filesystem
793
588
        opt_constraint constraint opt_ident
794
589
 
 
590
%type <execute_string>
 
591
        execute_var_or_string
 
592
 
795
593
%type <lex_str_ptr>
796
594
        opt_table_alias
797
595
 
804
602
%type <string>
805
603
        text_string opt_gconcat_separator
806
604
 
 
605
%type <field_val>
 
606
      field_definition
 
607
      int_type
 
608
      real_type
 
609
 
 
610
%type <boolean>
 
611
        opt_wait
 
612
        opt_concurrent
 
613
        opt_status
 
614
        opt_zerofill
 
615
        opt_if_not_exists
 
616
        if_exists 
 
617
        opt_temporary 
 
618
        opt_field_number_signed
 
619
 
807
620
%type <num>
808
 
        type int_type real_type order_dir field_def
809
 
        if_exists opt_table_options
810
 
        opt_if_not_exists
811
 
        opt_temporary all_or_any opt_distinct
 
621
        order_dir
 
622
        field_def
 
623
        opt_table_options
 
624
        all_or_any opt_distinct
812
625
        union_option
813
626
        start_transaction_opts opt_chain opt_release
814
627
        union_opt select_derived_init option_type2
 
628
        kill_option
815
629
 
816
630
%type <m_fk_option>
817
631
        delete_option
833
647
        table_wild simple_expr udf_expr
834
648
        expr_or_default set_expr_or_default
835
649
        signed_literal now_or_signed_literal opt_escape
836
 
        simple_ident_nospvar simple_ident_q
 
650
        simple_ident_q
837
651
        field_or_var limit_option
838
652
        function_call_keyword
839
653
        function_call_nonkeyword
873
687
 
874
688
%type <interval_time_st> interval_time_stamp
875
689
 
876
 
%type <row_type> row_types
877
 
 
878
 
%type <column_format_type> column_format_types
879
 
 
880
690
%type <tx_isolation> isolation_types
881
691
 
882
692
%type <cast_type> cast_type
883
693
 
884
 
%type <symbol> keyword keyword_sp
 
694
%type <symbol>
 
695
        keyword
 
696
        keyword_sp
 
697
        keyword_exception_for_variable
 
698
        row_format
885
699
 
886
700
%type <charset>
887
701
        collation_name
902
716
        insert_values update delete truncate rename
903
717
        show describe load alter flush
904
718
        begin commit rollback savepoint release
905
 
        analyze check start checksum
 
719
        analyze check start
906
720
        field_list field_list_item field_spec kill column_def key_def
907
721
        select_item_list select_item values_list no_braces
908
722
        opt_limit_clause delete_limit_clause fields opt_values values
916
730
        flush_options flush_option
917
731
        equal optional_braces
918
732
        normal_join
919
 
        table_to_table_list table_to_table opt_table_list opt_as
 
733
        table_to_table_list table_to_table opt_table_list
920
734
        single_multi
921
735
        union_clause union_list
922
736
        precision subselect_start
923
737
        subselect_end select_var_list select_var_list_init opt_len
924
738
        opt_extended_describe
925
739
        statement
 
740
        execute
926
741
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
927
742
        init_key_options key_options key_opts key_opt key_using_alg
928
743
END_OF_INPUT
969
784
            }
970
785
            else
971
786
            {
972
 
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
973
 
              session->lex->statement=
974
 
                new(std::nothrow) statement::EmptyQuery(YYSession);
975
 
              if (session->lex->statement == NULL)
976
 
                DRIZZLE_YYABORT;
 
787
              session->lex->statement= new statement::EmptyQuery(YYSession);
977
788
            }
978
789
          }
979
790
        | verb_clause END_OF_INPUT {}
989
800
          alter
990
801
        | analyze
991
802
        | check
992
 
        | checksum
993
803
        | commit
994
804
        | create
995
805
        | delete
996
806
        | describe
997
807
        | drop
 
808
        | execute
998
809
        | flush
999
810
        | insert
1000
811
        | kill
1017
828
/* create a table */
1018
829
 
1019
830
create:
1020
 
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1021
 
          {
1022
 
            Session *session= YYSession;
1023
 
            LEX *lex= session->lex;
1024
 
            lex->sql_command= SQLCOM_CREATE_TABLE;
1025
 
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1026
 
            lex->statement= statement;
1027
 
            if (lex->statement == NULL)
1028
 
              DRIZZLE_YYABORT;
1029
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1030
 
                                                   TL_OPTION_UPDATING,
1031
 
                                                   TL_WRITE))
1032
 
              DRIZZLE_YYABORT;
1033
 
            lex->col_list.empty();
1034
 
            statement->change=NULL;
1035
 
            statement->is_if_not_exists= $4;
1036
 
            statement->create_info.db_type= NULL;
1037
 
            statement->create_info.default_table_charset= NULL;
1038
 
            lex->name.str= 0;
 
831
          CREATE CATALOG_SYM catalog_name
 
832
          {
 
833
            Lex->statement= new statement::catalog::Create(YYSession, $3);
 
834
          }
 
835
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
836
          {
 
837
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
1039
838
 
1040
 
            message::Table &proto= statement->create_table_message;
1041
 
           
1042
 
            proto.set_name($5->table.str);
1043
 
            if ($2)
1044
 
              proto.set_type(message::Table::TEMPORARY);
1045
 
            else
1046
 
              proto.set_type(message::Table::STANDARD);
 
839
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
 
840
                                                     TL_OPTION_UPDATING,
 
841
                                                     TL_WRITE))
 
842
              DRIZZLE_YYABORT;
 
843
            Lex->col_list.empty();
1047
844
          }
1048
 
          create2
 
845
          create_table_definition
1049
846
          {
1050
 
            LEX *lex= YYSession->lex;
1051
 
            lex->current_select= &lex->select_lex;
 
847
            Lex->current_select= &Lex->select_lex;
1052
848
          }
1053
849
        | CREATE build_method
1054
850
          {
1055
 
            LEX *lex=Lex;
1056
 
            lex->sql_command= SQLCOM_CREATE_INDEX;
1057
 
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1058
 
            lex->statement= statement;
1059
 
            if (lex->statement == NULL)
1060
 
              DRIZZLE_YYABORT;
1061
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1062
 
            statement->alter_info.build_method= $2;
1063
 
            lex->col_list.empty();
1064
 
            statement->change=NULL;
 
851
            Lex->statement= new statement::CreateIndex(YYSession, $2);
1065
852
          }
1066
853
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
1067
854
          {
1068
 
            LEX *lex=Lex;
1069
 
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
855
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
 
856
                                                            NULL,
 
857
                                                            TL_OPTION_UPDATING))
 
858
              DRIZZLE_YYABORT;
1070
859
 
1071
 
            if (!lex->current_select->add_table_to_list(lex->session, $9,
1072
 
                                                        NULL,
1073
 
                                                        TL_OPTION_UPDATING))
1074
 
              DRIZZLE_YYABORT;
1075
 
            Key *key;
1076
 
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1077
 
            statement->alter_info.key_list.push_back(key);
1078
 
            lex->col_list.empty();
 
860
            parser::buildKey(Lex, $4, $6);
1079
861
          }
1080
 
        | CREATE DATABASE opt_if_not_exists ident
 
862
        | CREATE DATABASE opt_if_not_exists schema_name
1081
863
          {
1082
 
            LEX *lex=Lex;
1083
 
 
1084
 
            lex->sql_command=SQLCOM_CREATE_DB;
1085
 
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1086
 
            lex->statement= statement;
1087
 
            if (lex->statement == NULL)
1088
 
              DRIZZLE_YYABORT;
1089
 
            statement->is_if_not_exists= $3;
 
864
            Lex->statement= new statement::CreateSchema(YYSession);
1090
865
          }
1091
866
          opt_create_database_options
1092
867
          {
1094
869
          }
1095
870
        ;
1096
871
 
1097
 
create2:
1098
 
          '(' create2a {}
1099
 
        | opt_create_table_options
1100
 
          create3 {}
1101
 
        | LIKE table_ident opt_create_table_options
1102
 
          {
1103
 
            Session *session= YYSession;
1104
 
            LEX *lex= session->lex;
1105
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1106
 
 
1107
 
            statement->is_create_table_like= true;
1108
 
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1109
 
              DRIZZLE_YYABORT;
1110
 
          }
1111
 
        | '(' LIKE table_ident ')'
1112
 
          {
1113
 
            Session *session= YYSession;
1114
 
            LEX *lex= session->lex;
1115
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1116
 
 
1117
 
            statement->is_create_table_like= true;
1118
 
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1119
 
              DRIZZLE_YYABORT;
1120
 
          }
1121
 
        ;
1122
 
 
1123
 
create2a:
1124
 
          field_list ')' opt_create_table_options
1125
 
          create3 {}
1126
 
        |  create_select ')'
1127
 
           { Lex->current_select->set_braces(1);}
 
872
create_table_definition:
 
873
          '(' field_list ')' opt_create_table_options  create_select_as
 
874
          { }
 
875
        | '(' create_select ')'
 
876
           {
 
877
             Lex->current_select->set_braces(1);
 
878
           }
1128
879
           union_opt {}
 
880
        |  '(' create_like ')' opt_create_table_options
 
881
          { }
 
882
        | create_like opt_create_table_options
 
883
          { }
 
884
        | opt_create_table_options create_select_as 
 
885
          { }
1129
886
        ;
1130
887
 
1131
 
create3:
 
888
create_select_as:
1132
889
          /* empty */ {}
1133
 
        | opt_duplicate opt_as create_select
1134
 
          { Lex->current_select->set_braces(0);}
 
890
        | opt_duplicate_as create_select
 
891
          {
 
892
            Lex->current_select->set_braces(0);
 
893
          }
1135
894
          union_clause {}
1136
 
        | opt_duplicate opt_as '(' create_select ')'
1137
 
          { Lex->current_select->set_braces(1);}
 
895
        | opt_duplicate_as '(' create_select ')'
 
896
          {
 
897
            Lex->current_select->set_braces(1);
 
898
          }
1138
899
          union_opt {}
1139
900
        ;
1140
901
 
 
902
create_like:
 
903
          LIKE table_ident
 
904
          {
 
905
            ((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
 
906
 
 
907
            if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
 
908
              DRIZZLE_YYABORT;
 
909
          }
 
910
        ;
 
911
 
1141
912
create_select:
 
913
          stored_select
 
914
          {
 
915
          }
 
916
        ;
 
917
 
 
918
/*
 
919
  This rule is used for both CREATE TABLE .. SELECT,  AND INSERT ... SELECT
 
920
*/
 
921
stored_select:
1142
922
          SELECT_SYM
1143
923
          {
1144
 
            LEX *lex=Lex;
1145
 
            lex->lock_option= TL_READ;
1146
 
            if (lex->sql_command == SQLCOM_INSERT)
 
924
            Lex->lock_option= TL_READ;
 
925
            if (Lex->sql_command == SQLCOM_INSERT)
1147
926
            {
1148
 
              lex->sql_command= SQLCOM_INSERT_SELECT;
1149
 
              delete lex->statement;
1150
 
              lex->statement=
1151
 
                new(std::nothrow) statement::InsertSelect(YYSession);
1152
 
              if (lex->statement == NULL)
1153
 
                DRIZZLE_YYABORT;
 
927
              delete Lex->statement;
 
928
              Lex->statement= new statement::InsertSelect(YYSession);
1154
929
            }
1155
 
            else if (lex->sql_command == SQLCOM_REPLACE)
 
930
            else if (Lex->sql_command == SQLCOM_REPLACE)
1156
931
            {
1157
 
              lex->sql_command= SQLCOM_REPLACE_SELECT;
1158
 
              delete lex->statement;
1159
 
              lex->statement=
1160
 
                new(std::nothrow) statement::ReplaceSelect(YYSession);
1161
 
              if (lex->statement == NULL)
1162
 
                DRIZZLE_YYABORT;
 
932
              delete Lex->statement;
 
933
              Lex->statement= new statement::ReplaceSelect(YYSession);
1163
934
            }
1164
935
            /*
1165
936
              The following work only with the local list, the global list
1166
937
              is created correctly in this case
1167
938
            */
1168
 
            lex->current_select->table_list.save_and_clear(&lex->save_list);
1169
 
            mysql_init_select(lex);
1170
 
            lex->current_select->parsing_place= SELECT_LIST;
 
939
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
 
940
            init_select(Lex);
 
941
            Lex->current_select->parsing_place= SELECT_LIST;
1171
942
          }
1172
943
          select_options select_item_list
1173
944
          {
1183
954
          }
1184
955
        ;
1185
956
 
1186
 
opt_as:
1187
 
          /* empty */ {}
1188
 
        | AS {}
1189
 
        ;
1190
 
 
1191
957
opt_create_database_options:
1192
958
          /* empty */ {}
1193
959
        | default_collation_schema {}
 
960
        | opt_database_custom_options {}
 
961
        ;
 
962
 
 
963
opt_database_custom_options:
 
964
        custom_database_option
 
965
        | custom_database_option ',' opt_database_custom_options
 
966
        ;
 
967
 
 
968
custom_database_option:
 
969
          ident_or_text
 
970
          {
 
971
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
972
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
 
973
          }
 
974
        | ident_or_text equal ident_or_text
 
975
          {
 
976
            parser::buildSchemaOption(Lex, $1.str, $3);
 
977
          }
 
978
        | ident_or_text equal ulonglong_num
 
979
          {
 
980
            parser::buildSchemaOption(Lex, $1.str, $3);
 
981
          }
1194
982
        ;
1195
983
 
1196
984
opt_table_options:
1200
988
 
1201
989
opt_if_not_exists:
1202
990
          /* empty */ { $$= false; }
1203
 
        | IF not EXISTS { $$= true; }
 
991
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
1204
992
        ;
1205
993
 
1206
994
opt_create_table_options:
1217
1005
          create_table_option
1218
1006
        | create_table_option     create_table_options
1219
1007
        | create_table_option ',' create_table_options
1220
 
        ;
1221
1008
 
1222
1009
create_table_option:
1223
 
          ENGINE_SYM opt_equal ident_or_text
1224
 
          {
1225
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1226
 
            message::Table::StorageEngine *protoengine;
1227
 
            protoengine= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine();
1228
 
 
1229
 
            statement->is_engine_set= true;
1230
 
 
1231
 
            protoengine->set_name($3.str);
1232
 
          }
1233
 
        | BLOCK_SIZE_SYM opt_equal ulong_num
1234
 
          {
1235
 
            message::Table::TableOptions *tableopts;
1236
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1237
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1238
 
 
1239
 
            tableopts->set_block_size($3);
1240
 
            statement->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
 
1010
          custom_engine_option;
 
1011
 
 
1012
custom_engine_option:
 
1013
        ENGINE_SYM equal ident_or_text
 
1014
          {
 
1015
            Lex->table()->mutable_engine()->set_name($3.str);
1241
1016
          }
1242
1017
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1243
1018
          {
1244
 
            message::Table::TableOptions *tableopts;
1245
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1246
 
 
1247
 
            tableopts->set_comment($3.str);
 
1019
            Lex->table()->mutable_options()->set_comment($3.str);
1248
1020
          }
1249
1021
        | AUTO_INC opt_equal ulonglong_num
1250
1022
          {
1251
 
            message::Table::TableOptions *tableopts;
1252
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1253
 
 
1254
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1255
 
 
1256
 
            statement->create_info.auto_increment_value=$3;
1257
 
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1258
 
            tableopts->set_auto_increment_value($3);
1259
 
          }
1260
 
        | ROW_FORMAT_SYM opt_equal row_types
1261
 
          {
1262
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1263
 
            message::Table::TableOptions *table_options= statement->createTableMessage().mutable_options();
1264
 
 
1265
 
            statement->create_info.row_type= $3;
1266
 
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1267
 
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1268
 
 
1269
 
            switch(statement->create_info.row_type)
1270
 
            {
1271
 
            case ROW_TYPE_DEFAULT:
1272
 
              /* No use setting a default row type... just adds redundant info to message */
1273
 
              break;
1274
 
            case ROW_TYPE_FIXED:
1275
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_FIXED);
1276
 
              break;
1277
 
            case ROW_TYPE_DYNAMIC:
1278
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_DYNAMIC);
1279
 
              break;
1280
 
            case ROW_TYPE_COMPRESSED:
1281
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_COMPRESSED);
1282
 
              break;
1283
 
            case ROW_TYPE_REDUNDANT:
1284
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_REDUNDANT);
1285
 
              break;
1286
 
            case ROW_TYPE_COMPACT:
1287
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_COMPACT);
1288
 
              break;
1289
 
            case ROW_TYPE_PAGE:
1290
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_PAGE);
1291
 
              break;
1292
 
            default:
1293
 
              abort();
1294
 
            }
 
1023
            Lex->table()->mutable_options()->set_auto_increment_value($3);
 
1024
          }
 
1025
        |  ROW_FORMAT_SYM equal row_format_or_text
 
1026
          {
 
1027
            parser::buildEngineOption(Lex, "ROW_FORMAT", $3);
 
1028
          }
 
1029
        |  FILE_SYM equal TEXT_STRING_sys
 
1030
          {
 
1031
            parser::buildEngineOption(Lex, "FILE", $3);
 
1032
          }
 
1033
        |  ident_or_text equal engine_option_value
 
1034
          {
 
1035
            parser::buildEngineOption(Lex, $1.str, $3);
 
1036
          }
 
1037
        | ident_or_text equal ulonglong_num
 
1038
          {
 
1039
            parser::buildEngineOption(Lex, $1.str, $3);
1295
1040
          }
1296
1041
        | default_collation
1297
 
        | KEY_BLOCK_SIZE opt_equal ulong_num
1298
 
          {
1299
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1300
 
 
1301
 
            statement->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1302
 
 
1303
 
            message::Table::TableOptions *tableopts;
1304
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1305
 
            tableopts->set_key_block_size($3);
1306
 
          }
1307
1042
        ;
1308
1043
 
1309
1044
default_collation:
1310
1045
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1311
1046
          {
1312
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1313
 
 
1314
 
            HA_CREATE_INFO *cinfo= &statement->create_info;
1315
 
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1316
 
                 cinfo->default_table_charset && $4 &&
1317
 
                 !my_charset_same(cinfo->default_table_charset,$4))
1318
 
              {
1319
 
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1320
 
                         $4->name, cinfo->default_table_charset->csname);
1321
 
                DRIZZLE_YYABORT;
1322
 
              }
1323
 
              statement->create_info.default_table_charset= $4;
1324
 
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1047
            if (not parser::buildCollation(Lex, $4))
 
1048
            {
 
1049
              DRIZZLE_YYABORT;
 
1050
            }
1325
1051
          }
1326
1052
        ;
1327
1053
 
1328
1054
default_collation_schema:
1329
1055
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1330
1056
          {
1331
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1332
 
 
1333
 
            message::Schema &schema_message= statement->schema_message;
1334
 
            schema_message.set_collation($4->name);
1335
 
          }
1336
 
        ;
1337
 
 
1338
 
column_format_types:
1339
 
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
1340
 
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
1341
 
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
1342
 
 
1343
 
row_types:
1344
 
          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
1345
 
        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
1346
 
        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
1347
 
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
1348
 
        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
1349
 
        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
1350
 
        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
 
1057
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
 
1058
          }
 
1059
        ;
 
1060
 
 
1061
row_format:
 
1062
          COMPACT_SYM  {}
 
1063
        | COMPRESSED_SYM  {}
 
1064
        | DEFAULT  {}
 
1065
        | DYNAMIC_SYM  {}
 
1066
        | FIXED_SYM  {}
 
1067
        | REDUNDANT_SYM  {}
 
1068
        ;
 
1069
 
 
1070
row_format_or_text:
 
1071
          row_format
 
1072
          {
 
1073
            $$.str= YYSession->strmake($1.str, $1.length);
 
1074
            $$.length= $1.length;
 
1075
          }
1351
1076
        ;
1352
1077
 
1353
1078
opt_select_from:
1376
1101
key_def:
1377
1102
          key_type opt_ident key_alg '(' key_list ')' key_options
1378
1103
          {
1379
 
            LEX *lex=Lex;
1380
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1381
 
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1382
 
                              lex->col_list);
1383
 
            statement->alter_info.key_list.push_back(key);
1384
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1104
            parser::buildKey(Lex, $1, $2);
1385
1105
          }
1386
1106
        | opt_constraint constraint_key_type opt_ident key_alg
1387
1107
          '(' key_list ')' key_options
1388
1108
          {
1389
 
            LEX *lex=Lex;
1390
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1391
 
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1392
 
                              lex->col_list);
1393
 
            statement->alter_info.key_list.push_back(key);
1394
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1109
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
1395
1110
          }
1396
1111
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1397
1112
          {
1398
 
            LEX *lex=Lex;
1399
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1400
 
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1401
 
                                      $8,
1402
 
                                      lex->ref_list,
1403
 
                                      statement->fk_delete_opt,
1404
 
                                      statement->fk_update_opt,
1405
 
                                      statement->fk_match_option);
1406
 
            statement->alter_info.key_list.push_back(key);
1407
 
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1408
 
                         &default_key_create_info, 1,
1409
 
                         lex->col_list);
1410
 
            statement->alter_info.key_list.push_back(key);
1411
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1412
 
            /* Only used for ALTER TABLE. Ignored otherwise. */
1413
 
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
1113
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
1414
1114
          }
1415
1115
        | constraint opt_check_constraint
1416
1116
          {
1443
1143
field_spec:
1444
1144
          field_ident
1445
1145
          {
1446
 
            LEX *lex=Lex;
1447
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1448
 
            lex->length=lex->dec=0;
1449
 
            lex->type=0;
1450
 
            statement->default_value= statement->on_update_value= 0;
1451
 
            statement->comment= null_lex_str;
1452
 
            lex->charset=NULL;
1453
 
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1454
 
 
1455
 
            message::AlterTable &alter_proto=
1456
 
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1457
 
            statement->current_proto_field= alter_proto.add_added_field();
 
1146
            parser::buildCreateFieldIdent(Lex);
1458
1147
          }
1459
1148
          field_def
1460
1149
          {
1461
 
            LEX *lex=Lex;
1462
1150
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1463
1151
 
1464
 
            if (statement->current_proto_field)
1465
 
              statement->current_proto_field->set_name($1.str);
 
1152
            if (Lex->field())
 
1153
            {
 
1154
              Lex->field()->set_name($1.str);
 
1155
            }
1466
1156
 
1467
 
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1468
 
                                  lex->length,lex->dec,lex->type,
 
1157
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
 
1158
                                  Lex->length, Lex->dec, Lex->type,
1469
1159
                                  statement->column_format,
1470
1160
                                  statement->default_value, statement->on_update_value,
1471
1161
                                  &statement->comment,
1472
 
                                  statement->change, &lex->interval_list, lex->charset))
 
1162
                                  statement->change, &Lex->interval_list, Lex->charset))
1473
1163
              DRIZZLE_YYABORT;
1474
1164
 
1475
 
            statement->current_proto_field= NULL;
 
1165
            Lex->setField(NULL);
1476
1166
          }
1477
1167
        ;
 
1168
 
1478
1169
field_def:
1479
 
          type opt_attribute {}
 
1170
          field_definition opt_attribute {}
1480
1171
        ;
1481
1172
 
1482
 
type:
1483
 
        int_type
1484
 
        {
1485
 
          $$=$1;
1486
 
          Lex->length=(char*) 0; /* use default length */
1487
 
          statement::CreateTable *statement=
1488
 
            (statement::CreateTable *)Lex->statement;
1489
 
 
1490
 
          if (statement->current_proto_field)
1491
 
          {
1492
 
            if ($1 == DRIZZLE_TYPE_LONG)
1493
 
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1494
 
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
1495
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1496
 
            else
1497
 
              abort();
1498
 
          }
 
1173
field_definition:
 
1174
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
 
1175
          { 
 
1176
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1499
1177
          }
1500
1178
        | real_type opt_precision
1501
1179
          {
1502
 
            $$=$1;
1503
 
 
1504
 
            statement::CreateTable *statement=
1505
 
              (statement::CreateTable *)Lex->statement;
1506
 
 
1507
 
            if (statement->current_proto_field)
1508
 
            {
1509
 
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
1510
 
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1511
 
            }
1512
 
          }
1513
 
          | char '(' NUM ')'
1514
 
            {
1515
 
              Lex->length=$3.str;
1516
 
              $$=DRIZZLE_TYPE_VARCHAR;
1517
 
 
1518
 
            statement::CreateTable *statement=
1519
 
              (statement::CreateTable *)Lex->statement;
1520
 
 
1521
 
            if (statement->current_proto_field)
1522
 
            {
1523
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1524
 
              message::Table::Field::StringFieldOptions *string_field_options;
1525
 
 
1526
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1527
 
 
1528
 
              string_field_options->set_length(atoi($3.str));
1529
 
            }
1530
 
            }
1531
 
          | char
1532
 
            {
1533
 
              Lex->length=(char*) "1";
1534
 
              $$=DRIZZLE_TYPE_VARCHAR;
1535
 
 
1536
 
            statement::CreateTable *statement=
1537
 
              (statement::CreateTable *)Lex->statement;
1538
 
 
1539
 
            if (statement->current_proto_field)
1540
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1541
 
            }
1542
 
          | varchar '(' NUM ')'
1543
 
            {
1544
 
              Lex->length=$3.str;
1545
 
              $$= DRIZZLE_TYPE_VARCHAR;
1546
 
 
1547
 
            statement::CreateTable *statement=
1548
 
              (statement::CreateTable *)Lex->statement;
1549
 
 
1550
 
            if (statement->current_proto_field)
1551
 
            {
1552
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1553
 
 
1554
 
              message::Table::Field::StringFieldOptions *string_field_options;
1555
 
 
1556
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1557
 
 
1558
 
              string_field_options->set_length(atoi($3.str));
1559
 
            }
1560
 
            }
1561
 
          | VARBINARY '(' NUM ')'
1562
 
            {
1563
 
              Lex->length=$3.str;
1564
 
              Lex->charset=&my_charset_bin;
1565
 
              $$= DRIZZLE_TYPE_VARCHAR;
1566
 
 
1567
 
            statement::CreateTable *statement=
1568
 
              (statement::CreateTable *)Lex->statement;
1569
 
 
1570
 
            if (statement->current_proto_field)
1571
 
            {
1572
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1573
 
              message::Table::Field::StringFieldOptions *string_field_options;
1574
 
 
1575
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1576
 
 
1577
 
              string_field_options->set_length(atoi($3.str));
1578
 
              string_field_options->set_collation_id(my_charset_bin.number);
1579
 
              string_field_options->set_collation(my_charset_bin.name);
1580
 
            }
1581
 
            }
1582
 
          | DATE_SYM
 
1180
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1181
            $$= parser::buildDoubleColumn(Lex);
 
1182
          }
 
1183
        | char '(' NUM ')'
 
1184
          {
 
1185
            $$= parser::buildVarcharColumn(Lex, $3.str);
 
1186
          }
 
1187
        | char
 
1188
          {
 
1189
            $$= parser::buildVarcharColumn(Lex, "1");
 
1190
          }
 
1191
        | varchar '(' NUM ')'
 
1192
          {
 
1193
            $$= parser::buildVarcharColumn(Lex, $3.str);
 
1194
          }
 
1195
        | VARBINARY '(' NUM ')'
 
1196
          {
 
1197
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
 
1198
          }
 
1199
        | DATE_SYM
1583
1200
          {
1584
1201
            $$=DRIZZLE_TYPE_DATE;
1585
1202
 
1586
 
            statement::CreateTable *statement=
1587
 
              (statement::CreateTable *)Lex->statement;
1588
 
 
1589
 
            if (statement->current_proto_field)
1590
 
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1591
 
          }
1592
 
          | TIMESTAMP_SYM
1593
 
          {
1594
 
            $$=DRIZZLE_TYPE_TIMESTAMP;
1595
 
 
1596
 
            statement::CreateTable *statement=
1597
 
              (statement::CreateTable *)Lex->statement;
1598
 
 
1599
 
            if (statement->current_proto_field)
1600
 
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1601
 
          }
1602
 
          | DATETIME_SYM
 
1203
            if (Lex->field())
 
1204
              Lex->field()->set_type(message::Table::Field::DATE);
 
1205
          }
 
1206
        | TIME_SYM
 
1207
          {
 
1208
            $$=DRIZZLE_TYPE_TIME;
 
1209
 
 
1210
            if (Lex->field())
 
1211
              Lex->field()->set_type(message::Table::Field::TIME);
 
1212
          }
 
1213
        | TIMESTAMP_SYM
 
1214
          {
 
1215
            $$=parser::buildTimestampColumn(Lex, NULL);
 
1216
          }
 
1217
        | TIMESTAMP_SYM '(' NUM ')'
 
1218
          {
 
1219
            $$=parser::buildTimestampColumn(Lex, $3.str);
 
1220
          }
 
1221
        | DATETIME_SYM
1603
1222
          {
1604
1223
            $$=DRIZZLE_TYPE_DATETIME;
1605
1224
 
1606
 
            statement::CreateTable *statement=
1607
 
              (statement::CreateTable *)Lex->statement;
1608
 
 
1609
 
            if (statement->current_proto_field)
1610
 
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1611
 
          }
1612
 
          | BLOB_SYM
1613
 
            {
1614
 
              Lex->charset=&my_charset_bin;
1615
 
              $$=DRIZZLE_TYPE_BLOB;
1616
 
              Lex->length=(char*) 0; /* use default length */
1617
 
 
1618
 
              statement::CreateTable *statement=
1619
 
                (statement::CreateTable *)Lex->statement;
1620
 
 
1621
 
              if (statement->current_proto_field)
1622
 
              {
1623
 
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
1624
 
                message::Table::Field::StringFieldOptions *string_field_options;
1625
 
 
1626
 
                string_field_options= statement->current_proto_field->mutable_string_options();
1627
 
                string_field_options->set_collation_id(my_charset_bin.number);
1628
 
                string_field_options->set_collation(my_charset_bin.name);
1629
 
              }
1630
 
            }
1631
 
          | TEXT_SYM
1632
 
            {
1633
 
              $$=DRIZZLE_TYPE_BLOB;
1634
 
              Lex->length=(char*) 0; /* use default length */
1635
 
 
1636
 
            statement::CreateTable *statement=
1637
 
              (statement::CreateTable *)Lex->statement;
1638
 
 
1639
 
            if (statement->current_proto_field)
1640
 
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
1641
 
            }
1642
 
          | DECIMAL_SYM float_options
1643
 
          {
1644
 
            $$=DRIZZLE_TYPE_DECIMAL;
1645
 
 
1646
 
            statement::CreateTable *statement=
1647
 
              (statement::CreateTable *)Lex->statement;
1648
 
 
1649
 
            if (statement->current_proto_field)
1650
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1651
 
          }
1652
 
          | NUMERIC_SYM float_options
1653
 
          {
1654
 
            $$=DRIZZLE_TYPE_DECIMAL;
1655
 
 
1656
 
            statement::CreateTable *statement=
1657
 
              (statement::CreateTable *)Lex->statement;
1658
 
 
1659
 
            if (statement->current_proto_field)
1660
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1661
 
          }
1662
 
          | FIXED_SYM float_options
1663
 
          {
1664
 
            $$=DRIZZLE_TYPE_DECIMAL;
1665
 
 
1666
 
            statement::CreateTable *statement=
1667
 
              (statement::CreateTable *)Lex->statement;
1668
 
 
1669
 
            if (statement->current_proto_field)
1670
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1671
 
          }
1672
 
          | ENUM_SYM
1673
 
            {Lex->interval_list.empty();}
1674
 
            '(' string_list ')'
 
1225
            if (Lex->field())
 
1226
              Lex->field()->set_type(message::Table::Field::DATETIME);
 
1227
          }
 
1228
        | BLOB_SYM
 
1229
          {
 
1230
            $$= parser::buildBlobColumn(Lex);
 
1231
          }
 
1232
        | TEXT_SYM
 
1233
          {
 
1234
            $$=DRIZZLE_TYPE_BLOB;
 
1235
            Lex->length=(char*) 0; /* use default length */
 
1236
 
 
1237
          if (Lex->field())
 
1238
            Lex->field()->set_type(message::Table::Field::BLOB);
 
1239
          }
 
1240
        | DECIMAL_SYM float_options
 
1241
          {
 
1242
            $$= parser::buildDecimalColumn(Lex);
 
1243
          }
 
1244
        | NUMERIC_SYM float_options
 
1245
          {
 
1246
            $$= parser::buildDecimalColumn(Lex);
 
1247
          }
 
1248
        | FIXED_SYM float_options
 
1249
          {
 
1250
            $$= parser::buildDecimalColumn(Lex);
 
1251
          }
 
1252
        | ENUM_SYM
 
1253
          {
 
1254
            Lex->interval_list.empty();
 
1255
          }
 
1256
          '(' string_list ')'
1675
1257
          {
1676
1258
            $$=DRIZZLE_TYPE_ENUM;
1677
1259
 
1678
 
            statement::CreateTable *statement=
1679
 
              (statement::CreateTable *)Lex->statement;
1680
 
 
1681
 
            if (statement->current_proto_field)
1682
 
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
 
1260
            if (Lex->field())
 
1261
              Lex->field()->set_type(message::Table::Field::ENUM);
 
1262
          }
 
1263
        | UUID_SYM
 
1264
          {
 
1265
            $$= parser::buildUuidColumn(Lex);
 
1266
          }
 
1267
        | BOOLEAN_SYM
 
1268
          {
 
1269
            $$= parser::buildBooleanColumn(Lex);
1683
1270
          }
1684
1271
        | SERIAL_SYM
1685
1272
          {
1686
 
            $$=DRIZZLE_TYPE_LONGLONG;
1687
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1688
 
 
1689
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1690
 
            if (statement->current_proto_field)
1691
 
            {
1692
 
              message::Table::Field::FieldConstraints *constraints;
1693
 
              constraints= statement->current_proto_field->mutable_constraints();
1694
 
              constraints->set_is_nullable(false);
1695
 
 
1696
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1697
 
            }
 
1273
            $$= parser::buildSerialColumn(Lex);
1698
1274
          }
1699
1275
        ;
1700
1276
 
1708
1284
        ;
1709
1285
 
1710
1286
int_type:
1711
 
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
1712
 
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
 
1287
          INT_SYM 
 
1288
          {
 
1289
            $$= DRIZZLE_TYPE_LONG;
 
1290
          }
 
1291
        | BOOL_SYM
 
1292
          {
 
1293
            $$= DRIZZLE_TYPE_LONG;
 
1294
          }
 
1295
        | BIGINT_SYM
 
1296
          {
 
1297
            $$= DRIZZLE_TYPE_LONGLONG;
 
1298
          }
1713
1299
        ;
1714
1300
 
1715
1301
real_type:
1718
1304
            $$= DRIZZLE_TYPE_DOUBLE;
1719
1305
          }
1720
1306
        | DOUBLE_SYM
1721
 
          { $$=DRIZZLE_TYPE_DOUBLE; }
 
1307
          {
 
1308
            $$= DRIZZLE_TYPE_DOUBLE;
 
1309
          }
1722
1310
        | DOUBLE_SYM PRECISION
1723
 
          { $$=DRIZZLE_TYPE_DOUBLE; }
 
1311
          {
 
1312
            $$= DRIZZLE_TYPE_DOUBLE;
 
1313
          }
1724
1314
        ;
1725
1315
 
1726
1316
float_options:
1735
1325
precision:
1736
1326
          '(' NUM ',' NUM ')'
1737
1327
          {
1738
 
            LEX *lex=Lex;
1739
 
            lex->length=$2.str;
1740
 
            lex->dec=$4.str;
 
1328
            Lex->length= $2.str;
 
1329
            Lex->dec= $4.str;
1741
1330
          }
1742
1331
        ;
1743
1332
 
1746
1335
        | '(' NUM ')' { Lex->length= $2.str; }
1747
1336
        ;
1748
1337
 
 
1338
opt_field_number_signed:
 
1339
          /* empty */ { $$= false; }
 
1340
        | SIGNED_SYM { $$= false; }
 
1341
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1342
        ;
 
1343
 
 
1344
ignored_field_number_length:
 
1345
          /* empty */ { }
 
1346
        | '(' NUM ')' { }
 
1347
        ;
 
1348
 
 
1349
opt_zerofill:
 
1350
          /* empty */ { $$= false; }
 
1351
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1352
        ;
 
1353
 
1749
1354
opt_precision:
1750
 
          /* empty */ {}
1751
 
        | precision {}
 
1355
          /* empty */
 
1356
          { Lex->dec=Lex->length= (char*)0; }
 
1357
        | '(' NUM ')'
 
1358
          { Lex->length=Lex->dec= (char*)0; }
 
1359
        | precision
 
1360
          {}
1752
1361
        ;
1753
1362
 
1754
1363
opt_attribute:
1764
1373
attribute:
1765
1374
          NULL_SYM
1766
1375
          {
1767
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1768
1376
            Lex->type&= ~ NOT_NULL_FLAG;
1769
 
 
1770
 
            if (statement->current_proto_field)
1771
 
            {
1772
 
              message::Table::Field::FieldConstraints *constraints;
1773
 
              constraints= statement->current_proto_field->mutable_constraints();
1774
 
              constraints->set_is_nullable(true);
1775
 
            }
1776
 
          }
1777
 
        | COLUMN_FORMAT_SYM column_format_types
1778
 
          {
1779
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1780
 
 
1781
 
            statement->column_format= $2;
1782
 
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1783
1377
          }
1784
1378
        | not NULL_SYM
1785
1379
          {
1786
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1787
1380
            Lex->type|= NOT_NULL_FLAG;
1788
1381
 
1789
 
            if (statement->current_proto_field)
 
1382
            if (Lex->field())
1790
1383
            {
1791
 
              message::Table::Field::FieldConstraints *constraints;
1792
 
              constraints= statement->current_proto_field->mutable_constraints();
1793
 
              constraints->set_is_nullable(false);
 
1384
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1794
1385
            }
1795
1386
          }
1796
1387
        | DEFAULT now_or_signed_literal
1801
1392
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1802
1393
          }
1803
1394
        | ON UPDATE_SYM NOW_SYM optional_braces
1804
 
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
 
1395
          {
 
1396
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
 
1397
          }
1805
1398
        | AUTO_INC
1806
1399
          {
1807
 
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1808
 
 
1809
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1810
 
            if (statement->current_proto_field)
1811
 
            {
1812
 
              message::Table::Field::FieldConstraints *constraints;
1813
 
 
1814
 
              constraints= statement->current_proto_field->mutable_constraints();
1815
 
              constraints->set_is_nullable(false);
1816
 
            }
 
1400
            parser::buildAutoOnColumn(Lex);
1817
1401
          }
1818
1402
        | SERIAL_SYM DEFAULT VALUE_SYM
1819
1403
          {
1820
 
            LEX *lex=Lex;
1821
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1822
 
 
1823
 
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1824
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1825
 
 
1826
 
            if (statement->current_proto_field)
1827
 
            {
1828
 
              message::Table::Field::FieldConstraints *constraints;
1829
 
              constraints= statement->current_proto_field->mutable_constraints();
1830
 
              constraints->set_is_nullable(false);
1831
 
            }
 
1404
            (void)parser::buildSerialColumn(Lex);
1832
1405
          }
1833
1406
        | opt_primary KEY_SYM
1834
1407
          {
1835
 
            LEX *lex=Lex;
1836
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1837
 
 
1838
 
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1839
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1840
 
 
1841
 
            if (statement->current_proto_field)
1842
 
            {
1843
 
              message::Table::Field::FieldConstraints *constraints;
1844
 
              constraints= statement->current_proto_field->mutable_constraints();
1845
 
              constraints->set_is_nullable(false);
1846
 
            }
 
1408
            parser::buildPrimaryOnColumn(Lex);
1847
1409
          }
1848
1410
        | UNIQUE_SYM
1849
1411
          {
1850
 
            LEX *lex=Lex;
1851
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1852
 
 
1853
 
            lex->type|= UNIQUE_FLAG;
1854
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1412
            parser::buildKeyOnColumn(Lex);
1855
1413
          }
1856
1414
        | UNIQUE_SYM KEY_SYM
1857
1415
          {
1858
 
            LEX *lex=Lex;
1859
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1860
 
 
1861
 
            lex->type|= UNIQUE_KEY_FLAG;
1862
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1416
            parser::buildKeyOnColumn(Lex);
1863
1417
          }
1864
1418
        | COMMENT_SYM TEXT_STRING_sys
1865
1419
          {
1866
1420
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
1421
            statement->comment= $2;
1868
1422
 
1869
 
            if (statement->current_proto_field)
1870
 
              statement->current_proto_field->set_comment($2.str);
 
1423
            if (Lex->field())
 
1424
              Lex->field()->set_comment($2.str);
1871
1425
          }
1872
1426
        | COLLATE_SYM collation_name
1873
1427
          {
1939
1493
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1940
1494
        | ident
1941
1495
          {
1942
 
            LEX *lex= Lex;
1943
 
            lex->ref_list.empty();
1944
 
            lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1496
            Lex->ref_list.empty();
 
1497
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
1945
1498
          }
1946
1499
        ;
1947
1500
 
1948
1501
opt_match_clause:
1949
1502
          /* empty */
1950
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
 
1503
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
1951
1504
        | MATCH FULL
1952
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
 
1505
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
1953
1506
        | MATCH PARTIAL
1954
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
 
1507
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
1955
1508
        | MATCH SIMPLE_SYM
1956
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
 
1509
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
1957
1510
        ;
1958
1511
 
1959
1512
opt_on_update_delete:
1960
1513
          /* empty */
1961
1514
          {
1962
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1963
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1515
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1516
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1964
1517
          }
1965
1518
        | ON UPDATE_SYM delete_option
1966
1519
          {
1967
1520
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1968
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1521
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1969
1522
          }
1970
1523
        | ON DELETE_SYM delete_option
1971
1524
          {
1972
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1525
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1973
1526
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1974
1527
          }
1975
1528
        | ON UPDATE_SYM delete_option
1987
1540
        ;
1988
1541
 
1989
1542
delete_option:
1990
 
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
1991
 
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
1992
 
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
1993
 
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
1994
 
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
 
1543
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
 
1544
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
 
1545
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
 
1546
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
 
1547
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
1995
1548
        ;
1996
1549
 
1997
1550
key_type:
2031
1584
        ;
2032
1585
 
2033
1586
/*
2034
 
  For now, key_alg initializies lex->key_create_info.
 
1587
  For now, key_alg initializies Lex->key_create_info.
2035
1588
  In the future, when all key options are after key definition,
2036
1589
  we can remove key_alg and move init_key_options to key_options
2037
1590
*/
2053
1606
 
2054
1607
key_using_alg:
2055
1608
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2056
 
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2057
1609
        ;
2058
1610
 
2059
1611
key_opt:
2106
1658
*/
2107
1659
 
2108
1660
alter:
2109
 
          ALTER build_method opt_ignore TABLE_SYM table_ident
 
1661
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
2110
1662
          {
2111
 
            Session *session= YYSession;
2112
 
            LEX *lex= session->lex;
2113
 
            lex->name.str= 0;
2114
 
            lex->name.length= 0;
2115
 
            lex->sql_command= SQLCOM_ALTER_TABLE;
2116
 
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
2117
 
            lex->statement= statement;
2118
 
            if (lex->statement == NULL)
2119
 
              DRIZZLE_YYABORT;
2120
 
            lex->duplicates= DUP_ERROR;
2121
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2122
 
                                                   TL_OPTION_UPDATING))
2123
 
              DRIZZLE_YYABORT;
2124
 
            lex->col_list.empty();
2125
 
            lex->select_lex.init_order();
2126
 
            lex->select_lex.db=
2127
 
              ((TableList*) lex->select_lex.table_list.first)->db;
2128
 
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
2129
 
            statement->alter_info.build_method= $2;
 
1663
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5, $2);
 
1664
            Lex->statement= statement;
 
1665
            Lex->duplicates= DUP_ERROR;
 
1666
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
 
1667
            {
 
1668
              DRIZZLE_YYABORT;
 
1669
            }
 
1670
 
 
1671
            Lex->col_list.empty();
 
1672
            Lex->select_lex.init_order();
 
1673
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
2130
1674
          }
2131
1675
          alter_commands
2132
1676
          {}
2133
 
        | ALTER DATABASE ident_or_empty
 
1677
        | ALTER_SYM DATABASE schema_name
2134
1678
          {
2135
 
            LEX *lex=Lex;
2136
 
            lex->sql_command=SQLCOM_ALTER_DB;
2137
 
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
2138
 
            if (lex->statement == NULL)
2139
 
              DRIZZLE_YYABORT;
 
1679
            Lex->statement= new statement::AlterSchema(YYSession);
2140
1680
          }
2141
1681
          default_collation_schema
2142
1682
          {
2143
 
            LEX *lex=Lex;
2144
 
            lex->name= $3;
2145
 
            if (lex->name.str == NULL &&
2146
 
                lex->copy_db_to(&lex->name.str, &lex->name.length))
 
1683
            Lex->name= $3;
 
1684
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
2147
1685
              DRIZZLE_YYABORT;
2148
1686
          }
2149
1687
        ;
2150
1688
 
2151
 
ident_or_empty:
2152
 
          /* empty */ { $$.str= 0; $$.length= 0; }
2153
 
        | ident { $$= $1; }
2154
 
        ;
2155
 
 
2156
1689
alter_commands:
2157
1690
          /* empty */
2158
1691
        | DISCARD TABLESPACE
2189
1722
        ;
2190
1723
 
2191
1724
add_column:
2192
 
          ADD opt_column
 
1725
          ADD_SYM opt_column
2193
1726
          {
2194
1727
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2195
1728
 
2200
1733
 
2201
1734
alter_list_item:
2202
1735
          add_column column_def opt_place { }
2203
 
        | ADD key_def
 
1736
        | ADD_SYM key_def
2204
1737
          {
2205
1738
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2206
1739
 
2213
1746
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2214
1747
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2215
1748
          }
2216
 
        | CHANGE opt_column field_ident
 
1749
        | CHANGE_SYM opt_column field_ident
2217
1750
          {
2218
1751
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2219
1752
            statement->change= $3.str;
2222
1755
          field_spec opt_place
2223
1756
        | MODIFY_SYM opt_column field_ident
2224
1757
          {
2225
 
            LEX *lex=Lex;
2226
1758
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2227
 
            lex->length=lex->dec=0; lex->type=0;
 
1759
            Lex->length= Lex->dec=0;
 
1760
            Lex->type= 0;
2228
1761
            statement->default_value= statement->on_update_value= 0;
2229
1762
            statement->comment= null_lex_str;
2230
 
            lex->charset= NULL;
 
1763
            Lex->charset= NULL;
2231
1764
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2232
1765
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2233
1766
 
2234
 
            statement->current_proto_field= NULL;
 
1767
            Lex->setField(NULL);
2235
1768
          }
2236
1769
          field_def
2237
1770
          {
2238
 
            LEX *lex=Lex;
2239
1771
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2240
1772
 
2241
 
            if (add_field_to_list(lex->session,&$3,
 
1773
            if (add_field_to_list(Lex->session,&$3,
2242
1774
                                  (enum enum_field_types) $5,
2243
 
                                  lex->length, lex->dec, lex->type,
 
1775
                                  Lex->length, Lex->dec, Lex->type,
2244
1776
                                  statement->column_format,
2245
1777
                                  statement->default_value,
2246
1778
                                  statement->on_update_value,
2247
1779
                                  &statement->comment,
2248
 
                                  $3.str, &lex->interval_list, lex->charset))
 
1780
                                  $3.str, &Lex->interval_list, Lex->charset))
2249
1781
              DRIZZLE_YYABORT;
2250
1782
          }
2251
1783
          opt_place
2259
1791
        | DROP FOREIGN KEY_SYM opt_ident
2260
1792
          {
2261
1793
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2262
 
 
 
1794
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY,
 
1795
                                                                    $4.str));
2263
1796
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2264
1797
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
2265
1798
          }
2293
1826
            statement->alter_info.keys_onoff= ENABLE;
2294
1827
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2295
1828
          }
2296
 
        | ALTER opt_column field_ident SET DEFAULT signed_literal
 
1829
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
2297
1830
          {
2298
1831
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2299
1832
 
2300
1833
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
2301
1834
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2302
1835
          }
2303
 
        | ALTER opt_column field_ident DROP DEFAULT
 
1836
        | ALTER_SYM opt_column field_ident DROP DEFAULT
2304
1837
          {
2305
1838
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2306
1839
 
2309
1842
          }
2310
1843
        | RENAME opt_to table_ident
2311
1844
          {
2312
 
            LEX *lex=Lex;
2313
1845
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2314
1846
            size_t dummy;
2315
1847
 
2316
 
            lex->select_lex.db=$3->db.str;
2317
 
            if (lex->select_lex.db == NULL &&
2318
 
                lex->copy_db_to(&lex->select_lex.db, &dummy))
 
1848
            Lex->select_lex.db=$3->db.str;
 
1849
            if (Lex->select_lex.db == NULL &&
 
1850
                Lex->copy_db_to(&Lex->select_lex.db, &dummy))
2319
1851
            {
2320
1852
              DRIZZLE_YYABORT;
2321
1853
            }
2326
1858
              DRIZZLE_YYABORT;
2327
1859
            }
2328
1860
 
2329
 
            lex->name= $3->table;
 
1861
            Lex->name= $3->table;
2330
1862
            statement->alter_info.flags.set(ALTER_RENAME);
2331
1863
          }
2332
1864
        | CONVERT_SYM TO_SYM collation_name_or_default
2333
1865
          {
2334
1866
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2335
1867
 
2336
 
            statement->create_info.table_charset=
2337
 
            statement->create_info.default_table_charset= $3;
2338
 
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
 
1868
            statement->create_info().table_charset=
 
1869
            statement->create_info().default_table_charset= $3;
 
1870
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
2339
1871
              HA_CREATE_USED_DEFAULT_CHARSET);
2340
1872
            statement->alter_info.flags.set(ALTER_CONVERT);
2341
1873
          }
2373
1905
          /* empty */ {}
2374
1906
        | AFTER_SYM ident
2375
1907
          {
2376
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2377
 
 
2378
 
            store_position_for_column($2.str);
2379
 
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
1908
            parser::storeAlterColumnPosition(Lex, $2.str);
2380
1909
          }
2381
1910
        | FIRST_SYM
2382
1911
          {
2383
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2384
 
 
2385
 
            store_position_for_column(first_keyword);
2386
 
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
1912
            parser::storeAlterColumnPosition(Lex, first_keyword);
2387
1913
          }
2388
1914
        ;
2389
1915
 
2397
1923
start:
2398
1924
          START_SYM TRANSACTION_SYM start_transaction_opts
2399
1925
          {
2400
 
            LEX *lex= Lex;
2401
 
            lex->sql_command= SQLCOM_BEGIN;
2402
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2403
 
            if (lex->statement == NULL)
2404
 
              DRIZZLE_YYABORT;
 
1926
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2405
1927
          }
2406
1928
        ;
2407
1929
 
2413
1935
          }
2414
1936
        ;
2415
1937
 
2416
 
 
2417
 
checksum:
2418
 
          CHECKSUM_SYM table_or_tables
2419
 
          {
2420
 
            LEX *lex=Lex;
2421
 
            lex->sql_command = SQLCOM_CHECKSUM;
2422
 
            lex->statement= new(std::nothrow) statement::Checksum(YYSession);
2423
 
            if (lex->statement == NULL)
2424
 
              DRIZZLE_YYABORT;
2425
 
          }
2426
 
          table_list
2427
 
          {}
2428
 
        ;
2429
 
 
2430
 
 
2431
1938
analyze:
2432
1939
          ANALYZE_SYM table_or_tables
2433
1940
          {
2434
 
            LEX *lex=Lex;
2435
 
            lex->sql_command = SQLCOM_ANALYZE;
2436
 
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
2437
 
            if (lex->statement == NULL)
2438
 
              DRIZZLE_YYABORT;
 
1941
            Lex->statement= new statement::Analyze(YYSession);
2439
1942
          }
2440
1943
          table_list
2441
1944
          {}
2444
1947
check:
2445
1948
          CHECK_SYM table_or_tables
2446
1949
          {
2447
 
            LEX *lex=Lex;
2448
 
 
2449
 
            lex->sql_command = SQLCOM_CHECK;
2450
 
            lex->statement= new(std::nothrow) statement::Check(YYSession);
2451
 
            if (lex->statement == NULL)
2452
 
              DRIZZLE_YYABORT;
 
1950
            Lex->statement= new statement::Check(YYSession);
2453
1951
          }
2454
1952
          table_list
2455
1953
          {}
2458
1956
rename:
2459
1957
          RENAME table_or_tables
2460
1958
          {
2461
 
            Lex->sql_command= SQLCOM_RENAME_TABLE;
2462
 
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
2463
 
            if (Lex->statement == NULL)
2464
 
              DRIZZLE_YYABORT;
 
1959
            Lex->statement= new statement::RenameTable(YYSession);
2465
1960
          }
2466
1961
          table_to_table_list
2467
1962
          {}
2475
1970
table_to_table:
2476
1971
          table_ident TO_SYM table_ident
2477
1972
          {
2478
 
            LEX *lex=Lex;
2479
 
            Select_Lex *sl= lex->current_select;
2480
 
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
 
1973
            Select_Lex *sl= Lex->current_select;
 
1974
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
2481
1975
                                       TL_IGNORE) ||
2482
 
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
 
1976
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
2483
1977
                                       TL_IGNORE))
2484
1978
              DRIZZLE_YYABORT;
2485
1979
          }
2493
1987
select:
2494
1988
          select_init
2495
1989
          {
2496
 
            LEX *lex= Lex;
2497
 
            lex->sql_command= SQLCOM_SELECT;
2498
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
2499
 
            if (lex->statement == NULL)
2500
 
              DRIZZLE_YYABORT;
 
1990
            Lex->statement= new statement::Select(YYSession);
2501
1991
          }
2502
1992
        ;
2503
1993
 
2510
2000
select_paren:
2511
2001
          SELECT_SYM select_part2
2512
2002
          {
2513
 
            if (setup_select_in_parentheses(Lex))
 
2003
            if (parser::setup_select_in_parentheses(YYSession, Lex))
2514
2004
              DRIZZLE_YYABORT;
2515
2005
          }
2516
2006
        | '(' select_paren ')'
2520
2010
select_paren_derived:
2521
2011
          SELECT_SYM select_part2_derived
2522
2012
          {
2523
 
            if (setup_select_in_parentheses(Lex))
 
2013
            if (parser::setup_select_in_parentheses(YYSession, Lex))
2524
2014
              DRIZZLE_YYABORT;
2525
2015
          }
2526
2016
        | '(' select_paren_derived ')'
2529
2019
select_init2:
2530
2020
          select_part2
2531
2021
          {
2532
 
            LEX *lex= Lex;
2533
 
            Select_Lex * sel= lex->current_select;
2534
 
            if (lex->current_select->set_braces(0))
 
2022
            Select_Lex * sel= Lex->current_select;
 
2023
            if (Lex->current_select->set_braces(0))
2535
2024
            {
2536
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
2025
              parser::my_parse_error(YYSession->m_lip);
2537
2026
              DRIZZLE_YYABORT;
2538
2027
            }
2539
2028
            if (sel->linkage == UNION_TYPE &&
2540
2029
                sel->master_unit()->first_select()->braces)
2541
2030
            {
2542
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
2031
              parser::my_parse_error(YYSession->m_lip);
2543
2032
              DRIZZLE_YYABORT;
2544
2033
            }
2545
2034
          }
2548
2037
 
2549
2038
select_part2:
2550
2039
          {
2551
 
            LEX *lex= Lex;
2552
 
            Select_Lex *sel= lex->current_select;
 
2040
            Select_Lex *sel= Lex->current_select;
2553
2041
            if (sel->linkage != UNION_TYPE)
2554
 
              mysql_init_select(lex);
2555
 
            lex->current_select->parsing_place= SELECT_LIST;
 
2042
              init_select(Lex);
 
2043
            Lex->current_select->parsing_place= SELECT_LIST;
2556
2044
          }
2557
2045
          select_options select_item_list
2558
2046
          {
2582
2070
select_options:
2583
2071
          /* empty*/
2584
2072
        | select_option_list
2585
 
          {
2586
 
            if (Lex->current_select->options & SELECT_DISTINCT &&
2587
 
                Lex->current_select->options & SELECT_ALL)
2588
 
            {
2589
 
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2590
 
              DRIZZLE_YYABORT;
2591
 
            }
2592
 
          }
 
2073
          { }
2593
2074
        ;
2594
2075
 
2595
2076
select_option_list:
2597
2078
        | select_option
2598
2079
        ;
2599
2080
 
 
2081
select_option_distinct_or_all:
 
2082
          DISTINCT
 
2083
          {
 
2084
            Lex->current_select->options|= SELECT_DISTINCT; 
 
2085
 
 
2086
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
 
2087
            {
 
2088
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2089
              DRIZZLE_YYABORT;
 
2090
            }
 
2091
          }
 
2092
        | ALL
 
2093
          {
 
2094
            Lex->current_select->options|= SELECT_ALL; 
 
2095
 
 
2096
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
 
2097
            {
 
2098
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2099
              DRIZZLE_YYABORT;
 
2100
            }
 
2101
          }
 
2102
        ;
 
2103
 
 
2104
select_option_small_or_big:
 
2105
          SQL_SMALL_RESULT
 
2106
          {
 
2107
            Lex->current_select->options|= SELECT_SMALL_RESULT;
 
2108
 
 
2109
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
 
2110
            {
 
2111
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
 
2112
              DRIZZLE_YYABORT;
 
2113
            }
 
2114
          }
 
2115
        | SQL_BIG_RESULT
 
2116
          {
 
2117
            Lex->current_select->options|= SELECT_BIG_RESULT;
 
2118
 
 
2119
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
 
2120
            {
 
2121
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
 
2122
              DRIZZLE_YYABORT;
 
2123
            }
 
2124
          }
 
2125
        ;
 
2126
 
 
2127
 
2600
2128
select_option:
2601
2129
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
2602
 
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
2603
 
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
2604
 
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2605
2130
        | SQL_BUFFER_RESULT
2606
2131
          {
2607
 
            if (check_simple_select())
 
2132
            if (check_simple_select(YYSession))
2608
2133
              DRIZZLE_YYABORT;
2609
2134
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2610
2135
          }
 
2136
        | select_option_small_or_big
 
2137
          { }
 
2138
        | select_option_distinct_or_all
 
2139
          { }
2611
2140
        | SQL_CALC_FOUND_ROWS
2612
2141
          {
2613
 
            if (check_simple_select())
 
2142
            if (check_simple_select(YYSession))
2614
2143
              DRIZZLE_YYABORT;
2615
2144
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2616
2145
          }
2617
 
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2618
2146
        ;
2619
2147
 
2620
2148
select_lock_type:
2621
2149
          /* empty */
2622
2150
        | FOR_SYM UPDATE_SYM
2623
2151
          {
2624
 
            LEX *lex=Lex;
2625
 
            lex->current_select->set_lock_for_tables(TL_WRITE);
 
2152
            Lex->current_select->set_lock_for_tables(TL_WRITE);
2626
2153
          }
2627
2154
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2628
2155
          {
2629
 
            LEX *lex=Lex;
2630
 
            lex->current_select->
 
2156
            Lex->current_select->
2631
2157
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2632
2158
          }
2633
2159
        ;
2637
2163
        | select_item
2638
2164
        | '*'
2639
2165
          {
2640
 
            Session *session= YYSession;
2641
 
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2166
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
2642
2167
                                                          context,
2643
2168
                                                          NULL, NULL, "*")))
2644
2169
              DRIZZLE_YYABORT;
2645
 
            (session->lex->current_select->with_wild)++;
 
2170
            (YYSession->lex->current_select->with_wild)++;
2646
2171
          }
2647
2172
        ;
2648
2173
 
2649
2174
select_item:
2650
2175
          remember_name table_wild remember_end
2651
2176
          {
2652
 
            Session *session= YYSession;
2653
 
 
2654
 
            if (session->add_item_to_list($2))
 
2177
            if (YYSession->add_item_to_list($2))
2655
2178
              DRIZZLE_YYABORT;
2656
2179
          }
2657
2180
        | remember_name expr remember_end select_alias
2658
2181
          {
2659
 
            Session *session= YYSession;
2660
2182
            assert($1 < $3);
2661
2183
 
2662
 
            if (session->add_item_to_list($2))
 
2184
            if (YYSession->add_item_to_list($2))
2663
2185
              DRIZZLE_YYABORT;
 
2186
 
2664
2187
            if ($4.str)
2665
2188
            {
2666
2189
              $2->is_autogenerated_name= false;
2668
2191
            }
2669
2192
            else if (!$2->name)
2670
2193
            {
2671
 
              $2->set_name($1, (uint) ($3 - $1), session->charset());
 
2194
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
2672
2195
            }
2673
2196
          }
2674
2197
        ;
2675
2198
 
2676
2199
remember_name:
2677
2200
          {
2678
 
            Session *session= YYSession;
2679
 
            Lex_input_stream *lip= session->m_lip;
 
2201
            Lex_input_stream *lip= YYSession->m_lip;
2680
2202
            $$= (char*) lip->get_cpp_tok_start();
2681
2203
          }
2682
2204
        ;
2683
2205
 
2684
2206
remember_end:
2685
2207
          {
2686
 
            Session *session= YYSession;
2687
 
            Lex_input_stream *lip= session->m_lip;
 
2208
            Lex_input_stream *lip= YYSession->m_lip;
2688
2209
            $$= (char*) lip->get_cpp_tok_end();
2689
2210
          }
2690
2211
        ;
2837
2358
          }
2838
2359
        | bit_expr not IN_SYM '(' subselect ')'
2839
2360
          {
2840
 
            Session *session= YYSession;
2841
 
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
2842
 
            $$= negate_expression(session, item);
 
2361
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
 
2362
            $$= negate_expression(YYSession, item);
2843
2363
          }
2844
2364
        | bit_expr IN_SYM '(' expr ')'
2845
2365
          {
2846
 
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2366
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
2847
2367
          }
2848
2368
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2849
2369
          {
2853
2373
          }
2854
2374
        | bit_expr not IN_SYM '(' expr ')'
2855
2375
          {
2856
 
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2376
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
2857
2377
          }
2858
2378
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2859
2379
          {
2864
2384
            $$= item;
2865
2385
          }
2866
2386
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2867
 
          { $$= new Item_func_between($1,$3,$5); }
 
2387
          {
 
2388
            $$= new Item_func_between($1,$3,$5);
 
2389
          }
2868
2390
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2869
2391
          {
2870
2392
            Item_func_between *item= new Item_func_between($1,$4,$6);
2872
2394
            $$= item;
2873
2395
          }
2874
2396
        | bit_expr LIKE simple_expr opt_escape
2875
 
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
 
2397
          { 
 
2398
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
 
2399
          }
2876
2400
        | bit_expr not LIKE simple_expr opt_escape
2877
 
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
 
2401
          { 
 
2402
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used));
 
2403
          }
 
2404
        | bit_expr REGEXP_SYM bit_expr
 
2405
          { 
 
2406
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
2407
            args->push_back($1);
 
2408
            args->push_back($3);
 
2409
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2410
            {
 
2411
              DRIZZLE_YYABORT;
 
2412
            }
 
2413
          }
 
2414
        | bit_expr not REGEXP_SYM bit_expr
 
2415
          { 
 
2416
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
2417
            args->push_back($1);
 
2418
            args->push_back($4);
 
2419
            args->push_back(new (YYSession->mem_root) Item_int(1));
 
2420
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2421
            {
 
2422
              DRIZZLE_YYABORT;
 
2423
            }
 
2424
          }
2878
2425
        | bit_expr
2879
2426
        ;
2880
2427
 
2890
2437
        | bit_expr '*' bit_expr %prec '*'
2891
2438
          { $$= new Item_func_mul($1,$3); }
2892
2439
        | bit_expr '/' bit_expr %prec '/'
2893
 
          { $$= new Item_func_div($1,$3); }
 
2440
          { $$= new Item_func_div(YYSession,$1,$3); }
2894
2441
        | bit_expr '%' bit_expr %prec '%'
2895
2442
          { $$= new Item_func_mod($1,$3); }
2896
2443
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2934
2481
        | function_call_conflict
2935
2482
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2936
2483
          {
2937
 
            Session *session= YYSession;
2938
 
            Item *i1= new (session->mem_root) Item_string($3.str,
 
2484
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
2939
2485
                                                      $3.length,
2940
 
                                                      session->charset());
2941
 
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
 
2486
                                                      YYSession->charset());
 
2487
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
2942
2488
          }
2943
2489
        | literal
2944
2490
        | variable
2945
2491
        | sum_expr
 
2492
          {
 
2493
            Lex->setSumExprUsed();
 
2494
          }
2946
2495
        | '+' simple_expr %prec NEG { $$= $2; }
2947
2496
        | '-' simple_expr %prec NEG
2948
2497
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2973
2522
          }
2974
2523
        | CAST_SYM '(' expr AS cast_type ')'
2975
2524
          {
2976
 
            LEX *lex= Lex;
2977
 
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
2978
 
                                 lex->charset);
 
2525
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
 
2526
                                 Lex->charset);
2979
2527
            if (!$$)
2980
2528
              DRIZZLE_YYABORT;
2981
2529
          }
2993
2541
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2994
2542
                                                         $3);
2995
2543
          }
2996
 
        | VALUES '(' simple_ident_nospvar ')'
 
2544
        | VALUES '(' simple_ident ')'
2997
2545
          {
2998
2546
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2999
2547
                                                        $3);
3015
2563
        | CURRENT_USER optional_braces
3016
2564
          {
3017
2565
            std::string user_str("user");
3018
 
            if (! ($$= reserved_keyword_function(user_str, NULL)))
 
2566
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
3019
2567
            {
3020
2568
              DRIZZLE_YYABORT;
3021
2569
            }
 
2570
            Lex->setCacheable(false);
3022
2571
          }
3023
2572
        | DATE_SYM '(' expr ')'
3024
2573
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3027
2576
        | HOUR_SYM '(' expr ')'
3028
2577
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
3029
2578
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3030
 
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
 
2579
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
3031
2580
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3032
2581
          {
3033
 
            Session *session= YYSession;
3034
 
            List<Item> *list= new (session->mem_root) List<Item>;
 
2582
            List<Item> *list= new (YYSession->mem_root) List<Item>;
3035
2583
            list->push_front($5);
3036
2584
            list->push_front($3);
3037
 
            Item_row *item= new (session->mem_root) Item_row(*list);
3038
 
            $$= new (session->mem_root) Item_func_interval(item);
 
2585
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
 
2586
            $$= new (YYSession->mem_root) Item_func_interval(item);
3039
2587
          }
3040
2588
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3041
2589
          {
3042
 
            Session *session= YYSession;
3043
2590
            $7->push_front($5);
3044
2591
            $7->push_front($3);
3045
 
            Item_row *item= new (session->mem_root) Item_row(*$7);
3046
 
            $$= new (session->mem_root) Item_func_interval(item);
 
2592
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
 
2593
            $$= new (YYSession->mem_root) Item_func_interval(item);
3047
2594
          }
3048
2595
        | LEFT '(' expr ',' expr ')'
3049
2596
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3075
2622
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3076
2623
        | USER '(' ')'
3077
2624
          {
3078
 
            std::string user_str("user");
3079
 
            if (! ($$= reserved_keyword_function(user_str, NULL)))
 
2625
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
3080
2626
            {
3081
2627
              DRIZZLE_YYABORT;
3082
2628
            }
 
2629
            Lex->setCacheable(false);
3083
2630
          }
3084
2631
        | YEAR_SYM '(' expr ')'
3085
2632
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3107
2654
        | CURDATE optional_braces
3108
2655
          {
3109
2656
            $$= new (YYSession->mem_root) Item_func_curdate_local();
 
2657
            Lex->setCacheable(false);
3110
2658
          }
3111
2659
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3112
2660
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
3117
2665
        | NOW_SYM optional_braces
3118
2666
          {
3119
2667
            $$= new (YYSession->mem_root) Item_func_now_local();
 
2668
            Lex->setCacheable(false);
3120
2669
          }
3121
2670
        | NOW_SYM '(' expr ')'
3122
2671
          {
3123
2672
            $$= new (YYSession->mem_root) Item_func_now_local($3);
 
2673
            Lex->setCacheable(false);
3124
2674
          }
3125
2675
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3126
2676
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
3138
2688
            args->push_back($3);
3139
2689
            args->push_back($5);
3140
2690
            args->push_back($7);
3141
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
2691
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3142
2692
            {
3143
2693
              DRIZZLE_YYABORT;
3144
2694
            }
3149
2699
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3150
2700
            args->push_back($3);
3151
2701
            args->push_back($5);
3152
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
2702
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3153
2703
            {
3154
2704
              DRIZZLE_YYABORT;
3155
2705
            }
3161
2711
            args->push_back($3);
3162
2712
            args->push_back($5);
3163
2713
            args->push_back($7);
3164
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
2714
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3165
2715
            {
3166
2716
              DRIZZLE_YYABORT;
3167
2717
            }
3172
2722
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3173
2723
            args->push_back($3);
3174
2724
            args->push_back($5);
3175
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
2725
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3176
2726
            {
3177
2727
              DRIZZLE_YYABORT;
3178
2728
            }
3179
2729
          }
3180
2730
        | SYSDATE optional_braces
3181
 
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
 
2731
          { 
 
2732
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
 
2733
            Lex->setCacheable(false);
 
2734
          }
3182
2735
        | SYSDATE '(' expr ')'
3183
 
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
 
2736
          { 
 
2737
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
 
2738
            Lex->setCacheable(false);
 
2739
          }
3184
2740
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3185
2741
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
3186
2742
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3188
2744
        | UTC_DATE_SYM optional_braces
3189
2745
          {
3190
2746
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
 
2747
            Lex->setCacheable(false);
3191
2748
          }
3192
2749
        | UTC_TIMESTAMP_SYM optional_braces
3193
2750
          {
3194
2751
            $$= new (YYSession->mem_root) Item_func_now_utc();
 
2752
            Lex->setCacheable(false);
3195
2753
          }
3196
2754
        ;
3197
2755
 
3207
2765
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3208
2766
        | DATABASE '(' ')'
3209
2767
          {
3210
 
            std::string database_str("database");
3211
 
            if (! ($$= reserved_keyword_function(database_str, NULL)))
3212
 
            {
3213
 
              DRIZZLE_YYABORT;
3214
 
            }
3215
 
          }
 
2768
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
 
2769
            {
 
2770
              DRIZZLE_YYABORT;
 
2771
            }
 
2772
            Lex->setCacheable(false);
 
2773
          }
 
2774
        | CATALOG_SYM '(' ')'
 
2775
          {
 
2776
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
 
2777
            {
 
2778
              DRIZZLE_YYABORT;
 
2779
            }
 
2780
            Lex->setCacheable(false);
 
2781
          }
 
2782
        | EXECUTE_SYM '(' expr ')' opt_wait
 
2783
          {
 
2784
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
2785
            args->push_back($3);
 
2786
 
 
2787
            if ($5)
 
2788
            {
 
2789
              args->push_back(new (YYSession->mem_root) Item_int(1));
 
2790
            }
 
2791
 
 
2792
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
 
2793
            {
 
2794
              DRIZZLE_YYABORT;
 
2795
            }
 
2796
          }
3216
2797
        | IF '(' expr ',' expr ',' expr ')'
3217
2798
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
 
2799
        | KILL_SYM kill_option '(' expr ')'
 
2800
          {
 
2801
            std::string kill_str("kill");
 
2802
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
2803
            args->push_back($4);
 
2804
 
 
2805
            if ($2)
 
2806
            {
 
2807
              args->push_back(new (YYSession->mem_root) Item_uint(1));
 
2808
            }
 
2809
 
 
2810
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
 
2811
            {
 
2812
              DRIZZLE_YYABORT;
 
2813
            }
 
2814
          }
3218
2815
        | MICROSECOND_SYM '(' expr ')'
3219
2816
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
3220
2817
        | MOD_SYM '(' expr ',' expr ')'
3222
2819
        | QUARTER_SYM '(' expr ')'
3223
2820
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
3224
2821
        | REPEAT_SYM '(' expr ',' expr ')'
3225
 
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
 
2822
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
3226
2823
        | REPLACE '(' expr ',' expr ',' expr ')'
3227
 
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3228
 
        | REVERSE_SYM '(' expr ')'
3229
 
          {
3230
 
            std::string reverse_str("reverse");
3231
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3232
 
            args->push_back($3);
3233
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
3234
 
            {
3235
 
              DRIZZLE_YYABORT;
3236
 
            }
3237
 
          }
 
2824
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
3238
2825
        | TRUNCATE_SYM '(' expr ',' expr ')'
3239
2826
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
 
2827
        | WAIT_SYM '(' expr ')'
 
2828
          {
 
2829
            std::string wait_str("wait");
 
2830
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
2831
            args->push_back($3);
 
2832
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
2833
            {
 
2834
              DRIZZLE_YYABORT;
 
2835
            }
 
2836
          }
 
2837
        | UUID_SYM '(' ')'
 
2838
          {
 
2839
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
 
2840
            {
 
2841
              DRIZZLE_YYABORT;
 
2842
            }
 
2843
            Lex->setCacheable(false);
 
2844
          }
 
2845
        | WAIT_SYM '(' expr ',' expr ')'
 
2846
          {
 
2847
            std::string wait_str("wait");
 
2848
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
2849
            args->push_back($3);
 
2850
            args->push_back($5);
 
2851
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
2852
            {
 
2853
              DRIZZLE_YYABORT;
 
2854
            }
 
2855
          }
3240
2856
        ;
3241
2857
 
3242
2858
/*
3257
2873
          }
3258
2874
          opt_udf_expr_list ')'
3259
2875
          {
3260
 
            Session *session= YYSession;
3261
2876
            Create_func *builder;
3262
2877
            Item *item= NULL;
3263
2878
 
3273
2888
            builder= find_native_function_builder($1);
3274
2889
            if (builder)
3275
2890
            {
3276
 
              item= builder->create(session, $1, $4);
 
2891
              item= builder->create(YYSession, $1, $4);
3277
2892
            }
3278
2893
            else
3279
2894
            {
3281
2896
              const plugin::Function *udf= $<udf>3;
3282
2897
              if (udf)
3283
2898
              {
3284
 
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
2899
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
3285
2900
              } else {
3286
2901
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3287
2902
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3292
2907
            {
3293
2908
              DRIZZLE_YYABORT;
3294
2909
            }
 
2910
            Lex->setCacheable(false);
3295
2911
          }
3296
2912
        ;
3297
2913
 
3397
3013
        ;
3398
3014
 
3399
3015
variable_aux:
3400
 
          ident_or_text SET_VAR expr
 
3016
          user_variable_ident SET_VAR expr
3401
3017
          {
3402
3018
            $$= new Item_func_set_user_var($1, $3);
 
3019
            Lex->setCacheable(false);
3403
3020
          }
3404
 
        | ident_or_text
 
3021
        | user_variable_ident
3405
3022
          {
3406
 
            $$= new Item_func_get_user_var($1);
 
3023
            $$= new Item_func_get_user_var(*YYSession, $1);
 
3024
            Lex->setCacheable(false);
3407
3025
          }
3408
 
        | '@' opt_var_ident_type ident_or_text opt_component
 
3026
        | '@' opt_var_ident_type user_variable_ident opt_component
3409
3027
          {
3410
3028
            /* disallow "SELECT @@global.global.variable" */
3411
 
            if ($3.str && $4.str && check_reserved_words(&$3))
 
3029
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
3412
3030
            {
3413
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3031
              parser::my_parse_error(YYSession->m_lip);
3414
3032
              DRIZZLE_YYABORT;
3415
3033
            }
3416
3034
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3419
3037
        ;
3420
3038
 
3421
3039
opt_distinct:
3422
 
          /* empty */ { $$ = 0; }
3423
 
        | DISTINCT    { $$ = 1; }
 
3040
          /* empty */ { $$ = false; }
 
3041
        | DISTINCT    { $$ = true; }
3424
3042
        ;
3425
3043
 
3426
3044
opt_gconcat_separator:
3449
3067
in_sum_expr:
3450
3068
          opt_all
3451
3069
          {
3452
 
            LEX *lex= Lex;
3453
 
            if (lex->current_select->inc_in_sum_expr())
 
3070
            if (Lex->current_select->inc_in_sum_expr())
3454
3071
            {
3455
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3072
              parser::my_parse_error(YYSession->m_lip);
3456
3073
              DRIZZLE_YYABORT;
3457
3074
            }
3458
3075
          }
3466
3083
cast_type:
3467
3084
          BINARY opt_len
3468
3085
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
 
3086
        | BOOLEAN_SYM
 
3087
          { $$=ITEM_CAST_BOOLEAN; Lex->charset= &my_charset_bin; Lex->dec= 0; }
 
3088
        | SIGNED_SYM
 
3089
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3090
        | SIGNED_SYM INT_SYM
 
3091
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3092
        | INT_SYM
 
3093
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3094
        | UNSIGNED_SYM
 
3095
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3096
        | UNSIGNED_SYM INT_SYM
 
3097
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3469
3098
        | CHAR_SYM opt_len
3470
3099
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3471
3100
        | DATE_SYM
3472
3101
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3102
        | TIME_SYM
 
3103
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3473
3104
        | DATETIME_SYM
3474
3105
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3475
3106
        | DECIMAL_SYM float_options
3520
3151
          table_factor { $$=$1; }
3521
3152
        | join_table
3522
3153
          {
3523
 
            LEX *lex= Lex;
3524
 
            if (!($$= lex->current_select->nest_last_join(lex->session)))
 
3154
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
3525
3155
              DRIZZLE_YYABORT;
3526
3156
          }
3527
3157
        ;
3567
3197
            left-associative joins.
3568
3198
          */
3569
3199
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
3570
 
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); }
 
3200
          { 
 
3201
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
 
3202
            Lex->is_cross= false;
 
3203
          }
3571
3204
        | table_ref STRAIGHT_JOIN table_factor
3572
 
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
 
3205
          { 
 
3206
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
 
3207
          }
3573
3208
        | table_ref normal_join table_ref
3574
3209
          ON
3575
3210
          {
3576
3211
            DRIZZLE_YYABORT_UNLESS($1 && $3);
 
3212
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
3577
3213
            /* Change the current name resolution context to a local context. */
3578
3214
            if (push_new_name_resolution_context(YYSession, $1, $3))
3579
3215
              DRIZZLE_YYABORT;
3662
3298
          }
3663
3299
          expr
3664
3300
          {
3665
 
            LEX *lex= Lex;
3666
 
            if (!($$= lex->current_select->convert_right_join()))
 
3301
            if (!($$= Lex->current_select->convert_right_join()))
3667
3302
              DRIZZLE_YYABORT;
3668
3303
            add_join_on($$, $8);
3669
3304
            Lex->pop_context();
3675
3310
          }
3676
3311
          USING '(' using_list ')'
3677
3312
          {
3678
 
            LEX *lex= Lex;
3679
 
            if (!($$= lex->current_select->convert_right_join()))
 
3313
            if (!($$= Lex->current_select->convert_right_join()))
3680
3314
              DRIZZLE_YYABORT;
3681
3315
            add_join_natural($$,$5,$9,Lex->current_select);
3682
3316
          }
3684
3318
          {
3685
3319
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3686
3320
            add_join_natural($6,$1,NULL,Lex->current_select);
3687
 
            LEX *lex= Lex;
3688
 
            if (!($$= lex->current_select->convert_right_join()))
 
3321
            if (!($$= Lex->current_select->convert_right_join()))
3689
3322
              DRIZZLE_YYABORT;
3690
3323
          }
3691
3324
        ;
3693
3326
normal_join:
3694
3327
          JOIN_SYM {}
3695
3328
        | INNER_SYM JOIN_SYM {}
3696
 
        | CROSS JOIN_SYM {}
 
3329
        | CROSS JOIN_SYM
 
3330
          {
 
3331
            Lex->is_cross= true;
 
3332
            Lex->current_select->is_cross= true;
 
3333
          }
3697
3334
        ;
3698
3335
 
3699
3336
/*
3706
3343
/* Warning - may return NULL in case of incomplete SELECT */
3707
3344
table_factor:
3708
3345
          {
3709
 
            Select_Lex *sel= Lex->current_select;
3710
 
            sel->table_join_options= 0;
3711
3346
          }
3712
3347
          table_ident opt_table_alias opt_key_definition
3713
3348
          {
3714
3349
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3715
 
                             Lex->current_select->get_table_join_options(),
 
3350
                             0,
3716
3351
                             Lex->lock_option,
3717
3352
                             Lex->current_select->pop_index_hints())))
3718
3353
              DRIZZLE_YYABORT;
3720
3355
          }
3721
3356
        | select_derived_init get_select_lex select_derived2
3722
3357
          {
3723
 
            LEX *lex= Lex;
3724
 
            Select_Lex *sel= lex->current_select;
 
3358
            Select_Lex *sel= Lex->current_select;
3725
3359
            if ($1)
3726
3360
            {
3727
3361
              if (sel->set_braces(1))
3728
3362
              {
3729
 
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
3363
                parser::my_parse_error(YYSession->m_lip);
3730
3364
                DRIZZLE_YYABORT;
3731
3365
              }
3732
3366
              /* select in braces, can't contain global parameters */
3734
3368
                sel->master_unit()->global_parameters=
3735
3369
                   sel->master_unit()->fake_select_lex;
3736
3370
            }
3737
 
            if ($2->init_nested_join(lex->session))
 
3371
            if ($2->init_nested_join(Lex->session))
3738
3372
              DRIZZLE_YYABORT;
3739
3373
            $$= 0;
3740
3374
            /* incomplete derived tables return NULL, we must be
3763
3397
            /* Use $2 instead of Lex->current_select as derived table will
3764
3398
               alter value of Lex->current_select. */
3765
3399
            if (!($3 || $5) && $2->embedding &&
3766
 
                !$2->embedding->nested_join->join_list.elements)
 
3400
                !$2->embedding->getNestedJoin()->join_list.elements)
3767
3401
            {
3768
3402
              /* we have a derived table ($3 == NULL) but no alias,
3769
3403
                 Since we are nested in further parentheses so we
3776
3410
              /* Handle case of derived table, alias may be NULL if there
3777
3411
                 are no outer parentheses, add_table_to_list() will throw
3778
3412
                 error in this case */
3779
 
              LEX *lex=Lex;
3780
 
              Select_Lex *sel= lex->current_select;
 
3413
              Select_Lex *sel= Lex->current_select;
3781
3414
              Select_Lex_Unit *unit= sel->master_unit();
3782
 
              lex->current_select= sel= unit->outer_select();
3783
 
              if (!($$= sel->add_table_to_list(lex->session,
 
3415
              Lex->current_select= sel= unit->outer_select();
 
3416
              if (!($$= sel->add_table_to_list(Lex->session,
3784
3417
                                               new Table_ident(unit), $5, 0,
3785
3418
                                               TL_READ)))
3786
3419
 
3787
3420
                DRIZZLE_YYABORT;
3788
3421
              sel->add_joined_table($$);
3789
 
              lex->pop_context();
 
3422
              Lex->pop_context();
3790
3423
            }
3791
3424
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3792
3425
            {
3793
3426
              /* simple nested joins cannot have aliases or unions */
3794
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3427
              parser::my_parse_error(YYSession->m_lip);
3795
3428
              DRIZZLE_YYABORT;
3796
3429
            }
3797
3430
            else
3805
3438
          UNION_SYM
3806
3439
          union_option
3807
3440
          {
3808
 
            if (add_select_to_union_list(Lex, (bool)$3))
 
3441
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
3809
3442
              DRIZZLE_YYABORT;
3810
3443
          }
3811
3444
          query_specification
3823
3456
select_init2_derived:
3824
3457
          select_part2_derived
3825
3458
          {
3826
 
            LEX *lex= Lex;
3827
 
            Select_Lex * sel= lex->current_select;
3828
 
            if (lex->current_select->set_braces(0))
 
3459
            Select_Lex * sel= Lex->current_select;
 
3460
            if (Lex->current_select->set_braces(0))
3829
3461
            {
3830
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3462
              parser::my_parse_error(YYSession->m_lip);
3831
3463
              DRIZZLE_YYABORT;
3832
3464
            }
3833
3465
            if (sel->linkage == UNION_TYPE &&
3834
3466
                sel->master_unit()->first_select()->braces)
3835
3467
            {
3836
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3468
              parser::my_parse_error(YYSession->m_lip);
3837
3469
              DRIZZLE_YYABORT;
3838
3470
            }
3839
3471
          }
3842
3474
/* The equivalent of select_part2 for nested queries. */
3843
3475
select_part2_derived:
3844
3476
          {
3845
 
            LEX *lex= Lex;
3846
 
            Select_Lex *sel= lex->current_select;
 
3477
            Select_Lex *sel= Lex->current_select;
3847
3478
            if (sel->linkage != UNION_TYPE)
3848
 
              mysql_init_select(lex);
3849
 
            lex->current_select->parsing_place= SELECT_LIST;
 
3479
              init_select(Lex);
 
3480
            Lex->current_select->parsing_place= SELECT_LIST;
3850
3481
          }
3851
3482
          select_options select_item_list
3852
3483
          {
3859
3490
select_derived:
3860
3491
          get_select_lex
3861
3492
          {
3862
 
            LEX *lex= Lex;
3863
 
            if ($1->init_nested_join(lex->session))
 
3493
            if ($1->init_nested_join(Lex->session))
3864
3494
              DRIZZLE_YYABORT;
3865
3495
          }
3866
3496
          derived_table_list
3867
3497
          {
3868
 
            LEX *lex= Lex;
3869
3498
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3870
3499
               for derived tables, both must equal NULL */
3871
3500
 
3872
 
            if (!($$= $1->end_nested_join(lex->session)) && $3)
 
3501
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
3873
3502
              DRIZZLE_YYABORT;
 
3503
 
3874
3504
            if (!$3 && $$)
3875
3505
            {
3876
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3506
              parser::my_parse_error(YYSession->m_lip);
3877
3507
              DRIZZLE_YYABORT;
3878
3508
            }
3879
3509
          }
3881
3511
 
3882
3512
select_derived2:
3883
3513
          {
3884
 
            LEX *lex= Lex;
3885
 
            lex->derived_tables|= DERIVED_SUBQUERY;
3886
 
            if (!lex->expr_allows_subselect)
 
3514
            Lex->derived_tables|= DERIVED_SUBQUERY;
 
3515
            if (not Lex->expr_allows_subselect)
3887
3516
            {
3888
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3517
              parser::my_parse_error(YYSession->m_lip);
3889
3518
              DRIZZLE_YYABORT;
3890
3519
            }
3891
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
3892
 
                mysql_new_select(lex, 1))
 
3520
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
3893
3521
              DRIZZLE_YYABORT;
3894
 
            mysql_init_select(lex);
3895
 
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
3896
 
            lex->current_select->parsing_place= SELECT_LIST;
 
3522
            init_select(Lex);
 
3523
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3524
            Lex->current_select->parsing_place= SELECT_LIST;
3897
3525
          }
3898
3526
          select_options select_item_list
3899
3527
          {
3909
3537
select_derived_init:
3910
3538
          SELECT_SYM
3911
3539
          {
3912
 
            LEX *lex= Lex;
3913
 
 
3914
 
            Select_Lex *sel= lex->current_select;
 
3540
            Select_Lex *sel= Lex->current_select;
3915
3541
            TableList *embedding;
3916
 
            if (!sel->embedding || sel->end_nested_join(lex->session))
 
3542
            if (!sel->embedding || sel->end_nested_join(Lex->session))
3917
3543
            {
3918
3544
              /* we are not in parentheses */
3919
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3545
              parser::my_parse_error(YYSession->m_lip);
3920
3546
              DRIZZLE_YYABORT;
3921
3547
            }
3922
3548
            embedding= Lex->current_select->embedding;
3923
3549
            $$= embedding &&
3924
 
                !embedding->nested_join->join_list.elements;
 
3550
                !embedding->getNestedJoin()->join_list.elements;
3925
3551
            /* return true if we are deeply nested */
3926
3552
          }
3927
3553
        ;
4064
3690
opt_table_alias:
4065
3691
          /* empty */ { $$=0; }
4066
3692
        | table_alias ident
4067
 
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
 
3693
          {
 
3694
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
 
3695
          }
4068
3696
        ;
4069
3697
 
4070
3698
opt_all:
4144
3772
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
4145
3773
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
4146
3774
            */
4147
 
            LEX *lex= Lex;
4148
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
3775
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4149
3776
            {
4150
3777
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
4151
3778
                       "global union parameters");
4152
3779
              DRIZZLE_YYABORT;
4153
3780
            }
4154
 
            lex->current_select->olap= ROLLUP_TYPE;
 
3781
            Lex->current_select->olap= ROLLUP_TYPE;
4155
3782
          }
4156
3783
        ;
4157
3784
 
4169
3796
        ;
4170
3797
 
4171
3798
alter_order_item:
4172
 
          simple_ident_nospvar order_dir
 
3799
          simple_ident order_dir
4173
3800
          {
4174
 
            Session *session= YYSession;
4175
3801
            bool ascending= ($2 == 1) ? true : false;
4176
 
            if (session->add_order_to_list($1, ascending))
 
3802
            if (YYSession->add_order_to_list($1, ascending))
4177
3803
              DRIZZLE_YYABORT;
4178
3804
          }
4179
3805
        ;
4190
3816
order_clause:
4191
3817
          ORDER_SYM BY
4192
3818
          {
4193
 
            LEX *lex=Lex;
4194
 
            Select_Lex *sel= lex->current_select;
4195
 
            Select_Lex_Unit *unit= sel-> master_unit();
4196
 
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4197
 
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
4198
 
                (sel->linkage != UNION_TYPE || sel->braces))
4199
 
            {
4200
 
              my_error(ER_WRONG_USAGE, MYF(0),
4201
 
                       "CUBE/ROLLUP", "ORDER BY");
 
3819
            if (not parser::buildOrderBy(Lex))
4202
3820
              DRIZZLE_YYABORT;
4203
 
            }
4204
 
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
4205
 
            {
4206
 
              /*
4207
 
                A query of the of the form (SELECT ...) ORDER BY order_list is
4208
 
                executed in the same way as the query
4209
 
                SELECT ... ORDER BY order_list
4210
 
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
4211
 
                Otherwise we create a fake Select_Lex if it has not been created
4212
 
                yet.
4213
 
              */
4214
 
              Select_Lex *first_sl= unit->first_select();
4215
 
              if (!unit->is_union() &&
4216
 
                  (first_sl->order_list.elements ||
4217
 
                   first_sl->select_limit) &&           
4218
 
                  unit->add_fake_select_lex(lex->session))
4219
 
                DRIZZLE_YYABORT;
4220
 
            }
4221
3821
          }
4222
3822
          order_list
4223
3823
        ;
4224
3824
 
4225
3825
order_list:
4226
3826
          order_list ',' order_ident order_dir
4227
 
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
 
3827
          {
 
3828
            if (YYSession->add_order_to_list($3,(bool) $4))
 
3829
              DRIZZLE_YYABORT;
 
3830
          }
4228
3831
        | order_ident order_dir
4229
 
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
 
3832
          {
 
3833
            if (YYSession->add_order_to_list($1,(bool) $2))
 
3834
              DRIZZLE_YYABORT;
 
3835
          }
4230
3836
        ;
4231
3837
 
4232
3838
order_dir:
4238
3844
opt_limit_clause_init:
4239
3845
          /* empty */
4240
3846
          {
4241
 
            LEX *lex= Lex;
4242
 
            Select_Lex *sel= lex->current_select;
 
3847
            Select_Lex *sel= Lex->current_select;
4243
3848
            sel->offset_limit= 0;
4244
3849
            sel->select_limit= 0;
4245
3850
          }
4288
3893
delete_limit_clause:
4289
3894
          /* empty */
4290
3895
          {
4291
 
            LEX *lex=Lex;
4292
 
            lex->current_select->select_limit= 0;
 
3896
            Lex->current_select->select_limit= 0;
4293
3897
          }
4294
3898
        | LIMIT limit_option
4295
3899
          {
4300
3904
        ;
4301
3905
 
4302
3906
ulong_num:
4303
 
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4304
 
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
4305
 
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4306
 
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4307
 
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4308
 
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
3907
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
3908
        | HEX_NUM       { $$= (unsigned long) strtol($1.str, (char**) 0, 16); }
 
3909
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
3910
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
3911
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
3912
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
4309
3913
        ;
4310
3914
 
4311
3915
ulonglong_num:
4318
3922
 
4319
3923
select_var_list_init:
4320
3924
          {
4321
 
            LEX *lex=Lex;
4322
 
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
 
3925
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
4323
3926
              DRIZZLE_YYABORT;
4324
3927
          }
4325
3928
          select_var_list
4332
3935
        ;
4333
3936
 
4334
3937
select_var_ident: 
4335
 
          '@' ident_or_text
 
3938
          '@' user_variable_ident
4336
3939
          {
4337
 
            LEX *lex=Lex;
4338
 
            if (lex->result)
4339
 
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
 
3940
            if (Lex->result)
 
3941
            {
 
3942
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
 
3943
            }
4340
3944
            else
 
3945
            {
4341
3946
              /*
4342
3947
                The parser won't create select_result instance only
4343
3948
                if it's an EXPLAIN.
4344
3949
              */
4345
 
              assert(lex->describe);
 
3950
              assert(Lex->describe);
 
3951
            }
4346
3952
          }
4347
3953
        ;
4348
3954
 
4355
3961
into_destination:
4356
3962
          OUTFILE TEXT_STRING_filesystem
4357
3963
          {
4358
 
            LEX *lex= Lex;
4359
 
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
4360
 
                !(lex->result= new select_export(lex->exchange)))
 
3964
            Lex->setCacheable(false);
 
3965
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
 
3966
                !(Lex->result= new select_export(Lex->exchange)))
4361
3967
              DRIZZLE_YYABORT;
4362
3968
          }
4363
3969
          opt_field_term opt_line_term
4364
3970
        | DUMPFILE TEXT_STRING_filesystem
4365
3971
          {
4366
 
            LEX *lex=Lex;
4367
 
            if (!lex->describe)
 
3972
            if (not Lex->describe)
4368
3973
            {
4369
 
              if (!(lex->exchange= new file_exchange($2.str,1)))
 
3974
              Lex->setCacheable(false);
 
3975
              if (not (Lex->exchange= new file_exchange($2.str,1)))
4370
3976
                DRIZZLE_YYABORT;
4371
 
              if (!(lex->result= new select_dump(lex->exchange)))
 
3977
              if (not (Lex->result= new select_dump(Lex->exchange)))
4372
3978
                DRIZZLE_YYABORT;
4373
3979
            }
4374
3980
          }
4375
3981
        | select_var_list_init
4376
 
          { }
 
3982
          {Lex->setCacheable(false);}
4377
3983
        ;
4378
3984
 
4379
3985
/*
4381
3987
*/
4382
3988
 
4383
3989
drop:
4384
 
          DROP opt_temporary table_or_tables if_exists table_list
4385
 
          {
4386
 
            LEX *lex=Lex;
4387
 
            lex->sql_command = SQLCOM_DROP_TABLE;
4388
 
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
4389
 
            lex->statement= statement;
4390
 
            if (lex->statement == NULL)
4391
 
              DRIZZLE_YYABORT;
 
3990
          DROP CATALOG_SYM catalog_name
 
3991
          {
 
3992
            Lex->statement= new statement::catalog::Drop(YYSession, $3);
 
3993
          }
 
3994
        | DROP opt_temporary table_or_tables if_exists table_list
 
3995
          {
 
3996
            statement::DropTable *statement= new statement::DropTable(YYSession);
 
3997
            Lex->statement= statement;
4392
3998
            statement->drop_temporary= $2;
4393
3999
            statement->drop_if_exists= $4;
4394
4000
          }
4395
4001
        | DROP build_method INDEX_SYM ident ON table_ident {}
4396
4002
          {
4397
 
            LEX *lex=Lex;
4398
 
            lex->sql_command= SQLCOM_DROP_INDEX;
4399
 
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
4400
 
            lex->statement= statement;
4401
 
            if (lex->statement == NULL)
4402
 
              DRIZZLE_YYABORT;
 
4003
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
 
4004
            Lex->statement= statement;
4403
4005
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4404
4006
            statement->alter_info.build_method= $2;
4405
4007
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4406
 
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4407
 
                                                        TL_OPTION_UPDATING))
 
4008
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
 
4009
                                                          TL_OPTION_UPDATING))
4408
4010
              DRIZZLE_YYABORT;
4409
4011
          }
4410
 
        | DROP DATABASE if_exists ident
 
4012
        | DROP DATABASE if_exists schema_name
4411
4013
          {
4412
 
            LEX *lex=Lex;
4413
 
            lex->sql_command= SQLCOM_DROP_DB;
4414
 
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
4415
 
            lex->statement= statement;
4416
 
            if (lex->statement == NULL)
4417
 
              DRIZZLE_YYABORT;
 
4014
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
 
4015
            Lex->statement= statement;
4418
4016
            statement->drop_if_exists=$3;
4419
 
            lex->name= $4;
 
4017
            Lex->name= $4;
4420
4018
          }
 
4019
        ;
 
4020
 
4421
4021
table_list:
4422
4022
          table_name
4423
4023
        | table_list ',' table_name
4432
4032
        ;
4433
4033
 
4434
4034
if_exists:
4435
 
          /* empty */ { $$= 0; }
4436
 
        | IF EXISTS { $$= 1; }
 
4035
          /* empty */ { $$= false; }
 
4036
        | IF EXISTS { $$= true; }
4437
4037
        ;
4438
4038
 
4439
4039
opt_temporary:
4440
 
          /* empty */ { $$= 0; }
4441
 
        | TEMPORARY_SYM { $$= 1; }
4442
 
        ;
 
4040
          /* empty */ { $$= false; }
 
4041
        | TEMPORARY_SYM { $$= true; }
 
4042
        ;
 
4043
 
 
4044
/*
 
4045
  Execute a string as dynamic SQL.
 
4046
*/
 
4047
 
 
4048
execute:
 
4049
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
 
4050
        {
 
4051
          Lex->statement= new statement::Execute(YYSession, $2, $3, $4, $5);
 
4052
        }
 
4053
 
 
4054
 
 
4055
execute_var_or_string:
 
4056
         user_variable_ident
 
4057
         {
 
4058
            $$.set($1);
 
4059
         }
 
4060
        | '@' user_variable_ident
 
4061
        {
 
4062
            $$.set($2, true);
 
4063
        }
 
4064
 
 
4065
opt_status:
 
4066
          /* empty */ { $$= false; }
 
4067
        | WITH NO_SYM RETURN_SYM { $$= true; }
 
4068
        ;
 
4069
 
 
4070
opt_concurrent:
 
4071
          /* empty */ { $$= false; }
 
4072
        | CONCURRENT { $$= true; }
 
4073
        ;
 
4074
 
 
4075
opt_wait:
 
4076
          /* empty */ { $$= false; }
 
4077
        | WAIT_SYM { $$= true; }
 
4078
        ;
 
4079
 
4443
4080
/*
4444
4081
** Insert : add new data to table
4445
4082
*/
4447
4084
insert:
4448
4085
          INSERT
4449
4086
          {
4450
 
            LEX *lex= Lex;
4451
 
            lex->sql_command= SQLCOM_INSERT;
4452
 
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
4453
 
            if (lex->statement == NULL)
4454
 
              DRIZZLE_YYABORT;
4455
 
            lex->duplicates= DUP_ERROR;
4456
 
            mysql_init_select(lex);
 
4087
            Lex->statement= new statement::Insert(YYSession);
 
4088
            Lex->duplicates= DUP_ERROR;
 
4089
            init_select(Lex);
4457
4090
            /* for subselects */
4458
 
            lex->lock_option= TL_READ;
 
4091
            Lex->lock_option= TL_READ;
4459
4092
          }
4460
4093
          opt_ignore insert2
4461
4094
          {
4469
4102
replace:
4470
4103
          REPLACE
4471
4104
          {
4472
 
            LEX *lex= Lex;
4473
 
            lex->sql_command= SQLCOM_REPLACE;
4474
 
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
4475
 
            if (lex->statement == NULL)
4476
 
              DRIZZLE_YYABORT;
4477
 
            lex->duplicates= DUP_REPLACE;
4478
 
            mysql_init_select(lex);
 
4105
            Lex->statement= new statement::Replace(YYSession);
 
4106
            Lex->duplicates= DUP_REPLACE;
 
4107
            init_select(Lex);
4479
4108
          }
4480
4109
          insert2
4481
4110
          {
4494
4123
insert_table:
4495
4124
          table_name
4496
4125
          {
4497
 
            LEX *lex=Lex;
4498
 
            lex->field_list.empty();
4499
 
            lex->many_values.empty();
4500
 
            lex->insert_list=0;
 
4126
            Lex->field_list.empty();
 
4127
            Lex->many_values.empty();
 
4128
            Lex->insert_list=0;
4501
4129
          };
4502
4130
 
4503
4131
insert_field_spec:
4504
4132
          insert_values {}
4505
4133
        | '(' ')' insert_values {}
4506
4134
        | '(' fields ')' insert_values {}
4507
 
        | SET
 
4135
        | SET_SYM
4508
4136
          {
4509
 
            LEX *lex=Lex;
4510
 
            if (!(lex->insert_list = new List_item) ||
4511
 
                lex->many_values.push_back(lex->insert_list))
 
4137
            if (not (Lex->insert_list = new List_item) ||
 
4138
                Lex->many_values.push_back(Lex->insert_list))
4512
4139
              DRIZZLE_YYABORT;
4513
4140
          }
4514
4141
          ident_eq_list
4522
4149
insert_values:
4523
4150
          VALUES values_list {}
4524
4151
        | VALUE_SYM values_list {}
4525
 
        | create_select
4526
 
          { Lex->current_select->set_braces(0);}
 
4152
        | stored_select
 
4153
          {
 
4154
            Lex->current_select->set_braces(0);
 
4155
          }
4527
4156
          union_clause {}
4528
 
        | '(' create_select ')'
4529
 
          { Lex->current_select->set_braces(1);}
 
4157
        | '(' stored_select ')'
 
4158
          {
 
4159
            Lex->current_select->set_braces(1);
 
4160
          }
4530
4161
          union_opt {}
4531
4162
        ;
4532
4163
 
4541
4172
        ;
4542
4173
 
4543
4174
ident_eq_value:
4544
 
          simple_ident_nospvar equal expr_or_default
 
4175
          simple_ident equal expr_or_default
4545
4176
          {
4546
 
            LEX *lex=Lex;
4547
 
            if (lex->field_list.push_back($1) ||
4548
 
                lex->insert_list->push_back($3))
 
4177
            if (Lex->field_list.push_back($1) ||
 
4178
                Lex->insert_list->push_back($3))
4549
4179
              DRIZZLE_YYABORT;
4550
4180
          }
4551
4181
        ;
4568
4198
          }
4569
4199
          opt_values ')'
4570
4200
          {
4571
 
            LEX *lex=Lex;
4572
 
            if (lex->many_values.push_back(lex->insert_list))
 
4201
            if (Lex->many_values.push_back(Lex->insert_list))
4573
4202
              DRIZZLE_YYABORT;
4574
4203
          }
4575
4204
        ;
4608
4237
update:
4609
4238
          UPDATE_SYM opt_ignore table_ident
4610
4239
          {
4611
 
            LEX *lex= Lex;
4612
 
            mysql_init_select(lex);
4613
 
            lex->sql_command= SQLCOM_UPDATE;
4614
 
            lex->statement= new(std::nothrow) statement::Update(YYSession);
4615
 
            if (lex->statement == NULL)
4616
 
              DRIZZLE_YYABORT;
4617
 
            lex->lock_option= TL_UNLOCK; /* Will be set later */
4618
 
            lex->duplicates= DUP_ERROR;
4619
 
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4240
            init_select(Lex);
 
4241
            Lex->statement= new statement::Update(YYSession);
 
4242
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4243
            Lex->duplicates= DUP_ERROR;
 
4244
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4620
4245
              DRIZZLE_YYABORT;
4621
4246
          }
4622
 
          SET update_list
 
4247
          SET_SYM update_list
4623
4248
          {
4624
 
            LEX *lex= Lex;
4625
 
            if (lex->select_lex.get_table_list()->derived)
 
4249
            if (Lex->select_lex.get_table_list()->derived)
4626
4250
            {
4627
4251
              /* it is single table update and it is update of derived table */
4628
4252
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4629
 
                       lex->select_lex.get_table_list()->alias, "UPDATE");
 
4253
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
4630
4254
              DRIZZLE_YYABORT;
4631
4255
            }
4632
4256
            /*
4633
4257
              In case of multi-update setting write lock for all tables may
4634
4258
              be too pessimistic. We will decrease lock level if possible in
4635
 
              mysql_multi_update().
 
4259
              multi_update().
4636
4260
            */
4637
4261
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4638
4262
          }
4645
4269
        ;
4646
4270
 
4647
4271
update_elem:
4648
 
          simple_ident_nospvar equal expr_or_default
 
4272
          simple_ident equal expr_or_default
4649
4273
          {
4650
4274
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4651
4275
              DRIZZLE_YYABORT;
4658
4282
        ;
4659
4283
 
4660
4284
insert_update_elem:
4661
 
          simple_ident_nospvar equal expr_or_default
 
4285
          simple_ident equal expr_or_default
4662
4286
          {
4663
 
          LEX *lex= Lex;
4664
 
          if (lex->update_list.push_back($1) ||
4665
 
              lex->value_list.push_back($3))
 
4287
          if (Lex->update_list.push_back($1) ||
 
4288
              Lex->value_list.push_back($3))
4666
4289
              DRIZZLE_YYABORT;
4667
4290
          }
4668
4291
        ;
4672
4295
delete:
4673
4296
          DELETE_SYM
4674
4297
          {
4675
 
            LEX *lex= Lex;
4676
 
            lex->sql_command= SQLCOM_DELETE;
4677
 
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
4678
 
            if (lex->statement == NULL)
4679
 
              DRIZZLE_YYABORT;
4680
 
            mysql_init_select(lex);
4681
 
            lex->lock_option= TL_WRITE_DEFAULT;
4682
 
            lex->ignore= 0;
4683
 
            lex->select_lex.init_order();
 
4298
            Lex->statement= new statement::Delete(YYSession);
 
4299
            init_select(Lex);
 
4300
            Lex->lock_option= TL_WRITE_DEFAULT;
 
4301
            Lex->ignore= 0;
 
4302
            Lex->select_lex.init_order();
4684
4303
          }
4685
4304
          opt_delete_options single_multi
4686
4305
        ;
4708
4327
truncate:
4709
4328
          TRUNCATE_SYM opt_table_sym table_name
4710
4329
          {
4711
 
            LEX* lex= Lex;
4712
 
            lex->sql_command= SQLCOM_TRUNCATE;
4713
 
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
4714
 
            if (lex->statement == NULL)
4715
 
              DRIZZLE_YYABORT;
4716
 
            lex->select_lex.options= 0;
4717
 
            lex->select_lex.init_order();
 
4330
            Lex->statement= new statement::Truncate(YYSession);
 
4331
            Lex->select_lex.options= 0;
 
4332
            Lex->select_lex.init_order();
4718
4333
          }
4719
4334
        ;
4720
4335
 
4728
4343
show:
4729
4344
          SHOW
4730
4345
          {
4731
 
            LEX *lex=Lex;
4732
 
            lex->wild=0;
4733
 
            lex->lock_option= TL_READ;
4734
 
            mysql_init_select(lex);
4735
 
            lex->current_select->parsing_place= SELECT_LIST;
 
4346
            Lex->lock_option= TL_READ;
 
4347
            init_select(Lex);
 
4348
            Lex->current_select->parsing_place= SELECT_LIST;
4736
4349
          }
4737
4350
          show_param
4738
4351
          {}
4739
4352
        ;
4740
4353
 
 
4354
/* SHOW SCHEMAS */
4741
4355
show_param:
4742
4356
           DATABASES show_wild
4743
4357
           {
4744
 
             LEX *lex= Lex;
4745
 
             Session *session= YYSession;
4746
 
 
4747
 
             lex->sql_command= SQLCOM_SELECT;
4748
 
             lex->statement=
4749
 
               new(std::nothrow) statement::Select(session);
4750
 
             if (lex->statement == NULL)
4751
 
               DRIZZLE_YYABORT;
4752
 
 
4753
 
             std::string column_name= "Database";
4754
 
             if (Lex->wild)
4755
 
             {
4756
 
               column_name.append(" (");
4757
 
               column_name.append(Lex->wild->ptr());
4758
 
               column_name.append(")");
4759
 
             }
4760
 
 
4761
 
             if (Lex->current_select->where)
4762
 
             {
4763
 
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4764
 
                 DRIZZLE_YYABORT;
4765
 
             }
4766
 
             else
4767
 
             {
4768
 
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4769
 
                 DRIZZLE_YYABORT;
4770
 
             }
4771
 
 
4772
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4773
 
             my_field->is_autogenerated_name= false;
4774
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4775
 
 
4776
 
             if (session->add_item_to_list(my_field))
 
4358
             if (not show::buildScemas(YYSession))
4777
4359
               DRIZZLE_YYABORT;
4778
4360
           }
 
4361
           /* SHOW TABLES */
4779
4362
         | TABLES opt_db show_wild
4780
4363
           {
4781
 
             LEX *lex= Lex;
4782
 
             Session *session= YYSession;
4783
 
 
4784
 
             lex->sql_command= SQLCOM_SELECT;
4785
 
 
4786
 
             statement::Select *select=
4787
 
               new(std::nothrow) statement::Select(YYSession);
4788
 
 
4789
 
             lex->statement= select;
4790
 
 
4791
 
             if (lex->statement == NULL)
4792
 
               DRIZZLE_YYABORT;
4793
 
 
4794
 
 
4795
 
              std::string column_name= "Tables_in_";
4796
 
 
4797
 
              if ($2)
4798
 
              {
4799
 
                SchemaIdentifier identifier($2);
4800
 
                column_name.append($2);
4801
 
                lex->select_lex.db= $2;
4802
 
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
4803
 
                {
4804
 
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4805
 
                }
4806
 
                select->setShowPredicate($2, "");
4807
 
              }
4808
 
              else if (not session->db.empty())
4809
 
              {
4810
 
                column_name.append(session->db);
4811
 
                select->setShowPredicate(session->db, "");
4812
 
              }
4813
 
              else
4814
 
              {
4815
 
                 my_error(ER_NO_DB_ERROR, MYF(0));
4816
 
              }
4817
 
 
4818
 
 
4819
 
             if (Lex->wild)
4820
 
             {
4821
 
               column_name.append(" (");
4822
 
               column_name.append(Lex->wild->ptr());
4823
 
               column_name.append(")");
4824
 
             }
4825
 
 
4826
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4827
 
               DRIZZLE_YYABORT;
4828
 
 
4829
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4830
 
             my_field->is_autogenerated_name= false;
4831
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4832
 
 
4833
 
             if (session->add_item_to_list(my_field))
 
4364
             if (not show::buildTables(YYSession, $2))
4834
4365
               DRIZZLE_YYABORT;
4835
4366
           }
 
4367
           /* SHOW TEMPORARY TABLES */
4836
4368
         | TEMPORARY_SYM TABLES show_wild
4837
4369
           {
4838
 
             LEX *lex= Lex;
4839
 
             Session *session= YYSession;
4840
 
 
4841
 
             lex->sql_command= SQLCOM_SELECT;
4842
 
 
4843
 
             statement::Select *select=
4844
 
               new(std::nothrow) statement::Select(YYSession);
4845
 
 
4846
 
             lex->statement= select;
4847
 
 
4848
 
             if (lex->statement == NULL)
4849
 
               DRIZZLE_YYABORT;
4850
 
 
4851
 
 
4852
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4853
 
               DRIZZLE_YYABORT;
4854
 
 
4855
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4856
 
                                                           context,
4857
 
                                                           NULL, NULL, "*")))
4858
 
               DRIZZLE_YYABORT;
4859
 
             (session->lex->current_select->with_wild)++;
4860
 
 
 
4370
             if (not show::buildTemporaryTables(YYSession))
 
4371
               DRIZZLE_YYABORT;
4861
4372
           }
 
4373
           /* SHOW TABLE STATUS */
4862
4374
         | TABLE_SYM STATUS_SYM opt_db show_wild
4863
4375
           {
4864
 
             LEX *lex= Lex;
4865
 
             lex->sql_command= SQLCOM_SELECT;
4866
 
             statement::Select *select=
4867
 
               new(std::nothrow) statement::Select(YYSession);
4868
 
 
4869
 
             lex->statement= select;
4870
 
 
4871
 
             if (lex->statement == NULL)
4872
 
               DRIZZLE_YYABORT;
4873
 
 
4874
 
             Session *session= YYSession;
4875
 
 
4876
 
             std::string column_name= "Tables_in_";
4877
 
 
4878
 
             if ($3)
4879
 
             {
4880
 
               lex->select_lex.db= $3;
4881
 
 
4882
 
               SchemaIdentifier identifier($3);
4883
 
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
4884
 
               {
4885
 
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4886
 
               }
4887
 
 
4888
 
               select->setShowPredicate($3, "");
4889
 
             }
4890
 
             else
4891
 
             {
4892
 
               select->setShowPredicate(session->db, "");
4893
 
             }
4894
 
 
4895
 
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
4896
 
               DRIZZLE_YYABORT;
4897
 
 
4898
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4899
 
                                                           context,
4900
 
                                                           NULL, NULL, "*")))
4901
 
               DRIZZLE_YYABORT;
4902
 
             (session->lex->current_select->with_wild)++;
 
4376
             if (not show::buildTableStatus(YYSession, $3))
 
4377
               DRIZZLE_YYABORT;
4903
4378
           }
 
4379
           /* SHOW COLUMNS FROM table_name */
4904
4380
        | COLUMNS from_or_in table_ident opt_db show_wild
4905
 
          {
4906
 
             LEX *lex= Lex;
4907
 
             Session *session= YYSession;
4908
 
             statement::Select *select;
4909
 
 
4910
 
             lex->sql_command= SQLCOM_SELECT;
4911
 
 
4912
 
             select= new(std::nothrow) statement::Select(session);
4913
 
 
4914
 
             lex->statement= select;
4915
 
 
4916
 
             if (lex->statement == NULL)
4917
 
               DRIZZLE_YYABORT;
4918
 
 
4919
 
             if ($4)
4920
 
              select->setShowPredicate($4, $3->table.str);
4921
 
             else if ($3->db.str)
4922
 
              select->setShowPredicate($3->db.str, $3->table.str);
4923
 
             else
4924
 
              select->setShowPredicate(session->db, $3->table.str);
4925
 
 
4926
 
             {
4927
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4928
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4929
 
               {
4930
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
4931
 
                            select->getShowSchema().c_str(), 
4932
 
                            $3->table.str);
4933
 
               }
4934
 
             }
4935
 
 
4936
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
4937
 
               DRIZZLE_YYABORT;
4938
 
 
4939
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4940
 
                                                           context,
4941
 
                                                           NULL, NULL, "*")))
4942
 
               DRIZZLE_YYABORT;
4943
 
             (session->lex->current_select->with_wild)++;
4944
 
 
4945
 
          }
 
4381
           {
 
4382
             if (not show::buildColumns(YYSession, $4, $3))
 
4383
               DRIZZLE_YYABORT;
 
4384
           }
 
4385
          /* SHOW INDEXES from table */
4946
4386
        | keys_or_index from_or_in table_ident opt_db where_clause
4947
 
          {
4948
 
             LEX *lex= Lex;
4949
 
             Session *session= YYSession;
4950
 
             statement::Select *select;
4951
 
 
4952
 
             lex->sql_command= SQLCOM_SELECT;
4953
 
 
4954
 
             select= new(std::nothrow) statement::Select(session);
4955
 
 
4956
 
             lex->statement= select;
4957
 
 
4958
 
             if (lex->statement == NULL)
4959
 
               DRIZZLE_YYABORT;
4960
 
 
4961
 
             if ($4)
4962
 
              select->setShowPredicate($4, $3->table.str);
4963
 
             else if ($3->db.str)
4964
 
              select->setShowPredicate($3->db.str, $3->table.str);
4965
 
             else
4966
 
              select->setShowPredicate(session->db, $3->table.str);
4967
 
 
4968
 
             {
4969
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4970
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4971
 
               {
4972
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
4973
 
                            select->getShowSchema().c_str(), 
4974
 
                            $3->table.str);
4975
 
               }
4976
 
             }
4977
 
 
4978
 
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
4979
 
               DRIZZLE_YYABORT;
4980
 
 
4981
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4982
 
                                                           context,
4983
 
                                                           NULL, NULL, "*")))
4984
 
               DRIZZLE_YYABORT;
4985
 
             (session->lex->current_select->with_wild)++;
4986
 
          }
 
4387
           {
 
4388
             if (not show::buildIndex(YYSession, $4, $3))
 
4389
               DRIZZLE_YYABORT;
 
4390
           }
4987
4391
        | COUNT_SYM '(' '*' ')' WARNINGS
4988
4392
          {
4989
 
            (void) create_select_for_variable("warning_count");
4990
 
            LEX *lex= Lex;
4991
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
4992
 
            if (lex->statement == NULL)
4993
 
              DRIZZLE_YYABORT;
 
4393
            show::buildSelectWarning(YYSession);
4994
4394
          }
4995
4395
        | COUNT_SYM '(' '*' ')' ERRORS
4996
4396
          {
4997
 
            (void) create_select_for_variable("error_count");
4998
 
            LEX *lex= Lex;
4999
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
5000
 
            if (lex->statement == NULL)
5001
 
              DRIZZLE_YYABORT;
 
4397
            show::buildSelectError(YYSession);
5002
4398
          }
5003
4399
        | WARNINGS opt_limit_clause_init
5004
4400
          {
5005
 
            Lex->sql_command = SQLCOM_SHOW_WARNS;
5006
 
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5007
 
            if (Lex->statement == NULL)
5008
 
              DRIZZLE_YYABORT;
 
4401
            show::buildWarnings(YYSession);
5009
4402
          }
5010
4403
        | ERRORS opt_limit_clause_init
5011
4404
          {
5012
 
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
5013
 
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5014
 
            if (Lex->statement == NULL)
5015
 
              DRIZZLE_YYABORT;
 
4405
            show::buildErrors(YYSession);
5016
4406
          }
5017
4407
        | opt_var_type STATUS_SYM show_wild
5018
 
           {
5019
 
             LEX *lex= Lex;
5020
 
             lex->sql_command= SQLCOM_SELECT;
5021
 
             lex->statement=
5022
 
               new(std::nothrow) statement::Select(YYSession);
5023
 
             if (lex->statement == NULL)
5024
 
               DRIZZLE_YYABORT;
5025
 
 
5026
 
             Session *session= YYSession;
5027
 
 
5028
 
             if ($1 == OPT_GLOBAL)
5029
 
             {
5030
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5031
 
                 DRIZZLE_YYABORT;
5032
 
             }
5033
 
             else
5034
 
             {
5035
 
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5036
 
                 DRIZZLE_YYABORT;
5037
 
             }
5038
 
 
5039
 
             std::string key("Variable_name");
5040
 
             std::string value("Value");
5041
 
 
5042
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5043
 
             my_field->is_autogenerated_name= false;
5044
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5045
 
 
5046
 
             if (session->add_item_to_list(my_field))
5047
 
               DRIZZLE_YYABORT;
5048
 
 
5049
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5050
 
             my_field->is_autogenerated_name= false;
5051
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5052
 
 
5053
 
             if (session->add_item_to_list(my_field))
5054
 
               DRIZZLE_YYABORT;
5055
 
           }
 
4408
          {
 
4409
            if (not show::buildStatus(YYSession, $1))
 
4410
              DRIZZLE_YYABORT;
 
4411
          }
 
4412
        | engine_option_value STATUS_SYM
 
4413
          {
 
4414
            if (not show::buildEngineStatus(YYSession, $1))
 
4415
              DRIZZLE_YYABORT;
 
4416
          }
 
4417
        | CREATE TABLE_SYM table_ident
 
4418
          {
 
4419
            if (not show::buildCreateTable(YYSession, $3))
 
4420
              DRIZZLE_YYABORT;
 
4421
          }
5056
4422
        | PROCESSLIST_SYM
5057
4423
          {
5058
 
           {
5059
 
             LEX *lex= Lex;
5060
 
             lex->sql_command= SQLCOM_SELECT;
5061
 
             lex->statement=
5062
 
               new(std::nothrow) statement::Select(YYSession);
5063
 
             if (lex->statement == NULL)
5064
 
               DRIZZLE_YYABORT;
5065
 
 
5066
 
             Session *session= YYSession;
5067
 
 
5068
 
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5069
 
               DRIZZLE_YYABORT;
5070
 
 
5071
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5072
 
                                                           context,
5073
 
                                                           NULL, NULL, "*")))
5074
 
               DRIZZLE_YYABORT;
5075
 
             (session->lex->current_select->with_wild)++;
5076
 
           }
 
4424
            if (not show::buildProcesslist(YYSession))
 
4425
              DRIZZLE_YYABORT;
5077
4426
          }
5078
4427
        | opt_var_type  VARIABLES show_wild
5079
 
           {
5080
 
             LEX *lex= Lex;
5081
 
             lex->sql_command= SQLCOM_SELECT;
5082
 
             lex->statement=
5083
 
               new(std::nothrow) statement::Select(YYSession);
5084
 
             if (lex->statement == NULL)
5085
 
               DRIZZLE_YYABORT;
5086
 
 
5087
 
             Session *session= YYSession;
5088
 
 
5089
 
             if ($1 == OPT_GLOBAL)
5090
 
             {
5091
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5092
 
                 DRIZZLE_YYABORT;
5093
 
             }
5094
 
             else
5095
 
             {
5096
 
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5097
 
                 DRIZZLE_YYABORT;
5098
 
             }
5099
 
 
5100
 
             std::string key("Variable_name");
5101
 
             std::string value("Value");
5102
 
 
5103
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5104
 
             my_field->is_autogenerated_name= false;
5105
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5106
 
 
5107
 
             if (session->add_item_to_list(my_field))
5108
 
               DRIZZLE_YYABORT;
5109
 
 
5110
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5111
 
             my_field->is_autogenerated_name= false;
5112
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5113
 
 
5114
 
             if (session->add_item_to_list(my_field))
5115
 
               DRIZZLE_YYABORT;
5116
 
           }
 
4428
          {
 
4429
            if (not show::buildVariables(YYSession, $1))
 
4430
              DRIZZLE_YYABORT;
 
4431
          }
5117
4432
        | CREATE DATABASE opt_if_not_exists ident
5118
4433
          {
5119
 
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5120
 
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
5121
 
            Lex->statement= statement;
5122
 
            if (Lex->statement == NULL)
5123
 
              DRIZZLE_YYABORT;
5124
 
            statement->is_if_not_exists= $3;
5125
 
            Lex->name= $4;
5126
 
          }
5127
 
        | CREATE TABLE_SYM table_ident
5128
 
          {
5129
 
            LEX *lex= Lex;
5130
 
            lex->sql_command = SQLCOM_SHOW_CREATE;
5131
 
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
5132
 
            if (lex->statement == NULL)
5133
 
              DRIZZLE_YYABORT;
5134
 
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4434
            if (not show::buildCreateSchema(YYSession, $4))
5135
4435
              DRIZZLE_YYABORT;
5136
4436
          }
5137
4437
 
5166
4466
describe:
5167
4467
          describe_command table_ident
5168
4468
          {
5169
 
            Session *session= YYSession;
5170
 
            statement::Select *select;
5171
 
            LEX *lex= Lex;
5172
 
            lex->lock_option= TL_READ;
5173
 
            mysql_init_select(lex);
5174
 
            lex->current_select->parsing_place= SELECT_LIST;
5175
 
            lex->sql_command= SQLCOM_SELECT;
5176
 
            select= new(std::nothrow) statement::Select(session);
5177
 
            lex->statement= select;
5178
 
            if (lex->statement == NULL)
 
4469
            if (not show::buildDescribe(YYSession, $2))
 
4470
            {
5179
4471
              DRIZZLE_YYABORT;
5180
 
            lex->select_lex.db= 0;
5181
 
 
5182
 
             if ($2->db.str)
5183
 
              select->setShowPredicate($2->db.str, $2->table.str);
5184
 
             else
5185
 
              select->setShowPredicate(session->db, $2->table.str);
5186
 
 
5187
 
             {
5188
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
5189
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5190
 
               {
5191
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5192
 
                            select->getShowSchema().c_str(), 
5193
 
                            $2->table.str);
5194
 
               }
5195
 
             }
5196
 
 
5197
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5198
 
               DRIZZLE_YYABORT;
5199
 
 
5200
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5201
 
                                                           context,
5202
 
                                                           NULL, NULL, "*")))
5203
 
               DRIZZLE_YYABORT;
5204
 
             (session->lex->current_select->with_wild)++;
5205
 
 
 
4472
            }
5206
4473
          }
5207
4474
          opt_describe_column {}
5208
4475
        | describe_command opt_extended_describe
5209
4476
          { Lex->describe|= DESCRIBE_NORMAL; }
5210
4477
          select
5211
4478
          {
5212
 
            LEX *lex=Lex;
5213
 
            lex->select_lex.options|= SELECT_DESCRIBE;
 
4479
            Lex->select_lex.options|= SELECT_DESCRIBE;
5214
4480
          }
5215
4481
        ;
5216
4482
 
5241
4507
flush:
5242
4508
          FLUSH_SYM
5243
4509
          {
5244
 
            LEX *lex=Lex;
5245
 
            lex->sql_command= SQLCOM_FLUSH;
5246
 
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
5247
 
            if (lex->statement == NULL)
5248
 
              DRIZZLE_YYABORT;
5249
 
            lex->type= 0;
 
4510
            Lex->statement= new statement::Flush(YYSession);
5250
4511
          }
5251
4512
          flush_options
5252
4513
          {}
5279
4540
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5280
4541
            statement->setFlushStatus(true);
5281
4542
          }
 
4543
        | GLOBAL_SYM STATUS_SYM
 
4544
          {
 
4545
            statement::Flush *statement= (statement::Flush*)Lex->statement;
 
4546
            statement->setFlushGlobalStatus(true);
 
4547
          }
5282
4548
        ;
5283
4549
 
5284
4550
opt_table_list:
5291
4557
kill:
5292
4558
          KILL_SYM kill_option expr
5293
4559
          {
5294
 
            LEX *lex=Lex;
5295
 
            lex->value_list.empty();
5296
 
            lex->value_list.push_front($3);
5297
 
            lex->sql_command= SQLCOM_KILL;
5298
 
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
5299
 
            if (lex->statement == NULL)
5300
 
              DRIZZLE_YYABORT;
 
4560
            Lex->statement= new statement::Kill(YYSession, $3, $2);
5301
4561
          }
5302
4562
        ;
5303
4563
 
5304
4564
kill_option:
5305
 
          /* empty */ { Lex->type= 0; }
5306
 
        | CONNECTION_SYM { Lex->type= 0; }
5307
 
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
 
4565
          /* empty */ { $$= false; }
 
4566
        | CONNECTION_SYM { $$= false; }
 
4567
        | QUERY_SYM      { $$= true; }
5308
4568
        ;
5309
4569
 
5310
4570
/* change database */
5311
4571
 
5312
4572
use:
5313
 
          USE_SYM ident
 
4573
          USE_SYM schema_name
5314
4574
          {
5315
 
            LEX *lex=Lex;
5316
 
            lex->sql_command=SQLCOM_CHANGE_DB;
5317
 
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
5318
 
            if (lex->statement == NULL)
5319
 
              DRIZZLE_YYABORT;
5320
 
            lex->select_lex.db= $2.str;
 
4575
            Lex->statement= new statement::ChangeSchema(YYSession);
 
4576
            Lex->select_lex.db= $2.str;
5321
4577
          }
5322
4578
        ;
5323
4579
 
5326
4582
load:
5327
4583
          LOAD data_file
5328
4584
          {
5329
 
            Session *session= YYSession;
5330
 
            LEX *lex= session->lex;
5331
 
 
5332
 
            lex->sql_command= SQLCOM_LOAD;
5333
 
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
5334
 
            lex->statement= statement;
5335
 
            if (lex->statement == NULL)
5336
 
              DRIZZLE_YYABORT;
5337
 
 
5338
 
            Lex_input_stream *lip= session->m_lip;
 
4585
            statement::Load *statement= new statement::Load(YYSession);
 
4586
            Lex->statement= statement;
 
4587
 
 
4588
            Lex_input_stream *lip= YYSession->m_lip;
5339
4589
            statement->fname_start= lip->get_ptr();
5340
4590
          }
5341
4591
          load_data_lock INFILE TEXT_STRING_filesystem
5342
4592
          {
5343
 
            LEX *lex=Lex;
5344
 
            lex->lock_option= $4;
5345
 
            lex->duplicates= DUP_ERROR;
5346
 
            lex->ignore= 0;
5347
 
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
 
4593
            Lex->lock_option= $4;
 
4594
            Lex->duplicates= DUP_ERROR;
 
4595
            Lex->ignore= 0;
 
4596
            if (not (Lex->exchange= new file_exchange($6.str, 0, $2)))
5348
4597
              DRIZZLE_YYABORT;
5349
4598
          }
5350
4599
          opt_duplicate INTO
5351
4600
          {
5352
 
            Session *session= YYSession;
5353
 
            Lex_input_stream *lip= session->m_lip;
 
4601
            Lex_input_stream *lip= YYSession->m_lip;
5354
4602
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
5355
4603
          }
5356
4604
          TABLE_SYM table_ident
5357
4605
          {
5358
 
            LEX *lex=Lex;
5359
4606
            if (!Lex->current_select->add_table_to_list(YYSession,
5360
4607
                    $12, NULL, TL_OPTION_UPDATING,
5361
 
                    lex->lock_option))
 
4608
                    Lex->lock_option))
5362
4609
              DRIZZLE_YYABORT;
5363
 
            lex->field_list.empty();
5364
 
            lex->update_list.empty();
5365
 
            lex->value_list.empty();
 
4610
            Lex->field_list.empty();
 
4611
            Lex->update_list.empty();
 
4612
            Lex->value_list.empty();
5366
4613
          }
5367
4614
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5368
4615
          opt_load_data_set_spec
5386
4633
        | IGNORE_SYM { Lex->ignore= 1; }
5387
4634
        ;
5388
4635
 
 
4636
opt_duplicate_as:
 
4637
          /* empty */ { Lex->duplicates=DUP_ERROR; }
 
4638
        | AS { Lex->duplicates=DUP_ERROR; }
 
4639
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
 
4640
        | IGNORE_SYM { Lex->ignore= true; }
 
4641
        | REPLACE AS { Lex->duplicates=DUP_REPLACE; }
 
4642
        | IGNORE_SYM AS { Lex->ignore= true; }
 
4643
        ;
 
4644
 
5389
4645
opt_field_term:
5390
4646
          /* empty */
5391
4647
        | COLUMNS field_term_list
5404
4660
          }
5405
4661
        | OPTIONALLY ENCLOSED BY text_string
5406
4662
          {
5407
 
            LEX *lex= Lex;
5408
 
            assert(lex->exchange != 0);
5409
 
            lex->exchange->enclosed= $4;
5410
 
            lex->exchange->opt_enclosed= 1;
 
4663
            assert(Lex->exchange != 0);
 
4664
            Lex->exchange->enclosed= $4;
 
4665
            Lex->exchange->opt_enclosed= 1;
5411
4666
          }
5412
4667
        | ENCLOSED BY text_string
5413
4668
          {
5472
4727
        ;
5473
4728
 
5474
4729
field_or_var:
5475
 
          simple_ident_nospvar {$$= $1;}
5476
 
        | '@' ident_or_text
 
4730
          simple_ident {$$= $1;}
 
4731
        | '@' user_variable_ident
5477
4732
          { $$= new Item_user_var_as_out_param($2); }
5478
4733
        ;
5479
4734
 
5480
4735
opt_load_data_set_spec:
5481
4736
          /* empty */ {}
5482
 
        | SET insert_update_list {}
 
4737
        | SET_SYM insert_update_list {}
5483
4738
        ;
5484
4739
 
5485
4740
/* Common definitions */
5487
4742
text_literal:
5488
4743
        TEXT_STRING_literal
5489
4744
        {
5490
 
          Session *session= YYSession;
5491
 
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
 
4745
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
5492
4746
        }
5493
4747
        | text_literal TEXT_STRING_literal
5494
4748
          {
5544
4798
            $$ = new Item_null();
5545
4799
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5546
4800
          }
5547
 
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5548
 
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
 
4801
        | FALSE_SYM { $$= new drizzled::item::False(); }
 
4802
        | TRUE_SYM { $$= new drizzled::item::True(); }
5549
4803
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
5550
4804
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
5551
4805
        | DATE_SYM text_literal { $$ = $2; }
5588
4842
**********************************************************************/
5589
4843
 
5590
4844
insert_ident:
5591
 
          simple_ident_nospvar { $$=$1; }
 
4845
          simple_ident { $$=$1; }
5592
4846
        | table_wild { $$=$1; }
5593
4847
        ;
5594
4848
 
5595
4849
table_wild:
5596
4850
          ident '.' '*'
5597
4851
          {
5598
 
            Select_Lex *sel= Lex->current_select;
5599
 
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
5600
 
            sel->with_wild++;
 
4852
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
5601
4853
          }
5602
4854
        | ident '.' ident '.' '*'
5603
4855
          {
5604
 
            Select_Lex *sel= Lex->current_select;
5605
 
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
5606
 
            sel->with_wild++;
 
4856
            $$= parser::buildTableWild(Lex, $1, $3);
5607
4857
          }
5608
4858
        ;
5609
4859
 
5614
4864
simple_ident:
5615
4865
          ident
5616
4866
          {
5617
 
            {
5618
 
              Select_Lex *sel=Lex->current_select;
5619
 
              $$= (sel->parsing_place != IN_HAVING ||
5620
 
                  sel->get_in_sum_expr() > 0) ?
5621
 
                  (Item*) new Item_field(Lex->current_context(),
5622
 
                                         (const char *)NULL, NULL, $1.str) :
5623
 
                  (Item*) new Item_ref(Lex->current_context(),
5624
 
                                       (const char *)NULL, NULL, $1.str);
5625
 
            }
5626
 
          }
5627
 
        | simple_ident_q { $$= $1; }
5628
 
        ;
5629
 
 
5630
 
simple_ident_nospvar:
5631
 
          ident
5632
 
          {
5633
 
            Select_Lex *sel=Lex->current_select;
5634
 
            $$= (sel->parsing_place != IN_HAVING ||
5635
 
                sel->get_in_sum_expr() > 0) ?
5636
 
                (Item*) new Item_field(Lex->current_context(),
5637
 
                                       (const char *)NULL, NULL, $1.str) :
5638
 
                (Item*) new Item_ref(Lex->current_context(),
5639
 
                                     (const char *)NULL, NULL, $1.str);
 
4867
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
5640
4868
          }
5641
4869
        | simple_ident_q { $$= $1; }
5642
4870
        ;
5644
4872
simple_ident_q:
5645
4873
          ident '.' ident
5646
4874
          {
5647
 
            Session *session= YYSession;
5648
 
            LEX *lex= session->lex;
5649
 
 
5650
 
            {
5651
 
              Select_Lex *sel= lex->current_select;
5652
 
              if (sel->no_table_names_allowed)
5653
 
              {
5654
 
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5655
 
                         MYF(0), $1.str, session->where);
5656
 
              }
5657
 
              $$= (sel->parsing_place != IN_HAVING ||
5658
 
                  sel->get_in_sum_expr() > 0) ?
5659
 
                  (Item*) new Item_field(Lex->current_context(),
5660
 
                                         (const char *)NULL, $1.str, $3.str) :
5661
 
                  (Item*) new Item_ref(Lex->current_context(),
5662
 
                                       (const char *)NULL, $1.str, $3.str);
5663
 
            }
 
4875
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
5664
4876
          }
5665
4877
        | '.' ident '.' ident
5666
4878
          {
5667
 
            Session *session= YYSession;
5668
 
            LEX *lex= session->lex;
5669
 
            Select_Lex *sel= lex->current_select;
5670
 
            if (sel->no_table_names_allowed)
5671
 
            {
5672
 
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5673
 
                       MYF(0), $2.str, session->where);
5674
 
            }
5675
 
            $$= (sel->parsing_place != IN_HAVING ||
5676
 
                sel->get_in_sum_expr() > 0) ?
5677
 
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
5678
 
                (Item*) new Item_ref(Lex->current_context(),
5679
 
                                     (const char *)NULL, $2.str, $4.str);
 
4879
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
5680
4880
          }
5681
4881
        | ident '.' ident '.' ident
5682
4882
          {
5683
 
            Session *session= YYSession;
5684
 
            LEX *lex= session->lex;
5685
 
            Select_Lex *sel= lex->current_select;
5686
 
            if (sel->no_table_names_allowed)
5687
 
            {
5688
 
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5689
 
                       MYF(0), $3.str, session->where);
5690
 
            }
5691
 
            $$= (sel->parsing_place != IN_HAVING ||
5692
 
                sel->get_in_sum_expr() > 0) ?
5693
 
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
5694
 
                                       $5.str) :
5695
 
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
5696
 
                                     $5.str);
 
4883
            $$= parser::buildIdent(Lex, $1, $3, $5);
5697
4884
          }
5698
4885
        ;
5699
4886
 
5700
4887
field_ident:
5701
 
          ident { $$=$1;}
 
4888
          ident 
 
4889
          {
 
4890
            $$=$1;
 
4891
          }
5702
4892
        | ident '.' ident '.' ident
5703
4893
          {
5704
 
            TableList *table=
5705
 
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5706
 
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5707
 
            {
5708
 
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5709
 
              DRIZZLE_YYABORT;
5710
 
            }
5711
 
            if (my_strcasecmp(table_alias_charset, $3.str,
5712
 
                              table->table_name))
5713
 
            {
5714
 
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
5715
 
              DRIZZLE_YYABORT;
5716
 
            }
 
4894
            if (not parser::checkFieldIdent(Lex, $1, $3))
 
4895
              DRIZZLE_YYABORT;
 
4896
 
5717
4897
            $$=$5;
5718
4898
          }
5719
4899
        | ident '.' ident
5720
4900
          {
5721
 
            TableList *table=
5722
 
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5723
 
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5724
 
            {
5725
 
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
 
4901
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
5726
4902
              DRIZZLE_YYABORT;
5727
 
            }
 
4903
 
5728
4904
            $$=$3;
5729
4905
          }
5730
 
        | '.' ident { $$=$2;} /* For Delphi */
 
4906
        | '.' ident 
 
4907
          { /* For Delphi */
 
4908
            $$=$2;
 
4909
          }
5731
4910
        ;
5732
4911
 
5733
4912
table_ident:
5734
 
          ident { $$=new Table_ident($1); }
5735
 
        | ident '.' ident { $$=new Table_ident($1,$3);}
5736
 
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
 
4913
          ident
 
4914
          {
 
4915
            $$= new Table_ident($1);
 
4916
          }
 
4917
        | schema_name '.' ident
 
4918
          {
 
4919
            $$=new Table_ident($1,$3);
 
4920
          }
 
4921
        | '.' ident
 
4922
        { /* For Delphi */
 
4923
          $$= new Table_ident($2);
 
4924
        }
 
4925
        ;
 
4926
 
 
4927
schema_name:
 
4928
          ident
 
4929
        ;
 
4930
 
 
4931
catalog_name:
 
4932
          ident
5737
4933
        ;
5738
4934
 
5739
4935
IDENT_sys:
5740
 
          IDENT { $$= $1; }
 
4936
          IDENT 
 
4937
          {
 
4938
            $$= $1;
 
4939
          }
5741
4940
        | IDENT_QUOTED
5742
4941
          {
5743
4942
            const CHARSET_INFO * const cs= system_charset_info;
5780
4979
          IDENT_sys    { $$=$1; }
5781
4980
        | keyword
5782
4981
          {
5783
 
            Session *session= YYSession;
5784
 
            $$.str= session->strmake($1.str, $1.length);
 
4982
            $$.str= YYSession->strmake($1.str, $1.length);
5785
4983
            $$.length= $1.length;
5786
4984
          }
5787
4985
        ;
5788
4986
 
5789
4987
ident_or_text:
5790
 
          ident           { $$=$1;}
5791
 
        | TEXT_STRING_sys { $$=$1;}
5792
 
        | LEX_HOSTNAME { $$=$1;}
 
4988
          IDENT_sys           { $$=$1;}
 
4989
        | TEXT_STRING_sys { $$=$1;}
 
4990
        ;
 
4991
 
 
4992
engine_option_value:
 
4993
          IDENT_sys           { $$=$1;}
 
4994
        | TEXT_STRING_sys { $$=$1;}
 
4995
        ;
 
4996
 
 
4997
keyword_exception_for_variable:
 
4998
          TIMESTAMP_SYM         {}
 
4999
        | SQL_BUFFER_RESULT     {}
 
5000
        | IDENTITY_SYM          {}
5793
5001
        ;
5794
5002
 
5795
5003
/* Keyword that we allow for identifiers (except SP labels) */
5796
5004
keyword:
5797
5005
          keyword_sp            {}
5798
5006
        | BEGIN_SYM             {}
5799
 
        | BYTE_SYM              {}
5800
5007
        | CHECKSUM_SYM          {}
5801
5008
        | CLOSE_SYM             {}
5802
5009
        | COMMENT_SYM           {}
5803
5010
        | COMMIT_SYM            {}
5804
5011
        | CONTAINS_SYM          {}
5805
5012
        | DEALLOCATE_SYM        {}
 
5013
        | DO_SYM                {}
5806
5014
        | END                   {}
5807
5015
        | FLUSH_SYM             {}
5808
5016
        | NO_SYM                {}
5811
5019
        | SAVEPOINT_SYM         {}
5812
5020
        | SECURITY_SYM          {}
5813
5021
        | SERVER_SYM            {}
 
5022
        | SIGNED_SYM            {}
5814
5023
        | START_SYM             {}
5815
5024
        | STOP_SYM              {}
5816
5025
        | TRUNCATE_SYM          {}
5830
5039
        | ANY_SYM                  {}
5831
5040
        | AT_SYM                   {}
5832
5041
        | AUTO_INC                 {}
5833
 
        | AVG_ROW_LENGTH           {}
5834
5042
        | AVG_SYM                  {}
5835
5043
        | BIT_SYM                  {}
5836
 
        | BLOCK_SIZE_SYM           {}
5837
 
        | BLOCK_SYM                {}
5838
5044
        | BOOL_SYM                 {}
5839
5045
        | BOOLEAN_SYM              {}
5840
5046
        | BTREE_SYM                {}
5842
5048
        | CHAIN_SYM                {}
5843
5049
        | COALESCE                 {}
5844
5050
        | COLLATION_SYM            {}
5845
 
        | COLUMN_FORMAT_SYM        {}
5846
5051
        | COLUMNS                  {}
5847
5052
        | COMMITTED_SYM            {}
5848
5053
        | COMPACT_SYM              {}
5849
5054
        | COMPRESSED_SYM           {}
5850
5055
        | CONCURRENT               {}
5851
 
        | CONNECTION_SYM           {}
 
5056
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
5852
5057
        | CONSISTENT_SYM           {}
5853
5058
        | CUBE_SYM                 {}
5854
5059
        | DATA_SYM                 {}
5855
5060
        | DATABASES                {}
5856
 
        | DATAFILE_SYM             {}
5857
5061
        | DATETIME_SYM             {}
5858
 
        | DATE_SYM                 {}
 
5062
        | DATE_SYM                 {} /* Create conflict */
5859
5063
        | DAY_SYM                  {}
5860
5064
        | DISABLE_SYM              {}
5861
5065
        | DISCARD                  {}
5886
5090
        | KEY_BLOCK_SIZE           {}
5887
5091
        | LAST_SYM                 {}
5888
5092
        | LEVEL_SYM                {}
5889
 
        | LIST_SYM                 {}
5890
5093
        | LOCAL_SYM                {}
5891
5094
        | LOCKS_SYM                {}
5892
5095
        | LOGS_SYM                 {}
5893
 
        | MAX_ROWS                 {}
5894
 
        | MAX_SIZE_SYM             {}
5895
5096
        | MAX_VALUE_SYM            {}
5896
5097
        | MEDIUM_SYM               {}
5897
5098
        | MERGE_SYM                {}
5898
5099
        | MICROSECOND_SYM          {}
5899
5100
        | MINUTE_SYM               {}
5900
 
        | MIN_ROWS                 {}
5901
5101
        | MODIFY_SYM               {}
5902
5102
        | MODE_SYM                 {}
5903
5103
        | MONTH_SYM                {}
5912
5112
        | ONE_SHOT_SYM             {}
5913
5113
        | ONE_SYM                  {}
5914
5114
        | ONLINE_SYM               {}
5915
 
        | PAGE_SYM                 {}
5916
5115
        | PARTIAL                  {}
5917
 
        | PHASE_SYM                {}
5918
5116
        | PREV_SYM                 {}
5919
5117
        | PROCESS                  {}
5920
5118
        | PROCESSLIST_SYM          {}
5921
5119
        | QUARTER_SYM              {}
5922
 
        | QUERY_SYM                {}
5923
 
        | READ_ONLY_SYM            {}
 
5120
        | QUERY_SYM                {} // Causes conflict
5924
5121
        | REDUNDANT_SYM            {}
5925
5122
        | REPEATABLE_SYM           {}
5926
5123
        | RETURNS_SYM              {}
5927
 
        | REVERSE_SYM              {}
5928
5124
        | ROLLUP_SYM               {}
5929
5125
        | ROUTINE_SYM              {}
5930
5126
        | ROWS_SYM                 {}
5936
5132
        | SESSION_SYM              {}
5937
5133
        | SIMPLE_SYM               {}
5938
5134
        | SHARE_SYM                {}
5939
 
        | SHUTDOWN                 {}
5940
5135
        | SNAPSHOT_SYM             {}
5941
 
        | SQL_BUFFER_RESULT        {}
5942
5136
        | STATUS_SYM               {}
5943
 
        | STORAGE_SYM              {}
5944
5137
        | STRING_SYM               {}
5945
5138
        | SUBDATE_SYM              {}
5946
5139
        | SUBJECT_SYM              {}
5947
5140
        | SUSPEND_SYM              {}
5948
 
        | SWAPS_SYM                {}
5949
 
        | SWITCHES_SYM             {}
5950
5141
        | TABLES                   {}
5951
5142
        | TABLESPACE               {}
5952
5143
        | TEMPORARY_SYM            {}
5953
5144
        | TEXT_SYM                 {}
5954
5145
        | TRANSACTION_SYM          {}
5955
 
        | TIMESTAMP_SYM            {}
 
5146
        | TIME_SYM                 {}
5956
5147
        | TIMESTAMP_ADD            {}
5957
5148
        | TIMESTAMP_DIFF           {}
5958
 
        | TYPES_SYM                {}
5959
5149
        | TYPE_SYM                 {}
5960
5150
        | UNCOMMITTED_SYM          {}
5961
5151
        | UNDOFILE_SYM             {}
5962
5152
        | UNKNOWN_SYM              {}
 
5153
        | UUID_SYM                 {}
5963
5154
        | USER                     {}
5964
5155
        | VARIABLES                {}
5965
5156
        | VALUE_SYM                {}
5972
5163
/* Option functions */
5973
5164
 
5974
5165
set:
5975
 
          SET opt_option
 
5166
          SET_SYM opt_option
5976
5167
          {
5977
 
            LEX *lex=Lex;
5978
 
            lex->sql_command= SQLCOM_SET_OPTION;
5979
 
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
5980
 
            lex->statement= statement;
5981
 
            if (lex->statement == NULL)
5982
 
              DRIZZLE_YYABORT;
5983
 
            mysql_init_select(lex);
5984
 
            lex->option_type=OPT_SESSION;
5985
 
            lex->var_list.empty();
 
5168
            Lex->statement= new statement::SetOption(YYSession);
5986
5169
          }
5987
5170
          option_value_list
5988
5171
          {}
5999
5182
        ;
6000
5183
 
6001
5184
option_type_value:
6002
 
          {
6003
 
          }
 
5185
          { }
6004
5186
          ext_option_value
6005
 
          {
6006
 
          }
 
5187
          { }
6007
5188
        ;
6008
5189
 
6009
5190
option_type:
6040
5221
sys_option_value:
6041
5222
          option_type internal_variable_name equal set_expr_or_default
6042
5223
          {
6043
 
            LEX *lex=Lex;
6044
 
 
6045
5224
            if ($2.var)
6046
5225
            { /* System variable */
6047
5226
              if ($1)
6048
 
                lex->option_type= $1;
6049
 
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
6050
 
                                      &$2.base_name, $4));
 
5227
              {
 
5228
                Lex->option_type= $1;
 
5229
              }
 
5230
              Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type, $2.var, &$2.base_name, $4)));
6051
5231
            }
6052
5232
          }
6053
5233
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
6054
5234
          {
6055
 
            LEX *lex=Lex;
6056
 
            lex->option_type= $1;
6057
 
            lex->var_list.push_back(new set_var(lex->option_type,
6058
 
                                                find_sys_var(YYSession, "tx_isolation"),
6059
 
                                                &null_lex_str,
6060
 
                                                new Item_int((int32_t) $5)));
 
5235
            Lex->option_type= $1;
 
5236
            Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type,
 
5237
                                              find_sys_var("tx_isolation"),
 
5238
                                              &null_lex_str,
 
5239
                                              new Item_int((int32_t)
 
5240
                                              $5))));
6061
5241
          }
6062
5242
        ;
6063
5243
 
6064
5244
option_value:
6065
 
          '@' ident_or_text equal expr
 
5245
          '@' user_variable_ident equal expr
6066
5246
          {
6067
 
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
 
5247
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
6068
5248
          }
6069
5249
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6070
5250
          {
6071
 
            LEX *lex=Lex;
6072
 
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6073
 
          }
 
5251
            Lex->var_list.push_back(SetVarPtr(new set_var($3, $4.var, &$4.base_name, $6)));
 
5252
          }
 
5253
        ;
 
5254
 
 
5255
user_variable_ident:
 
5256
          internal_variable_ident { $$=$1;}
 
5257
        | TEXT_STRING_sys { $$=$1;}
 
5258
        | LEX_HOSTNAME { $$=$1;}
 
5259
        ;
 
5260
 
 
5261
internal_variable_ident:
 
5262
          keyword_exception_for_variable
 
5263
          {
 
5264
            $$.str= YYSession->strmake($1.str, $1.length);
 
5265
            $$.length= $1.length;
 
5266
          }
 
5267
        | IDENT_sys    { $$=$1; }
6074
5268
        ;
6075
5269
 
6076
5270
internal_variable_name:
6077
 
          ident
 
5271
          internal_variable_ident
6078
5272
          {
6079
 
            Session *session= YYSession;
6080
 
 
6081
5273
            /* We have to lookup here since local vars can shadow sysvars */
6082
5274
            {
6083
5275
              /* Not an SP local variable */
6084
 
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
 
5276
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
6085
5277
              if (!tmp)
6086
5278
                DRIZZLE_YYABORT;
6087
5279
              $$.var= tmp;
6113
5305
unlock:
6114
5306
          UNLOCK_SYM
6115
5307
          {
6116
 
            LEX *lex= Lex;
6117
 
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
6118
 
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
6119
 
            if (lex->statement == NULL)
6120
 
              DRIZZLE_YYABORT;
 
5308
            Lex->statement= new statement::UnlockTables(YYSession);
6121
5309
          }
6122
5310
          table_or_tables
6123
5311
          {}
6126
5314
begin:
6127
5315
          BEGIN_SYM
6128
5316
          {
6129
 
            LEX *lex=Lex;
6130
 
            lex->sql_command = SQLCOM_BEGIN;
6131
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
6132
 
            if (lex->statement == NULL)
6133
 
              DRIZZLE_YYABORT;
 
5317
            Lex->statement= new statement::StartTransaction(YYSession);
6134
5318
          }
6135
5319
          opt_work {}
6136
5320
        ;
6162
5346
commit:
6163
5347
          COMMIT_SYM opt_work opt_chain opt_release
6164
5348
          {
6165
 
            LEX *lex=Lex;
6166
 
            lex->sql_command= SQLCOM_COMMIT;
6167
 
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
6168
 
            lex->statement= statement;
6169
 
            if (lex->statement == NULL)
6170
 
              DRIZZLE_YYABORT;
6171
 
            statement->tx_chain= $3;
6172
 
            statement->tx_release= $4;
 
5349
            Lex->statement= new statement::Commit(YYSession, $3, $4);
6173
5350
          }
6174
5351
        ;
6175
5352
 
6176
5353
rollback:
6177
5354
          ROLLBACK_SYM opt_work opt_chain opt_release
6178
5355
          {
6179
 
            LEX *lex=Lex;
6180
 
            lex->sql_command= SQLCOM_ROLLBACK;
6181
 
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
6182
 
            lex->statement= statement;
6183
 
            if (lex->statement == NULL)
6184
 
              DRIZZLE_YYABORT;
6185
 
            statement->tx_chain= $3;
6186
 
            statement->tx_release= $4;
 
5356
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
6187
5357
          }
6188
 
        | ROLLBACK_SYM opt_work
6189
 
          TO_SYM opt_savepoint ident
 
5358
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
6190
5359
          {
6191
 
            LEX *lex=Lex;
6192
 
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
6193
 
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
6194
 
            if (lex->statement == NULL)
6195
 
              DRIZZLE_YYABORT;
6196
 
            lex->ident= $5;
 
5360
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
6197
5361
          }
6198
5362
        ;
6199
5363
 
6200
5364
savepoint:
6201
 
          SAVEPOINT_SYM ident
 
5365
          SAVEPOINT_SYM savepoint_ident
6202
5366
          {
6203
 
            LEX *lex=Lex;
6204
 
            lex->sql_command= SQLCOM_SAVEPOINT;
6205
 
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
6206
 
            if (lex->statement == NULL)
6207
 
              DRIZZLE_YYABORT;
6208
 
            lex->ident= $2;
 
5367
            Lex->statement= new statement::Savepoint(YYSession, $2);
6209
5368
          }
6210
5369
        ;
6211
5370
 
6212
5371
release:
6213
 
          RELEASE_SYM SAVEPOINT_SYM ident
 
5372
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
6214
5373
          {
6215
 
            LEX *lex=Lex;
6216
 
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
6217
 
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
6218
 
            if (lex->statement == NULL)
6219
 
              DRIZZLE_YYABORT;
6220
 
            lex->ident= $3;
 
5374
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
6221
5375
          }
6222
5376
        ;
6223
5377
 
 
5378
savepoint_ident:
 
5379
               IDENT_sys
 
5380
               ;
 
5381
 
6224
5382
/*
6225
5383
   UNIONS : glue selects together
6226
5384
*/
6234
5392
union_list:
6235
5393
          UNION_SYM union_option
6236
5394
          {
6237
 
            if (add_select_to_union_list(Lex, (bool)$2))
 
5395
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
6238
5396
              DRIZZLE_YYABORT;
6239
5397
          }
6240
5398
          select_init
6255
5413
 
6256
5414
union_order_or_limit:
6257
5415
          {
6258
 
            Session *session= YYSession;
6259
 
            LEX *lex= session->lex;
6260
 
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6261
 
            Select_Lex *sel= lex->current_select;
 
5416
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
5417
            Select_Lex *sel= Lex->current_select;
6262
5418
            Select_Lex_Unit *unit= sel->master_unit();
6263
5419
            Select_Lex *fake= unit->fake_select_lex;
6264
5420
            if (fake)
6265
5421
            {
6266
5422
              unit->global_parameters= fake;
6267
5423
              fake->no_table_names_allowed= 1;
6268
 
              lex->current_select= fake;
 
5424
              Lex->current_select= fake;
6269
5425
            }
6270
 
            session->where= "global ORDER clause";
 
5426
            YYSession->setWhere("global ORDER clause");
6271
5427
          }
6272
5428
          order_or_limit
6273
5429
          {
6274
 
            Session *session= YYSession;
6275
 
            session->lex->current_select->no_table_names_allowed= 0;
6276
 
            session->where= "";
 
5430
            YYSession->lex->current_select->no_table_names_allowed= 0;
 
5431
            YYSession->setWhere("");
6277
5432
          }
6278
5433
        ;
6279
5434
 
6304
5459
        | query_expression_body
6305
5460
          UNION_SYM union_option
6306
5461
          {
6307
 
            if (add_select_to_union_list(Lex, (bool)$3))
 
5462
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
6308
5463
              DRIZZLE_YYABORT;
6309
5464
          }
6310
5465
          query_specification
6324
5479
 
6325
5480
subselect_start:
6326
5481
          {
6327
 
            LEX *lex=Lex;
6328
 
            if (!lex->expr_allows_subselect)
 
5482
            if (not Lex->expr_allows_subselect)
6329
5483
            {
6330
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
5484
              parser::my_parse_error(YYSession->m_lip);
6331
5485
              DRIZZLE_YYABORT;
6332
5486
            }
6333
5487
            /*
6337
5491
              (SELECT .. ) UNION ...  becomes
6338
5492
              SELECT * FROM ((SELECT ...) UNION ...)
6339
5493
            */
6340
 
            if (mysql_new_select(Lex, 1))
 
5494
            if (new_select(Lex, 1))
6341
5495
              DRIZZLE_YYABORT;
6342
5496
          }
6343
5497
        ;
6344
5498
 
6345
5499
subselect_end:
6346
5500
          {
6347
 
            LEX *lex=Lex;
6348
 
            lex->pop_context();
6349
 
            Select_Lex *child= lex->current_select;
6350
 
            lex->current_select = lex->current_select->return_after_parsing();
6351
 
            lex->nest_level--;
6352
 
            lex->current_select->n_child_sum_items += child->n_sum_items;
 
5501
            Lex->pop_context();
 
5502
            Select_Lex *child= Lex->current_select;
 
5503
            Lex->current_select= Lex->current_select->return_after_parsing();
 
5504
            Lex->nest_level--;
 
5505
            Lex->current_select->n_child_sum_items += child->n_sum_items;
6353
5506
            /*
6354
5507
              A subselect can add fields to an outer select. Reserve space for
6355
5508
              them.
6356
5509
            */
6357
 
            lex->current_select->select_n_where_fields+=
 
5510
            Lex->current_select->select_n_where_fields+=
6358
5511
            child->select_n_where_fields;
6359
5512
          }
6360
5513
        ;