~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2010-12-30 04:59:36 UTC
  • mto: (2040.1.2 clean) (2041.2.1 clean)
  • mto: This revision was merged to the branch mainline in revision 2041.
  • Revision ID: brian@tangent.org-20101230045936-r1i4sek9qotl8abq
result_type() to display the internal type.

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
 
88
90
}
89
91
 
90
92
 
 
93
static bool check_reserved_words(LEX_STRING *name)
 
94
{
 
95
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
 
96
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
 
97
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
 
98
    return true;
 
99
  return false;
 
100
}
 
101
 
 
102
/**
 
103
  @brief Push an error message into MySQL error stack with line
 
104
  and position information.
 
105
 
 
106
  This function provides semantic action implementers with a way
 
107
  to push the famous "You have a syntax error near..." error
 
108
  message into the error stack, which is normally produced only if
 
109
  a parse error is discovered internally by the Bison generated
 
110
  parser.
 
111
*/
 
112
 
 
113
struct my_parse_error_st {
 
114
  const char *s;
 
115
  Session *session;
 
116
};
 
117
 
 
118
static void my_parse_error(void *arg)
 
119
{
 
120
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
 
121
 
 
122
  const char *s= ptr->s;
 
123
  Session *session= ptr->session;
 
124
 
 
125
  Lex_input_stream *lip= session->m_lip;
 
126
 
 
127
  const char *yytext= lip->get_tok_start();
 
128
  /* Push an error into the error stack */
 
129
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
130
                  (yytext ? yytext : ""),
 
131
                  lip->yylineno);
 
132
}
 
133
 
91
134
/**
92
135
  @brief Bison callback to report a syntax/OOM error
93
136
 
103
146
 
104
147
  This function is not for use in semantic actions and is internal to
105
148
  the parser, as it performs some pre-return cleanup.
106
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
149
  In semantic actions, please use my_parse_error or my_error to
107
150
  push an error into the error stack and DRIZZLE_YYABORT
108
151
  to abort from the parser.
109
152
*/
110
153
 
111
154
static void DRIZZLEerror(const char *s)
112
155
{
113
 
  parser::errorOn(s);
 
156
  Session *session= current_session;
 
157
 
 
158
  /*
 
159
    Restore the original LEX if it was replaced when parsing
 
160
    a stored procedure. We must ensure that a parsing error
 
161
    does not leave any side effects in the Session.
 
162
  */
 
163
  LEX::cleanup_lex_after_parse_error(session);
 
164
 
 
165
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
166
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
167
    s= ER(ER_SYNTAX_ERROR);
 
168
 
 
169
  struct my_parse_error_st pass= { s, session };
 
170
  my_parse_error(&pass);
 
171
}
 
172
 
 
173
/**
 
174
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
175
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
176
  This function returns the proper item for the SQL expression
 
177
  <code>left [NOT] IN ( expr )</code>
 
178
  @param session the current thread
 
179
  @param left the in predicand
 
180
  @param equal true for IN predicates, false for NOT IN predicates
 
181
  @param expr first and only expression of the in value list
 
182
  @return an expression representing the IN predicate.
 
183
*/
 
184
static Item* handle_sql2003_note184_exception(Session *session,
 
185
                                              Item* left, bool equal,
 
186
                                              Item *expr)
 
187
{
 
188
  /*
 
189
    Relevant references for this issue:
 
190
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
191
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
192
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
193
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
194
    - SQL:2003 Feature F561, "Full value expressions".
 
195
 
 
196
    The exception in SQL:2003 Note 184 means:
 
197
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
198
    should be re-interpreted as an Item_in_subselect, which corresponds
 
199
    to a <table subquery> when used inside an <in predicate>.
 
200
 
 
201
    Our reading of Note 184 is reccursive, so that all:
 
202
    - IN (( <subquery> ))
 
203
    - IN ((( <subquery> )))
 
204
    - IN '('^N <subquery> ')'^N
 
205
    - etc
 
206
    should be interpreted as a <table subquery>, no matter how deep in the
 
207
    expression the <subquery> is.
 
208
  */
 
209
 
 
210
  Item *result;
 
211
 
 
212
  if (expr->type() == Item::SUBSELECT_ITEM)
 
213
  {
 
214
    Item_subselect *expr2 = (Item_subselect*) expr;
 
215
 
 
216
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
217
    {
 
218
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
219
      Select_Lex *subselect;
 
220
 
 
221
      /*
 
222
        Implement the mandated change, by altering the semantic tree:
 
223
          left IN Item_singlerow_subselect(subselect)
 
224
        is modified to
 
225
          left IN (subselect)
 
226
        which is represented as
 
227
          Item_in_subselect(left, subselect)
 
228
      */
 
229
      subselect= expr3->invalidate_and_restore_select_lex();
 
230
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
231
 
 
232
      if (! equal)
 
233
        result = negate_expression(session, result);
 
234
 
 
235
      return(result);
 
236
    }
 
237
  }
 
238
 
 
239
  if (equal)
 
240
    result= new (session->mem_root) Item_func_eq(left, expr);
 
241
  else
 
242
    result= new (session->mem_root) Item_func_ne(left, expr);
 
243
 
 
244
  return(result);
 
245
}
 
246
 
 
247
/**
 
248
   @brief Creates a new Select_Lex for a UNION branch.
 
249
 
 
250
   Sets up and initializes a Select_Lex structure for a query once the parser
 
251
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
252
   the new Select_Lex becomes the current one..=
 
253
 
 
254
   @lex The parser state.
 
255
 
 
256
   @is_union_distinct True if the union preceding the new select statement
 
257
   uses UNION DISTINCT.
 
258
 
 
259
   @return <code>false</code> if successful, <code>true</code> if an error was
 
260
   reported. In the latter case parsing should stop.
 
261
 */
 
262
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
 
263
{
 
264
  if (lex->result)
 
265
  {
 
266
    /* Only the last SELECT can have  INTO...... */
 
267
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
268
    return true;
 
269
  }
 
270
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
271
  {
 
272
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
273
    my_parse_error(&pass);
 
274
    return true;
 
275
  }
 
276
  /* This counter shouldn't be incremented for UNION parts */
 
277
  lex->nest_level--;
 
278
  if (new_select(lex, 0))
 
279
    return true;
 
280
  init_select(lex);
 
281
  lex->current_select->linkage=UNION_TYPE;
 
282
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
283
    lex->current_select->master_unit()->union_distinct=
 
284
      lex->current_select;
 
285
  return false;
 
286
}
 
287
 
 
288
/**
 
289
   @brief Initializes a Select_Lex for a query within parentheses (aka
 
290
   braces).
 
291
 
 
292
   @return false if successful, true if an error was reported. In the latter
 
293
   case parsing should stop.
 
294
 */
 
295
static bool setup_select_in_parentheses(Session *session, LEX *lex)
 
296
{
 
297
  Select_Lex * sel= lex->current_select;
 
298
  if (sel->set_braces(1))
 
299
  {
 
300
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
301
    my_parse_error(&pass);
 
302
    return true;
 
303
  }
 
304
  if (sel->linkage == UNION_TYPE &&
 
305
      !sel->master_unit()->first_select()->braces &&
 
306
      sel->master_unit()->first_select()->linkage ==
 
307
      UNION_TYPE)
 
308
  {
 
309
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
310
    my_parse_error(&pass);
 
311
    return true;
 
312
  }
 
313
  if (sel->linkage == UNION_TYPE &&
 
314
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
315
      sel->master_unit()->fake_select_lex)
 
316
  {
 
317
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
318
    return true;
 
319
  }
 
320
  /* select in braces, can't contain global parameters */
 
321
  if (sel->master_unit()->fake_select_lex)
 
322
    sel->master_unit()->global_parameters=
 
323
      sel->master_unit()->fake_select_lex;
 
324
  return false;
 
325
}
 
326
 
 
327
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
 
328
{
 
329
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
 
330
  Item *item= NULL;
 
331
 
 
332
  if (udf)
 
333
  {
 
334
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
 
335
  } else {
 
336
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
337
  }
 
338
 
 
339
  return item;
114
340
}
115
341
 
116
342
} /* namespace drizzled; */
118
344
using namespace drizzled;
119
345
%}
120
346
%union {
121
 
  bool boolean;
122
347
  int  num;
123
 
  unsigned long ulong_num;
 
348
  ulong ulong_num;
124
349
  uint64_t ulonglong_number;
125
350
  int64_t longlong_number;
126
351
  drizzled::LEX_STRING lex_str;
136
361
  drizzled::Key_part_spec *key_part;
137
362
  const drizzled::plugin::Function *udf;
138
363
  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;
 
364
  struct drizzled::sys_var_with_base variable;
 
365
  enum drizzled::sql_var_t var_type;
142
366
  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;
 
367
  enum drizzled::ha_key_alg key_alg;
 
368
  enum drizzled::column_format_type column_format_type;
 
369
  enum drizzled::ha_rkey_function ha_rkey_mode;
 
370
  enum drizzled::enum_tx_isolation tx_isolation;
 
371
  enum drizzled::Cast_target cast_type;
147
372
  const drizzled::CHARSET_INFO *charset;
148
373
  drizzled::thr_lock_type lock_type;
149
374
  drizzled::interval_type interval, interval_time_st;
150
 
  drizzled::type::timestamp_t date_time_type;
 
375
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
151
376
  drizzled::Select_Lex *select_lex;
152
377
  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;
 
378
  struct drizzled::st_lex *lex;
 
379
  enum drizzled::index_hint_type index_hint;
 
380
  enum drizzled::enum_filetype filetype;
 
381
  enum drizzled::ha_build_method build_method;
157
382
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
158
383
  drizzled::execute_string_t execute_string;
159
384
}
161
386
%{
162
387
namespace drizzled
163
388
{
164
 
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
 
389
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
165
390
}
166
391
%}
167
392
 
168
 
%debug
169
393
%pure_parser                                    /* We have threads */
170
 
 
171
394
/*
172
 
  Currently there are 70 shift/reduce conflicts.
 
395
  Currently there are 88 shift/reduce conflicts.
173
396
  We should not introduce new conflicts any more.
174
397
*/
175
 
%expect 70
 
398
%expect 95
176
399
 
177
400
/*
178
401
   Comments for TOKENS.
207
430
%token  ASENSITIVE_SYM                /* FUTURE-USE */
208
431
%token  AT_SYM                        /* SQL-2003-R */
209
432
%token  AUTO_INC
 
433
%token  AVG_ROW_LENGTH
210
434
%token  AVG_SYM                       /* SQL-2003-N */
211
435
%token  BEFORE_SYM                    /* SQL-2003-N */
212
436
%token  BEGIN_SYM                     /* SQL-2003-R */
221
445
%token  BOTH                          /* SQL-2003-R */
222
446
%token  BTREE_SYM
223
447
%token  BY                            /* SQL-2003-R */
 
448
%token  BYTE_SYM
224
449
%token  CALL_SYM                      /* SQL-2003-R */
225
450
%token  CASCADE                       /* SQL-2003-N */
226
451
%token  CASCADED                      /* SQL-2003-R */
227
452
%token  CASE_SYM                      /* SQL-2003-R */
228
453
%token  CAST_SYM                      /* SQL-2003-R */
229
 
%token  CATALOG_SYM
230
454
%token  CHAIN_SYM                     /* SQL-2003-N */
231
455
%token  CHANGE_SYM
232
456
%token  CHAR_SYM                      /* SQL-2003-R */
249
473
%token  CONSISTENT_SYM
250
474
%token  CONSTRAINT                    /* SQL-2003-R */
251
475
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
476
%token  CONTINUE_SYM                  /* SQL-2003-R */
252
477
%token  CONVERT_SYM                   /* SQL-2003-N */
253
478
%token  COUNT_SYM                     /* SQL-2003-N */
254
479
%token  CREATE                        /* SQL-2003-R */
259
484
%token  CURSOR_SYM                    /* SQL-2003-R */
260
485
%token  DATABASE
261
486
%token  DATABASES
 
487
%token  DATAFILE_SYM
262
488
%token  DATA_SYM                      /* SQL-2003-N */
263
489
%token  DATETIME_SYM
264
490
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
282
508
%token  DISCARD
283
509
%token  DISTINCT                      /* SQL-2003-R */
284
510
%token  DIV_SYM
285
 
%token  DO_SYM
286
511
%token  DOUBLE_SYM                    /* SQL-2003-R */
287
512
%token  DROP                          /* SQL-2003-R */
288
513
%token  DUMPFILE
290
515
%token  DYNAMIC_SYM                   /* SQL-2003-R */
291
516
%token  EACH_SYM                      /* SQL-2003-R */
292
517
%token  ELSE                          /* SQL-2003-R */
 
518
%token  ELSEIF_SYM
293
519
%token  ENABLE_SYM
294
520
%token  ENCLOSED
295
521
%token  END                           /* SQL-2003-R */
303
529
%token  ESCAPED
304
530
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
531
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
 
532
%token  EXECUTE_SYM
307
533
%token  EXISTS                        /* SQL-2003-R */
308
534
%token  EXTENDED_SYM
309
535
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
536
%token  FALSE_SYM                     /* SQL-2003-R */
 
537
%token  FETCH_SYM                     /* SQL-2003-R */
 
538
%token  COLUMN_FORMAT_SYM
311
539
%token  FILE_SYM
312
540
%token  FIRST_SYM                     /* SQL-2003-N */
313
541
%token  FIXED_SYM
334
562
%token  HOUR_SYM                      /* SQL-2003-R */
335
563
%token  IDENT
336
564
%token  IDENTIFIED_SYM
337
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
338
565
%token  IDENT_QUOTED
339
566
%token  IF
340
567
%token  IGNORE_SYM
367
594
%token  LIKE                          /* SQL-2003-R */
368
595
%token  LIMIT
369
596
%token  LINES
 
597
%token  LIST_SYM
370
598
%token  LOAD
371
599
%token  LOCAL_SYM                     /* SQL-2003-R */
 
600
%token  LOCATOR_SYM                   /* SQL-2003-N */
372
601
%token  LOCKS_SYM
373
602
%token  LOCK_SYM
374
603
%token  LOGS_SYM
375
604
%token  LONG_NUM
376
605
%token  LONG_SYM
 
606
%token  LOOP_SYM
377
607
%token  LT                            /* OPERATOR */
378
608
%token  MATCH                         /* SQL-2003-R */
 
609
%token  MAX_ROWS
 
610
%token  MAX_SIZE_SYM
379
611
%token  MAX_SYM                       /* SQL-2003-N */
380
612
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
381
613
%token  MEDIUM_SYM
384
616
%token  MINUTE_MICROSECOND_SYM
385
617
%token  MINUTE_SECOND_SYM
386
618
%token  MINUTE_SYM                    /* SQL-2003-R */
 
619
%token  MIN_ROWS
387
620
%token  MIN_SYM                       /* SQL-2003-N */
388
621
%token  MODE_SYM
389
622
%token  MODIFIES_SYM                  /* SQL-2003-R */
420
653
%token  OUTER
421
654
%token  OUTFILE
422
655
%token  OUT_SYM                       /* SQL-2003-R */
 
656
%token  PAGE_SYM
423
657
%token  PARTIAL                       /* SQL-2003-N */
 
658
%token  PHASE_SYM
424
659
%token  POSITION_SYM                  /* SQL-2003-N */
425
660
%token  PRECISION                     /* SQL-2003-R */
426
661
%token  PREV_SYM
431
666
%token  QUERY_SYM
432
667
%token  RANGE_SYM                     /* SQL-2003-R */
433
668
%token  READS_SYM                     /* SQL-2003-R */
 
669
%token  READ_ONLY_SYM
434
670
%token  READ_SYM                      /* SQL-2003-N */
435
671
%token  READ_WRITE_SYM
436
672
%token  REAL                          /* SQL-2003-R */
445
681
%token  RESTRICT
446
682
%token  RETURNS_SYM                   /* SQL-2003-R */
447
683
%token  RETURN_SYM                    /* SQL-2003-R */
 
684
%token  REVERSE_SYM
448
685
%token  REVOKE                        /* SQL-2003-R */
449
686
%token  RIGHT                         /* SQL-2003-R */
450
687
%token  ROLLBACK_SYM                  /* SQL-2003-R */
464
701
%token  SERIAL_SYM
465
702
%token  SESSION_SYM                   /* SQL-2003-N */
466
703
%token  SERVER_SYM
 
704
%token  SERVER_OPTIONS
467
705
%token  SET_SYM                           /* SQL-2003-R */
468
706
%token  SET_VAR
469
707
%token  SHARE_SYM
486
724
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
487
725
%token  STD_SYM
488
726
%token  STOP_SYM
 
727
%token  STORAGE_SYM
489
728
%token  STORED_SYM
490
729
%token  STRAIGHT_JOIN
491
730
%token  STRING_SYM
494
733
%token  SUBSTRING                     /* SQL-2003-N */
495
734
%token  SUM_SYM                       /* SQL-2003-N */
496
735
%token  SUSPEND_SYM
 
736
%token  SWAPS_SYM
 
737
%token  SWITCHES_SYM
497
738
%token  SYSDATE
498
739
%token  TABLES
499
740
%token  TABLESPACE
514
755
%token  TRIM                          /* SQL-2003-N */
515
756
%token  TRUE_SYM                      /* SQL-2003-R */
516
757
%token  TRUNCATE_SYM
 
758
%token  TYPES_SYM
517
759
%token  TYPE_SYM                      /* SQL-2003-N */
518
760
%token  ULONGLONG_NUM
519
761
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
572
814
 
573
815
%type <lex_str>
574
816
        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
 
817
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
581
818
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
582
 
        schema_name
583
 
        catalog_name
584
819
        opt_component
585
 
        engine_option_value
586
 
        savepoint_ident
587
 
        BIN_NUM TEXT_STRING_filesystem
 
820
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
588
821
        opt_constraint constraint opt_ident
589
822
 
590
823
%type <execute_string>
602
835
%type <string>
603
836
        text_string opt_gconcat_separator
604
837
 
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
 
838
%type <num>
 
839
        type int_type real_type order_dir field_def
 
840
        if_exists opt_table_options
615
841
        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
 
842
        opt_temporary all_or_any opt_distinct
625
843
        union_option
626
844
        start_transaction_opts opt_chain opt_release
627
845
        union_opt select_derived_init option_type2
 
846
        opt_status
 
847
        opt_concurrent
 
848
        opt_wait
 
849
        opt_zerofill
 
850
        opt_field_number_signed
628
851
        kill_option
629
852
 
630
853
%type <m_fk_option>
647
870
        table_wild simple_expr udf_expr
648
871
        expr_or_default set_expr_or_default
649
872
        signed_literal now_or_signed_literal opt_escape
650
 
        simple_ident_q
 
873
        simple_ident_nospvar simple_ident_q
651
874
        field_or_var limit_option
652
875
        function_call_keyword
653
876
        function_call_nonkeyword
687
910
 
688
911
%type <interval_time_st> interval_time_stamp
689
912
 
 
913
%type <column_format_type> column_format_types
 
914
 
690
915
%type <tx_isolation> isolation_types
691
916
 
692
917
%type <cast_type> cast_type
693
918
 
694
 
%type <symbol>
695
 
        keyword
696
 
        keyword_sp
697
 
        keyword_exception_for_variable
698
 
        row_format
 
919
%type <symbol> keyword keyword_sp
699
920
 
700
921
%type <charset>
701
922
        collation_name
730
951
        flush_options flush_option
731
952
        equal optional_braces
732
953
        normal_join
733
 
        table_to_table_list table_to_table opt_table_list
 
954
        table_to_table_list table_to_table opt_table_list opt_as
734
955
        single_multi
735
956
        union_clause union_list
736
957
        precision subselect_start
784
1005
            }
785
1006
            else
786
1007
            {
787
 
              session->lex->statement= new statement::EmptyQuery(YYSession);
 
1008
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1009
              session->lex->statement=
 
1010
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
1011
              if (session->lex->statement == NULL)
 
1012
                DRIZZLE_YYABORT;
788
1013
            }
789
1014
          }
790
1015
        | verb_clause END_OF_INPUT {}
828
1053
/* create a table */
829
1054
 
830
1055
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);
 
1056
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1057
          {
 
1058
            Session *session= YYSession;
 
1059
            LEX *lex= session->lex;
 
1060
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1061
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1062
            lex->statement= statement;
 
1063
            if (lex->statement == NULL)
 
1064
              DRIZZLE_YYABORT;
 
1065
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1066
                                                   TL_OPTION_UPDATING,
 
1067
                                                   TL_WRITE))
 
1068
              DRIZZLE_YYABORT;
 
1069
            lex->col_list.empty();
 
1070
            statement->change=NULL;
 
1071
            statement->is_if_not_exists= $4;
 
1072
            statement->create_info.db_type= NULL;
 
1073
            statement->create_info.default_table_charset= NULL;
 
1074
            lex->name.str= 0;
838
1075
 
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();
 
1076
            message::Table &proto= statement->create_table_message;
 
1077
           
 
1078
            proto.set_name($5->table.str);
 
1079
            if ($2)
 
1080
              proto.set_type(message::Table::TEMPORARY);
 
1081
            else
 
1082
              proto.set_type(message::Table::STANDARD);
844
1083
          }
845
 
          create_table_definition
 
1084
          create2
846
1085
          {
847
 
            Lex->current_select= &Lex->select_lex;
 
1086
            LEX *lex= YYSession->lex;
 
1087
            lex->current_select= &lex->select_lex;
848
1088
          }
849
1089
        | CREATE build_method
850
1090
          {
851
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1091
            LEX *lex=Lex;
 
1092
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1093
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1094
            lex->statement= statement;
 
1095
            if (lex->statement == NULL)
 
1096
              DRIZZLE_YYABORT;
 
1097
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1098
            statement->alter_info.build_method= $2;
 
1099
            lex->col_list.empty();
 
1100
            statement->change=NULL;
852
1101
          }
853
1102
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
1103
          {
855
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
856
 
                                                            NULL,
857
 
                                                            TL_OPTION_UPDATING))
 
1104
            LEX *lex=Lex;
 
1105
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1106
 
 
1107
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1108
                                                        NULL,
 
1109
                                                        TL_OPTION_UPDATING))
858
1110
              DRIZZLE_YYABORT;
859
 
 
860
 
            parser::buildKey(Lex, $4, $6);
 
1111
            Key *key;
 
1112
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1113
            statement->alter_info.key_list.push_back(key);
 
1114
            lex->col_list.empty();
861
1115
          }
862
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1116
        | CREATE DATABASE opt_if_not_exists ident
863
1117
          {
864
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1118
            LEX *lex=Lex;
 
1119
 
 
1120
            lex->sql_command=SQLCOM_CREATE_DB;
 
1121
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1122
            lex->statement= statement;
 
1123
            if (lex->statement == NULL)
 
1124
              DRIZZLE_YYABORT;
 
1125
            statement->is_if_not_exists= $3;
865
1126
          }
866
1127
          opt_create_database_options
867
1128
          {
869
1130
          }
870
1131
        ;
871
1132
 
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
 
           }
 
1133
create2:
 
1134
          '(' create2a {}
 
1135
        | opt_create_table_options
 
1136
          create3 {}
 
1137
        | LIKE table_ident opt_create_table_options
 
1138
          {
 
1139
            Session *session= YYSession;
 
1140
            LEX *lex= session->lex;
 
1141
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1142
 
 
1143
            statement->is_create_table_like= true;
 
1144
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1145
              DRIZZLE_YYABORT;
 
1146
          }
 
1147
        | '(' LIKE table_ident ')'
 
1148
          {
 
1149
            Session *session= YYSession;
 
1150
            LEX *lex= session->lex;
 
1151
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1152
 
 
1153
            statement->is_create_table_like= true;
 
1154
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1155
              DRIZZLE_YYABORT;
 
1156
          }
 
1157
        ;
 
1158
 
 
1159
create2a:
 
1160
          field_list ')' opt_create_table_options
 
1161
          create3 {}
 
1162
        |  create_select ')'
 
1163
           { Lex->current_select->set_braces(1);}
879
1164
           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
1165
        ;
887
1166
 
888
 
create_select_as:
 
1167
create3:
889
1168
          /* empty */ {}
890
 
        | opt_duplicate_as create_select
891
 
          {
892
 
            Lex->current_select->set_braces(0);
893
 
          }
 
1169
        | opt_duplicate opt_as create_select
 
1170
          { Lex->current_select->set_braces(0);}
894
1171
          union_clause {}
895
 
        | opt_duplicate_as '(' create_select ')'
896
 
          {
897
 
            Lex->current_select->set_braces(1);
898
 
          }
 
1172
        | opt_duplicate opt_as '(' create_select ')'
 
1173
          { Lex->current_select->set_braces(1);}
899
1174
          union_opt {}
900
1175
        ;
901
1176
 
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
1177
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
1178
          SELECT_SYM
923
1179
          {
924
 
            Lex->lock_option= TL_READ;
925
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1180
            LEX *lex=Lex;
 
1181
            lex->lock_option= TL_READ;
 
1182
            if (lex->sql_command == SQLCOM_INSERT)
926
1183
            {
927
 
              delete Lex->statement;
928
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1184
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1185
              delete lex->statement;
 
1186
              lex->statement=
 
1187
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1188
              if (lex->statement == NULL)
 
1189
                DRIZZLE_YYABORT;
929
1190
            }
930
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1191
            else if (lex->sql_command == SQLCOM_REPLACE)
931
1192
            {
932
 
              delete Lex->statement;
933
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1193
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1194
              delete lex->statement;
 
1195
              lex->statement=
 
1196
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1197
              if (lex->statement == NULL)
 
1198
                DRIZZLE_YYABORT;
934
1199
            }
935
1200
            /*
936
1201
              The following work only with the local list, the global list
937
1202
              is created correctly in this case
938
1203
            */
939
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
 
            init_select(Lex);
941
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1204
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1205
            init_select(lex);
 
1206
            lex->current_select->parsing_place= SELECT_LIST;
942
1207
          }
943
1208
          select_options select_item_list
944
1209
          {
954
1219
          }
955
1220
        ;
956
1221
 
 
1222
opt_as:
 
1223
          /* empty */ {}
 
1224
        | AS {}
 
1225
        ;
 
1226
 
957
1227
opt_create_database_options:
958
1228
          /* empty */ {}
959
1229
        | default_collation_schema {}
967
1237
 
968
1238
custom_database_option:
969
1239
          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
 
          }
 
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
        }
974
1246
        | ident_or_text equal ident_or_text
975
 
          {
976
 
            parser::buildSchemaOption(Lex, $1.str, $3);
977
 
          }
 
1247
        {
 
1248
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1249
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1250
 
 
1251
          opt->set_name($1.str);
 
1252
          opt->set_state($3.str);
 
1253
        }
978
1254
        | ident_or_text equal ulonglong_num
979
 
          {
980
 
            parser::buildSchemaOption(Lex, $1.str, $3);
981
 
          }
 
1255
        {
 
1256
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1257
          char number_as_string[22];
 
1258
 
 
1259
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1260
 
 
1261
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1262
 
 
1263
          opt->set_name($1.str);
 
1264
          opt->set_state(number_as_string);
 
1265
        }
982
1266
        ;
983
1267
 
984
1268
opt_table_options:
988
1272
 
989
1273
opt_if_not_exists:
990
1274
          /* empty */ { $$= false; }
991
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1275
        | IF not EXISTS { $$= true; }
992
1276
        ;
993
1277
 
994
1278
opt_create_table_options:
1012
1296
custom_engine_option:
1013
1297
        ENGINE_SYM equal ident_or_text
1014
1298
          {
1015
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1299
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1300
 
 
1301
            statement->is_engine_set= true;
 
1302
 
 
1303
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1016
1304
          }
1017
1305
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1018
1306
          {
1019
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1307
            message::Table::TableOptions *tableopts;
 
1308
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1309
 
 
1310
            tableopts->set_comment($3.str);
1020
1311
          }
1021
1312
        | AUTO_INC opt_equal ulonglong_num
1022
1313
          {
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);
 
1314
            message::Table::TableOptions *tableopts;
 
1315
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1316
 
 
1317
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1318
 
 
1319
            statement->create_info.auto_increment_value=$3;
 
1320
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1321
            tableopts->set_auto_increment_value($3);
 
1322
          }
 
1323
        |  ident_or_text equal ident_or_text
 
1324
          {
 
1325
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1326
 
 
1327
            opt->set_name($1.str);
 
1328
            opt->set_state($3.str);
1036
1329
          }
1037
1330
        | ident_or_text equal ulonglong_num
1038
1331
          {
1039
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1332
            char number_as_string[22];
 
1333
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1334
 
 
1335
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1336
            opt->set_name($1.str);
 
1337
            opt->set_state(number_as_string);
1040
1338
          }
1041
1339
        | default_collation
1042
1340
        ;
1044
1342
default_collation:
1045
1343
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1046
1344
          {
1047
 
            if (not parser::buildCollation(Lex, $4))
1048
 
            {
1049
 
              DRIZZLE_YYABORT;
1050
 
            }
 
1345
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1346
 
 
1347
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1348
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1349
                 cinfo->default_table_charset && $4 &&
 
1350
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1351
              {
 
1352
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1353
                         $4->name, cinfo->default_table_charset->csname);
 
1354
                DRIZZLE_YYABORT;
 
1355
              }
 
1356
              statement->create_info.default_table_charset= $4;
 
1357
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1051
1358
          }
1052
1359
        ;
1053
1360
 
1054
1361
default_collation_schema:
1055
1362
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1056
1363
          {
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
 
        ;
 
1364
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1365
 
 
1366
            message::Schema &schema_message= statement->schema_message;
 
1367
            schema_message.set_collation($4->name);
 
1368
          }
 
1369
        ;
 
1370
 
 
1371
column_format_types:
 
1372
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1373
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1374
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1375
 
1077
1376
 
1078
1377
opt_select_from:
1079
1378
          opt_limit_clause {}
1101
1400
key_def:
1102
1401
          key_type opt_ident key_alg '(' key_list ')' key_options
1103
1402
          {
1104
 
            parser::buildKey(Lex, $1, $2);
 
1403
            LEX *lex=Lex;
 
1404
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1405
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1406
                              lex->col_list);
 
1407
            statement->alter_info.key_list.push_back(key);
 
1408
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1105
1409
          }
1106
1410
        | opt_constraint constraint_key_type opt_ident key_alg
1107
1411
          '(' key_list ')' key_options
1108
1412
          {
1109
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1413
            LEX *lex=Lex;
 
1414
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1415
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1416
                              lex->col_list);
 
1417
            statement->alter_info.key_list.push_back(key);
 
1418
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1110
1419
          }
1111
1420
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1112
1421
          {
1113
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1422
            LEX *lex=Lex;
 
1423
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1424
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
 
1425
                                      $8,
 
1426
                                      lex->ref_list,
 
1427
                                      statement->fk_delete_opt,
 
1428
                                      statement->fk_update_opt,
 
1429
                                      statement->fk_match_option);
 
1430
 
 
1431
            statement->alter_info.key_list.push_back(key);
 
1432
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1433
                         &default_key_create_info, 1,
 
1434
                         lex->col_list);
 
1435
            statement->alter_info.key_list.push_back(key);
 
1436
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1437
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1438
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1114
1439
          }
1115
1440
        | constraint opt_check_constraint
1116
1441
          {
1143
1468
field_spec:
1144
1469
          field_ident
1145
1470
          {
1146
 
            parser::buildCreateFieldIdent(Lex);
 
1471
            LEX *lex=Lex;
 
1472
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1473
            lex->length=lex->dec=0;
 
1474
            lex->type=0;
 
1475
            statement->default_value= statement->on_update_value= 0;
 
1476
            statement->comment= null_lex_str;
 
1477
            lex->charset=NULL;
 
1478
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1479
 
 
1480
            message::AlterTable &alter_proto=
 
1481
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1482
            statement->current_proto_field= alter_proto.add_added_field();
1147
1483
          }
1148
1484
          field_def
1149
1485
          {
 
1486
            LEX *lex=Lex;
1150
1487
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1151
1488
 
1152
 
            if (Lex->field())
1153
 
            {
1154
 
              Lex->field()->set_name($1.str);
1155
 
            }
 
1489
            if (statement->current_proto_field)
 
1490
              statement->current_proto_field->set_name($1.str);
1156
1491
 
1157
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
 
                                  Lex->length, Lex->dec, Lex->type,
 
1492
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1493
                                  lex->length,lex->dec,lex->type,
1159
1494
                                  statement->column_format,
1160
1495
                                  statement->default_value, statement->on_update_value,
1161
1496
                                  &statement->comment,
1162
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1497
                                  statement->change, &lex->interval_list, lex->charset))
1163
1498
              DRIZZLE_YYABORT;
1164
1499
 
1165
 
            Lex->setField(NULL);
 
1500
            statement->current_proto_field= NULL;
1166
1501
          }
1167
1502
        ;
1168
 
 
1169
1503
field_def:
1170
 
          field_definition opt_attribute {}
 
1504
          type opt_attribute {}
1171
1505
        ;
1172
1506
 
1173
 
field_definition:
 
1507
type:
1174
1508
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1175
1509
          { 
1176
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
 
1510
            $$= $1;
 
1511
            Lex->length=(char*) 0; /* use default length */
 
1512
            statement::CreateTable *statement=
 
1513
              (statement::CreateTable *)Lex->statement;
 
1514
 
 
1515
            if ($3 or $4)
 
1516
            {
 
1517
              $1= DRIZZLE_TYPE_LONGLONG;
 
1518
            }
 
1519
 
 
1520
            if (statement->current_proto_field)
 
1521
            {
 
1522
              assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
 
1523
              // We update the type for unsigned types
 
1524
              if ($3 or $4)
 
1525
              {
 
1526
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1527
                statement->current_proto_field->mutable_constraints()->set_is_unsigned(true);
 
1528
              }
 
1529
              if ($1 == DRIZZLE_TYPE_LONG)
 
1530
              {
 
1531
                statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1532
              }
 
1533
              else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1534
              {
 
1535
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1536
              }
 
1537
            }
1177
1538
          }
1178
1539
        | real_type opt_precision
1179
1540
          {
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
 
1541
            $$=$1;
 
1542
 
 
1543
            statement::CreateTable *statement=
 
1544
              (statement::CreateTable *)Lex->statement;
 
1545
 
 
1546
            if (statement->current_proto_field)
 
1547
            {
 
1548
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1549
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1550
            }
 
1551
          }
 
1552
          | char '(' NUM ')'
 
1553
            {
 
1554
              Lex->length=$3.str;
 
1555
              $$=DRIZZLE_TYPE_VARCHAR;
 
1556
 
 
1557
            statement::CreateTable *statement=
 
1558
              (statement::CreateTable *)Lex->statement;
 
1559
 
 
1560
            if (statement->current_proto_field)
 
1561
            {
 
1562
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1563
              message::Table::Field::StringFieldOptions *string_field_options;
 
1564
 
 
1565
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1566
 
 
1567
              string_field_options->set_length(atoi($3.str));
 
1568
            }
 
1569
            }
 
1570
          | char
 
1571
            {
 
1572
              Lex->length=(char*) "1";
 
1573
              $$=DRIZZLE_TYPE_VARCHAR;
 
1574
 
 
1575
            statement::CreateTable *statement=
 
1576
              (statement::CreateTable *)Lex->statement;
 
1577
 
 
1578
            if (statement->current_proto_field)
 
1579
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1580
            }
 
1581
          | varchar '(' NUM ')'
 
1582
            {
 
1583
              Lex->length=$3.str;
 
1584
              $$= DRIZZLE_TYPE_VARCHAR;
 
1585
 
 
1586
            statement::CreateTable *statement=
 
1587
              (statement::CreateTable *)Lex->statement;
 
1588
 
 
1589
            if (statement->current_proto_field)
 
1590
            {
 
1591
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1592
 
 
1593
              message::Table::Field::StringFieldOptions *string_field_options;
 
1594
 
 
1595
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1596
 
 
1597
              string_field_options->set_length(atoi($3.str));
 
1598
            }
 
1599
            }
 
1600
          | VARBINARY '(' NUM ')'
 
1601
            {
 
1602
              Lex->length=$3.str;
 
1603
              Lex->charset=&my_charset_bin;
 
1604
              $$= DRIZZLE_TYPE_VARCHAR;
 
1605
 
 
1606
            statement::CreateTable *statement=
 
1607
              (statement::CreateTable *)Lex->statement;
 
1608
 
 
1609
            if (statement->current_proto_field)
 
1610
            {
 
1611
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1612
              message::Table::Field::StringFieldOptions *string_field_options;
 
1613
 
 
1614
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1615
 
 
1616
              string_field_options->set_length(atoi($3.str));
 
1617
              string_field_options->set_collation_id(my_charset_bin.number);
 
1618
              string_field_options->set_collation(my_charset_bin.name);
 
1619
            }
 
1620
            }
 
1621
          | DATE_SYM
1200
1622
          {
1201
1623
            $$=DRIZZLE_TYPE_DATE;
1202
1624
 
1203
 
            if (Lex->field())
1204
 
              Lex->field()->set_type(message::Table::Field::DATE);
 
1625
            statement::CreateTable *statement=
 
1626
              (statement::CreateTable *)Lex->statement;
 
1627
 
 
1628
            if (statement->current_proto_field)
 
1629
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1205
1630
          }
1206
 
        | TIME_SYM
 
1631
          | TIME_SYM
1207
1632
          {
1208
1633
            $$=DRIZZLE_TYPE_TIME;
1209
1634
 
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
 
1635
            statement::CreateTable *statement=
 
1636
              (statement::CreateTable *)Lex->statement;
 
1637
 
 
1638
            if (statement->current_proto_field)
 
1639
              statement->current_proto_field->set_type(message::Table::Field::TIME);
 
1640
          }
 
1641
          | TIMESTAMP_SYM
 
1642
          {
 
1643
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1644
 
 
1645
            statement::CreateTable *statement=
 
1646
              (statement::CreateTable *)Lex->statement;
 
1647
 
 
1648
            if (statement->current_proto_field)
 
1649
              statement->current_proto_field->set_type(message::Table::Field::EPOCH);
 
1650
          }
 
1651
          | DATETIME_SYM
1222
1652
          {
1223
1653
            $$=DRIZZLE_TYPE_DATETIME;
1224
1654
 
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 ')'
 
1655
            statement::CreateTable *statement=
 
1656
              (statement::CreateTable *)Lex->statement;
 
1657
 
 
1658
            if (statement->current_proto_field)
 
1659
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1660
          }
 
1661
          | BLOB_SYM
 
1662
            {
 
1663
              Lex->charset=&my_charset_bin;
 
1664
              $$=DRIZZLE_TYPE_BLOB;
 
1665
              Lex->length=(char*) 0; /* use default length */
 
1666
 
 
1667
              statement::CreateTable *statement=
 
1668
                (statement::CreateTable *)Lex->statement;
 
1669
 
 
1670
              if (statement->current_proto_field)
 
1671
              {
 
1672
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1673
                message::Table::Field::StringFieldOptions *string_field_options;
 
1674
 
 
1675
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1676
                string_field_options->set_collation_id(my_charset_bin.number);
 
1677
                string_field_options->set_collation(my_charset_bin.name);
 
1678
              }
 
1679
            }
 
1680
          | TEXT_SYM
 
1681
            {
 
1682
              $$=DRIZZLE_TYPE_BLOB;
 
1683
              Lex->length=(char*) 0; /* use default length */
 
1684
 
 
1685
            statement::CreateTable *statement=
 
1686
              (statement::CreateTable *)Lex->statement;
 
1687
 
 
1688
            if (statement->current_proto_field)
 
1689
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1690
            }
 
1691
          | DECIMAL_SYM float_options
 
1692
          {
 
1693
            $$=DRIZZLE_TYPE_DECIMAL;
 
1694
 
 
1695
            statement::CreateTable *statement=
 
1696
              (statement::CreateTable *)Lex->statement;
 
1697
 
 
1698
            if (statement->current_proto_field)
 
1699
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1700
          }
 
1701
          | NUMERIC_SYM float_options
 
1702
          {
 
1703
            $$=DRIZZLE_TYPE_DECIMAL;
 
1704
 
 
1705
            statement::CreateTable *statement=
 
1706
              (statement::CreateTable *)Lex->statement;
 
1707
 
 
1708
            if (statement->current_proto_field)
 
1709
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1710
          }
 
1711
          | FIXED_SYM float_options
 
1712
          {
 
1713
            $$=DRIZZLE_TYPE_DECIMAL;
 
1714
 
 
1715
            statement::CreateTable *statement=
 
1716
              (statement::CreateTable *)Lex->statement;
 
1717
 
 
1718
            if (statement->current_proto_field)
 
1719
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1720
          }
 
1721
          | ENUM_SYM
 
1722
            {Lex->interval_list.empty();}
 
1723
            '(' string_list ')'
1257
1724
          {
1258
1725
            $$=DRIZZLE_TYPE_ENUM;
1259
1726
 
1260
 
            if (Lex->field())
1261
 
              Lex->field()->set_type(message::Table::Field::ENUM);
 
1727
            statement::CreateTable *statement=
 
1728
              (statement::CreateTable *)Lex->statement;
 
1729
 
 
1730
            if (statement->current_proto_field)
 
1731
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1262
1732
          }
1263
 
        | UUID_SYM
 
1733
          | UUID_SYM
1264
1734
          {
1265
 
            $$= parser::buildUuidColumn(Lex);
 
1735
            $$=DRIZZLE_TYPE_UUID;
 
1736
 
 
1737
            statement::CreateTable *statement=
 
1738
              (statement::CreateTable *)Lex->statement;
 
1739
 
 
1740
            if (statement->current_proto_field)
 
1741
              statement->current_proto_field->set_type(message::Table::Field::UUID);
1266
1742
          }
 
1743
        | BOOL_SYM
 
1744
        {
 
1745
          $$=DRIZZLE_TYPE_BOOLEAN;
 
1746
 
 
1747
          statement::CreateTable *statement=
 
1748
            (statement::CreateTable *)Lex->statement;
 
1749
 
 
1750
          if (statement->current_proto_field)
 
1751
            statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
 
1752
        }
1267
1753
        | BOOLEAN_SYM
1268
 
          {
1269
 
            $$= parser::buildBooleanColumn(Lex);
1270
 
          }
 
1754
        {
 
1755
          $$=DRIZZLE_TYPE_BOOLEAN;
 
1756
 
 
1757
          statement::CreateTable *statement=
 
1758
            (statement::CreateTable *)Lex->statement;
 
1759
 
 
1760
          if (statement->current_proto_field)
 
1761
            statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
 
1762
        }
1271
1763
        | SERIAL_SYM
1272
1764
          {
1273
 
            $$= parser::buildSerialColumn(Lex);
 
1765
            $$=DRIZZLE_TYPE_LONGLONG;
 
1766
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1767
 
 
1768
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1769
            if (statement->current_proto_field)
 
1770
            {
 
1771
              message::Table::Field::FieldConstraints *constraints;
 
1772
              constraints= statement->current_proto_field->mutable_constraints();
 
1773
              constraints->set_is_nullable(false);
 
1774
 
 
1775
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1776
            }
1274
1777
          }
1275
1778
        ;
1276
1779
 
1284
1787
        ;
1285
1788
 
1286
1789
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
 
          }
 
1790
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1791
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1299
1792
        ;
1300
1793
 
1301
1794
real_type:
1304
1797
            $$= DRIZZLE_TYPE_DOUBLE;
1305
1798
          }
1306
1799
        | DOUBLE_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_DOUBLE;
1309
 
          }
 
1800
          { $$=DRIZZLE_TYPE_DOUBLE; }
1310
1801
        | DOUBLE_SYM PRECISION
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_DOUBLE;
1313
 
          }
 
1802
          { $$=DRIZZLE_TYPE_DOUBLE; }
1314
1803
        ;
1315
1804
 
1316
1805
float_options:
1325
1814
precision:
1326
1815
          '(' NUM ',' NUM ')'
1327
1816
          {
1328
 
            Lex->length= $2.str;
1329
 
            Lex->dec= $4.str;
 
1817
            LEX *lex=Lex;
 
1818
            lex->length=$2.str;
 
1819
            lex->dec=$4.str;
1330
1820
          }
1331
1821
        ;
1332
1822
 
1336
1826
        ;
1337
1827
 
1338
1828
opt_field_number_signed:
1339
 
          /* empty */ { $$= false; }
1340
 
        | SIGNED_SYM { $$= false; }
1341
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1829
          /* empty */ { $$= 0; }
 
1830
        | SIGNED_SYM { $$= 0; }
 
1831
        | UNSIGNED_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
1342
1832
        ;
1343
1833
 
1344
1834
ignored_field_number_length:
1347
1837
        ;
1348
1838
 
1349
1839
opt_zerofill:
1350
 
          /* empty */ { $$= false; }
1351
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1840
          /* empty */ { $$= 0; }
 
1841
        | ZEROFILL_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
1352
1842
        ;
1353
1843
 
1354
1844
opt_precision:
1355
 
          /* empty */
1356
 
          { Lex->dec=Lex->length= (char*)0; }
1357
 
        | '(' NUM ')'
1358
 
          { Lex->length=Lex->dec= (char*)0; }
1359
 
        | precision
1360
 
          {}
 
1845
          /* empty */ {}
 
1846
        | precision {}
1361
1847
        ;
1362
1848
 
1363
1849
opt_attribute:
1373
1859
attribute:
1374
1860
          NULL_SYM
1375
1861
          {
 
1862
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1376
1863
            Lex->type&= ~ NOT_NULL_FLAG;
 
1864
 
 
1865
            if (statement->current_proto_field)
 
1866
            {
 
1867
              message::Table::Field::FieldConstraints *constraints;
 
1868
              constraints= statement->current_proto_field->mutable_constraints();
 
1869
              constraints->set_is_nullable(true);
 
1870
            }
 
1871
          }
 
1872
        | COLUMN_FORMAT_SYM column_format_types
 
1873
          {
 
1874
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1875
 
 
1876
            statement->column_format= $2;
 
1877
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1377
1878
          }
1378
1879
        | not NULL_SYM
1379
1880
          {
 
1881
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1380
1882
            Lex->type|= NOT_NULL_FLAG;
1381
1883
 
1382
 
            if (Lex->field())
 
1884
            if (statement->current_proto_field)
1383
1885
            {
1384
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1886
              message::Table::Field::FieldConstraints *constraints;
 
1887
              constraints= statement->current_proto_field->mutable_constraints();
 
1888
              constraints->set_is_nullable(false);
1385
1889
            }
1386
1890
          }
1387
1891
        | DEFAULT now_or_signed_literal
1392
1896
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1393
1897
          }
1394
1898
        | ON UPDATE_SYM NOW_SYM optional_braces
1395
 
          {
1396
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1397
 
          }
 
1899
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1398
1900
        | AUTO_INC
1399
1901
          {
1400
 
            parser::buildAutoOnColumn(Lex);
 
1902
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1903
 
 
1904
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1905
            if (statement->current_proto_field)
 
1906
            {
 
1907
              message::Table::Field::FieldConstraints *constraints;
 
1908
 
 
1909
              constraints= statement->current_proto_field->mutable_constraints();
 
1910
              constraints->set_is_nullable(false);
 
1911
            }
1401
1912
          }
1402
1913
        | SERIAL_SYM DEFAULT VALUE_SYM
1403
1914
          {
1404
 
            (void)parser::buildSerialColumn(Lex);
 
1915
            LEX *lex=Lex;
 
1916
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1917
 
 
1918
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1919
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1920
 
 
1921
            if (statement->current_proto_field)
 
1922
            {
 
1923
              message::Table::Field::FieldConstraints *constraints;
 
1924
              constraints= statement->current_proto_field->mutable_constraints();
 
1925
              constraints->set_is_nullable(false);
 
1926
            }
1405
1927
          }
1406
1928
        | opt_primary KEY_SYM
1407
1929
          {
1408
 
            parser::buildPrimaryOnColumn(Lex);
 
1930
            LEX *lex=Lex;
 
1931
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1932
 
 
1933
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1934
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1935
 
 
1936
            if (statement->current_proto_field)
 
1937
            {
 
1938
              message::Table::Field::FieldConstraints *constraints;
 
1939
              constraints= statement->current_proto_field->mutable_constraints();
 
1940
              constraints->set_is_nullable(false);
 
1941
            }
1409
1942
          }
1410
1943
        | UNIQUE_SYM
1411
1944
          {
1412
 
            parser::buildKeyOnColumn(Lex);
 
1945
            LEX *lex=Lex;
 
1946
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1947
 
 
1948
            lex->type|= UNIQUE_FLAG;
 
1949
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1413
1950
          }
1414
1951
        | UNIQUE_SYM KEY_SYM
1415
1952
          {
1416
 
            parser::buildKeyOnColumn(Lex);
 
1953
            LEX *lex=Lex;
 
1954
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1955
 
 
1956
            lex->type|= UNIQUE_KEY_FLAG;
 
1957
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1417
1958
          }
1418
1959
        | COMMENT_SYM TEXT_STRING_sys
1419
1960
          {
1420
1961
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1421
1962
            statement->comment= $2;
1422
1963
 
1423
 
            if (Lex->field())
1424
 
              Lex->field()->set_comment($2.str);
 
1964
            if (statement->current_proto_field)
 
1965
              statement->current_proto_field->set_comment($2.str);
1425
1966
          }
1426
1967
        | COLLATE_SYM collation_name
1427
1968
          {
1493
2034
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1494
2035
        | ident
1495
2036
          {
1496
 
            Lex->ref_list.empty();
1497
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
2037
            LEX *lex= Lex;
 
2038
            lex->ref_list.empty();
 
2039
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1498
2040
          }
1499
2041
        ;
1500
2042
 
1584
2126
        ;
1585
2127
 
1586
2128
/*
1587
 
  For now, key_alg initializies Lex->key_create_info.
 
2129
  For now, key_alg initializies lex->key_create_info.
1588
2130
  In the future, when all key options are after key definition,
1589
2131
  we can remove key_alg and move init_key_options to key_options
1590
2132
*/
1606
2148
 
1607
2149
key_using_alg:
1608
2150
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2151
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1609
2152
        ;
1610
2153
 
1611
2154
key_opt:
1660
2203
alter:
1661
2204
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
1662
2205
          {
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());
 
2206
            Session *session= YYSession;
 
2207
            LEX *lex= session->lex;
 
2208
            lex->name.str= 0;
 
2209
            lex->name.length= 0;
 
2210
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2211
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2212
            lex->statement= statement;
 
2213
            if (lex->statement == NULL)
 
2214
              DRIZZLE_YYABORT;
 
2215
            lex->duplicates= DUP_ERROR;
 
2216
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2217
                                                   TL_OPTION_UPDATING))
 
2218
              DRIZZLE_YYABORT;
 
2219
            lex->col_list.empty();
 
2220
            lex->select_lex.init_order();
 
2221
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
 
2222
            statement->alter_info.build_method= $2;
1674
2223
          }
1675
2224
          alter_commands
1676
2225
          {}
1677
 
        | ALTER_SYM DATABASE schema_name
 
2226
        | ALTER_SYM DATABASE ident_or_empty
1678
2227
          {
1679
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2228
            LEX *lex=Lex;
 
2229
            lex->sql_command=SQLCOM_ALTER_DB;
 
2230
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2231
            if (lex->statement == NULL)
 
2232
              DRIZZLE_YYABORT;
1680
2233
          }
1681
2234
          default_collation_schema
1682
2235
          {
1683
 
            Lex->name= $3;
1684
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2236
            LEX *lex=Lex;
 
2237
            lex->name= $3;
 
2238
            if (lex->name.str == NULL &&
 
2239
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1685
2240
              DRIZZLE_YYABORT;
1686
2241
          }
1687
2242
        ;
1688
2243
 
 
2244
ident_or_empty:
 
2245
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2246
        | ident { $$= $1; }
 
2247
        ;
 
2248
 
1689
2249
alter_commands:
1690
2250
          /* empty */
1691
2251
        | DISCARD TABLESPACE
1755
2315
          field_spec opt_place
1756
2316
        | MODIFY_SYM opt_column field_ident
1757
2317
          {
 
2318
            LEX *lex=Lex;
1758
2319
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1759
 
            Lex->length= Lex->dec=0;
1760
 
            Lex->type= 0;
 
2320
            lex->length=lex->dec=0; lex->type=0;
1761
2321
            statement->default_value= statement->on_update_value= 0;
1762
2322
            statement->comment= null_lex_str;
1763
 
            Lex->charset= NULL;
 
2323
            lex->charset= NULL;
1764
2324
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1765
2325
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1766
2326
 
1767
 
            Lex->setField(NULL);
 
2327
            statement->current_proto_field= NULL;
1768
2328
          }
1769
2329
          field_def
1770
2330
          {
 
2331
            LEX *lex=Lex;
1771
2332
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1772
2333
 
1773
 
            if (add_field_to_list(Lex->session,&$3,
 
2334
            if (add_field_to_list(lex->session,&$3,
1774
2335
                                  (enum enum_field_types) $5,
1775
 
                                  Lex->length, Lex->dec, Lex->type,
 
2336
                                  lex->length, lex->dec, lex->type,
1776
2337
                                  statement->column_format,
1777
2338
                                  statement->default_value,
1778
2339
                                  statement->on_update_value,
1779
2340
                                  &statement->comment,
1780
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2341
                                  $3.str, &lex->interval_list, lex->charset))
1781
2342
              DRIZZLE_YYABORT;
1782
2343
          }
1783
2344
          opt_place
1842
2403
          }
1843
2404
        | RENAME opt_to table_ident
1844
2405
          {
 
2406
            LEX *lex=Lex;
1845
2407
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1846
2408
            size_t dummy;
1847
2409
 
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))
 
2410
            lex->select_lex.db=$3->db.str;
 
2411
            if (lex->select_lex.db == NULL &&
 
2412
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1851
2413
            {
1852
2414
              DRIZZLE_YYABORT;
1853
2415
            }
1858
2420
              DRIZZLE_YYABORT;
1859
2421
            }
1860
2422
 
1861
 
            Lex->name= $3->table;
 
2423
            lex->name= $3->table;
1862
2424
            statement->alter_info.flags.set(ALTER_RENAME);
1863
2425
          }
1864
2426
        | CONVERT_SYM TO_SYM collation_name_or_default
1865
2427
          {
1866
2428
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
2429
 
1868
 
            statement->create_info().table_charset=
1869
 
            statement->create_info().default_table_charset= $3;
1870
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2430
            statement->create_info.table_charset=
 
2431
            statement->create_info.default_table_charset= $3;
 
2432
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1871
2433
              HA_CREATE_USED_DEFAULT_CHARSET);
1872
2434
            statement->alter_info.flags.set(ALTER_CONVERT);
1873
2435
          }
1905
2467
          /* empty */ {}
1906
2468
        | AFTER_SYM ident
1907
2469
          {
1908
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2470
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2471
 
 
2472
            store_position_for_column($2.str);
 
2473
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1909
2474
          }
1910
2475
        | FIRST_SYM
1911
2476
          {
1912
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2477
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2478
 
 
2479
            store_position_for_column(first_keyword);
 
2480
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1913
2481
          }
1914
2482
        ;
1915
2483
 
1923
2491
start:
1924
2492
          START_SYM TRANSACTION_SYM start_transaction_opts
1925
2493
          {
1926
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2494
            LEX *lex= Lex;
 
2495
            lex->sql_command= SQLCOM_BEGIN;
 
2496
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2497
            if (lex->statement == NULL)
 
2498
              DRIZZLE_YYABORT;
1927
2499
          }
1928
2500
        ;
1929
2501
 
1938
2510
analyze:
1939
2511
          ANALYZE_SYM table_or_tables
1940
2512
          {
1941
 
            Lex->statement= new statement::Analyze(YYSession);
 
2513
            LEX *lex=Lex;
 
2514
            lex->sql_command = SQLCOM_ANALYZE;
 
2515
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2516
            if (lex->statement == NULL)
 
2517
              DRIZZLE_YYABORT;
1942
2518
          }
1943
2519
          table_list
1944
2520
          {}
1947
2523
check:
1948
2524
          CHECK_SYM table_or_tables
1949
2525
          {
1950
 
            Lex->statement= new statement::Check(YYSession);
 
2526
            LEX *lex=Lex;
 
2527
 
 
2528
            lex->sql_command = SQLCOM_CHECK;
 
2529
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2530
            if (lex->statement == NULL)
 
2531
              DRIZZLE_YYABORT;
1951
2532
          }
1952
2533
          table_list
1953
2534
          {}
1956
2537
rename:
1957
2538
          RENAME table_or_tables
1958
2539
          {
1959
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2540
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2541
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2542
            if (Lex->statement == NULL)
 
2543
              DRIZZLE_YYABORT;
1960
2544
          }
1961
2545
          table_to_table_list
1962
2546
          {}
1970
2554
table_to_table:
1971
2555
          table_ident TO_SYM table_ident
1972
2556
          {
1973
 
            Select_Lex *sl= Lex->current_select;
1974
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2557
            LEX *lex=Lex;
 
2558
            Select_Lex *sl= lex->current_select;
 
2559
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1975
2560
                                       TL_IGNORE) ||
1976
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2561
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1977
2562
                                       TL_IGNORE))
1978
2563
              DRIZZLE_YYABORT;
1979
2564
          }
1987
2572
select:
1988
2573
          select_init
1989
2574
          {
1990
 
            Lex->statement= new statement::Select(YYSession);
 
2575
            LEX *lex= Lex;
 
2576
            lex->sql_command= SQLCOM_SELECT;
 
2577
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2578
            if (lex->statement == NULL)
 
2579
              DRIZZLE_YYABORT;
1991
2580
          }
1992
2581
        ;
1993
2582
 
2000
2589
select_paren:
2001
2590
          SELECT_SYM select_part2
2002
2591
          {
2003
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2592
            if (setup_select_in_parentheses(YYSession, Lex))
2004
2593
              DRIZZLE_YYABORT;
2005
2594
          }
2006
2595
        | '(' select_paren ')'
2010
2599
select_paren_derived:
2011
2600
          SELECT_SYM select_part2_derived
2012
2601
          {
2013
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2602
            if (setup_select_in_parentheses(YYSession, Lex))
2014
2603
              DRIZZLE_YYABORT;
2015
2604
          }
2016
2605
        | '(' select_paren_derived ')'
2019
2608
select_init2:
2020
2609
          select_part2
2021
2610
          {
2022
 
            Select_Lex * sel= Lex->current_select;
2023
 
            if (Lex->current_select->set_braces(0))
 
2611
            LEX *lex= Lex;
 
2612
            Select_Lex * sel= lex->current_select;
 
2613
            if (lex->current_select->set_braces(0))
2024
2614
            {
2025
 
              parser::my_parse_error(YYSession->m_lip);
 
2615
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2616
              my_parse_error(&pass);
2026
2617
              DRIZZLE_YYABORT;
2027
2618
            }
2028
2619
            if (sel->linkage == UNION_TYPE &&
2029
2620
                sel->master_unit()->first_select()->braces)
2030
2621
            {
2031
 
              parser::my_parse_error(YYSession->m_lip);
 
2622
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2623
              my_parse_error(&pass);
2032
2624
              DRIZZLE_YYABORT;
2033
2625
            }
2034
2626
          }
2037
2629
 
2038
2630
select_part2:
2039
2631
          {
2040
 
            Select_Lex *sel= Lex->current_select;
 
2632
            LEX *lex= Lex;
 
2633
            Select_Lex *sel= lex->current_select;
2041
2634
            if (sel->linkage != UNION_TYPE)
2042
 
              init_select(Lex);
2043
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2635
              init_select(lex);
 
2636
            lex->current_select->parsing_place= SELECT_LIST;
2044
2637
          }
2045
2638
          select_options select_item_list
2046
2639
          {
2070
2663
select_options:
2071
2664
          /* empty*/
2072
2665
        | select_option_list
2073
 
          { }
 
2666
          {
 
2667
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2668
                Lex->current_select->options & SELECT_ALL)
 
2669
            {
 
2670
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2671
              DRIZZLE_YYABORT;
 
2672
            }
 
2673
          }
2074
2674
        ;
2075
2675
 
2076
2676
select_option_list:
2078
2678
        | select_option
2079
2679
        ;
2080
2680
 
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
2681
select_option:
2129
2682
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2683
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2684
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2685
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2130
2686
        | SQL_BUFFER_RESULT
2131
2687
          {
2132
 
            if (check_simple_select(YYSession))
 
2688
            if (check_simple_select())
2133
2689
              DRIZZLE_YYABORT;
2134
2690
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2135
2691
          }
2136
 
        | select_option_small_or_big
2137
 
          { }
2138
 
        | select_option_distinct_or_all
2139
 
          { }
2140
2692
        | SQL_CALC_FOUND_ROWS
2141
2693
          {
2142
 
            if (check_simple_select(YYSession))
 
2694
            if (check_simple_select())
2143
2695
              DRIZZLE_YYABORT;
2144
2696
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2145
2697
          }
 
2698
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2146
2699
        ;
2147
2700
 
2148
2701
select_lock_type:
2149
2702
          /* empty */
2150
2703
        | FOR_SYM UPDATE_SYM
2151
2704
          {
2152
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2705
            LEX *lex=Lex;
 
2706
            lex->current_select->set_lock_for_tables(TL_WRITE);
2153
2707
          }
2154
2708
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2155
2709
          {
2156
 
            Lex->current_select->
 
2710
            LEX *lex=Lex;
 
2711
            lex->current_select->
2157
2712
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2158
2713
          }
2159
2714
        ;
2163
2718
        | select_item
2164
2719
        | '*'
2165
2720
          {
2166
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
2721
            Session *session= YYSession;
 
2722
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
2167
2723
                                                          context,
2168
2724
                                                          NULL, NULL, "*")))
2169
2725
              DRIZZLE_YYABORT;
2170
 
            (YYSession->lex->current_select->with_wild)++;
 
2726
            (session->lex->current_select->with_wild)++;
2171
2727
          }
2172
2728
        ;
2173
2729
 
2174
2730
select_item:
2175
2731
          remember_name table_wild remember_end
2176
2732
          {
2177
 
            if (YYSession->add_item_to_list($2))
 
2733
            Session *session= YYSession;
 
2734
 
 
2735
            if (session->add_item_to_list($2))
2178
2736
              DRIZZLE_YYABORT;
2179
2737
          }
2180
2738
        | remember_name expr remember_end select_alias
2181
2739
          {
 
2740
            Session *session= YYSession;
2182
2741
            assert($1 < $3);
2183
2742
 
2184
 
            if (YYSession->add_item_to_list($2))
 
2743
            if (session->add_item_to_list($2))
2185
2744
              DRIZZLE_YYABORT;
2186
 
 
2187
2745
            if ($4.str)
2188
2746
            {
2189
2747
              $2->is_autogenerated_name= false;
2191
2749
            }
2192
2750
            else if (!$2->name)
2193
2751
            {
2194
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2752
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2195
2753
            }
2196
2754
          }
2197
2755
        ;
2198
2756
 
2199
2757
remember_name:
2200
2758
          {
2201
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2759
            Session *session= YYSession;
 
2760
            Lex_input_stream *lip= session->m_lip;
2202
2761
            $$= (char*) lip->get_cpp_tok_start();
2203
2762
          }
2204
2763
        ;
2205
2764
 
2206
2765
remember_end:
2207
2766
          {
2208
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2767
            Session *session= YYSession;
 
2768
            Lex_input_stream *lip= session->m_lip;
2209
2769
            $$= (char*) lip->get_cpp_tok_end();
2210
2770
          }
2211
2771
        ;
2358
2918
          }
2359
2919
        | bit_expr not IN_SYM '(' subselect ')'
2360
2920
          {
2361
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2362
 
            $$= negate_expression(YYSession, item);
 
2921
            Session *session= YYSession;
 
2922
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2923
            $$= negate_expression(session, item);
2363
2924
          }
2364
2925
        | bit_expr IN_SYM '(' expr ')'
2365
2926
          {
2366
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2927
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2367
2928
          }
2368
2929
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2369
2930
          {
2373
2934
          }
2374
2935
        | bit_expr not IN_SYM '(' expr ')'
2375
2936
          {
2376
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2937
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2377
2938
          }
2378
2939
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2379
2940
          {
2406
2967
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2407
2968
            args->push_back($1);
2408
2969
            args->push_back($3);
2409
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2970
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2410
2971
            {
2411
2972
              DRIZZLE_YYABORT;
2412
2973
            }
2417
2978
            args->push_back($1);
2418
2979
            args->push_back($4);
2419
2980
            args->push_back(new (YYSession->mem_root) Item_int(1));
2420
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2981
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2421
2982
            {
2422
2983
              DRIZZLE_YYABORT;
2423
2984
            }
2481
3042
        | function_call_conflict
2482
3043
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2483
3044
          {
2484
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
3045
            Session *session= YYSession;
 
3046
            Item *i1= new (session->mem_root) Item_string($3.str,
2485
3047
                                                      $3.length,
2486
 
                                                      YYSession->charset());
2487
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
3048
                                                      session->charset());
 
3049
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2488
3050
          }
2489
3051
        | literal
2490
3052
        | variable
2522
3084
          }
2523
3085
        | CAST_SYM '(' expr AS cast_type ')'
2524
3086
          {
2525
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2526
 
                                 Lex->charset);
 
3087
            LEX *lex= Lex;
 
3088
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
3089
                                 lex->charset);
2527
3090
            if (!$$)
2528
3091
              DRIZZLE_YYABORT;
2529
3092
          }
2541
3104
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2542
3105
                                                         $3);
2543
3106
          }
2544
 
        | VALUES '(' simple_ident ')'
 
3107
        | VALUES '(' simple_ident_nospvar ')'
2545
3108
          {
2546
3109
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2547
3110
                                                        $3);
2563
3126
        | CURRENT_USER optional_braces
2564
3127
          {
2565
3128
            std::string user_str("user");
2566
 
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
 
3129
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2567
3130
            {
2568
3131
              DRIZZLE_YYABORT;
2569
3132
            }
2579
3142
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
2580
3143
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2581
3144
          {
2582
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3145
            Session *session= YYSession;
 
3146
            List<Item> *list= new (session->mem_root) List<Item>;
2583
3147
            list->push_front($5);
2584
3148
            list->push_front($3);
2585
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2586
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3149
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3150
            $$= new (session->mem_root) Item_func_interval(item);
2587
3151
          }
2588
3152
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2589
3153
          {
 
3154
            Session *session= YYSession;
2590
3155
            $7->push_front($5);
2591
3156
            $7->push_front($3);
2592
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2593
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3157
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3158
            $$= new (session->mem_root) Item_func_interval(item);
2594
3159
          }
2595
3160
        | LEFT '(' expr ',' expr ')'
2596
3161
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2622
3187
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2623
3188
        | USER '(' ')'
2624
3189
          {
2625
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3190
            std::string user_str("user");
 
3191
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2626
3192
            {
2627
3193
              DRIZZLE_YYABORT;
2628
3194
            }
2688
3254
            args->push_back($3);
2689
3255
            args->push_back($5);
2690
3256
            args->push_back($7);
2691
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3257
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2692
3258
            {
2693
3259
              DRIZZLE_YYABORT;
2694
3260
            }
2699
3265
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2700
3266
            args->push_back($3);
2701
3267
            args->push_back($5);
2702
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3268
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2703
3269
            {
2704
3270
              DRIZZLE_YYABORT;
2705
3271
            }
2711
3277
            args->push_back($3);
2712
3278
            args->push_back($5);
2713
3279
            args->push_back($7);
2714
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3280
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2715
3281
            {
2716
3282
              DRIZZLE_YYABORT;
2717
3283
            }
2722
3288
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2723
3289
            args->push_back($3);
2724
3290
            args->push_back($5);
2725
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3291
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2726
3292
            {
2727
3293
              DRIZZLE_YYABORT;
2728
3294
            }
2765
3331
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2766
3332
        | DATABASE '(' ')'
2767
3333
          {
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)))
 
3334
            std::string database_str("database");
 
3335
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
2777
3336
            {
2778
3337
              DRIZZLE_YYABORT;
2779
3338
            }
2789
3348
              args->push_back(new (YYSession->mem_root) Item_int(1));
2790
3349
            }
2791
3350
 
2792
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
 
3351
            if (! ($$= reserved_keyword_function(YYSession, "execute", args)))
2793
3352
            {
2794
3353
              DRIZZLE_YYABORT;
2795
3354
            }
2807
3366
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2808
3367
            }
2809
3368
 
2810
 
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
 
3369
            if (! ($$= reserved_keyword_function(YYSession, kill_str, args)))
2811
3370
            {
2812
3371
              DRIZZLE_YYABORT;
2813
3372
            }
2822
3381
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
2823
3382
        | REPLACE '(' expr ',' expr ',' expr ')'
2824
3383
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3384
        | REVERSE_SYM '(' expr ')'
 
3385
          {
 
3386
            std::string reverse_str("reverse");
 
3387
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3388
            args->push_back($3);
 
3389
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
3390
            {
 
3391
              DRIZZLE_YYABORT;
 
3392
            }
 
3393
          }
2825
3394
        | TRUNCATE_SYM '(' expr ',' expr ')'
2826
3395
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2827
3396
        | WAIT_SYM '(' expr ')'
2829
3398
            std::string wait_str("wait");
2830
3399
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2831
3400
            args->push_back($3);
2832
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
3401
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2833
3402
            {
2834
3403
              DRIZZLE_YYABORT;
2835
3404
            }
2836
3405
          }
2837
3406
        | UUID_SYM '(' ')'
2838
3407
          {
2839
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
 
3408
            if (! ($$= reserved_keyword_function(YYSession, "uuid", NULL)))
2840
3409
            {
2841
3410
              DRIZZLE_YYABORT;
2842
3411
            }
2848
3417
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2849
3418
            args->push_back($3);
2850
3419
            args->push_back($5);
2851
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
3420
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2852
3421
            {
2853
3422
              DRIZZLE_YYABORT;
2854
3423
            }
2873
3442
          }
2874
3443
          opt_udf_expr_list ')'
2875
3444
          {
 
3445
            Session *session= YYSession;
2876
3446
            Create_func *builder;
2877
3447
            Item *item= NULL;
2878
3448
 
2888
3458
            builder= find_native_function_builder($1);
2889
3459
            if (builder)
2890
3460
            {
2891
 
              item= builder->create(YYSession, $1, $4);
 
3461
              item= builder->create(session, $1, $4);
2892
3462
            }
2893
3463
            else
2894
3464
            {
2896
3466
              const plugin::Function *udf= $<udf>3;
2897
3467
              if (udf)
2898
3468
              {
2899
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3469
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2900
3470
              } else {
2901
3471
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2902
3472
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3013
3583
        ;
3014
3584
 
3015
3585
variable_aux:
3016
 
          user_variable_ident SET_VAR expr
 
3586
          ident_or_text SET_VAR expr
3017
3587
          {
3018
3588
            $$= new Item_func_set_user_var($1, $3);
3019
3589
            Lex->setCacheable(false);
3020
3590
          }
3021
 
        | user_variable_ident
 
3591
        | ident_or_text
3022
3592
          {
3023
3593
            $$= new Item_func_get_user_var(*YYSession, $1);
3024
3594
            Lex->setCacheable(false);
3025
3595
          }
3026
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3596
        | '@' opt_var_ident_type ident_or_text opt_component
3027
3597
          {
3028
3598
            /* disallow "SELECT @@global.global.variable" */
3029
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3599
            if ($3.str && $4.str && check_reserved_words(&$3))
3030
3600
            {
3031
 
              parser::my_parse_error(YYSession->m_lip);
 
3601
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3602
              my_parse_error(&pass);
3032
3603
              DRIZZLE_YYABORT;
3033
3604
            }
3034
3605
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3037
3608
        ;
3038
3609
 
3039
3610
opt_distinct:
3040
 
          /* empty */ { $$ = false; }
3041
 
        | DISTINCT    { $$ = true; }
 
3611
          /* empty */ { $$ = 0; }
 
3612
        | DISTINCT    { $$ = 1; }
3042
3613
        ;
3043
3614
 
3044
3615
opt_gconcat_separator:
3067
3638
in_sum_expr:
3068
3639
          opt_all
3069
3640
          {
3070
 
            if (Lex->current_select->inc_in_sum_expr())
 
3641
            LEX *lex= Lex;
 
3642
            if (lex->current_select->inc_in_sum_expr())
3071
3643
            {
3072
 
              parser::my_parse_error(YYSession->m_lip);
 
3644
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3645
              my_parse_error(&pass);
3073
3646
              DRIZZLE_YYABORT;
3074
3647
            }
3075
3648
          }
3089
3662
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3090
3663
        | SIGNED_SYM INT_SYM
3091
3664
          { $$=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
3665
        | UNSIGNED_SYM
3095
3666
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3096
3667
        | UNSIGNED_SYM INT_SYM
3151
3722
          table_factor { $$=$1; }
3152
3723
        | join_table
3153
3724
          {
3154
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3725
            LEX *lex= Lex;
 
3726
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3155
3727
              DRIZZLE_YYABORT;
3156
3728
          }
3157
3729
        ;
3298
3870
          }
3299
3871
          expr
3300
3872
          {
3301
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3873
            LEX *lex= Lex;
 
3874
            if (!($$= lex->current_select->convert_right_join()))
3302
3875
              DRIZZLE_YYABORT;
3303
3876
            add_join_on($$, $8);
3304
3877
            Lex->pop_context();
3310
3883
          }
3311
3884
          USING '(' using_list ')'
3312
3885
          {
3313
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3886
            LEX *lex= Lex;
 
3887
            if (!($$= lex->current_select->convert_right_join()))
3314
3888
              DRIZZLE_YYABORT;
3315
3889
            add_join_natural($$,$5,$9,Lex->current_select);
3316
3890
          }
3318
3892
          {
3319
3893
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3320
3894
            add_join_natural($6,$1,NULL,Lex->current_select);
3321
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3895
            LEX *lex= Lex;
 
3896
            if (!($$= lex->current_select->convert_right_join()))
3322
3897
              DRIZZLE_YYABORT;
3323
3898
          }
3324
3899
        ;
3326
3901
normal_join:
3327
3902
          JOIN_SYM {}
3328
3903
        | INNER_SYM JOIN_SYM {}
3329
 
        | CROSS JOIN_SYM
3330
 
          {
3331
 
            Lex->is_cross= true;
3332
 
            Lex->current_select->is_cross= true;
3333
 
          }
 
3904
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3334
3905
        ;
3335
3906
 
3336
3907
/*
3355
3926
          }
3356
3927
        | select_derived_init get_select_lex select_derived2
3357
3928
          {
3358
 
            Select_Lex *sel= Lex->current_select;
 
3929
            LEX *lex= Lex;
 
3930
            Select_Lex *sel= lex->current_select;
3359
3931
            if ($1)
3360
3932
            {
3361
3933
              if (sel->set_braces(1))
3362
3934
              {
3363
 
                parser::my_parse_error(YYSession->m_lip);
 
3935
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3936
                my_parse_error(&pass);
3364
3937
                DRIZZLE_YYABORT;
3365
3938
              }
3366
3939
              /* select in braces, can't contain global parameters */
3368
3941
                sel->master_unit()->global_parameters=
3369
3942
                   sel->master_unit()->fake_select_lex;
3370
3943
            }
3371
 
            if ($2->init_nested_join(Lex->session))
 
3944
            if ($2->init_nested_join(lex->session))
3372
3945
              DRIZZLE_YYABORT;
3373
3946
            $$= 0;
3374
3947
            /* incomplete derived tables return NULL, we must be
3410
3983
              /* Handle case of derived table, alias may be NULL if there
3411
3984
                 are no outer parentheses, add_table_to_list() will throw
3412
3985
                 error in this case */
3413
 
              Select_Lex *sel= Lex->current_select;
 
3986
              LEX *lex=Lex;
 
3987
              Select_Lex *sel= lex->current_select;
3414
3988
              Select_Lex_Unit *unit= sel->master_unit();
3415
 
              Lex->current_select= sel= unit->outer_select();
3416
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3989
              lex->current_select= sel= unit->outer_select();
 
3990
              if (!($$= sel->add_table_to_list(lex->session,
3417
3991
                                               new Table_ident(unit), $5, 0,
3418
3992
                                               TL_READ)))
3419
3993
 
3420
3994
                DRIZZLE_YYABORT;
3421
3995
              sel->add_joined_table($$);
3422
 
              Lex->pop_context();
 
3996
              lex->pop_context();
3423
3997
            }
3424
3998
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3425
3999
            {
3426
4000
              /* simple nested joins cannot have aliases or unions */
3427
 
              parser::my_parse_error(YYSession->m_lip);
 
4001
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4002
              my_parse_error(&pass);
3428
4003
              DRIZZLE_YYABORT;
3429
4004
            }
3430
4005
            else
3438
4013
          UNION_SYM
3439
4014
          union_option
3440
4015
          {
3441
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
4016
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3442
4017
              DRIZZLE_YYABORT;
3443
4018
          }
3444
4019
          query_specification
3456
4031
select_init2_derived:
3457
4032
          select_part2_derived
3458
4033
          {
3459
 
            Select_Lex * sel= Lex->current_select;
3460
 
            if (Lex->current_select->set_braces(0))
 
4034
            LEX *lex= Lex;
 
4035
            Select_Lex * sel= lex->current_select;
 
4036
            if (lex->current_select->set_braces(0))
3461
4037
            {
3462
 
              parser::my_parse_error(YYSession->m_lip);
 
4038
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4039
              my_parse_error(&pass);
3463
4040
              DRIZZLE_YYABORT;
3464
4041
            }
3465
4042
            if (sel->linkage == UNION_TYPE &&
3466
4043
                sel->master_unit()->first_select()->braces)
3467
4044
            {
3468
 
              parser::my_parse_error(YYSession->m_lip);
 
4045
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4046
              my_parse_error(&pass);
3469
4047
              DRIZZLE_YYABORT;
3470
4048
            }
3471
4049
          }
3474
4052
/* The equivalent of select_part2 for nested queries. */
3475
4053
select_part2_derived:
3476
4054
          {
3477
 
            Select_Lex *sel= Lex->current_select;
 
4055
            LEX *lex= Lex;
 
4056
            Select_Lex *sel= lex->current_select;
3478
4057
            if (sel->linkage != UNION_TYPE)
3479
 
              init_select(Lex);
3480
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4058
              init_select(lex);
 
4059
            lex->current_select->parsing_place= SELECT_LIST;
3481
4060
          }
3482
4061
          select_options select_item_list
3483
4062
          {
3490
4069
select_derived:
3491
4070
          get_select_lex
3492
4071
          {
3493
 
            if ($1->init_nested_join(Lex->session))
 
4072
            LEX *lex= Lex;
 
4073
            if ($1->init_nested_join(lex->session))
3494
4074
              DRIZZLE_YYABORT;
3495
4075
          }
3496
4076
          derived_table_list
3497
4077
          {
 
4078
            LEX *lex= Lex;
3498
4079
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3499
4080
               for derived tables, both must equal NULL */
3500
4081
 
3501
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
4082
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3502
4083
              DRIZZLE_YYABORT;
3503
 
 
3504
4084
            if (!$3 && $$)
3505
4085
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
4086
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4087
              my_parse_error(&pass);
3507
4088
              DRIZZLE_YYABORT;
3508
4089
            }
3509
4090
          }
3511
4092
 
3512
4093
select_derived2:
3513
4094
          {
3514
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3515
 
            if (not Lex->expr_allows_subselect)
 
4095
            LEX *lex= Lex;
 
4096
            lex->derived_tables|= DERIVED_SUBQUERY;
 
4097
            if (!lex->expr_allows_subselect)
3516
4098
            {
3517
 
              parser::my_parse_error(YYSession->m_lip);
 
4099
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4100
              my_parse_error(&pass);
3518
4101
              DRIZZLE_YYABORT;
3519
4102
            }
3520
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
4103
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
4104
                new_select(lex, 1))
3521
4105
              DRIZZLE_YYABORT;
3522
 
            init_select(Lex);
3523
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3524
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4106
            init_select(lex);
 
4107
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
4108
            lex->current_select->parsing_place= SELECT_LIST;
3525
4109
          }
3526
4110
          select_options select_item_list
3527
4111
          {
3537
4121
select_derived_init:
3538
4122
          SELECT_SYM
3539
4123
          {
3540
 
            Select_Lex *sel= Lex->current_select;
 
4124
            LEX *lex= Lex;
 
4125
 
 
4126
            Select_Lex *sel= lex->current_select;
3541
4127
            TableList *embedding;
3542
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
4128
            if (!sel->embedding || sel->end_nested_join(lex->session))
3543
4129
            {
3544
4130
              /* we are not in parentheses */
3545
 
              parser::my_parse_error(YYSession->m_lip);
 
4131
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4132
              my_parse_error(&pass);
3546
4133
              DRIZZLE_YYABORT;
3547
4134
            }
3548
4135
            embedding= Lex->current_select->embedding;
3690
4277
opt_table_alias:
3691
4278
          /* empty */ { $$=0; }
3692
4279
        | table_alias ident
3693
 
          {
3694
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3695
 
          }
 
4280
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3696
4281
        ;
3697
4282
 
3698
4283
opt_all:
3772
4357
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3773
4358
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3774
4359
            */
3775
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4360
            LEX *lex= Lex;
 
4361
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3776
4362
            {
3777
4363
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3778
4364
                       "global union parameters");
3779
4365
              DRIZZLE_YYABORT;
3780
4366
            }
3781
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4367
            lex->current_select->olap= ROLLUP_TYPE;
3782
4368
          }
3783
4369
        ;
3784
4370
 
3796
4382
        ;
3797
4383
 
3798
4384
alter_order_item:
3799
 
          simple_ident order_dir
 
4385
          simple_ident_nospvar order_dir
3800
4386
          {
 
4387
            Session *session= YYSession;
3801
4388
            bool ascending= ($2 == 1) ? true : false;
3802
 
            if (YYSession->add_order_to_list($1, ascending))
 
4389
            if (session->add_order_to_list($1, ascending))
3803
4390
              DRIZZLE_YYABORT;
3804
4391
          }
3805
4392
        ;
3816
4403
order_clause:
3817
4404
          ORDER_SYM BY
3818
4405
          {
3819
 
            if (not parser::buildOrderBy(Lex))
 
4406
            LEX *lex=Lex;
 
4407
            Select_Lex *sel= lex->current_select;
 
4408
            Select_Lex_Unit *unit= sel-> master_unit();
 
4409
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4410
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4411
                (sel->linkage != UNION_TYPE || sel->braces))
 
4412
            {
 
4413
              my_error(ER_WRONG_USAGE, MYF(0),
 
4414
                       "CUBE/ROLLUP", "ORDER BY");
3820
4415
              DRIZZLE_YYABORT;
 
4416
            }
 
4417
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4418
            {
 
4419
              /*
 
4420
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4421
                executed in the same way as the query
 
4422
                SELECT ... ORDER BY order_list
 
4423
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4424
                Otherwise we create a fake Select_Lex if it has not been created
 
4425
                yet.
 
4426
              */
 
4427
              Select_Lex *first_sl= unit->first_select();
 
4428
              if (!unit->is_union() &&
 
4429
                  (first_sl->order_list.elements ||
 
4430
                   first_sl->select_limit) &&           
 
4431
                  unit->add_fake_select_lex(lex->session))
 
4432
                DRIZZLE_YYABORT;
 
4433
            }
3821
4434
          }
3822
4435
          order_list
3823
4436
        ;
3824
4437
 
3825
4438
order_list:
3826
4439
          order_list ',' order_ident order_dir
3827
 
          {
3828
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3829
 
              DRIZZLE_YYABORT;
3830
 
          }
 
4440
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3831
4441
        | order_ident order_dir
3832
 
          {
3833
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3834
 
              DRIZZLE_YYABORT;
3835
 
          }
 
4442
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3836
4443
        ;
3837
4444
 
3838
4445
order_dir:
3844
4451
opt_limit_clause_init:
3845
4452
          /* empty */
3846
4453
          {
3847
 
            Select_Lex *sel= Lex->current_select;
 
4454
            LEX *lex= Lex;
 
4455
            Select_Lex *sel= lex->current_select;
3848
4456
            sel->offset_limit= 0;
3849
4457
            sel->select_limit= 0;
3850
4458
          }
3893
4501
delete_limit_clause:
3894
4502
          /* empty */
3895
4503
          {
3896
 
            Lex->current_select->select_limit= 0;
 
4504
            LEX *lex=Lex;
 
4505
            lex->current_select->select_limit= 0;
3897
4506
          }
3898
4507
        | LIMIT limit_option
3899
4508
          {
3904
4513
        ;
3905
4514
 
3906
4515
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); }
 
4516
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4517
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4518
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4519
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4520
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4521
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3913
4522
        ;
3914
4523
 
3915
4524
ulonglong_num:
3922
4531
 
3923
4532
select_var_list_init:
3924
4533
          {
3925
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4534
            LEX *lex=Lex;
 
4535
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3926
4536
              DRIZZLE_YYABORT;
3927
4537
          }
3928
4538
          select_var_list
3935
4545
        ;
3936
4546
 
3937
4547
select_var_ident: 
3938
 
          '@' user_variable_ident
 
4548
          '@' ident_or_text
3939
4549
          {
3940
 
            if (Lex->result)
3941
 
            {
3942
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3943
 
            }
 
4550
            LEX *lex=Lex;
 
4551
            if (lex->result)
 
4552
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3944
4553
            else
3945
 
            {
3946
4554
              /*
3947
4555
                The parser won't create select_result instance only
3948
4556
                if it's an EXPLAIN.
3949
4557
              */
3950
 
              assert(Lex->describe);
3951
 
            }
 
4558
              assert(lex->describe);
3952
4559
          }
3953
4560
        ;
3954
4561
 
3961
4568
into_destination:
3962
4569
          OUTFILE TEXT_STRING_filesystem
3963
4570
          {
3964
 
            Lex->setCacheable(false);
3965
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3966
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4571
            LEX *lex= Lex;
 
4572
            lex->setCacheable(false);
 
4573
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4574
                !(lex->result= new select_export(lex->exchange)))
3967
4575
              DRIZZLE_YYABORT;
3968
4576
          }
3969
4577
          opt_field_term opt_line_term
3970
4578
        | DUMPFILE TEXT_STRING_filesystem
3971
4579
          {
3972
 
            if (not Lex->describe)
 
4580
            LEX *lex=Lex;
 
4581
            if (!lex->describe)
3973
4582
            {
3974
 
              Lex->setCacheable(false);
3975
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4583
              lex->setCacheable(false);
 
4584
              if (!(lex->exchange= new file_exchange($2.str,1)))
3976
4585
                DRIZZLE_YYABORT;
3977
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4586
              if (!(lex->result= new select_dump(lex->exchange)))
3978
4587
                DRIZZLE_YYABORT;
3979
4588
            }
3980
4589
          }
3987
4596
*/
3988
4597
 
3989
4598
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;
 
4599
          DROP opt_temporary table_or_tables if_exists table_list
 
4600
          {
 
4601
            LEX *lex=Lex;
 
4602
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4603
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4604
            lex->statement= statement;
 
4605
            if (lex->statement == NULL)
 
4606
              DRIZZLE_YYABORT;
3998
4607
            statement->drop_temporary= $2;
3999
4608
            statement->drop_if_exists= $4;
4000
4609
          }
4001
4610
        | DROP build_method INDEX_SYM ident ON table_ident {}
4002
4611
          {
4003
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
4004
 
            Lex->statement= statement;
 
4612
            LEX *lex=Lex;
 
4613
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4614
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4615
            lex->statement= statement;
 
4616
            if (lex->statement == NULL)
 
4617
              DRIZZLE_YYABORT;
4005
4618
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4006
4619
            statement->alter_info.build_method= $2;
4007
4620
            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))
 
4621
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4622
                                                        TL_OPTION_UPDATING))
4010
4623
              DRIZZLE_YYABORT;
4011
4624
          }
4012
 
        | DROP DATABASE if_exists schema_name
 
4625
        | DROP DATABASE if_exists ident
4013
4626
          {
4014
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4015
 
            Lex->statement= statement;
 
4627
            LEX *lex=Lex;
 
4628
            lex->sql_command= SQLCOM_DROP_DB;
 
4629
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4630
            lex->statement= statement;
 
4631
            if (lex->statement == NULL)
 
4632
              DRIZZLE_YYABORT;
4016
4633
            statement->drop_if_exists=$3;
4017
 
            Lex->name= $4;
 
4634
            lex->name= $4;
4018
4635
          }
4019
 
        ;
4020
 
 
4021
4636
table_list:
4022
4637
          table_name
4023
4638
        | table_list ',' table_name
4032
4647
        ;
4033
4648
 
4034
4649
if_exists:
4035
 
          /* empty */ { $$= false; }
4036
 
        | IF EXISTS { $$= true; }
 
4650
          /* empty */ { $$= 0; }
 
4651
        | IF EXISTS { $$= 1; }
4037
4652
        ;
4038
4653
 
4039
4654
opt_temporary:
4040
 
          /* empty */ { $$= false; }
4041
 
        | TEMPORARY_SYM { $$= true; }
 
4655
          /* empty */ { $$= 0; }
 
4656
        | TEMPORARY_SYM { $$= 1; }
4042
4657
        ;
4043
4658
 
4044
4659
/*
4045
4660
  Execute a string as dynamic SQL.
4046
 
*/
 
4661
  */
4047
4662
 
4048
4663
execute:
4049
4664
       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
 
        }
 
4665
       {
 
4666
          LEX *lex= Lex;
 
4667
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession, $2, $3, $4, $5);
 
4668
          lex->statement= statement;
 
4669
          if (lex->statement == NULL)
 
4670
            DRIZZLE_YYABORT;
 
4671
       }
4053
4672
 
4054
4673
 
4055
4674
execute_var_or_string:
4056
 
         user_variable_ident
 
4675
         ident_or_text
4057
4676
         {
4058
4677
            $$.set($1);
4059
4678
         }
4060
 
        | '@' user_variable_ident
 
4679
        | '@' ident_or_text
4061
4680
        {
4062
4681
            $$.set($2, true);
4063
4682
        }
4064
4683
 
4065
4684
opt_status:
4066
 
          /* empty */ { $$= false; }
4067
 
        | WITH NO_SYM RETURN_SYM { $$= true; }
 
4685
          /* empty */ { $$= 0; }
 
4686
        | WITH NO_SYM RETURN_SYM { $$= 1; }
4068
4687
        ;
4069
4688
 
4070
4689
opt_concurrent:
4071
 
          /* empty */ { $$= false; }
4072
 
        | CONCURRENT { $$= true; }
 
4690
          /* empty */ { $$= 0; }
 
4691
        | CONCURRENT { $$= 1; }
4073
4692
        ;
4074
4693
 
4075
4694
opt_wait:
4076
 
          /* empty */ { $$= false; }
4077
 
        | WAIT_SYM { $$= true; }
 
4695
          /* empty */ { $$= 0; }
 
4696
        | WAIT_SYM { $$= 1; }
4078
4697
        ;
4079
4698
 
4080
4699
/*
4084
4703
insert:
4085
4704
          INSERT
4086
4705
          {
4087
 
            Lex->statement= new statement::Insert(YYSession);
4088
 
            Lex->duplicates= DUP_ERROR;
4089
 
            init_select(Lex);
 
4706
            LEX *lex= Lex;
 
4707
            lex->sql_command= SQLCOM_INSERT;
 
4708
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4709
            if (lex->statement == NULL)
 
4710
              DRIZZLE_YYABORT;
 
4711
            lex->duplicates= DUP_ERROR;
 
4712
            init_select(lex);
4090
4713
            /* for subselects */
4091
 
            Lex->lock_option= TL_READ;
 
4714
            lex->lock_option= TL_READ;
4092
4715
          }
4093
4716
          opt_ignore insert2
4094
4717
          {
4102
4725
replace:
4103
4726
          REPLACE
4104
4727
          {
4105
 
            Lex->statement= new statement::Replace(YYSession);
4106
 
            Lex->duplicates= DUP_REPLACE;
4107
 
            init_select(Lex);
 
4728
            LEX *lex= Lex;
 
4729
            lex->sql_command= SQLCOM_REPLACE;
 
4730
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4731
            if (lex->statement == NULL)
 
4732
              DRIZZLE_YYABORT;
 
4733
            lex->duplicates= DUP_REPLACE;
 
4734
            init_select(lex);
4108
4735
          }
4109
4736
          insert2
4110
4737
          {
4123
4750
insert_table:
4124
4751
          table_name
4125
4752
          {
4126
 
            Lex->field_list.empty();
4127
 
            Lex->many_values.empty();
4128
 
            Lex->insert_list=0;
 
4753
            LEX *lex=Lex;
 
4754
            lex->field_list.empty();
 
4755
            lex->many_values.empty();
 
4756
            lex->insert_list=0;
4129
4757
          };
4130
4758
 
4131
4759
insert_field_spec:
4134
4762
        | '(' fields ')' insert_values {}
4135
4763
        | SET_SYM
4136
4764
          {
4137
 
            if (not (Lex->insert_list = new List_item) ||
4138
 
                Lex->many_values.push_back(Lex->insert_list))
 
4765
            LEX *lex=Lex;
 
4766
            if (!(lex->insert_list = new List_item) ||
 
4767
                lex->many_values.push_back(lex->insert_list))
4139
4768
              DRIZZLE_YYABORT;
4140
4769
          }
4141
4770
          ident_eq_list
4149
4778
insert_values:
4150
4779
          VALUES values_list {}
4151
4780
        | VALUE_SYM values_list {}
4152
 
        | stored_select
4153
 
          {
4154
 
            Lex->current_select->set_braces(0);
4155
 
          }
 
4781
        | create_select
 
4782
          { Lex->current_select->set_braces(0);}
4156
4783
          union_clause {}
4157
 
        | '(' stored_select ')'
4158
 
          {
4159
 
            Lex->current_select->set_braces(1);
4160
 
          }
 
4784
        | '(' create_select ')'
 
4785
          { Lex->current_select->set_braces(1);}
4161
4786
          union_opt {}
4162
4787
        ;
4163
4788
 
4172
4797
        ;
4173
4798
 
4174
4799
ident_eq_value:
4175
 
          simple_ident equal expr_or_default
 
4800
          simple_ident_nospvar equal expr_or_default
4176
4801
          {
4177
 
            if (Lex->field_list.push_back($1) ||
4178
 
                Lex->insert_list->push_back($3))
 
4802
            LEX *lex=Lex;
 
4803
            if (lex->field_list.push_back($1) ||
 
4804
                lex->insert_list->push_back($3))
4179
4805
              DRIZZLE_YYABORT;
4180
4806
          }
4181
4807
        ;
4198
4824
          }
4199
4825
          opt_values ')'
4200
4826
          {
4201
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4827
            LEX *lex=Lex;
 
4828
            if (lex->many_values.push_back(lex->insert_list))
4202
4829
              DRIZZLE_YYABORT;
4203
4830
          }
4204
4831
        ;
4237
4864
update:
4238
4865
          UPDATE_SYM opt_ignore table_ident
4239
4866
          {
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))
 
4867
            LEX *lex= Lex;
 
4868
            init_select(lex);
 
4869
            lex->sql_command= SQLCOM_UPDATE;
 
4870
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4871
            if (lex->statement == NULL)
 
4872
              DRIZZLE_YYABORT;
 
4873
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4874
            lex->duplicates= DUP_ERROR;
 
4875
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4245
4876
              DRIZZLE_YYABORT;
4246
4877
          }
4247
4878
          SET_SYM update_list
4248
4879
          {
4249
 
            if (Lex->select_lex.get_table_list()->derived)
 
4880
            LEX *lex= Lex;
 
4881
            if (lex->select_lex.get_table_list()->derived)
4250
4882
            {
4251
4883
              /* it is single table update and it is update of derived table */
4252
4884
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4253
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4885
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4254
4886
              DRIZZLE_YYABORT;
4255
4887
            }
4256
4888
            /*
4269
4901
        ;
4270
4902
 
4271
4903
update_elem:
4272
 
          simple_ident equal expr_or_default
 
4904
          simple_ident_nospvar equal expr_or_default
4273
4905
          {
4274
4906
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4275
4907
              DRIZZLE_YYABORT;
4282
4914
        ;
4283
4915
 
4284
4916
insert_update_elem:
4285
 
          simple_ident equal expr_or_default
 
4917
          simple_ident_nospvar equal expr_or_default
4286
4918
          {
4287
 
          if (Lex->update_list.push_back($1) ||
4288
 
              Lex->value_list.push_back($3))
 
4919
          LEX *lex= Lex;
 
4920
          if (lex->update_list.push_back($1) ||
 
4921
              lex->value_list.push_back($3))
4289
4922
              DRIZZLE_YYABORT;
4290
4923
          }
4291
4924
        ;
4295
4928
delete:
4296
4929
          DELETE_SYM
4297
4930
          {
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();
 
4931
            LEX *lex= Lex;
 
4932
            lex->sql_command= SQLCOM_DELETE;
 
4933
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4934
            if (lex->statement == NULL)
 
4935
              DRIZZLE_YYABORT;
 
4936
            init_select(lex);
 
4937
            lex->lock_option= TL_WRITE_DEFAULT;
 
4938
            lex->ignore= 0;
 
4939
            lex->select_lex.init_order();
4303
4940
          }
4304
4941
          opt_delete_options single_multi
4305
4942
        ;
4327
4964
truncate:
4328
4965
          TRUNCATE_SYM opt_table_sym table_name
4329
4966
          {
4330
 
            Lex->statement= new statement::Truncate(YYSession);
4331
 
            Lex->select_lex.options= 0;
4332
 
            Lex->select_lex.init_order();
 
4967
            LEX* lex= Lex;
 
4968
            lex->sql_command= SQLCOM_TRUNCATE;
 
4969
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4970
            if (lex->statement == NULL)
 
4971
              DRIZZLE_YYABORT;
 
4972
            lex->select_lex.options= 0;
 
4973
            lex->select_lex.init_order();
4333
4974
          }
4334
4975
        ;
4335
4976
 
4343
4984
show:
4344
4985
          SHOW
4345
4986
          {
4346
 
            Lex->lock_option= TL_READ;
4347
 
            init_select(Lex);
4348
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4987
            LEX *lex=Lex;
 
4988
            lex->wild=0;
 
4989
            lex->lock_option= TL_READ;
 
4990
            init_select(lex);
 
4991
            lex->current_select->parsing_place= SELECT_LIST;
4349
4992
          }
4350
4993
          show_param
4351
4994
          {}
4355
4998
show_param:
4356
4999
           DATABASES show_wild
4357
5000
           {
4358
 
             if (not show::buildScemas(YYSession))
4359
 
               DRIZZLE_YYABORT;
 
5001
             LEX *lex= Lex;
 
5002
             Session *session= YYSession;
 
5003
 
 
5004
             lex->sql_command= SQLCOM_SELECT;
 
5005
             lex->statement=
 
5006
               new(std::nothrow) statement::Show(session);
 
5007
             if (lex->statement == NULL)
 
5008
               DRIZZLE_YYABORT;
 
5009
 
 
5010
             std::string column_name= "Database";
 
5011
             if (Lex->wild)
 
5012
             {
 
5013
               column_name.append(" (");
 
5014
               column_name.append(Lex->wild->ptr());
 
5015
               column_name.append(")");
 
5016
             }
 
5017
 
 
5018
             if (Lex->current_select->where)
 
5019
             {
 
5020
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
5021
                 DRIZZLE_YYABORT;
 
5022
             }
 
5023
             else
 
5024
             {
 
5025
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
5026
                 DRIZZLE_YYABORT;
 
5027
             }
 
5028
 
 
5029
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5030
             my_field->is_autogenerated_name= false;
 
5031
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
5032
 
 
5033
             if (session->add_item_to_list(my_field))
 
5034
               DRIZZLE_YYABORT;
 
5035
 
 
5036
              if (session->add_order_to_list(my_field, true))
 
5037
                DRIZZLE_YYABORT;
4360
5038
           }
4361
5039
           /* SHOW TABLES */
4362
5040
         | TABLES opt_db show_wild
4363
5041
           {
4364
 
             if (not show::buildTables(YYSession, $2))
4365
 
               DRIZZLE_YYABORT;
 
5042
             LEX *lex= Lex;
 
5043
             Session *session= YYSession;
 
5044
 
 
5045
             lex->sql_command= SQLCOM_SELECT;
 
5046
 
 
5047
             statement::Show *select=
 
5048
               new(std::nothrow) statement::Show(YYSession);
 
5049
 
 
5050
             lex->statement= select;
 
5051
 
 
5052
             if (lex->statement == NULL)
 
5053
               DRIZZLE_YYABORT;
 
5054
 
 
5055
 
 
5056
              std::string column_name= "Tables_in_";
 
5057
 
 
5058
              util::string::const_shared_ptr schema(session->schema());
 
5059
              if ($2)
 
5060
              {
 
5061
                SchemaIdentifier identifier($2);
 
5062
                column_name.append($2);
 
5063
                lex->select_lex.db= $2;
 
5064
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
5065
                {
 
5066
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
5067
                }
 
5068
                select->setShowPredicate($2, "");
 
5069
              }
 
5070
              else if (schema and not schema->empty())
 
5071
              {
 
5072
                column_name.append(*schema);
 
5073
                select->setShowPredicate(*schema, "");
 
5074
              }
 
5075
              else
 
5076
              {
 
5077
                my_error(ER_NO_DB_ERROR, MYF(0));
 
5078
                DRIZZLE_YYABORT;
 
5079
              }
 
5080
 
 
5081
 
 
5082
             if (Lex->wild)
 
5083
             {
 
5084
               column_name.append(" (");
 
5085
               column_name.append(Lex->wild->ptr());
 
5086
               column_name.append(")");
 
5087
             }
 
5088
 
 
5089
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
5090
               DRIZZLE_YYABORT;
 
5091
 
 
5092
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5093
             my_field->is_autogenerated_name= false;
 
5094
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
5095
 
 
5096
             if (session->add_item_to_list(my_field))
 
5097
               DRIZZLE_YYABORT;
 
5098
 
 
5099
              if (session->add_order_to_list(my_field, true))
 
5100
                DRIZZLE_YYABORT;
4366
5101
           }
4367
5102
           /* SHOW TEMPORARY TABLES */
4368
5103
         | TEMPORARY_SYM TABLES show_wild
4369
5104
           {
4370
 
             if (not show::buildTemporaryTables(YYSession))
4371
 
               DRIZZLE_YYABORT;
 
5105
             LEX *lex= Lex;
 
5106
             Session *session= YYSession;
 
5107
 
 
5108
             lex->sql_command= SQLCOM_SELECT;
 
5109
 
 
5110
             statement::Show *select=
 
5111
               new(std::nothrow) statement::Show(YYSession);
 
5112
 
 
5113
             lex->statement= select;
 
5114
 
 
5115
             if (lex->statement == NULL)
 
5116
               DRIZZLE_YYABORT;
 
5117
 
 
5118
 
 
5119
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
 
5120
               DRIZZLE_YYABORT;
 
5121
 
 
5122
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5123
                                                           context,
 
5124
                                                           NULL, NULL, "*")))
 
5125
               DRIZZLE_YYABORT;
 
5126
             (session->lex->current_select->with_wild)++;
 
5127
 
4372
5128
           }
4373
5129
           /* SHOW TABLE STATUS */
4374
5130
         | TABLE_SYM STATUS_SYM opt_db show_wild
4375
5131
           {
4376
 
             if (not show::buildTableStatus(YYSession, $3))
4377
 
               DRIZZLE_YYABORT;
 
5132
             LEX *lex= Lex;
 
5133
             lex->sql_command= SQLCOM_SELECT;
 
5134
             statement::Show *select=
 
5135
               new(std::nothrow) statement::Show(YYSession);
 
5136
 
 
5137
             lex->statement= select;
 
5138
 
 
5139
             if (lex->statement == NULL)
 
5140
               DRIZZLE_YYABORT;
 
5141
 
 
5142
             Session *session= YYSession;
 
5143
 
 
5144
             std::string column_name= "Tables_in_";
 
5145
 
 
5146
             util::string::const_shared_ptr schema(session->schema());
 
5147
             if ($3)
 
5148
             {
 
5149
               lex->select_lex.db= $3;
 
5150
 
 
5151
               SchemaIdentifier identifier($3);
 
5152
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
5153
               {
 
5154
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
5155
               }
 
5156
 
 
5157
               select->setShowPredicate($3, "");
 
5158
             }
 
5159
             else if (schema)
 
5160
             {
 
5161
               select->setShowPredicate(*schema, "");
 
5162
             }
 
5163
             else
 
5164
             {
 
5165
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5166
               DRIZZLE_YYABORT;
 
5167
             }
 
5168
 
 
5169
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
5170
               DRIZZLE_YYABORT;
 
5171
 
 
5172
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5173
                                                           context,
 
5174
                                                           NULL, NULL, "*")))
 
5175
               DRIZZLE_YYABORT;
 
5176
             (session->lex->current_select->with_wild)++;
4378
5177
           }
4379
5178
           /* SHOW COLUMNS FROM table_name */
4380
5179
        | COLUMNS from_or_in table_ident opt_db show_wild
4381
 
           {
4382
 
             if (not show::buildColumns(YYSession, $4, $3))
4383
 
               DRIZZLE_YYABORT;
4384
 
           }
 
5180
          {
 
5181
             LEX *lex= Lex;
 
5182
             Session *session= YYSession;
 
5183
             statement::Show *select;
 
5184
 
 
5185
             lex->sql_command= SQLCOM_SELECT;
 
5186
 
 
5187
             select= new(std::nothrow) statement::Show(session);
 
5188
 
 
5189
             lex->statement= select;
 
5190
 
 
5191
             if (lex->statement == NULL)
 
5192
               DRIZZLE_YYABORT;
 
5193
 
 
5194
             util::string::const_shared_ptr schema(session->schema());
 
5195
             if ($4)
 
5196
             {
 
5197
              select->setShowPredicate($4, $3->table.str);
 
5198
             }
 
5199
             else if ($3->db.str)
 
5200
             {
 
5201
              select->setShowPredicate($3->db.str, $3->table.str);
 
5202
             }
 
5203
             else if (schema)
 
5204
             {
 
5205
               select->setShowPredicate(*schema, $3->table.str);
 
5206
             }
 
5207
             else
 
5208
             {
 
5209
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5210
               DRIZZLE_YYABORT;
 
5211
             }
 
5212
 
 
5213
             {
 
5214
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5215
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5216
               {
 
5217
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5218
                            select->getShowSchema().c_str(), 
 
5219
                            $3->table.str);
 
5220
               }
 
5221
             }
 
5222
 
 
5223
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5224
               DRIZZLE_YYABORT;
 
5225
 
 
5226
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5227
                                                           context,
 
5228
                                                           NULL, NULL, "*")))
 
5229
               DRIZZLE_YYABORT;
 
5230
             (session->lex->current_select->with_wild)++;
 
5231
 
 
5232
          }
4385
5233
          /* SHOW INDEXES from table */
4386
5234
        | 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
 
           }
 
5235
          {
 
5236
             LEX *lex= Lex;
 
5237
             Session *session= YYSession;
 
5238
             statement::Show *select;
 
5239
 
 
5240
             lex->sql_command= SQLCOM_SELECT;
 
5241
 
 
5242
             select= new(std::nothrow) statement::Show(session);
 
5243
 
 
5244
             lex->statement= select;
 
5245
 
 
5246
             if (lex->statement == NULL)
 
5247
               DRIZZLE_YYABORT;
 
5248
 
 
5249
             util::string::const_shared_ptr schema(session->schema());
 
5250
             if ($4)
 
5251
             {
 
5252
              select->setShowPredicate($4, $3->table.str);
 
5253
             }
 
5254
             else if ($3->db.str)
 
5255
             {
 
5256
              select->setShowPredicate($3->db.str, $3->table.str);
 
5257
             }
 
5258
             else if (schema)
 
5259
             {
 
5260
               select->setShowPredicate(*schema, $3->table.str);
 
5261
             }
 
5262
             else
 
5263
             {
 
5264
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5265
               DRIZZLE_YYABORT;
 
5266
             }
 
5267
 
 
5268
             {
 
5269
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5270
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5271
               {
 
5272
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5273
                            select->getShowSchema().c_str(), 
 
5274
                            $3->table.str);
 
5275
               }
 
5276
             }
 
5277
 
 
5278
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
5279
               DRIZZLE_YYABORT;
 
5280
 
 
5281
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5282
                                                           context,
 
5283
                                                           NULL, NULL, "*")))
 
5284
               DRIZZLE_YYABORT;
 
5285
             (session->lex->current_select->with_wild)++;
 
5286
          }
4391
5287
        | COUNT_SYM '(' '*' ')' WARNINGS
4392
5288
          {
4393
 
            show::buildSelectWarning(YYSession);
 
5289
            (void) create_select_for_variable("warning_count");
 
5290
            LEX *lex= Lex;
 
5291
            lex->statement= new(std::nothrow) statement::Show(YYSession);
 
5292
            if (lex->statement == NULL)
 
5293
              DRIZZLE_YYABORT;
4394
5294
          }
4395
5295
        | COUNT_SYM '(' '*' ')' ERRORS
4396
5296
          {
4397
 
            show::buildSelectError(YYSession);
 
5297
            (void) create_select_for_variable("error_count");
 
5298
            LEX *lex= Lex;
 
5299
            lex->statement= new(std::nothrow) statement::Show(YYSession);
 
5300
            if (lex->statement == NULL)
 
5301
              DRIZZLE_YYABORT;
4398
5302
          }
4399
5303
        | WARNINGS opt_limit_clause_init
4400
5304
          {
4401
 
            show::buildWarnings(YYSession);
 
5305
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5306
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
5307
            if (Lex->statement == NULL)
 
5308
              DRIZZLE_YYABORT;
4402
5309
          }
4403
5310
        | ERRORS opt_limit_clause_init
4404
5311
          {
4405
 
            show::buildErrors(YYSession);
 
5312
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5313
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
5314
            if (Lex->statement == NULL)
 
5315
              DRIZZLE_YYABORT;
4406
5316
          }
4407
5317
        | 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
 
          }
 
5318
           {
 
5319
             LEX *lex= Lex;
 
5320
             lex->sql_command= SQLCOM_SELECT;
 
5321
             lex->statement=
 
5322
               new(std::nothrow) statement::Show(YYSession);
 
5323
             if (lex->statement == NULL)
 
5324
               DRIZZLE_YYABORT;
 
5325
 
 
5326
             Session *session= YYSession;
 
5327
 
 
5328
             if ($1 == OPT_GLOBAL)
 
5329
             {
 
5330
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5331
                 DRIZZLE_YYABORT;
 
5332
             }
 
5333
             else
 
5334
             {
 
5335
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5336
                 DRIZZLE_YYABORT;
 
5337
             }
 
5338
 
 
5339
             std::string key("Variable_name");
 
5340
             std::string value("Value");
 
5341
 
 
5342
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5343
             my_field->is_autogenerated_name= false;
 
5344
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5345
 
 
5346
             if (session->add_item_to_list(my_field))
 
5347
               DRIZZLE_YYABORT;
 
5348
 
 
5349
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5350
             my_field->is_autogenerated_name= false;
 
5351
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5352
 
 
5353
             if (session->add_item_to_list(my_field))
 
5354
               DRIZZLE_YYABORT;
 
5355
           }
4417
5356
        | CREATE TABLE_SYM table_ident
4418
 
          {
4419
 
            if (not show::buildCreateTable(YYSession, $3))
4420
 
              DRIZZLE_YYABORT;
4421
 
          }
 
5357
           {
 
5358
             LEX *lex= Lex;
 
5359
             lex->sql_command= SQLCOM_SELECT;
 
5360
             statement::Show *select=
 
5361
               new(std::nothrow) statement::Show(YYSession);
 
5362
 
 
5363
             lex->statement= select;
 
5364
 
 
5365
             if (lex->statement == NULL)
 
5366
               DRIZZLE_YYABORT;
 
5367
 
 
5368
             Session *session= YYSession;
 
5369
 
 
5370
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
 
5371
               DRIZZLE_YYABORT;
 
5372
 
 
5373
             util::string::const_shared_ptr schema(session->schema());
 
5374
             if ($3->db.str)
 
5375
             {
 
5376
               select->setShowPredicate($3->db.str, $3->table.str);
 
5377
             }
 
5378
             else if (schema)
 
5379
             {
 
5380
               select->setShowPredicate(*schema, $3->table.str);
 
5381
             }
 
5382
             else
 
5383
             {
 
5384
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5385
               DRIZZLE_YYABORT;
 
5386
             }
 
5387
 
 
5388
             std::string key("Table");
 
5389
             std::string value("Create Table");
 
5390
 
 
5391
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5392
             my_field->is_autogenerated_name= false;
 
5393
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5394
 
 
5395
             if (session->add_item_to_list(my_field))
 
5396
               DRIZZLE_YYABORT;
 
5397
 
 
5398
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5399
             my_field->is_autogenerated_name= false;
 
5400
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5401
 
 
5402
             if (session->add_item_to_list(my_field))
 
5403
               DRIZZLE_YYABORT;
 
5404
           }
4422
5405
        | PROCESSLIST_SYM
4423
5406
          {
4424
 
            if (not show::buildProcesslist(YYSession))
4425
 
              DRIZZLE_YYABORT;
 
5407
           {
 
5408
             LEX *lex= Lex;
 
5409
             lex->sql_command= SQLCOM_SELECT;
 
5410
             lex->statement=
 
5411
               new(std::nothrow) statement::Show(YYSession);
 
5412
             if (lex->statement == NULL)
 
5413
               DRIZZLE_YYABORT;
 
5414
 
 
5415
             Session *session= YYSession;
 
5416
 
 
5417
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
5418
               DRIZZLE_YYABORT;
 
5419
 
 
5420
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5421
                                                           context,
 
5422
                                                           NULL, NULL, "*")))
 
5423
               DRIZZLE_YYABORT;
 
5424
             (session->lex->current_select->with_wild)++;
 
5425
           }
4426
5426
          }
4427
5427
        | opt_var_type  VARIABLES show_wild
4428
 
          {
4429
 
            if (not show::buildVariables(YYSession, $1))
4430
 
              DRIZZLE_YYABORT;
4431
 
          }
 
5428
           {
 
5429
             LEX *lex= Lex;
 
5430
             lex->sql_command= SQLCOM_SELECT;
 
5431
             lex->statement=
 
5432
               new(std::nothrow) statement::Show(YYSession);
 
5433
             if (lex->statement == NULL)
 
5434
               DRIZZLE_YYABORT;
 
5435
 
 
5436
             Session *session= YYSession;
 
5437
 
 
5438
             if ($1 == OPT_GLOBAL)
 
5439
             {
 
5440
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5441
                 DRIZZLE_YYABORT;
 
5442
             }
 
5443
             else
 
5444
             {
 
5445
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5446
                 DRIZZLE_YYABORT;
 
5447
             }
 
5448
 
 
5449
             std::string key("Variable_name");
 
5450
             std::string value("Value");
 
5451
 
 
5452
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5453
             my_field->is_autogenerated_name= false;
 
5454
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5455
 
 
5456
             if (session->add_item_to_list(my_field))
 
5457
               DRIZZLE_YYABORT;
 
5458
 
 
5459
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5460
             my_field->is_autogenerated_name= false;
 
5461
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5462
 
 
5463
             if (session->add_item_to_list(my_field))
 
5464
               DRIZZLE_YYABORT;
 
5465
           }
4432
5466
        | CREATE DATABASE opt_if_not_exists ident
4433
 
          {
4434
 
            if (not show::buildCreateSchema(YYSession, $4))
4435
 
              DRIZZLE_YYABORT;
4436
 
          }
 
5467
           {
 
5468
             LEX *lex= Lex;
 
5469
             lex->sql_command= SQLCOM_SELECT;
 
5470
             statement::Show *select=
 
5471
               new(std::nothrow) statement::Show(YYSession);
 
5472
 
 
5473
             lex->statement= select;
 
5474
 
 
5475
             if (lex->statement == NULL)
 
5476
               DRIZZLE_YYABORT;
 
5477
 
 
5478
             Session *session= YYSession;
 
5479
 
 
5480
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
 
5481
               DRIZZLE_YYABORT;
 
5482
 
 
5483
             util::string::const_shared_ptr schema(session->schema());
 
5484
             if ($4.str)
 
5485
             {
 
5486
              select->setShowPredicate($4.str);
 
5487
             }
 
5488
             else if (schema)
 
5489
             {
 
5490
               select->setShowPredicate(*schema);
 
5491
             }
 
5492
             else
 
5493
             {
 
5494
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5495
               DRIZZLE_YYABORT;
 
5496
             }
 
5497
 
 
5498
             std::string key("Database");
 
5499
             std::string value("Create Database");
 
5500
 
 
5501
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5502
             my_field->is_autogenerated_name= false;
 
5503
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5504
 
 
5505
             if (session->add_item_to_list(my_field))
 
5506
               DRIZZLE_YYABORT;
 
5507
 
 
5508
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5509
             my_field->is_autogenerated_name= false;
 
5510
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5511
 
 
5512
             if (session->add_item_to_list(my_field))
 
5513
               DRIZZLE_YYABORT;
 
5514
           }
4437
5515
 
4438
5516
opt_db:
4439
5517
          /* empty */  { $$= 0; }
4466
5544
describe:
4467
5545
          describe_command table_ident
4468
5546
          {
4469
 
            if (not show::buildDescribe(YYSession, $2))
4470
 
            {
 
5547
            Session *session= YYSession;
 
5548
            statement::Show *select;
 
5549
            LEX *lex= Lex;
 
5550
            lex->lock_option= TL_READ;
 
5551
            init_select(lex);
 
5552
            lex->current_select->parsing_place= SELECT_LIST;
 
5553
            lex->sql_command= SQLCOM_SELECT;
 
5554
            select= new(std::nothrow) statement::Show(session);
 
5555
            lex->statement= select;
 
5556
            if (lex->statement == NULL)
4471
5557
              DRIZZLE_YYABORT;
4472
 
            }
 
5558
            lex->select_lex.db= 0;
 
5559
 
 
5560
             util::string::const_shared_ptr schema(session->schema());
 
5561
             if ($2->db.str)
 
5562
             {
 
5563
               select->setShowPredicate($2->db.str, $2->table.str);
 
5564
             }
 
5565
             else if (schema)
 
5566
             {
 
5567
               select->setShowPredicate(*schema, $2->table.str);
 
5568
             }
 
5569
             else
 
5570
             {
 
5571
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5572
               DRIZZLE_YYABORT;
 
5573
             }
 
5574
 
 
5575
             {
 
5576
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5577
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5578
               {
 
5579
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5580
                            select->getShowSchema().c_str(), 
 
5581
                            $2->table.str);
 
5582
               }
 
5583
             }
 
5584
 
 
5585
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5586
               DRIZZLE_YYABORT;
 
5587
 
 
5588
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5589
                                                           context,
 
5590
                                                           NULL, NULL, "*")))
 
5591
             {
 
5592
               DRIZZLE_YYABORT;
 
5593
             }
 
5594
             (session->lex->current_select->with_wild)++;
 
5595
 
4473
5596
          }
4474
5597
          opt_describe_column {}
4475
5598
        | describe_command opt_extended_describe
4476
5599
          { Lex->describe|= DESCRIBE_NORMAL; }
4477
5600
          select
4478
5601
          {
4479
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5602
            LEX *lex=Lex;
 
5603
            lex->select_lex.options|= SELECT_DESCRIBE;
4480
5604
          }
4481
5605
        ;
4482
5606
 
4507
5631
flush:
4508
5632
          FLUSH_SYM
4509
5633
          {
4510
 
            Lex->statement= new statement::Flush(YYSession);
 
5634
            LEX *lex=Lex;
 
5635
            lex->sql_command= SQLCOM_FLUSH;
 
5636
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5637
            if (lex->statement == NULL)
 
5638
              DRIZZLE_YYABORT;
 
5639
            lex->type= 0;
4511
5640
          }
4512
5641
          flush_options
4513
5642
          {}
4557
5686
kill:
4558
5687
          KILL_SYM kill_option expr
4559
5688
          {
4560
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5689
            LEX *lex=Lex;
 
5690
 
 
5691
            if ($2)
 
5692
            {
 
5693
              Lex->type= ONLY_KILL_QUERY;
 
5694
            }
 
5695
            else
 
5696
            {
 
5697
              Lex->type= 0;
 
5698
            }
 
5699
 
 
5700
            lex->value_list.empty();
 
5701
            lex->value_list.push_front($3);
 
5702
            lex->sql_command= SQLCOM_KILL;
 
5703
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5704
            if (lex->statement == NULL)
 
5705
              DRIZZLE_YYABORT;
4561
5706
          }
4562
5707
        ;
4563
5708
 
4564
5709
kill_option:
4565
 
          /* empty */ { $$= false; }
4566
 
        | CONNECTION_SYM { $$= false; }
4567
 
        | QUERY_SYM      { $$= true; }
 
5710
          /* empty */ { $$= 0; }
 
5711
        | CONNECTION_SYM { $$= 0; }
 
5712
        | QUERY_SYM      { $$= 1; }
4568
5713
        ;
4569
5714
 
4570
5715
/* change database */
4571
5716
 
4572
5717
use:
4573
 
          USE_SYM schema_name
 
5718
          USE_SYM ident
4574
5719
          {
4575
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4576
 
            Lex->select_lex.db= $2.str;
 
5720
            LEX *lex=Lex;
 
5721
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5722
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5723
            if (lex->statement == NULL)
 
5724
              DRIZZLE_YYABORT;
 
5725
            lex->select_lex.db= $2.str;
4577
5726
          }
4578
5727
        ;
4579
5728
 
4582
5731
load:
4583
5732
          LOAD data_file
4584
5733
          {
4585
 
            statement::Load *statement= new statement::Load(YYSession);
4586
 
            Lex->statement= statement;
4587
 
 
4588
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5734
            Session *session= YYSession;
 
5735
            LEX *lex= session->lex;
 
5736
 
 
5737
            lex->sql_command= SQLCOM_LOAD;
 
5738
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5739
            lex->statement= statement;
 
5740
            if (lex->statement == NULL)
 
5741
              DRIZZLE_YYABORT;
 
5742
 
 
5743
            Lex_input_stream *lip= session->m_lip;
4589
5744
            statement->fname_start= lip->get_ptr();
4590
5745
          }
4591
5746
          load_data_lock INFILE TEXT_STRING_filesystem
4592
5747
          {
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)))
 
5748
            LEX *lex=Lex;
 
5749
            lex->lock_option= $4;
 
5750
            lex->duplicates= DUP_ERROR;
 
5751
            lex->ignore= 0;
 
5752
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4597
5753
              DRIZZLE_YYABORT;
4598
5754
          }
4599
5755
          opt_duplicate INTO
4600
5756
          {
4601
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5757
            Session *session= YYSession;
 
5758
            Lex_input_stream *lip= session->m_lip;
4602
5759
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4603
5760
          }
4604
5761
          TABLE_SYM table_ident
4605
5762
          {
 
5763
            LEX *lex=Lex;
4606
5764
            if (!Lex->current_select->add_table_to_list(YYSession,
4607
5765
                    $12, NULL, TL_OPTION_UPDATING,
4608
 
                    Lex->lock_option))
 
5766
                    lex->lock_option))
4609
5767
              DRIZZLE_YYABORT;
4610
 
            Lex->field_list.empty();
4611
 
            Lex->update_list.empty();
4612
 
            Lex->value_list.empty();
 
5768
            lex->field_list.empty();
 
5769
            lex->update_list.empty();
 
5770
            lex->value_list.empty();
4613
5771
          }
4614
5772
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4615
5773
          opt_load_data_set_spec
4633
5791
        | IGNORE_SYM { Lex->ignore= 1; }
4634
5792
        ;
4635
5793
 
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
5794
opt_field_term:
4646
5795
          /* empty */
4647
5796
        | COLUMNS field_term_list
4660
5809
          }
4661
5810
        | OPTIONALLY ENCLOSED BY text_string
4662
5811
          {
4663
 
            assert(Lex->exchange != 0);
4664
 
            Lex->exchange->enclosed= $4;
4665
 
            Lex->exchange->opt_enclosed= 1;
 
5812
            LEX *lex= Lex;
 
5813
            assert(lex->exchange != 0);
 
5814
            lex->exchange->enclosed= $4;
 
5815
            lex->exchange->opt_enclosed= 1;
4666
5816
          }
4667
5817
        | ENCLOSED BY text_string
4668
5818
          {
4727
5877
        ;
4728
5878
 
4729
5879
field_or_var:
4730
 
          simple_ident {$$= $1;}
4731
 
        | '@' user_variable_ident
 
5880
          simple_ident_nospvar {$$= $1;}
 
5881
        | '@' ident_or_text
4732
5882
          { $$= new Item_user_var_as_out_param($2); }
4733
5883
        ;
4734
5884
 
4742
5892
text_literal:
4743
5893
        TEXT_STRING_literal
4744
5894
        {
4745
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5895
          Session *session= YYSession;
 
5896
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4746
5897
        }
4747
5898
        | text_literal TEXT_STRING_literal
4748
5899
          {
4842
5993
**********************************************************************/
4843
5994
 
4844
5995
insert_ident:
4845
 
          simple_ident { $$=$1; }
 
5996
          simple_ident_nospvar { $$=$1; }
4846
5997
        | table_wild { $$=$1; }
4847
5998
        ;
4848
5999
 
4849
6000
table_wild:
4850
6001
          ident '.' '*'
4851
6002
          {
4852
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
6003
            Select_Lex *sel= Lex->current_select;
 
6004
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
6005
            sel->with_wild++;
4853
6006
          }
4854
6007
        | ident '.' ident '.' '*'
4855
6008
          {
4856
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
6009
            Select_Lex *sel= Lex->current_select;
 
6010
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
6011
            sel->with_wild++;
4857
6012
          }
4858
6013
        ;
4859
6014
 
4864
6019
simple_ident:
4865
6020
          ident
4866
6021
          {
4867
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
6022
            {
 
6023
              Select_Lex *sel=Lex->current_select;
 
6024
              $$= (sel->parsing_place != IN_HAVING ||
 
6025
                  sel->get_in_sum_expr() > 0) ?
 
6026
                  (Item*) new Item_field(Lex->current_context(),
 
6027
                                         (const char *)NULL, NULL, $1.str) :
 
6028
                  (Item*) new Item_ref(Lex->current_context(),
 
6029
                                       (const char *)NULL, NULL, $1.str);
 
6030
            }
 
6031
          }
 
6032
        | simple_ident_q { $$= $1; }
 
6033
        ;
 
6034
 
 
6035
simple_ident_nospvar:
 
6036
          ident
 
6037
          {
 
6038
            Select_Lex *sel=Lex->current_select;
 
6039
            $$= (sel->parsing_place != IN_HAVING ||
 
6040
                sel->get_in_sum_expr() > 0) ?
 
6041
                (Item*) new Item_field(Lex->current_context(),
 
6042
                                       (const char *)NULL, NULL, $1.str) :
 
6043
                (Item*) new Item_ref(Lex->current_context(),
 
6044
                                     (const char *)NULL, NULL, $1.str);
4868
6045
          }
4869
6046
        | simple_ident_q { $$= $1; }
4870
6047
        ;
4872
6049
simple_ident_q:
4873
6050
          ident '.' ident
4874
6051
          {
4875
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
6052
            Session *session= YYSession;
 
6053
            LEX *lex= session->lex;
 
6054
 
 
6055
            {
 
6056
              Select_Lex *sel= lex->current_select;
 
6057
              if (sel->no_table_names_allowed)
 
6058
              {
 
6059
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6060
                         MYF(0), $1.str, session->where);
 
6061
              }
 
6062
              $$= (sel->parsing_place != IN_HAVING ||
 
6063
                  sel->get_in_sum_expr() > 0) ?
 
6064
                  (Item*) new Item_field(Lex->current_context(),
 
6065
                                         (const char *)NULL, $1.str, $3.str) :
 
6066
                  (Item*) new Item_ref(Lex->current_context(),
 
6067
                                       (const char *)NULL, $1.str, $3.str);
 
6068
            }
4876
6069
          }
4877
6070
        | '.' ident '.' ident
4878
6071
          {
4879
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
6072
            Session *session= YYSession;
 
6073
            LEX *lex= session->lex;
 
6074
            Select_Lex *sel= lex->current_select;
 
6075
            if (sel->no_table_names_allowed)
 
6076
            {
 
6077
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6078
                       MYF(0), $2.str, session->where);
 
6079
            }
 
6080
            $$= (sel->parsing_place != IN_HAVING ||
 
6081
                sel->get_in_sum_expr() > 0) ?
 
6082
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
6083
                (Item*) new Item_ref(Lex->current_context(),
 
6084
                                     (const char *)NULL, $2.str, $4.str);
4880
6085
          }
4881
6086
        | ident '.' ident '.' ident
4882
6087
          {
4883
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
6088
            Session *session= YYSession;
 
6089
            LEX *lex= session->lex;
 
6090
            Select_Lex *sel= lex->current_select;
 
6091
            if (sel->no_table_names_allowed)
 
6092
            {
 
6093
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6094
                       MYF(0), $3.str, session->where);
 
6095
            }
 
6096
            $$= (sel->parsing_place != IN_HAVING ||
 
6097
                sel->get_in_sum_expr() > 0) ?
 
6098
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
6099
                                       $5.str) :
 
6100
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
6101
                                     $5.str);
4884
6102
          }
4885
6103
        ;
4886
6104
 
4887
6105
field_ident:
4888
 
          ident 
4889
 
          {
4890
 
            $$=$1;
4891
 
          }
 
6106
          ident { $$=$1;}
4892
6107
        | ident '.' ident '.' ident
4893
6108
          {
4894
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4895
 
              DRIZZLE_YYABORT;
4896
 
 
 
6109
            TableList *table=
 
6110
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
6111
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
 
6112
            {
 
6113
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
6114
              DRIZZLE_YYABORT;
 
6115
            }
 
6116
            if (my_strcasecmp(table_alias_charset, $3.str,
 
6117
                              table->getTableName()))
 
6118
            {
 
6119
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
6120
              DRIZZLE_YYABORT;
 
6121
            }
4897
6122
            $$=$5;
4898
6123
          }
4899
6124
        | ident '.' ident
4900
6125
          {
4901
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
6126
            TableList *table=
 
6127
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
6128
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
6129
            {
 
6130
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6131
              DRIZZLE_YYABORT;
4903
 
 
 
6132
            }
4904
6133
            $$=$3;
4905
6134
          }
4906
 
        | '.' ident 
4907
 
          { /* For Delphi */
4908
 
            $$=$2;
4909
 
          }
 
6135
        | '.' ident { $$=$2;} /* For Delphi */
4910
6136
        ;
4911
6137
 
4912
6138
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
 
6139
          ident { $$=new Table_ident($1); }
 
6140
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
6141
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4933
6142
        ;
4934
6143
 
4935
6144
IDENT_sys:
4936
 
          IDENT 
4937
 
          {
4938
 
            $$= $1;
4939
 
          }
 
6145
          IDENT { $$= $1; }
4940
6146
        | IDENT_QUOTED
4941
6147
          {
4942
6148
            const CHARSET_INFO * const cs= system_charset_info;
4979
6185
          IDENT_sys    { $$=$1; }
4980
6186
        | keyword
4981
6187
          {
4982
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
6188
            Session *session= YYSession;
 
6189
            $$.str= session->strmake($1.str, $1.length);
4983
6190
            $$.length= $1.length;
4984
6191
          }
4985
6192
        ;
4986
6193
 
4987
6194
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          {}
 
6195
          ident           { $$=$1;}
 
6196
        | TEXT_STRING_sys { $$=$1;}
 
6197
        | LEX_HOSTNAME { $$=$1;}
5001
6198
        ;
5002
6199
 
5003
6200
/* Keyword that we allow for identifiers (except SP labels) */
5004
6201
keyword:
5005
6202
          keyword_sp            {}
5006
6203
        | BEGIN_SYM             {}
 
6204
        | BYTE_SYM              {}
5007
6205
        | CHECKSUM_SYM          {}
5008
6206
        | CLOSE_SYM             {}
5009
6207
        | COMMENT_SYM           {}
5010
6208
        | COMMIT_SYM            {}
5011
6209
        | CONTAINS_SYM          {}
5012
6210
        | DEALLOCATE_SYM        {}
5013
 
        | DO_SYM                {}
5014
6211
        | END                   {}
5015
6212
        | FLUSH_SYM             {}
5016
6213
        | NO_SYM                {}
5019
6216
        | SAVEPOINT_SYM         {}
5020
6217
        | SECURITY_SYM          {}
5021
6218
        | SERVER_SYM            {}
5022
 
        | SIGNED_SYM            {}
5023
6219
        | START_SYM             {}
5024
6220
        | STOP_SYM              {}
5025
6221
        | TRUNCATE_SYM          {}
5039
6235
        | ANY_SYM                  {}
5040
6236
        | AT_SYM                   {}
5041
6237
        | AUTO_INC                 {}
 
6238
        | AVG_ROW_LENGTH           {}
5042
6239
        | AVG_SYM                  {}
5043
6240
        | BIT_SYM                  {}
5044
6241
        | BOOL_SYM                 {}
5048
6245
        | CHAIN_SYM                {}
5049
6246
        | COALESCE                 {}
5050
6247
        | COLLATION_SYM            {}
 
6248
        | COLUMN_FORMAT_SYM        {}
5051
6249
        | COLUMNS                  {}
5052
6250
        | COMMITTED_SYM            {}
5053
6251
        | COMPACT_SYM              {}
5054
6252
        | COMPRESSED_SYM           {}
5055
6253
        | CONCURRENT               {}
5056
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
6254
        | CONNECTION_SYM           {}
5057
6255
        | CONSISTENT_SYM           {}
5058
6256
        | CUBE_SYM                 {}
5059
6257
        | DATA_SYM                 {}
5060
6258
        | DATABASES                {}
 
6259
        | DATAFILE_SYM             {}
5061
6260
        | DATETIME_SYM             {}
5062
 
        | DATE_SYM                 {} /* Create conflict */
 
6261
        | DATE_SYM                 {}
5063
6262
        | DAY_SYM                  {}
5064
6263
        | DISABLE_SYM              {}
5065
6264
        | DISCARD                  {}
5090
6289
        | KEY_BLOCK_SIZE           {}
5091
6290
        | LAST_SYM                 {}
5092
6291
        | LEVEL_SYM                {}
 
6292
        | LIST_SYM                 {}
5093
6293
        | LOCAL_SYM                {}
5094
6294
        | LOCKS_SYM                {}
5095
6295
        | LOGS_SYM                 {}
 
6296
        | MAX_ROWS                 {}
 
6297
        | MAX_SIZE_SYM             {}
5096
6298
        | MAX_VALUE_SYM            {}
5097
6299
        | MEDIUM_SYM               {}
5098
6300
        | MERGE_SYM                {}
5099
6301
        | MICROSECOND_SYM          {}
5100
6302
        | MINUTE_SYM               {}
 
6303
        | MIN_ROWS                 {}
5101
6304
        | MODIFY_SYM               {}
5102
6305
        | MODE_SYM                 {}
5103
6306
        | MONTH_SYM                {}
5112
6315
        | ONE_SHOT_SYM             {}
5113
6316
        | ONE_SYM                  {}
5114
6317
        | ONLINE_SYM               {}
 
6318
        | PAGE_SYM                 {}
5115
6319
        | PARTIAL                  {}
 
6320
        | PHASE_SYM                {}
5116
6321
        | PREV_SYM                 {}
5117
6322
        | PROCESS                  {}
5118
6323
        | PROCESSLIST_SYM          {}
5119
6324
        | QUARTER_SYM              {}
5120
 
        | QUERY_SYM                {} // Causes conflict
 
6325
        | QUERY_SYM                {}
 
6326
        | READ_ONLY_SYM            {}
5121
6327
        | REDUNDANT_SYM            {}
5122
6328
        | REPEATABLE_SYM           {}
5123
6329
        | RETURNS_SYM              {}
 
6330
        | REVERSE_SYM              {}
5124
6331
        | ROLLUP_SYM               {}
5125
6332
        | ROUTINE_SYM              {}
5126
6333
        | ROWS_SYM                 {}
5133
6340
        | SIMPLE_SYM               {}
5134
6341
        | SHARE_SYM                {}
5135
6342
        | SNAPSHOT_SYM             {}
 
6343
        | SQL_BUFFER_RESULT        {}
5136
6344
        | STATUS_SYM               {}
 
6345
        | STORAGE_SYM              {}
5137
6346
        | STRING_SYM               {}
5138
6347
        | SUBDATE_SYM              {}
5139
6348
        | SUBJECT_SYM              {}
5140
6349
        | SUSPEND_SYM              {}
 
6350
        | SWAPS_SYM                {}
 
6351
        | SWITCHES_SYM             {}
5141
6352
        | TABLES                   {}
5142
6353
        | TABLESPACE               {}
5143
6354
        | TEMPORARY_SYM            {}
5144
6355
        | TEXT_SYM                 {}
5145
6356
        | TRANSACTION_SYM          {}
5146
6357
        | TIME_SYM                 {}
 
6358
        | TIMESTAMP_SYM            {}
5147
6359
        | TIMESTAMP_ADD            {}
5148
6360
        | TIMESTAMP_DIFF           {}
 
6361
        | TYPES_SYM                {}
5149
6362
        | TYPE_SYM                 {}
5150
6363
        | UNCOMMITTED_SYM          {}
5151
6364
        | UNDOFILE_SYM             {}
5152
6365
        | UNKNOWN_SYM              {}
5153
 
        | UUID_SYM                 {}
5154
6366
        | USER                     {}
5155
6367
        | VARIABLES                {}
5156
6368
        | VALUE_SYM                {}
5165
6377
set:
5166
6378
          SET_SYM opt_option
5167
6379
          {
5168
 
            Lex->statement= new statement::SetOption(YYSession);
 
6380
            LEX *lex=Lex;
 
6381
            lex->sql_command= SQLCOM_SET_OPTION;
 
6382
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
6383
            lex->statement= statement;
 
6384
            if (lex->statement == NULL)
 
6385
              DRIZZLE_YYABORT;
 
6386
            init_select(lex);
 
6387
            lex->option_type=OPT_SESSION;
 
6388
            lex->var_list.empty();
5169
6389
          }
5170
6390
          option_value_list
5171
6391
          {}
5182
6402
        ;
5183
6403
 
5184
6404
option_type_value:
5185
 
          { }
 
6405
          {
 
6406
          }
5186
6407
          ext_option_value
5187
 
          { }
 
6408
          {
 
6409
          }
5188
6410
        ;
5189
6411
 
5190
6412
option_type:
5221
6443
sys_option_value:
5222
6444
          option_type internal_variable_name equal set_expr_or_default
5223
6445
          {
 
6446
            LEX *lex=Lex;
 
6447
 
5224
6448
            if ($2.var)
5225
6449
            { /* System variable */
5226
6450
              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)));
 
6451
                lex->option_type= $1;
 
6452
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6453
                                      &$2.base_name, $4));
5231
6454
            }
5232
6455
          }
5233
6456
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5234
6457
          {
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))));
 
6458
            LEX *lex=Lex;
 
6459
            lex->option_type= $1;
 
6460
            lex->var_list.push_back(new set_var(lex->option_type,
 
6461
                                                find_sys_var("tx_isolation"),
 
6462
                                                &null_lex_str,
 
6463
                                                new Item_int((int32_t) $5)));
5241
6464
          }
5242
6465
        ;
5243
6466
 
5244
6467
option_value:
5245
 
          '@' user_variable_ident equal expr
 
6468
          '@' ident_or_text equal expr
5246
6469
          {
5247
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6470
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5248
6471
          }
5249
6472
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5250
6473
          {
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; }
 
6474
            LEX *lex=Lex;
 
6475
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6476
          }
5268
6477
        ;
5269
6478
 
5270
6479
internal_variable_name:
5271
 
          internal_variable_ident
 
6480
          ident
5272
6481
          {
5273
6482
            /* We have to lookup here since local vars can shadow sysvars */
5274
6483
            {
5275
6484
              /* Not an SP local variable */
5276
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6485
              sys_var *tmp=find_sys_var($1.str, $1.length);
5277
6486
              if (!tmp)
5278
6487
                DRIZZLE_YYABORT;
5279
6488
              $$.var= tmp;
5305
6514
unlock:
5306
6515
          UNLOCK_SYM
5307
6516
          {
5308
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6517
            LEX *lex= Lex;
 
6518
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6519
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6520
            if (lex->statement == NULL)
 
6521
              DRIZZLE_YYABORT;
5309
6522
          }
5310
6523
          table_or_tables
5311
6524
          {}
5314
6527
begin:
5315
6528
          BEGIN_SYM
5316
6529
          {
5317
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6530
            LEX *lex=Lex;
 
6531
            lex->sql_command = SQLCOM_BEGIN;
 
6532
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6533
            if (lex->statement == NULL)
 
6534
              DRIZZLE_YYABORT;
5318
6535
          }
5319
6536
          opt_work {}
5320
6537
        ;
5346
6563
commit:
5347
6564
          COMMIT_SYM opt_work opt_chain opt_release
5348
6565
          {
5349
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6566
            LEX *lex=Lex;
 
6567
            lex->sql_command= SQLCOM_COMMIT;
 
6568
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6569
            lex->statement= statement;
 
6570
            if (lex->statement == NULL)
 
6571
              DRIZZLE_YYABORT;
 
6572
            statement->tx_chain= $3;
 
6573
            statement->tx_release= $4;
5350
6574
          }
5351
6575
        ;
5352
6576
 
5353
6577
rollback:
5354
6578
          ROLLBACK_SYM opt_work opt_chain opt_release
5355
6579
          {
5356
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6580
            LEX *lex=Lex;
 
6581
            lex->sql_command= SQLCOM_ROLLBACK;
 
6582
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6583
            lex->statement= statement;
 
6584
            if (lex->statement == NULL)
 
6585
              DRIZZLE_YYABORT;
 
6586
            statement->tx_chain= $3;
 
6587
            statement->tx_release= $4;
5357
6588
          }
5358
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6589
        | ROLLBACK_SYM opt_work
 
6590
          TO_SYM opt_savepoint ident
5359
6591
          {
5360
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6592
            LEX *lex=Lex;
 
6593
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6594
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6595
            if (lex->statement == NULL)
 
6596
              DRIZZLE_YYABORT;
 
6597
            lex->ident= $5;
5361
6598
          }
5362
6599
        ;
5363
6600
 
5364
6601
savepoint:
5365
 
          SAVEPOINT_SYM savepoint_ident
 
6602
          SAVEPOINT_SYM ident
5366
6603
          {
5367
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6604
            LEX *lex=Lex;
 
6605
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6606
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6607
            if (lex->statement == NULL)
 
6608
              DRIZZLE_YYABORT;
 
6609
            lex->ident= $2;
5368
6610
          }
5369
6611
        ;
5370
6612
 
5371
6613
release:
5372
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6614
          RELEASE_SYM SAVEPOINT_SYM ident
5373
6615
          {
5374
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6616
            LEX *lex=Lex;
 
6617
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6618
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6619
            if (lex->statement == NULL)
 
6620
              DRIZZLE_YYABORT;
 
6621
            lex->ident= $3;
5375
6622
          }
5376
6623
        ;
5377
6624
 
5378
 
savepoint_ident:
5379
 
               IDENT_sys
5380
 
               ;
5381
 
 
5382
6625
/*
5383
6626
   UNIONS : glue selects together
5384
6627
*/
5392
6635
union_list:
5393
6636
          UNION_SYM union_option
5394
6637
          {
5395
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6638
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5396
6639
              DRIZZLE_YYABORT;
5397
6640
          }
5398
6641
          select_init
5413
6656
 
5414
6657
union_order_or_limit:
5415
6658
          {
5416
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5417
 
            Select_Lex *sel= Lex->current_select;
 
6659
            Session *session= YYSession;
 
6660
            LEX *lex= session->lex;
 
6661
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6662
            Select_Lex *sel= lex->current_select;
5418
6663
            Select_Lex_Unit *unit= sel->master_unit();
5419
6664
            Select_Lex *fake= unit->fake_select_lex;
5420
6665
            if (fake)
5421
6666
            {
5422
6667
              unit->global_parameters= fake;
5423
6668
              fake->no_table_names_allowed= 1;
5424
 
              Lex->current_select= fake;
 
6669
              lex->current_select= fake;
5425
6670
            }
5426
 
            YYSession->setWhere("global ORDER clause");
 
6671
            session->where= "global ORDER clause";
5427
6672
          }
5428
6673
          order_or_limit
5429
6674
          {
5430
 
            YYSession->lex->current_select->no_table_names_allowed= 0;
5431
 
            YYSession->setWhere("");
 
6675
            Session *session= YYSession;
 
6676
            session->lex->current_select->no_table_names_allowed= 0;
 
6677
            session->where= "";
5432
6678
          }
5433
6679
        ;
5434
6680
 
5459
6705
        | query_expression_body
5460
6706
          UNION_SYM union_option
5461
6707
          {
5462
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6708
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5463
6709
              DRIZZLE_YYABORT;
5464
6710
          }
5465
6711
          query_specification
5479
6725
 
5480
6726
subselect_start:
5481
6727
          {
5482
 
            if (not Lex->expr_allows_subselect)
 
6728
            LEX *lex=Lex;
 
6729
            if (!lex->expr_allows_subselect)
5483
6730
            {
5484
 
              parser::my_parse_error(YYSession->m_lip);
 
6731
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6732
              my_parse_error(&pass);
5485
6733
              DRIZZLE_YYABORT;
5486
6734
            }
5487
6735
            /*
5498
6746
 
5499
6747
subselect_end:
5500
6748
          {
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;
 
6749
            LEX *lex=Lex;
 
6750
            lex->pop_context();
 
6751
            Select_Lex *child= lex->current_select;
 
6752
            lex->current_select = lex->current_select->return_after_parsing();
 
6753
            lex->nest_level--;
 
6754
            lex->current_select->n_child_sum_items += child->n_sum_items;
5506
6755
            /*
5507
6756
              A subselect can add fields to an outer select. Reserve space for
5508
6757
              them.
5509
6758
            */
5510
 
            Lex->current_select->select_n_where_fields+=
 
6759
            lex->current_select->select_n_where_fields+=
5511
6760
            child->select_n_where_fields;
5512
6761
          }
5513
6762
        ;