~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2010-12-25 00:28:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2031.
  • Revision ID: brian@tangent.org-20101225002849-g73mg6ihulajis0o
First pass in refactoring of the name of my_decimal.

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
 
    unsigned long val= *(F);                          \
 
48
    ulong 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);\
63
64
    YYABORT;                                  \
64
65
  } while (0)
65
66
 
66
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
67
68
  if (!(A))                             \
68
69
  {                                     \
69
 
    parser::my_parse_error(YYSession->m_lip);\
 
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    my_parse_error(&pass);\
70
72
    DRIZZLE_YYABORT;                      \
71
73
  }
72
74
 
80
82
class Item;
81
83
class Item_num;
82
84
 
83
 
namespace item
84
 
{
85
 
class Boolean;
86
 
class True;
87
 
class False;
88
 
}
89
 
 
 
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
}
90
126
 
91
127
/**
92
128
  @brief Bison callback to report a syntax/OOM error
103
139
 
104
140
  This function is not for use in semantic actions and is internal to
105
141
  the parser, as it performs some pre-return cleanup.
106
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
142
  In semantic actions, please use my_parse_error or my_error to
107
143
  push an error into the error stack and DRIZZLE_YYABORT
108
144
  to abort from the parser.
109
145
*/
110
146
 
111
147
static void DRIZZLEerror(const char *s)
112
148
{
113
 
  parser::errorOn(s);
 
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 (new_select(lex, 0))
 
272
    return true;
 
273
  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;
114
333
}
115
334
 
116
335
} /* namespace drizzled; */
118
337
using namespace drizzled;
119
338
%}
120
339
%union {
121
 
  bool boolean;
122
340
  int  num;
123
 
  unsigned long ulong_num;
 
341
  ulong ulong_num;
124
342
  uint64_t ulonglong_number;
125
343
  int64_t longlong_number;
126
344
  drizzled::LEX_STRING lex_str;
136
354
  drizzled::Key_part_spec *key_part;
137
355
  const drizzled::plugin::Function *udf;
138
356
  drizzled::TableList *table_list;
139
 
  drizzled::enum_field_types field_val;
140
 
  drizzled::sys_var_with_base variable;
141
 
  drizzled::sql_var_t var_type;
 
357
  struct drizzled::sys_var_with_base variable;
 
358
  enum drizzled::sql_var_t var_type;
142
359
  drizzled::Key::Keytype key_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;
 
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;
147
365
  const drizzled::CHARSET_INFO *charset;
148
366
  drizzled::thr_lock_type lock_type;
149
367
  drizzled::interval_type interval, interval_time_st;
150
 
  drizzled::type::timestamp_t date_time_type;
 
368
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
151
369
  drizzled::Select_Lex *select_lex;
152
370
  drizzled::chooser_compare_func_creator boolfunc2creator;
153
 
  drizzled::st_lex *lex;
154
 
  drizzled::index_hint_type index_hint;
155
 
  drizzled::enum_filetype filetype;
156
 
  drizzled::ha_build_method build_method;
 
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;
157
375
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
158
376
  drizzled::execute_string_t execute_string;
159
377
}
161
379
%{
162
380
namespace drizzled
163
381
{
164
 
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
 
382
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
165
383
}
166
384
%}
167
385
 
168
 
%debug
169
386
%pure_parser                                    /* We have threads */
170
 
 
171
387
/*
172
 
  Currently there are 70 shift/reduce conflicts.
 
388
  Currently there are 88 shift/reduce conflicts.
173
389
  We should not introduce new conflicts any more.
174
390
*/
175
 
%expect 70
 
391
%expect 95
176
392
 
177
393
/*
178
394
   Comments for TOKENS.
207
423
%token  ASENSITIVE_SYM                /* FUTURE-USE */
208
424
%token  AT_SYM                        /* SQL-2003-R */
209
425
%token  AUTO_INC
 
426
%token  AVG_ROW_LENGTH
210
427
%token  AVG_SYM                       /* SQL-2003-N */
211
428
%token  BEFORE_SYM                    /* SQL-2003-N */
212
429
%token  BEGIN_SYM                     /* SQL-2003-R */
221
438
%token  BOTH                          /* SQL-2003-R */
222
439
%token  BTREE_SYM
223
440
%token  BY                            /* SQL-2003-R */
 
441
%token  BYTE_SYM
224
442
%token  CALL_SYM                      /* SQL-2003-R */
225
443
%token  CASCADE                       /* SQL-2003-N */
226
444
%token  CASCADED                      /* SQL-2003-R */
227
445
%token  CASE_SYM                      /* SQL-2003-R */
228
446
%token  CAST_SYM                      /* SQL-2003-R */
229
 
%token  CATALOG_SYM
230
447
%token  CHAIN_SYM                     /* SQL-2003-N */
231
448
%token  CHANGE_SYM
232
449
%token  CHAR_SYM                      /* SQL-2003-R */
249
466
%token  CONSISTENT_SYM
250
467
%token  CONSTRAINT                    /* SQL-2003-R */
251
468
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
469
%token  CONTINUE_SYM                  /* SQL-2003-R */
252
470
%token  CONVERT_SYM                   /* SQL-2003-N */
253
471
%token  COUNT_SYM                     /* SQL-2003-N */
254
472
%token  CREATE                        /* SQL-2003-R */
259
477
%token  CURSOR_SYM                    /* SQL-2003-R */
260
478
%token  DATABASE
261
479
%token  DATABASES
 
480
%token  DATAFILE_SYM
262
481
%token  DATA_SYM                      /* SQL-2003-N */
263
482
%token  DATETIME_SYM
264
483
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
282
501
%token  DISCARD
283
502
%token  DISTINCT                      /* SQL-2003-R */
284
503
%token  DIV_SYM
285
 
%token  DO_SYM
286
504
%token  DOUBLE_SYM                    /* SQL-2003-R */
287
505
%token  DROP                          /* SQL-2003-R */
288
506
%token  DUMPFILE
290
508
%token  DYNAMIC_SYM                   /* SQL-2003-R */
291
509
%token  EACH_SYM                      /* SQL-2003-R */
292
510
%token  ELSE                          /* SQL-2003-R */
 
511
%token  ELSEIF_SYM
293
512
%token  ENABLE_SYM
294
513
%token  ENCLOSED
295
514
%token  END                           /* SQL-2003-R */
303
522
%token  ESCAPED
304
523
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
524
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
 
525
%token  EXECUTE_SYM
307
526
%token  EXISTS                        /* SQL-2003-R */
308
527
%token  EXTENDED_SYM
309
528
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
529
%token  FALSE_SYM                     /* SQL-2003-R */
 
530
%token  FETCH_SYM                     /* SQL-2003-R */
 
531
%token  COLUMN_FORMAT_SYM
311
532
%token  FILE_SYM
312
533
%token  FIRST_SYM                     /* SQL-2003-N */
313
534
%token  FIXED_SYM
334
555
%token  HOUR_SYM                      /* SQL-2003-R */
335
556
%token  IDENT
336
557
%token  IDENTIFIED_SYM
337
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
338
558
%token  IDENT_QUOTED
339
559
%token  IF
340
560
%token  IGNORE_SYM
367
587
%token  LIKE                          /* SQL-2003-R */
368
588
%token  LIMIT
369
589
%token  LINES
 
590
%token  LIST_SYM
370
591
%token  LOAD
371
592
%token  LOCAL_SYM                     /* SQL-2003-R */
 
593
%token  LOCATOR_SYM                   /* SQL-2003-N */
372
594
%token  LOCKS_SYM
373
595
%token  LOCK_SYM
374
596
%token  LOGS_SYM
375
597
%token  LONG_NUM
376
598
%token  LONG_SYM
 
599
%token  LOOP_SYM
377
600
%token  LT                            /* OPERATOR */
378
601
%token  MATCH                         /* SQL-2003-R */
 
602
%token  MAX_ROWS
 
603
%token  MAX_SIZE_SYM
379
604
%token  MAX_SYM                       /* SQL-2003-N */
380
605
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
381
606
%token  MEDIUM_SYM
384
609
%token  MINUTE_MICROSECOND_SYM
385
610
%token  MINUTE_SECOND_SYM
386
611
%token  MINUTE_SYM                    /* SQL-2003-R */
 
612
%token  MIN_ROWS
387
613
%token  MIN_SYM                       /* SQL-2003-N */
388
614
%token  MODE_SYM
389
615
%token  MODIFIES_SYM                  /* SQL-2003-R */
420
646
%token  OUTER
421
647
%token  OUTFILE
422
648
%token  OUT_SYM                       /* SQL-2003-R */
 
649
%token  PAGE_SYM
423
650
%token  PARTIAL                       /* SQL-2003-N */
 
651
%token  PHASE_SYM
424
652
%token  POSITION_SYM                  /* SQL-2003-N */
425
653
%token  PRECISION                     /* SQL-2003-R */
426
654
%token  PREV_SYM
431
659
%token  QUERY_SYM
432
660
%token  RANGE_SYM                     /* SQL-2003-R */
433
661
%token  READS_SYM                     /* SQL-2003-R */
 
662
%token  READ_ONLY_SYM
434
663
%token  READ_SYM                      /* SQL-2003-N */
435
664
%token  READ_WRITE_SYM
436
665
%token  REAL                          /* SQL-2003-R */
445
674
%token  RESTRICT
446
675
%token  RETURNS_SYM                   /* SQL-2003-R */
447
676
%token  RETURN_SYM                    /* SQL-2003-R */
 
677
%token  REVERSE_SYM
448
678
%token  REVOKE                        /* SQL-2003-R */
449
679
%token  RIGHT                         /* SQL-2003-R */
450
680
%token  ROLLBACK_SYM                  /* SQL-2003-R */
464
694
%token  SERIAL_SYM
465
695
%token  SESSION_SYM                   /* SQL-2003-N */
466
696
%token  SERVER_SYM
 
697
%token  SERVER_OPTIONS
467
698
%token  SET_SYM                           /* SQL-2003-R */
468
699
%token  SET_VAR
469
700
%token  SHARE_SYM
486
717
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
487
718
%token  STD_SYM
488
719
%token  STOP_SYM
 
720
%token  STORAGE_SYM
489
721
%token  STORED_SYM
490
722
%token  STRAIGHT_JOIN
491
723
%token  STRING_SYM
494
726
%token  SUBSTRING                     /* SQL-2003-N */
495
727
%token  SUM_SYM                       /* SQL-2003-N */
496
728
%token  SUSPEND_SYM
 
729
%token  SWAPS_SYM
 
730
%token  SWITCHES_SYM
497
731
%token  SYSDATE
498
732
%token  TABLES
499
733
%token  TABLESPACE
514
748
%token  TRIM                          /* SQL-2003-N */
515
749
%token  TRUE_SYM                      /* SQL-2003-R */
516
750
%token  TRUNCATE_SYM
 
751
%token  TYPES_SYM
517
752
%token  TYPE_SYM                      /* SQL-2003-N */
518
753
%token  ULONGLONG_NUM
519
754
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
572
807
 
573
808
%type <lex_str>
574
809
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
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
 
810
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
581
811
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
582
 
        schema_name
583
 
        catalog_name
584
812
        opt_component
585
 
        engine_option_value
586
 
        savepoint_ident
587
 
        BIN_NUM TEXT_STRING_filesystem
 
813
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
588
814
        opt_constraint constraint opt_ident
589
815
 
590
816
%type <execute_string>
602
828
%type <string>
603
829
        text_string opt_gconcat_separator
604
830
 
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
 
831
%type <num>
 
832
        type int_type real_type order_dir field_def
 
833
        if_exists opt_table_options
615
834
        opt_if_not_exists
616
 
        if_exists 
617
 
        opt_temporary 
618
 
        opt_field_number_signed
619
 
 
620
 
%type <num>
621
 
        order_dir
622
 
        field_def
623
 
        opt_table_options
624
 
        all_or_any opt_distinct
 
835
        opt_temporary all_or_any opt_distinct
625
836
        union_option
626
837
        start_transaction_opts opt_chain opt_release
627
838
        union_opt select_derived_init option_type2
 
839
        opt_status
 
840
        opt_concurrent
 
841
        opt_wait
 
842
        opt_zerofill
 
843
        opt_field_number_signed
628
844
        kill_option
629
845
 
630
846
%type <m_fk_option>
647
863
        table_wild simple_expr udf_expr
648
864
        expr_or_default set_expr_or_default
649
865
        signed_literal now_or_signed_literal opt_escape
650
 
        simple_ident_q
 
866
        simple_ident_nospvar simple_ident_q
651
867
        field_or_var limit_option
652
868
        function_call_keyword
653
869
        function_call_nonkeyword
687
903
 
688
904
%type <interval_time_st> interval_time_stamp
689
905
 
 
906
%type <column_format_type> column_format_types
 
907
 
690
908
%type <tx_isolation> isolation_types
691
909
 
692
910
%type <cast_type> cast_type
693
911
 
694
 
%type <symbol>
695
 
        keyword
696
 
        keyword_sp
697
 
        keyword_exception_for_variable
698
 
        row_format
 
912
%type <symbol> keyword keyword_sp
699
913
 
700
914
%type <charset>
701
915
        collation_name
730
944
        flush_options flush_option
731
945
        equal optional_braces
732
946
        normal_join
733
 
        table_to_table_list table_to_table opt_table_list
 
947
        table_to_table_list table_to_table opt_table_list opt_as
734
948
        single_multi
735
949
        union_clause union_list
736
950
        precision subselect_start
784
998
            }
785
999
            else
786
1000
            {
787
 
              session->lex->statement= new statement::EmptyQuery(YYSession);
 
1001
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1002
              session->lex->statement=
 
1003
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
1004
              if (session->lex->statement == NULL)
 
1005
                DRIZZLE_YYABORT;
788
1006
            }
789
1007
          }
790
1008
        | verb_clause END_OF_INPUT {}
828
1046
/* create a table */
829
1047
 
830
1048
create:
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);
 
1049
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1050
          {
 
1051
            Session *session= YYSession;
 
1052
            LEX *lex= session->lex;
 
1053
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1054
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1055
            lex->statement= statement;
 
1056
            if (lex->statement == NULL)
 
1057
              DRIZZLE_YYABORT;
 
1058
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1059
                                                   TL_OPTION_UPDATING,
 
1060
                                                   TL_WRITE))
 
1061
              DRIZZLE_YYABORT;
 
1062
            lex->col_list.empty();
 
1063
            statement->change=NULL;
 
1064
            statement->is_if_not_exists= $4;
 
1065
            statement->create_info.db_type= NULL;
 
1066
            statement->create_info.default_table_charset= NULL;
 
1067
            lex->name.str= 0;
838
1068
 
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();
 
1069
            message::Table &proto= statement->create_table_message;
 
1070
           
 
1071
            proto.set_name($5->table.str);
 
1072
            if ($2)
 
1073
              proto.set_type(message::Table::TEMPORARY);
 
1074
            else
 
1075
              proto.set_type(message::Table::STANDARD);
844
1076
          }
845
 
          create_table_definition
 
1077
          create2
846
1078
          {
847
 
            Lex->current_select= &Lex->select_lex;
 
1079
            LEX *lex= YYSession->lex;
 
1080
            lex->current_select= &lex->select_lex;
848
1081
          }
849
1082
        | CREATE build_method
850
1083
          {
851
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1084
            LEX *lex=Lex;
 
1085
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1086
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1087
            lex->statement= statement;
 
1088
            if (lex->statement == NULL)
 
1089
              DRIZZLE_YYABORT;
 
1090
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1091
            statement->alter_info.build_method= $2;
 
1092
            lex->col_list.empty();
 
1093
            statement->change=NULL;
852
1094
          }
853
1095
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
1096
          {
855
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
856
 
                                                            NULL,
857
 
                                                            TL_OPTION_UPDATING))
 
1097
            LEX *lex=Lex;
 
1098
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1099
 
 
1100
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1101
                                                        NULL,
 
1102
                                                        TL_OPTION_UPDATING))
858
1103
              DRIZZLE_YYABORT;
859
 
 
860
 
            parser::buildKey(Lex, $4, $6);
 
1104
            Key *key;
 
1105
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1106
            statement->alter_info.key_list.push_back(key);
 
1107
            lex->col_list.empty();
861
1108
          }
862
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1109
        | CREATE DATABASE opt_if_not_exists ident
863
1110
          {
864
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1111
            LEX *lex=Lex;
 
1112
 
 
1113
            lex->sql_command=SQLCOM_CREATE_DB;
 
1114
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1115
            lex->statement= statement;
 
1116
            if (lex->statement == NULL)
 
1117
              DRIZZLE_YYABORT;
 
1118
            statement->is_if_not_exists= $3;
865
1119
          }
866
1120
          opt_create_database_options
867
1121
          {
869
1123
          }
870
1124
        ;
871
1125
 
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
 
           }
 
1126
create2:
 
1127
          '(' create2a {}
 
1128
        | opt_create_table_options
 
1129
          create3 {}
 
1130
        | LIKE table_ident opt_create_table_options
 
1131
          {
 
1132
            Session *session= YYSession;
 
1133
            LEX *lex= session->lex;
 
1134
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1135
 
 
1136
            statement->is_create_table_like= true;
 
1137
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1138
              DRIZZLE_YYABORT;
 
1139
          }
 
1140
        | '(' LIKE table_ident ')'
 
1141
          {
 
1142
            Session *session= YYSession;
 
1143
            LEX *lex= session->lex;
 
1144
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1145
 
 
1146
            statement->is_create_table_like= true;
 
1147
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1148
              DRIZZLE_YYABORT;
 
1149
          }
 
1150
        ;
 
1151
 
 
1152
create2a:
 
1153
          field_list ')' opt_create_table_options
 
1154
          create3 {}
 
1155
        |  create_select ')'
 
1156
           { Lex->current_select->set_braces(1);}
879
1157
           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
 
          { }
886
1158
        ;
887
1159
 
888
 
create_select_as:
 
1160
create3:
889
1161
          /* empty */ {}
890
 
        | opt_duplicate_as create_select
891
 
          {
892
 
            Lex->current_select->set_braces(0);
893
 
          }
 
1162
        | opt_duplicate opt_as create_select
 
1163
          { Lex->current_select->set_braces(0);}
894
1164
          union_clause {}
895
 
        | opt_duplicate_as '(' create_select ')'
896
 
          {
897
 
            Lex->current_select->set_braces(1);
898
 
          }
 
1165
        | opt_duplicate opt_as '(' create_select ')'
 
1166
          { Lex->current_select->set_braces(1);}
899
1167
          union_opt {}
900
1168
        ;
901
1169
 
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
 
 
912
1170
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:
922
1171
          SELECT_SYM
923
1172
          {
924
 
            Lex->lock_option= TL_READ;
925
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1173
            LEX *lex=Lex;
 
1174
            lex->lock_option= TL_READ;
 
1175
            if (lex->sql_command == SQLCOM_INSERT)
926
1176
            {
927
 
              delete Lex->statement;
928
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1177
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1178
              delete lex->statement;
 
1179
              lex->statement=
 
1180
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1181
              if (lex->statement == NULL)
 
1182
                DRIZZLE_YYABORT;
929
1183
            }
930
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1184
            else if (lex->sql_command == SQLCOM_REPLACE)
931
1185
            {
932
 
              delete Lex->statement;
933
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1186
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1187
              delete lex->statement;
 
1188
              lex->statement=
 
1189
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1190
              if (lex->statement == NULL)
 
1191
                DRIZZLE_YYABORT;
934
1192
            }
935
1193
            /*
936
1194
              The following work only with the local list, the global list
937
1195
              is created correctly in this case
938
1196
            */
939
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
 
            init_select(Lex);
941
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1197
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1198
            init_select(lex);
 
1199
            lex->current_select->parsing_place= SELECT_LIST;
942
1200
          }
943
1201
          select_options select_item_list
944
1202
          {
954
1212
          }
955
1213
        ;
956
1214
 
 
1215
opt_as:
 
1216
          /* empty */ {}
 
1217
        | AS {}
 
1218
        ;
 
1219
 
957
1220
opt_create_database_options:
958
1221
          /* empty */ {}
959
1222
        | default_collation_schema {}
967
1230
 
968
1231
custom_database_option:
969
1232
          ident_or_text
970
 
          {
971
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
972
 
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
973
 
          }
 
1233
        {
 
1234
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1235
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1236
 
 
1237
          opt->set_name($1.str);
 
1238
        }
974
1239
        | ident_or_text equal ident_or_text
975
 
          {
976
 
            parser::buildSchemaOption(Lex, $1.str, $3);
977
 
          }
 
1240
        {
 
1241
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1242
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1243
 
 
1244
          opt->set_name($1.str);
 
1245
          opt->set_state($3.str);
 
1246
        }
978
1247
        | ident_or_text equal ulonglong_num
979
 
          {
980
 
            parser::buildSchemaOption(Lex, $1.str, $3);
981
 
          }
 
1248
        {
 
1249
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1250
          char number_as_string[22];
 
1251
 
 
1252
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1253
 
 
1254
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1255
 
 
1256
          opt->set_name($1.str);
 
1257
          opt->set_state(number_as_string);
 
1258
        }
982
1259
        ;
983
1260
 
984
1261
opt_table_options:
988
1265
 
989
1266
opt_if_not_exists:
990
1267
          /* empty */ { $$= false; }
991
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1268
        | IF not EXISTS { $$= true; }
992
1269
        ;
993
1270
 
994
1271
opt_create_table_options:
1012
1289
custom_engine_option:
1013
1290
        ENGINE_SYM equal ident_or_text
1014
1291
          {
1015
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1292
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1293
 
 
1294
            statement->is_engine_set= true;
 
1295
 
 
1296
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1016
1297
          }
1017
1298
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1018
1299
          {
1019
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1300
            message::Table::TableOptions *tableopts;
 
1301
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1302
 
 
1303
            tableopts->set_comment($3.str);
1020
1304
          }
1021
1305
        | AUTO_INC opt_equal ulonglong_num
1022
1306
          {
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);
 
1307
            message::Table::TableOptions *tableopts;
 
1308
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1309
 
 
1310
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1311
 
 
1312
            statement->create_info.auto_increment_value=$3;
 
1313
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1314
            tableopts->set_auto_increment_value($3);
 
1315
          }
 
1316
        |  ident_or_text equal ident_or_text
 
1317
          {
 
1318
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1319
 
 
1320
            opt->set_name($1.str);
 
1321
            opt->set_state($3.str);
1036
1322
          }
1037
1323
        | ident_or_text equal ulonglong_num
1038
1324
          {
1039
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1325
            char number_as_string[22];
 
1326
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1327
 
 
1328
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1329
            opt->set_name($1.str);
 
1330
            opt->set_state(number_as_string);
1040
1331
          }
1041
1332
        | default_collation
1042
1333
        ;
1044
1335
default_collation:
1045
1336
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1046
1337
          {
1047
 
            if (not parser::buildCollation(Lex, $4))
1048
 
            {
1049
 
              DRIZZLE_YYABORT;
1050
 
            }
 
1338
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1339
 
 
1340
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1341
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1342
                 cinfo->default_table_charset && $4 &&
 
1343
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1344
              {
 
1345
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1346
                         $4->name, cinfo->default_table_charset->csname);
 
1347
                DRIZZLE_YYABORT;
 
1348
              }
 
1349
              statement->create_info.default_table_charset= $4;
 
1350
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1051
1351
          }
1052
1352
        ;
1053
1353
 
1054
1354
default_collation_schema:
1055
1355
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1056
1356
          {
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
 
        ;
 
1357
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1358
 
 
1359
            message::Schema &schema_message= statement->schema_message;
 
1360
            schema_message.set_collation($4->name);
 
1361
          }
 
1362
        ;
 
1363
 
 
1364
column_format_types:
 
1365
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1366
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1367
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1368
 
1077
1369
 
1078
1370
opt_select_from:
1079
1371
          opt_limit_clause {}
1101
1393
key_def:
1102
1394
          key_type opt_ident key_alg '(' key_list ')' key_options
1103
1395
          {
1104
 
            parser::buildKey(Lex, $1, $2);
 
1396
            LEX *lex=Lex;
 
1397
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1398
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1399
                              lex->col_list);
 
1400
            statement->alter_info.key_list.push_back(key);
 
1401
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1105
1402
          }
1106
1403
        | opt_constraint constraint_key_type opt_ident key_alg
1107
1404
          '(' key_list ')' key_options
1108
1405
          {
1109
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1406
            LEX *lex=Lex;
 
1407
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1408
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1409
                              lex->col_list);
 
1410
            statement->alter_info.key_list.push_back(key);
 
1411
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1110
1412
          }
1111
1413
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1112
1414
          {
1113
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1415
            LEX *lex=Lex;
 
1416
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1417
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
 
1418
                                      $8,
 
1419
                                      lex->ref_list,
 
1420
                                      statement->fk_delete_opt,
 
1421
                                      statement->fk_update_opt,
 
1422
                                      statement->fk_match_option);
 
1423
 
 
1424
            statement->alter_info.key_list.push_back(key);
 
1425
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1426
                         &default_key_create_info, 1,
 
1427
                         lex->col_list);
 
1428
            statement->alter_info.key_list.push_back(key);
 
1429
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1430
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1431
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1114
1432
          }
1115
1433
        | constraint opt_check_constraint
1116
1434
          {
1143
1461
field_spec:
1144
1462
          field_ident
1145
1463
          {
1146
 
            parser::buildCreateFieldIdent(Lex);
 
1464
            LEX *lex=Lex;
 
1465
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1466
            lex->length=lex->dec=0;
 
1467
            lex->type=0;
 
1468
            statement->default_value= statement->on_update_value= 0;
 
1469
            statement->comment= null_lex_str;
 
1470
            lex->charset=NULL;
 
1471
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1472
 
 
1473
            message::AlterTable &alter_proto=
 
1474
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1475
            statement->current_proto_field= alter_proto.add_added_field();
1147
1476
          }
1148
1477
          field_def
1149
1478
          {
 
1479
            LEX *lex=Lex;
1150
1480
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1151
1481
 
1152
 
            if (Lex->field())
1153
 
            {
1154
 
              Lex->field()->set_name($1.str);
1155
 
            }
 
1482
            if (statement->current_proto_field)
 
1483
              statement->current_proto_field->set_name($1.str);
1156
1484
 
1157
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
 
                                  Lex->length, Lex->dec, Lex->type,
 
1485
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1486
                                  lex->length,lex->dec,lex->type,
1159
1487
                                  statement->column_format,
1160
1488
                                  statement->default_value, statement->on_update_value,
1161
1489
                                  &statement->comment,
1162
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1490
                                  statement->change, &lex->interval_list, lex->charset))
1163
1491
              DRIZZLE_YYABORT;
1164
1492
 
1165
 
            Lex->setField(NULL);
 
1493
            statement->current_proto_field= NULL;
1166
1494
          }
1167
1495
        ;
1168
 
 
1169
1496
field_def:
1170
 
          field_definition opt_attribute {}
 
1497
          type opt_attribute {}
1171
1498
        ;
1172
1499
 
1173
 
field_definition:
 
1500
type:
1174
1501
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1175
1502
          { 
1176
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
 
1503
            $$= $1;
 
1504
            Lex->length=(char*) 0; /* use default length */
 
1505
            statement::CreateTable *statement=
 
1506
              (statement::CreateTable *)Lex->statement;
 
1507
 
 
1508
            if ($3 or $4)
 
1509
            {
 
1510
              $1= DRIZZLE_TYPE_LONGLONG;
 
1511
            }
 
1512
 
 
1513
            if (statement->current_proto_field)
 
1514
            {
 
1515
              assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
 
1516
              // We update the type for unsigned types
 
1517
              if ($3 or $4)
 
1518
              {
 
1519
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1520
                statement->current_proto_field->mutable_constraints()->set_is_unsigned(true);
 
1521
              }
 
1522
              if ($1 == DRIZZLE_TYPE_LONG)
 
1523
              {
 
1524
                statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1525
              }
 
1526
              else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1527
              {
 
1528
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1529
              }
 
1530
            }
1177
1531
          }
1178
1532
        | real_type opt_precision
1179
1533
          {
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
 
1534
            $$=$1;
 
1535
 
 
1536
            statement::CreateTable *statement=
 
1537
              (statement::CreateTable *)Lex->statement;
 
1538
 
 
1539
            if (statement->current_proto_field)
 
1540
            {
 
1541
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1542
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1543
            }
 
1544
          }
 
1545
          | char '(' NUM ')'
 
1546
            {
 
1547
              Lex->length=$3.str;
 
1548
              $$=DRIZZLE_TYPE_VARCHAR;
 
1549
 
 
1550
            statement::CreateTable *statement=
 
1551
              (statement::CreateTable *)Lex->statement;
 
1552
 
 
1553
            if (statement->current_proto_field)
 
1554
            {
 
1555
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1556
              message::Table::Field::StringFieldOptions *string_field_options;
 
1557
 
 
1558
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1559
 
 
1560
              string_field_options->set_length(atoi($3.str));
 
1561
            }
 
1562
            }
 
1563
          | char
 
1564
            {
 
1565
              Lex->length=(char*) "1";
 
1566
              $$=DRIZZLE_TYPE_VARCHAR;
 
1567
 
 
1568
            statement::CreateTable *statement=
 
1569
              (statement::CreateTable *)Lex->statement;
 
1570
 
 
1571
            if (statement->current_proto_field)
 
1572
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1573
            }
 
1574
          | varchar '(' NUM ')'
 
1575
            {
 
1576
              Lex->length=$3.str;
 
1577
              $$= DRIZZLE_TYPE_VARCHAR;
 
1578
 
 
1579
            statement::CreateTable *statement=
 
1580
              (statement::CreateTable *)Lex->statement;
 
1581
 
 
1582
            if (statement->current_proto_field)
 
1583
            {
 
1584
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1585
 
 
1586
              message::Table::Field::StringFieldOptions *string_field_options;
 
1587
 
 
1588
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1589
 
 
1590
              string_field_options->set_length(atoi($3.str));
 
1591
            }
 
1592
            }
 
1593
          | VARBINARY '(' NUM ')'
 
1594
            {
 
1595
              Lex->length=$3.str;
 
1596
              Lex->charset=&my_charset_bin;
 
1597
              $$= DRIZZLE_TYPE_VARCHAR;
 
1598
 
 
1599
            statement::CreateTable *statement=
 
1600
              (statement::CreateTable *)Lex->statement;
 
1601
 
 
1602
            if (statement->current_proto_field)
 
1603
            {
 
1604
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1605
              message::Table::Field::StringFieldOptions *string_field_options;
 
1606
 
 
1607
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1608
 
 
1609
              string_field_options->set_length(atoi($3.str));
 
1610
              string_field_options->set_collation_id(my_charset_bin.number);
 
1611
              string_field_options->set_collation(my_charset_bin.name);
 
1612
            }
 
1613
            }
 
1614
          | DATE_SYM
1200
1615
          {
1201
1616
            $$=DRIZZLE_TYPE_DATE;
1202
1617
 
1203
 
            if (Lex->field())
1204
 
              Lex->field()->set_type(message::Table::Field::DATE);
 
1618
            statement::CreateTable *statement=
 
1619
              (statement::CreateTable *)Lex->statement;
 
1620
 
 
1621
            if (statement->current_proto_field)
 
1622
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1205
1623
          }
1206
 
        | TIME_SYM
 
1624
          | TIME_SYM
1207
1625
          {
1208
1626
            $$=DRIZZLE_TYPE_TIME;
1209
1627
 
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
 
1628
            statement::CreateTable *statement=
 
1629
              (statement::CreateTable *)Lex->statement;
 
1630
 
 
1631
            if (statement->current_proto_field)
 
1632
              statement->current_proto_field->set_type(message::Table::Field::TIME);
 
1633
          }
 
1634
          | TIMESTAMP_SYM
 
1635
          {
 
1636
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1637
 
 
1638
            statement::CreateTable *statement=
 
1639
              (statement::CreateTable *)Lex->statement;
 
1640
 
 
1641
            if (statement->current_proto_field)
 
1642
              statement->current_proto_field->set_type(message::Table::Field::EPOCH);
 
1643
          }
 
1644
          | DATETIME_SYM
1222
1645
          {
1223
1646
            $$=DRIZZLE_TYPE_DATETIME;
1224
1647
 
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 ')'
 
1648
            statement::CreateTable *statement=
 
1649
              (statement::CreateTable *)Lex->statement;
 
1650
 
 
1651
            if (statement->current_proto_field)
 
1652
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1653
          }
 
1654
          | BLOB_SYM
 
1655
            {
 
1656
              Lex->charset=&my_charset_bin;
 
1657
              $$=DRIZZLE_TYPE_BLOB;
 
1658
              Lex->length=(char*) 0; /* use default length */
 
1659
 
 
1660
              statement::CreateTable *statement=
 
1661
                (statement::CreateTable *)Lex->statement;
 
1662
 
 
1663
              if (statement->current_proto_field)
 
1664
              {
 
1665
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1666
                message::Table::Field::StringFieldOptions *string_field_options;
 
1667
 
 
1668
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1669
                string_field_options->set_collation_id(my_charset_bin.number);
 
1670
                string_field_options->set_collation(my_charset_bin.name);
 
1671
              }
 
1672
            }
 
1673
          | TEXT_SYM
 
1674
            {
 
1675
              $$=DRIZZLE_TYPE_BLOB;
 
1676
              Lex->length=(char*) 0; /* use default length */
 
1677
 
 
1678
            statement::CreateTable *statement=
 
1679
              (statement::CreateTable *)Lex->statement;
 
1680
 
 
1681
            if (statement->current_proto_field)
 
1682
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1683
            }
 
1684
          | DECIMAL_SYM float_options
 
1685
          {
 
1686
            $$=DRIZZLE_TYPE_DECIMAL;
 
1687
 
 
1688
            statement::CreateTable *statement=
 
1689
              (statement::CreateTable *)Lex->statement;
 
1690
 
 
1691
            if (statement->current_proto_field)
 
1692
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1693
          }
 
1694
          | NUMERIC_SYM float_options
 
1695
          {
 
1696
            $$=DRIZZLE_TYPE_DECIMAL;
 
1697
 
 
1698
            statement::CreateTable *statement=
 
1699
              (statement::CreateTable *)Lex->statement;
 
1700
 
 
1701
            if (statement->current_proto_field)
 
1702
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1703
          }
 
1704
          | FIXED_SYM float_options
 
1705
          {
 
1706
            $$=DRIZZLE_TYPE_DECIMAL;
 
1707
 
 
1708
            statement::CreateTable *statement=
 
1709
              (statement::CreateTable *)Lex->statement;
 
1710
 
 
1711
            if (statement->current_proto_field)
 
1712
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1713
          }
 
1714
          | ENUM_SYM
 
1715
            {Lex->interval_list.empty();}
 
1716
            '(' string_list ')'
1257
1717
          {
1258
1718
            $$=DRIZZLE_TYPE_ENUM;
1259
1719
 
1260
 
            if (Lex->field())
1261
 
              Lex->field()->set_type(message::Table::Field::ENUM);
 
1720
            statement::CreateTable *statement=
 
1721
              (statement::CreateTable *)Lex->statement;
 
1722
 
 
1723
            if (statement->current_proto_field)
 
1724
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1262
1725
          }
1263
 
        | UUID_SYM
 
1726
          | UUID_SYM
1264
1727
          {
1265
 
            $$= parser::buildUuidColumn(Lex);
 
1728
            $$=DRIZZLE_TYPE_UUID;
 
1729
 
 
1730
            statement::CreateTable *statement=
 
1731
              (statement::CreateTable *)Lex->statement;
 
1732
 
 
1733
            if (statement->current_proto_field)
 
1734
              statement->current_proto_field->set_type(message::Table::Field::UUID);
1266
1735
          }
 
1736
        | BOOL_SYM
 
1737
        {
 
1738
          $$=DRIZZLE_TYPE_BOOLEAN;
 
1739
 
 
1740
          statement::CreateTable *statement=
 
1741
            (statement::CreateTable *)Lex->statement;
 
1742
 
 
1743
          if (statement->current_proto_field)
 
1744
            statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
 
1745
        }
1267
1746
        | BOOLEAN_SYM
1268
 
          {
1269
 
            $$= parser::buildBooleanColumn(Lex);
1270
 
          }
 
1747
        {
 
1748
          $$=DRIZZLE_TYPE_BOOLEAN;
 
1749
 
 
1750
          statement::CreateTable *statement=
 
1751
            (statement::CreateTable *)Lex->statement;
 
1752
 
 
1753
          if (statement->current_proto_field)
 
1754
            statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
 
1755
        }
1271
1756
        | SERIAL_SYM
1272
1757
          {
1273
 
            $$= parser::buildSerialColumn(Lex);
 
1758
            $$=DRIZZLE_TYPE_LONGLONG;
 
1759
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1760
 
 
1761
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1762
            if (statement->current_proto_field)
 
1763
            {
 
1764
              message::Table::Field::FieldConstraints *constraints;
 
1765
              constraints= statement->current_proto_field->mutable_constraints();
 
1766
              constraints->set_is_nullable(false);
 
1767
 
 
1768
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1769
            }
1274
1770
          }
1275
1771
        ;
1276
1772
 
1284
1780
        ;
1285
1781
 
1286
1782
int_type:
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
 
          }
 
1783
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1784
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1299
1785
        ;
1300
1786
 
1301
1787
real_type:
1304
1790
            $$= DRIZZLE_TYPE_DOUBLE;
1305
1791
          }
1306
1792
        | DOUBLE_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_DOUBLE;
1309
 
          }
 
1793
          { $$=DRIZZLE_TYPE_DOUBLE; }
1310
1794
        | DOUBLE_SYM PRECISION
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_DOUBLE;
1313
 
          }
 
1795
          { $$=DRIZZLE_TYPE_DOUBLE; }
1314
1796
        ;
1315
1797
 
1316
1798
float_options:
1325
1807
precision:
1326
1808
          '(' NUM ',' NUM ')'
1327
1809
          {
1328
 
            Lex->length= $2.str;
1329
 
            Lex->dec= $4.str;
 
1810
            LEX *lex=Lex;
 
1811
            lex->length=$2.str;
 
1812
            lex->dec=$4.str;
1330
1813
          }
1331
1814
        ;
1332
1815
 
1336
1819
        ;
1337
1820
 
1338
1821
opt_field_number_signed:
1339
 
          /* empty */ { $$= false; }
1340
 
        | SIGNED_SYM { $$= false; }
1341
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1822
          /* empty */ { $$= 0; }
 
1823
        | SIGNED_SYM { $$= 0; }
 
1824
        | UNSIGNED_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
1342
1825
        ;
1343
1826
 
1344
1827
ignored_field_number_length:
1347
1830
        ;
1348
1831
 
1349
1832
opt_zerofill:
1350
 
          /* empty */ { $$= false; }
1351
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1833
          /* empty */ { $$= 0; }
 
1834
        | ZEROFILL_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
1352
1835
        ;
1353
1836
 
1354
1837
opt_precision:
1355
 
          /* empty */
1356
 
          { Lex->dec=Lex->length= (char*)0; }
1357
 
        | '(' NUM ')'
1358
 
          { Lex->length=Lex->dec= (char*)0; }
1359
 
        | precision
1360
 
          {}
 
1838
          /* empty */ {}
 
1839
        | precision {}
1361
1840
        ;
1362
1841
 
1363
1842
opt_attribute:
1373
1852
attribute:
1374
1853
          NULL_SYM
1375
1854
          {
 
1855
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1376
1856
            Lex->type&= ~ NOT_NULL_FLAG;
 
1857
 
 
1858
            if (statement->current_proto_field)
 
1859
            {
 
1860
              message::Table::Field::FieldConstraints *constraints;
 
1861
              constraints= statement->current_proto_field->mutable_constraints();
 
1862
              constraints->set_is_nullable(true);
 
1863
            }
 
1864
          }
 
1865
        | COLUMN_FORMAT_SYM column_format_types
 
1866
          {
 
1867
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1868
 
 
1869
            statement->column_format= $2;
 
1870
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1377
1871
          }
1378
1872
        | not NULL_SYM
1379
1873
          {
 
1874
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1380
1875
            Lex->type|= NOT_NULL_FLAG;
1381
1876
 
1382
 
            if (Lex->field())
 
1877
            if (statement->current_proto_field)
1383
1878
            {
1384
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1879
              message::Table::Field::FieldConstraints *constraints;
 
1880
              constraints= statement->current_proto_field->mutable_constraints();
 
1881
              constraints->set_is_nullable(false);
1385
1882
            }
1386
1883
          }
1387
1884
        | DEFAULT now_or_signed_literal
1392
1889
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1393
1890
          }
1394
1891
        | ON UPDATE_SYM NOW_SYM optional_braces
1395
 
          {
1396
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1397
 
          }
 
1892
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1398
1893
        | AUTO_INC
1399
1894
          {
1400
 
            parser::buildAutoOnColumn(Lex);
 
1895
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1896
 
 
1897
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1898
            if (statement->current_proto_field)
 
1899
            {
 
1900
              message::Table::Field::FieldConstraints *constraints;
 
1901
 
 
1902
              constraints= statement->current_proto_field->mutable_constraints();
 
1903
              constraints->set_is_nullable(false);
 
1904
            }
1401
1905
          }
1402
1906
        | SERIAL_SYM DEFAULT VALUE_SYM
1403
1907
          {
1404
 
            (void)parser::buildSerialColumn(Lex);
 
1908
            LEX *lex=Lex;
 
1909
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1910
 
 
1911
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1912
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1913
 
 
1914
            if (statement->current_proto_field)
 
1915
            {
 
1916
              message::Table::Field::FieldConstraints *constraints;
 
1917
              constraints= statement->current_proto_field->mutable_constraints();
 
1918
              constraints->set_is_nullable(false);
 
1919
            }
1405
1920
          }
1406
1921
        | opt_primary KEY_SYM
1407
1922
          {
1408
 
            parser::buildPrimaryOnColumn(Lex);
 
1923
            LEX *lex=Lex;
 
1924
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1925
 
 
1926
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1927
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1928
 
 
1929
            if (statement->current_proto_field)
 
1930
            {
 
1931
              message::Table::Field::FieldConstraints *constraints;
 
1932
              constraints= statement->current_proto_field->mutable_constraints();
 
1933
              constraints->set_is_nullable(false);
 
1934
            }
1409
1935
          }
1410
1936
        | UNIQUE_SYM
1411
1937
          {
1412
 
            parser::buildKeyOnColumn(Lex);
 
1938
            LEX *lex=Lex;
 
1939
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1940
 
 
1941
            lex->type|= UNIQUE_FLAG;
 
1942
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1413
1943
          }
1414
1944
        | UNIQUE_SYM KEY_SYM
1415
1945
          {
1416
 
            parser::buildKeyOnColumn(Lex);
 
1946
            LEX *lex=Lex;
 
1947
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1948
 
 
1949
            lex->type|= UNIQUE_KEY_FLAG;
 
1950
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1417
1951
          }
1418
1952
        | COMMENT_SYM TEXT_STRING_sys
1419
1953
          {
1420
1954
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1421
1955
            statement->comment= $2;
1422
1956
 
1423
 
            if (Lex->field())
1424
 
              Lex->field()->set_comment($2.str);
 
1957
            if (statement->current_proto_field)
 
1958
              statement->current_proto_field->set_comment($2.str);
1425
1959
          }
1426
1960
        | COLLATE_SYM collation_name
1427
1961
          {
1493
2027
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1494
2028
        | ident
1495
2029
          {
1496
 
            Lex->ref_list.empty();
1497
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
2030
            LEX *lex= Lex;
 
2031
            lex->ref_list.empty();
 
2032
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1498
2033
          }
1499
2034
        ;
1500
2035
 
1584
2119
        ;
1585
2120
 
1586
2121
/*
1587
 
  For now, key_alg initializies Lex->key_create_info.
 
2122
  For now, key_alg initializies lex->key_create_info.
1588
2123
  In the future, when all key options are after key definition,
1589
2124
  we can remove key_alg and move init_key_options to key_options
1590
2125
*/
1606
2141
 
1607
2142
key_using_alg:
1608
2143
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2144
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1609
2145
        ;
1610
2146
 
1611
2147
key_opt:
1660
2196
alter:
1661
2197
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
1662
2198
          {
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());
 
2199
            Session *session= YYSession;
 
2200
            LEX *lex= session->lex;
 
2201
            lex->name.str= 0;
 
2202
            lex->name.length= 0;
 
2203
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2204
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2205
            lex->statement= statement;
 
2206
            if (lex->statement == NULL)
 
2207
              DRIZZLE_YYABORT;
 
2208
            lex->duplicates= DUP_ERROR;
 
2209
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2210
                                                   TL_OPTION_UPDATING))
 
2211
              DRIZZLE_YYABORT;
 
2212
            lex->col_list.empty();
 
2213
            lex->select_lex.init_order();
 
2214
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
 
2215
            statement->alter_info.build_method= $2;
1674
2216
          }
1675
2217
          alter_commands
1676
2218
          {}
1677
 
        | ALTER_SYM DATABASE schema_name
 
2219
        | ALTER_SYM DATABASE ident_or_empty
1678
2220
          {
1679
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2221
            LEX *lex=Lex;
 
2222
            lex->sql_command=SQLCOM_ALTER_DB;
 
2223
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2224
            if (lex->statement == NULL)
 
2225
              DRIZZLE_YYABORT;
1680
2226
          }
1681
2227
          default_collation_schema
1682
2228
          {
1683
 
            Lex->name= $3;
1684
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2229
            LEX *lex=Lex;
 
2230
            lex->name= $3;
 
2231
            if (lex->name.str == NULL &&
 
2232
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1685
2233
              DRIZZLE_YYABORT;
1686
2234
          }
1687
2235
        ;
1688
2236
 
 
2237
ident_or_empty:
 
2238
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2239
        | ident { $$= $1; }
 
2240
        ;
 
2241
 
1689
2242
alter_commands:
1690
2243
          /* empty */
1691
2244
        | DISCARD TABLESPACE
1755
2308
          field_spec opt_place
1756
2309
        | MODIFY_SYM opt_column field_ident
1757
2310
          {
 
2311
            LEX *lex=Lex;
1758
2312
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1759
 
            Lex->length= Lex->dec=0;
1760
 
            Lex->type= 0;
 
2313
            lex->length=lex->dec=0; lex->type=0;
1761
2314
            statement->default_value= statement->on_update_value= 0;
1762
2315
            statement->comment= null_lex_str;
1763
 
            Lex->charset= NULL;
 
2316
            lex->charset= NULL;
1764
2317
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1765
2318
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1766
2319
 
1767
 
            Lex->setField(NULL);
 
2320
            statement->current_proto_field= NULL;
1768
2321
          }
1769
2322
          field_def
1770
2323
          {
 
2324
            LEX *lex=Lex;
1771
2325
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1772
2326
 
1773
 
            if (add_field_to_list(Lex->session,&$3,
 
2327
            if (add_field_to_list(lex->session,&$3,
1774
2328
                                  (enum enum_field_types) $5,
1775
 
                                  Lex->length, Lex->dec, Lex->type,
 
2329
                                  lex->length, lex->dec, lex->type,
1776
2330
                                  statement->column_format,
1777
2331
                                  statement->default_value,
1778
2332
                                  statement->on_update_value,
1779
2333
                                  &statement->comment,
1780
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2334
                                  $3.str, &lex->interval_list, lex->charset))
1781
2335
              DRIZZLE_YYABORT;
1782
2336
          }
1783
2337
          opt_place
1842
2396
          }
1843
2397
        | RENAME opt_to table_ident
1844
2398
          {
 
2399
            LEX *lex=Lex;
1845
2400
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1846
2401
            size_t dummy;
1847
2402
 
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))
 
2403
            lex->select_lex.db=$3->db.str;
 
2404
            if (lex->select_lex.db == NULL &&
 
2405
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1851
2406
            {
1852
2407
              DRIZZLE_YYABORT;
1853
2408
            }
1858
2413
              DRIZZLE_YYABORT;
1859
2414
            }
1860
2415
 
1861
 
            Lex->name= $3->table;
 
2416
            lex->name= $3->table;
1862
2417
            statement->alter_info.flags.set(ALTER_RENAME);
1863
2418
          }
1864
2419
        | CONVERT_SYM TO_SYM collation_name_or_default
1865
2420
          {
1866
2421
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
2422
 
1868
 
            statement->create_info().table_charset=
1869
 
            statement->create_info().default_table_charset= $3;
1870
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2423
            statement->create_info.table_charset=
 
2424
            statement->create_info.default_table_charset= $3;
 
2425
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1871
2426
              HA_CREATE_USED_DEFAULT_CHARSET);
1872
2427
            statement->alter_info.flags.set(ALTER_CONVERT);
1873
2428
          }
1905
2460
          /* empty */ {}
1906
2461
        | AFTER_SYM ident
1907
2462
          {
1908
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2463
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2464
 
 
2465
            store_position_for_column($2.str);
 
2466
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1909
2467
          }
1910
2468
        | FIRST_SYM
1911
2469
          {
1912
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2470
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2471
 
 
2472
            store_position_for_column(first_keyword);
 
2473
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1913
2474
          }
1914
2475
        ;
1915
2476
 
1923
2484
start:
1924
2485
          START_SYM TRANSACTION_SYM start_transaction_opts
1925
2486
          {
1926
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2487
            LEX *lex= Lex;
 
2488
            lex->sql_command= SQLCOM_BEGIN;
 
2489
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2490
            if (lex->statement == NULL)
 
2491
              DRIZZLE_YYABORT;
1927
2492
          }
1928
2493
        ;
1929
2494
 
1938
2503
analyze:
1939
2504
          ANALYZE_SYM table_or_tables
1940
2505
          {
1941
 
            Lex->statement= new statement::Analyze(YYSession);
 
2506
            LEX *lex=Lex;
 
2507
            lex->sql_command = SQLCOM_ANALYZE;
 
2508
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2509
            if (lex->statement == NULL)
 
2510
              DRIZZLE_YYABORT;
1942
2511
          }
1943
2512
          table_list
1944
2513
          {}
1947
2516
check:
1948
2517
          CHECK_SYM table_or_tables
1949
2518
          {
1950
 
            Lex->statement= new statement::Check(YYSession);
 
2519
            LEX *lex=Lex;
 
2520
 
 
2521
            lex->sql_command = SQLCOM_CHECK;
 
2522
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2523
            if (lex->statement == NULL)
 
2524
              DRIZZLE_YYABORT;
1951
2525
          }
1952
2526
          table_list
1953
2527
          {}
1956
2530
rename:
1957
2531
          RENAME table_or_tables
1958
2532
          {
1959
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2533
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2534
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2535
            if (Lex->statement == NULL)
 
2536
              DRIZZLE_YYABORT;
1960
2537
          }
1961
2538
          table_to_table_list
1962
2539
          {}
1970
2547
table_to_table:
1971
2548
          table_ident TO_SYM table_ident
1972
2549
          {
1973
 
            Select_Lex *sl= Lex->current_select;
1974
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2550
            LEX *lex=Lex;
 
2551
            Select_Lex *sl= lex->current_select;
 
2552
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1975
2553
                                       TL_IGNORE) ||
1976
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2554
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1977
2555
                                       TL_IGNORE))
1978
2556
              DRIZZLE_YYABORT;
1979
2557
          }
1987
2565
select:
1988
2566
          select_init
1989
2567
          {
1990
 
            Lex->statement= new statement::Select(YYSession);
 
2568
            LEX *lex= Lex;
 
2569
            lex->sql_command= SQLCOM_SELECT;
 
2570
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2571
            if (lex->statement == NULL)
 
2572
              DRIZZLE_YYABORT;
1991
2573
          }
1992
2574
        ;
1993
2575
 
2000
2582
select_paren:
2001
2583
          SELECT_SYM select_part2
2002
2584
          {
2003
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2585
            if (setup_select_in_parentheses(YYSession, Lex))
2004
2586
              DRIZZLE_YYABORT;
2005
2587
          }
2006
2588
        | '(' select_paren ')'
2010
2592
select_paren_derived:
2011
2593
          SELECT_SYM select_part2_derived
2012
2594
          {
2013
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2595
            if (setup_select_in_parentheses(YYSession, Lex))
2014
2596
              DRIZZLE_YYABORT;
2015
2597
          }
2016
2598
        | '(' select_paren_derived ')'
2019
2601
select_init2:
2020
2602
          select_part2
2021
2603
          {
2022
 
            Select_Lex * sel= Lex->current_select;
2023
 
            if (Lex->current_select->set_braces(0))
 
2604
            LEX *lex= Lex;
 
2605
            Select_Lex * sel= lex->current_select;
 
2606
            if (lex->current_select->set_braces(0))
2024
2607
            {
2025
 
              parser::my_parse_error(YYSession->m_lip);
 
2608
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2609
              my_parse_error(&pass);
2026
2610
              DRIZZLE_YYABORT;
2027
2611
            }
2028
2612
            if (sel->linkage == UNION_TYPE &&
2029
2613
                sel->master_unit()->first_select()->braces)
2030
2614
            {
2031
 
              parser::my_parse_error(YYSession->m_lip);
 
2615
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2616
              my_parse_error(&pass);
2032
2617
              DRIZZLE_YYABORT;
2033
2618
            }
2034
2619
          }
2037
2622
 
2038
2623
select_part2:
2039
2624
          {
2040
 
            Select_Lex *sel= Lex->current_select;
 
2625
            LEX *lex= Lex;
 
2626
            Select_Lex *sel= lex->current_select;
2041
2627
            if (sel->linkage != UNION_TYPE)
2042
 
              init_select(Lex);
2043
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2628
              init_select(lex);
 
2629
            lex->current_select->parsing_place= SELECT_LIST;
2044
2630
          }
2045
2631
          select_options select_item_list
2046
2632
          {
2070
2656
select_options:
2071
2657
          /* empty*/
2072
2658
        | select_option_list
2073
 
          { }
 
2659
          {
 
2660
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2661
                Lex->current_select->options & SELECT_ALL)
 
2662
            {
 
2663
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2664
              DRIZZLE_YYABORT;
 
2665
            }
 
2666
          }
2074
2667
        ;
2075
2668
 
2076
2669
select_option_list:
2078
2671
        | select_option
2079
2672
        ;
2080
2673
 
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
 
 
2128
2674
select_option:
2129
2675
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2676
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2677
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2678
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2130
2679
        | SQL_BUFFER_RESULT
2131
2680
          {
2132
 
            if (check_simple_select(YYSession))
 
2681
            if (check_simple_select())
2133
2682
              DRIZZLE_YYABORT;
2134
2683
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2135
2684
          }
2136
 
        | select_option_small_or_big
2137
 
          { }
2138
 
        | select_option_distinct_or_all
2139
 
          { }
2140
2685
        | SQL_CALC_FOUND_ROWS
2141
2686
          {
2142
 
            if (check_simple_select(YYSession))
 
2687
            if (check_simple_select())
2143
2688
              DRIZZLE_YYABORT;
2144
2689
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2145
2690
          }
 
2691
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2146
2692
        ;
2147
2693
 
2148
2694
select_lock_type:
2149
2695
          /* empty */
2150
2696
        | FOR_SYM UPDATE_SYM
2151
2697
          {
2152
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2698
            LEX *lex=Lex;
 
2699
            lex->current_select->set_lock_for_tables(TL_WRITE);
2153
2700
          }
2154
2701
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2155
2702
          {
2156
 
            Lex->current_select->
 
2703
            LEX *lex=Lex;
 
2704
            lex->current_select->
2157
2705
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2158
2706
          }
2159
2707
        ;
2163
2711
        | select_item
2164
2712
        | '*'
2165
2713
          {
2166
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
2714
            Session *session= YYSession;
 
2715
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
2167
2716
                                                          context,
2168
2717
                                                          NULL, NULL, "*")))
2169
2718
              DRIZZLE_YYABORT;
2170
 
            (YYSession->lex->current_select->with_wild)++;
 
2719
            (session->lex->current_select->with_wild)++;
2171
2720
          }
2172
2721
        ;
2173
2722
 
2174
2723
select_item:
2175
2724
          remember_name table_wild remember_end
2176
2725
          {
2177
 
            if (YYSession->add_item_to_list($2))
 
2726
            Session *session= YYSession;
 
2727
 
 
2728
            if (session->add_item_to_list($2))
2178
2729
              DRIZZLE_YYABORT;
2179
2730
          }
2180
2731
        | remember_name expr remember_end select_alias
2181
2732
          {
 
2733
            Session *session= YYSession;
2182
2734
            assert($1 < $3);
2183
2735
 
2184
 
            if (YYSession->add_item_to_list($2))
 
2736
            if (session->add_item_to_list($2))
2185
2737
              DRIZZLE_YYABORT;
2186
 
 
2187
2738
            if ($4.str)
2188
2739
            {
2189
2740
              $2->is_autogenerated_name= false;
2191
2742
            }
2192
2743
            else if (!$2->name)
2193
2744
            {
2194
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2745
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2195
2746
            }
2196
2747
          }
2197
2748
        ;
2198
2749
 
2199
2750
remember_name:
2200
2751
          {
2201
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2752
            Session *session= YYSession;
 
2753
            Lex_input_stream *lip= session->m_lip;
2202
2754
            $$= (char*) lip->get_cpp_tok_start();
2203
2755
          }
2204
2756
        ;
2205
2757
 
2206
2758
remember_end:
2207
2759
          {
2208
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2760
            Session *session= YYSession;
 
2761
            Lex_input_stream *lip= session->m_lip;
2209
2762
            $$= (char*) lip->get_cpp_tok_end();
2210
2763
          }
2211
2764
        ;
2358
2911
          }
2359
2912
        | bit_expr not IN_SYM '(' subselect ')'
2360
2913
          {
2361
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2362
 
            $$= negate_expression(YYSession, item);
 
2914
            Session *session= YYSession;
 
2915
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2916
            $$= negate_expression(session, item);
2363
2917
          }
2364
2918
        | bit_expr IN_SYM '(' expr ')'
2365
2919
          {
2366
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2920
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2367
2921
          }
2368
2922
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2369
2923
          {
2373
2927
          }
2374
2928
        | bit_expr not IN_SYM '(' expr ')'
2375
2929
          {
2376
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2930
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2377
2931
          }
2378
2932
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2379
2933
          {
2406
2960
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2407
2961
            args->push_back($1);
2408
2962
            args->push_back($3);
2409
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2963
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2410
2964
            {
2411
2965
              DRIZZLE_YYABORT;
2412
2966
            }
2417
2971
            args->push_back($1);
2418
2972
            args->push_back($4);
2419
2973
            args->push_back(new (YYSession->mem_root) Item_int(1));
2420
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2974
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2421
2975
            {
2422
2976
              DRIZZLE_YYABORT;
2423
2977
            }
2481
3035
        | function_call_conflict
2482
3036
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2483
3037
          {
2484
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
3038
            Session *session= YYSession;
 
3039
            Item *i1= new (session->mem_root) Item_string($3.str,
2485
3040
                                                      $3.length,
2486
 
                                                      YYSession->charset());
2487
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
3041
                                                      session->charset());
 
3042
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2488
3043
          }
2489
3044
        | literal
2490
3045
        | variable
2522
3077
          }
2523
3078
        | CAST_SYM '(' expr AS cast_type ')'
2524
3079
          {
2525
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2526
 
                                 Lex->charset);
 
3080
            LEX *lex= Lex;
 
3081
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
3082
                                 lex->charset);
2527
3083
            if (!$$)
2528
3084
              DRIZZLE_YYABORT;
2529
3085
          }
2541
3097
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2542
3098
                                                         $3);
2543
3099
          }
2544
 
        | VALUES '(' simple_ident ')'
 
3100
        | VALUES '(' simple_ident_nospvar ')'
2545
3101
          {
2546
3102
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2547
3103
                                                        $3);
2563
3119
        | CURRENT_USER optional_braces
2564
3120
          {
2565
3121
            std::string user_str("user");
2566
 
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
 
3122
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2567
3123
            {
2568
3124
              DRIZZLE_YYABORT;
2569
3125
            }
2579
3135
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
2580
3136
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2581
3137
          {
2582
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3138
            Session *session= YYSession;
 
3139
            List<Item> *list= new (session->mem_root) List<Item>;
2583
3140
            list->push_front($5);
2584
3141
            list->push_front($3);
2585
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2586
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3142
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3143
            $$= new (session->mem_root) Item_func_interval(item);
2587
3144
          }
2588
3145
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2589
3146
          {
 
3147
            Session *session= YYSession;
2590
3148
            $7->push_front($5);
2591
3149
            $7->push_front($3);
2592
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2593
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3150
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3151
            $$= new (session->mem_root) Item_func_interval(item);
2594
3152
          }
2595
3153
        | LEFT '(' expr ',' expr ')'
2596
3154
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2622
3180
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2623
3181
        | USER '(' ')'
2624
3182
          {
2625
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3183
            std::string user_str("user");
 
3184
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2626
3185
            {
2627
3186
              DRIZZLE_YYABORT;
2628
3187
            }
2688
3247
            args->push_back($3);
2689
3248
            args->push_back($5);
2690
3249
            args->push_back($7);
2691
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3250
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2692
3251
            {
2693
3252
              DRIZZLE_YYABORT;
2694
3253
            }
2699
3258
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2700
3259
            args->push_back($3);
2701
3260
            args->push_back($5);
2702
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3261
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2703
3262
            {
2704
3263
              DRIZZLE_YYABORT;
2705
3264
            }
2711
3270
            args->push_back($3);
2712
3271
            args->push_back($5);
2713
3272
            args->push_back($7);
2714
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3273
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2715
3274
            {
2716
3275
              DRIZZLE_YYABORT;
2717
3276
            }
2722
3281
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2723
3282
            args->push_back($3);
2724
3283
            args->push_back($5);
2725
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3284
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2726
3285
            {
2727
3286
              DRIZZLE_YYABORT;
2728
3287
            }
2765
3324
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2766
3325
        | DATABASE '(' ')'
2767
3326
          {
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)))
 
3327
            std::string database_str("database");
 
3328
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
2777
3329
            {
2778
3330
              DRIZZLE_YYABORT;
2779
3331
            }
2789
3341
              args->push_back(new (YYSession->mem_root) Item_int(1));
2790
3342
            }
2791
3343
 
2792
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
 
3344
            if (! ($$= reserved_keyword_function(YYSession, "execute", args)))
2793
3345
            {
2794
3346
              DRIZZLE_YYABORT;
2795
3347
            }
2807
3359
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2808
3360
            }
2809
3361
 
2810
 
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
 
3362
            if (! ($$= reserved_keyword_function(YYSession, kill_str, args)))
2811
3363
            {
2812
3364
              DRIZZLE_YYABORT;
2813
3365
            }
2822
3374
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
2823
3375
        | REPLACE '(' expr ',' expr ',' expr ')'
2824
3376
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3377
        | REVERSE_SYM '(' expr ')'
 
3378
          {
 
3379
            std::string reverse_str("reverse");
 
3380
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3381
            args->push_back($3);
 
3382
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
3383
            {
 
3384
              DRIZZLE_YYABORT;
 
3385
            }
 
3386
          }
2825
3387
        | TRUNCATE_SYM '(' expr ',' expr ')'
2826
3388
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2827
3389
        | WAIT_SYM '(' expr ')'
2829
3391
            std::string wait_str("wait");
2830
3392
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2831
3393
            args->push_back($3);
2832
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
3394
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2833
3395
            {
2834
3396
              DRIZZLE_YYABORT;
2835
3397
            }
2836
3398
          }
2837
3399
        | UUID_SYM '(' ')'
2838
3400
          {
2839
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
 
3401
            if (! ($$= reserved_keyword_function(YYSession, "uuid", NULL)))
2840
3402
            {
2841
3403
              DRIZZLE_YYABORT;
2842
3404
            }
2848
3410
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2849
3411
            args->push_back($3);
2850
3412
            args->push_back($5);
2851
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
3413
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2852
3414
            {
2853
3415
              DRIZZLE_YYABORT;
2854
3416
            }
2873
3435
          }
2874
3436
          opt_udf_expr_list ')'
2875
3437
          {
 
3438
            Session *session= YYSession;
2876
3439
            Create_func *builder;
2877
3440
            Item *item= NULL;
2878
3441
 
2888
3451
            builder= find_native_function_builder($1);
2889
3452
            if (builder)
2890
3453
            {
2891
 
              item= builder->create(YYSession, $1, $4);
 
3454
              item= builder->create(session, $1, $4);
2892
3455
            }
2893
3456
            else
2894
3457
            {
2896
3459
              const plugin::Function *udf= $<udf>3;
2897
3460
              if (udf)
2898
3461
              {
2899
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3462
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2900
3463
              } else {
2901
3464
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2902
3465
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3013
3576
        ;
3014
3577
 
3015
3578
variable_aux:
3016
 
          user_variable_ident SET_VAR expr
 
3579
          ident_or_text SET_VAR expr
3017
3580
          {
3018
3581
            $$= new Item_func_set_user_var($1, $3);
3019
3582
            Lex->setCacheable(false);
3020
3583
          }
3021
 
        | user_variable_ident
 
3584
        | ident_or_text
3022
3585
          {
3023
3586
            $$= new Item_func_get_user_var(*YYSession, $1);
3024
3587
            Lex->setCacheable(false);
3025
3588
          }
3026
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3589
        | '@' opt_var_ident_type ident_or_text opt_component
3027
3590
          {
3028
3591
            /* disallow "SELECT @@global.global.variable" */
3029
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3592
            if ($3.str && $4.str && check_reserved_words(&$3))
3030
3593
            {
3031
 
              parser::my_parse_error(YYSession->m_lip);
 
3594
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3595
              my_parse_error(&pass);
3032
3596
              DRIZZLE_YYABORT;
3033
3597
            }
3034
3598
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3037
3601
        ;
3038
3602
 
3039
3603
opt_distinct:
3040
 
          /* empty */ { $$ = false; }
3041
 
        | DISTINCT    { $$ = true; }
 
3604
          /* empty */ { $$ = 0; }
 
3605
        | DISTINCT    { $$ = 1; }
3042
3606
        ;
3043
3607
 
3044
3608
opt_gconcat_separator:
3067
3631
in_sum_expr:
3068
3632
          opt_all
3069
3633
          {
3070
 
            if (Lex->current_select->inc_in_sum_expr())
 
3634
            LEX *lex= Lex;
 
3635
            if (lex->current_select->inc_in_sum_expr())
3071
3636
            {
3072
 
              parser::my_parse_error(YYSession->m_lip);
 
3637
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3638
              my_parse_error(&pass);
3073
3639
              DRIZZLE_YYABORT;
3074
3640
            }
3075
3641
          }
3083
3649
cast_type:
3084
3650
          BINARY opt_len
3085
3651
          { $$=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
3652
        | SIGNED_SYM
3089
3653
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3090
3654
        | SIGNED_SYM INT_SYM
3091
3655
          { $$=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
3656
        | UNSIGNED_SYM
3095
3657
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3096
3658
        | UNSIGNED_SYM INT_SYM
3151
3713
          table_factor { $$=$1; }
3152
3714
        | join_table
3153
3715
          {
3154
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3716
            LEX *lex= Lex;
 
3717
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3155
3718
              DRIZZLE_YYABORT;
3156
3719
          }
3157
3720
        ;
3298
3861
          }
3299
3862
          expr
3300
3863
          {
3301
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3864
            LEX *lex= Lex;
 
3865
            if (!($$= lex->current_select->convert_right_join()))
3302
3866
              DRIZZLE_YYABORT;
3303
3867
            add_join_on($$, $8);
3304
3868
            Lex->pop_context();
3310
3874
          }
3311
3875
          USING '(' using_list ')'
3312
3876
          {
3313
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3877
            LEX *lex= Lex;
 
3878
            if (!($$= lex->current_select->convert_right_join()))
3314
3879
              DRIZZLE_YYABORT;
3315
3880
            add_join_natural($$,$5,$9,Lex->current_select);
3316
3881
          }
3318
3883
          {
3319
3884
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3320
3885
            add_join_natural($6,$1,NULL,Lex->current_select);
3321
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3886
            LEX *lex= Lex;
 
3887
            if (!($$= lex->current_select->convert_right_join()))
3322
3888
              DRIZZLE_YYABORT;
3323
3889
          }
3324
3890
        ;
3326
3892
normal_join:
3327
3893
          JOIN_SYM {}
3328
3894
        | INNER_SYM JOIN_SYM {}
3329
 
        | CROSS JOIN_SYM
3330
 
          {
3331
 
            Lex->is_cross= true;
3332
 
            Lex->current_select->is_cross= true;
3333
 
          }
 
3895
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3334
3896
        ;
3335
3897
 
3336
3898
/*
3355
3917
          }
3356
3918
        | select_derived_init get_select_lex select_derived2
3357
3919
          {
3358
 
            Select_Lex *sel= Lex->current_select;
 
3920
            LEX *lex= Lex;
 
3921
            Select_Lex *sel= lex->current_select;
3359
3922
            if ($1)
3360
3923
            {
3361
3924
              if (sel->set_braces(1))
3362
3925
              {
3363
 
                parser::my_parse_error(YYSession->m_lip);
 
3926
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3927
                my_parse_error(&pass);
3364
3928
                DRIZZLE_YYABORT;
3365
3929
              }
3366
3930
              /* select in braces, can't contain global parameters */
3368
3932
                sel->master_unit()->global_parameters=
3369
3933
                   sel->master_unit()->fake_select_lex;
3370
3934
            }
3371
 
            if ($2->init_nested_join(Lex->session))
 
3935
            if ($2->init_nested_join(lex->session))
3372
3936
              DRIZZLE_YYABORT;
3373
3937
            $$= 0;
3374
3938
            /* incomplete derived tables return NULL, we must be
3410
3974
              /* Handle case of derived table, alias may be NULL if there
3411
3975
                 are no outer parentheses, add_table_to_list() will throw
3412
3976
                 error in this case */
3413
 
              Select_Lex *sel= Lex->current_select;
 
3977
              LEX *lex=Lex;
 
3978
              Select_Lex *sel= lex->current_select;
3414
3979
              Select_Lex_Unit *unit= sel->master_unit();
3415
 
              Lex->current_select= sel= unit->outer_select();
3416
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3980
              lex->current_select= sel= unit->outer_select();
 
3981
              if (!($$= sel->add_table_to_list(lex->session,
3417
3982
                                               new Table_ident(unit), $5, 0,
3418
3983
                                               TL_READ)))
3419
3984
 
3420
3985
                DRIZZLE_YYABORT;
3421
3986
              sel->add_joined_table($$);
3422
 
              Lex->pop_context();
 
3987
              lex->pop_context();
3423
3988
            }
3424
3989
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3425
3990
            {
3426
3991
              /* simple nested joins cannot have aliases or unions */
3427
 
              parser::my_parse_error(YYSession->m_lip);
 
3992
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3993
              my_parse_error(&pass);
3428
3994
              DRIZZLE_YYABORT;
3429
3995
            }
3430
3996
            else
3438
4004
          UNION_SYM
3439
4005
          union_option
3440
4006
          {
3441
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
4007
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3442
4008
              DRIZZLE_YYABORT;
3443
4009
          }
3444
4010
          query_specification
3456
4022
select_init2_derived:
3457
4023
          select_part2_derived
3458
4024
          {
3459
 
            Select_Lex * sel= Lex->current_select;
3460
 
            if (Lex->current_select->set_braces(0))
 
4025
            LEX *lex= Lex;
 
4026
            Select_Lex * sel= lex->current_select;
 
4027
            if (lex->current_select->set_braces(0))
3461
4028
            {
3462
 
              parser::my_parse_error(YYSession->m_lip);
 
4029
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4030
              my_parse_error(&pass);
3463
4031
              DRIZZLE_YYABORT;
3464
4032
            }
3465
4033
            if (sel->linkage == UNION_TYPE &&
3466
4034
                sel->master_unit()->first_select()->braces)
3467
4035
            {
3468
 
              parser::my_parse_error(YYSession->m_lip);
 
4036
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4037
              my_parse_error(&pass);
3469
4038
              DRIZZLE_YYABORT;
3470
4039
            }
3471
4040
          }
3474
4043
/* The equivalent of select_part2 for nested queries. */
3475
4044
select_part2_derived:
3476
4045
          {
3477
 
            Select_Lex *sel= Lex->current_select;
 
4046
            LEX *lex= Lex;
 
4047
            Select_Lex *sel= lex->current_select;
3478
4048
            if (sel->linkage != UNION_TYPE)
3479
 
              init_select(Lex);
3480
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4049
              init_select(lex);
 
4050
            lex->current_select->parsing_place= SELECT_LIST;
3481
4051
          }
3482
4052
          select_options select_item_list
3483
4053
          {
3490
4060
select_derived:
3491
4061
          get_select_lex
3492
4062
          {
3493
 
            if ($1->init_nested_join(Lex->session))
 
4063
            LEX *lex= Lex;
 
4064
            if ($1->init_nested_join(lex->session))
3494
4065
              DRIZZLE_YYABORT;
3495
4066
          }
3496
4067
          derived_table_list
3497
4068
          {
 
4069
            LEX *lex= Lex;
3498
4070
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3499
4071
               for derived tables, both must equal NULL */
3500
4072
 
3501
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
4073
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3502
4074
              DRIZZLE_YYABORT;
3503
 
 
3504
4075
            if (!$3 && $$)
3505
4076
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
4077
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4078
              my_parse_error(&pass);
3507
4079
              DRIZZLE_YYABORT;
3508
4080
            }
3509
4081
          }
3511
4083
 
3512
4084
select_derived2:
3513
4085
          {
3514
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3515
 
            if (not Lex->expr_allows_subselect)
 
4086
            LEX *lex= Lex;
 
4087
            lex->derived_tables|= DERIVED_SUBQUERY;
 
4088
            if (!lex->expr_allows_subselect)
3516
4089
            {
3517
 
              parser::my_parse_error(YYSession->m_lip);
 
4090
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4091
              my_parse_error(&pass);
3518
4092
              DRIZZLE_YYABORT;
3519
4093
            }
3520
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
4094
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
4095
                new_select(lex, 1))
3521
4096
              DRIZZLE_YYABORT;
3522
 
            init_select(Lex);
3523
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3524
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4097
            init_select(lex);
 
4098
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
4099
            lex->current_select->parsing_place= SELECT_LIST;
3525
4100
          }
3526
4101
          select_options select_item_list
3527
4102
          {
3537
4112
select_derived_init:
3538
4113
          SELECT_SYM
3539
4114
          {
3540
 
            Select_Lex *sel= Lex->current_select;
 
4115
            LEX *lex= Lex;
 
4116
 
 
4117
            Select_Lex *sel= lex->current_select;
3541
4118
            TableList *embedding;
3542
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
4119
            if (!sel->embedding || sel->end_nested_join(lex->session))
3543
4120
            {
3544
4121
              /* we are not in parentheses */
3545
 
              parser::my_parse_error(YYSession->m_lip);
 
4122
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4123
              my_parse_error(&pass);
3546
4124
              DRIZZLE_YYABORT;
3547
4125
            }
3548
4126
            embedding= Lex->current_select->embedding;
3690
4268
opt_table_alias:
3691
4269
          /* empty */ { $$=0; }
3692
4270
        | table_alias ident
3693
 
          {
3694
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3695
 
          }
 
4271
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3696
4272
        ;
3697
4273
 
3698
4274
opt_all:
3772
4348
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3773
4349
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3774
4350
            */
3775
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4351
            LEX *lex= Lex;
 
4352
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3776
4353
            {
3777
4354
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3778
4355
                       "global union parameters");
3779
4356
              DRIZZLE_YYABORT;
3780
4357
            }
3781
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4358
            lex->current_select->olap= ROLLUP_TYPE;
3782
4359
          }
3783
4360
        ;
3784
4361
 
3796
4373
        ;
3797
4374
 
3798
4375
alter_order_item:
3799
 
          simple_ident order_dir
 
4376
          simple_ident_nospvar order_dir
3800
4377
          {
 
4378
            Session *session= YYSession;
3801
4379
            bool ascending= ($2 == 1) ? true : false;
3802
 
            if (YYSession->add_order_to_list($1, ascending))
 
4380
            if (session->add_order_to_list($1, ascending))
3803
4381
              DRIZZLE_YYABORT;
3804
4382
          }
3805
4383
        ;
3816
4394
order_clause:
3817
4395
          ORDER_SYM BY
3818
4396
          {
3819
 
            if (not parser::buildOrderBy(Lex))
 
4397
            LEX *lex=Lex;
 
4398
            Select_Lex *sel= lex->current_select;
 
4399
            Select_Lex_Unit *unit= sel-> master_unit();
 
4400
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4401
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4402
                (sel->linkage != UNION_TYPE || sel->braces))
 
4403
            {
 
4404
              my_error(ER_WRONG_USAGE, MYF(0),
 
4405
                       "CUBE/ROLLUP", "ORDER BY");
3820
4406
              DRIZZLE_YYABORT;
 
4407
            }
 
4408
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4409
            {
 
4410
              /*
 
4411
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4412
                executed in the same way as the query
 
4413
                SELECT ... ORDER BY order_list
 
4414
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4415
                Otherwise we create a fake Select_Lex if it has not been created
 
4416
                yet.
 
4417
              */
 
4418
              Select_Lex *first_sl= unit->first_select();
 
4419
              if (!unit->is_union() &&
 
4420
                  (first_sl->order_list.elements ||
 
4421
                   first_sl->select_limit) &&           
 
4422
                  unit->add_fake_select_lex(lex->session))
 
4423
                DRIZZLE_YYABORT;
 
4424
            }
3821
4425
          }
3822
4426
          order_list
3823
4427
        ;
3824
4428
 
3825
4429
order_list:
3826
4430
          order_list ',' order_ident order_dir
3827
 
          {
3828
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3829
 
              DRIZZLE_YYABORT;
3830
 
          }
 
4431
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3831
4432
        | order_ident order_dir
3832
 
          {
3833
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3834
 
              DRIZZLE_YYABORT;
3835
 
          }
 
4433
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3836
4434
        ;
3837
4435
 
3838
4436
order_dir:
3844
4442
opt_limit_clause_init:
3845
4443
          /* empty */
3846
4444
          {
3847
 
            Select_Lex *sel= Lex->current_select;
 
4445
            LEX *lex= Lex;
 
4446
            Select_Lex *sel= lex->current_select;
3848
4447
            sel->offset_limit= 0;
3849
4448
            sel->select_limit= 0;
3850
4449
          }
3893
4492
delete_limit_clause:
3894
4493
          /* empty */
3895
4494
          {
3896
 
            Lex->current_select->select_limit= 0;
 
4495
            LEX *lex=Lex;
 
4496
            lex->current_select->select_limit= 0;
3897
4497
          }
3898
4498
        | LIMIT limit_option
3899
4499
          {
3904
4504
        ;
3905
4505
 
3906
4506
ulong_num:
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); }
 
4507
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4508
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4509
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4510
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4511
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4512
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3913
4513
        ;
3914
4514
 
3915
4515
ulonglong_num:
3922
4522
 
3923
4523
select_var_list_init:
3924
4524
          {
3925
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4525
            LEX *lex=Lex;
 
4526
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3926
4527
              DRIZZLE_YYABORT;
3927
4528
          }
3928
4529
          select_var_list
3935
4536
        ;
3936
4537
 
3937
4538
select_var_ident: 
3938
 
          '@' user_variable_ident
 
4539
          '@' ident_or_text
3939
4540
          {
3940
 
            if (Lex->result)
3941
 
            {
3942
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3943
 
            }
 
4541
            LEX *lex=Lex;
 
4542
            if (lex->result)
 
4543
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3944
4544
            else
3945
 
            {
3946
4545
              /*
3947
4546
                The parser won't create select_result instance only
3948
4547
                if it's an EXPLAIN.
3949
4548
              */
3950
 
              assert(Lex->describe);
3951
 
            }
 
4549
              assert(lex->describe);
3952
4550
          }
3953
4551
        ;
3954
4552
 
3961
4559
into_destination:
3962
4560
          OUTFILE TEXT_STRING_filesystem
3963
4561
          {
3964
 
            Lex->setCacheable(false);
3965
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3966
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4562
            LEX *lex= Lex;
 
4563
            lex->setCacheable(false);
 
4564
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4565
                !(lex->result= new select_export(lex->exchange)))
3967
4566
              DRIZZLE_YYABORT;
3968
4567
          }
3969
4568
          opt_field_term opt_line_term
3970
4569
        | DUMPFILE TEXT_STRING_filesystem
3971
4570
          {
3972
 
            if (not Lex->describe)
 
4571
            LEX *lex=Lex;
 
4572
            if (!lex->describe)
3973
4573
            {
3974
 
              Lex->setCacheable(false);
3975
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4574
              lex->setCacheable(false);
 
4575
              if (!(lex->exchange= new file_exchange($2.str,1)))
3976
4576
                DRIZZLE_YYABORT;
3977
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4577
              if (!(lex->result= new select_dump(lex->exchange)))
3978
4578
                DRIZZLE_YYABORT;
3979
4579
            }
3980
4580
          }
3987
4587
*/
3988
4588
 
3989
4589
drop:
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;
 
4590
          DROP opt_temporary table_or_tables if_exists table_list
 
4591
          {
 
4592
            LEX *lex=Lex;
 
4593
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4594
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4595
            lex->statement= statement;
 
4596
            if (lex->statement == NULL)
 
4597
              DRIZZLE_YYABORT;
3998
4598
            statement->drop_temporary= $2;
3999
4599
            statement->drop_if_exists= $4;
4000
4600
          }
4001
4601
        | DROP build_method INDEX_SYM ident ON table_ident {}
4002
4602
          {
4003
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
4004
 
            Lex->statement= statement;
 
4603
            LEX *lex=Lex;
 
4604
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4605
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4606
            lex->statement= statement;
 
4607
            if (lex->statement == NULL)
 
4608
              DRIZZLE_YYABORT;
4005
4609
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4006
4610
            statement->alter_info.build_method= $2;
4007
4611
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4008
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
4009
 
                                                          TL_OPTION_UPDATING))
 
4612
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4613
                                                        TL_OPTION_UPDATING))
4010
4614
              DRIZZLE_YYABORT;
4011
4615
          }
4012
 
        | DROP DATABASE if_exists schema_name
 
4616
        | DROP DATABASE if_exists ident
4013
4617
          {
4014
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4015
 
            Lex->statement= statement;
 
4618
            LEX *lex=Lex;
 
4619
            lex->sql_command= SQLCOM_DROP_DB;
 
4620
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4621
            lex->statement= statement;
 
4622
            if (lex->statement == NULL)
 
4623
              DRIZZLE_YYABORT;
4016
4624
            statement->drop_if_exists=$3;
4017
 
            Lex->name= $4;
 
4625
            lex->name= $4;
4018
4626
          }
4019
 
        ;
4020
 
 
4021
4627
table_list:
4022
4628
          table_name
4023
4629
        | table_list ',' table_name
4032
4638
        ;
4033
4639
 
4034
4640
if_exists:
4035
 
          /* empty */ { $$= false; }
4036
 
        | IF EXISTS { $$= true; }
 
4641
          /* empty */ { $$= 0; }
 
4642
        | IF EXISTS { $$= 1; }
4037
4643
        ;
4038
4644
 
4039
4645
opt_temporary:
4040
 
          /* empty */ { $$= false; }
4041
 
        | TEMPORARY_SYM { $$= true; }
 
4646
          /* empty */ { $$= 0; }
 
4647
        | TEMPORARY_SYM { $$= 1; }
4042
4648
        ;
4043
4649
 
4044
4650
/*
4045
4651
  Execute a string as dynamic SQL.
4046
 
*/
 
4652
  */
4047
4653
 
4048
4654
execute:
4049
4655
       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
 
        }
 
4656
       {
 
4657
          LEX *lex= Lex;
 
4658
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession, $2, $3, $4, $5);
 
4659
          lex->statement= statement;
 
4660
          if (lex->statement == NULL)
 
4661
            DRIZZLE_YYABORT;
 
4662
       }
4053
4663
 
4054
4664
 
4055
4665
execute_var_or_string:
4056
 
         user_variable_ident
 
4666
         ident_or_text
4057
4667
         {
4058
4668
            $$.set($1);
4059
4669
         }
4060
 
        | '@' user_variable_ident
 
4670
        | '@' ident_or_text
4061
4671
        {
4062
4672
            $$.set($2, true);
4063
4673
        }
4064
4674
 
4065
4675
opt_status:
4066
 
          /* empty */ { $$= false; }
4067
 
        | WITH NO_SYM RETURN_SYM { $$= true; }
 
4676
          /* empty */ { $$= 0; }
 
4677
        | WITH NO_SYM RETURN_SYM { $$= 1; }
4068
4678
        ;
4069
4679
 
4070
4680
opt_concurrent:
4071
 
          /* empty */ { $$= false; }
4072
 
        | CONCURRENT { $$= true; }
 
4681
          /* empty */ { $$= 0; }
 
4682
        | CONCURRENT { $$= 1; }
4073
4683
        ;
4074
4684
 
4075
4685
opt_wait:
4076
 
          /* empty */ { $$= false; }
4077
 
        | WAIT_SYM { $$= true; }
 
4686
          /* empty */ { $$= 0; }
 
4687
        | WAIT_SYM { $$= 1; }
4078
4688
        ;
4079
4689
 
4080
4690
/*
4084
4694
insert:
4085
4695
          INSERT
4086
4696
          {
4087
 
            Lex->statement= new statement::Insert(YYSession);
4088
 
            Lex->duplicates= DUP_ERROR;
4089
 
            init_select(Lex);
 
4697
            LEX *lex= Lex;
 
4698
            lex->sql_command= SQLCOM_INSERT;
 
4699
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4700
            if (lex->statement == NULL)
 
4701
              DRIZZLE_YYABORT;
 
4702
            lex->duplicates= DUP_ERROR;
 
4703
            init_select(lex);
4090
4704
            /* for subselects */
4091
 
            Lex->lock_option= TL_READ;
 
4705
            lex->lock_option= TL_READ;
4092
4706
          }
4093
4707
          opt_ignore insert2
4094
4708
          {
4102
4716
replace:
4103
4717
          REPLACE
4104
4718
          {
4105
 
            Lex->statement= new statement::Replace(YYSession);
4106
 
            Lex->duplicates= DUP_REPLACE;
4107
 
            init_select(Lex);
 
4719
            LEX *lex= Lex;
 
4720
            lex->sql_command= SQLCOM_REPLACE;
 
4721
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4722
            if (lex->statement == NULL)
 
4723
              DRIZZLE_YYABORT;
 
4724
            lex->duplicates= DUP_REPLACE;
 
4725
            init_select(lex);
4108
4726
          }
4109
4727
          insert2
4110
4728
          {
4123
4741
insert_table:
4124
4742
          table_name
4125
4743
          {
4126
 
            Lex->field_list.empty();
4127
 
            Lex->many_values.empty();
4128
 
            Lex->insert_list=0;
 
4744
            LEX *lex=Lex;
 
4745
            lex->field_list.empty();
 
4746
            lex->many_values.empty();
 
4747
            lex->insert_list=0;
4129
4748
          };
4130
4749
 
4131
4750
insert_field_spec:
4134
4753
        | '(' fields ')' insert_values {}
4135
4754
        | SET_SYM
4136
4755
          {
4137
 
            if (not (Lex->insert_list = new List_item) ||
4138
 
                Lex->many_values.push_back(Lex->insert_list))
 
4756
            LEX *lex=Lex;
 
4757
            if (!(lex->insert_list = new List_item) ||
 
4758
                lex->many_values.push_back(lex->insert_list))
4139
4759
              DRIZZLE_YYABORT;
4140
4760
          }
4141
4761
          ident_eq_list
4149
4769
insert_values:
4150
4770
          VALUES values_list {}
4151
4771
        | VALUE_SYM values_list {}
4152
 
        | stored_select
4153
 
          {
4154
 
            Lex->current_select->set_braces(0);
4155
 
          }
 
4772
        | create_select
 
4773
          { Lex->current_select->set_braces(0);}
4156
4774
          union_clause {}
4157
 
        | '(' stored_select ')'
4158
 
          {
4159
 
            Lex->current_select->set_braces(1);
4160
 
          }
 
4775
        | '(' create_select ')'
 
4776
          { Lex->current_select->set_braces(1);}
4161
4777
          union_opt {}
4162
4778
        ;
4163
4779
 
4172
4788
        ;
4173
4789
 
4174
4790
ident_eq_value:
4175
 
          simple_ident equal expr_or_default
 
4791
          simple_ident_nospvar equal expr_or_default
4176
4792
          {
4177
 
            if (Lex->field_list.push_back($1) ||
4178
 
                Lex->insert_list->push_back($3))
 
4793
            LEX *lex=Lex;
 
4794
            if (lex->field_list.push_back($1) ||
 
4795
                lex->insert_list->push_back($3))
4179
4796
              DRIZZLE_YYABORT;
4180
4797
          }
4181
4798
        ;
4198
4815
          }
4199
4816
          opt_values ')'
4200
4817
          {
4201
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4818
            LEX *lex=Lex;
 
4819
            if (lex->many_values.push_back(lex->insert_list))
4202
4820
              DRIZZLE_YYABORT;
4203
4821
          }
4204
4822
        ;
4237
4855
update:
4238
4856
          UPDATE_SYM opt_ignore table_ident
4239
4857
          {
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))
 
4858
            LEX *lex= Lex;
 
4859
            init_select(lex);
 
4860
            lex->sql_command= SQLCOM_UPDATE;
 
4861
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4862
            if (lex->statement == NULL)
 
4863
              DRIZZLE_YYABORT;
 
4864
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4865
            lex->duplicates= DUP_ERROR;
 
4866
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4245
4867
              DRIZZLE_YYABORT;
4246
4868
          }
4247
4869
          SET_SYM update_list
4248
4870
          {
4249
 
            if (Lex->select_lex.get_table_list()->derived)
 
4871
            LEX *lex= Lex;
 
4872
            if (lex->select_lex.get_table_list()->derived)
4250
4873
            {
4251
4874
              /* it is single table update and it is update of derived table */
4252
4875
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4253
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4876
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4254
4877
              DRIZZLE_YYABORT;
4255
4878
            }
4256
4879
            /*
4269
4892
        ;
4270
4893
 
4271
4894
update_elem:
4272
 
          simple_ident equal expr_or_default
 
4895
          simple_ident_nospvar equal expr_or_default
4273
4896
          {
4274
4897
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4275
4898
              DRIZZLE_YYABORT;
4282
4905
        ;
4283
4906
 
4284
4907
insert_update_elem:
4285
 
          simple_ident equal expr_or_default
 
4908
          simple_ident_nospvar equal expr_or_default
4286
4909
          {
4287
 
          if (Lex->update_list.push_back($1) ||
4288
 
              Lex->value_list.push_back($3))
 
4910
          LEX *lex= Lex;
 
4911
          if (lex->update_list.push_back($1) ||
 
4912
              lex->value_list.push_back($3))
4289
4913
              DRIZZLE_YYABORT;
4290
4914
          }
4291
4915
        ;
4295
4919
delete:
4296
4920
          DELETE_SYM
4297
4921
          {
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();
 
4922
            LEX *lex= Lex;
 
4923
            lex->sql_command= SQLCOM_DELETE;
 
4924
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4925
            if (lex->statement == NULL)
 
4926
              DRIZZLE_YYABORT;
 
4927
            init_select(lex);
 
4928
            lex->lock_option= TL_WRITE_DEFAULT;
 
4929
            lex->ignore= 0;
 
4930
            lex->select_lex.init_order();
4303
4931
          }
4304
4932
          opt_delete_options single_multi
4305
4933
        ;
4327
4955
truncate:
4328
4956
          TRUNCATE_SYM opt_table_sym table_name
4329
4957
          {
4330
 
            Lex->statement= new statement::Truncate(YYSession);
4331
 
            Lex->select_lex.options= 0;
4332
 
            Lex->select_lex.init_order();
 
4958
            LEX* lex= Lex;
 
4959
            lex->sql_command= SQLCOM_TRUNCATE;
 
4960
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4961
            if (lex->statement == NULL)
 
4962
              DRIZZLE_YYABORT;
 
4963
            lex->select_lex.options= 0;
 
4964
            lex->select_lex.init_order();
4333
4965
          }
4334
4966
        ;
4335
4967
 
4343
4975
show:
4344
4976
          SHOW
4345
4977
          {
4346
 
            Lex->lock_option= TL_READ;
4347
 
            init_select(Lex);
4348
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4978
            LEX *lex=Lex;
 
4979
            lex->wild=0;
 
4980
            lex->lock_option= TL_READ;
 
4981
            init_select(lex);
 
4982
            lex->current_select->parsing_place= SELECT_LIST;
4349
4983
          }
4350
4984
          show_param
4351
4985
          {}
4355
4989
show_param:
4356
4990
           DATABASES show_wild
4357
4991
           {
4358
 
             if (not show::buildScemas(YYSession))
4359
 
               DRIZZLE_YYABORT;
 
4992
             LEX *lex= Lex;
 
4993
             Session *session= YYSession;
 
4994
 
 
4995
             lex->sql_command= SQLCOM_SELECT;
 
4996
             lex->statement=
 
4997
               new(std::nothrow) statement::Show(session);
 
4998
             if (lex->statement == NULL)
 
4999
               DRIZZLE_YYABORT;
 
5000
 
 
5001
             std::string column_name= "Database";
 
5002
             if (Lex->wild)
 
5003
             {
 
5004
               column_name.append(" (");
 
5005
               column_name.append(Lex->wild->ptr());
 
5006
               column_name.append(")");
 
5007
             }
 
5008
 
 
5009
             if (Lex->current_select->where)
 
5010
             {
 
5011
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
5012
                 DRIZZLE_YYABORT;
 
5013
             }
 
5014
             else
 
5015
             {
 
5016
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
5017
                 DRIZZLE_YYABORT;
 
5018
             }
 
5019
 
 
5020
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5021
             my_field->is_autogenerated_name= false;
 
5022
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
5023
 
 
5024
             if (session->add_item_to_list(my_field))
 
5025
               DRIZZLE_YYABORT;
 
5026
 
 
5027
              if (session->add_order_to_list(my_field, true))
 
5028
                DRIZZLE_YYABORT;
4360
5029
           }
4361
5030
           /* SHOW TABLES */
4362
5031
         | TABLES opt_db show_wild
4363
5032
           {
4364
 
             if (not show::buildTables(YYSession, $2))
4365
 
               DRIZZLE_YYABORT;
 
5033
             LEX *lex= Lex;
 
5034
             Session *session= YYSession;
 
5035
 
 
5036
             lex->sql_command= SQLCOM_SELECT;
 
5037
 
 
5038
             statement::Show *select=
 
5039
               new(std::nothrow) statement::Show(YYSession);
 
5040
 
 
5041
             lex->statement= select;
 
5042
 
 
5043
             if (lex->statement == NULL)
 
5044
               DRIZZLE_YYABORT;
 
5045
 
 
5046
 
 
5047
              std::string column_name= "Tables_in_";
 
5048
 
 
5049
              util::string::const_shared_ptr schema(session->schema());
 
5050
              if ($2)
 
5051
              {
 
5052
                SchemaIdentifier identifier($2);
 
5053
                column_name.append($2);
 
5054
                lex->select_lex.db= $2;
 
5055
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
5056
                {
 
5057
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
5058
                }
 
5059
                select->setShowPredicate($2, "");
 
5060
              }
 
5061
              else if (schema and not schema->empty())
 
5062
              {
 
5063
                column_name.append(*schema);
 
5064
                select->setShowPredicate(*schema, "");
 
5065
              }
 
5066
              else
 
5067
              {
 
5068
                my_error(ER_NO_DB_ERROR, MYF(0));
 
5069
                DRIZZLE_YYABORT;
 
5070
              }
 
5071
 
 
5072
 
 
5073
             if (Lex->wild)
 
5074
             {
 
5075
               column_name.append(" (");
 
5076
               column_name.append(Lex->wild->ptr());
 
5077
               column_name.append(")");
 
5078
             }
 
5079
 
 
5080
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
5081
               DRIZZLE_YYABORT;
 
5082
 
 
5083
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5084
             my_field->is_autogenerated_name= false;
 
5085
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
5086
 
 
5087
             if (session->add_item_to_list(my_field))
 
5088
               DRIZZLE_YYABORT;
 
5089
 
 
5090
              if (session->add_order_to_list(my_field, true))
 
5091
                DRIZZLE_YYABORT;
4366
5092
           }
4367
5093
           /* SHOW TEMPORARY TABLES */
4368
5094
         | TEMPORARY_SYM TABLES show_wild
4369
5095
           {
4370
 
             if (not show::buildTemporaryTables(YYSession))
4371
 
               DRIZZLE_YYABORT;
 
5096
             LEX *lex= Lex;
 
5097
             Session *session= YYSession;
 
5098
 
 
5099
             lex->sql_command= SQLCOM_SELECT;
 
5100
 
 
5101
             statement::Show *select=
 
5102
               new(std::nothrow) statement::Show(YYSession);
 
5103
 
 
5104
             lex->statement= select;
 
5105
 
 
5106
             if (lex->statement == NULL)
 
5107
               DRIZZLE_YYABORT;
 
5108
 
 
5109
 
 
5110
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
 
5111
               DRIZZLE_YYABORT;
 
5112
 
 
5113
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5114
                                                           context,
 
5115
                                                           NULL, NULL, "*")))
 
5116
               DRIZZLE_YYABORT;
 
5117
             (session->lex->current_select->with_wild)++;
 
5118
 
4372
5119
           }
4373
5120
           /* SHOW TABLE STATUS */
4374
5121
         | TABLE_SYM STATUS_SYM opt_db show_wild
4375
5122
           {
4376
 
             if (not show::buildTableStatus(YYSession, $3))
4377
 
               DRIZZLE_YYABORT;
 
5123
             LEX *lex= Lex;
 
5124
             lex->sql_command= SQLCOM_SELECT;
 
5125
             statement::Show *select=
 
5126
               new(std::nothrow) statement::Show(YYSession);
 
5127
 
 
5128
             lex->statement= select;
 
5129
 
 
5130
             if (lex->statement == NULL)
 
5131
               DRIZZLE_YYABORT;
 
5132
 
 
5133
             Session *session= YYSession;
 
5134
 
 
5135
             std::string column_name= "Tables_in_";
 
5136
 
 
5137
             util::string::const_shared_ptr schema(session->schema());
 
5138
             if ($3)
 
5139
             {
 
5140
               lex->select_lex.db= $3;
 
5141
 
 
5142
               SchemaIdentifier identifier($3);
 
5143
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
5144
               {
 
5145
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
5146
               }
 
5147
 
 
5148
               select->setShowPredicate($3, "");
 
5149
             }
 
5150
             else if (schema)
 
5151
             {
 
5152
               select->setShowPredicate(*schema, "");
 
5153
             }
 
5154
             else
 
5155
             {
 
5156
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5157
               DRIZZLE_YYABORT;
 
5158
             }
 
5159
 
 
5160
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
5161
               DRIZZLE_YYABORT;
 
5162
 
 
5163
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5164
                                                           context,
 
5165
                                                           NULL, NULL, "*")))
 
5166
               DRIZZLE_YYABORT;
 
5167
             (session->lex->current_select->with_wild)++;
4378
5168
           }
4379
5169
           /* SHOW COLUMNS FROM table_name */
4380
5170
        | COLUMNS from_or_in table_ident opt_db show_wild
4381
 
           {
4382
 
             if (not show::buildColumns(YYSession, $4, $3))
4383
 
               DRIZZLE_YYABORT;
4384
 
           }
 
5171
          {
 
5172
             LEX *lex= Lex;
 
5173
             Session *session= YYSession;
 
5174
             statement::Show *select;
 
5175
 
 
5176
             lex->sql_command= SQLCOM_SELECT;
 
5177
 
 
5178
             select= new(std::nothrow) statement::Show(session);
 
5179
 
 
5180
             lex->statement= select;
 
5181
 
 
5182
             if (lex->statement == NULL)
 
5183
               DRIZZLE_YYABORT;
 
5184
 
 
5185
             util::string::const_shared_ptr schema(session->schema());
 
5186
             if ($4)
 
5187
             {
 
5188
              select->setShowPredicate($4, $3->table.str);
 
5189
             }
 
5190
             else if ($3->db.str)
 
5191
             {
 
5192
              select->setShowPredicate($3->db.str, $3->table.str);
 
5193
             }
 
5194
             else if (schema)
 
5195
             {
 
5196
               select->setShowPredicate(*schema, $3->table.str);
 
5197
             }
 
5198
             else
 
5199
             {
 
5200
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5201
               DRIZZLE_YYABORT;
 
5202
             }
 
5203
 
 
5204
             {
 
5205
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5206
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5207
               {
 
5208
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5209
                            select->getShowSchema().c_str(), 
 
5210
                            $3->table.str);
 
5211
               }
 
5212
             }
 
5213
 
 
5214
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5215
               DRIZZLE_YYABORT;
 
5216
 
 
5217
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5218
                                                           context,
 
5219
                                                           NULL, NULL, "*")))
 
5220
               DRIZZLE_YYABORT;
 
5221
             (session->lex->current_select->with_wild)++;
 
5222
 
 
5223
          }
4385
5224
          /* SHOW INDEXES from table */
4386
5225
        | keys_or_index from_or_in table_ident opt_db where_clause
4387
 
           {
4388
 
             if (not show::buildIndex(YYSession, $4, $3))
4389
 
               DRIZZLE_YYABORT;
4390
 
           }
 
5226
          {
 
5227
             LEX *lex= Lex;
 
5228
             Session *session= YYSession;
 
5229
             statement::Show *select;
 
5230
 
 
5231
             lex->sql_command= SQLCOM_SELECT;
 
5232
 
 
5233
             select= new(std::nothrow) statement::Show(session);
 
5234
 
 
5235
             lex->statement= select;
 
5236
 
 
5237
             if (lex->statement == NULL)
 
5238
               DRIZZLE_YYABORT;
 
5239
 
 
5240
             util::string::const_shared_ptr schema(session->schema());
 
5241
             if ($4)
 
5242
             {
 
5243
              select->setShowPredicate($4, $3->table.str);
 
5244
             }
 
5245
             else if ($3->db.str)
 
5246
             {
 
5247
              select->setShowPredicate($3->db.str, $3->table.str);
 
5248
             }
 
5249
             else if (schema)
 
5250
             {
 
5251
               select->setShowPredicate(*schema, $3->table.str);
 
5252
             }
 
5253
             else
 
5254
             {
 
5255
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5256
               DRIZZLE_YYABORT;
 
5257
             }
 
5258
 
 
5259
             {
 
5260
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5261
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5262
               {
 
5263
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5264
                            select->getShowSchema().c_str(), 
 
5265
                            $3->table.str);
 
5266
               }
 
5267
             }
 
5268
 
 
5269
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
5270
               DRIZZLE_YYABORT;
 
5271
 
 
5272
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5273
                                                           context,
 
5274
                                                           NULL, NULL, "*")))
 
5275
               DRIZZLE_YYABORT;
 
5276
             (session->lex->current_select->with_wild)++;
 
5277
          }
4391
5278
        | COUNT_SYM '(' '*' ')' WARNINGS
4392
5279
          {
4393
 
            show::buildSelectWarning(YYSession);
 
5280
            (void) create_select_for_variable("warning_count");
 
5281
            LEX *lex= Lex;
 
5282
            lex->statement= new(std::nothrow) statement::Show(YYSession);
 
5283
            if (lex->statement == NULL)
 
5284
              DRIZZLE_YYABORT;
4394
5285
          }
4395
5286
        | COUNT_SYM '(' '*' ')' ERRORS
4396
5287
          {
4397
 
            show::buildSelectError(YYSession);
 
5288
            (void) create_select_for_variable("error_count");
 
5289
            LEX *lex= Lex;
 
5290
            lex->statement= new(std::nothrow) statement::Show(YYSession);
 
5291
            if (lex->statement == NULL)
 
5292
              DRIZZLE_YYABORT;
4398
5293
          }
4399
5294
        | WARNINGS opt_limit_clause_init
4400
5295
          {
4401
 
            show::buildWarnings(YYSession);
 
5296
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5297
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
5298
            if (Lex->statement == NULL)
 
5299
              DRIZZLE_YYABORT;
4402
5300
          }
4403
5301
        | ERRORS opt_limit_clause_init
4404
5302
          {
4405
 
            show::buildErrors(YYSession);
 
5303
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5304
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
5305
            if (Lex->statement == NULL)
 
5306
              DRIZZLE_YYABORT;
4406
5307
          }
4407
5308
        | opt_var_type STATUS_SYM show_wild
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
 
          }
 
5309
           {
 
5310
             LEX *lex= Lex;
 
5311
             lex->sql_command= SQLCOM_SELECT;
 
5312
             lex->statement=
 
5313
               new(std::nothrow) statement::Show(YYSession);
 
5314
             if (lex->statement == NULL)
 
5315
               DRIZZLE_YYABORT;
 
5316
 
 
5317
             Session *session= YYSession;
 
5318
 
 
5319
             if ($1 == OPT_GLOBAL)
 
5320
             {
 
5321
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5322
                 DRIZZLE_YYABORT;
 
5323
             }
 
5324
             else
 
5325
             {
 
5326
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5327
                 DRIZZLE_YYABORT;
 
5328
             }
 
5329
 
 
5330
             std::string key("Variable_name");
 
5331
             std::string value("Value");
 
5332
 
 
5333
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5334
             my_field->is_autogenerated_name= false;
 
5335
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5336
 
 
5337
             if (session->add_item_to_list(my_field))
 
5338
               DRIZZLE_YYABORT;
 
5339
 
 
5340
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5341
             my_field->is_autogenerated_name= false;
 
5342
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5343
 
 
5344
             if (session->add_item_to_list(my_field))
 
5345
               DRIZZLE_YYABORT;
 
5346
           }
4417
5347
        | CREATE TABLE_SYM table_ident
4418
 
          {
4419
 
            if (not show::buildCreateTable(YYSession, $3))
4420
 
              DRIZZLE_YYABORT;
4421
 
          }
 
5348
           {
 
5349
             LEX *lex= Lex;
 
5350
             lex->sql_command= SQLCOM_SELECT;
 
5351
             statement::Show *select=
 
5352
               new(std::nothrow) statement::Show(YYSession);
 
5353
 
 
5354
             lex->statement= select;
 
5355
 
 
5356
             if (lex->statement == NULL)
 
5357
               DRIZZLE_YYABORT;
 
5358
 
 
5359
             Session *session= YYSession;
 
5360
 
 
5361
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
 
5362
               DRIZZLE_YYABORT;
 
5363
 
 
5364
             util::string::const_shared_ptr schema(session->schema());
 
5365
             if ($3->db.str)
 
5366
             {
 
5367
               select->setShowPredicate($3->db.str, $3->table.str);
 
5368
             }
 
5369
             else if (schema)
 
5370
             {
 
5371
               select->setShowPredicate(*schema, $3->table.str);
 
5372
             }
 
5373
             else
 
5374
             {
 
5375
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5376
               DRIZZLE_YYABORT;
 
5377
             }
 
5378
 
 
5379
             std::string key("Table");
 
5380
             std::string value("Create Table");
 
5381
 
 
5382
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5383
             my_field->is_autogenerated_name= false;
 
5384
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5385
 
 
5386
             if (session->add_item_to_list(my_field))
 
5387
               DRIZZLE_YYABORT;
 
5388
 
 
5389
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5390
             my_field->is_autogenerated_name= false;
 
5391
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5392
 
 
5393
             if (session->add_item_to_list(my_field))
 
5394
               DRIZZLE_YYABORT;
 
5395
           }
4422
5396
        | PROCESSLIST_SYM
4423
5397
          {
4424
 
            if (not show::buildProcesslist(YYSession))
4425
 
              DRIZZLE_YYABORT;
 
5398
           {
 
5399
             LEX *lex= Lex;
 
5400
             lex->sql_command= SQLCOM_SELECT;
 
5401
             lex->statement=
 
5402
               new(std::nothrow) statement::Show(YYSession);
 
5403
             if (lex->statement == NULL)
 
5404
               DRIZZLE_YYABORT;
 
5405
 
 
5406
             Session *session= YYSession;
 
5407
 
 
5408
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
5409
               DRIZZLE_YYABORT;
 
5410
 
 
5411
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5412
                                                           context,
 
5413
                                                           NULL, NULL, "*")))
 
5414
               DRIZZLE_YYABORT;
 
5415
             (session->lex->current_select->with_wild)++;
 
5416
           }
4426
5417
          }
4427
5418
        | opt_var_type  VARIABLES show_wild
4428
 
          {
4429
 
            if (not show::buildVariables(YYSession, $1))
4430
 
              DRIZZLE_YYABORT;
4431
 
          }
 
5419
           {
 
5420
             LEX *lex= Lex;
 
5421
             lex->sql_command= SQLCOM_SELECT;
 
5422
             lex->statement=
 
5423
               new(std::nothrow) statement::Show(YYSession);
 
5424
             if (lex->statement == NULL)
 
5425
               DRIZZLE_YYABORT;
 
5426
 
 
5427
             Session *session= YYSession;
 
5428
 
 
5429
             if ($1 == OPT_GLOBAL)
 
5430
             {
 
5431
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5432
                 DRIZZLE_YYABORT;
 
5433
             }
 
5434
             else
 
5435
             {
 
5436
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5437
                 DRIZZLE_YYABORT;
 
5438
             }
 
5439
 
 
5440
             std::string key("Variable_name");
 
5441
             std::string value("Value");
 
5442
 
 
5443
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5444
             my_field->is_autogenerated_name= false;
 
5445
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5446
 
 
5447
             if (session->add_item_to_list(my_field))
 
5448
               DRIZZLE_YYABORT;
 
5449
 
 
5450
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5451
             my_field->is_autogenerated_name= false;
 
5452
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5453
 
 
5454
             if (session->add_item_to_list(my_field))
 
5455
               DRIZZLE_YYABORT;
 
5456
           }
4432
5457
        | CREATE DATABASE opt_if_not_exists ident
4433
 
          {
4434
 
            if (not show::buildCreateSchema(YYSession, $4))
4435
 
              DRIZZLE_YYABORT;
4436
 
          }
 
5458
           {
 
5459
             LEX *lex= Lex;
 
5460
             lex->sql_command= SQLCOM_SELECT;
 
5461
             statement::Show *select=
 
5462
               new(std::nothrow) statement::Show(YYSession);
 
5463
 
 
5464
             lex->statement= select;
 
5465
 
 
5466
             if (lex->statement == NULL)
 
5467
               DRIZZLE_YYABORT;
 
5468
 
 
5469
             Session *session= YYSession;
 
5470
 
 
5471
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
 
5472
               DRIZZLE_YYABORT;
 
5473
 
 
5474
             util::string::const_shared_ptr schema(session->schema());
 
5475
             if ($4.str)
 
5476
             {
 
5477
              select->setShowPredicate($4.str);
 
5478
             }
 
5479
             else if (schema)
 
5480
             {
 
5481
               select->setShowPredicate(*schema);
 
5482
             }
 
5483
             else
 
5484
             {
 
5485
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5486
               DRIZZLE_YYABORT;
 
5487
             }
 
5488
 
 
5489
             std::string key("Database");
 
5490
             std::string value("Create Database");
 
5491
 
 
5492
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5493
             my_field->is_autogenerated_name= false;
 
5494
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5495
 
 
5496
             if (session->add_item_to_list(my_field))
 
5497
               DRIZZLE_YYABORT;
 
5498
 
 
5499
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5500
             my_field->is_autogenerated_name= false;
 
5501
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5502
 
 
5503
             if (session->add_item_to_list(my_field))
 
5504
               DRIZZLE_YYABORT;
 
5505
           }
4437
5506
 
4438
5507
opt_db:
4439
5508
          /* empty */  { $$= 0; }
4466
5535
describe:
4467
5536
          describe_command table_ident
4468
5537
          {
4469
 
            if (not show::buildDescribe(YYSession, $2))
4470
 
            {
 
5538
            Session *session= YYSession;
 
5539
            statement::Show *select;
 
5540
            LEX *lex= Lex;
 
5541
            lex->lock_option= TL_READ;
 
5542
            init_select(lex);
 
5543
            lex->current_select->parsing_place= SELECT_LIST;
 
5544
            lex->sql_command= SQLCOM_SELECT;
 
5545
            select= new(std::nothrow) statement::Show(session);
 
5546
            lex->statement= select;
 
5547
            if (lex->statement == NULL)
4471
5548
              DRIZZLE_YYABORT;
4472
 
            }
 
5549
            lex->select_lex.db= 0;
 
5550
 
 
5551
             util::string::const_shared_ptr schema(session->schema());
 
5552
             if ($2->db.str)
 
5553
             {
 
5554
               select->setShowPredicate($2->db.str, $2->table.str);
 
5555
             }
 
5556
             else if (schema)
 
5557
             {
 
5558
               select->setShowPredicate(*schema, $2->table.str);
 
5559
             }
 
5560
             else
 
5561
             {
 
5562
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5563
               DRIZZLE_YYABORT;
 
5564
             }
 
5565
 
 
5566
             {
 
5567
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5568
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5569
               {
 
5570
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5571
                            select->getShowSchema().c_str(), 
 
5572
                            $2->table.str);
 
5573
               }
 
5574
             }
 
5575
 
 
5576
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5577
               DRIZZLE_YYABORT;
 
5578
 
 
5579
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5580
                                                           context,
 
5581
                                                           NULL, NULL, "*")))
 
5582
             {
 
5583
               DRIZZLE_YYABORT;
 
5584
             }
 
5585
             (session->lex->current_select->with_wild)++;
 
5586
 
4473
5587
          }
4474
5588
          opt_describe_column {}
4475
5589
        | describe_command opt_extended_describe
4476
5590
          { Lex->describe|= DESCRIBE_NORMAL; }
4477
5591
          select
4478
5592
          {
4479
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5593
            LEX *lex=Lex;
 
5594
            lex->select_lex.options|= SELECT_DESCRIBE;
4480
5595
          }
4481
5596
        ;
4482
5597
 
4507
5622
flush:
4508
5623
          FLUSH_SYM
4509
5624
          {
4510
 
            Lex->statement= new statement::Flush(YYSession);
 
5625
            LEX *lex=Lex;
 
5626
            lex->sql_command= SQLCOM_FLUSH;
 
5627
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5628
            if (lex->statement == NULL)
 
5629
              DRIZZLE_YYABORT;
 
5630
            lex->type= 0;
4511
5631
          }
4512
5632
          flush_options
4513
5633
          {}
4557
5677
kill:
4558
5678
          KILL_SYM kill_option expr
4559
5679
          {
4560
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5680
            LEX *lex=Lex;
 
5681
 
 
5682
            if ($2)
 
5683
            {
 
5684
              Lex->type= ONLY_KILL_QUERY;
 
5685
            }
 
5686
            else
 
5687
            {
 
5688
              Lex->type= 0;
 
5689
            }
 
5690
 
 
5691
            lex->value_list.empty();
 
5692
            lex->value_list.push_front($3);
 
5693
            lex->sql_command= SQLCOM_KILL;
 
5694
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5695
            if (lex->statement == NULL)
 
5696
              DRIZZLE_YYABORT;
4561
5697
          }
4562
5698
        ;
4563
5699
 
4564
5700
kill_option:
4565
 
          /* empty */ { $$= false; }
4566
 
        | CONNECTION_SYM { $$= false; }
4567
 
        | QUERY_SYM      { $$= true; }
 
5701
          /* empty */ { $$= 0; }
 
5702
        | CONNECTION_SYM { $$= 0; }
 
5703
        | QUERY_SYM      { $$= 1; }
4568
5704
        ;
4569
5705
 
4570
5706
/* change database */
4571
5707
 
4572
5708
use:
4573
 
          USE_SYM schema_name
 
5709
          USE_SYM ident
4574
5710
          {
4575
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4576
 
            Lex->select_lex.db= $2.str;
 
5711
            LEX *lex=Lex;
 
5712
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5713
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5714
            if (lex->statement == NULL)
 
5715
              DRIZZLE_YYABORT;
 
5716
            lex->select_lex.db= $2.str;
4577
5717
          }
4578
5718
        ;
4579
5719
 
4582
5722
load:
4583
5723
          LOAD data_file
4584
5724
          {
4585
 
            statement::Load *statement= new statement::Load(YYSession);
4586
 
            Lex->statement= statement;
4587
 
 
4588
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5725
            Session *session= YYSession;
 
5726
            LEX *lex= session->lex;
 
5727
 
 
5728
            lex->sql_command= SQLCOM_LOAD;
 
5729
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5730
            lex->statement= statement;
 
5731
            if (lex->statement == NULL)
 
5732
              DRIZZLE_YYABORT;
 
5733
 
 
5734
            Lex_input_stream *lip= session->m_lip;
4589
5735
            statement->fname_start= lip->get_ptr();
4590
5736
          }
4591
5737
          load_data_lock INFILE TEXT_STRING_filesystem
4592
5738
          {
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)))
 
5739
            LEX *lex=Lex;
 
5740
            lex->lock_option= $4;
 
5741
            lex->duplicates= DUP_ERROR;
 
5742
            lex->ignore= 0;
 
5743
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4597
5744
              DRIZZLE_YYABORT;
4598
5745
          }
4599
5746
          opt_duplicate INTO
4600
5747
          {
4601
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5748
            Session *session= YYSession;
 
5749
            Lex_input_stream *lip= session->m_lip;
4602
5750
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4603
5751
          }
4604
5752
          TABLE_SYM table_ident
4605
5753
          {
 
5754
            LEX *lex=Lex;
4606
5755
            if (!Lex->current_select->add_table_to_list(YYSession,
4607
5756
                    $12, NULL, TL_OPTION_UPDATING,
4608
 
                    Lex->lock_option))
 
5757
                    lex->lock_option))
4609
5758
              DRIZZLE_YYABORT;
4610
 
            Lex->field_list.empty();
4611
 
            Lex->update_list.empty();
4612
 
            Lex->value_list.empty();
 
5759
            lex->field_list.empty();
 
5760
            lex->update_list.empty();
 
5761
            lex->value_list.empty();
4613
5762
          }
4614
5763
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4615
5764
          opt_load_data_set_spec
4633
5782
        | IGNORE_SYM { Lex->ignore= 1; }
4634
5783
        ;
4635
5784
 
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
 
 
4645
5785
opt_field_term:
4646
5786
          /* empty */
4647
5787
        | COLUMNS field_term_list
4660
5800
          }
4661
5801
        | OPTIONALLY ENCLOSED BY text_string
4662
5802
          {
4663
 
            assert(Lex->exchange != 0);
4664
 
            Lex->exchange->enclosed= $4;
4665
 
            Lex->exchange->opt_enclosed= 1;
 
5803
            LEX *lex= Lex;
 
5804
            assert(lex->exchange != 0);
 
5805
            lex->exchange->enclosed= $4;
 
5806
            lex->exchange->opt_enclosed= 1;
4666
5807
          }
4667
5808
        | ENCLOSED BY text_string
4668
5809
          {
4727
5868
        ;
4728
5869
 
4729
5870
field_or_var:
4730
 
          simple_ident {$$= $1;}
4731
 
        | '@' user_variable_ident
 
5871
          simple_ident_nospvar {$$= $1;}
 
5872
        | '@' ident_or_text
4732
5873
          { $$= new Item_user_var_as_out_param($2); }
4733
5874
        ;
4734
5875
 
4742
5883
text_literal:
4743
5884
        TEXT_STRING_literal
4744
5885
        {
4745
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5886
          Session *session= YYSession;
 
5887
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4746
5888
        }
4747
5889
        | text_literal TEXT_STRING_literal
4748
5890
          {
4798
5940
            $$ = new Item_null();
4799
5941
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4800
5942
          }
4801
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4802
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5943
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5944
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4803
5945
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4804
5946
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4805
5947
        | DATE_SYM text_literal { $$ = $2; }
4842
5984
**********************************************************************/
4843
5985
 
4844
5986
insert_ident:
4845
 
          simple_ident { $$=$1; }
 
5987
          simple_ident_nospvar { $$=$1; }
4846
5988
        | table_wild { $$=$1; }
4847
5989
        ;
4848
5990
 
4849
5991
table_wild:
4850
5992
          ident '.' '*'
4851
5993
          {
4852
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5994
            Select_Lex *sel= Lex->current_select;
 
5995
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5996
            sel->with_wild++;
4853
5997
          }
4854
5998
        | ident '.' ident '.' '*'
4855
5999
          {
4856
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
6000
            Select_Lex *sel= Lex->current_select;
 
6001
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
6002
            sel->with_wild++;
4857
6003
          }
4858
6004
        ;
4859
6005
 
4864
6010
simple_ident:
4865
6011
          ident
4866
6012
          {
4867
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
6013
            {
 
6014
              Select_Lex *sel=Lex->current_select;
 
6015
              $$= (sel->parsing_place != IN_HAVING ||
 
6016
                  sel->get_in_sum_expr() > 0) ?
 
6017
                  (Item*) new Item_field(Lex->current_context(),
 
6018
                                         (const char *)NULL, NULL, $1.str) :
 
6019
                  (Item*) new Item_ref(Lex->current_context(),
 
6020
                                       (const char *)NULL, NULL, $1.str);
 
6021
            }
 
6022
          }
 
6023
        | simple_ident_q { $$= $1; }
 
6024
        ;
 
6025
 
 
6026
simple_ident_nospvar:
 
6027
          ident
 
6028
          {
 
6029
            Select_Lex *sel=Lex->current_select;
 
6030
            $$= (sel->parsing_place != IN_HAVING ||
 
6031
                sel->get_in_sum_expr() > 0) ?
 
6032
                (Item*) new Item_field(Lex->current_context(),
 
6033
                                       (const char *)NULL, NULL, $1.str) :
 
6034
                (Item*) new Item_ref(Lex->current_context(),
 
6035
                                     (const char *)NULL, NULL, $1.str);
4868
6036
          }
4869
6037
        | simple_ident_q { $$= $1; }
4870
6038
        ;
4872
6040
simple_ident_q:
4873
6041
          ident '.' ident
4874
6042
          {
4875
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
6043
            Session *session= YYSession;
 
6044
            LEX *lex= session->lex;
 
6045
 
 
6046
            {
 
6047
              Select_Lex *sel= lex->current_select;
 
6048
              if (sel->no_table_names_allowed)
 
6049
              {
 
6050
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6051
                         MYF(0), $1.str, session->where);
 
6052
              }
 
6053
              $$= (sel->parsing_place != IN_HAVING ||
 
6054
                  sel->get_in_sum_expr() > 0) ?
 
6055
                  (Item*) new Item_field(Lex->current_context(),
 
6056
                                         (const char *)NULL, $1.str, $3.str) :
 
6057
                  (Item*) new Item_ref(Lex->current_context(),
 
6058
                                       (const char *)NULL, $1.str, $3.str);
 
6059
            }
4876
6060
          }
4877
6061
        | '.' ident '.' ident
4878
6062
          {
4879
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
6063
            Session *session= YYSession;
 
6064
            LEX *lex= session->lex;
 
6065
            Select_Lex *sel= lex->current_select;
 
6066
            if (sel->no_table_names_allowed)
 
6067
            {
 
6068
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6069
                       MYF(0), $2.str, session->where);
 
6070
            }
 
6071
            $$= (sel->parsing_place != IN_HAVING ||
 
6072
                sel->get_in_sum_expr() > 0) ?
 
6073
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
6074
                (Item*) new Item_ref(Lex->current_context(),
 
6075
                                     (const char *)NULL, $2.str, $4.str);
4880
6076
          }
4881
6077
        | ident '.' ident '.' ident
4882
6078
          {
4883
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
6079
            Session *session= YYSession;
 
6080
            LEX *lex= session->lex;
 
6081
            Select_Lex *sel= lex->current_select;
 
6082
            if (sel->no_table_names_allowed)
 
6083
            {
 
6084
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6085
                       MYF(0), $3.str, session->where);
 
6086
            }
 
6087
            $$= (sel->parsing_place != IN_HAVING ||
 
6088
                sel->get_in_sum_expr() > 0) ?
 
6089
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
6090
                                       $5.str) :
 
6091
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
6092
                                     $5.str);
4884
6093
          }
4885
6094
        ;
4886
6095
 
4887
6096
field_ident:
4888
 
          ident 
4889
 
          {
4890
 
            $$=$1;
4891
 
          }
 
6097
          ident { $$=$1;}
4892
6098
        | ident '.' ident '.' ident
4893
6099
          {
4894
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4895
 
              DRIZZLE_YYABORT;
4896
 
 
 
6100
            TableList *table=
 
6101
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
6102
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
 
6103
            {
 
6104
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
6105
              DRIZZLE_YYABORT;
 
6106
            }
 
6107
            if (my_strcasecmp(table_alias_charset, $3.str,
 
6108
                              table->getTableName()))
 
6109
            {
 
6110
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
6111
              DRIZZLE_YYABORT;
 
6112
            }
4897
6113
            $$=$5;
4898
6114
          }
4899
6115
        | ident '.' ident
4900
6116
          {
4901
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
6117
            TableList *table=
 
6118
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
6119
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
6120
            {
 
6121
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6122
              DRIZZLE_YYABORT;
4903
 
 
 
6123
            }
4904
6124
            $$=$3;
4905
6125
          }
4906
 
        | '.' ident 
4907
 
          { /* For Delphi */
4908
 
            $$=$2;
4909
 
          }
 
6126
        | '.' ident { $$=$2;} /* For Delphi */
4910
6127
        ;
4911
6128
 
4912
6129
table_ident:
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
 
6130
          ident { $$=new Table_ident($1); }
 
6131
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
6132
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4933
6133
        ;
4934
6134
 
4935
6135
IDENT_sys:
4936
 
          IDENT 
4937
 
          {
4938
 
            $$= $1;
4939
 
          }
 
6136
          IDENT { $$= $1; }
4940
6137
        | IDENT_QUOTED
4941
6138
          {
4942
6139
            const CHARSET_INFO * const cs= system_charset_info;
4979
6176
          IDENT_sys    { $$=$1; }
4980
6177
        | keyword
4981
6178
          {
4982
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
6179
            Session *session= YYSession;
 
6180
            $$.str= session->strmake($1.str, $1.length);
4983
6181
            $$.length= $1.length;
4984
6182
          }
4985
6183
        ;
4986
6184
 
4987
6185
ident_or_text:
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          {}
 
6186
          ident           { $$=$1;}
 
6187
        | TEXT_STRING_sys { $$=$1;}
 
6188
        | LEX_HOSTNAME { $$=$1;}
5001
6189
        ;
5002
6190
 
5003
6191
/* Keyword that we allow for identifiers (except SP labels) */
5004
6192
keyword:
5005
6193
          keyword_sp            {}
5006
6194
        | BEGIN_SYM             {}
 
6195
        | BYTE_SYM              {}
5007
6196
        | CHECKSUM_SYM          {}
5008
6197
        | CLOSE_SYM             {}
5009
6198
        | COMMENT_SYM           {}
5010
6199
        | COMMIT_SYM            {}
5011
6200
        | CONTAINS_SYM          {}
5012
6201
        | DEALLOCATE_SYM        {}
5013
 
        | DO_SYM                {}
5014
6202
        | END                   {}
5015
6203
        | FLUSH_SYM             {}
5016
6204
        | NO_SYM                {}
5019
6207
        | SAVEPOINT_SYM         {}
5020
6208
        | SECURITY_SYM          {}
5021
6209
        | SERVER_SYM            {}
5022
 
        | SIGNED_SYM            {}
5023
6210
        | START_SYM             {}
5024
6211
        | STOP_SYM              {}
5025
6212
        | TRUNCATE_SYM          {}
5039
6226
        | ANY_SYM                  {}
5040
6227
        | AT_SYM                   {}
5041
6228
        | AUTO_INC                 {}
 
6229
        | AVG_ROW_LENGTH           {}
5042
6230
        | AVG_SYM                  {}
5043
6231
        | BIT_SYM                  {}
5044
6232
        | BOOL_SYM                 {}
5048
6236
        | CHAIN_SYM                {}
5049
6237
        | COALESCE                 {}
5050
6238
        | COLLATION_SYM            {}
 
6239
        | COLUMN_FORMAT_SYM        {}
5051
6240
        | COLUMNS                  {}
5052
6241
        | COMMITTED_SYM            {}
5053
6242
        | COMPACT_SYM              {}
5054
6243
        | COMPRESSED_SYM           {}
5055
6244
        | CONCURRENT               {}
5056
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
6245
        | CONNECTION_SYM           {}
5057
6246
        | CONSISTENT_SYM           {}
5058
6247
        | CUBE_SYM                 {}
5059
6248
        | DATA_SYM                 {}
5060
6249
        | DATABASES                {}
 
6250
        | DATAFILE_SYM             {}
5061
6251
        | DATETIME_SYM             {}
5062
 
        | DATE_SYM                 {} /* Create conflict */
 
6252
        | DATE_SYM                 {}
5063
6253
        | DAY_SYM                  {}
5064
6254
        | DISABLE_SYM              {}
5065
6255
        | DISCARD                  {}
5090
6280
        | KEY_BLOCK_SIZE           {}
5091
6281
        | LAST_SYM                 {}
5092
6282
        | LEVEL_SYM                {}
 
6283
        | LIST_SYM                 {}
5093
6284
        | LOCAL_SYM                {}
5094
6285
        | LOCKS_SYM                {}
5095
6286
        | LOGS_SYM                 {}
 
6287
        | MAX_ROWS                 {}
 
6288
        | MAX_SIZE_SYM             {}
5096
6289
        | MAX_VALUE_SYM            {}
5097
6290
        | MEDIUM_SYM               {}
5098
6291
        | MERGE_SYM                {}
5099
6292
        | MICROSECOND_SYM          {}
5100
6293
        | MINUTE_SYM               {}
 
6294
        | MIN_ROWS                 {}
5101
6295
        | MODIFY_SYM               {}
5102
6296
        | MODE_SYM                 {}
5103
6297
        | MONTH_SYM                {}
5112
6306
        | ONE_SHOT_SYM             {}
5113
6307
        | ONE_SYM                  {}
5114
6308
        | ONLINE_SYM               {}
 
6309
        | PAGE_SYM                 {}
5115
6310
        | PARTIAL                  {}
 
6311
        | PHASE_SYM                {}
5116
6312
        | PREV_SYM                 {}
5117
6313
        | PROCESS                  {}
5118
6314
        | PROCESSLIST_SYM          {}
5119
6315
        | QUARTER_SYM              {}
5120
 
        | QUERY_SYM                {} // Causes conflict
 
6316
        | QUERY_SYM                {}
 
6317
        | READ_ONLY_SYM            {}
5121
6318
        | REDUNDANT_SYM            {}
5122
6319
        | REPEATABLE_SYM           {}
5123
6320
        | RETURNS_SYM              {}
 
6321
        | REVERSE_SYM              {}
5124
6322
        | ROLLUP_SYM               {}
5125
6323
        | ROUTINE_SYM              {}
5126
6324
        | ROWS_SYM                 {}
5133
6331
        | SIMPLE_SYM               {}
5134
6332
        | SHARE_SYM                {}
5135
6333
        | SNAPSHOT_SYM             {}
 
6334
        | SQL_BUFFER_RESULT        {}
5136
6335
        | STATUS_SYM               {}
 
6336
        | STORAGE_SYM              {}
5137
6337
        | STRING_SYM               {}
5138
6338
        | SUBDATE_SYM              {}
5139
6339
        | SUBJECT_SYM              {}
5140
6340
        | SUSPEND_SYM              {}
 
6341
        | SWAPS_SYM                {}
 
6342
        | SWITCHES_SYM             {}
5141
6343
        | TABLES                   {}
5142
6344
        | TABLESPACE               {}
5143
6345
        | TEMPORARY_SYM            {}
5144
6346
        | TEXT_SYM                 {}
5145
6347
        | TRANSACTION_SYM          {}
5146
6348
        | TIME_SYM                 {}
 
6349
        | TIMESTAMP_SYM            {}
5147
6350
        | TIMESTAMP_ADD            {}
5148
6351
        | TIMESTAMP_DIFF           {}
 
6352
        | TYPES_SYM                {}
5149
6353
        | TYPE_SYM                 {}
5150
6354
        | UNCOMMITTED_SYM          {}
5151
6355
        | UNDOFILE_SYM             {}
5152
6356
        | UNKNOWN_SYM              {}
5153
 
        | UUID_SYM                 {}
5154
6357
        | USER                     {}
5155
6358
        | VARIABLES                {}
5156
6359
        | VALUE_SYM                {}
5165
6368
set:
5166
6369
          SET_SYM opt_option
5167
6370
          {
5168
 
            Lex->statement= new statement::SetOption(YYSession);
 
6371
            LEX *lex=Lex;
 
6372
            lex->sql_command= SQLCOM_SET_OPTION;
 
6373
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
6374
            lex->statement= statement;
 
6375
            if (lex->statement == NULL)
 
6376
              DRIZZLE_YYABORT;
 
6377
            init_select(lex);
 
6378
            lex->option_type=OPT_SESSION;
 
6379
            lex->var_list.empty();
5169
6380
          }
5170
6381
          option_value_list
5171
6382
          {}
5182
6393
        ;
5183
6394
 
5184
6395
option_type_value:
5185
 
          { }
 
6396
          {
 
6397
          }
5186
6398
          ext_option_value
5187
 
          { }
 
6399
          {
 
6400
          }
5188
6401
        ;
5189
6402
 
5190
6403
option_type:
5221
6434
sys_option_value:
5222
6435
          option_type internal_variable_name equal set_expr_or_default
5223
6436
          {
 
6437
            LEX *lex=Lex;
 
6438
 
5224
6439
            if ($2.var)
5225
6440
            { /* System variable */
5226
6441
              if ($1)
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)));
 
6442
                lex->option_type= $1;
 
6443
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6444
                                      &$2.base_name, $4));
5231
6445
            }
5232
6446
          }
5233
6447
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5234
6448
          {
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))));
 
6449
            LEX *lex=Lex;
 
6450
            lex->option_type= $1;
 
6451
            lex->var_list.push_back(new set_var(lex->option_type,
 
6452
                                                find_sys_var("tx_isolation"),
 
6453
                                                &null_lex_str,
 
6454
                                                new Item_int((int32_t) $5)));
5241
6455
          }
5242
6456
        ;
5243
6457
 
5244
6458
option_value:
5245
 
          '@' user_variable_ident equal expr
 
6459
          '@' ident_or_text equal expr
5246
6460
          {
5247
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6461
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5248
6462
          }
5249
6463
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5250
6464
          {
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; }
 
6465
            LEX *lex=Lex;
 
6466
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6467
          }
5268
6468
        ;
5269
6469
 
5270
6470
internal_variable_name:
5271
 
          internal_variable_ident
 
6471
          ident
5272
6472
          {
5273
6473
            /* We have to lookup here since local vars can shadow sysvars */
5274
6474
            {
5275
6475
              /* Not an SP local variable */
5276
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6476
              sys_var *tmp=find_sys_var($1.str, $1.length);
5277
6477
              if (!tmp)
5278
6478
                DRIZZLE_YYABORT;
5279
6479
              $$.var= tmp;
5305
6505
unlock:
5306
6506
          UNLOCK_SYM
5307
6507
          {
5308
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6508
            LEX *lex= Lex;
 
6509
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6510
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6511
            if (lex->statement == NULL)
 
6512
              DRIZZLE_YYABORT;
5309
6513
          }
5310
6514
          table_or_tables
5311
6515
          {}
5314
6518
begin:
5315
6519
          BEGIN_SYM
5316
6520
          {
5317
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6521
            LEX *lex=Lex;
 
6522
            lex->sql_command = SQLCOM_BEGIN;
 
6523
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6524
            if (lex->statement == NULL)
 
6525
              DRIZZLE_YYABORT;
5318
6526
          }
5319
6527
          opt_work {}
5320
6528
        ;
5346
6554
commit:
5347
6555
          COMMIT_SYM opt_work opt_chain opt_release
5348
6556
          {
5349
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6557
            LEX *lex=Lex;
 
6558
            lex->sql_command= SQLCOM_COMMIT;
 
6559
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6560
            lex->statement= statement;
 
6561
            if (lex->statement == NULL)
 
6562
              DRIZZLE_YYABORT;
 
6563
            statement->tx_chain= $3;
 
6564
            statement->tx_release= $4;
5350
6565
          }
5351
6566
        ;
5352
6567
 
5353
6568
rollback:
5354
6569
          ROLLBACK_SYM opt_work opt_chain opt_release
5355
6570
          {
5356
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6571
            LEX *lex=Lex;
 
6572
            lex->sql_command= SQLCOM_ROLLBACK;
 
6573
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6574
            lex->statement= statement;
 
6575
            if (lex->statement == NULL)
 
6576
              DRIZZLE_YYABORT;
 
6577
            statement->tx_chain= $3;
 
6578
            statement->tx_release= $4;
5357
6579
          }
5358
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6580
        | ROLLBACK_SYM opt_work
 
6581
          TO_SYM opt_savepoint ident
5359
6582
          {
5360
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6583
            LEX *lex=Lex;
 
6584
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6585
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6586
            if (lex->statement == NULL)
 
6587
              DRIZZLE_YYABORT;
 
6588
            lex->ident= $5;
5361
6589
          }
5362
6590
        ;
5363
6591
 
5364
6592
savepoint:
5365
 
          SAVEPOINT_SYM savepoint_ident
 
6593
          SAVEPOINT_SYM ident
5366
6594
          {
5367
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6595
            LEX *lex=Lex;
 
6596
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6597
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6598
            if (lex->statement == NULL)
 
6599
              DRIZZLE_YYABORT;
 
6600
            lex->ident= $2;
5368
6601
          }
5369
6602
        ;
5370
6603
 
5371
6604
release:
5372
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6605
          RELEASE_SYM SAVEPOINT_SYM ident
5373
6606
          {
5374
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6607
            LEX *lex=Lex;
 
6608
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6609
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6610
            if (lex->statement == NULL)
 
6611
              DRIZZLE_YYABORT;
 
6612
            lex->ident= $3;
5375
6613
          }
5376
6614
        ;
5377
6615
 
5378
 
savepoint_ident:
5379
 
               IDENT_sys
5380
 
               ;
5381
 
 
5382
6616
/*
5383
6617
   UNIONS : glue selects together
5384
6618
*/
5392
6626
union_list:
5393
6627
          UNION_SYM union_option
5394
6628
          {
5395
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6629
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5396
6630
              DRIZZLE_YYABORT;
5397
6631
          }
5398
6632
          select_init
5413
6647
 
5414
6648
union_order_or_limit:
5415
6649
          {
5416
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5417
 
            Select_Lex *sel= Lex->current_select;
 
6650
            Session *session= YYSession;
 
6651
            LEX *lex= session->lex;
 
6652
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6653
            Select_Lex *sel= lex->current_select;
5418
6654
            Select_Lex_Unit *unit= sel->master_unit();
5419
6655
            Select_Lex *fake= unit->fake_select_lex;
5420
6656
            if (fake)
5421
6657
            {
5422
6658
              unit->global_parameters= fake;
5423
6659
              fake->no_table_names_allowed= 1;
5424
 
              Lex->current_select= fake;
 
6660
              lex->current_select= fake;
5425
6661
            }
5426
 
            YYSession->setWhere("global ORDER clause");
 
6662
            session->where= "global ORDER clause";
5427
6663
          }
5428
6664
          order_or_limit
5429
6665
          {
5430
 
            YYSession->lex->current_select->no_table_names_allowed= 0;
5431
 
            YYSession->setWhere("");
 
6666
            Session *session= YYSession;
 
6667
            session->lex->current_select->no_table_names_allowed= 0;
 
6668
            session->where= "";
5432
6669
          }
5433
6670
        ;
5434
6671
 
5459
6696
        | query_expression_body
5460
6697
          UNION_SYM union_option
5461
6698
          {
5462
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6699
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5463
6700
              DRIZZLE_YYABORT;
5464
6701
          }
5465
6702
          query_specification
5479
6716
 
5480
6717
subselect_start:
5481
6718
          {
5482
 
            if (not Lex->expr_allows_subselect)
 
6719
            LEX *lex=Lex;
 
6720
            if (!lex->expr_allows_subselect)
5483
6721
            {
5484
 
              parser::my_parse_error(YYSession->m_lip);
 
6722
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6723
              my_parse_error(&pass);
5485
6724
              DRIZZLE_YYABORT;
5486
6725
            }
5487
6726
            /*
5498
6737
 
5499
6738
subselect_end:
5500
6739
          {
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;
 
6740
            LEX *lex=Lex;
 
6741
            lex->pop_context();
 
6742
            Select_Lex *child= lex->current_select;
 
6743
            lex->current_select = lex->current_select->return_after_parsing();
 
6744
            lex->nest_level--;
 
6745
            lex->current_select->n_child_sum_items += child->n_sum_items;
5506
6746
            /*
5507
6747
              A subselect can add fields to an outer select. Reserve space for
5508
6748
              them.
5509
6749
            */
5510
 
            Lex->current_select->select_n_where_fields+=
 
6750
            lex->current_select->select_n_where_fields+=
5511
6751
            child->select_n_where_fields;
5512
6752
          }
5513
6753
        ;