~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#define yyoverflow(A,B,C,D,E,F)               \
47
47
  {                                           \
48
 
    ulong val= *(F);                          \
 
48
    unsigned long val= *(F);                          \
49
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
50
50
    {                                         \
51
51
      yyerror((char*) (A));                   \
60
60
#define DRIZZLE_YYABORT                         \
61
61
  do                                          \
62
62
  {                                           \
63
 
    LEX::cleanup_lex_after_parse_error(YYSession);\
64
63
    YYABORT;                                  \
65
64
  } while (0)
66
65
 
67
66
#define DRIZZLE_YYABORT_UNLESS(A)         \
68
67
  if (!(A))                             \
69
68
  {                                     \
70
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
71
 
    my_parse_error(&pass);\
 
69
    parser::my_parse_error(YYSession->m_lip);\
72
70
    DRIZZLE_YYABORT;                      \
73
71
  }
74
72
 
82
80
class Item;
83
81
class Item_num;
84
82
 
85
 
 
86
 
static bool check_reserved_words(LEX_STRING *name)
87
 
{
88
 
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
89
 
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
90
 
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
91
 
    return true;
92
 
  return false;
93
 
}
94
 
 
95
 
/**
96
 
  @brief Push an error message into MySQL error stack with line
97
 
  and position information.
98
 
 
99
 
  This function provides semantic action implementers with a way
100
 
  to push the famous "You have a syntax error near..." error
101
 
  message into the error stack, which is normally produced only if
102
 
  a parse error is discovered internally by the Bison generated
103
 
  parser.
104
 
*/
105
 
 
106
 
struct my_parse_error_st {
107
 
  const char *s;
108
 
  Session *session;
109
 
};
110
 
 
111
 
static void my_parse_error(void *arg)
112
 
{
113
 
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
114
 
 
115
 
  const char *s= ptr->s;
116
 
  Session *session= ptr->session;
117
 
 
118
 
  Lex_input_stream *lip= session->m_lip;
119
 
 
120
 
  const char *yytext= lip->get_tok_start();
121
 
  /* Push an error into the error stack */
122
 
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
123
 
                  (yytext ? yytext : ""),
124
 
                  lip->yylineno);
125
 
}
 
83
namespace item
 
84
{
 
85
class Boolean;
 
86
class True;
 
87
class False;
 
88
}
 
89
 
126
90
 
127
91
/**
128
92
  @brief Bison callback to report a syntax/OOM error
139
103
 
140
104
  This function is not for use in semantic actions and is internal to
141
105
  the parser, as it performs some pre-return cleanup.
142
 
  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
143
107
  push an error into the error stack and DRIZZLE_YYABORT
144
108
  to abort from the parser.
145
109
*/
146
110
 
147
111
static void DRIZZLEerror(const char *s)
148
112
{
149
 
  Session *session= current_session;
150
 
 
151
 
  /*
152
 
    Restore the original LEX if it was replaced when parsing
153
 
    a stored procedure. We must ensure that a parsing error
154
 
    does not leave any side effects in the Session.
155
 
  */
156
 
  LEX::cleanup_lex_after_parse_error(session);
157
 
 
158
 
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
159
 
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
160
 
    s= ER(ER_SYNTAX_ERROR);
161
 
 
162
 
  struct my_parse_error_st pass= { s, session };
163
 
  my_parse_error(&pass);
164
 
}
165
 
 
166
 
/**
167
 
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
168
 
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
169
 
  This function returns the proper item for the SQL expression
170
 
  <code>left [NOT] IN ( expr )</code>
171
 
  @param session the current thread
172
 
  @param left the in predicand
173
 
  @param equal true for IN predicates, false for NOT IN predicates
174
 
  @param expr first and only expression of the in value list
175
 
  @return an expression representing the IN predicate.
176
 
*/
177
 
static Item* handle_sql2003_note184_exception(Session *session,
178
 
                                              Item* left, bool equal,
179
 
                                              Item *expr)
180
 
{
181
 
  /*
182
 
    Relevant references for this issue:
183
 
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
184
 
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
185
 
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
186
 
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
187
 
    - SQL:2003 Feature F561, "Full value expressions".
188
 
 
189
 
    The exception in SQL:2003 Note 184 means:
190
 
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
191
 
    should be re-interpreted as an Item_in_subselect, which corresponds
192
 
    to a <table subquery> when used inside an <in predicate>.
193
 
 
194
 
    Our reading of Note 184 is reccursive, so that all:
195
 
    - IN (( <subquery> ))
196
 
    - IN ((( <subquery> )))
197
 
    - IN '('^N <subquery> ')'^N
198
 
    - etc
199
 
    should be interpreted as a <table subquery>, no matter how deep in the
200
 
    expression the <subquery> is.
201
 
  */
202
 
 
203
 
  Item *result;
204
 
 
205
 
  if (expr->type() == Item::SUBSELECT_ITEM)
206
 
  {
207
 
    Item_subselect *expr2 = (Item_subselect*) expr;
208
 
 
209
 
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
210
 
    {
211
 
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
212
 
      Select_Lex *subselect;
213
 
 
214
 
      /*
215
 
        Implement the mandated change, by altering the semantic tree:
216
 
          left IN Item_singlerow_subselect(subselect)
217
 
        is modified to
218
 
          left IN (subselect)
219
 
        which is represented as
220
 
          Item_in_subselect(left, subselect)
221
 
      */
222
 
      subselect= expr3->invalidate_and_restore_select_lex();
223
 
      result= new (session->mem_root) Item_in_subselect(left, subselect);
224
 
 
225
 
      if (! equal)
226
 
        result = negate_expression(session, result);
227
 
 
228
 
      return(result);
229
 
    }
230
 
  }
231
 
 
232
 
  if (equal)
233
 
    result= new (session->mem_root) Item_func_eq(left, expr);
234
 
  else
235
 
    result= new (session->mem_root) Item_func_ne(left, expr);
236
 
 
237
 
  return(result);
238
 
}
239
 
 
240
 
/**
241
 
   @brief Creates a new Select_Lex for a UNION branch.
242
 
 
243
 
   Sets up and initializes a Select_Lex structure for a query once the parser
244
 
   discovers a UNION token. The current Select_Lex is pushed on the stack and
245
 
   the new Select_Lex becomes the current one..=
246
 
 
247
 
   @lex The parser state.
248
 
 
249
 
   @is_union_distinct True if the union preceding the new select statement
250
 
   uses UNION DISTINCT.
251
 
 
252
 
   @return <code>false</code> if successful, <code>true</code> if an error was
253
 
   reported. In the latter case parsing should stop.
254
 
 */
255
 
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
256
 
{
257
 
  if (lex->result)
258
 
  {
259
 
    /* Only the last SELECT can have  INTO...... */
260
 
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
261
 
    return true;
262
 
  }
263
 
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
264
 
  {
265
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
266
 
    my_parse_error(&pass);
267
 
    return true;
268
 
  }
269
 
  /* This counter shouldn't be incremented for UNION parts */
270
 
  lex->nest_level--;
271
 
  if (mysql_new_select(lex, 0))
272
 
    return true;
273
 
  mysql_init_select(lex);
274
 
  lex->current_select->linkage=UNION_TYPE;
275
 
  if (is_union_distinct) /* UNION DISTINCT - remember position */
276
 
    lex->current_select->master_unit()->union_distinct=
277
 
      lex->current_select;
278
 
  return false;
279
 
}
280
 
 
281
 
/**
282
 
   @brief Initializes a Select_Lex for a query within parentheses (aka
283
 
   braces).
284
 
 
285
 
   @return false if successful, true if an error was reported. In the latter
286
 
   case parsing should stop.
287
 
 */
288
 
static bool setup_select_in_parentheses(Session *session, LEX *lex)
289
 
{
290
 
  Select_Lex * sel= lex->current_select;
291
 
  if (sel->set_braces(1))
292
 
  {
293
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
294
 
    my_parse_error(&pass);
295
 
    return true;
296
 
  }
297
 
  if (sel->linkage == UNION_TYPE &&
298
 
      !sel->master_unit()->first_select()->braces &&
299
 
      sel->master_unit()->first_select()->linkage ==
300
 
      UNION_TYPE)
301
 
  {
302
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
303
 
    my_parse_error(&pass);
304
 
    return true;
305
 
  }
306
 
  if (sel->linkage == UNION_TYPE &&
307
 
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
308
 
      sel->master_unit()->fake_select_lex)
309
 
  {
310
 
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
311
 
    return true;
312
 
  }
313
 
  /* select in braces, can't contain global parameters */
314
 
  if (sel->master_unit()->fake_select_lex)
315
 
    sel->master_unit()->global_parameters=
316
 
      sel->master_unit()->fake_select_lex;
317
 
  return false;
318
 
}
319
 
 
320
 
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
321
 
{
322
 
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
323
 
  Item *item= NULL;
324
 
 
325
 
  if (udf)
326
 
  {
327
 
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
328
 
  } else {
329
 
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
330
 
  }
331
 
 
332
 
  return item;
 
113
  parser::errorOn(s);
333
114
}
334
115
 
335
116
} /* namespace drizzled; */
337
118
using namespace drizzled;
338
119
%}
339
120
%union {
 
121
  bool boolean;
340
122
  int  num;
341
 
  ulong ulong_num;
 
123
  unsigned long ulong_num;
342
124
  uint64_t ulonglong_number;
343
125
  int64_t longlong_number;
344
126
  drizzled::LEX_STRING lex_str;
354
136
  drizzled::Key_part_spec *key_part;
355
137
  const drizzled::plugin::Function *udf;
356
138
  drizzled::TableList *table_list;
357
 
  struct drizzled::sys_var_with_base variable;
358
 
  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;
359
142
  drizzled::Key::Keytype key_type;
360
 
  enum drizzled::ha_key_alg key_alg;
361
 
  enum drizzled::column_format_type column_format_type;
362
 
  enum drizzled::ha_rkey_function ha_rkey_mode;
363
 
  enum drizzled::enum_tx_isolation tx_isolation;
364
 
  enum drizzled::Cast_target cast_type;
 
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;
365
147
  const drizzled::CHARSET_INFO *charset;
366
148
  drizzled::thr_lock_type lock_type;
367
149
  drizzled::interval_type interval, interval_time_st;
368
 
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
 
150
  drizzled::type::timestamp_t date_time_type;
369
151
  drizzled::Select_Lex *select_lex;
370
152
  drizzled::chooser_compare_func_creator boolfunc2creator;
371
 
  struct drizzled::st_lex *lex;
372
 
  enum drizzled::index_hint_type index_hint;
373
 
  enum drizzled::enum_filetype filetype;
374
 
  enum drizzled::ha_build_method build_method;
 
153
  drizzled::st_lex *lex;
 
154
  drizzled::index_hint_type index_hint;
 
155
  drizzled::enum_filetype filetype;
 
156
  drizzled::ha_build_method build_method;
375
157
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
376
158
  drizzled::execute_string_t execute_string;
377
159
}
379
161
%{
380
162
namespace drizzled
381
163
{
382
 
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 
164
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
383
165
}
384
166
%}
385
167
 
 
168
%debug
386
169
%pure_parser                                    /* We have threads */
 
170
 
387
171
/*
388
 
  Currently there are 88 shift/reduce conflicts.
 
172
  Currently there are 70 shift/reduce conflicts.
389
173
  We should not introduce new conflicts any more.
390
174
*/
391
 
%expect 94
 
175
%expect 70
392
176
 
393
177
/*
394
178
   Comments for TOKENS.
409
193
 
410
194
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
411
195
%token  ACTION                        /* SQL-2003-N */
412
 
%token  ADD                           /* SQL-2003-R */
 
196
%token  ADD_SYM                           /* SQL-2003-R */
413
197
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
414
198
%token  AFTER_SYM                     /* SQL-2003-N */
415
199
%token  AGGREGATE_SYM
416
200
%token  ALL                           /* SQL-2003-R */
417
 
%token  ALTER                         /* SQL-2003-R */
 
201
%token  ALTER_SYM                         /* SQL-2003-R */
418
202
%token  ANALYZE_SYM
419
203
%token  AND_SYM                       /* SQL-2003-R */
420
204
%token  ANY_SYM                       /* SQL-2003-R */
423
207
%token  ASENSITIVE_SYM                /* FUTURE-USE */
424
208
%token  AT_SYM                        /* SQL-2003-R */
425
209
%token  AUTO_INC
426
 
%token  AVG_ROW_LENGTH
427
210
%token  AVG_SYM                       /* SQL-2003-N */
428
211
%token  BEFORE_SYM                    /* SQL-2003-N */
429
212
%token  BEGIN_SYM                     /* SQL-2003-R */
438
221
%token  BOTH                          /* SQL-2003-R */
439
222
%token  BTREE_SYM
440
223
%token  BY                            /* SQL-2003-R */
441
 
%token  BYTE_SYM
442
224
%token  CALL_SYM                      /* SQL-2003-R */
443
225
%token  CASCADE                       /* SQL-2003-N */
444
226
%token  CASCADED                      /* SQL-2003-R */
445
227
%token  CASE_SYM                      /* SQL-2003-R */
446
228
%token  CAST_SYM                      /* SQL-2003-R */
 
229
%token  CATALOG_SYM
447
230
%token  CHAIN_SYM                     /* SQL-2003-N */
448
 
%token  CHANGE
 
231
%token  CHANGE_SYM
449
232
%token  CHAR_SYM                      /* SQL-2003-R */
450
233
%token  CHECKSUM_SYM
451
234
%token  CHECK_SYM                     /* SQL-2003-R */
466
249
%token  CONSISTENT_SYM
467
250
%token  CONSTRAINT                    /* SQL-2003-R */
468
251
%token  CONTAINS_SYM                  /* SQL-2003-N */
469
 
%token  CONTINUE_SYM                  /* SQL-2003-R */
470
252
%token  CONVERT_SYM                   /* SQL-2003-N */
471
253
%token  COUNT_SYM                     /* SQL-2003-N */
472
254
%token  CREATE                        /* SQL-2003-R */
477
259
%token  CURSOR_SYM                    /* SQL-2003-R */
478
260
%token  DATABASE
479
261
%token  DATABASES
480
 
%token  DATAFILE_SYM
481
262
%token  DATA_SYM                      /* SQL-2003-N */
482
263
%token  DATETIME_SYM
483
264
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
501
282
%token  DISCARD
502
283
%token  DISTINCT                      /* SQL-2003-R */
503
284
%token  DIV_SYM
 
285
%token  DO_SYM
504
286
%token  DOUBLE_SYM                    /* SQL-2003-R */
505
287
%token  DROP                          /* SQL-2003-R */
506
288
%token  DUMPFILE
508
290
%token  DYNAMIC_SYM                   /* SQL-2003-R */
509
291
%token  EACH_SYM                      /* SQL-2003-R */
510
292
%token  ELSE                          /* SQL-2003-R */
511
 
%token  ELSEIF_SYM
512
293
%token  ENABLE_SYM
513
294
%token  ENCLOSED
514
295
%token  END                           /* SQL-2003-R */
522
303
%token  ESCAPED
523
304
%token  ESCAPE_SYM                    /* SQL-2003-R */
524
305
%token  EXCLUSIVE_SYM
525
 
%token  EXECUTE_SYM
 
306
%token  EXECUTE_SYM                   /* SQL-2003-R */
526
307
%token  EXISTS                        /* SQL-2003-R */
527
308
%token  EXTENDED_SYM
528
309
%token  EXTRACT_SYM                   /* SQL-2003-N */
529
310
%token  FALSE_SYM                     /* SQL-2003-R */
530
 
%token  FETCH_SYM                     /* SQL-2003-R */
531
 
%token  COLUMN_FORMAT_SYM
532
311
%token  FILE_SYM
533
312
%token  FIRST_SYM                     /* SQL-2003-N */
534
313
%token  FIXED_SYM
555
334
%token  HOUR_SYM                      /* SQL-2003-R */
556
335
%token  IDENT
557
336
%token  IDENTIFIED_SYM
 
337
%token  IDENTITY_SYM                  /* SQL-2003-R */
558
338
%token  IDENT_QUOTED
559
339
%token  IF
560
340
%token  IGNORE_SYM
587
367
%token  LIKE                          /* SQL-2003-R */
588
368
%token  LIMIT
589
369
%token  LINES
590
 
%token  LIST_SYM
591
370
%token  LOAD
592
371
%token  LOCAL_SYM                     /* SQL-2003-R */
593
 
%token  LOCATOR_SYM                   /* SQL-2003-N */
594
372
%token  LOCKS_SYM
595
373
%token  LOCK_SYM
596
374
%token  LOGS_SYM
597
375
%token  LONG_NUM
598
376
%token  LONG_SYM
599
 
%token  LOOP_SYM
600
377
%token  LT                            /* OPERATOR */
601
378
%token  MATCH                         /* SQL-2003-R */
602
 
%token  MAX_ROWS
603
 
%token  MAX_SIZE_SYM
604
379
%token  MAX_SYM                       /* SQL-2003-N */
605
380
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
606
381
%token  MEDIUM_SYM
609
384
%token  MINUTE_MICROSECOND_SYM
610
385
%token  MINUTE_SECOND_SYM
611
386
%token  MINUTE_SYM                    /* SQL-2003-R */
612
 
%token  MIN_ROWS
613
387
%token  MIN_SYM                       /* SQL-2003-N */
614
388
%token  MODE_SYM
615
389
%token  MODIFIES_SYM                  /* SQL-2003-R */
646
420
%token  OUTER
647
421
%token  OUTFILE
648
422
%token  OUT_SYM                       /* SQL-2003-R */
649
 
%token  PAGE_SYM
650
423
%token  PARTIAL                       /* SQL-2003-N */
651
 
%token  PHASE_SYM
652
424
%token  POSITION_SYM                  /* SQL-2003-N */
653
425
%token  PRECISION                     /* SQL-2003-R */
654
426
%token  PREV_SYM
659
431
%token  QUERY_SYM
660
432
%token  RANGE_SYM                     /* SQL-2003-R */
661
433
%token  READS_SYM                     /* SQL-2003-R */
662
 
%token  READ_ONLY_SYM
663
434
%token  READ_SYM                      /* SQL-2003-N */
664
435
%token  READ_WRITE_SYM
665
436
%token  REAL                          /* SQL-2003-R */
666
437
%token  REDUNDANT_SYM
 
438
%token  REGEXP_SYM
667
439
%token  REFERENCES                    /* SQL-2003-R */
668
440
%token  RELEASE_SYM                   /* SQL-2003-R */
669
441
%token  RENAME
673
445
%token  RESTRICT
674
446
%token  RETURNS_SYM                   /* SQL-2003-R */
675
447
%token  RETURN_SYM                    /* SQL-2003-R */
676
 
%token  REVERSE_SYM
677
448
%token  REVOKE                        /* SQL-2003-R */
678
449
%token  RIGHT                         /* SQL-2003-R */
679
450
%token  ROLLBACK_SYM                  /* SQL-2003-R */
693
464
%token  SERIAL_SYM
694
465
%token  SESSION_SYM                   /* SQL-2003-N */
695
466
%token  SERVER_SYM
696
 
%token  SERVER_OPTIONS
697
 
%token  SET                           /* SQL-2003-R */
 
467
%token  SET_SYM                           /* SQL-2003-R */
698
468
%token  SET_VAR
699
469
%token  SHARE_SYM
700
470
%token  SHOW
 
471
%token  SIGNED_SYM
701
472
%token  SIMPLE_SYM                    /* SQL-2003-N */
702
473
%token  SNAPSHOT_SYM
703
474
%token  SPECIFIC_SYM                  /* SQL-2003-R */
715
486
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
716
487
%token  STD_SYM
717
488
%token  STOP_SYM
718
 
%token  STORAGE_SYM
719
489
%token  STORED_SYM
720
490
%token  STRAIGHT_JOIN
721
491
%token  STRING_SYM
724
494
%token  SUBSTRING                     /* SQL-2003-N */
725
495
%token  SUM_SYM                       /* SQL-2003-N */
726
496
%token  SUSPEND_SYM
727
 
%token  SWAPS_SYM
728
 
%token  SWITCHES_SYM
729
497
%token  SYSDATE
730
498
%token  TABLES
731
499
%token  TABLESPACE
736
504
%token  TEXT_STRING
737
505
%token  TEXT_SYM
738
506
%token  THEN_SYM                      /* SQL-2003-R */
 
507
%token  TIME_SYM                 /* SQL-2003-R */
739
508
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
740
509
%token  TIMESTAMP_ADD
741
510
%token  TIMESTAMP_DIFF
745
514
%token  TRIM                          /* SQL-2003-N */
746
515
%token  TRUE_SYM                      /* SQL-2003-R */
747
516
%token  TRUNCATE_SYM
748
 
%token  TYPES_SYM
749
517
%token  TYPE_SYM                      /* SQL-2003-N */
750
518
%token  ULONGLONG_NUM
751
519
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
755
523
%token  UNIQUE_SYM
756
524
%token  UNKNOWN_SYM                   /* SQL-2003-R */
757
525
%token  UNLOCK_SYM
 
526
%token  UNSIGNED_SYM
758
527
%token  UPDATE_SYM                    /* SQL-2003-R */
759
528
%token  USAGE                         /* SQL-2003-N */
760
529
%token  USER                          /* SQL-2003-R */
762
531
%token  USING                         /* SQL-2003-R */
763
532
%token  UTC_DATE_SYM
764
533
%token  UTC_TIMESTAMP_SYM
 
534
%token  UUID_SYM
765
535
%token  VALUES                        /* SQL-2003-R */
766
536
%token  VALUE_SYM                     /* SQL-2003-R */
767
537
%token  VARBINARY
770
540
%token  VARIANCE_SYM
771
541
%token  VARYING                       /* SQL-2003-R */
772
542
%token  VAR_SAMP_SYM
 
543
%token  WAIT_SYM
773
544
%token  WARNINGS
774
545
%token  WEEK_SYM
775
546
%token  WHEN_SYM                      /* SQL-2003-R */
781
552
%token  XOR
782
553
%token  YEAR_MONTH_SYM
783
554
%token  YEAR_SYM                      /* SQL-2003-R */
 
555
%token  ZEROFILL_SYM
784
556
 
785
557
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
786
558
/* A dummy token to force the priority of table_ref production in a join. */
790
562
%left   XOR
791
563
%left   AND_SYM
792
564
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
793
 
%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
794
566
%left   '-' '+'
795
567
%left   '*' '/' '%' DIV_SYM MOD_SYM
796
568
%left   NEG
800
572
 
801
573
%type <lex_str>
802
574
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
803
 
        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
804
581
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
 
582
        schema_name
 
583
        catalog_name
805
584
        opt_component
806
 
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
585
        engine_option_value
 
586
        savepoint_ident
 
587
        BIN_NUM TEXT_STRING_filesystem
807
588
        opt_constraint constraint opt_ident
808
589
 
809
590
%type <execute_string>
821
602
%type <string>
822
603
        text_string opt_gconcat_separator
823
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
 
824
620
%type <num>
825
 
        type int_type real_type order_dir field_def
826
 
        if_exists opt_table_options
827
 
        opt_if_not_exists
828
 
        opt_temporary all_or_any opt_distinct
 
621
        order_dir
 
622
        field_def
 
623
        opt_table_options
 
624
        all_or_any opt_distinct
829
625
        union_option
830
626
        start_transaction_opts opt_chain opt_release
831
627
        union_opt select_derived_init option_type2
832
 
        opt_status
833
 
        opt_concurrent
 
628
        kill_option
834
629
 
835
630
%type <m_fk_option>
836
631
        delete_option
852
647
        table_wild simple_expr udf_expr
853
648
        expr_or_default set_expr_or_default
854
649
        signed_literal now_or_signed_literal opt_escape
855
 
        simple_ident_nospvar simple_ident_q
 
650
        simple_ident_q
856
651
        field_or_var limit_option
857
652
        function_call_keyword
858
653
        function_call_nonkeyword
892
687
 
893
688
%type <interval_time_st> interval_time_stamp
894
689
 
895
 
%type <column_format_type> column_format_types
896
 
 
897
690
%type <tx_isolation> isolation_types
898
691
 
899
692
%type <cast_type> cast_type
900
693
 
901
 
%type <symbol> keyword keyword_sp
 
694
%type <symbol>
 
695
        keyword
 
696
        keyword_sp
 
697
        keyword_exception_for_variable
 
698
        row_format
902
699
 
903
700
%type <charset>
904
701
        collation_name
933
730
        flush_options flush_option
934
731
        equal optional_braces
935
732
        normal_join
936
 
        table_to_table_list table_to_table opt_table_list opt_as
 
733
        table_to_table_list table_to_table opt_table_list
937
734
        single_multi
938
735
        union_clause union_list
939
736
        precision subselect_start
987
784
            }
988
785
            else
989
786
            {
990
 
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
991
 
              session->lex->statement=
992
 
                new(std::nothrow) statement::EmptyQuery(YYSession);
993
 
              if (session->lex->statement == NULL)
994
 
                DRIZZLE_YYABORT;
 
787
              session->lex->statement= new statement::EmptyQuery(YYSession);
995
788
            }
996
789
          }
997
790
        | verb_clause END_OF_INPUT {}
1035
828
/* create a table */
1036
829
 
1037
830
create:
1038
 
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1039
 
          {
1040
 
            Session *session= YYSession;
1041
 
            LEX *lex= session->lex;
1042
 
            lex->sql_command= SQLCOM_CREATE_TABLE;
1043
 
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1044
 
            lex->statement= statement;
1045
 
            if (lex->statement == NULL)
1046
 
              DRIZZLE_YYABORT;
1047
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1048
 
                                                   TL_OPTION_UPDATING,
1049
 
                                                   TL_WRITE))
1050
 
              DRIZZLE_YYABORT;
1051
 
            lex->col_list.empty();
1052
 
            statement->change=NULL;
1053
 
            statement->is_if_not_exists= $4;
1054
 
            statement->create_info.db_type= NULL;
1055
 
            statement->create_info.default_table_charset= NULL;
1056
 
            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);
1057
838
 
1058
 
            message::Table &proto= statement->create_table_message;
1059
 
           
1060
 
            proto.set_name($5->table.str);
1061
 
            if ($2)
1062
 
              proto.set_type(message::Table::TEMPORARY);
1063
 
            else
1064
 
              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();
1065
844
          }
1066
 
          create2
 
845
          create_table_definition
1067
846
          {
1068
 
            LEX *lex= YYSession->lex;
1069
 
            lex->current_select= &lex->select_lex;
 
847
            Lex->current_select= &Lex->select_lex;
1070
848
          }
1071
849
        | CREATE build_method
1072
850
          {
1073
 
            LEX *lex=Lex;
1074
 
            lex->sql_command= SQLCOM_CREATE_INDEX;
1075
 
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1076
 
            lex->statement= statement;
1077
 
            if (lex->statement == NULL)
1078
 
              DRIZZLE_YYABORT;
1079
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1080
 
            statement->alter_info.build_method= $2;
1081
 
            lex->col_list.empty();
1082
 
            statement->change=NULL;
 
851
            Lex->statement= new statement::CreateIndex(YYSession, $2);
1083
852
          }
1084
853
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
1085
854
          {
1086
 
            LEX *lex=Lex;
1087
 
            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;
1088
859
 
1089
 
            if (!lex->current_select->add_table_to_list(lex->session, $9,
1090
 
                                                        NULL,
1091
 
                                                        TL_OPTION_UPDATING))
1092
 
              DRIZZLE_YYABORT;
1093
 
            Key *key;
1094
 
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1095
 
            statement->alter_info.key_list.push_back(key);
1096
 
            lex->col_list.empty();
 
860
            parser::buildKey(Lex, $4, $6);
1097
861
          }
1098
 
        | CREATE DATABASE opt_if_not_exists ident
 
862
        | CREATE DATABASE opt_if_not_exists schema_name
1099
863
          {
1100
 
            LEX *lex=Lex;
1101
 
 
1102
 
            lex->sql_command=SQLCOM_CREATE_DB;
1103
 
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1104
 
            lex->statement= statement;
1105
 
            if (lex->statement == NULL)
1106
 
              DRIZZLE_YYABORT;
1107
 
            statement->is_if_not_exists= $3;
 
864
            Lex->statement= new statement::CreateSchema(YYSession);
1108
865
          }
1109
866
          opt_create_database_options
1110
867
          {
1112
869
          }
1113
870
        ;
1114
871
 
1115
 
create2:
1116
 
          '(' create2a {}
1117
 
        | opt_create_table_options
1118
 
          create3 {}
1119
 
        | LIKE table_ident opt_create_table_options
1120
 
          {
1121
 
            Session *session= YYSession;
1122
 
            LEX *lex= session->lex;
1123
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1124
 
 
1125
 
            statement->is_create_table_like= true;
1126
 
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1127
 
              DRIZZLE_YYABORT;
1128
 
          }
1129
 
        | '(' LIKE table_ident ')'
1130
 
          {
1131
 
            Session *session= YYSession;
1132
 
            LEX *lex= session->lex;
1133
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1134
 
 
1135
 
            statement->is_create_table_like= true;
1136
 
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1137
 
              DRIZZLE_YYABORT;
1138
 
          }
1139
 
        ;
1140
 
 
1141
 
create2a:
1142
 
          field_list ')' opt_create_table_options
1143
 
          create3 {}
1144
 
        |  create_select ')'
1145
 
           { 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
           }
1146
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
          { }
1147
886
        ;
1148
887
 
1149
 
create3:
 
888
create_select_as:
1150
889
          /* empty */ {}
1151
 
        | opt_duplicate opt_as create_select
1152
 
          { Lex->current_select->set_braces(0);}
 
890
        | opt_duplicate_as create_select
 
891
          {
 
892
            Lex->current_select->set_braces(0);
 
893
          }
1153
894
          union_clause {}
1154
 
        | opt_duplicate opt_as '(' create_select ')'
1155
 
          { Lex->current_select->set_braces(1);}
 
895
        | opt_duplicate_as '(' create_select ')'
 
896
          {
 
897
            Lex->current_select->set_braces(1);
 
898
          }
1156
899
          union_opt {}
1157
900
        ;
1158
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
 
1159
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:
1160
922
          SELECT_SYM
1161
923
          {
1162
 
            LEX *lex=Lex;
1163
 
            lex->lock_option= TL_READ;
1164
 
            if (lex->sql_command == SQLCOM_INSERT)
 
924
            Lex->lock_option= TL_READ;
 
925
            if (Lex->sql_command == SQLCOM_INSERT)
1165
926
            {
1166
 
              lex->sql_command= SQLCOM_INSERT_SELECT;
1167
 
              delete lex->statement;
1168
 
              lex->statement=
1169
 
                new(std::nothrow) statement::InsertSelect(YYSession);
1170
 
              if (lex->statement == NULL)
1171
 
                DRIZZLE_YYABORT;
 
927
              delete Lex->statement;
 
928
              Lex->statement= new statement::InsertSelect(YYSession);
1172
929
            }
1173
 
            else if (lex->sql_command == SQLCOM_REPLACE)
 
930
            else if (Lex->sql_command == SQLCOM_REPLACE)
1174
931
            {
1175
 
              lex->sql_command= SQLCOM_REPLACE_SELECT;
1176
 
              delete lex->statement;
1177
 
              lex->statement=
1178
 
                new(std::nothrow) statement::ReplaceSelect(YYSession);
1179
 
              if (lex->statement == NULL)
1180
 
                DRIZZLE_YYABORT;
 
932
              delete Lex->statement;
 
933
              Lex->statement= new statement::ReplaceSelect(YYSession);
1181
934
            }
1182
935
            /*
1183
936
              The following work only with the local list, the global list
1184
937
              is created correctly in this case
1185
938
            */
1186
 
            lex->current_select->table_list.save_and_clear(&lex->save_list);
1187
 
            mysql_init_select(lex);
1188
 
            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;
1189
942
          }
1190
943
          select_options select_item_list
1191
944
          {
1201
954
          }
1202
955
        ;
1203
956
 
1204
 
opt_as:
1205
 
          /* empty */ {}
1206
 
        | AS {}
1207
 
        ;
1208
 
 
1209
957
opt_create_database_options:
1210
958
          /* empty */ {}
1211
959
        | default_collation_schema {}
1219
967
 
1220
968
custom_database_option:
1221
969
          ident_or_text
1222
 
        {
1223
 
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1224
 
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
1225
 
 
1226
 
          opt->set_name($1.str);
1227
 
        }
 
970
          {
 
971
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
972
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
 
973
          }
1228
974
        | ident_or_text equal ident_or_text
1229
 
        {
1230
 
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1231
 
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
1232
 
 
1233
 
          opt->set_name($1.str);
1234
 
          opt->set_state($3.str);
1235
 
        }
 
975
          {
 
976
            parser::buildSchemaOption(Lex, $1.str, $3);
 
977
          }
1236
978
        | ident_or_text equal ulonglong_num
1237
 
        {
1238
 
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1239
 
          char number_as_string[22];
1240
 
 
1241
 
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
1242
 
 
1243
 
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
1244
 
 
1245
 
          opt->set_name($1.str);
1246
 
          opt->set_state(number_as_string);
1247
 
        }
 
979
          {
 
980
            parser::buildSchemaOption(Lex, $1.str, $3);
 
981
          }
1248
982
        ;
1249
983
 
1250
984
opt_table_options:
1254
988
 
1255
989
opt_if_not_exists:
1256
990
          /* empty */ { $$= false; }
1257
 
        | IF not EXISTS { $$= true; }
 
991
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
1258
992
        ;
1259
993
 
1260
994
opt_create_table_options:
1278
1012
custom_engine_option:
1279
1013
        ENGINE_SYM equal ident_or_text
1280
1014
          {
1281
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1282
 
 
1283
 
            statement->is_engine_set= true;
1284
 
 
1285
 
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
 
1015
            Lex->table()->mutable_engine()->set_name($3.str);
1286
1016
          }
1287
1017
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1288
1018
          {
1289
 
            message::Table::TableOptions *tableopts;
1290
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1291
 
 
1292
 
            tableopts->set_comment($3.str);
 
1019
            Lex->table()->mutable_options()->set_comment($3.str);
1293
1020
          }
1294
1021
        | AUTO_INC opt_equal ulonglong_num
1295
1022
          {
1296
 
            message::Table::TableOptions *tableopts;
1297
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1298
 
 
1299
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1300
 
 
1301
 
            statement->create_info.auto_increment_value=$3;
1302
 
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1303
 
            tableopts->set_auto_increment_value($3);
1304
 
          }
1305
 
        |  ident_or_text equal ident_or_text
1306
 
          {
1307
 
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
1308
 
 
1309
 
            opt->set_name($1.str);
1310
 
            opt->set_state($3.str);
 
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);
1311
1036
          }
1312
1037
        | ident_or_text equal ulonglong_num
1313
1038
          {
1314
 
            char number_as_string[22];
1315
 
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
1316
 
 
1317
 
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
1318
 
            opt->set_name($1.str);
1319
 
            opt->set_state(number_as_string);
 
1039
            parser::buildEngineOption(Lex, $1.str, $3);
1320
1040
          }
1321
1041
        | default_collation
1322
1042
        ;
1324
1044
default_collation:
1325
1045
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1326
1046
          {
1327
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1328
 
 
1329
 
            HA_CREATE_INFO *cinfo= &statement->create_info;
1330
 
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1331
 
                 cinfo->default_table_charset && $4 &&
1332
 
                 !my_charset_same(cinfo->default_table_charset,$4))
1333
 
              {
1334
 
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1335
 
                         $4->name, cinfo->default_table_charset->csname);
1336
 
                DRIZZLE_YYABORT;
1337
 
              }
1338
 
              statement->create_info.default_table_charset= $4;
1339
 
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1047
            if (not parser::buildCollation(Lex, $4))
 
1048
            {
 
1049
              DRIZZLE_YYABORT;
 
1050
            }
1340
1051
          }
1341
1052
        ;
1342
1053
 
1343
1054
default_collation_schema:
1344
1055
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1345
1056
          {
1346
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1347
 
 
1348
 
            message::Schema &schema_message= statement->schema_message;
1349
 
            schema_message.set_collation($4->name);
1350
 
          }
1351
 
        ;
1352
 
 
1353
 
column_format_types:
1354
 
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
1355
 
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
1356
 
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
1357
 
 
 
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
          }
 
1076
        ;
1358
1077
 
1359
1078
opt_select_from:
1360
1079
          opt_limit_clause {}
1382
1101
key_def:
1383
1102
          key_type opt_ident key_alg '(' key_list ')' key_options
1384
1103
          {
1385
 
            LEX *lex=Lex;
1386
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1387
 
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1388
 
                              lex->col_list);
1389
 
            statement->alter_info.key_list.push_back(key);
1390
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1104
            parser::buildKey(Lex, $1, $2);
1391
1105
          }
1392
1106
        | opt_constraint constraint_key_type opt_ident key_alg
1393
1107
          '(' key_list ')' key_options
1394
1108
          {
1395
 
            LEX *lex=Lex;
1396
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1397
 
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1398
 
                              lex->col_list);
1399
 
            statement->alter_info.key_list.push_back(key);
1400
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1109
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
1401
1110
          }
1402
1111
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1403
1112
          {
1404
 
            LEX *lex=Lex;
1405
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1406
 
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
1407
 
                                      $8,
1408
 
                                      lex->ref_list,
1409
 
                                      statement->fk_delete_opt,
1410
 
                                      statement->fk_update_opt,
1411
 
                                      statement->fk_match_option);
1412
 
 
1413
 
            statement->alter_info.key_list.push_back(key);
1414
 
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1415
 
                         &default_key_create_info, 1,
1416
 
                         lex->col_list);
1417
 
            statement->alter_info.key_list.push_back(key);
1418
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1419
 
            /* Only used for ALTER TABLE. Ignored otherwise. */
1420
 
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
1113
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
1421
1114
          }
1422
1115
        | constraint opt_check_constraint
1423
1116
          {
1450
1143
field_spec:
1451
1144
          field_ident
1452
1145
          {
1453
 
            LEX *lex=Lex;
1454
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1455
 
            lex->length=lex->dec=0;
1456
 
            lex->type=0;
1457
 
            statement->default_value= statement->on_update_value= 0;
1458
 
            statement->comment= null_lex_str;
1459
 
            lex->charset=NULL;
1460
 
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1461
 
 
1462
 
            message::AlterTable &alter_proto=
1463
 
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1464
 
            statement->current_proto_field= alter_proto.add_added_field();
 
1146
            parser::buildCreateFieldIdent(Lex);
1465
1147
          }
1466
1148
          field_def
1467
1149
          {
1468
 
            LEX *lex=Lex;
1469
1150
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1470
1151
 
1471
 
            if (statement->current_proto_field)
1472
 
              statement->current_proto_field->set_name($1.str);
 
1152
            if (Lex->field())
 
1153
            {
 
1154
              Lex->field()->set_name($1.str);
 
1155
            }
1473
1156
 
1474
 
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1475
 
                                  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,
1476
1159
                                  statement->column_format,
1477
1160
                                  statement->default_value, statement->on_update_value,
1478
1161
                                  &statement->comment,
1479
 
                                  statement->change, &lex->interval_list, lex->charset))
 
1162
                                  statement->change, &Lex->interval_list, Lex->charset))
1480
1163
              DRIZZLE_YYABORT;
1481
1164
 
1482
 
            statement->current_proto_field= NULL;
 
1165
            Lex->setField(NULL);
1483
1166
          }
1484
1167
        ;
 
1168
 
1485
1169
field_def:
1486
 
          type opt_attribute {}
 
1170
          field_definition opt_attribute {}
1487
1171
        ;
1488
1172
 
1489
 
type:
1490
 
        int_type
1491
 
        {
1492
 
          $$=$1;
1493
 
          Lex->length=(char*) 0; /* use default length */
1494
 
          statement::CreateTable *statement=
1495
 
            (statement::CreateTable *)Lex->statement;
1496
 
 
1497
 
          if (statement->current_proto_field)
1498
 
          {
1499
 
            if ($1 == DRIZZLE_TYPE_LONG)
1500
 
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1501
 
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
1502
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1503
 
            else
1504
 
              abort();
1505
 
          }
 
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));
1506
1177
          }
1507
1178
        | real_type opt_precision
1508
1179
          {
1509
 
            $$=$1;
1510
 
 
1511
 
            statement::CreateTable *statement=
1512
 
              (statement::CreateTable *)Lex->statement;
1513
 
 
1514
 
            if (statement->current_proto_field)
1515
 
            {
1516
 
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
1517
 
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1518
 
            }
1519
 
          }
1520
 
          | char '(' NUM ')'
1521
 
            {
1522
 
              Lex->length=$3.str;
1523
 
              $$=DRIZZLE_TYPE_VARCHAR;
1524
 
 
1525
 
            statement::CreateTable *statement=
1526
 
              (statement::CreateTable *)Lex->statement;
1527
 
 
1528
 
            if (statement->current_proto_field)
1529
 
            {
1530
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1531
 
              message::Table::Field::StringFieldOptions *string_field_options;
1532
 
 
1533
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1534
 
 
1535
 
              string_field_options->set_length(atoi($3.str));
1536
 
            }
1537
 
            }
1538
 
          | char
1539
 
            {
1540
 
              Lex->length=(char*) "1";
1541
 
              $$=DRIZZLE_TYPE_VARCHAR;
1542
 
 
1543
 
            statement::CreateTable *statement=
1544
 
              (statement::CreateTable *)Lex->statement;
1545
 
 
1546
 
            if (statement->current_proto_field)
1547
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1548
 
            }
1549
 
          | varchar '(' NUM ')'
1550
 
            {
1551
 
              Lex->length=$3.str;
1552
 
              $$= DRIZZLE_TYPE_VARCHAR;
1553
 
 
1554
 
            statement::CreateTable *statement=
1555
 
              (statement::CreateTable *)Lex->statement;
1556
 
 
1557
 
            if (statement->current_proto_field)
1558
 
            {
1559
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1560
 
 
1561
 
              message::Table::Field::StringFieldOptions *string_field_options;
1562
 
 
1563
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1564
 
 
1565
 
              string_field_options->set_length(atoi($3.str));
1566
 
            }
1567
 
            }
1568
 
          | VARBINARY '(' NUM ')'
1569
 
            {
1570
 
              Lex->length=$3.str;
1571
 
              Lex->charset=&my_charset_bin;
1572
 
              $$= DRIZZLE_TYPE_VARCHAR;
1573
 
 
1574
 
            statement::CreateTable *statement=
1575
 
              (statement::CreateTable *)Lex->statement;
1576
 
 
1577
 
            if (statement->current_proto_field)
1578
 
            {
1579
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1580
 
              message::Table::Field::StringFieldOptions *string_field_options;
1581
 
 
1582
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1583
 
 
1584
 
              string_field_options->set_length(atoi($3.str));
1585
 
              string_field_options->set_collation_id(my_charset_bin.number);
1586
 
              string_field_options->set_collation(my_charset_bin.name);
1587
 
            }
1588
 
            }
1589
 
          | 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
1590
1200
          {
1591
1201
            $$=DRIZZLE_TYPE_DATE;
1592
1202
 
1593
 
            statement::CreateTable *statement=
1594
 
              (statement::CreateTable *)Lex->statement;
1595
 
 
1596
 
            if (statement->current_proto_field)
1597
 
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1598
 
          }
1599
 
          | TIMESTAMP_SYM
1600
 
          {
1601
 
            $$=DRIZZLE_TYPE_TIMESTAMP;
1602
 
 
1603
 
            statement::CreateTable *statement=
1604
 
              (statement::CreateTable *)Lex->statement;
1605
 
 
1606
 
            if (statement->current_proto_field)
1607
 
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1608
 
          }
1609
 
          | 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
1610
1222
          {
1611
1223
            $$=DRIZZLE_TYPE_DATETIME;
1612
1224
 
1613
 
            statement::CreateTable *statement=
1614
 
              (statement::CreateTable *)Lex->statement;
1615
 
 
1616
 
            if (statement->current_proto_field)
1617
 
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1618
 
          }
1619
 
          | BLOB_SYM
1620
 
            {
1621
 
              Lex->charset=&my_charset_bin;
1622
 
              $$=DRIZZLE_TYPE_BLOB;
1623
 
              Lex->length=(char*) 0; /* use default length */
1624
 
 
1625
 
              statement::CreateTable *statement=
1626
 
                (statement::CreateTable *)Lex->statement;
1627
 
 
1628
 
              if (statement->current_proto_field)
1629
 
              {
1630
 
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
1631
 
                message::Table::Field::StringFieldOptions *string_field_options;
1632
 
 
1633
 
                string_field_options= statement->current_proto_field->mutable_string_options();
1634
 
                string_field_options->set_collation_id(my_charset_bin.number);
1635
 
                string_field_options->set_collation(my_charset_bin.name);
1636
 
              }
1637
 
            }
1638
 
          | TEXT_SYM
1639
 
            {
1640
 
              $$=DRIZZLE_TYPE_BLOB;
1641
 
              Lex->length=(char*) 0; /* use default length */
1642
 
 
1643
 
            statement::CreateTable *statement=
1644
 
              (statement::CreateTable *)Lex->statement;
1645
 
 
1646
 
            if (statement->current_proto_field)
1647
 
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
1648
 
            }
1649
 
          | DECIMAL_SYM float_options
1650
 
          {
1651
 
            $$=DRIZZLE_TYPE_DECIMAL;
1652
 
 
1653
 
            statement::CreateTable *statement=
1654
 
              (statement::CreateTable *)Lex->statement;
1655
 
 
1656
 
            if (statement->current_proto_field)
1657
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1658
 
          }
1659
 
          | NUMERIC_SYM float_options
1660
 
          {
1661
 
            $$=DRIZZLE_TYPE_DECIMAL;
1662
 
 
1663
 
            statement::CreateTable *statement=
1664
 
              (statement::CreateTable *)Lex->statement;
1665
 
 
1666
 
            if (statement->current_proto_field)
1667
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1668
 
          }
1669
 
          | FIXED_SYM float_options
1670
 
          {
1671
 
            $$=DRIZZLE_TYPE_DECIMAL;
1672
 
 
1673
 
            statement::CreateTable *statement=
1674
 
              (statement::CreateTable *)Lex->statement;
1675
 
 
1676
 
            if (statement->current_proto_field)
1677
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1678
 
          }
1679
 
          | ENUM_SYM
1680
 
            {Lex->interval_list.empty();}
1681
 
            '(' 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 ')'
1682
1257
          {
1683
1258
            $$=DRIZZLE_TYPE_ENUM;
1684
1259
 
1685
 
            statement::CreateTable *statement=
1686
 
              (statement::CreateTable *)Lex->statement;
1687
 
 
1688
 
            if (statement->current_proto_field)
1689
 
              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);
1690
1270
          }
1691
1271
        | SERIAL_SYM
1692
1272
          {
1693
 
            $$=DRIZZLE_TYPE_LONGLONG;
1694
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1695
 
 
1696
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1697
 
            if (statement->current_proto_field)
1698
 
            {
1699
 
              message::Table::Field::FieldConstraints *constraints;
1700
 
              constraints= statement->current_proto_field->mutable_constraints();
1701
 
              constraints->set_is_nullable(false);
1702
 
 
1703
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1704
 
            }
 
1273
            $$= parser::buildSerialColumn(Lex);
1705
1274
          }
1706
1275
        ;
1707
1276
 
1715
1284
        ;
1716
1285
 
1717
1286
int_type:
1718
 
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
1719
 
        | 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
          }
1720
1299
        ;
1721
1300
 
1722
1301
real_type:
1725
1304
            $$= DRIZZLE_TYPE_DOUBLE;
1726
1305
          }
1727
1306
        | DOUBLE_SYM
1728
 
          { $$=DRIZZLE_TYPE_DOUBLE; }
 
1307
          {
 
1308
            $$= DRIZZLE_TYPE_DOUBLE;
 
1309
          }
1729
1310
        | DOUBLE_SYM PRECISION
1730
 
          { $$=DRIZZLE_TYPE_DOUBLE; }
 
1311
          {
 
1312
            $$= DRIZZLE_TYPE_DOUBLE;
 
1313
          }
1731
1314
        ;
1732
1315
 
1733
1316
float_options:
1742
1325
precision:
1743
1326
          '(' NUM ',' NUM ')'
1744
1327
          {
1745
 
            LEX *lex=Lex;
1746
 
            lex->length=$2.str;
1747
 
            lex->dec=$4.str;
 
1328
            Lex->length= $2.str;
 
1329
            Lex->dec= $4.str;
1748
1330
          }
1749
1331
        ;
1750
1332
 
1753
1335
        | '(' NUM ')' { Lex->length= $2.str; }
1754
1336
        ;
1755
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
 
1756
1354
opt_precision:
1757
 
          /* empty */ {}
1758
 
        | precision {}
 
1355
          /* empty */
 
1356
          { Lex->dec=Lex->length= (char*)0; }
 
1357
        | '(' NUM ')'
 
1358
          { Lex->length=Lex->dec= (char*)0; }
 
1359
        | precision
 
1360
          {}
1759
1361
        ;
1760
1362
 
1761
1363
opt_attribute:
1771
1373
attribute:
1772
1374
          NULL_SYM
1773
1375
          {
1774
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1775
1376
            Lex->type&= ~ NOT_NULL_FLAG;
1776
 
 
1777
 
            if (statement->current_proto_field)
1778
 
            {
1779
 
              message::Table::Field::FieldConstraints *constraints;
1780
 
              constraints= statement->current_proto_field->mutable_constraints();
1781
 
              constraints->set_is_nullable(true);
1782
 
            }
1783
 
          }
1784
 
        | COLUMN_FORMAT_SYM column_format_types
1785
 
          {
1786
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1787
 
 
1788
 
            statement->column_format= $2;
1789
 
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1790
1377
          }
1791
1378
        | not NULL_SYM
1792
1379
          {
1793
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1794
1380
            Lex->type|= NOT_NULL_FLAG;
1795
1381
 
1796
 
            if (statement->current_proto_field)
 
1382
            if (Lex->field())
1797
1383
            {
1798
 
              message::Table::Field::FieldConstraints *constraints;
1799
 
              constraints= statement->current_proto_field->mutable_constraints();
1800
 
              constraints->set_is_nullable(false);
 
1384
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1801
1385
            }
1802
1386
          }
1803
1387
        | DEFAULT now_or_signed_literal
1808
1392
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1809
1393
          }
1810
1394
        | ON UPDATE_SYM NOW_SYM optional_braces
1811
 
          { ((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
          }
1812
1398
        | AUTO_INC
1813
1399
          {
1814
 
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1815
 
 
1816
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1817
 
            if (statement->current_proto_field)
1818
 
            {
1819
 
              message::Table::Field::FieldConstraints *constraints;
1820
 
 
1821
 
              constraints= statement->current_proto_field->mutable_constraints();
1822
 
              constraints->set_is_nullable(false);
1823
 
            }
 
1400
            parser::buildAutoOnColumn(Lex);
1824
1401
          }
1825
1402
        | SERIAL_SYM DEFAULT VALUE_SYM
1826
1403
          {
1827
 
            LEX *lex=Lex;
1828
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1829
 
 
1830
 
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1831
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1832
 
 
1833
 
            if (statement->current_proto_field)
1834
 
            {
1835
 
              message::Table::Field::FieldConstraints *constraints;
1836
 
              constraints= statement->current_proto_field->mutable_constraints();
1837
 
              constraints->set_is_nullable(false);
1838
 
            }
 
1404
            (void)parser::buildSerialColumn(Lex);
1839
1405
          }
1840
1406
        | opt_primary KEY_SYM
1841
1407
          {
1842
 
            LEX *lex=Lex;
1843
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1844
 
 
1845
 
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1846
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1847
 
 
1848
 
            if (statement->current_proto_field)
1849
 
            {
1850
 
              message::Table::Field::FieldConstraints *constraints;
1851
 
              constraints= statement->current_proto_field->mutable_constraints();
1852
 
              constraints->set_is_nullable(false);
1853
 
            }
 
1408
            parser::buildPrimaryOnColumn(Lex);
1854
1409
          }
1855
1410
        | UNIQUE_SYM
1856
1411
          {
1857
 
            LEX *lex=Lex;
1858
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1859
 
 
1860
 
            lex->type|= UNIQUE_FLAG;
1861
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1412
            parser::buildKeyOnColumn(Lex);
1862
1413
          }
1863
1414
        | UNIQUE_SYM KEY_SYM
1864
1415
          {
1865
 
            LEX *lex=Lex;
1866
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
 
 
1868
 
            lex->type|= UNIQUE_KEY_FLAG;
1869
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1416
            parser::buildKeyOnColumn(Lex);
1870
1417
          }
1871
1418
        | COMMENT_SYM TEXT_STRING_sys
1872
1419
          {
1873
1420
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1874
1421
            statement->comment= $2;
1875
1422
 
1876
 
            if (statement->current_proto_field)
1877
 
              statement->current_proto_field->set_comment($2.str);
 
1423
            if (Lex->field())
 
1424
              Lex->field()->set_comment($2.str);
1878
1425
          }
1879
1426
        | COLLATE_SYM collation_name
1880
1427
          {
1946
1493
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1947
1494
        | ident
1948
1495
          {
1949
 
            LEX *lex= Lex;
1950
 
            lex->ref_list.empty();
1951
 
            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));
1952
1498
          }
1953
1499
        ;
1954
1500
 
1996
1542
delete_option:
1997
1543
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1998
1544
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1999
 
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
 
1545
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
2000
1546
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
2001
 
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
 
1547
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
2002
1548
        ;
2003
1549
 
2004
1550
key_type:
2038
1584
        ;
2039
1585
 
2040
1586
/*
2041
 
  For now, key_alg initializies lex->key_create_info.
 
1587
  For now, key_alg initializies Lex->key_create_info.
2042
1588
  In the future, when all key options are after key definition,
2043
1589
  we can remove key_alg and move init_key_options to key_options
2044
1590
*/
2060
1606
 
2061
1607
key_using_alg:
2062
1608
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2063
 
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2064
1609
        ;
2065
1610
 
2066
1611
key_opt:
2113
1658
*/
2114
1659
 
2115
1660
alter:
2116
 
          ALTER build_method opt_ignore TABLE_SYM table_ident
 
1661
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
2117
1662
          {
2118
 
            Session *session= YYSession;
2119
 
            LEX *lex= session->lex;
2120
 
            lex->name.str= 0;
2121
 
            lex->name.length= 0;
2122
 
            lex->sql_command= SQLCOM_ALTER_TABLE;
2123
 
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
2124
 
            lex->statement= statement;
2125
 
            if (lex->statement == NULL)
2126
 
              DRIZZLE_YYABORT;
2127
 
            lex->duplicates= DUP_ERROR;
2128
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2129
 
                                                   TL_OPTION_UPDATING))
2130
 
              DRIZZLE_YYABORT;
2131
 
            lex->col_list.empty();
2132
 
            lex->select_lex.init_order();
2133
 
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
2134
 
            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());
2135
1674
          }
2136
1675
          alter_commands
2137
1676
          {}
2138
 
        | ALTER DATABASE ident_or_empty
 
1677
        | ALTER_SYM DATABASE schema_name
2139
1678
          {
2140
 
            LEX *lex=Lex;
2141
 
            lex->sql_command=SQLCOM_ALTER_DB;
2142
 
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
2143
 
            if (lex->statement == NULL)
2144
 
              DRIZZLE_YYABORT;
 
1679
            Lex->statement= new statement::AlterSchema(YYSession);
2145
1680
          }
2146
1681
          default_collation_schema
2147
1682
          {
2148
 
            LEX *lex=Lex;
2149
 
            lex->name= $3;
2150
 
            if (lex->name.str == NULL &&
2151
 
                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))
2152
1685
              DRIZZLE_YYABORT;
2153
1686
          }
2154
1687
        ;
2155
1688
 
2156
 
ident_or_empty:
2157
 
          /* empty */ { $$.str= 0; $$.length= 0; }
2158
 
        | ident { $$= $1; }
2159
 
        ;
2160
 
 
2161
1689
alter_commands:
2162
1690
          /* empty */
2163
1691
        | DISCARD TABLESPACE
2194
1722
        ;
2195
1723
 
2196
1724
add_column:
2197
 
          ADD opt_column
 
1725
          ADD_SYM opt_column
2198
1726
          {
2199
1727
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2200
1728
 
2205
1733
 
2206
1734
alter_list_item:
2207
1735
          add_column column_def opt_place { }
2208
 
        | ADD key_def
 
1736
        | ADD_SYM key_def
2209
1737
          {
2210
1738
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2211
1739
 
2218
1746
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2219
1747
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2220
1748
          }
2221
 
        | CHANGE opt_column field_ident
 
1749
        | CHANGE_SYM opt_column field_ident
2222
1750
          {
2223
1751
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2224
1752
            statement->change= $3.str;
2227
1755
          field_spec opt_place
2228
1756
        | MODIFY_SYM opt_column field_ident
2229
1757
          {
2230
 
            LEX *lex=Lex;
2231
1758
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2232
 
            lex->length=lex->dec=0; lex->type=0;
 
1759
            Lex->length= Lex->dec=0;
 
1760
            Lex->type= 0;
2233
1761
            statement->default_value= statement->on_update_value= 0;
2234
1762
            statement->comment= null_lex_str;
2235
 
            lex->charset= NULL;
 
1763
            Lex->charset= NULL;
2236
1764
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2237
1765
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2238
1766
 
2239
 
            statement->current_proto_field= NULL;
 
1767
            Lex->setField(NULL);
2240
1768
          }
2241
1769
          field_def
2242
1770
          {
2243
 
            LEX *lex=Lex;
2244
1771
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2245
1772
 
2246
 
            if (add_field_to_list(lex->session,&$3,
 
1773
            if (add_field_to_list(Lex->session,&$3,
2247
1774
                                  (enum enum_field_types) $5,
2248
 
                                  lex->length, lex->dec, lex->type,
 
1775
                                  Lex->length, Lex->dec, Lex->type,
2249
1776
                                  statement->column_format,
2250
1777
                                  statement->default_value,
2251
1778
                                  statement->on_update_value,
2252
1779
                                  &statement->comment,
2253
 
                                  $3.str, &lex->interval_list, lex->charset))
 
1780
                                  $3.str, &Lex->interval_list, Lex->charset))
2254
1781
              DRIZZLE_YYABORT;
2255
1782
          }
2256
1783
          opt_place
2299
1826
            statement->alter_info.keys_onoff= ENABLE;
2300
1827
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2301
1828
          }
2302
 
        | ALTER opt_column field_ident SET DEFAULT signed_literal
 
1829
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
2303
1830
          {
2304
1831
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2305
1832
 
2306
1833
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
2307
1834
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2308
1835
          }
2309
 
        | ALTER opt_column field_ident DROP DEFAULT
 
1836
        | ALTER_SYM opt_column field_ident DROP DEFAULT
2310
1837
          {
2311
1838
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2312
1839
 
2315
1842
          }
2316
1843
        | RENAME opt_to table_ident
2317
1844
          {
2318
 
            LEX *lex=Lex;
2319
1845
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2320
1846
            size_t dummy;
2321
1847
 
2322
 
            lex->select_lex.db=$3->db.str;
2323
 
            if (lex->select_lex.db == NULL &&
2324
 
                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))
2325
1851
            {
2326
1852
              DRIZZLE_YYABORT;
2327
1853
            }
2332
1858
              DRIZZLE_YYABORT;
2333
1859
            }
2334
1860
 
2335
 
            lex->name= $3->table;
 
1861
            Lex->name= $3->table;
2336
1862
            statement->alter_info.flags.set(ALTER_RENAME);
2337
1863
          }
2338
1864
        | CONVERT_SYM TO_SYM collation_name_or_default
2339
1865
          {
2340
1866
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2341
1867
 
2342
 
            statement->create_info.table_charset=
2343
 
            statement->create_info.default_table_charset= $3;
2344
 
            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 |
2345
1871
              HA_CREATE_USED_DEFAULT_CHARSET);
2346
1872
            statement->alter_info.flags.set(ALTER_CONVERT);
2347
1873
          }
2379
1905
          /* empty */ {}
2380
1906
        | AFTER_SYM ident
2381
1907
          {
2382
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2383
 
 
2384
 
            store_position_for_column($2.str);
2385
 
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
1908
            parser::storeAlterColumnPosition(Lex, $2.str);
2386
1909
          }
2387
1910
        | FIRST_SYM
2388
1911
          {
2389
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2390
 
 
2391
 
            store_position_for_column(first_keyword);
2392
 
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
1912
            parser::storeAlterColumnPosition(Lex, first_keyword);
2393
1913
          }
2394
1914
        ;
2395
1915
 
2403
1923
start:
2404
1924
          START_SYM TRANSACTION_SYM start_transaction_opts
2405
1925
          {
2406
 
            LEX *lex= Lex;
2407
 
            lex->sql_command= SQLCOM_BEGIN;
2408
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2409
 
            if (lex->statement == NULL)
2410
 
              DRIZZLE_YYABORT;
 
1926
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2411
1927
          }
2412
1928
        ;
2413
1929
 
2422
1938
analyze:
2423
1939
          ANALYZE_SYM table_or_tables
2424
1940
          {
2425
 
            LEX *lex=Lex;
2426
 
            lex->sql_command = SQLCOM_ANALYZE;
2427
 
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
2428
 
            if (lex->statement == NULL)
2429
 
              DRIZZLE_YYABORT;
 
1941
            Lex->statement= new statement::Analyze(YYSession);
2430
1942
          }
2431
1943
          table_list
2432
1944
          {}
2435
1947
check:
2436
1948
          CHECK_SYM table_or_tables
2437
1949
          {
2438
 
            LEX *lex=Lex;
2439
 
 
2440
 
            lex->sql_command = SQLCOM_CHECK;
2441
 
            lex->statement= new(std::nothrow) statement::Check(YYSession);
2442
 
            if (lex->statement == NULL)
2443
 
              DRIZZLE_YYABORT;
 
1950
            Lex->statement= new statement::Check(YYSession);
2444
1951
          }
2445
1952
          table_list
2446
1953
          {}
2449
1956
rename:
2450
1957
          RENAME table_or_tables
2451
1958
          {
2452
 
            Lex->sql_command= SQLCOM_RENAME_TABLE;
2453
 
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
2454
 
            if (Lex->statement == NULL)
2455
 
              DRIZZLE_YYABORT;
 
1959
            Lex->statement= new statement::RenameTable(YYSession);
2456
1960
          }
2457
1961
          table_to_table_list
2458
1962
          {}
2466
1970
table_to_table:
2467
1971
          table_ident TO_SYM table_ident
2468
1972
          {
2469
 
            LEX *lex=Lex;
2470
 
            Select_Lex *sl= lex->current_select;
2471
 
            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,
2472
1975
                                       TL_IGNORE) ||
2473
 
                !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,
2474
1977
                                       TL_IGNORE))
2475
1978
              DRIZZLE_YYABORT;
2476
1979
          }
2484
1987
select:
2485
1988
          select_init
2486
1989
          {
2487
 
            LEX *lex= Lex;
2488
 
            lex->sql_command= SQLCOM_SELECT;
2489
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
2490
 
            if (lex->statement == NULL)
2491
 
              DRIZZLE_YYABORT;
 
1990
            Lex->statement= new statement::Select(YYSession);
2492
1991
          }
2493
1992
        ;
2494
1993
 
2501
2000
select_paren:
2502
2001
          SELECT_SYM select_part2
2503
2002
          {
2504
 
            if (setup_select_in_parentheses(YYSession, Lex))
 
2003
            if (parser::setup_select_in_parentheses(YYSession, Lex))
2505
2004
              DRIZZLE_YYABORT;
2506
2005
          }
2507
2006
        | '(' select_paren ')'
2511
2010
select_paren_derived:
2512
2011
          SELECT_SYM select_part2_derived
2513
2012
          {
2514
 
            if (setup_select_in_parentheses(YYSession, Lex))
 
2013
            if (parser::setup_select_in_parentheses(YYSession, Lex))
2515
2014
              DRIZZLE_YYABORT;
2516
2015
          }
2517
2016
        | '(' select_paren_derived ')'
2520
2019
select_init2:
2521
2020
          select_part2
2522
2021
          {
2523
 
            LEX *lex= Lex;
2524
 
            Select_Lex * sel= lex->current_select;
2525
 
            if (lex->current_select->set_braces(0))
 
2022
            Select_Lex * sel= Lex->current_select;
 
2023
            if (Lex->current_select->set_braces(0))
2526
2024
            {
2527
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2528
 
              my_parse_error(&pass);
 
2025
              parser::my_parse_error(YYSession->m_lip);
2529
2026
              DRIZZLE_YYABORT;
2530
2027
            }
2531
2028
            if (sel->linkage == UNION_TYPE &&
2532
2029
                sel->master_unit()->first_select()->braces)
2533
2030
            {
2534
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2535
 
              my_parse_error(&pass);
 
2031
              parser::my_parse_error(YYSession->m_lip);
2536
2032
              DRIZZLE_YYABORT;
2537
2033
            }
2538
2034
          }
2541
2037
 
2542
2038
select_part2:
2543
2039
          {
2544
 
            LEX *lex= Lex;
2545
 
            Select_Lex *sel= lex->current_select;
 
2040
            Select_Lex *sel= Lex->current_select;
2546
2041
            if (sel->linkage != UNION_TYPE)
2547
 
              mysql_init_select(lex);
2548
 
            lex->current_select->parsing_place= SELECT_LIST;
 
2042
              init_select(Lex);
 
2043
            Lex->current_select->parsing_place= SELECT_LIST;
2549
2044
          }
2550
2045
          select_options select_item_list
2551
2046
          {
2575
2070
select_options:
2576
2071
          /* empty*/
2577
2072
        | select_option_list
2578
 
          {
2579
 
            if (Lex->current_select->options & SELECT_DISTINCT &&
2580
 
                Lex->current_select->options & SELECT_ALL)
2581
 
            {
2582
 
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2583
 
              DRIZZLE_YYABORT;
2584
 
            }
2585
 
          }
 
2073
          { }
2586
2074
        ;
2587
2075
 
2588
2076
select_option_list:
2590
2078
        | select_option
2591
2079
        ;
2592
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
 
2593
2128
select_option:
2594
2129
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
2595
 
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
2596
 
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
2597
 
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2598
2130
        | SQL_BUFFER_RESULT
2599
2131
          {
2600
 
            if (check_simple_select())
 
2132
            if (check_simple_select(YYSession))
2601
2133
              DRIZZLE_YYABORT;
2602
2134
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2603
2135
          }
 
2136
        | select_option_small_or_big
 
2137
          { }
 
2138
        | select_option_distinct_or_all
 
2139
          { }
2604
2140
        | SQL_CALC_FOUND_ROWS
2605
2141
          {
2606
 
            if (check_simple_select())
 
2142
            if (check_simple_select(YYSession))
2607
2143
              DRIZZLE_YYABORT;
2608
2144
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2609
2145
          }
2610
 
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2611
2146
        ;
2612
2147
 
2613
2148
select_lock_type:
2614
2149
          /* empty */
2615
2150
        | FOR_SYM UPDATE_SYM
2616
2151
          {
2617
 
            LEX *lex=Lex;
2618
 
            lex->current_select->set_lock_for_tables(TL_WRITE);
 
2152
            Lex->current_select->set_lock_for_tables(TL_WRITE);
2619
2153
          }
2620
2154
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2621
2155
          {
2622
 
            LEX *lex=Lex;
2623
 
            lex->current_select->
 
2156
            Lex->current_select->
2624
2157
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2625
2158
          }
2626
2159
        ;
2630
2163
        | select_item
2631
2164
        | '*'
2632
2165
          {
2633
 
            Session *session= YYSession;
2634
 
            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->
2635
2167
                                                          context,
2636
2168
                                                          NULL, NULL, "*")))
2637
2169
              DRIZZLE_YYABORT;
2638
 
            (session->lex->current_select->with_wild)++;
 
2170
            (YYSession->lex->current_select->with_wild)++;
2639
2171
          }
2640
2172
        ;
2641
2173
 
2642
2174
select_item:
2643
2175
          remember_name table_wild remember_end
2644
2176
          {
2645
 
            Session *session= YYSession;
2646
 
 
2647
 
            if (session->add_item_to_list($2))
 
2177
            if (YYSession->add_item_to_list($2))
2648
2178
              DRIZZLE_YYABORT;
2649
2179
          }
2650
2180
        | remember_name expr remember_end select_alias
2651
2181
          {
2652
 
            Session *session= YYSession;
2653
2182
            assert($1 < $3);
2654
2183
 
2655
 
            if (session->add_item_to_list($2))
 
2184
            if (YYSession->add_item_to_list($2))
2656
2185
              DRIZZLE_YYABORT;
 
2186
 
2657
2187
            if ($4.str)
2658
2188
            {
2659
2189
              $2->is_autogenerated_name= false;
2661
2191
            }
2662
2192
            else if (!$2->name)
2663
2193
            {
2664
 
              $2->set_name($1, (uint) ($3 - $1), session->charset());
 
2194
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
2665
2195
            }
2666
2196
          }
2667
2197
        ;
2668
2198
 
2669
2199
remember_name:
2670
2200
          {
2671
 
            Session *session= YYSession;
2672
 
            Lex_input_stream *lip= session->m_lip;
 
2201
            Lex_input_stream *lip= YYSession->m_lip;
2673
2202
            $$= (char*) lip->get_cpp_tok_start();
2674
2203
          }
2675
2204
        ;
2676
2205
 
2677
2206
remember_end:
2678
2207
          {
2679
 
            Session *session= YYSession;
2680
 
            Lex_input_stream *lip= session->m_lip;
 
2208
            Lex_input_stream *lip= YYSession->m_lip;
2681
2209
            $$= (char*) lip->get_cpp_tok_end();
2682
2210
          }
2683
2211
        ;
2830
2358
          }
2831
2359
        | bit_expr not IN_SYM '(' subselect ')'
2832
2360
          {
2833
 
            Session *session= YYSession;
2834
 
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
2835
 
            $$= negate_expression(session, item);
 
2361
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
 
2362
            $$= negate_expression(YYSession, item);
2836
2363
          }
2837
2364
        | bit_expr IN_SYM '(' expr ')'
2838
2365
          {
2839
 
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2366
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
2840
2367
          }
2841
2368
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2842
2369
          {
2846
2373
          }
2847
2374
        | bit_expr not IN_SYM '(' expr ')'
2848
2375
          {
2849
 
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2376
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
2850
2377
          }
2851
2378
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2852
2379
          {
2857
2384
            $$= item;
2858
2385
          }
2859
2386
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2860
 
          { $$= new Item_func_between($1,$3,$5); }
 
2387
          {
 
2388
            $$= new Item_func_between($1,$3,$5);
 
2389
          }
2861
2390
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2862
2391
          {
2863
2392
            Item_func_between *item= new Item_func_between($1,$4,$6);
2865
2394
            $$= item;
2866
2395
          }
2867
2396
        | bit_expr LIKE simple_expr opt_escape
2868
 
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
 
2397
          { 
 
2398
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
 
2399
          }
2869
2400
        | bit_expr not LIKE simple_expr opt_escape
2870
 
          { $$= 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
          }
2871
2425
        | bit_expr
2872
2426
        ;
2873
2427
 
2927
2481
        | function_call_conflict
2928
2482
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2929
2483
          {
2930
 
            Session *session= YYSession;
2931
 
            Item *i1= new (session->mem_root) Item_string($3.str,
 
2484
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
2932
2485
                                                      $3.length,
2933
 
                                                      session->charset());
2934
 
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
 
2486
                                                      YYSession->charset());
 
2487
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
2935
2488
          }
2936
2489
        | literal
2937
2490
        | variable
2969
2522
          }
2970
2523
        | CAST_SYM '(' expr AS cast_type ')'
2971
2524
          {
2972
 
            LEX *lex= Lex;
2973
 
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
2974
 
                                 lex->charset);
 
2525
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
 
2526
                                 Lex->charset);
2975
2527
            if (!$$)
2976
2528
              DRIZZLE_YYABORT;
2977
2529
          }
2989
2541
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2990
2542
                                                         $3);
2991
2543
          }
2992
 
        | VALUES '(' simple_ident_nospvar ')'
 
2544
        | VALUES '(' simple_ident ')'
2993
2545
          {
2994
2546
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2995
2547
                                                        $3);
3011
2563
        | CURRENT_USER optional_braces
3012
2564
          {
3013
2565
            std::string user_str("user");
3014
 
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
 
2566
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
3015
2567
            {
3016
2568
              DRIZZLE_YYABORT;
3017
2569
            }
3027
2579
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
3028
2580
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3029
2581
          {
3030
 
            Session *session= YYSession;
3031
 
            List<Item> *list= new (session->mem_root) List<Item>;
 
2582
            List<Item> *list= new (YYSession->mem_root) List<Item>;
3032
2583
            list->push_front($5);
3033
2584
            list->push_front($3);
3034
 
            Item_row *item= new (session->mem_root) Item_row(*list);
3035
 
            $$= 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);
3036
2587
          }
3037
2588
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3038
2589
          {
3039
 
            Session *session= YYSession;
3040
2590
            $7->push_front($5);
3041
2591
            $7->push_front($3);
3042
 
            Item_row *item= new (session->mem_root) Item_row(*$7);
3043
 
            $$= 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);
3044
2594
          }
3045
2595
        | LEFT '(' expr ',' expr ')'
3046
2596
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3072
2622
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3073
2623
        | USER '(' ')'
3074
2624
          {
3075
 
            std::string user_str("user");
3076
 
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
 
2625
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
3077
2626
            {
3078
2627
              DRIZZLE_YYABORT;
3079
2628
            }
3139
2688
            args->push_back($3);
3140
2689
            args->push_back($5);
3141
2690
            args->push_back($7);
3142
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2691
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3143
2692
            {
3144
2693
              DRIZZLE_YYABORT;
3145
2694
            }
3150
2699
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3151
2700
            args->push_back($3);
3152
2701
            args->push_back($5);
3153
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2702
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3154
2703
            {
3155
2704
              DRIZZLE_YYABORT;
3156
2705
            }
3162
2711
            args->push_back($3);
3163
2712
            args->push_back($5);
3164
2713
            args->push_back($7);
3165
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2714
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3166
2715
            {
3167
2716
              DRIZZLE_YYABORT;
3168
2717
            }
3173
2722
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3174
2723
            args->push_back($3);
3175
2724
            args->push_back($5);
3176
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2725
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3177
2726
            {
3178
2727
              DRIZZLE_YYABORT;
3179
2728
            }
3216
2765
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3217
2766
        | DATABASE '(' ')'
3218
2767
          {
3219
 
            std::string database_str("database");
3220
 
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
3221
 
            {
3222
 
              DRIZZLE_YYABORT;
3223
 
            }
3224
 
            Lex->setCacheable(false);
3225
 
          }
 
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
          }
3226
2797
        | IF '(' expr ',' expr ',' expr ')'
3227
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
          }
3228
2815
        | MICROSECOND_SYM '(' expr ')'
3229
2816
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
3230
2817
        | MOD_SYM '(' expr ',' expr ')'
3235
2822
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
3236
2823
        | REPLACE '(' expr ',' expr ',' expr ')'
3237
2824
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
3238
 
        | REVERSE_SYM '(' expr ')'
3239
 
          {
3240
 
            std::string reverse_str("reverse");
3241
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3242
 
            args->push_back($3);
3243
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3244
 
            {
3245
 
              DRIZZLE_YYABORT;
3246
 
            }
3247
 
          }
3248
2825
        | TRUNCATE_SYM '(' expr ',' expr ')'
3249
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
          }
3250
2856
        ;
3251
2857
 
3252
2858
/*
3267
2873
          }
3268
2874
          opt_udf_expr_list ')'
3269
2875
          {
3270
 
            Session *session= YYSession;
3271
2876
            Create_func *builder;
3272
2877
            Item *item= NULL;
3273
2878
 
3283
2888
            builder= find_native_function_builder($1);
3284
2889
            if (builder)
3285
2890
            {
3286
 
              item= builder->create(session, $1, $4);
 
2891
              item= builder->create(YYSession, $1, $4);
3287
2892
            }
3288
2893
            else
3289
2894
            {
3291
2896
              const plugin::Function *udf= $<udf>3;
3292
2897
              if (udf)
3293
2898
              {
3294
 
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
2899
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
3295
2900
              } else {
3296
2901
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3297
2902
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3408
3013
        ;
3409
3014
 
3410
3015
variable_aux:
3411
 
          ident_or_text SET_VAR expr
 
3016
          user_variable_ident SET_VAR expr
3412
3017
          {
3413
3018
            $$= new Item_func_set_user_var($1, $3);
3414
3019
            Lex->setCacheable(false);
3415
3020
          }
3416
 
        | ident_or_text
 
3021
        | user_variable_ident
3417
3022
          {
3418
3023
            $$= new Item_func_get_user_var(*YYSession, $1);
3419
3024
            Lex->setCacheable(false);
3420
3025
          }
3421
 
        | '@' opt_var_ident_type ident_or_text opt_component
 
3026
        | '@' opt_var_ident_type user_variable_ident opt_component
3422
3027
          {
3423
3028
            /* disallow "SELECT @@global.global.variable" */
3424
 
            if ($3.str && $4.str && check_reserved_words(&$3))
 
3029
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
3425
3030
            {
3426
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3427
 
              my_parse_error(&pass);
 
3031
              parser::my_parse_error(YYSession->m_lip);
3428
3032
              DRIZZLE_YYABORT;
3429
3033
            }
3430
3034
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3433
3037
        ;
3434
3038
 
3435
3039
opt_distinct:
3436
 
          /* empty */ { $$ = 0; }
3437
 
        | DISTINCT    { $$ = 1; }
 
3040
          /* empty */ { $$ = false; }
 
3041
        | DISTINCT    { $$ = true; }
3438
3042
        ;
3439
3043
 
3440
3044
opt_gconcat_separator:
3463
3067
in_sum_expr:
3464
3068
          opt_all
3465
3069
          {
3466
 
            LEX *lex= Lex;
3467
 
            if (lex->current_select->inc_in_sum_expr())
 
3070
            if (Lex->current_select->inc_in_sum_expr())
3468
3071
            {
3469
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3470
 
              my_parse_error(&pass);
 
3072
              parser::my_parse_error(YYSession->m_lip);
3471
3073
              DRIZZLE_YYABORT;
3472
3074
            }
3473
3075
          }
3481
3083
cast_type:
3482
3084
          BINARY opt_len
3483
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; }
3484
3098
        | CHAR_SYM opt_len
3485
3099
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3486
3100
        | DATE_SYM
3487
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; }
3488
3104
        | DATETIME_SYM
3489
3105
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3490
3106
        | DECIMAL_SYM float_options
3535
3151
          table_factor { $$=$1; }
3536
3152
        | join_table
3537
3153
          {
3538
 
            LEX *lex= Lex;
3539
 
            if (!($$= lex->current_select->nest_last_join(lex->session)))
 
3154
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
3540
3155
              DRIZZLE_YYABORT;
3541
3156
          }
3542
3157
        ;
3683
3298
          }
3684
3299
          expr
3685
3300
          {
3686
 
            LEX *lex= Lex;
3687
 
            if (!($$= lex->current_select->convert_right_join()))
 
3301
            if (!($$= Lex->current_select->convert_right_join()))
3688
3302
              DRIZZLE_YYABORT;
3689
3303
            add_join_on($$, $8);
3690
3304
            Lex->pop_context();
3696
3310
          }
3697
3311
          USING '(' using_list ')'
3698
3312
          {
3699
 
            LEX *lex= Lex;
3700
 
            if (!($$= lex->current_select->convert_right_join()))
 
3313
            if (!($$= Lex->current_select->convert_right_join()))
3701
3314
              DRIZZLE_YYABORT;
3702
3315
            add_join_natural($$,$5,$9,Lex->current_select);
3703
3316
          }
3705
3318
          {
3706
3319
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3707
3320
            add_join_natural($6,$1,NULL,Lex->current_select);
3708
 
            LEX *lex= Lex;
3709
 
            if (!($$= lex->current_select->convert_right_join()))
 
3321
            if (!($$= Lex->current_select->convert_right_join()))
3710
3322
              DRIZZLE_YYABORT;
3711
3323
          }
3712
3324
        ;
3714
3326
normal_join:
3715
3327
          JOIN_SYM {}
3716
3328
        | INNER_SYM JOIN_SYM {}
3717
 
        | CROSS JOIN_SYM { Lex->is_cross= true; }
 
3329
        | CROSS JOIN_SYM
 
3330
          {
 
3331
            Lex->is_cross= true;
 
3332
            Lex->current_select->is_cross= true;
 
3333
          }
3718
3334
        ;
3719
3335
 
3720
3336
/*
3739
3355
          }
3740
3356
        | select_derived_init get_select_lex select_derived2
3741
3357
          {
3742
 
            LEX *lex= Lex;
3743
 
            Select_Lex *sel= lex->current_select;
 
3358
            Select_Lex *sel= Lex->current_select;
3744
3359
            if ($1)
3745
3360
            {
3746
3361
              if (sel->set_braces(1))
3747
3362
              {
3748
 
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3749
 
                my_parse_error(&pass);
 
3363
                parser::my_parse_error(YYSession->m_lip);
3750
3364
                DRIZZLE_YYABORT;
3751
3365
              }
3752
3366
              /* select in braces, can't contain global parameters */
3754
3368
                sel->master_unit()->global_parameters=
3755
3369
                   sel->master_unit()->fake_select_lex;
3756
3370
            }
3757
 
            if ($2->init_nested_join(lex->session))
 
3371
            if ($2->init_nested_join(Lex->session))
3758
3372
              DRIZZLE_YYABORT;
3759
3373
            $$= 0;
3760
3374
            /* incomplete derived tables return NULL, we must be
3796
3410
              /* Handle case of derived table, alias may be NULL if there
3797
3411
                 are no outer parentheses, add_table_to_list() will throw
3798
3412
                 error in this case */
3799
 
              LEX *lex=Lex;
3800
 
              Select_Lex *sel= lex->current_select;
 
3413
              Select_Lex *sel= Lex->current_select;
3801
3414
              Select_Lex_Unit *unit= sel->master_unit();
3802
 
              lex->current_select= sel= unit->outer_select();
3803
 
              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,
3804
3417
                                               new Table_ident(unit), $5, 0,
3805
3418
                                               TL_READ)))
3806
3419
 
3807
3420
                DRIZZLE_YYABORT;
3808
3421
              sel->add_joined_table($$);
3809
 
              lex->pop_context();
 
3422
              Lex->pop_context();
3810
3423
            }
3811
3424
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3812
3425
            {
3813
3426
              /* simple nested joins cannot have aliases or unions */
3814
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3815
 
              my_parse_error(&pass);
 
3427
              parser::my_parse_error(YYSession->m_lip);
3816
3428
              DRIZZLE_YYABORT;
3817
3429
            }
3818
3430
            else
3826
3438
          UNION_SYM
3827
3439
          union_option
3828
3440
          {
3829
 
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3441
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
3830
3442
              DRIZZLE_YYABORT;
3831
3443
          }
3832
3444
          query_specification
3844
3456
select_init2_derived:
3845
3457
          select_part2_derived
3846
3458
          {
3847
 
            LEX *lex= Lex;
3848
 
            Select_Lex * sel= lex->current_select;
3849
 
            if (lex->current_select->set_braces(0))
 
3459
            Select_Lex * sel= Lex->current_select;
 
3460
            if (Lex->current_select->set_braces(0))
3850
3461
            {
3851
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3852
 
              my_parse_error(&pass);
 
3462
              parser::my_parse_error(YYSession->m_lip);
3853
3463
              DRIZZLE_YYABORT;
3854
3464
            }
3855
3465
            if (sel->linkage == UNION_TYPE &&
3856
3466
                sel->master_unit()->first_select()->braces)
3857
3467
            {
3858
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3859
 
              my_parse_error(&pass);
 
3468
              parser::my_parse_error(YYSession->m_lip);
3860
3469
              DRIZZLE_YYABORT;
3861
3470
            }
3862
3471
          }
3865
3474
/* The equivalent of select_part2 for nested queries. */
3866
3475
select_part2_derived:
3867
3476
          {
3868
 
            LEX *lex= Lex;
3869
 
            Select_Lex *sel= lex->current_select;
 
3477
            Select_Lex *sel= Lex->current_select;
3870
3478
            if (sel->linkage != UNION_TYPE)
3871
 
              mysql_init_select(lex);
3872
 
            lex->current_select->parsing_place= SELECT_LIST;
 
3479
              init_select(Lex);
 
3480
            Lex->current_select->parsing_place= SELECT_LIST;
3873
3481
          }
3874
3482
          select_options select_item_list
3875
3483
          {
3882
3490
select_derived:
3883
3491
          get_select_lex
3884
3492
          {
3885
 
            LEX *lex= Lex;
3886
 
            if ($1->init_nested_join(lex->session))
 
3493
            if ($1->init_nested_join(Lex->session))
3887
3494
              DRIZZLE_YYABORT;
3888
3495
          }
3889
3496
          derived_table_list
3890
3497
          {
3891
 
            LEX *lex= Lex;
3892
3498
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3893
3499
               for derived tables, both must equal NULL */
3894
3500
 
3895
 
            if (!($$= $1->end_nested_join(lex->session)) && $3)
 
3501
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
3896
3502
              DRIZZLE_YYABORT;
 
3503
 
3897
3504
            if (!$3 && $$)
3898
3505
            {
3899
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3900
 
              my_parse_error(&pass);
 
3506
              parser::my_parse_error(YYSession->m_lip);
3901
3507
              DRIZZLE_YYABORT;
3902
3508
            }
3903
3509
          }
3905
3511
 
3906
3512
select_derived2:
3907
3513
          {
3908
 
            LEX *lex= Lex;
3909
 
            lex->derived_tables|= DERIVED_SUBQUERY;
3910
 
            if (!lex->expr_allows_subselect)
 
3514
            Lex->derived_tables|= DERIVED_SUBQUERY;
 
3515
            if (not Lex->expr_allows_subselect)
3911
3516
            {
3912
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3913
 
              my_parse_error(&pass);
 
3517
              parser::my_parse_error(YYSession->m_lip);
3914
3518
              DRIZZLE_YYABORT;
3915
3519
            }
3916
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
3917
 
                mysql_new_select(lex, 1))
 
3520
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
3918
3521
              DRIZZLE_YYABORT;
3919
 
            mysql_init_select(lex);
3920
 
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
3921
 
            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;
3922
3525
          }
3923
3526
          select_options select_item_list
3924
3527
          {
3934
3537
select_derived_init:
3935
3538
          SELECT_SYM
3936
3539
          {
3937
 
            LEX *lex= Lex;
3938
 
 
3939
 
            Select_Lex *sel= lex->current_select;
 
3540
            Select_Lex *sel= Lex->current_select;
3940
3541
            TableList *embedding;
3941
 
            if (!sel->embedding || sel->end_nested_join(lex->session))
 
3542
            if (!sel->embedding || sel->end_nested_join(Lex->session))
3942
3543
            {
3943
3544
              /* we are not in parentheses */
3944
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3945
 
              my_parse_error(&pass);
 
3545
              parser::my_parse_error(YYSession->m_lip);
3946
3546
              DRIZZLE_YYABORT;
3947
3547
            }
3948
3548
            embedding= Lex->current_select->embedding;
4090
3690
opt_table_alias:
4091
3691
          /* empty */ { $$=0; }
4092
3692
        | table_alias ident
4093
 
          { $$= (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
          }
4094
3696
        ;
4095
3697
 
4096
3698
opt_all:
4170
3772
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
4171
3773
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
4172
3774
            */
4173
 
            LEX *lex= Lex;
4174
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
3775
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4175
3776
            {
4176
3777
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
4177
3778
                       "global union parameters");
4178
3779
              DRIZZLE_YYABORT;
4179
3780
            }
4180
 
            lex->current_select->olap= ROLLUP_TYPE;
 
3781
            Lex->current_select->olap= ROLLUP_TYPE;
4181
3782
          }
4182
3783
        ;
4183
3784
 
4195
3796
        ;
4196
3797
 
4197
3798
alter_order_item:
4198
 
          simple_ident_nospvar order_dir
 
3799
          simple_ident order_dir
4199
3800
          {
4200
 
            Session *session= YYSession;
4201
3801
            bool ascending= ($2 == 1) ? true : false;
4202
 
            if (session->add_order_to_list($1, ascending))
 
3802
            if (YYSession->add_order_to_list($1, ascending))
4203
3803
              DRIZZLE_YYABORT;
4204
3804
          }
4205
3805
        ;
4216
3816
order_clause:
4217
3817
          ORDER_SYM BY
4218
3818
          {
4219
 
            LEX *lex=Lex;
4220
 
            Select_Lex *sel= lex->current_select;
4221
 
            Select_Lex_Unit *unit= sel-> master_unit();
4222
 
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4223
 
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
4224
 
                (sel->linkage != UNION_TYPE || sel->braces))
4225
 
            {
4226
 
              my_error(ER_WRONG_USAGE, MYF(0),
4227
 
                       "CUBE/ROLLUP", "ORDER BY");
 
3819
            if (not parser::buildOrderBy(Lex))
4228
3820
              DRIZZLE_YYABORT;
4229
 
            }
4230
 
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
4231
 
            {
4232
 
              /*
4233
 
                A query of the of the form (SELECT ...) ORDER BY order_list is
4234
 
                executed in the same way as the query
4235
 
                SELECT ... ORDER BY order_list
4236
 
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
4237
 
                Otherwise we create a fake Select_Lex if it has not been created
4238
 
                yet.
4239
 
              */
4240
 
              Select_Lex *first_sl= unit->first_select();
4241
 
              if (!unit->is_union() &&
4242
 
                  (first_sl->order_list.elements ||
4243
 
                   first_sl->select_limit) &&           
4244
 
                  unit->add_fake_select_lex(lex->session))
4245
 
                DRIZZLE_YYABORT;
4246
 
            }
4247
3821
          }
4248
3822
          order_list
4249
3823
        ;
4250
3824
 
4251
3825
order_list:
4252
3826
          order_list ',' order_ident order_dir
4253
 
          { 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
          }
4254
3831
        | order_ident order_dir
4255
 
          { 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
          }
4256
3836
        ;
4257
3837
 
4258
3838
order_dir:
4264
3844
opt_limit_clause_init:
4265
3845
          /* empty */
4266
3846
          {
4267
 
            LEX *lex= Lex;
4268
 
            Select_Lex *sel= lex->current_select;
 
3847
            Select_Lex *sel= Lex->current_select;
4269
3848
            sel->offset_limit= 0;
4270
3849
            sel->select_limit= 0;
4271
3850
          }
4314
3893
delete_limit_clause:
4315
3894
          /* empty */
4316
3895
          {
4317
 
            LEX *lex=Lex;
4318
 
            lex->current_select->select_limit= 0;
 
3896
            Lex->current_select->select_limit= 0;
4319
3897
          }
4320
3898
        | LIMIT limit_option
4321
3899
          {
4326
3904
        ;
4327
3905
 
4328
3906
ulong_num:
4329
 
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4330
 
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
4331
 
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4332
 
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4333
 
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4334
 
        | 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); }
4335
3913
        ;
4336
3914
 
4337
3915
ulonglong_num:
4344
3922
 
4345
3923
select_var_list_init:
4346
3924
          {
4347
 
            LEX *lex=Lex;
4348
 
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
 
3925
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
4349
3926
              DRIZZLE_YYABORT;
4350
3927
          }
4351
3928
          select_var_list
4358
3935
        ;
4359
3936
 
4360
3937
select_var_ident: 
4361
 
          '@' ident_or_text
 
3938
          '@' user_variable_ident
4362
3939
          {
4363
 
            LEX *lex=Lex;
4364
 
            if (lex->result)
4365
 
              ((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
            }
4366
3944
            else
 
3945
            {
4367
3946
              /*
4368
3947
                The parser won't create select_result instance only
4369
3948
                if it's an EXPLAIN.
4370
3949
              */
4371
 
              assert(lex->describe);
 
3950
              assert(Lex->describe);
 
3951
            }
4372
3952
          }
4373
3953
        ;
4374
3954
 
4381
3961
into_destination:
4382
3962
          OUTFILE TEXT_STRING_filesystem
4383
3963
          {
4384
 
            LEX *lex= Lex;
4385
 
            lex->setCacheable(false);
4386
 
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
4387
 
                !(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)))
4388
3967
              DRIZZLE_YYABORT;
4389
3968
          }
4390
3969
          opt_field_term opt_line_term
4391
3970
        | DUMPFILE TEXT_STRING_filesystem
4392
3971
          {
4393
 
            LEX *lex=Lex;
4394
 
            if (!lex->describe)
 
3972
            if (not Lex->describe)
4395
3973
            {
4396
 
              lex->setCacheable(false);
4397
 
              if (!(lex->exchange= new file_exchange($2.str,1)))
 
3974
              Lex->setCacheable(false);
 
3975
              if (not (Lex->exchange= new file_exchange($2.str,1)))
4398
3976
                DRIZZLE_YYABORT;
4399
 
              if (!(lex->result= new select_dump(lex->exchange)))
 
3977
              if (not (Lex->result= new select_dump(Lex->exchange)))
4400
3978
                DRIZZLE_YYABORT;
4401
3979
            }
4402
3980
          }
4409
3987
*/
4410
3988
 
4411
3989
drop:
4412
 
          DROP opt_temporary table_or_tables if_exists table_list
4413
 
          {
4414
 
            LEX *lex=Lex;
4415
 
            lex->sql_command = SQLCOM_DROP_TABLE;
4416
 
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
4417
 
            lex->statement= statement;
4418
 
            if (lex->statement == NULL)
4419
 
              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;
4420
3998
            statement->drop_temporary= $2;
4421
3999
            statement->drop_if_exists= $4;
4422
4000
          }
4423
4001
        | DROP build_method INDEX_SYM ident ON table_ident {}
4424
4002
          {
4425
 
            LEX *lex=Lex;
4426
 
            lex->sql_command= SQLCOM_DROP_INDEX;
4427
 
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
4428
 
            lex->statement= statement;
4429
 
            if (lex->statement == NULL)
4430
 
              DRIZZLE_YYABORT;
 
4003
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
 
4004
            Lex->statement= statement;
4431
4005
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4432
4006
            statement->alter_info.build_method= $2;
4433
4007
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4434
 
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4435
 
                                                        TL_OPTION_UPDATING))
 
4008
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
 
4009
                                                          TL_OPTION_UPDATING))
4436
4010
              DRIZZLE_YYABORT;
4437
4011
          }
4438
 
        | DROP DATABASE if_exists ident
 
4012
        | DROP DATABASE if_exists schema_name
4439
4013
          {
4440
 
            LEX *lex=Lex;
4441
 
            lex->sql_command= SQLCOM_DROP_DB;
4442
 
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
4443
 
            lex->statement= statement;
4444
 
            if (lex->statement == NULL)
4445
 
              DRIZZLE_YYABORT;
 
4014
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
 
4015
            Lex->statement= statement;
4446
4016
            statement->drop_if_exists=$3;
4447
 
            lex->name= $4;
 
4017
            Lex->name= $4;
4448
4018
          }
 
4019
        ;
 
4020
 
4449
4021
table_list:
4450
4022
          table_name
4451
4023
        | table_list ',' table_name
4460
4032
        ;
4461
4033
 
4462
4034
if_exists:
4463
 
          /* empty */ { $$= 0; }
4464
 
        | IF EXISTS { $$= 1; }
 
4035
          /* empty */ { $$= false; }
 
4036
        | IF EXISTS { $$= true; }
4465
4037
        ;
4466
4038
 
4467
4039
opt_temporary:
4468
 
          /* empty */ { $$= 0; }
4469
 
        | TEMPORARY_SYM { $$= 1; }
 
4040
          /* empty */ { $$= false; }
 
4041
        | TEMPORARY_SYM { $$= true; }
4470
4042
        ;
4471
4043
 
4472
4044
/*
4473
4045
  Execute a string as dynamic SQL.
4474
 
  */
 
4046
*/
4475
4047
 
4476
4048
execute:
4477
 
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent
4478
 
       {
4479
 
          LEX *lex= Lex;
4480
 
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession, $2, $3, $4);
4481
 
          lex->statement= statement;
4482
 
          if (lex->statement == NULL)
4483
 
            DRIZZLE_YYABORT;
4484
 
       }
 
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
        }
4485
4053
 
4486
4054
 
4487
4055
execute_var_or_string:
4488
 
         ident_or_text
 
4056
         user_variable_ident
4489
4057
         {
4490
4058
            $$.set($1);
4491
4059
         }
4492
 
        | '@' ident_or_text
 
4060
        | '@' user_variable_ident
4493
4061
        {
4494
4062
            $$.set($2, true);
4495
4063
        }
4496
4064
 
4497
4065
opt_status:
4498
 
          /* empty */ { $$= 0; }
4499
 
        | WITH NO_SYM RETURN_SYM { $$= 1; }
 
4066
          /* empty */ { $$= false; }
 
4067
        | WITH NO_SYM RETURN_SYM { $$= true; }
4500
4068
        ;
4501
4069
 
4502
4070
opt_concurrent:
4503
 
          /* empty */ { $$= 0; }
4504
 
        | CONCURRENT { $$= 1; }
 
4071
          /* empty */ { $$= false; }
 
4072
        | CONCURRENT { $$= true; }
 
4073
        ;
 
4074
 
 
4075
opt_wait:
 
4076
          /* empty */ { $$= false; }
 
4077
        | WAIT_SYM { $$= true; }
4505
4078
        ;
4506
4079
 
4507
4080
/*
4511
4084
insert:
4512
4085
          INSERT
4513
4086
          {
4514
 
            LEX *lex= Lex;
4515
 
            lex->sql_command= SQLCOM_INSERT;
4516
 
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
4517
 
            if (lex->statement == NULL)
4518
 
              DRIZZLE_YYABORT;
4519
 
            lex->duplicates= DUP_ERROR;
4520
 
            mysql_init_select(lex);
 
4087
            Lex->statement= new statement::Insert(YYSession);
 
4088
            Lex->duplicates= DUP_ERROR;
 
4089
            init_select(Lex);
4521
4090
            /* for subselects */
4522
 
            lex->lock_option= TL_READ;
 
4091
            Lex->lock_option= TL_READ;
4523
4092
          }
4524
4093
          opt_ignore insert2
4525
4094
          {
4533
4102
replace:
4534
4103
          REPLACE
4535
4104
          {
4536
 
            LEX *lex= Lex;
4537
 
            lex->sql_command= SQLCOM_REPLACE;
4538
 
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
4539
 
            if (lex->statement == NULL)
4540
 
              DRIZZLE_YYABORT;
4541
 
            lex->duplicates= DUP_REPLACE;
4542
 
            mysql_init_select(lex);
 
4105
            Lex->statement= new statement::Replace(YYSession);
 
4106
            Lex->duplicates= DUP_REPLACE;
 
4107
            init_select(Lex);
4543
4108
          }
4544
4109
          insert2
4545
4110
          {
4558
4123
insert_table:
4559
4124
          table_name
4560
4125
          {
4561
 
            LEX *lex=Lex;
4562
 
            lex->field_list.empty();
4563
 
            lex->many_values.empty();
4564
 
            lex->insert_list=0;
 
4126
            Lex->field_list.empty();
 
4127
            Lex->many_values.empty();
 
4128
            Lex->insert_list=0;
4565
4129
          };
4566
4130
 
4567
4131
insert_field_spec:
4568
4132
          insert_values {}
4569
4133
        | '(' ')' insert_values {}
4570
4134
        | '(' fields ')' insert_values {}
4571
 
        | SET
 
4135
        | SET_SYM
4572
4136
          {
4573
 
            LEX *lex=Lex;
4574
 
            if (!(lex->insert_list = new List_item) ||
4575
 
                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))
4576
4139
              DRIZZLE_YYABORT;
4577
4140
          }
4578
4141
          ident_eq_list
4586
4149
insert_values:
4587
4150
          VALUES values_list {}
4588
4151
        | VALUE_SYM values_list {}
4589
 
        | create_select
4590
 
          { Lex->current_select->set_braces(0);}
 
4152
        | stored_select
 
4153
          {
 
4154
            Lex->current_select->set_braces(0);
 
4155
          }
4591
4156
          union_clause {}
4592
 
        | '(' create_select ')'
4593
 
          { Lex->current_select->set_braces(1);}
 
4157
        | '(' stored_select ')'
 
4158
          {
 
4159
            Lex->current_select->set_braces(1);
 
4160
          }
4594
4161
          union_opt {}
4595
4162
        ;
4596
4163
 
4605
4172
        ;
4606
4173
 
4607
4174
ident_eq_value:
4608
 
          simple_ident_nospvar equal expr_or_default
 
4175
          simple_ident equal expr_or_default
4609
4176
          {
4610
 
            LEX *lex=Lex;
4611
 
            if (lex->field_list.push_back($1) ||
4612
 
                lex->insert_list->push_back($3))
 
4177
            if (Lex->field_list.push_back($1) ||
 
4178
                Lex->insert_list->push_back($3))
4613
4179
              DRIZZLE_YYABORT;
4614
4180
          }
4615
4181
        ;
4632
4198
          }
4633
4199
          opt_values ')'
4634
4200
          {
4635
 
            LEX *lex=Lex;
4636
 
            if (lex->many_values.push_back(lex->insert_list))
 
4201
            if (Lex->many_values.push_back(Lex->insert_list))
4637
4202
              DRIZZLE_YYABORT;
4638
4203
          }
4639
4204
        ;
4672
4237
update:
4673
4238
          UPDATE_SYM opt_ignore table_ident
4674
4239
          {
4675
 
            LEX *lex= Lex;
4676
 
            mysql_init_select(lex);
4677
 
            lex->sql_command= SQLCOM_UPDATE;
4678
 
            lex->statement= new(std::nothrow) statement::Update(YYSession);
4679
 
            if (lex->statement == NULL)
4680
 
              DRIZZLE_YYABORT;
4681
 
            lex->lock_option= TL_UNLOCK; /* Will be set later */
4682
 
            lex->duplicates= DUP_ERROR;
4683
 
            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))
4684
4245
              DRIZZLE_YYABORT;
4685
4246
          }
4686
 
          SET update_list
 
4247
          SET_SYM update_list
4687
4248
          {
4688
 
            LEX *lex= Lex;
4689
 
            if (lex->select_lex.get_table_list()->derived)
 
4249
            if (Lex->select_lex.get_table_list()->derived)
4690
4250
            {
4691
4251
              /* it is single table update and it is update of derived table */
4692
4252
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4693
 
                       lex->select_lex.get_table_list()->alias, "UPDATE");
 
4253
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
4694
4254
              DRIZZLE_YYABORT;
4695
4255
            }
4696
4256
            /*
4697
4257
              In case of multi-update setting write lock for all tables may
4698
4258
              be too pessimistic. We will decrease lock level if possible in
4699
 
              mysql_multi_update().
 
4259
              multi_update().
4700
4260
            */
4701
4261
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4702
4262
          }
4709
4269
        ;
4710
4270
 
4711
4271
update_elem:
4712
 
          simple_ident_nospvar equal expr_or_default
 
4272
          simple_ident equal expr_or_default
4713
4273
          {
4714
4274
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4715
4275
              DRIZZLE_YYABORT;
4722
4282
        ;
4723
4283
 
4724
4284
insert_update_elem:
4725
 
          simple_ident_nospvar equal expr_or_default
 
4285
          simple_ident equal expr_or_default
4726
4286
          {
4727
 
          LEX *lex= Lex;
4728
 
          if (lex->update_list.push_back($1) ||
4729
 
              lex->value_list.push_back($3))
 
4287
          if (Lex->update_list.push_back($1) ||
 
4288
              Lex->value_list.push_back($3))
4730
4289
              DRIZZLE_YYABORT;
4731
4290
          }
4732
4291
        ;
4736
4295
delete:
4737
4296
          DELETE_SYM
4738
4297
          {
4739
 
            LEX *lex= Lex;
4740
 
            lex->sql_command= SQLCOM_DELETE;
4741
 
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
4742
 
            if (lex->statement == NULL)
4743
 
              DRIZZLE_YYABORT;
4744
 
            mysql_init_select(lex);
4745
 
            lex->lock_option= TL_WRITE_DEFAULT;
4746
 
            lex->ignore= 0;
4747
 
            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();
4748
4303
          }
4749
4304
          opt_delete_options single_multi
4750
4305
        ;
4772
4327
truncate:
4773
4328
          TRUNCATE_SYM opt_table_sym table_name
4774
4329
          {
4775
 
            LEX* lex= Lex;
4776
 
            lex->sql_command= SQLCOM_TRUNCATE;
4777
 
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
4778
 
            if (lex->statement == NULL)
4779
 
              DRIZZLE_YYABORT;
4780
 
            lex->select_lex.options= 0;
4781
 
            lex->select_lex.init_order();
 
4330
            Lex->statement= new statement::Truncate(YYSession);
 
4331
            Lex->select_lex.options= 0;
 
4332
            Lex->select_lex.init_order();
4782
4333
          }
4783
4334
        ;
4784
4335
 
4792
4343
show:
4793
4344
          SHOW
4794
4345
          {
4795
 
            LEX *lex=Lex;
4796
 
            lex->wild=0;
4797
 
            lex->lock_option= TL_READ;
4798
 
            mysql_init_select(lex);
4799
 
            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;
4800
4349
          }
4801
4350
          show_param
4802
4351
          {}
4806
4355
show_param:
4807
4356
           DATABASES show_wild
4808
4357
           {
4809
 
             LEX *lex= Lex;
4810
 
             Session *session= YYSession;
4811
 
 
4812
 
             lex->sql_command= SQLCOM_SELECT;
4813
 
             lex->statement=
4814
 
               new(std::nothrow) statement::Show(session);
4815
 
             if (lex->statement == NULL)
4816
 
               DRIZZLE_YYABORT;
4817
 
 
4818
 
             std::string column_name= "Database";
4819
 
             if (Lex->wild)
4820
 
             {
4821
 
               column_name.append(" (");
4822
 
               column_name.append(Lex->wild->ptr());
4823
 
               column_name.append(")");
4824
 
             }
4825
 
 
4826
 
             if (Lex->current_select->where)
4827
 
             {
4828
 
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4829
 
                 DRIZZLE_YYABORT;
4830
 
             }
4831
 
             else
4832
 
             {
4833
 
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4834
 
                 DRIZZLE_YYABORT;
4835
 
             }
4836
 
 
4837
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4838
 
             my_field->is_autogenerated_name= false;
4839
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4840
 
 
4841
 
             if (session->add_item_to_list(my_field))
4842
 
               DRIZZLE_YYABORT;
4843
 
 
4844
 
              if (session->add_order_to_list(my_field, true))
4845
 
                DRIZZLE_YYABORT;
 
4358
             if (not show::buildScemas(YYSession))
 
4359
               DRIZZLE_YYABORT;
4846
4360
           }
4847
4361
           /* SHOW TABLES */
4848
4362
         | TABLES opt_db show_wild
4849
4363
           {
4850
 
             LEX *lex= Lex;
4851
 
             Session *session= YYSession;
4852
 
 
4853
 
             lex->sql_command= SQLCOM_SELECT;
4854
 
 
4855
 
             statement::Show *select=
4856
 
               new(std::nothrow) statement::Show(YYSession);
4857
 
 
4858
 
             lex->statement= select;
4859
 
 
4860
 
             if (lex->statement == NULL)
4861
 
               DRIZZLE_YYABORT;
4862
 
 
4863
 
 
4864
 
              std::string column_name= "Tables_in_";
4865
 
 
4866
 
              if ($2)
4867
 
              {
4868
 
                SchemaIdentifier identifier($2);
4869
 
                column_name.append($2);
4870
 
                lex->select_lex.db= $2;
4871
 
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
4872
 
                {
4873
 
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4874
 
                }
4875
 
                select->setShowPredicate($2, "");
4876
 
              }
4877
 
              else if (not session->db.empty())
4878
 
              {
4879
 
                column_name.append(session->db);
4880
 
                select->setShowPredicate(session->db, "");
4881
 
              }
4882
 
              else
4883
 
              {
4884
 
                 my_error(ER_NO_DB_ERROR, MYF(0));
4885
 
              }
4886
 
 
4887
 
 
4888
 
             if (Lex->wild)
4889
 
             {
4890
 
               column_name.append(" (");
4891
 
               column_name.append(Lex->wild->ptr());
4892
 
               column_name.append(")");
4893
 
             }
4894
 
 
4895
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4896
 
               DRIZZLE_YYABORT;
4897
 
 
4898
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4899
 
             my_field->is_autogenerated_name= false;
4900
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4901
 
 
4902
 
             if (session->add_item_to_list(my_field))
4903
 
               DRIZZLE_YYABORT;
4904
 
 
4905
 
              if (session->add_order_to_list(my_field, true))
4906
 
                DRIZZLE_YYABORT;
 
4364
             if (not show::buildTables(YYSession, $2))
 
4365
               DRIZZLE_YYABORT;
4907
4366
           }
4908
4367
           /* SHOW TEMPORARY TABLES */
4909
4368
         | TEMPORARY_SYM TABLES show_wild
4910
4369
           {
4911
 
             LEX *lex= Lex;
4912
 
             Session *session= YYSession;
4913
 
 
4914
 
             lex->sql_command= SQLCOM_SELECT;
4915
 
 
4916
 
             statement::Show *select=
4917
 
               new(std::nothrow) statement::Show(YYSession);
4918
 
 
4919
 
             lex->statement= select;
4920
 
 
4921
 
             if (lex->statement == NULL)
4922
 
               DRIZZLE_YYABORT;
4923
 
 
4924
 
 
4925
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4926
 
               DRIZZLE_YYABORT;
4927
 
 
4928
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4929
 
                                                           context,
4930
 
                                                           NULL, NULL, "*")))
4931
 
               DRIZZLE_YYABORT;
4932
 
             (session->lex->current_select->with_wild)++;
4933
 
 
 
4370
             if (not show::buildTemporaryTables(YYSession))
 
4371
               DRIZZLE_YYABORT;
4934
4372
           }
4935
4373
           /* SHOW TABLE STATUS */
4936
4374
         | TABLE_SYM STATUS_SYM opt_db show_wild
4937
4375
           {
4938
 
             LEX *lex= Lex;
4939
 
             lex->sql_command= SQLCOM_SELECT;
4940
 
             statement::Show *select=
4941
 
               new(std::nothrow) statement::Show(YYSession);
4942
 
 
4943
 
             lex->statement= select;
4944
 
 
4945
 
             if (lex->statement == NULL)
4946
 
               DRIZZLE_YYABORT;
4947
 
 
4948
 
             Session *session= YYSession;
4949
 
 
4950
 
             std::string column_name= "Tables_in_";
4951
 
 
4952
 
             if ($3)
4953
 
             {
4954
 
               lex->select_lex.db= $3;
4955
 
 
4956
 
               SchemaIdentifier identifier($3);
4957
 
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
4958
 
               {
4959
 
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4960
 
               }
4961
 
 
4962
 
               select->setShowPredicate($3, "");
4963
 
             }
4964
 
             else
4965
 
             {
4966
 
               select->setShowPredicate(session->db, "");
4967
 
             }
4968
 
 
4969
 
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
4970
 
               DRIZZLE_YYABORT;
4971
 
 
4972
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4973
 
                                                           context,
4974
 
                                                           NULL, NULL, "*")))
4975
 
               DRIZZLE_YYABORT;
4976
 
             (session->lex->current_select->with_wild)++;
 
4376
             if (not show::buildTableStatus(YYSession, $3))
 
4377
               DRIZZLE_YYABORT;
4977
4378
           }
4978
4379
           /* SHOW COLUMNS FROM table_name */
4979
4380
        | COLUMNS from_or_in table_ident opt_db show_wild
4980
 
          {
4981
 
             LEX *lex= Lex;
4982
 
             Session *session= YYSession;
4983
 
             statement::Show *select;
4984
 
 
4985
 
             lex->sql_command= SQLCOM_SELECT;
4986
 
 
4987
 
             select= new(std::nothrow) statement::Show(session);
4988
 
 
4989
 
             lex->statement= select;
4990
 
 
4991
 
             if (lex->statement == NULL)
4992
 
               DRIZZLE_YYABORT;
4993
 
 
4994
 
             if ($4)
4995
 
              select->setShowPredicate($4, $3->table.str);
4996
 
             else if ($3->db.str)
4997
 
              select->setShowPredicate($3->db.str, $3->table.str);
4998
 
             else
4999
 
              select->setShowPredicate(session->db, $3->table.str);
5000
 
 
5001
 
             {
5002
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5003
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5004
 
               {
5005
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5006
 
                            select->getShowSchema().c_str(), 
5007
 
                            $3->table.str);
5008
 
               }
5009
 
             }
5010
 
 
5011
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5012
 
               DRIZZLE_YYABORT;
5013
 
 
5014
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5015
 
                                                           context,
5016
 
                                                           NULL, NULL, "*")))
5017
 
               DRIZZLE_YYABORT;
5018
 
             (session->lex->current_select->with_wild)++;
5019
 
 
5020
 
          }
 
4381
           {
 
4382
             if (not show::buildColumns(YYSession, $4, $3))
 
4383
               DRIZZLE_YYABORT;
 
4384
           }
5021
4385
          /* SHOW INDEXES from table */
5022
4386
        | keys_or_index from_or_in table_ident opt_db where_clause
5023
 
          {
5024
 
             LEX *lex= Lex;
5025
 
             Session *session= YYSession;
5026
 
             statement::Show *select;
5027
 
 
5028
 
             lex->sql_command= SQLCOM_SELECT;
5029
 
 
5030
 
             select= new(std::nothrow) statement::Show(session);
5031
 
 
5032
 
             lex->statement= select;
5033
 
 
5034
 
             if (lex->statement == NULL)
5035
 
               DRIZZLE_YYABORT;
5036
 
 
5037
 
             if ($4)
5038
 
              select->setShowPredicate($4, $3->table.str);
5039
 
             else if ($3->db.str)
5040
 
              select->setShowPredicate($3->db.str, $3->table.str);
5041
 
             else
5042
 
              select->setShowPredicate(session->db, $3->table.str);
5043
 
 
5044
 
             {
5045
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5046
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5047
 
               {
5048
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5049
 
                            select->getShowSchema().c_str(), 
5050
 
                            $3->table.str);
5051
 
               }
5052
 
             }
5053
 
 
5054
 
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
5055
 
               DRIZZLE_YYABORT;
5056
 
 
5057
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5058
 
                                                           context,
5059
 
                                                           NULL, NULL, "*")))
5060
 
               DRIZZLE_YYABORT;
5061
 
             (session->lex->current_select->with_wild)++;
5062
 
          }
 
4387
           {
 
4388
             if (not show::buildIndex(YYSession, $4, $3))
 
4389
               DRIZZLE_YYABORT;
 
4390
           }
5063
4391
        | COUNT_SYM '(' '*' ')' WARNINGS
5064
4392
          {
5065
 
            (void) create_select_for_variable("warning_count");
5066
 
            LEX *lex= Lex;
5067
 
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5068
 
            if (lex->statement == NULL)
5069
 
              DRIZZLE_YYABORT;
 
4393
            show::buildSelectWarning(YYSession);
5070
4394
          }
5071
4395
        | COUNT_SYM '(' '*' ')' ERRORS
5072
4396
          {
5073
 
            (void) create_select_for_variable("error_count");
5074
 
            LEX *lex= Lex;
5075
 
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5076
 
            if (lex->statement == NULL)
5077
 
              DRIZZLE_YYABORT;
 
4397
            show::buildSelectError(YYSession);
5078
4398
          }
5079
4399
        | WARNINGS opt_limit_clause_init
5080
4400
          {
5081
 
            Lex->sql_command = SQLCOM_SHOW_WARNS;
5082
 
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5083
 
            if (Lex->statement == NULL)
5084
 
              DRIZZLE_YYABORT;
 
4401
            show::buildWarnings(YYSession);
5085
4402
          }
5086
4403
        | ERRORS opt_limit_clause_init
5087
4404
          {
5088
 
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
5089
 
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5090
 
            if (Lex->statement == NULL)
5091
 
              DRIZZLE_YYABORT;
 
4405
            show::buildErrors(YYSession);
5092
4406
          }
5093
4407
        | opt_var_type STATUS_SYM show_wild
5094
 
           {
5095
 
             LEX *lex= Lex;
5096
 
             lex->sql_command= SQLCOM_SELECT;
5097
 
             lex->statement=
5098
 
               new(std::nothrow) statement::Show(YYSession);
5099
 
             if (lex->statement == NULL)
5100
 
               DRIZZLE_YYABORT;
5101
 
 
5102
 
             Session *session= YYSession;
5103
 
 
5104
 
             if ($1 == OPT_GLOBAL)
5105
 
             {
5106
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5107
 
                 DRIZZLE_YYABORT;
5108
 
             }
5109
 
             else
5110
 
             {
5111
 
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5112
 
                 DRIZZLE_YYABORT;
5113
 
             }
5114
 
 
5115
 
             std::string key("Variable_name");
5116
 
             std::string value("Value");
5117
 
 
5118
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5119
 
             my_field->is_autogenerated_name= false;
5120
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5121
 
 
5122
 
             if (session->add_item_to_list(my_field))
5123
 
               DRIZZLE_YYABORT;
5124
 
 
5125
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5126
 
             my_field->is_autogenerated_name= false;
5127
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5128
 
 
5129
 
             if (session->add_item_to_list(my_field))
5130
 
               DRIZZLE_YYABORT;
5131
 
           }
 
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
          }
5132
4417
        | CREATE TABLE_SYM table_ident
5133
 
           {
5134
 
             LEX *lex= Lex;
5135
 
             lex->sql_command= SQLCOM_SELECT;
5136
 
             statement::Show *select=
5137
 
               new(std::nothrow) statement::Show(YYSession);
5138
 
 
5139
 
             lex->statement= select;
5140
 
 
5141
 
             if (lex->statement == NULL)
5142
 
               DRIZZLE_YYABORT;
5143
 
 
5144
 
             Session *session= YYSession;
5145
 
 
5146
 
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5147
 
               DRIZZLE_YYABORT;
5148
 
 
5149
 
             if ($3->db.str)
5150
 
              select->setShowPredicate($3->db.str, $3->table.str);
5151
 
             else
5152
 
              select->setShowPredicate(session->db, $3->table.str);
5153
 
 
5154
 
             std::string key("Table");
5155
 
             std::string value("Create Table");
5156
 
 
5157
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5158
 
             my_field->is_autogenerated_name= false;
5159
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5160
 
 
5161
 
             if (session->add_item_to_list(my_field))
5162
 
               DRIZZLE_YYABORT;
5163
 
 
5164
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5165
 
             my_field->is_autogenerated_name= false;
5166
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5167
 
 
5168
 
             if (session->add_item_to_list(my_field))
5169
 
               DRIZZLE_YYABORT;
5170
 
           }
 
4418
          {
 
4419
            if (not show::buildCreateTable(YYSession, $3))
 
4420
              DRIZZLE_YYABORT;
 
4421
          }
5171
4422
        | PROCESSLIST_SYM
5172
4423
          {
5173
 
           {
5174
 
             LEX *lex= Lex;
5175
 
             lex->sql_command= SQLCOM_SELECT;
5176
 
             lex->statement=
5177
 
               new(std::nothrow) statement::Show(YYSession);
5178
 
             if (lex->statement == NULL)
5179
 
               DRIZZLE_YYABORT;
5180
 
 
5181
 
             Session *session= YYSession;
5182
 
 
5183
 
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5184
 
               DRIZZLE_YYABORT;
5185
 
 
5186
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5187
 
                                                           context,
5188
 
                                                           NULL, NULL, "*")))
5189
 
               DRIZZLE_YYABORT;
5190
 
             (session->lex->current_select->with_wild)++;
5191
 
           }
 
4424
            if (not show::buildProcesslist(YYSession))
 
4425
              DRIZZLE_YYABORT;
5192
4426
          }
5193
4427
        | opt_var_type  VARIABLES show_wild
5194
 
           {
5195
 
             LEX *lex= Lex;
5196
 
             lex->sql_command= SQLCOM_SELECT;
5197
 
             lex->statement=
5198
 
               new(std::nothrow) statement::Show(YYSession);
5199
 
             if (lex->statement == NULL)
5200
 
               DRIZZLE_YYABORT;
5201
 
 
5202
 
             Session *session= YYSession;
5203
 
 
5204
 
             if ($1 == OPT_GLOBAL)
5205
 
             {
5206
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5207
 
                 DRIZZLE_YYABORT;
5208
 
             }
5209
 
             else
5210
 
             {
5211
 
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5212
 
                 DRIZZLE_YYABORT;
5213
 
             }
5214
 
 
5215
 
             std::string key("Variable_name");
5216
 
             std::string value("Value");
5217
 
 
5218
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5219
 
             my_field->is_autogenerated_name= false;
5220
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5221
 
 
5222
 
             if (session->add_item_to_list(my_field))
5223
 
               DRIZZLE_YYABORT;
5224
 
 
5225
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5226
 
             my_field->is_autogenerated_name= false;
5227
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5228
 
 
5229
 
             if (session->add_item_to_list(my_field))
5230
 
               DRIZZLE_YYABORT;
5231
 
           }
 
4428
          {
 
4429
            if (not show::buildVariables(YYSession, $1))
 
4430
              DRIZZLE_YYABORT;
 
4431
          }
5232
4432
        | CREATE DATABASE opt_if_not_exists ident
5233
 
           {
5234
 
             LEX *lex= Lex;
5235
 
             lex->sql_command= SQLCOM_SELECT;
5236
 
             statement::Show *select=
5237
 
               new(std::nothrow) statement::Show(YYSession);
5238
 
 
5239
 
             lex->statement= select;
5240
 
 
5241
 
             if (lex->statement == NULL)
5242
 
               DRIZZLE_YYABORT;
5243
 
 
5244
 
             Session *session= YYSession;
5245
 
 
5246
 
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5247
 
               DRIZZLE_YYABORT;
5248
 
 
5249
 
             if ($4.str)
5250
 
              select->setShowPredicate($4.str);
5251
 
             else
5252
 
              select->setShowPredicate(session->db);
5253
 
 
5254
 
             std::string key("Database");
5255
 
             std::string value("Create Database");
5256
 
 
5257
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5258
 
             my_field->is_autogenerated_name= false;
5259
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5260
 
 
5261
 
             if (session->add_item_to_list(my_field))
5262
 
               DRIZZLE_YYABORT;
5263
 
 
5264
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5265
 
             my_field->is_autogenerated_name= false;
5266
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5267
 
 
5268
 
             if (session->add_item_to_list(my_field))
5269
 
               DRIZZLE_YYABORT;
5270
 
           }
 
4433
          {
 
4434
            if (not show::buildCreateSchema(YYSession, $4))
 
4435
              DRIZZLE_YYABORT;
 
4436
          }
5271
4437
 
5272
4438
opt_db:
5273
4439
          /* empty */  { $$= 0; }
5300
4466
describe:
5301
4467
          describe_command table_ident
5302
4468
          {
5303
 
            Session *session= YYSession;
5304
 
            statement::Show *select;
5305
 
            LEX *lex= Lex;
5306
 
            lex->lock_option= TL_READ;
5307
 
            mysql_init_select(lex);
5308
 
            lex->current_select->parsing_place= SELECT_LIST;
5309
 
            lex->sql_command= SQLCOM_SELECT;
5310
 
            select= new(std::nothrow) statement::Show(session);
5311
 
            lex->statement= select;
5312
 
            if (lex->statement == NULL)
 
4469
            if (not show::buildDescribe(YYSession, $2))
 
4470
            {
5313
4471
              DRIZZLE_YYABORT;
5314
 
            lex->select_lex.db= 0;
5315
 
 
5316
 
             if ($2->db.str)
5317
 
              select->setShowPredicate($2->db.str, $2->table.str);
5318
 
             else
5319
 
              select->setShowPredicate(session->db, $2->table.str);
5320
 
 
5321
 
             {
5322
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
5323
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5324
 
               {
5325
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5326
 
                            select->getShowSchema().c_str(), 
5327
 
                            $2->table.str);
5328
 
               }
5329
 
             }
5330
 
 
5331
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5332
 
               DRIZZLE_YYABORT;
5333
 
 
5334
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5335
 
                                                           context,
5336
 
                                                           NULL, NULL, "*")))
5337
 
               DRIZZLE_YYABORT;
5338
 
             (session->lex->current_select->with_wild)++;
5339
 
 
 
4472
            }
5340
4473
          }
5341
4474
          opt_describe_column {}
5342
4475
        | describe_command opt_extended_describe
5343
4476
          { Lex->describe|= DESCRIBE_NORMAL; }
5344
4477
          select
5345
4478
          {
5346
 
            LEX *lex=Lex;
5347
 
            lex->select_lex.options|= SELECT_DESCRIBE;
 
4479
            Lex->select_lex.options|= SELECT_DESCRIBE;
5348
4480
          }
5349
4481
        ;
5350
4482
 
5375
4507
flush:
5376
4508
          FLUSH_SYM
5377
4509
          {
5378
 
            LEX *lex=Lex;
5379
 
            lex->sql_command= SQLCOM_FLUSH;
5380
 
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
5381
 
            if (lex->statement == NULL)
5382
 
              DRIZZLE_YYABORT;
5383
 
            lex->type= 0;
 
4510
            Lex->statement= new statement::Flush(YYSession);
5384
4511
          }
5385
4512
          flush_options
5386
4513
          {}
5430
4557
kill:
5431
4558
          KILL_SYM kill_option expr
5432
4559
          {
5433
 
            LEX *lex=Lex;
5434
 
            lex->value_list.empty();
5435
 
            lex->value_list.push_front($3);
5436
 
            lex->sql_command= SQLCOM_KILL;
5437
 
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
5438
 
            if (lex->statement == NULL)
5439
 
              DRIZZLE_YYABORT;
 
4560
            Lex->statement= new statement::Kill(YYSession, $3, $2);
5440
4561
          }
5441
4562
        ;
5442
4563
 
5443
4564
kill_option:
5444
 
          /* empty */ { Lex->type= 0; }
5445
 
        | CONNECTION_SYM { Lex->type= 0; }
5446
 
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
 
4565
          /* empty */ { $$= false; }
 
4566
        | CONNECTION_SYM { $$= false; }
 
4567
        | QUERY_SYM      { $$= true; }
5447
4568
        ;
5448
4569
 
5449
4570
/* change database */
5450
4571
 
5451
4572
use:
5452
 
          USE_SYM ident
 
4573
          USE_SYM schema_name
5453
4574
          {
5454
 
            LEX *lex=Lex;
5455
 
            lex->sql_command=SQLCOM_CHANGE_DB;
5456
 
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
5457
 
            if (lex->statement == NULL)
5458
 
              DRIZZLE_YYABORT;
5459
 
            lex->select_lex.db= $2.str;
 
4575
            Lex->statement= new statement::ChangeSchema(YYSession);
 
4576
            Lex->select_lex.db= $2.str;
5460
4577
          }
5461
4578
        ;
5462
4579
 
5465
4582
load:
5466
4583
          LOAD data_file
5467
4584
          {
5468
 
            Session *session= YYSession;
5469
 
            LEX *lex= session->lex;
5470
 
 
5471
 
            lex->sql_command= SQLCOM_LOAD;
5472
 
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
5473
 
            lex->statement= statement;
5474
 
            if (lex->statement == NULL)
5475
 
              DRIZZLE_YYABORT;
5476
 
 
5477
 
            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;
5478
4589
            statement->fname_start= lip->get_ptr();
5479
4590
          }
5480
4591
          load_data_lock INFILE TEXT_STRING_filesystem
5481
4592
          {
5482
 
            LEX *lex=Lex;
5483
 
            lex->lock_option= $4;
5484
 
            lex->duplicates= DUP_ERROR;
5485
 
            lex->ignore= 0;
5486
 
            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)))
5487
4597
              DRIZZLE_YYABORT;
5488
4598
          }
5489
4599
          opt_duplicate INTO
5490
4600
          {
5491
 
            Session *session= YYSession;
5492
 
            Lex_input_stream *lip= session->m_lip;
 
4601
            Lex_input_stream *lip= YYSession->m_lip;
5493
4602
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
5494
4603
          }
5495
4604
          TABLE_SYM table_ident
5496
4605
          {
5497
 
            LEX *lex=Lex;
5498
4606
            if (!Lex->current_select->add_table_to_list(YYSession,
5499
4607
                    $12, NULL, TL_OPTION_UPDATING,
5500
 
                    lex->lock_option))
 
4608
                    Lex->lock_option))
5501
4609
              DRIZZLE_YYABORT;
5502
 
            lex->field_list.empty();
5503
 
            lex->update_list.empty();
5504
 
            lex->value_list.empty();
 
4610
            Lex->field_list.empty();
 
4611
            Lex->update_list.empty();
 
4612
            Lex->value_list.empty();
5505
4613
          }
5506
4614
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5507
4615
          opt_load_data_set_spec
5525
4633
        | IGNORE_SYM { Lex->ignore= 1; }
5526
4634
        ;
5527
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
 
5528
4645
opt_field_term:
5529
4646
          /* empty */
5530
4647
        | COLUMNS field_term_list
5543
4660
          }
5544
4661
        | OPTIONALLY ENCLOSED BY text_string
5545
4662
          {
5546
 
            LEX *lex= Lex;
5547
 
            assert(lex->exchange != 0);
5548
 
            lex->exchange->enclosed= $4;
5549
 
            lex->exchange->opt_enclosed= 1;
 
4663
            assert(Lex->exchange != 0);
 
4664
            Lex->exchange->enclosed= $4;
 
4665
            Lex->exchange->opt_enclosed= 1;
5550
4666
          }
5551
4667
        | ENCLOSED BY text_string
5552
4668
          {
5611
4727
        ;
5612
4728
 
5613
4729
field_or_var:
5614
 
          simple_ident_nospvar {$$= $1;}
5615
 
        | '@' ident_or_text
 
4730
          simple_ident {$$= $1;}
 
4731
        | '@' user_variable_ident
5616
4732
          { $$= new Item_user_var_as_out_param($2); }
5617
4733
        ;
5618
4734
 
5619
4735
opt_load_data_set_spec:
5620
4736
          /* empty */ {}
5621
 
        | SET insert_update_list {}
 
4737
        | SET_SYM insert_update_list {}
5622
4738
        ;
5623
4739
 
5624
4740
/* Common definitions */
5626
4742
text_literal:
5627
4743
        TEXT_STRING_literal
5628
4744
        {
5629
 
          Session *session= YYSession;
5630
 
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
 
4745
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
5631
4746
        }
5632
4747
        | text_literal TEXT_STRING_literal
5633
4748
          {
5683
4798
            $$ = new Item_null();
5684
4799
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5685
4800
          }
5686
 
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5687
 
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
 
4801
        | FALSE_SYM { $$= new drizzled::item::False(); }
 
4802
        | TRUE_SYM { $$= new drizzled::item::True(); }
5688
4803
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
5689
4804
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
5690
4805
        | DATE_SYM text_literal { $$ = $2; }
5727
4842
**********************************************************************/
5728
4843
 
5729
4844
insert_ident:
5730
 
          simple_ident_nospvar { $$=$1; }
 
4845
          simple_ident { $$=$1; }
5731
4846
        | table_wild { $$=$1; }
5732
4847
        ;
5733
4848
 
5734
4849
table_wild:
5735
4850
          ident '.' '*'
5736
4851
          {
5737
 
            Select_Lex *sel= Lex->current_select;
5738
 
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
5739
 
            sel->with_wild++;
 
4852
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
5740
4853
          }
5741
4854
        | ident '.' ident '.' '*'
5742
4855
          {
5743
 
            Select_Lex *sel= Lex->current_select;
5744
 
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
5745
 
            sel->with_wild++;
 
4856
            $$= parser::buildTableWild(Lex, $1, $3);
5746
4857
          }
5747
4858
        ;
5748
4859
 
5753
4864
simple_ident:
5754
4865
          ident
5755
4866
          {
5756
 
            {
5757
 
              Select_Lex *sel=Lex->current_select;
5758
 
              $$= (sel->parsing_place != IN_HAVING ||
5759
 
                  sel->get_in_sum_expr() > 0) ?
5760
 
                  (Item*) new Item_field(Lex->current_context(),
5761
 
                                         (const char *)NULL, NULL, $1.str) :
5762
 
                  (Item*) new Item_ref(Lex->current_context(),
5763
 
                                       (const char *)NULL, NULL, $1.str);
5764
 
            }
5765
 
          }
5766
 
        | simple_ident_q { $$= $1; }
5767
 
        ;
5768
 
 
5769
 
simple_ident_nospvar:
5770
 
          ident
5771
 
          {
5772
 
            Select_Lex *sel=Lex->current_select;
5773
 
            $$= (sel->parsing_place != IN_HAVING ||
5774
 
                sel->get_in_sum_expr() > 0) ?
5775
 
                (Item*) new Item_field(Lex->current_context(),
5776
 
                                       (const char *)NULL, NULL, $1.str) :
5777
 
                (Item*) new Item_ref(Lex->current_context(),
5778
 
                                     (const char *)NULL, NULL, $1.str);
 
4867
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
5779
4868
          }
5780
4869
        | simple_ident_q { $$= $1; }
5781
4870
        ;
5783
4872
simple_ident_q:
5784
4873
          ident '.' ident
5785
4874
          {
5786
 
            Session *session= YYSession;
5787
 
            LEX *lex= session->lex;
5788
 
 
5789
 
            {
5790
 
              Select_Lex *sel= lex->current_select;
5791
 
              if (sel->no_table_names_allowed)
5792
 
              {
5793
 
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5794
 
                         MYF(0), $1.str, session->where);
5795
 
              }
5796
 
              $$= (sel->parsing_place != IN_HAVING ||
5797
 
                  sel->get_in_sum_expr() > 0) ?
5798
 
                  (Item*) new Item_field(Lex->current_context(),
5799
 
                                         (const char *)NULL, $1.str, $3.str) :
5800
 
                  (Item*) new Item_ref(Lex->current_context(),
5801
 
                                       (const char *)NULL, $1.str, $3.str);
5802
 
            }
 
4875
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
5803
4876
          }
5804
4877
        | '.' ident '.' ident
5805
4878
          {
5806
 
            Session *session= YYSession;
5807
 
            LEX *lex= session->lex;
5808
 
            Select_Lex *sel= lex->current_select;
5809
 
            if (sel->no_table_names_allowed)
5810
 
            {
5811
 
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5812
 
                       MYF(0), $2.str, session->where);
5813
 
            }
5814
 
            $$= (sel->parsing_place != IN_HAVING ||
5815
 
                sel->get_in_sum_expr() > 0) ?
5816
 
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
5817
 
                (Item*) new Item_ref(Lex->current_context(),
5818
 
                                     (const char *)NULL, $2.str, $4.str);
 
4879
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
5819
4880
          }
5820
4881
        | ident '.' ident '.' ident
5821
4882
          {
5822
 
            Session *session= YYSession;
5823
 
            LEX *lex= session->lex;
5824
 
            Select_Lex *sel= lex->current_select;
5825
 
            if (sel->no_table_names_allowed)
5826
 
            {
5827
 
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5828
 
                       MYF(0), $3.str, session->where);
5829
 
            }
5830
 
            $$= (sel->parsing_place != IN_HAVING ||
5831
 
                sel->get_in_sum_expr() > 0) ?
5832
 
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
5833
 
                                       $5.str) :
5834
 
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
5835
 
                                     $5.str);
 
4883
            $$= parser::buildIdent(Lex, $1, $3, $5);
5836
4884
          }
5837
4885
        ;
5838
4886
 
5839
4887
field_ident:
5840
 
          ident { $$=$1;}
 
4888
          ident 
 
4889
          {
 
4890
            $$=$1;
 
4891
          }
5841
4892
        | ident '.' ident '.' ident
5842
4893
          {
5843
 
            TableList *table=
5844
 
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5845
 
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
5846
 
            {
5847
 
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5848
 
              DRIZZLE_YYABORT;
5849
 
            }
5850
 
            if (my_strcasecmp(table_alias_charset, $3.str,
5851
 
                              table->getTableName()))
5852
 
            {
5853
 
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
5854
 
              DRIZZLE_YYABORT;
5855
 
            }
 
4894
            if (not parser::checkFieldIdent(Lex, $1, $3))
 
4895
              DRIZZLE_YYABORT;
 
4896
 
5856
4897
            $$=$5;
5857
4898
          }
5858
4899
        | ident '.' ident
5859
4900
          {
5860
 
            TableList *table=
5861
 
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5862
 
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5863
 
            {
5864
 
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
 
4901
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
5865
4902
              DRIZZLE_YYABORT;
5866
 
            }
 
4903
 
5867
4904
            $$=$3;
5868
4905
          }
5869
 
        | '.' ident { $$=$2;} /* For Delphi */
 
4906
        | '.' ident 
 
4907
          { /* For Delphi */
 
4908
            $$=$2;
 
4909
          }
5870
4910
        ;
5871
4911
 
5872
4912
table_ident:
5873
 
          ident { $$=new Table_ident($1); }
5874
 
        | ident '.' ident { $$=new Table_ident($1,$3);}
5875
 
        | '.' 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
5876
4933
        ;
5877
4934
 
5878
4935
IDENT_sys:
5879
 
          IDENT { $$= $1; }
 
4936
          IDENT 
 
4937
          {
 
4938
            $$= $1;
 
4939
          }
5880
4940
        | IDENT_QUOTED
5881
4941
          {
5882
4942
            const CHARSET_INFO * const cs= system_charset_info;
5919
4979
          IDENT_sys    { $$=$1; }
5920
4980
        | keyword
5921
4981
          {
5922
 
            Session *session= YYSession;
5923
 
            $$.str= session->strmake($1.str, $1.length);
 
4982
            $$.str= YYSession->strmake($1.str, $1.length);
5924
4983
            $$.length= $1.length;
5925
4984
          }
5926
4985
        ;
5927
4986
 
5928
4987
ident_or_text:
5929
 
          ident           { $$=$1;}
5930
 
        | TEXT_STRING_sys { $$=$1;}
5931
 
        | 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          {}
5932
5001
        ;
5933
5002
 
5934
5003
/* Keyword that we allow for identifiers (except SP labels) */
5935
5004
keyword:
5936
5005
          keyword_sp            {}
5937
5006
        | BEGIN_SYM             {}
5938
 
        | BYTE_SYM              {}
5939
5007
        | CHECKSUM_SYM          {}
5940
5008
        | CLOSE_SYM             {}
5941
5009
        | COMMENT_SYM           {}
5942
5010
        | COMMIT_SYM            {}
5943
5011
        | CONTAINS_SYM          {}
5944
5012
        | DEALLOCATE_SYM        {}
 
5013
        | DO_SYM                {}
5945
5014
        | END                   {}
5946
5015
        | FLUSH_SYM             {}
5947
5016
        | NO_SYM                {}
5950
5019
        | SAVEPOINT_SYM         {}
5951
5020
        | SECURITY_SYM          {}
5952
5021
        | SERVER_SYM            {}
 
5022
        | SIGNED_SYM            {}
5953
5023
        | START_SYM             {}
5954
5024
        | STOP_SYM              {}
5955
5025
        | TRUNCATE_SYM          {}
5969
5039
        | ANY_SYM                  {}
5970
5040
        | AT_SYM                   {}
5971
5041
        | AUTO_INC                 {}
5972
 
        | AVG_ROW_LENGTH           {}
5973
5042
        | AVG_SYM                  {}
5974
5043
        | BIT_SYM                  {}
5975
5044
        | BOOL_SYM                 {}
5979
5048
        | CHAIN_SYM                {}
5980
5049
        | COALESCE                 {}
5981
5050
        | COLLATION_SYM            {}
5982
 
        | COLUMN_FORMAT_SYM        {}
5983
5051
        | COLUMNS                  {}
5984
5052
        | COMMITTED_SYM            {}
5985
5053
        | COMPACT_SYM              {}
5986
5054
        | COMPRESSED_SYM           {}
5987
5055
        | CONCURRENT               {}
5988
 
        | CONNECTION_SYM           {}
 
5056
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
5989
5057
        | CONSISTENT_SYM           {}
5990
5058
        | CUBE_SYM                 {}
5991
5059
        | DATA_SYM                 {}
5992
5060
        | DATABASES                {}
5993
 
        | DATAFILE_SYM             {}
5994
5061
        | DATETIME_SYM             {}
5995
 
        | DATE_SYM                 {}
 
5062
        | DATE_SYM                 {} /* Create conflict */
5996
5063
        | DAY_SYM                  {}
5997
5064
        | DISABLE_SYM              {}
5998
5065
        | DISCARD                  {}
6023
5090
        | KEY_BLOCK_SIZE           {}
6024
5091
        | LAST_SYM                 {}
6025
5092
        | LEVEL_SYM                {}
6026
 
        | LIST_SYM                 {}
6027
5093
        | LOCAL_SYM                {}
6028
5094
        | LOCKS_SYM                {}
6029
5095
        | LOGS_SYM                 {}
6030
 
        | MAX_ROWS                 {}
6031
 
        | MAX_SIZE_SYM             {}
6032
5096
        | MAX_VALUE_SYM            {}
6033
5097
        | MEDIUM_SYM               {}
6034
5098
        | MERGE_SYM                {}
6035
5099
        | MICROSECOND_SYM          {}
6036
5100
        | MINUTE_SYM               {}
6037
 
        | MIN_ROWS                 {}
6038
5101
        | MODIFY_SYM               {}
6039
5102
        | MODE_SYM                 {}
6040
5103
        | MONTH_SYM                {}
6049
5112
        | ONE_SHOT_SYM             {}
6050
5113
        | ONE_SYM                  {}
6051
5114
        | ONLINE_SYM               {}
6052
 
        | PAGE_SYM                 {}
6053
5115
        | PARTIAL                  {}
6054
 
        | PHASE_SYM                {}
6055
5116
        | PREV_SYM                 {}
6056
5117
        | PROCESS                  {}
6057
5118
        | PROCESSLIST_SYM          {}
6058
5119
        | QUARTER_SYM              {}
6059
 
        | QUERY_SYM                {}
6060
 
        | READ_ONLY_SYM            {}
 
5120
        | QUERY_SYM                {} // Causes conflict
6061
5121
        | REDUNDANT_SYM            {}
6062
5122
        | REPEATABLE_SYM           {}
6063
5123
        | RETURNS_SYM              {}
6064
 
        | REVERSE_SYM              {}
6065
5124
        | ROLLUP_SYM               {}
6066
5125
        | ROUTINE_SYM              {}
6067
5126
        | ROWS_SYM                 {}
6074
5133
        | SIMPLE_SYM               {}
6075
5134
        | SHARE_SYM                {}
6076
5135
        | SNAPSHOT_SYM             {}
6077
 
        | SQL_BUFFER_RESULT        {}
6078
5136
        | STATUS_SYM               {}
6079
 
        | STORAGE_SYM              {}
6080
5137
        | STRING_SYM               {}
6081
5138
        | SUBDATE_SYM              {}
6082
5139
        | SUBJECT_SYM              {}
6083
5140
        | SUSPEND_SYM              {}
6084
 
        | SWAPS_SYM                {}
6085
 
        | SWITCHES_SYM             {}
6086
5141
        | TABLES                   {}
6087
5142
        | TABLESPACE               {}
6088
5143
        | TEMPORARY_SYM            {}
6089
5144
        | TEXT_SYM                 {}
6090
5145
        | TRANSACTION_SYM          {}
6091
 
        | TIMESTAMP_SYM            {}
 
5146
        | TIME_SYM                 {}
6092
5147
        | TIMESTAMP_ADD            {}
6093
5148
        | TIMESTAMP_DIFF           {}
6094
 
        | TYPES_SYM                {}
6095
5149
        | TYPE_SYM                 {}
6096
5150
        | UNCOMMITTED_SYM          {}
6097
5151
        | UNDOFILE_SYM             {}
6098
5152
        | UNKNOWN_SYM              {}
 
5153
        | UUID_SYM                 {}
6099
5154
        | USER                     {}
6100
5155
        | VARIABLES                {}
6101
5156
        | VALUE_SYM                {}
6108
5163
/* Option functions */
6109
5164
 
6110
5165
set:
6111
 
          SET opt_option
 
5166
          SET_SYM opt_option
6112
5167
          {
6113
 
            LEX *lex=Lex;
6114
 
            lex->sql_command= SQLCOM_SET_OPTION;
6115
 
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
6116
 
            lex->statement= statement;
6117
 
            if (lex->statement == NULL)
6118
 
              DRIZZLE_YYABORT;
6119
 
            mysql_init_select(lex);
6120
 
            lex->option_type=OPT_SESSION;
6121
 
            lex->var_list.empty();
 
5168
            Lex->statement= new statement::SetOption(YYSession);
6122
5169
          }
6123
5170
          option_value_list
6124
5171
          {}
6135
5182
        ;
6136
5183
 
6137
5184
option_type_value:
6138
 
          {
6139
 
          }
 
5185
          { }
6140
5186
          ext_option_value
6141
 
          {
6142
 
          }
 
5187
          { }
6143
5188
        ;
6144
5189
 
6145
5190
option_type:
6176
5221
sys_option_value:
6177
5222
          option_type internal_variable_name equal set_expr_or_default
6178
5223
          {
6179
 
            LEX *lex=Lex;
6180
 
 
6181
5224
            if ($2.var)
6182
5225
            { /* System variable */
6183
5226
              if ($1)
6184
 
                lex->option_type= $1;
6185
 
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
6186
 
                                      &$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)));
6187
5231
            }
6188
5232
          }
6189
5233
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
6190
5234
          {
6191
 
            LEX *lex=Lex;
6192
 
            lex->option_type= $1;
6193
 
            lex->var_list.push_back(new set_var(lex->option_type,
6194
 
                                                find_sys_var(YYSession, "tx_isolation"),
6195
 
                                                &null_lex_str,
6196
 
                                                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))));
6197
5241
          }
6198
5242
        ;
6199
5243
 
6200
5244
option_value:
6201
 
          '@' ident_or_text equal expr
 
5245
          '@' user_variable_ident equal expr
6202
5246
          {
6203
 
            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))));
6204
5248
          }
6205
5249
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6206
5250
          {
6207
 
            LEX *lex=Lex;
6208
 
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6209
 
          }
 
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; }
6210
5268
        ;
6211
5269
 
6212
5270
internal_variable_name:
6213
 
          ident
 
5271
          internal_variable_ident
6214
5272
          {
6215
 
            Session *session= YYSession;
6216
 
 
6217
5273
            /* We have to lookup here since local vars can shadow sysvars */
6218
5274
            {
6219
5275
              /* Not an SP local variable */
6220
 
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
 
5276
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
6221
5277
              if (!tmp)
6222
5278
                DRIZZLE_YYABORT;
6223
5279
              $$.var= tmp;
6249
5305
unlock:
6250
5306
          UNLOCK_SYM
6251
5307
          {
6252
 
            LEX *lex= Lex;
6253
 
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
6254
 
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
6255
 
            if (lex->statement == NULL)
6256
 
              DRIZZLE_YYABORT;
 
5308
            Lex->statement= new statement::UnlockTables(YYSession);
6257
5309
          }
6258
5310
          table_or_tables
6259
5311
          {}
6262
5314
begin:
6263
5315
          BEGIN_SYM
6264
5316
          {
6265
 
            LEX *lex=Lex;
6266
 
            lex->sql_command = SQLCOM_BEGIN;
6267
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
6268
 
            if (lex->statement == NULL)
6269
 
              DRIZZLE_YYABORT;
 
5317
            Lex->statement= new statement::StartTransaction(YYSession);
6270
5318
          }
6271
5319
          opt_work {}
6272
5320
        ;
6298
5346
commit:
6299
5347
          COMMIT_SYM opt_work opt_chain opt_release
6300
5348
          {
6301
 
            LEX *lex=Lex;
6302
 
            lex->sql_command= SQLCOM_COMMIT;
6303
 
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
6304
 
            lex->statement= statement;
6305
 
            if (lex->statement == NULL)
6306
 
              DRIZZLE_YYABORT;
6307
 
            statement->tx_chain= $3;
6308
 
            statement->tx_release= $4;
 
5349
            Lex->statement= new statement::Commit(YYSession, $3, $4);
6309
5350
          }
6310
5351
        ;
6311
5352
 
6312
5353
rollback:
6313
5354
          ROLLBACK_SYM opt_work opt_chain opt_release
6314
5355
          {
6315
 
            LEX *lex=Lex;
6316
 
            lex->sql_command= SQLCOM_ROLLBACK;
6317
 
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
6318
 
            lex->statement= statement;
6319
 
            if (lex->statement == NULL)
6320
 
              DRIZZLE_YYABORT;
6321
 
            statement->tx_chain= $3;
6322
 
            statement->tx_release= $4;
 
5356
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
6323
5357
          }
6324
 
        | ROLLBACK_SYM opt_work
6325
 
          TO_SYM opt_savepoint ident
 
5358
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
6326
5359
          {
6327
 
            LEX *lex=Lex;
6328
 
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
6329
 
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
6330
 
            if (lex->statement == NULL)
6331
 
              DRIZZLE_YYABORT;
6332
 
            lex->ident= $5;
 
5360
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
6333
5361
          }
6334
5362
        ;
6335
5363
 
6336
5364
savepoint:
6337
 
          SAVEPOINT_SYM ident
 
5365
          SAVEPOINT_SYM savepoint_ident
6338
5366
          {
6339
 
            LEX *lex=Lex;
6340
 
            lex->sql_command= SQLCOM_SAVEPOINT;
6341
 
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
6342
 
            if (lex->statement == NULL)
6343
 
              DRIZZLE_YYABORT;
6344
 
            lex->ident= $2;
 
5367
            Lex->statement= new statement::Savepoint(YYSession, $2);
6345
5368
          }
6346
5369
        ;
6347
5370
 
6348
5371
release:
6349
 
          RELEASE_SYM SAVEPOINT_SYM ident
 
5372
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
6350
5373
          {
6351
 
            LEX *lex=Lex;
6352
 
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
6353
 
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
6354
 
            if (lex->statement == NULL)
6355
 
              DRIZZLE_YYABORT;
6356
 
            lex->ident= $3;
 
5374
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
6357
5375
          }
6358
5376
        ;
6359
5377
 
 
5378
savepoint_ident:
 
5379
               IDENT_sys
 
5380
               ;
 
5381
 
6360
5382
/*
6361
5383
   UNIONS : glue selects together
6362
5384
*/
6370
5392
union_list:
6371
5393
          UNION_SYM union_option
6372
5394
          {
6373
 
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
 
5395
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
6374
5396
              DRIZZLE_YYABORT;
6375
5397
          }
6376
5398
          select_init
6391
5413
 
6392
5414
union_order_or_limit:
6393
5415
          {
6394
 
            Session *session= YYSession;
6395
 
            LEX *lex= session->lex;
6396
 
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6397
 
            Select_Lex *sel= lex->current_select;
 
5416
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
5417
            Select_Lex *sel= Lex->current_select;
6398
5418
            Select_Lex_Unit *unit= sel->master_unit();
6399
5419
            Select_Lex *fake= unit->fake_select_lex;
6400
5420
            if (fake)
6401
5421
            {
6402
5422
              unit->global_parameters= fake;
6403
5423
              fake->no_table_names_allowed= 1;
6404
 
              lex->current_select= fake;
 
5424
              Lex->current_select= fake;
6405
5425
            }
6406
 
            session->where= "global ORDER clause";
 
5426
            YYSession->setWhere("global ORDER clause");
6407
5427
          }
6408
5428
          order_or_limit
6409
5429
          {
6410
 
            Session *session= YYSession;
6411
 
            session->lex->current_select->no_table_names_allowed= 0;
6412
 
            session->where= "";
 
5430
            YYSession->lex->current_select->no_table_names_allowed= 0;
 
5431
            YYSession->setWhere("");
6413
5432
          }
6414
5433
        ;
6415
5434
 
6440
5459
        | query_expression_body
6441
5460
          UNION_SYM union_option
6442
5461
          {
6443
 
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
 
5462
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
6444
5463
              DRIZZLE_YYABORT;
6445
5464
          }
6446
5465
          query_specification
6460
5479
 
6461
5480
subselect_start:
6462
5481
          {
6463
 
            LEX *lex=Lex;
6464
 
            if (!lex->expr_allows_subselect)
 
5482
            if (not Lex->expr_allows_subselect)
6465
5483
            {
6466
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
6467
 
              my_parse_error(&pass);
 
5484
              parser::my_parse_error(YYSession->m_lip);
6468
5485
              DRIZZLE_YYABORT;
6469
5486
            }
6470
5487
            /*
6474
5491
              (SELECT .. ) UNION ...  becomes
6475
5492
              SELECT * FROM ((SELECT ...) UNION ...)
6476
5493
            */
6477
 
            if (mysql_new_select(Lex, 1))
 
5494
            if (new_select(Lex, 1))
6478
5495
              DRIZZLE_YYABORT;
6479
5496
          }
6480
5497
        ;
6481
5498
 
6482
5499
subselect_end:
6483
5500
          {
6484
 
            LEX *lex=Lex;
6485
 
            lex->pop_context();
6486
 
            Select_Lex *child= lex->current_select;
6487
 
            lex->current_select = lex->current_select->return_after_parsing();
6488
 
            lex->nest_level--;
6489
 
            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;
6490
5506
            /*
6491
5507
              A subselect can add fields to an outer select. Reserve space for
6492
5508
              them.
6493
5509
            */
6494
 
            lex->current_select->select_n_where_fields+=
 
5510
            Lex->current_select->select_n_where_fields+=
6495
5511
            child->select_n_where_fields;
6496
5512
          }
6497
5513
        ;