~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Monty Taylor
  • Date: 2010-12-26 01:32:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101226013211-c1tx52h7evovmijg
fixed dict and eval.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#define yyoverflow(A,B,C,D,E,F)               \
47
47
  {                                           \
48
 
    unsigned long val= *(F);                          \
 
48
    ulong val= *(F);                          \
49
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
50
50
    {                                         \
51
51
      yyerror((char*) (A));                   \
60
60
#define DRIZZLE_YYABORT                         \
61
61
  do                                          \
62
62
  {                                           \
 
63
    LEX::cleanup_lex_after_parse_error(YYSession);\
63
64
    YYABORT;                                  \
64
65
  } while (0)
65
66
 
66
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
67
68
  if (!(A))                             \
68
69
  {                                     \
69
 
    parser::my_parse_error(YYSession->m_lip);\
 
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    my_parse_error(&pass);\
70
72
    DRIZZLE_YYABORT;                      \
71
73
  }
72
74
 
80
82
class Item;
81
83
class Item_num;
82
84
 
83
 
namespace item
84
 
{
85
 
class Boolean;
86
 
class True;
87
 
class False;
88
 
}
89
 
 
 
85
 
 
86
static bool check_reserved_words(LEX_STRING *name)
 
87
{
 
88
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
 
89
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
 
90
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
 
91
    return true;
 
92
  return false;
 
93
}
 
94
 
 
95
/**
 
96
  @brief Push an error message into MySQL error stack with line
 
97
  and position information.
 
98
 
 
99
  This function provides semantic action implementers with a way
 
100
  to push the famous "You have a syntax error near..." error
 
101
  message into the error stack, which is normally produced only if
 
102
  a parse error is discovered internally by the Bison generated
 
103
  parser.
 
104
*/
 
105
 
 
106
struct my_parse_error_st {
 
107
  const char *s;
 
108
  Session *session;
 
109
};
 
110
 
 
111
static void my_parse_error(void *arg)
 
112
{
 
113
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
 
114
 
 
115
  const char *s= ptr->s;
 
116
  Session *session= ptr->session;
 
117
 
 
118
  Lex_input_stream *lip= session->m_lip;
 
119
 
 
120
  const char *yytext= lip->get_tok_start();
 
121
  /* Push an error into the error stack */
 
122
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
123
                  (yytext ? yytext : ""),
 
124
                  lip->yylineno);
 
125
}
90
126
 
91
127
/**
92
128
  @brief Bison callback to report a syntax/OOM error
103
139
 
104
140
  This function is not for use in semantic actions and is internal to
105
141
  the parser, as it performs some pre-return cleanup.
106
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
142
  In semantic actions, please use my_parse_error or my_error to
107
143
  push an error into the error stack and DRIZZLE_YYABORT
108
144
  to abort from the parser.
109
145
*/
110
146
 
111
147
static void DRIZZLEerror(const char *s)
112
148
{
113
 
  parser::errorOn(s);
 
149
  Session *session= current_session;
 
150
 
 
151
  /*
 
152
    Restore the original LEX if it was replaced when parsing
 
153
    a stored procedure. We must ensure that a parsing error
 
154
    does not leave any side effects in the Session.
 
155
  */
 
156
  LEX::cleanup_lex_after_parse_error(session);
 
157
 
 
158
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
159
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
160
    s= ER(ER_SYNTAX_ERROR);
 
161
 
 
162
  struct my_parse_error_st pass= { s, session };
 
163
  my_parse_error(&pass);
 
164
}
 
165
 
 
166
/**
 
167
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
168
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
169
  This function returns the proper item for the SQL expression
 
170
  <code>left [NOT] IN ( expr )</code>
 
171
  @param session the current thread
 
172
  @param left the in predicand
 
173
  @param equal true for IN predicates, false for NOT IN predicates
 
174
  @param expr first and only expression of the in value list
 
175
  @return an expression representing the IN predicate.
 
176
*/
 
177
static Item* handle_sql2003_note184_exception(Session *session,
 
178
                                              Item* left, bool equal,
 
179
                                              Item *expr)
 
180
{
 
181
  /*
 
182
    Relevant references for this issue:
 
183
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
184
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
185
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
186
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
187
    - SQL:2003 Feature F561, "Full value expressions".
 
188
 
 
189
    The exception in SQL:2003 Note 184 means:
 
190
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
191
    should be re-interpreted as an Item_in_subselect, which corresponds
 
192
    to a <table subquery> when used inside an <in predicate>.
 
193
 
 
194
    Our reading of Note 184 is reccursive, so that all:
 
195
    - IN (( <subquery> ))
 
196
    - IN ((( <subquery> )))
 
197
    - IN '('^N <subquery> ')'^N
 
198
    - etc
 
199
    should be interpreted as a <table subquery>, no matter how deep in the
 
200
    expression the <subquery> is.
 
201
  */
 
202
 
 
203
  Item *result;
 
204
 
 
205
  if (expr->type() == Item::SUBSELECT_ITEM)
 
206
  {
 
207
    Item_subselect *expr2 = (Item_subselect*) expr;
 
208
 
 
209
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
210
    {
 
211
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
212
      Select_Lex *subselect;
 
213
 
 
214
      /*
 
215
        Implement the mandated change, by altering the semantic tree:
 
216
          left IN Item_singlerow_subselect(subselect)
 
217
        is modified to
 
218
          left IN (subselect)
 
219
        which is represented as
 
220
          Item_in_subselect(left, subselect)
 
221
      */
 
222
      subselect= expr3->invalidate_and_restore_select_lex();
 
223
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
224
 
 
225
      if (! equal)
 
226
        result = negate_expression(session, result);
 
227
 
 
228
      return(result);
 
229
    }
 
230
  }
 
231
 
 
232
  if (equal)
 
233
    result= new (session->mem_root) Item_func_eq(left, expr);
 
234
  else
 
235
    result= new (session->mem_root) Item_func_ne(left, expr);
 
236
 
 
237
  return(result);
 
238
}
 
239
 
 
240
/**
 
241
   @brief Creates a new Select_Lex for a UNION branch.
 
242
 
 
243
   Sets up and initializes a Select_Lex structure for a query once the parser
 
244
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
245
   the new Select_Lex becomes the current one..=
 
246
 
 
247
   @lex The parser state.
 
248
 
 
249
   @is_union_distinct True if the union preceding the new select statement
 
250
   uses UNION DISTINCT.
 
251
 
 
252
   @return <code>false</code> if successful, <code>true</code> if an error was
 
253
   reported. In the latter case parsing should stop.
 
254
 */
 
255
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
 
256
{
 
257
  if (lex->result)
 
258
  {
 
259
    /* Only the last SELECT can have  INTO...... */
 
260
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
261
    return true;
 
262
  }
 
263
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
264
  {
 
265
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
266
    my_parse_error(&pass);
 
267
    return true;
 
268
  }
 
269
  /* This counter shouldn't be incremented for UNION parts */
 
270
  lex->nest_level--;
 
271
  if (mysql_new_select(lex, 0))
 
272
    return true;
 
273
  mysql_init_select(lex);
 
274
  lex->current_select->linkage=UNION_TYPE;
 
275
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
276
    lex->current_select->master_unit()->union_distinct=
 
277
      lex->current_select;
 
278
  return false;
 
279
}
 
280
 
 
281
/**
 
282
   @brief Initializes a Select_Lex for a query within parentheses (aka
 
283
   braces).
 
284
 
 
285
   @return false if successful, true if an error was reported. In the latter
 
286
   case parsing should stop.
 
287
 */
 
288
static bool setup_select_in_parentheses(Session *session, LEX *lex)
 
289
{
 
290
  Select_Lex * sel= lex->current_select;
 
291
  if (sel->set_braces(1))
 
292
  {
 
293
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
294
    my_parse_error(&pass);
 
295
    return true;
 
296
  }
 
297
  if (sel->linkage == UNION_TYPE &&
 
298
      !sel->master_unit()->first_select()->braces &&
 
299
      sel->master_unit()->first_select()->linkage ==
 
300
      UNION_TYPE)
 
301
  {
 
302
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
303
    my_parse_error(&pass);
 
304
    return true;
 
305
  }
 
306
  if (sel->linkage == UNION_TYPE &&
 
307
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
308
      sel->master_unit()->fake_select_lex)
 
309
  {
 
310
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
311
    return true;
 
312
  }
 
313
  /* select in braces, can't contain global parameters */
 
314
  if (sel->master_unit()->fake_select_lex)
 
315
    sel->master_unit()->global_parameters=
 
316
      sel->master_unit()->fake_select_lex;
 
317
  return false;
 
318
}
 
319
 
 
320
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
 
321
{
 
322
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
 
323
  Item *item= NULL;
 
324
 
 
325
  if (udf)
 
326
  {
 
327
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
 
328
  } else {
 
329
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
330
  }
 
331
 
 
332
  return item;
114
333
}
115
334
 
116
335
} /* namespace drizzled; */
118
337
using namespace drizzled;
119
338
%}
120
339
%union {
121
 
  bool boolean;
122
340
  int  num;
123
 
  unsigned long ulong_num;
 
341
  ulong ulong_num;
124
342
  uint64_t ulonglong_number;
125
343
  int64_t longlong_number;
126
344
  drizzled::LEX_STRING lex_str;
136
354
  drizzled::Key_part_spec *key_part;
137
355
  const drizzled::plugin::Function *udf;
138
356
  drizzled::TableList *table_list;
139
 
  drizzled::enum_field_types field_val;
140
 
  drizzled::sys_var_with_base variable;
141
 
  drizzled::sql_var_t var_type;
 
357
  struct drizzled::sys_var_with_base variable;
 
358
  enum drizzled::sql_var_t var_type;
142
359
  drizzled::Key::Keytype key_type;
143
 
  drizzled::ha_key_alg key_alg;
144
 
  drizzled::ha_rkey_function ha_rkey_mode;
145
 
  drizzled::enum_tx_isolation tx_isolation;
146
 
  drizzled::Cast_target cast_type;
 
360
  enum drizzled::ha_key_alg key_alg;
 
361
  enum drizzled::column_format_type column_format_type;
 
362
  enum drizzled::ha_rkey_function ha_rkey_mode;
 
363
  enum drizzled::enum_tx_isolation tx_isolation;
 
364
  enum drizzled::Cast_target cast_type;
147
365
  const drizzled::CHARSET_INFO *charset;
148
366
  drizzled::thr_lock_type lock_type;
149
367
  drizzled::interval_type interval, interval_time_st;
150
 
  drizzled::type::timestamp_t date_time_type;
 
368
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
151
369
  drizzled::Select_Lex *select_lex;
152
370
  drizzled::chooser_compare_func_creator boolfunc2creator;
153
 
  drizzled::st_lex *lex;
154
 
  drizzled::index_hint_type index_hint;
155
 
  drizzled::enum_filetype filetype;
156
 
  drizzled::ha_build_method build_method;
 
371
  struct drizzled::st_lex *lex;
 
372
  enum drizzled::index_hint_type index_hint;
 
373
  enum drizzled::enum_filetype filetype;
 
374
  enum drizzled::ha_build_method build_method;
157
375
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
158
376
  drizzled::execute_string_t execute_string;
159
377
}
161
379
%{
162
380
namespace drizzled
163
381
{
164
 
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
 
382
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
165
383
}
166
384
%}
167
385
 
168
 
%debug
169
386
%pure_parser                                    /* We have threads */
170
 
 
171
387
/*
172
 
  Currently there are 70 shift/reduce conflicts.
 
388
  Currently there are 88 shift/reduce conflicts.
173
389
  We should not introduce new conflicts any more.
174
390
*/
175
 
%expect 70
 
391
%expect 95
176
392
 
177
393
/*
178
394
   Comments for TOKENS.
193
409
 
194
410
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
195
411
%token  ACTION                        /* SQL-2003-N */
196
 
%token  ADD_SYM                           /* SQL-2003-R */
 
412
%token  ADD                           /* SQL-2003-R */
197
413
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
198
414
%token  AFTER_SYM                     /* SQL-2003-N */
199
415
%token  AGGREGATE_SYM
200
416
%token  ALL                           /* SQL-2003-R */
201
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
417
%token  ALTER                         /* SQL-2003-R */
202
418
%token  ANALYZE_SYM
203
419
%token  AND_SYM                       /* SQL-2003-R */
204
420
%token  ANY_SYM                       /* SQL-2003-R */
207
423
%token  ASENSITIVE_SYM                /* FUTURE-USE */
208
424
%token  AT_SYM                        /* SQL-2003-R */
209
425
%token  AUTO_INC
 
426
%token  AVG_ROW_LENGTH
210
427
%token  AVG_SYM                       /* SQL-2003-N */
211
428
%token  BEFORE_SYM                    /* SQL-2003-N */
212
429
%token  BEGIN_SYM                     /* SQL-2003-R */
221
438
%token  BOTH                          /* SQL-2003-R */
222
439
%token  BTREE_SYM
223
440
%token  BY                            /* SQL-2003-R */
 
441
%token  BYTE_SYM
224
442
%token  CALL_SYM                      /* SQL-2003-R */
225
443
%token  CASCADE                       /* SQL-2003-N */
226
444
%token  CASCADED                      /* SQL-2003-R */
227
445
%token  CASE_SYM                      /* SQL-2003-R */
228
446
%token  CAST_SYM                      /* SQL-2003-R */
229
 
%token  CATALOG_SYM
230
447
%token  CHAIN_SYM                     /* SQL-2003-N */
231
 
%token  CHANGE_SYM
 
448
%token  CHANGE
232
449
%token  CHAR_SYM                      /* SQL-2003-R */
233
450
%token  CHECKSUM_SYM
234
451
%token  CHECK_SYM                     /* SQL-2003-R */
249
466
%token  CONSISTENT_SYM
250
467
%token  CONSTRAINT                    /* SQL-2003-R */
251
468
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
469
%token  CONTINUE_SYM                  /* SQL-2003-R */
252
470
%token  CONVERT_SYM                   /* SQL-2003-N */
253
471
%token  COUNT_SYM                     /* SQL-2003-N */
254
472
%token  CREATE                        /* SQL-2003-R */
259
477
%token  CURSOR_SYM                    /* SQL-2003-R */
260
478
%token  DATABASE
261
479
%token  DATABASES
 
480
%token  DATAFILE_SYM
262
481
%token  DATA_SYM                      /* SQL-2003-N */
263
482
%token  DATETIME_SYM
264
483
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
282
501
%token  DISCARD
283
502
%token  DISTINCT                      /* SQL-2003-R */
284
503
%token  DIV_SYM
285
 
%token  DO_SYM
286
504
%token  DOUBLE_SYM                    /* SQL-2003-R */
287
505
%token  DROP                          /* SQL-2003-R */
288
506
%token  DUMPFILE
290
508
%token  DYNAMIC_SYM                   /* SQL-2003-R */
291
509
%token  EACH_SYM                      /* SQL-2003-R */
292
510
%token  ELSE                          /* SQL-2003-R */
 
511
%token  ELSEIF_SYM
293
512
%token  ENABLE_SYM
294
513
%token  ENCLOSED
295
514
%token  END                           /* SQL-2003-R */
303
522
%token  ESCAPED
304
523
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
524
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
 
525
%token  EXECUTE_SYM
307
526
%token  EXISTS                        /* SQL-2003-R */
308
527
%token  EXTENDED_SYM
309
528
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
529
%token  FALSE_SYM                     /* SQL-2003-R */
 
530
%token  FETCH_SYM                     /* SQL-2003-R */
 
531
%token  COLUMN_FORMAT_SYM
311
532
%token  FILE_SYM
312
533
%token  FIRST_SYM                     /* SQL-2003-N */
313
534
%token  FIXED_SYM
334
555
%token  HOUR_SYM                      /* SQL-2003-R */
335
556
%token  IDENT
336
557
%token  IDENTIFIED_SYM
337
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
338
558
%token  IDENT_QUOTED
339
559
%token  IF
340
560
%token  IGNORE_SYM
367
587
%token  LIKE                          /* SQL-2003-R */
368
588
%token  LIMIT
369
589
%token  LINES
 
590
%token  LIST_SYM
370
591
%token  LOAD
371
592
%token  LOCAL_SYM                     /* SQL-2003-R */
 
593
%token  LOCATOR_SYM                   /* SQL-2003-N */
372
594
%token  LOCKS_SYM
373
595
%token  LOCK_SYM
374
596
%token  LOGS_SYM
375
597
%token  LONG_NUM
376
598
%token  LONG_SYM
 
599
%token  LOOP_SYM
377
600
%token  LT                            /* OPERATOR */
378
601
%token  MATCH                         /* SQL-2003-R */
 
602
%token  MAX_ROWS
 
603
%token  MAX_SIZE_SYM
379
604
%token  MAX_SYM                       /* SQL-2003-N */
380
605
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
381
606
%token  MEDIUM_SYM
384
609
%token  MINUTE_MICROSECOND_SYM
385
610
%token  MINUTE_SECOND_SYM
386
611
%token  MINUTE_SYM                    /* SQL-2003-R */
 
612
%token  MIN_ROWS
387
613
%token  MIN_SYM                       /* SQL-2003-N */
388
614
%token  MODE_SYM
389
615
%token  MODIFIES_SYM                  /* SQL-2003-R */
420
646
%token  OUTER
421
647
%token  OUTFILE
422
648
%token  OUT_SYM                       /* SQL-2003-R */
 
649
%token  PAGE_SYM
423
650
%token  PARTIAL                       /* SQL-2003-N */
 
651
%token  PHASE_SYM
424
652
%token  POSITION_SYM                  /* SQL-2003-N */
425
653
%token  PRECISION                     /* SQL-2003-R */
426
654
%token  PREV_SYM
431
659
%token  QUERY_SYM
432
660
%token  RANGE_SYM                     /* SQL-2003-R */
433
661
%token  READS_SYM                     /* SQL-2003-R */
 
662
%token  READ_ONLY_SYM
434
663
%token  READ_SYM                      /* SQL-2003-N */
435
664
%token  READ_WRITE_SYM
436
665
%token  REAL                          /* SQL-2003-R */
445
674
%token  RESTRICT
446
675
%token  RETURNS_SYM                   /* SQL-2003-R */
447
676
%token  RETURN_SYM                    /* SQL-2003-R */
 
677
%token  REVERSE_SYM
448
678
%token  REVOKE                        /* SQL-2003-R */
449
679
%token  RIGHT                         /* SQL-2003-R */
450
680
%token  ROLLBACK_SYM                  /* SQL-2003-R */
464
694
%token  SERIAL_SYM
465
695
%token  SESSION_SYM                   /* SQL-2003-N */
466
696
%token  SERVER_SYM
467
 
%token  SET_SYM                           /* SQL-2003-R */
 
697
%token  SERVER_OPTIONS
 
698
%token  SET                           /* SQL-2003-R */
468
699
%token  SET_VAR
469
700
%token  SHARE_SYM
470
701
%token  SHOW
486
717
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
487
718
%token  STD_SYM
488
719
%token  STOP_SYM
 
720
%token  STORAGE_SYM
489
721
%token  STORED_SYM
490
722
%token  STRAIGHT_JOIN
491
723
%token  STRING_SYM
494
726
%token  SUBSTRING                     /* SQL-2003-N */
495
727
%token  SUM_SYM                       /* SQL-2003-N */
496
728
%token  SUSPEND_SYM
 
729
%token  SWAPS_SYM
 
730
%token  SWITCHES_SYM
497
731
%token  SYSDATE
498
732
%token  TABLES
499
733
%token  TABLESPACE
514
748
%token  TRIM                          /* SQL-2003-N */
515
749
%token  TRUE_SYM                      /* SQL-2003-R */
516
750
%token  TRUNCATE_SYM
 
751
%token  TYPES_SYM
517
752
%token  TYPE_SYM                      /* SQL-2003-N */
518
753
%token  ULONGLONG_NUM
519
754
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
572
807
 
573
808
%type <lex_str>
574
809
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
575
 
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
576
 
        ident
577
 
        ident_or_text
578
 
        internal_variable_ident
579
 
        user_variable_ident
580
 
        row_format_or_text
 
810
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
581
811
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
582
 
        schema_name
583
 
        catalog_name
584
812
        opt_component
585
 
        engine_option_value
586
 
        savepoint_ident
587
 
        BIN_NUM TEXT_STRING_filesystem
 
813
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
588
814
        opt_constraint constraint opt_ident
589
815
 
590
816
%type <execute_string>
602
828
%type <string>
603
829
        text_string opt_gconcat_separator
604
830
 
605
 
%type <field_val>
606
 
      field_definition
607
 
      int_type
608
 
      real_type
609
 
 
610
 
%type <boolean>
611
 
        opt_wait
612
 
        opt_concurrent
613
 
        opt_status
614
 
        opt_zerofill
 
831
%type <num>
 
832
        type int_type real_type order_dir field_def
 
833
        if_exists opt_table_options
615
834
        opt_if_not_exists
616
 
        if_exists 
617
 
        opt_temporary 
618
 
        opt_field_number_signed
619
 
 
620
 
%type <num>
621
 
        order_dir
622
 
        field_def
623
 
        opt_table_options
624
 
        all_or_any opt_distinct
 
835
        opt_temporary all_or_any opt_distinct
625
836
        union_option
626
837
        start_transaction_opts opt_chain opt_release
627
838
        union_opt select_derived_init option_type2
 
839
        opt_status
 
840
        opt_concurrent
 
841
        opt_wait
 
842
        opt_zerofill
 
843
        opt_field_number_signed
628
844
        kill_option
629
845
 
630
846
%type <m_fk_option>
647
863
        table_wild simple_expr udf_expr
648
864
        expr_or_default set_expr_or_default
649
865
        signed_literal now_or_signed_literal opt_escape
650
 
        simple_ident_q
 
866
        simple_ident_nospvar simple_ident_q
651
867
        field_or_var limit_option
652
868
        function_call_keyword
653
869
        function_call_nonkeyword
687
903
 
688
904
%type <interval_time_st> interval_time_stamp
689
905
 
 
906
%type <column_format_type> column_format_types
 
907
 
690
908
%type <tx_isolation> isolation_types
691
909
 
692
910
%type <cast_type> cast_type
693
911
 
694
 
%type <symbol>
695
 
        keyword
696
 
        keyword_sp
697
 
        keyword_exception_for_variable
698
 
        row_format
 
912
%type <symbol> keyword keyword_sp
699
913
 
700
914
%type <charset>
701
915
        collation_name
730
944
        flush_options flush_option
731
945
        equal optional_braces
732
946
        normal_join
733
 
        table_to_table_list table_to_table opt_table_list
 
947
        table_to_table_list table_to_table opt_table_list opt_as
734
948
        single_multi
735
949
        union_clause union_list
736
950
        precision subselect_start
784
998
            }
785
999
            else
786
1000
            {
787
 
              session->lex->statement= new statement::EmptyQuery(YYSession);
 
1001
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1002
              session->lex->statement=
 
1003
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
1004
              if (session->lex->statement == NULL)
 
1005
                DRIZZLE_YYABORT;
788
1006
            }
789
1007
          }
790
1008
        | verb_clause END_OF_INPUT {}
828
1046
/* create a table */
829
1047
 
830
1048
create:
831
 
          CREATE CATALOG_SYM catalog_name
832
 
          {
833
 
            Lex->statement= new statement::catalog::Create(YYSession, $3);
834
 
          }
835
 
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
836
 
          {
837
 
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
 
1049
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1050
          {
 
1051
            Session *session= YYSession;
 
1052
            LEX *lex= session->lex;
 
1053
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1054
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1055
            lex->statement= statement;
 
1056
            if (lex->statement == NULL)
 
1057
              DRIZZLE_YYABORT;
 
1058
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1059
                                                   TL_OPTION_UPDATING,
 
1060
                                                   TL_WRITE))
 
1061
              DRIZZLE_YYABORT;
 
1062
            lex->col_list.empty();
 
1063
            statement->change=NULL;
 
1064
            statement->is_if_not_exists= $4;
 
1065
            statement->create_info.db_type= NULL;
 
1066
            statement->create_info.default_table_charset= NULL;
 
1067
            lex->name.str= 0;
838
1068
 
839
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
840
 
                                                     TL_OPTION_UPDATING,
841
 
                                                     TL_WRITE))
842
 
              DRIZZLE_YYABORT;
843
 
            Lex->col_list.empty();
 
1069
            message::Table &proto= statement->create_table_message;
 
1070
           
 
1071
            proto.set_name($5->table.str);
 
1072
            if ($2)
 
1073
              proto.set_type(message::Table::TEMPORARY);
 
1074
            else
 
1075
              proto.set_type(message::Table::STANDARD);
844
1076
          }
845
 
          create_table_definition
 
1077
          create2
846
1078
          {
847
 
            Lex->current_select= &Lex->select_lex;
 
1079
            LEX *lex= YYSession->lex;
 
1080
            lex->current_select= &lex->select_lex;
848
1081
          }
849
1082
        | CREATE build_method
850
1083
          {
851
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1084
            LEX *lex=Lex;
 
1085
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1086
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1087
            lex->statement= statement;
 
1088
            if (lex->statement == NULL)
 
1089
              DRIZZLE_YYABORT;
 
1090
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1091
            statement->alter_info.build_method= $2;
 
1092
            lex->col_list.empty();
 
1093
            statement->change=NULL;
852
1094
          }
853
1095
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
1096
          {
855
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
856
 
                                                            NULL,
857
 
                                                            TL_OPTION_UPDATING))
 
1097
            LEX *lex=Lex;
 
1098
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1099
 
 
1100
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1101
                                                        NULL,
 
1102
                                                        TL_OPTION_UPDATING))
858
1103
              DRIZZLE_YYABORT;
859
 
 
860
 
            parser::buildKey(Lex, $4, $6);
 
1104
            Key *key;
 
1105
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1106
            statement->alter_info.key_list.push_back(key);
 
1107
            lex->col_list.empty();
861
1108
          }
862
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1109
        | CREATE DATABASE opt_if_not_exists ident
863
1110
          {
864
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1111
            LEX *lex=Lex;
 
1112
 
 
1113
            lex->sql_command=SQLCOM_CREATE_DB;
 
1114
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1115
            lex->statement= statement;
 
1116
            if (lex->statement == NULL)
 
1117
              DRIZZLE_YYABORT;
 
1118
            statement->is_if_not_exists= $3;
865
1119
          }
866
1120
          opt_create_database_options
867
1121
          {
869
1123
          }
870
1124
        ;
871
1125
 
872
 
create_table_definition:
873
 
          '(' field_list ')' opt_create_table_options  create_select_as
874
 
          { }
875
 
        | '(' create_select ')'
876
 
           {
877
 
             Lex->current_select->set_braces(1);
878
 
           }
 
1126
create2:
 
1127
          '(' create2a {}
 
1128
        | opt_create_table_options
 
1129
          create3 {}
 
1130
        | LIKE table_ident opt_create_table_options
 
1131
          {
 
1132
            Session *session= YYSession;
 
1133
            LEX *lex= session->lex;
 
1134
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1135
 
 
1136
            statement->is_create_table_like= true;
 
1137
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1138
              DRIZZLE_YYABORT;
 
1139
          }
 
1140
        | '(' LIKE table_ident ')'
 
1141
          {
 
1142
            Session *session= YYSession;
 
1143
            LEX *lex= session->lex;
 
1144
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1145
 
 
1146
            statement->is_create_table_like= true;
 
1147
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1148
              DRIZZLE_YYABORT;
 
1149
          }
 
1150
        ;
 
1151
 
 
1152
create2a:
 
1153
          field_list ')' opt_create_table_options
 
1154
          create3 {}
 
1155
        |  create_select ')'
 
1156
           { Lex->current_select->set_braces(1);}
879
1157
           union_opt {}
880
 
        |  '(' create_like ')' opt_create_table_options
881
 
          { }
882
 
        | create_like opt_create_table_options
883
 
          { }
884
 
        | opt_create_table_options create_select_as 
885
 
          { }
886
1158
        ;
887
1159
 
888
 
create_select_as:
 
1160
create3:
889
1161
          /* empty */ {}
890
 
        | opt_duplicate_as create_select
891
 
          {
892
 
            Lex->current_select->set_braces(0);
893
 
          }
 
1162
        | opt_duplicate opt_as create_select
 
1163
          { Lex->current_select->set_braces(0);}
894
1164
          union_clause {}
895
 
        | opt_duplicate_as '(' create_select ')'
896
 
          {
897
 
            Lex->current_select->set_braces(1);
898
 
          }
 
1165
        | opt_duplicate opt_as '(' create_select ')'
 
1166
          { Lex->current_select->set_braces(1);}
899
1167
          union_opt {}
900
1168
        ;
901
1169
 
902
 
create_like:
903
 
          LIKE table_ident
904
 
          {
905
 
            ((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
906
 
 
907
 
            if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
908
 
              DRIZZLE_YYABORT;
909
 
          }
910
 
        ;
911
 
 
912
1170
create_select:
913
 
          stored_select
914
 
          {
915
 
          }
916
 
        ;
917
 
 
918
 
/*
919
 
  This rule is used for both CREATE TABLE .. SELECT,  AND INSERT ... SELECT
920
 
*/
921
 
stored_select:
922
1171
          SELECT_SYM
923
1172
          {
924
 
            Lex->lock_option= TL_READ;
925
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1173
            LEX *lex=Lex;
 
1174
            lex->lock_option= TL_READ;
 
1175
            if (lex->sql_command == SQLCOM_INSERT)
926
1176
            {
927
 
              delete Lex->statement;
928
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1177
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1178
              delete lex->statement;
 
1179
              lex->statement=
 
1180
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1181
              if (lex->statement == NULL)
 
1182
                DRIZZLE_YYABORT;
929
1183
            }
930
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1184
            else if (lex->sql_command == SQLCOM_REPLACE)
931
1185
            {
932
 
              delete Lex->statement;
933
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1186
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1187
              delete lex->statement;
 
1188
              lex->statement=
 
1189
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1190
              if (lex->statement == NULL)
 
1191
                DRIZZLE_YYABORT;
934
1192
            }
935
1193
            /*
936
1194
              The following work only with the local list, the global list
937
1195
              is created correctly in this case
938
1196
            */
939
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
 
            init_select(Lex);
941
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1197
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1198
            mysql_init_select(lex);
 
1199
            lex->current_select->parsing_place= SELECT_LIST;
942
1200
          }
943
1201
          select_options select_item_list
944
1202
          {
954
1212
          }
955
1213
        ;
956
1214
 
 
1215
opt_as:
 
1216
          /* empty */ {}
 
1217
        | AS {}
 
1218
        ;
 
1219
 
957
1220
opt_create_database_options:
958
1221
          /* empty */ {}
959
1222
        | default_collation_schema {}
967
1230
 
968
1231
custom_database_option:
969
1232
          ident_or_text
970
 
          {
971
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
972
 
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
973
 
          }
 
1233
        {
 
1234
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1235
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1236
 
 
1237
          opt->set_name($1.str);
 
1238
        }
974
1239
        | ident_or_text equal ident_or_text
975
 
          {
976
 
            parser::buildSchemaOption(Lex, $1.str, $3);
977
 
          }
 
1240
        {
 
1241
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1242
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1243
 
 
1244
          opt->set_name($1.str);
 
1245
          opt->set_state($3.str);
 
1246
        }
978
1247
        | ident_or_text equal ulonglong_num
979
 
          {
980
 
            parser::buildSchemaOption(Lex, $1.str, $3);
981
 
          }
 
1248
        {
 
1249
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1250
          char number_as_string[22];
 
1251
 
 
1252
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1253
 
 
1254
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1255
 
 
1256
          opt->set_name($1.str);
 
1257
          opt->set_state(number_as_string);
 
1258
        }
982
1259
        ;
983
1260
 
984
1261
opt_table_options:
988
1265
 
989
1266
opt_if_not_exists:
990
1267
          /* empty */ { $$= false; }
991
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1268
        | IF not EXISTS { $$= true; }
992
1269
        ;
993
1270
 
994
1271
opt_create_table_options:
1012
1289
custom_engine_option:
1013
1290
        ENGINE_SYM equal ident_or_text
1014
1291
          {
1015
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1292
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1293
 
 
1294
            statement->is_engine_set= true;
 
1295
 
 
1296
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1016
1297
          }
1017
1298
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1018
1299
          {
1019
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1300
            message::Table::TableOptions *tableopts;
 
1301
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1302
 
 
1303
            tableopts->set_comment($3.str);
1020
1304
          }
1021
1305
        | AUTO_INC opt_equal ulonglong_num
1022
1306
          {
1023
 
            Lex->table()->mutable_options()->set_auto_increment_value($3);
1024
 
          }
1025
 
        |  ROW_FORMAT_SYM equal row_format_or_text
1026
 
          {
1027
 
            parser::buildEngineOption(Lex, "ROW_FORMAT", $3);
1028
 
          }
1029
 
        |  FILE_SYM equal TEXT_STRING_sys
1030
 
          {
1031
 
            parser::buildEngineOption(Lex, "FILE", $3);
1032
 
          }
1033
 
        |  ident_or_text equal engine_option_value
1034
 
          {
1035
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1307
            message::Table::TableOptions *tableopts;
 
1308
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1309
 
 
1310
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1311
 
 
1312
            statement->create_info.auto_increment_value=$3;
 
1313
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1314
            tableopts->set_auto_increment_value($3);
 
1315
          }
 
1316
        |  ident_or_text equal ident_or_text
 
1317
          {
 
1318
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1319
 
 
1320
            opt->set_name($1.str);
 
1321
            opt->set_state($3.str);
1036
1322
          }
1037
1323
        | ident_or_text equal ulonglong_num
1038
1324
          {
1039
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1325
            char number_as_string[22];
 
1326
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1327
 
 
1328
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1329
            opt->set_name($1.str);
 
1330
            opt->set_state(number_as_string);
1040
1331
          }
1041
1332
        | default_collation
1042
1333
        ;
1044
1335
default_collation:
1045
1336
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1046
1337
          {
1047
 
            if (not parser::buildCollation(Lex, $4))
1048
 
            {
1049
 
              DRIZZLE_YYABORT;
1050
 
            }
 
1338
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1339
 
 
1340
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1341
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1342
                 cinfo->default_table_charset && $4 &&
 
1343
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1344
              {
 
1345
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1346
                         $4->name, cinfo->default_table_charset->csname);
 
1347
                DRIZZLE_YYABORT;
 
1348
              }
 
1349
              statement->create_info.default_table_charset= $4;
 
1350
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1051
1351
          }
1052
1352
        ;
1053
1353
 
1054
1354
default_collation_schema:
1055
1355
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1056
1356
          {
1057
 
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
1058
 
          }
1059
 
        ;
1060
 
 
1061
 
row_format:
1062
 
          COMPACT_SYM  {}
1063
 
        | COMPRESSED_SYM  {}
1064
 
        | DEFAULT  {}
1065
 
        | DYNAMIC_SYM  {}
1066
 
        | FIXED_SYM  {}
1067
 
        | REDUNDANT_SYM  {}
1068
 
        ;
1069
 
 
1070
 
row_format_or_text:
1071
 
          row_format
1072
 
          {
1073
 
            $$.str= YYSession->strmake($1.str, $1.length);
1074
 
            $$.length= $1.length;
1075
 
          }
1076
 
        ;
 
1357
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1358
 
 
1359
            message::Schema &schema_message= statement->schema_message;
 
1360
            schema_message.set_collation($4->name);
 
1361
          }
 
1362
        ;
 
1363
 
 
1364
column_format_types:
 
1365
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1366
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1367
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1368
 
1077
1369
 
1078
1370
opt_select_from:
1079
1371
          opt_limit_clause {}
1101
1393
key_def:
1102
1394
          key_type opt_ident key_alg '(' key_list ')' key_options
1103
1395
          {
1104
 
            parser::buildKey(Lex, $1, $2);
 
1396
            LEX *lex=Lex;
 
1397
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1398
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1399
                              lex->col_list);
 
1400
            statement->alter_info.key_list.push_back(key);
 
1401
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1105
1402
          }
1106
1403
        | opt_constraint constraint_key_type opt_ident key_alg
1107
1404
          '(' key_list ')' key_options
1108
1405
          {
1109
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1406
            LEX *lex=Lex;
 
1407
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1408
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1409
                              lex->col_list);
 
1410
            statement->alter_info.key_list.push_back(key);
 
1411
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1110
1412
          }
1111
1413
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1112
1414
          {
1113
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1415
            LEX *lex=Lex;
 
1416
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1417
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
 
1418
                                      $8,
 
1419
                                      lex->ref_list,
 
1420
                                      statement->fk_delete_opt,
 
1421
                                      statement->fk_update_opt,
 
1422
                                      statement->fk_match_option);
 
1423
 
 
1424
            statement->alter_info.key_list.push_back(key);
 
1425
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1426
                         &default_key_create_info, 1,
 
1427
                         lex->col_list);
 
1428
            statement->alter_info.key_list.push_back(key);
 
1429
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1430
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1431
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1114
1432
          }
1115
1433
        | constraint opt_check_constraint
1116
1434
          {
1143
1461
field_spec:
1144
1462
          field_ident
1145
1463
          {
1146
 
            parser::buildCreateFieldIdent(Lex);
 
1464
            LEX *lex=Lex;
 
1465
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1466
            lex->length=lex->dec=0;
 
1467
            lex->type=0;
 
1468
            statement->default_value= statement->on_update_value= 0;
 
1469
            statement->comment= null_lex_str;
 
1470
            lex->charset=NULL;
 
1471
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1472
 
 
1473
            message::AlterTable &alter_proto=
 
1474
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1475
            statement->current_proto_field= alter_proto.add_added_field();
1147
1476
          }
1148
1477
          field_def
1149
1478
          {
 
1479
            LEX *lex=Lex;
1150
1480
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1151
1481
 
1152
 
            if (Lex->field())
1153
 
            {
1154
 
              Lex->field()->set_name($1.str);
1155
 
            }
 
1482
            if (statement->current_proto_field)
 
1483
              statement->current_proto_field->set_name($1.str);
1156
1484
 
1157
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
 
                                  Lex->length, Lex->dec, Lex->type,
 
1485
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1486
                                  lex->length,lex->dec,lex->type,
1159
1487
                                  statement->column_format,
1160
1488
                                  statement->default_value, statement->on_update_value,
1161
1489
                                  &statement->comment,
1162
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1490
                                  statement->change, &lex->interval_list, lex->charset))
1163
1491
              DRIZZLE_YYABORT;
1164
1492
 
1165
 
            Lex->setField(NULL);
 
1493
            statement->current_proto_field= NULL;
1166
1494
          }
1167
1495
        ;
1168
 
 
1169
1496
field_def:
1170
 
          field_definition opt_attribute {}
 
1497
          type opt_attribute {}
1171
1498
        ;
1172
1499
 
1173
 
field_definition:
 
1500
type:
1174
1501
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1175
1502
          { 
1176
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
 
1503
            $$= $1;
 
1504
            Lex->length=(char*) 0; /* use default length */
 
1505
            statement::CreateTable *statement=
 
1506
              (statement::CreateTable *)Lex->statement;
 
1507
 
 
1508
            if ($3 or $4)
 
1509
            {
 
1510
              $1= DRIZZLE_TYPE_LONGLONG;
 
1511
            }
 
1512
 
 
1513
            if (statement->current_proto_field)
 
1514
            {
 
1515
              assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
 
1516
              // We update the type for unsigned types
 
1517
              if ($3 or $4)
 
1518
              {
 
1519
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1520
                statement->current_proto_field->mutable_constraints()->set_is_unsigned(true);
 
1521
              }
 
1522
              if ($1 == DRIZZLE_TYPE_LONG)
 
1523
              {
 
1524
                statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1525
              }
 
1526
              else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1527
              {
 
1528
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1529
              }
 
1530
            }
1177
1531
          }
1178
1532
        | real_type opt_precision
1179
1533
          {
1180
 
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
1181
 
            $$= parser::buildDoubleColumn(Lex);
1182
 
          }
1183
 
        | char '(' NUM ')'
1184
 
          {
1185
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1186
 
          }
1187
 
        | char
1188
 
          {
1189
 
            $$= parser::buildVarcharColumn(Lex, "1");
1190
 
          }
1191
 
        | varchar '(' NUM ')'
1192
 
          {
1193
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1194
 
          }
1195
 
        | VARBINARY '(' NUM ')'
1196
 
          {
1197
 
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
1198
 
          }
1199
 
        | DATE_SYM
 
1534
            $$=$1;
 
1535
 
 
1536
            statement::CreateTable *statement=
 
1537
              (statement::CreateTable *)Lex->statement;
 
1538
 
 
1539
            if (statement->current_proto_field)
 
1540
            {
 
1541
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1542
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1543
            }
 
1544
          }
 
1545
          | char '(' NUM ')'
 
1546
            {
 
1547
              Lex->length=$3.str;
 
1548
              $$=DRIZZLE_TYPE_VARCHAR;
 
1549
 
 
1550
            statement::CreateTable *statement=
 
1551
              (statement::CreateTable *)Lex->statement;
 
1552
 
 
1553
            if (statement->current_proto_field)
 
1554
            {
 
1555
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1556
              message::Table::Field::StringFieldOptions *string_field_options;
 
1557
 
 
1558
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1559
 
 
1560
              string_field_options->set_length(atoi($3.str));
 
1561
            }
 
1562
            }
 
1563
          | char
 
1564
            {
 
1565
              Lex->length=(char*) "1";
 
1566
              $$=DRIZZLE_TYPE_VARCHAR;
 
1567
 
 
1568
            statement::CreateTable *statement=
 
1569
              (statement::CreateTable *)Lex->statement;
 
1570
 
 
1571
            if (statement->current_proto_field)
 
1572
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1573
            }
 
1574
          | varchar '(' NUM ')'
 
1575
            {
 
1576
              Lex->length=$3.str;
 
1577
              $$= DRIZZLE_TYPE_VARCHAR;
 
1578
 
 
1579
            statement::CreateTable *statement=
 
1580
              (statement::CreateTable *)Lex->statement;
 
1581
 
 
1582
            if (statement->current_proto_field)
 
1583
            {
 
1584
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1585
 
 
1586
              message::Table::Field::StringFieldOptions *string_field_options;
 
1587
 
 
1588
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1589
 
 
1590
              string_field_options->set_length(atoi($3.str));
 
1591
            }
 
1592
            }
 
1593
          | VARBINARY '(' NUM ')'
 
1594
            {
 
1595
              Lex->length=$3.str;
 
1596
              Lex->charset=&my_charset_bin;
 
1597
              $$= DRIZZLE_TYPE_VARCHAR;
 
1598
 
 
1599
            statement::CreateTable *statement=
 
1600
              (statement::CreateTable *)Lex->statement;
 
1601
 
 
1602
            if (statement->current_proto_field)
 
1603
            {
 
1604
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1605
              message::Table::Field::StringFieldOptions *string_field_options;
 
1606
 
 
1607
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1608
 
 
1609
              string_field_options->set_length(atoi($3.str));
 
1610
              string_field_options->set_collation_id(my_charset_bin.number);
 
1611
              string_field_options->set_collation(my_charset_bin.name);
 
1612
            }
 
1613
            }
 
1614
          | DATE_SYM
1200
1615
          {
1201
1616
            $$=DRIZZLE_TYPE_DATE;
1202
1617
 
1203
 
            if (Lex->field())
1204
 
              Lex->field()->set_type(message::Table::Field::DATE);
 
1618
            statement::CreateTable *statement=
 
1619
              (statement::CreateTable *)Lex->statement;
 
1620
 
 
1621
            if (statement->current_proto_field)
 
1622
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1205
1623
          }
1206
 
        | TIME_SYM
 
1624
          | TIME_SYM
1207
1625
          {
1208
1626
            $$=DRIZZLE_TYPE_TIME;
1209
1627
 
1210
 
            if (Lex->field())
1211
 
              Lex->field()->set_type(message::Table::Field::TIME);
1212
 
          }
1213
 
        | TIMESTAMP_SYM
1214
 
          {
1215
 
            $$=parser::buildTimestampColumn(Lex, NULL);
1216
 
          }
1217
 
        | TIMESTAMP_SYM '(' NUM ')'
1218
 
          {
1219
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1220
 
          }
1221
 
        | DATETIME_SYM
 
1628
            statement::CreateTable *statement=
 
1629
              (statement::CreateTable *)Lex->statement;
 
1630
 
 
1631
            if (statement->current_proto_field)
 
1632
              statement->current_proto_field->set_type(message::Table::Field::TIME);
 
1633
          }
 
1634
          | TIMESTAMP_SYM
 
1635
          {
 
1636
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1637
 
 
1638
            statement::CreateTable *statement=
 
1639
              (statement::CreateTable *)Lex->statement;
 
1640
 
 
1641
            if (statement->current_proto_field)
 
1642
              statement->current_proto_field->set_type(message::Table::Field::EPOCH);
 
1643
          }
 
1644
          | DATETIME_SYM
1222
1645
          {
1223
1646
            $$=DRIZZLE_TYPE_DATETIME;
1224
1647
 
1225
 
            if (Lex->field())
1226
 
              Lex->field()->set_type(message::Table::Field::DATETIME);
1227
 
          }
1228
 
        | BLOB_SYM
1229
 
          {
1230
 
            $$= parser::buildBlobColumn(Lex);
1231
 
          }
1232
 
        | TEXT_SYM
1233
 
          {
1234
 
            $$=DRIZZLE_TYPE_BLOB;
1235
 
            Lex->length=(char*) 0; /* use default length */
1236
 
 
1237
 
          if (Lex->field())
1238
 
            Lex->field()->set_type(message::Table::Field::BLOB);
1239
 
          }
1240
 
        | DECIMAL_SYM float_options
1241
 
          {
1242
 
            $$= parser::buildDecimalColumn(Lex);
1243
 
          }
1244
 
        | NUMERIC_SYM float_options
1245
 
          {
1246
 
            $$= parser::buildDecimalColumn(Lex);
1247
 
          }
1248
 
        | FIXED_SYM float_options
1249
 
          {
1250
 
            $$= parser::buildDecimalColumn(Lex);
1251
 
          }
1252
 
        | ENUM_SYM
1253
 
          {
1254
 
            Lex->interval_list.empty();
1255
 
          }
1256
 
          '(' string_list ')'
 
1648
            statement::CreateTable *statement=
 
1649
              (statement::CreateTable *)Lex->statement;
 
1650
 
 
1651
            if (statement->current_proto_field)
 
1652
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1653
          }
 
1654
          | BLOB_SYM
 
1655
            {
 
1656
              Lex->charset=&my_charset_bin;
 
1657
              $$=DRIZZLE_TYPE_BLOB;
 
1658
              Lex->length=(char*) 0; /* use default length */
 
1659
 
 
1660
              statement::CreateTable *statement=
 
1661
                (statement::CreateTable *)Lex->statement;
 
1662
 
 
1663
              if (statement->current_proto_field)
 
1664
              {
 
1665
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1666
                message::Table::Field::StringFieldOptions *string_field_options;
 
1667
 
 
1668
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1669
                string_field_options->set_collation_id(my_charset_bin.number);
 
1670
                string_field_options->set_collation(my_charset_bin.name);
 
1671
              }
 
1672
            }
 
1673
          | TEXT_SYM
 
1674
            {
 
1675
              $$=DRIZZLE_TYPE_BLOB;
 
1676
              Lex->length=(char*) 0; /* use default length */
 
1677
 
 
1678
            statement::CreateTable *statement=
 
1679
              (statement::CreateTable *)Lex->statement;
 
1680
 
 
1681
            if (statement->current_proto_field)
 
1682
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1683
            }
 
1684
          | DECIMAL_SYM float_options
 
1685
          {
 
1686
            $$=DRIZZLE_TYPE_DECIMAL;
 
1687
 
 
1688
            statement::CreateTable *statement=
 
1689
              (statement::CreateTable *)Lex->statement;
 
1690
 
 
1691
            if (statement->current_proto_field)
 
1692
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1693
          }
 
1694
          | NUMERIC_SYM float_options
 
1695
          {
 
1696
            $$=DRIZZLE_TYPE_DECIMAL;
 
1697
 
 
1698
            statement::CreateTable *statement=
 
1699
              (statement::CreateTable *)Lex->statement;
 
1700
 
 
1701
            if (statement->current_proto_field)
 
1702
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1703
          }
 
1704
          | FIXED_SYM float_options
 
1705
          {
 
1706
            $$=DRIZZLE_TYPE_DECIMAL;
 
1707
 
 
1708
            statement::CreateTable *statement=
 
1709
              (statement::CreateTable *)Lex->statement;
 
1710
 
 
1711
            if (statement->current_proto_field)
 
1712
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1713
          }
 
1714
          | ENUM_SYM
 
1715
            {Lex->interval_list.empty();}
 
1716
            '(' string_list ')'
1257
1717
          {
1258
1718
            $$=DRIZZLE_TYPE_ENUM;
1259
1719
 
1260
 
            if (Lex->field())
1261
 
              Lex->field()->set_type(message::Table::Field::ENUM);
1262
 
          }
1263
 
        | UUID_SYM
1264
 
          {
1265
 
            $$= parser::buildUuidColumn(Lex);
1266
 
          }
1267
 
        | BOOLEAN_SYM
1268
 
          {
1269
 
            $$= parser::buildBooleanColumn(Lex);
 
1720
            statement::CreateTable *statement=
 
1721
              (statement::CreateTable *)Lex->statement;
 
1722
 
 
1723
            if (statement->current_proto_field)
 
1724
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
 
1725
          }
 
1726
          | UUID_SYM
 
1727
          {
 
1728
            $$=DRIZZLE_TYPE_UUID;
 
1729
 
 
1730
            statement::CreateTable *statement=
 
1731
              (statement::CreateTable *)Lex->statement;
 
1732
 
 
1733
            if (statement->current_proto_field)
 
1734
              statement->current_proto_field->set_type(message::Table::Field::UUID);
1270
1735
          }
1271
1736
        | SERIAL_SYM
1272
1737
          {
1273
 
            $$= parser::buildSerialColumn(Lex);
 
1738
            $$=DRIZZLE_TYPE_LONGLONG;
 
1739
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1740
 
 
1741
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1742
            if (statement->current_proto_field)
 
1743
            {
 
1744
              message::Table::Field::FieldConstraints *constraints;
 
1745
              constraints= statement->current_proto_field->mutable_constraints();
 
1746
              constraints->set_is_nullable(false);
 
1747
 
 
1748
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1749
            }
1274
1750
          }
1275
1751
        ;
1276
1752
 
1284
1760
        ;
1285
1761
 
1286
1762
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
 
          }
 
1763
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1764
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1299
1765
        ;
1300
1766
 
1301
1767
real_type:
1304
1770
            $$= DRIZZLE_TYPE_DOUBLE;
1305
1771
          }
1306
1772
        | DOUBLE_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_DOUBLE;
1309
 
          }
 
1773
          { $$=DRIZZLE_TYPE_DOUBLE; }
1310
1774
        | DOUBLE_SYM PRECISION
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_DOUBLE;
1313
 
          }
 
1775
          { $$=DRIZZLE_TYPE_DOUBLE; }
1314
1776
        ;
1315
1777
 
1316
1778
float_options:
1325
1787
precision:
1326
1788
          '(' NUM ',' NUM ')'
1327
1789
          {
1328
 
            Lex->length= $2.str;
1329
 
            Lex->dec= $4.str;
 
1790
            LEX *lex=Lex;
 
1791
            lex->length=$2.str;
 
1792
            lex->dec=$4.str;
1330
1793
          }
1331
1794
        ;
1332
1795
 
1336
1799
        ;
1337
1800
 
1338
1801
opt_field_number_signed:
1339
 
          /* empty */ { $$= false; }
1340
 
        | SIGNED_SYM { $$= false; }
1341
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1802
          /* empty */ { $$= 0; }
 
1803
        | SIGNED_SYM { $$= 0; }
 
1804
        | UNSIGNED_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
1342
1805
        ;
1343
1806
 
1344
1807
ignored_field_number_length:
1347
1810
        ;
1348
1811
 
1349
1812
opt_zerofill:
1350
 
          /* empty */ { $$= false; }
1351
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1813
          /* empty */ { $$= 0; }
 
1814
        | ZEROFILL_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
1352
1815
        ;
1353
1816
 
1354
1817
opt_precision:
1355
 
          /* empty */
1356
 
          { Lex->dec=Lex->length= (char*)0; }
1357
 
        | '(' NUM ')'
1358
 
          { Lex->length=Lex->dec= (char*)0; }
1359
 
        | precision
1360
 
          {}
 
1818
          /* empty */ {}
 
1819
        | precision {}
1361
1820
        ;
1362
1821
 
1363
1822
opt_attribute:
1373
1832
attribute:
1374
1833
          NULL_SYM
1375
1834
          {
 
1835
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1376
1836
            Lex->type&= ~ NOT_NULL_FLAG;
 
1837
 
 
1838
            if (statement->current_proto_field)
 
1839
            {
 
1840
              message::Table::Field::FieldConstraints *constraints;
 
1841
              constraints= statement->current_proto_field->mutable_constraints();
 
1842
              constraints->set_is_nullable(true);
 
1843
            }
 
1844
          }
 
1845
        | COLUMN_FORMAT_SYM column_format_types
 
1846
          {
 
1847
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1848
 
 
1849
            statement->column_format= $2;
 
1850
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1377
1851
          }
1378
1852
        | not NULL_SYM
1379
1853
          {
 
1854
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1380
1855
            Lex->type|= NOT_NULL_FLAG;
1381
1856
 
1382
 
            if (Lex->field())
 
1857
            if (statement->current_proto_field)
1383
1858
            {
1384
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1859
              message::Table::Field::FieldConstraints *constraints;
 
1860
              constraints= statement->current_proto_field->mutable_constraints();
 
1861
              constraints->set_is_nullable(false);
1385
1862
            }
1386
1863
          }
1387
1864
        | DEFAULT now_or_signed_literal
1392
1869
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1393
1870
          }
1394
1871
        | ON UPDATE_SYM NOW_SYM optional_braces
1395
 
          {
1396
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1397
 
          }
 
1872
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1398
1873
        | AUTO_INC
1399
1874
          {
1400
 
            parser::buildAutoOnColumn(Lex);
 
1875
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1876
 
 
1877
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1878
            if (statement->current_proto_field)
 
1879
            {
 
1880
              message::Table::Field::FieldConstraints *constraints;
 
1881
 
 
1882
              constraints= statement->current_proto_field->mutable_constraints();
 
1883
              constraints->set_is_nullable(false);
 
1884
            }
1401
1885
          }
1402
1886
        | SERIAL_SYM DEFAULT VALUE_SYM
1403
1887
          {
1404
 
            (void)parser::buildSerialColumn(Lex);
 
1888
            LEX *lex=Lex;
 
1889
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1890
 
 
1891
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1892
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1893
 
 
1894
            if (statement->current_proto_field)
 
1895
            {
 
1896
              message::Table::Field::FieldConstraints *constraints;
 
1897
              constraints= statement->current_proto_field->mutable_constraints();
 
1898
              constraints->set_is_nullable(false);
 
1899
            }
1405
1900
          }
1406
1901
        | opt_primary KEY_SYM
1407
1902
          {
1408
 
            parser::buildPrimaryOnColumn(Lex);
 
1903
            LEX *lex=Lex;
 
1904
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1905
 
 
1906
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1907
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1908
 
 
1909
            if (statement->current_proto_field)
 
1910
            {
 
1911
              message::Table::Field::FieldConstraints *constraints;
 
1912
              constraints= statement->current_proto_field->mutable_constraints();
 
1913
              constraints->set_is_nullable(false);
 
1914
            }
1409
1915
          }
1410
1916
        | UNIQUE_SYM
1411
1917
          {
1412
 
            parser::buildKeyOnColumn(Lex);
 
1918
            LEX *lex=Lex;
 
1919
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1920
 
 
1921
            lex->type|= UNIQUE_FLAG;
 
1922
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1413
1923
          }
1414
1924
        | UNIQUE_SYM KEY_SYM
1415
1925
          {
1416
 
            parser::buildKeyOnColumn(Lex);
 
1926
            LEX *lex=Lex;
 
1927
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1928
 
 
1929
            lex->type|= UNIQUE_KEY_FLAG;
 
1930
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1417
1931
          }
1418
1932
        | COMMENT_SYM TEXT_STRING_sys
1419
1933
          {
1420
1934
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1421
1935
            statement->comment= $2;
1422
1936
 
1423
 
            if (Lex->field())
1424
 
              Lex->field()->set_comment($2.str);
 
1937
            if (statement->current_proto_field)
 
1938
              statement->current_proto_field->set_comment($2.str);
1425
1939
          }
1426
1940
        | COLLATE_SYM collation_name
1427
1941
          {
1493
2007
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1494
2008
        | ident
1495
2009
          {
1496
 
            Lex->ref_list.empty();
1497
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
2010
            LEX *lex= Lex;
 
2011
            lex->ref_list.empty();
 
2012
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1498
2013
          }
1499
2014
        ;
1500
2015
 
1542
2057
delete_option:
1543
2058
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1544
2059
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1545
 
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
 
2060
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1546
2061
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1547
 
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
 
2062
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
1548
2063
        ;
1549
2064
 
1550
2065
key_type:
1584
2099
        ;
1585
2100
 
1586
2101
/*
1587
 
  For now, key_alg initializies Lex->key_create_info.
 
2102
  For now, key_alg initializies lex->key_create_info.
1588
2103
  In the future, when all key options are after key definition,
1589
2104
  we can remove key_alg and move init_key_options to key_options
1590
2105
*/
1606
2121
 
1607
2122
key_using_alg:
1608
2123
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2124
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1609
2125
        ;
1610
2126
 
1611
2127
key_opt:
1658
2174
*/
1659
2175
 
1660
2176
alter:
1661
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2177
          ALTER build_method opt_ignore TABLE_SYM table_ident
1662
2178
          {
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());
 
2179
            Session *session= YYSession;
 
2180
            LEX *lex= session->lex;
 
2181
            lex->name.str= 0;
 
2182
            lex->name.length= 0;
 
2183
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2184
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2185
            lex->statement= statement;
 
2186
            if (lex->statement == NULL)
 
2187
              DRIZZLE_YYABORT;
 
2188
            lex->duplicates= DUP_ERROR;
 
2189
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2190
                                                   TL_OPTION_UPDATING))
 
2191
              DRIZZLE_YYABORT;
 
2192
            lex->col_list.empty();
 
2193
            lex->select_lex.init_order();
 
2194
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
 
2195
            statement->alter_info.build_method= $2;
1674
2196
          }
1675
2197
          alter_commands
1676
2198
          {}
1677
 
        | ALTER_SYM DATABASE schema_name
 
2199
        | ALTER DATABASE ident_or_empty
1678
2200
          {
1679
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2201
            LEX *lex=Lex;
 
2202
            lex->sql_command=SQLCOM_ALTER_DB;
 
2203
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2204
            if (lex->statement == NULL)
 
2205
              DRIZZLE_YYABORT;
1680
2206
          }
1681
2207
          default_collation_schema
1682
2208
          {
1683
 
            Lex->name= $3;
1684
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2209
            LEX *lex=Lex;
 
2210
            lex->name= $3;
 
2211
            if (lex->name.str == NULL &&
 
2212
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1685
2213
              DRIZZLE_YYABORT;
1686
2214
          }
1687
2215
        ;
1688
2216
 
 
2217
ident_or_empty:
 
2218
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2219
        | ident { $$= $1; }
 
2220
        ;
 
2221
 
1689
2222
alter_commands:
1690
2223
          /* empty */
1691
2224
        | DISCARD TABLESPACE
1722
2255
        ;
1723
2256
 
1724
2257
add_column:
1725
 
          ADD_SYM opt_column
 
2258
          ADD opt_column
1726
2259
          {
1727
2260
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1728
2261
 
1733
2266
 
1734
2267
alter_list_item:
1735
2268
          add_column column_def opt_place { }
1736
 
        | ADD_SYM key_def
 
2269
        | ADD key_def
1737
2270
          {
1738
2271
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
2272
 
1746
2279
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1747
2280
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1748
2281
          }
1749
 
        | CHANGE_SYM opt_column field_ident
 
2282
        | CHANGE opt_column field_ident
1750
2283
          {
1751
2284
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1752
2285
            statement->change= $3.str;
1755
2288
          field_spec opt_place
1756
2289
        | MODIFY_SYM opt_column field_ident
1757
2290
          {
 
2291
            LEX *lex=Lex;
1758
2292
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1759
 
            Lex->length= Lex->dec=0;
1760
 
            Lex->type= 0;
 
2293
            lex->length=lex->dec=0; lex->type=0;
1761
2294
            statement->default_value= statement->on_update_value= 0;
1762
2295
            statement->comment= null_lex_str;
1763
 
            Lex->charset= NULL;
 
2296
            lex->charset= NULL;
1764
2297
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1765
2298
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1766
2299
 
1767
 
            Lex->setField(NULL);
 
2300
            statement->current_proto_field= NULL;
1768
2301
          }
1769
2302
          field_def
1770
2303
          {
 
2304
            LEX *lex=Lex;
1771
2305
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1772
2306
 
1773
 
            if (add_field_to_list(Lex->session,&$3,
 
2307
            if (add_field_to_list(lex->session,&$3,
1774
2308
                                  (enum enum_field_types) $5,
1775
 
                                  Lex->length, Lex->dec, Lex->type,
 
2309
                                  lex->length, lex->dec, lex->type,
1776
2310
                                  statement->column_format,
1777
2311
                                  statement->default_value,
1778
2312
                                  statement->on_update_value,
1779
2313
                                  &statement->comment,
1780
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2314
                                  $3.str, &lex->interval_list, lex->charset))
1781
2315
              DRIZZLE_YYABORT;
1782
2316
          }
1783
2317
          opt_place
1826
2360
            statement->alter_info.keys_onoff= ENABLE;
1827
2361
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1828
2362
          }
1829
 
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
 
2363
        | ALTER opt_column field_ident SET DEFAULT signed_literal
1830
2364
          {
1831
2365
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1832
2366
 
1833
2367
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
1834
2368
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1835
2369
          }
1836
 
        | ALTER_SYM opt_column field_ident DROP DEFAULT
 
2370
        | ALTER opt_column field_ident DROP DEFAULT
1837
2371
          {
1838
2372
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1839
2373
 
1842
2376
          }
1843
2377
        | RENAME opt_to table_ident
1844
2378
          {
 
2379
            LEX *lex=Lex;
1845
2380
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1846
2381
            size_t dummy;
1847
2382
 
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))
 
2383
            lex->select_lex.db=$3->db.str;
 
2384
            if (lex->select_lex.db == NULL &&
 
2385
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1851
2386
            {
1852
2387
              DRIZZLE_YYABORT;
1853
2388
            }
1858
2393
              DRIZZLE_YYABORT;
1859
2394
            }
1860
2395
 
1861
 
            Lex->name= $3->table;
 
2396
            lex->name= $3->table;
1862
2397
            statement->alter_info.flags.set(ALTER_RENAME);
1863
2398
          }
1864
2399
        | CONVERT_SYM TO_SYM collation_name_or_default
1865
2400
          {
1866
2401
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
2402
 
1868
 
            statement->create_info().table_charset=
1869
 
            statement->create_info().default_table_charset= $3;
1870
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2403
            statement->create_info.table_charset=
 
2404
            statement->create_info.default_table_charset= $3;
 
2405
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1871
2406
              HA_CREATE_USED_DEFAULT_CHARSET);
1872
2407
            statement->alter_info.flags.set(ALTER_CONVERT);
1873
2408
          }
1905
2440
          /* empty */ {}
1906
2441
        | AFTER_SYM ident
1907
2442
          {
1908
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2443
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2444
 
 
2445
            store_position_for_column($2.str);
 
2446
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1909
2447
          }
1910
2448
        | FIRST_SYM
1911
2449
          {
1912
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2450
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2451
 
 
2452
            store_position_for_column(first_keyword);
 
2453
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1913
2454
          }
1914
2455
        ;
1915
2456
 
1923
2464
start:
1924
2465
          START_SYM TRANSACTION_SYM start_transaction_opts
1925
2466
          {
1926
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2467
            LEX *lex= Lex;
 
2468
            lex->sql_command= SQLCOM_BEGIN;
 
2469
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2470
            if (lex->statement == NULL)
 
2471
              DRIZZLE_YYABORT;
1927
2472
          }
1928
2473
        ;
1929
2474
 
1938
2483
analyze:
1939
2484
          ANALYZE_SYM table_or_tables
1940
2485
          {
1941
 
            Lex->statement= new statement::Analyze(YYSession);
 
2486
            LEX *lex=Lex;
 
2487
            lex->sql_command = SQLCOM_ANALYZE;
 
2488
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2489
            if (lex->statement == NULL)
 
2490
              DRIZZLE_YYABORT;
1942
2491
          }
1943
2492
          table_list
1944
2493
          {}
1947
2496
check:
1948
2497
          CHECK_SYM table_or_tables
1949
2498
          {
1950
 
            Lex->statement= new statement::Check(YYSession);
 
2499
            LEX *lex=Lex;
 
2500
 
 
2501
            lex->sql_command = SQLCOM_CHECK;
 
2502
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2503
            if (lex->statement == NULL)
 
2504
              DRIZZLE_YYABORT;
1951
2505
          }
1952
2506
          table_list
1953
2507
          {}
1956
2510
rename:
1957
2511
          RENAME table_or_tables
1958
2512
          {
1959
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2513
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2514
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2515
            if (Lex->statement == NULL)
 
2516
              DRIZZLE_YYABORT;
1960
2517
          }
1961
2518
          table_to_table_list
1962
2519
          {}
1970
2527
table_to_table:
1971
2528
          table_ident TO_SYM table_ident
1972
2529
          {
1973
 
            Select_Lex *sl= Lex->current_select;
1974
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2530
            LEX *lex=Lex;
 
2531
            Select_Lex *sl= lex->current_select;
 
2532
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1975
2533
                                       TL_IGNORE) ||
1976
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2534
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1977
2535
                                       TL_IGNORE))
1978
2536
              DRIZZLE_YYABORT;
1979
2537
          }
1987
2545
select:
1988
2546
          select_init
1989
2547
          {
1990
 
            Lex->statement= new statement::Select(YYSession);
 
2548
            LEX *lex= Lex;
 
2549
            lex->sql_command= SQLCOM_SELECT;
 
2550
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2551
            if (lex->statement == NULL)
 
2552
              DRIZZLE_YYABORT;
1991
2553
          }
1992
2554
        ;
1993
2555
 
2000
2562
select_paren:
2001
2563
          SELECT_SYM select_part2
2002
2564
          {
2003
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2565
            if (setup_select_in_parentheses(YYSession, Lex))
2004
2566
              DRIZZLE_YYABORT;
2005
2567
          }
2006
2568
        | '(' select_paren ')'
2010
2572
select_paren_derived:
2011
2573
          SELECT_SYM select_part2_derived
2012
2574
          {
2013
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2575
            if (setup_select_in_parentheses(YYSession, Lex))
2014
2576
              DRIZZLE_YYABORT;
2015
2577
          }
2016
2578
        | '(' select_paren_derived ')'
2019
2581
select_init2:
2020
2582
          select_part2
2021
2583
          {
2022
 
            Select_Lex * sel= Lex->current_select;
2023
 
            if (Lex->current_select->set_braces(0))
 
2584
            LEX *lex= Lex;
 
2585
            Select_Lex * sel= lex->current_select;
 
2586
            if (lex->current_select->set_braces(0))
2024
2587
            {
2025
 
              parser::my_parse_error(YYSession->m_lip);
 
2588
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2589
              my_parse_error(&pass);
2026
2590
              DRIZZLE_YYABORT;
2027
2591
            }
2028
2592
            if (sel->linkage == UNION_TYPE &&
2029
2593
                sel->master_unit()->first_select()->braces)
2030
2594
            {
2031
 
              parser::my_parse_error(YYSession->m_lip);
 
2595
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2596
              my_parse_error(&pass);
2032
2597
              DRIZZLE_YYABORT;
2033
2598
            }
2034
2599
          }
2037
2602
 
2038
2603
select_part2:
2039
2604
          {
2040
 
            Select_Lex *sel= Lex->current_select;
 
2605
            LEX *lex= Lex;
 
2606
            Select_Lex *sel= lex->current_select;
2041
2607
            if (sel->linkage != UNION_TYPE)
2042
 
              init_select(Lex);
2043
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2608
              mysql_init_select(lex);
 
2609
            lex->current_select->parsing_place= SELECT_LIST;
2044
2610
          }
2045
2611
          select_options select_item_list
2046
2612
          {
2070
2636
select_options:
2071
2637
          /* empty*/
2072
2638
        | select_option_list
2073
 
          { }
 
2639
          {
 
2640
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2641
                Lex->current_select->options & SELECT_ALL)
 
2642
            {
 
2643
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2644
              DRIZZLE_YYABORT;
 
2645
            }
 
2646
          }
2074
2647
        ;
2075
2648
 
2076
2649
select_option_list:
2078
2651
        | select_option
2079
2652
        ;
2080
2653
 
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
2654
select_option:
2129
2655
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2656
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2657
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2658
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2130
2659
        | SQL_BUFFER_RESULT
2131
2660
          {
2132
 
            if (check_simple_select(YYSession))
 
2661
            if (check_simple_select())
2133
2662
              DRIZZLE_YYABORT;
2134
2663
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2135
2664
          }
2136
 
        | select_option_small_or_big
2137
 
          { }
2138
 
        | select_option_distinct_or_all
2139
 
          { }
2140
2665
        | SQL_CALC_FOUND_ROWS
2141
2666
          {
2142
 
            if (check_simple_select(YYSession))
 
2667
            if (check_simple_select())
2143
2668
              DRIZZLE_YYABORT;
2144
2669
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2145
2670
          }
 
2671
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2146
2672
        ;
2147
2673
 
2148
2674
select_lock_type:
2149
2675
          /* empty */
2150
2676
        | FOR_SYM UPDATE_SYM
2151
2677
          {
2152
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2678
            LEX *lex=Lex;
 
2679
            lex->current_select->set_lock_for_tables(TL_WRITE);
2153
2680
          }
2154
2681
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2155
2682
          {
2156
 
            Lex->current_select->
 
2683
            LEX *lex=Lex;
 
2684
            lex->current_select->
2157
2685
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2158
2686
          }
2159
2687
        ;
2163
2691
        | select_item
2164
2692
        | '*'
2165
2693
          {
2166
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
2694
            Session *session= YYSession;
 
2695
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
2167
2696
                                                          context,
2168
2697
                                                          NULL, NULL, "*")))
2169
2698
              DRIZZLE_YYABORT;
2170
 
            (YYSession->lex->current_select->with_wild)++;
 
2699
            (session->lex->current_select->with_wild)++;
2171
2700
          }
2172
2701
        ;
2173
2702
 
2174
2703
select_item:
2175
2704
          remember_name table_wild remember_end
2176
2705
          {
2177
 
            if (YYSession->add_item_to_list($2))
 
2706
            Session *session= YYSession;
 
2707
 
 
2708
            if (session->add_item_to_list($2))
2178
2709
              DRIZZLE_YYABORT;
2179
2710
          }
2180
2711
        | remember_name expr remember_end select_alias
2181
2712
          {
 
2713
            Session *session= YYSession;
2182
2714
            assert($1 < $3);
2183
2715
 
2184
 
            if (YYSession->add_item_to_list($2))
 
2716
            if (session->add_item_to_list($2))
2185
2717
              DRIZZLE_YYABORT;
2186
 
 
2187
2718
            if ($4.str)
2188
2719
            {
2189
2720
              $2->is_autogenerated_name= false;
2191
2722
            }
2192
2723
            else if (!$2->name)
2193
2724
            {
2194
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2725
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2195
2726
            }
2196
2727
          }
2197
2728
        ;
2198
2729
 
2199
2730
remember_name:
2200
2731
          {
2201
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2732
            Session *session= YYSession;
 
2733
            Lex_input_stream *lip= session->m_lip;
2202
2734
            $$= (char*) lip->get_cpp_tok_start();
2203
2735
          }
2204
2736
        ;
2205
2737
 
2206
2738
remember_end:
2207
2739
          {
2208
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2740
            Session *session= YYSession;
 
2741
            Lex_input_stream *lip= session->m_lip;
2209
2742
            $$= (char*) lip->get_cpp_tok_end();
2210
2743
          }
2211
2744
        ;
2358
2891
          }
2359
2892
        | bit_expr not IN_SYM '(' subselect ')'
2360
2893
          {
2361
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2362
 
            $$= negate_expression(YYSession, item);
 
2894
            Session *session= YYSession;
 
2895
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2896
            $$= negate_expression(session, item);
2363
2897
          }
2364
2898
        | bit_expr IN_SYM '(' expr ')'
2365
2899
          {
2366
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2900
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2367
2901
          }
2368
2902
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2369
2903
          {
2373
2907
          }
2374
2908
        | bit_expr not IN_SYM '(' expr ')'
2375
2909
          {
2376
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2910
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2377
2911
          }
2378
2912
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2379
2913
          {
2406
2940
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2407
2941
            args->push_back($1);
2408
2942
            args->push_back($3);
2409
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2943
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2410
2944
            {
2411
2945
              DRIZZLE_YYABORT;
2412
2946
            }
2417
2951
            args->push_back($1);
2418
2952
            args->push_back($4);
2419
2953
            args->push_back(new (YYSession->mem_root) Item_int(1));
2420
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
 
2954
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
2421
2955
            {
2422
2956
              DRIZZLE_YYABORT;
2423
2957
            }
2481
3015
        | function_call_conflict
2482
3016
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2483
3017
          {
2484
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
3018
            Session *session= YYSession;
 
3019
            Item *i1= new (session->mem_root) Item_string($3.str,
2485
3020
                                                      $3.length,
2486
 
                                                      YYSession->charset());
2487
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
3021
                                                      session->charset());
 
3022
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2488
3023
          }
2489
3024
        | literal
2490
3025
        | variable
2522
3057
          }
2523
3058
        | CAST_SYM '(' expr AS cast_type ')'
2524
3059
          {
2525
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2526
 
                                 Lex->charset);
 
3060
            LEX *lex= Lex;
 
3061
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
3062
                                 lex->charset);
2527
3063
            if (!$$)
2528
3064
              DRIZZLE_YYABORT;
2529
3065
          }
2541
3077
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2542
3078
                                                         $3);
2543
3079
          }
2544
 
        | VALUES '(' simple_ident ')'
 
3080
        | VALUES '(' simple_ident_nospvar ')'
2545
3081
          {
2546
3082
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2547
3083
                                                        $3);
2563
3099
        | CURRENT_USER optional_braces
2564
3100
          {
2565
3101
            std::string user_str("user");
2566
 
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
 
3102
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2567
3103
            {
2568
3104
              DRIZZLE_YYABORT;
2569
3105
            }
2579
3115
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
2580
3116
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2581
3117
          {
2582
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3118
            Session *session= YYSession;
 
3119
            List<Item> *list= new (session->mem_root) List<Item>;
2583
3120
            list->push_front($5);
2584
3121
            list->push_front($3);
2585
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2586
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3122
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3123
            $$= new (session->mem_root) Item_func_interval(item);
2587
3124
          }
2588
3125
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2589
3126
          {
 
3127
            Session *session= YYSession;
2590
3128
            $7->push_front($5);
2591
3129
            $7->push_front($3);
2592
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2593
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3130
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3131
            $$= new (session->mem_root) Item_func_interval(item);
2594
3132
          }
2595
3133
        | LEFT '(' expr ',' expr ')'
2596
3134
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2622
3160
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2623
3161
        | USER '(' ')'
2624
3162
          {
2625
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3163
            std::string user_str("user");
 
3164
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2626
3165
            {
2627
3166
              DRIZZLE_YYABORT;
2628
3167
            }
2688
3227
            args->push_back($3);
2689
3228
            args->push_back($5);
2690
3229
            args->push_back($7);
2691
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3230
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2692
3231
            {
2693
3232
              DRIZZLE_YYABORT;
2694
3233
            }
2699
3238
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2700
3239
            args->push_back($3);
2701
3240
            args->push_back($5);
2702
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3241
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2703
3242
            {
2704
3243
              DRIZZLE_YYABORT;
2705
3244
            }
2711
3250
            args->push_back($3);
2712
3251
            args->push_back($5);
2713
3252
            args->push_back($7);
2714
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3253
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2715
3254
            {
2716
3255
              DRIZZLE_YYABORT;
2717
3256
            }
2722
3261
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2723
3262
            args->push_back($3);
2724
3263
            args->push_back($5);
2725
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3264
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2726
3265
            {
2727
3266
              DRIZZLE_YYABORT;
2728
3267
            }
2765
3304
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2766
3305
        | DATABASE '(' ')'
2767
3306
          {
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)))
 
3307
            std::string database_str("database");
 
3308
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
2777
3309
            {
2778
3310
              DRIZZLE_YYABORT;
2779
3311
            }
2789
3321
              args->push_back(new (YYSession->mem_root) Item_int(1));
2790
3322
            }
2791
3323
 
2792
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
 
3324
            if (! ($$= reserved_keyword_function(YYSession, "execute", args)))
2793
3325
            {
2794
3326
              DRIZZLE_YYABORT;
2795
3327
            }
2807
3339
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2808
3340
            }
2809
3341
 
2810
 
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
 
3342
            if (! ($$= reserved_keyword_function(YYSession, kill_str, args)))
2811
3343
            {
2812
3344
              DRIZZLE_YYABORT;
2813
3345
            }
2822
3354
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
2823
3355
        | REPLACE '(' expr ',' expr ',' expr ')'
2824
3356
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3357
        | REVERSE_SYM '(' expr ')'
 
3358
          {
 
3359
            std::string reverse_str("reverse");
 
3360
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3361
            args->push_back($3);
 
3362
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
3363
            {
 
3364
              DRIZZLE_YYABORT;
 
3365
            }
 
3366
          }
2825
3367
        | TRUNCATE_SYM '(' expr ',' expr ')'
2826
3368
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2827
3369
        | WAIT_SYM '(' expr ')'
2829
3371
            std::string wait_str("wait");
2830
3372
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2831
3373
            args->push_back($3);
2832
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
3374
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2833
3375
            {
2834
3376
              DRIZZLE_YYABORT;
2835
3377
            }
2836
3378
          }
2837
3379
        | UUID_SYM '(' ')'
2838
3380
          {
2839
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
 
3381
            if (! ($$= reserved_keyword_function(YYSession, "uuid", NULL)))
2840
3382
            {
2841
3383
              DRIZZLE_YYABORT;
2842
3384
            }
2848
3390
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2849
3391
            args->push_back($3);
2850
3392
            args->push_back($5);
2851
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
 
3393
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
2852
3394
            {
2853
3395
              DRIZZLE_YYABORT;
2854
3396
            }
2873
3415
          }
2874
3416
          opt_udf_expr_list ')'
2875
3417
          {
 
3418
            Session *session= YYSession;
2876
3419
            Create_func *builder;
2877
3420
            Item *item= NULL;
2878
3421
 
2888
3431
            builder= find_native_function_builder($1);
2889
3432
            if (builder)
2890
3433
            {
2891
 
              item= builder->create(YYSession, $1, $4);
 
3434
              item= builder->create(session, $1, $4);
2892
3435
            }
2893
3436
            else
2894
3437
            {
2896
3439
              const plugin::Function *udf= $<udf>3;
2897
3440
              if (udf)
2898
3441
              {
2899
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3442
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2900
3443
              } else {
2901
3444
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2902
3445
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3013
3556
        ;
3014
3557
 
3015
3558
variable_aux:
3016
 
          user_variable_ident SET_VAR expr
 
3559
          ident_or_text SET_VAR expr
3017
3560
          {
3018
3561
            $$= new Item_func_set_user_var($1, $3);
3019
3562
            Lex->setCacheable(false);
3020
3563
          }
3021
 
        | user_variable_ident
 
3564
        | ident_or_text
3022
3565
          {
3023
3566
            $$= new Item_func_get_user_var(*YYSession, $1);
3024
3567
            Lex->setCacheable(false);
3025
3568
          }
3026
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3569
        | '@' opt_var_ident_type ident_or_text opt_component
3027
3570
          {
3028
3571
            /* disallow "SELECT @@global.global.variable" */
3029
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3572
            if ($3.str && $4.str && check_reserved_words(&$3))
3030
3573
            {
3031
 
              parser::my_parse_error(YYSession->m_lip);
 
3574
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3575
              my_parse_error(&pass);
3032
3576
              DRIZZLE_YYABORT;
3033
3577
            }
3034
3578
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3037
3581
        ;
3038
3582
 
3039
3583
opt_distinct:
3040
 
          /* empty */ { $$ = false; }
3041
 
        | DISTINCT    { $$ = true; }
 
3584
          /* empty */ { $$ = 0; }
 
3585
        | DISTINCT    { $$ = 1; }
3042
3586
        ;
3043
3587
 
3044
3588
opt_gconcat_separator:
3067
3611
in_sum_expr:
3068
3612
          opt_all
3069
3613
          {
3070
 
            if (Lex->current_select->inc_in_sum_expr())
 
3614
            LEX *lex= Lex;
 
3615
            if (lex->current_select->inc_in_sum_expr())
3071
3616
            {
3072
 
              parser::my_parse_error(YYSession->m_lip);
 
3617
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3618
              my_parse_error(&pass);
3073
3619
              DRIZZLE_YYABORT;
3074
3620
            }
3075
3621
          }
3083
3629
cast_type:
3084
3630
          BINARY opt_len
3085
3631
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3086
 
        | BOOLEAN_SYM
3087
 
          { $$=ITEM_CAST_BOOLEAN; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3088
 
        | SIGNED_SYM
3089
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3090
 
        | SIGNED_SYM INT_SYM
3091
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3092
 
        | INT_SYM
3093
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3094
 
        | UNSIGNED_SYM
3095
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3096
 
        | UNSIGNED_SYM INT_SYM
3097
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3098
3632
        | CHAR_SYM opt_len
3099
3633
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3100
3634
        | DATE_SYM
3151
3685
          table_factor { $$=$1; }
3152
3686
        | join_table
3153
3687
          {
3154
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3688
            LEX *lex= Lex;
 
3689
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3155
3690
              DRIZZLE_YYABORT;
3156
3691
          }
3157
3692
        ;
3298
3833
          }
3299
3834
          expr
3300
3835
          {
3301
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3836
            LEX *lex= Lex;
 
3837
            if (!($$= lex->current_select->convert_right_join()))
3302
3838
              DRIZZLE_YYABORT;
3303
3839
            add_join_on($$, $8);
3304
3840
            Lex->pop_context();
3310
3846
          }
3311
3847
          USING '(' using_list ')'
3312
3848
          {
3313
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3849
            LEX *lex= Lex;
 
3850
            if (!($$= lex->current_select->convert_right_join()))
3314
3851
              DRIZZLE_YYABORT;
3315
3852
            add_join_natural($$,$5,$9,Lex->current_select);
3316
3853
          }
3318
3855
          {
3319
3856
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3320
3857
            add_join_natural($6,$1,NULL,Lex->current_select);
3321
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3858
            LEX *lex= Lex;
 
3859
            if (!($$= lex->current_select->convert_right_join()))
3322
3860
              DRIZZLE_YYABORT;
3323
3861
          }
3324
3862
        ;
3326
3864
normal_join:
3327
3865
          JOIN_SYM {}
3328
3866
        | INNER_SYM JOIN_SYM {}
3329
 
        | CROSS JOIN_SYM
3330
 
          {
3331
 
            Lex->is_cross= true;
3332
 
            Lex->current_select->is_cross= true;
3333
 
          }
 
3867
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3334
3868
        ;
3335
3869
 
3336
3870
/*
3355
3889
          }
3356
3890
        | select_derived_init get_select_lex select_derived2
3357
3891
          {
3358
 
            Select_Lex *sel= Lex->current_select;
 
3892
            LEX *lex= Lex;
 
3893
            Select_Lex *sel= lex->current_select;
3359
3894
            if ($1)
3360
3895
            {
3361
3896
              if (sel->set_braces(1))
3362
3897
              {
3363
 
                parser::my_parse_error(YYSession->m_lip);
 
3898
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3899
                my_parse_error(&pass);
3364
3900
                DRIZZLE_YYABORT;
3365
3901
              }
3366
3902
              /* select in braces, can't contain global parameters */
3368
3904
                sel->master_unit()->global_parameters=
3369
3905
                   sel->master_unit()->fake_select_lex;
3370
3906
            }
3371
 
            if ($2->init_nested_join(Lex->session))
 
3907
            if ($2->init_nested_join(lex->session))
3372
3908
              DRIZZLE_YYABORT;
3373
3909
            $$= 0;
3374
3910
            /* incomplete derived tables return NULL, we must be
3410
3946
              /* Handle case of derived table, alias may be NULL if there
3411
3947
                 are no outer parentheses, add_table_to_list() will throw
3412
3948
                 error in this case */
3413
 
              Select_Lex *sel= Lex->current_select;
 
3949
              LEX *lex=Lex;
 
3950
              Select_Lex *sel= lex->current_select;
3414
3951
              Select_Lex_Unit *unit= sel->master_unit();
3415
 
              Lex->current_select= sel= unit->outer_select();
3416
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3952
              lex->current_select= sel= unit->outer_select();
 
3953
              if (!($$= sel->add_table_to_list(lex->session,
3417
3954
                                               new Table_ident(unit), $5, 0,
3418
3955
                                               TL_READ)))
3419
3956
 
3420
3957
                DRIZZLE_YYABORT;
3421
3958
              sel->add_joined_table($$);
3422
 
              Lex->pop_context();
 
3959
              lex->pop_context();
3423
3960
            }
3424
3961
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3425
3962
            {
3426
3963
              /* simple nested joins cannot have aliases or unions */
3427
 
              parser::my_parse_error(YYSession->m_lip);
 
3964
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3965
              my_parse_error(&pass);
3428
3966
              DRIZZLE_YYABORT;
3429
3967
            }
3430
3968
            else
3438
3976
          UNION_SYM
3439
3977
          union_option
3440
3978
          {
3441
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3979
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3442
3980
              DRIZZLE_YYABORT;
3443
3981
          }
3444
3982
          query_specification
3456
3994
select_init2_derived:
3457
3995
          select_part2_derived
3458
3996
          {
3459
 
            Select_Lex * sel= Lex->current_select;
3460
 
            if (Lex->current_select->set_braces(0))
 
3997
            LEX *lex= Lex;
 
3998
            Select_Lex * sel= lex->current_select;
 
3999
            if (lex->current_select->set_braces(0))
3461
4000
            {
3462
 
              parser::my_parse_error(YYSession->m_lip);
 
4001
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4002
              my_parse_error(&pass);
3463
4003
              DRIZZLE_YYABORT;
3464
4004
            }
3465
4005
            if (sel->linkage == UNION_TYPE &&
3466
4006
                sel->master_unit()->first_select()->braces)
3467
4007
            {
3468
 
              parser::my_parse_error(YYSession->m_lip);
 
4008
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4009
              my_parse_error(&pass);
3469
4010
              DRIZZLE_YYABORT;
3470
4011
            }
3471
4012
          }
3474
4015
/* The equivalent of select_part2 for nested queries. */
3475
4016
select_part2_derived:
3476
4017
          {
3477
 
            Select_Lex *sel= Lex->current_select;
 
4018
            LEX *lex= Lex;
 
4019
            Select_Lex *sel= lex->current_select;
3478
4020
            if (sel->linkage != UNION_TYPE)
3479
 
              init_select(Lex);
3480
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4021
              mysql_init_select(lex);
 
4022
            lex->current_select->parsing_place= SELECT_LIST;
3481
4023
          }
3482
4024
          select_options select_item_list
3483
4025
          {
3490
4032
select_derived:
3491
4033
          get_select_lex
3492
4034
          {
3493
 
            if ($1->init_nested_join(Lex->session))
 
4035
            LEX *lex= Lex;
 
4036
            if ($1->init_nested_join(lex->session))
3494
4037
              DRIZZLE_YYABORT;
3495
4038
          }
3496
4039
          derived_table_list
3497
4040
          {
 
4041
            LEX *lex= Lex;
3498
4042
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3499
4043
               for derived tables, both must equal NULL */
3500
4044
 
3501
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
4045
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3502
4046
              DRIZZLE_YYABORT;
3503
 
 
3504
4047
            if (!$3 && $$)
3505
4048
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
4049
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4050
              my_parse_error(&pass);
3507
4051
              DRIZZLE_YYABORT;
3508
4052
            }
3509
4053
          }
3511
4055
 
3512
4056
select_derived2:
3513
4057
          {
3514
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3515
 
            if (not Lex->expr_allows_subselect)
 
4058
            LEX *lex= Lex;
 
4059
            lex->derived_tables|= DERIVED_SUBQUERY;
 
4060
            if (!lex->expr_allows_subselect)
3516
4061
            {
3517
 
              parser::my_parse_error(YYSession->m_lip);
 
4062
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4063
              my_parse_error(&pass);
3518
4064
              DRIZZLE_YYABORT;
3519
4065
            }
3520
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
4066
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
4067
                mysql_new_select(lex, 1))
3521
4068
              DRIZZLE_YYABORT;
3522
 
            init_select(Lex);
3523
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3524
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4069
            mysql_init_select(lex);
 
4070
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
4071
            lex->current_select->parsing_place= SELECT_LIST;
3525
4072
          }
3526
4073
          select_options select_item_list
3527
4074
          {
3537
4084
select_derived_init:
3538
4085
          SELECT_SYM
3539
4086
          {
3540
 
            Select_Lex *sel= Lex->current_select;
 
4087
            LEX *lex= Lex;
 
4088
 
 
4089
            Select_Lex *sel= lex->current_select;
3541
4090
            TableList *embedding;
3542
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
4091
            if (!sel->embedding || sel->end_nested_join(lex->session))
3543
4092
            {
3544
4093
              /* we are not in parentheses */
3545
 
              parser::my_parse_error(YYSession->m_lip);
 
4094
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
4095
              my_parse_error(&pass);
3546
4096
              DRIZZLE_YYABORT;
3547
4097
            }
3548
4098
            embedding= Lex->current_select->embedding;
3690
4240
opt_table_alias:
3691
4241
          /* empty */ { $$=0; }
3692
4242
        | table_alias ident
3693
 
          {
3694
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3695
 
          }
 
4243
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3696
4244
        ;
3697
4245
 
3698
4246
opt_all:
3772
4320
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3773
4321
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3774
4322
            */
3775
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4323
            LEX *lex= Lex;
 
4324
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3776
4325
            {
3777
4326
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3778
4327
                       "global union parameters");
3779
4328
              DRIZZLE_YYABORT;
3780
4329
            }
3781
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4330
            lex->current_select->olap= ROLLUP_TYPE;
3782
4331
          }
3783
4332
        ;
3784
4333
 
3796
4345
        ;
3797
4346
 
3798
4347
alter_order_item:
3799
 
          simple_ident order_dir
 
4348
          simple_ident_nospvar order_dir
3800
4349
          {
 
4350
            Session *session= YYSession;
3801
4351
            bool ascending= ($2 == 1) ? true : false;
3802
 
            if (YYSession->add_order_to_list($1, ascending))
 
4352
            if (session->add_order_to_list($1, ascending))
3803
4353
              DRIZZLE_YYABORT;
3804
4354
          }
3805
4355
        ;
3816
4366
order_clause:
3817
4367
          ORDER_SYM BY
3818
4368
          {
3819
 
            if (not parser::buildOrderBy(Lex))
 
4369
            LEX *lex=Lex;
 
4370
            Select_Lex *sel= lex->current_select;
 
4371
            Select_Lex_Unit *unit= sel-> master_unit();
 
4372
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4373
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4374
                (sel->linkage != UNION_TYPE || sel->braces))
 
4375
            {
 
4376
              my_error(ER_WRONG_USAGE, MYF(0),
 
4377
                       "CUBE/ROLLUP", "ORDER BY");
3820
4378
              DRIZZLE_YYABORT;
 
4379
            }
 
4380
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4381
            {
 
4382
              /*
 
4383
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4384
                executed in the same way as the query
 
4385
                SELECT ... ORDER BY order_list
 
4386
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4387
                Otherwise we create a fake Select_Lex if it has not been created
 
4388
                yet.
 
4389
              */
 
4390
              Select_Lex *first_sl= unit->first_select();
 
4391
              if (!unit->is_union() &&
 
4392
                  (first_sl->order_list.elements ||
 
4393
                   first_sl->select_limit) &&           
 
4394
                  unit->add_fake_select_lex(lex->session))
 
4395
                DRIZZLE_YYABORT;
 
4396
            }
3821
4397
          }
3822
4398
          order_list
3823
4399
        ;
3824
4400
 
3825
4401
order_list:
3826
4402
          order_list ',' order_ident order_dir
3827
 
          {
3828
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3829
 
              DRIZZLE_YYABORT;
3830
 
          }
 
4403
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3831
4404
        | order_ident order_dir
3832
 
          {
3833
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3834
 
              DRIZZLE_YYABORT;
3835
 
          }
 
4405
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3836
4406
        ;
3837
4407
 
3838
4408
order_dir:
3844
4414
opt_limit_clause_init:
3845
4415
          /* empty */
3846
4416
          {
3847
 
            Select_Lex *sel= Lex->current_select;
 
4417
            LEX *lex= Lex;
 
4418
            Select_Lex *sel= lex->current_select;
3848
4419
            sel->offset_limit= 0;
3849
4420
            sel->select_limit= 0;
3850
4421
          }
3893
4464
delete_limit_clause:
3894
4465
          /* empty */
3895
4466
          {
3896
 
            Lex->current_select->select_limit= 0;
 
4467
            LEX *lex=Lex;
 
4468
            lex->current_select->select_limit= 0;
3897
4469
          }
3898
4470
        | LIMIT limit_option
3899
4471
          {
3904
4476
        ;
3905
4477
 
3906
4478
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); }
 
4479
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4480
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4481
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4482
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4483
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4484
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3913
4485
        ;
3914
4486
 
3915
4487
ulonglong_num:
3922
4494
 
3923
4495
select_var_list_init:
3924
4496
          {
3925
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4497
            LEX *lex=Lex;
 
4498
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3926
4499
              DRIZZLE_YYABORT;
3927
4500
          }
3928
4501
          select_var_list
3935
4508
        ;
3936
4509
 
3937
4510
select_var_ident: 
3938
 
          '@' user_variable_ident
 
4511
          '@' ident_or_text
3939
4512
          {
3940
 
            if (Lex->result)
3941
 
            {
3942
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3943
 
            }
 
4513
            LEX *lex=Lex;
 
4514
            if (lex->result)
 
4515
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3944
4516
            else
3945
 
            {
3946
4517
              /*
3947
4518
                The parser won't create select_result instance only
3948
4519
                if it's an EXPLAIN.
3949
4520
              */
3950
 
              assert(Lex->describe);
3951
 
            }
 
4521
              assert(lex->describe);
3952
4522
          }
3953
4523
        ;
3954
4524
 
3961
4531
into_destination:
3962
4532
          OUTFILE TEXT_STRING_filesystem
3963
4533
          {
3964
 
            Lex->setCacheable(false);
3965
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3966
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4534
            LEX *lex= Lex;
 
4535
            lex->setCacheable(false);
 
4536
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4537
                !(lex->result= new select_export(lex->exchange)))
3967
4538
              DRIZZLE_YYABORT;
3968
4539
          }
3969
4540
          opt_field_term opt_line_term
3970
4541
        | DUMPFILE TEXT_STRING_filesystem
3971
4542
          {
3972
 
            if (not Lex->describe)
 
4543
            LEX *lex=Lex;
 
4544
            if (!lex->describe)
3973
4545
            {
3974
 
              Lex->setCacheable(false);
3975
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4546
              lex->setCacheable(false);
 
4547
              if (!(lex->exchange= new file_exchange($2.str,1)))
3976
4548
                DRIZZLE_YYABORT;
3977
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4549
              if (!(lex->result= new select_dump(lex->exchange)))
3978
4550
                DRIZZLE_YYABORT;
3979
4551
            }
3980
4552
          }
3987
4559
*/
3988
4560
 
3989
4561
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;
 
4562
          DROP opt_temporary table_or_tables if_exists table_list
 
4563
          {
 
4564
            LEX *lex=Lex;
 
4565
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4566
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4567
            lex->statement= statement;
 
4568
            if (lex->statement == NULL)
 
4569
              DRIZZLE_YYABORT;
3998
4570
            statement->drop_temporary= $2;
3999
4571
            statement->drop_if_exists= $4;
4000
4572
          }
4001
4573
        | DROP build_method INDEX_SYM ident ON table_ident {}
4002
4574
          {
4003
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
4004
 
            Lex->statement= statement;
 
4575
            LEX *lex=Lex;
 
4576
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4577
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4578
            lex->statement= statement;
 
4579
            if (lex->statement == NULL)
 
4580
              DRIZZLE_YYABORT;
4005
4581
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4006
4582
            statement->alter_info.build_method= $2;
4007
4583
            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))
 
4584
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4585
                                                        TL_OPTION_UPDATING))
4010
4586
              DRIZZLE_YYABORT;
4011
4587
          }
4012
 
        | DROP DATABASE if_exists schema_name
 
4588
        | DROP DATABASE if_exists ident
4013
4589
          {
4014
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4015
 
            Lex->statement= statement;
 
4590
            LEX *lex=Lex;
 
4591
            lex->sql_command= SQLCOM_DROP_DB;
 
4592
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4593
            lex->statement= statement;
 
4594
            if (lex->statement == NULL)
 
4595
              DRIZZLE_YYABORT;
4016
4596
            statement->drop_if_exists=$3;
4017
 
            Lex->name= $4;
 
4597
            lex->name= $4;
4018
4598
          }
4019
 
        ;
4020
 
 
4021
4599
table_list:
4022
4600
          table_name
4023
4601
        | table_list ',' table_name
4032
4610
        ;
4033
4611
 
4034
4612
if_exists:
4035
 
          /* empty */ { $$= false; }
4036
 
        | IF EXISTS { $$= true; }
 
4613
          /* empty */ { $$= 0; }
 
4614
        | IF EXISTS { $$= 1; }
4037
4615
        ;
4038
4616
 
4039
4617
opt_temporary:
4040
 
          /* empty */ { $$= false; }
4041
 
        | TEMPORARY_SYM { $$= true; }
 
4618
          /* empty */ { $$= 0; }
 
4619
        | TEMPORARY_SYM { $$= 1; }
4042
4620
        ;
4043
4621
 
4044
4622
/*
4045
4623
  Execute a string as dynamic SQL.
4046
 
*/
 
4624
  */
4047
4625
 
4048
4626
execute:
4049
4627
       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
 
        }
 
4628
       {
 
4629
          LEX *lex= Lex;
 
4630
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession, $2, $3, $4, $5);
 
4631
          lex->statement= statement;
 
4632
          if (lex->statement == NULL)
 
4633
            DRIZZLE_YYABORT;
 
4634
       }
4053
4635
 
4054
4636
 
4055
4637
execute_var_or_string:
4056
 
         user_variable_ident
 
4638
         ident_or_text
4057
4639
         {
4058
4640
            $$.set($1);
4059
4641
         }
4060
 
        | '@' user_variable_ident
 
4642
        | '@' ident_or_text
4061
4643
        {
4062
4644
            $$.set($2, true);
4063
4645
        }
4064
4646
 
4065
4647
opt_status:
4066
 
          /* empty */ { $$= false; }
4067
 
        | WITH NO_SYM RETURN_SYM { $$= true; }
 
4648
          /* empty */ { $$= 0; }
 
4649
        | WITH NO_SYM RETURN_SYM { $$= 1; }
4068
4650
        ;
4069
4651
 
4070
4652
opt_concurrent:
4071
 
          /* empty */ { $$= false; }
4072
 
        | CONCURRENT { $$= true; }
 
4653
          /* empty */ { $$= 0; }
 
4654
        | CONCURRENT { $$= 1; }
4073
4655
        ;
4074
4656
 
4075
4657
opt_wait:
4076
 
          /* empty */ { $$= false; }
4077
 
        | WAIT_SYM { $$= true; }
 
4658
          /* empty */ { $$= 0; }
 
4659
        | WAIT_SYM { $$= 1; }
4078
4660
        ;
4079
4661
 
4080
4662
/*
4084
4666
insert:
4085
4667
          INSERT
4086
4668
          {
4087
 
            Lex->statement= new statement::Insert(YYSession);
4088
 
            Lex->duplicates= DUP_ERROR;
4089
 
            init_select(Lex);
 
4669
            LEX *lex= Lex;
 
4670
            lex->sql_command= SQLCOM_INSERT;
 
4671
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4672
            if (lex->statement == NULL)
 
4673
              DRIZZLE_YYABORT;
 
4674
            lex->duplicates= DUP_ERROR;
 
4675
            mysql_init_select(lex);
4090
4676
            /* for subselects */
4091
 
            Lex->lock_option= TL_READ;
 
4677
            lex->lock_option= TL_READ;
4092
4678
          }
4093
4679
          opt_ignore insert2
4094
4680
          {
4102
4688
replace:
4103
4689
          REPLACE
4104
4690
          {
4105
 
            Lex->statement= new statement::Replace(YYSession);
4106
 
            Lex->duplicates= DUP_REPLACE;
4107
 
            init_select(Lex);
 
4691
            LEX *lex= Lex;
 
4692
            lex->sql_command= SQLCOM_REPLACE;
 
4693
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4694
            if (lex->statement == NULL)
 
4695
              DRIZZLE_YYABORT;
 
4696
            lex->duplicates= DUP_REPLACE;
 
4697
            mysql_init_select(lex);
4108
4698
          }
4109
4699
          insert2
4110
4700
          {
4123
4713
insert_table:
4124
4714
          table_name
4125
4715
          {
4126
 
            Lex->field_list.empty();
4127
 
            Lex->many_values.empty();
4128
 
            Lex->insert_list=0;
 
4716
            LEX *lex=Lex;
 
4717
            lex->field_list.empty();
 
4718
            lex->many_values.empty();
 
4719
            lex->insert_list=0;
4129
4720
          };
4130
4721
 
4131
4722
insert_field_spec:
4132
4723
          insert_values {}
4133
4724
        | '(' ')' insert_values {}
4134
4725
        | '(' fields ')' insert_values {}
4135
 
        | SET_SYM
 
4726
        | SET
4136
4727
          {
4137
 
            if (not (Lex->insert_list = new List_item) ||
4138
 
                Lex->many_values.push_back(Lex->insert_list))
 
4728
            LEX *lex=Lex;
 
4729
            if (!(lex->insert_list = new List_item) ||
 
4730
                lex->many_values.push_back(lex->insert_list))
4139
4731
              DRIZZLE_YYABORT;
4140
4732
          }
4141
4733
          ident_eq_list
4149
4741
insert_values:
4150
4742
          VALUES values_list {}
4151
4743
        | VALUE_SYM values_list {}
4152
 
        | stored_select
4153
 
          {
4154
 
            Lex->current_select->set_braces(0);
4155
 
          }
 
4744
        | create_select
 
4745
          { Lex->current_select->set_braces(0);}
4156
4746
          union_clause {}
4157
 
        | '(' stored_select ')'
4158
 
          {
4159
 
            Lex->current_select->set_braces(1);
4160
 
          }
 
4747
        | '(' create_select ')'
 
4748
          { Lex->current_select->set_braces(1);}
4161
4749
          union_opt {}
4162
4750
        ;
4163
4751
 
4172
4760
        ;
4173
4761
 
4174
4762
ident_eq_value:
4175
 
          simple_ident equal expr_or_default
 
4763
          simple_ident_nospvar equal expr_or_default
4176
4764
          {
4177
 
            if (Lex->field_list.push_back($1) ||
4178
 
                Lex->insert_list->push_back($3))
 
4765
            LEX *lex=Lex;
 
4766
            if (lex->field_list.push_back($1) ||
 
4767
                lex->insert_list->push_back($3))
4179
4768
              DRIZZLE_YYABORT;
4180
4769
          }
4181
4770
        ;
4198
4787
          }
4199
4788
          opt_values ')'
4200
4789
          {
4201
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4790
            LEX *lex=Lex;
 
4791
            if (lex->many_values.push_back(lex->insert_list))
4202
4792
              DRIZZLE_YYABORT;
4203
4793
          }
4204
4794
        ;
4237
4827
update:
4238
4828
          UPDATE_SYM opt_ignore table_ident
4239
4829
          {
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))
 
4830
            LEX *lex= Lex;
 
4831
            mysql_init_select(lex);
 
4832
            lex->sql_command= SQLCOM_UPDATE;
 
4833
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4834
            if (lex->statement == NULL)
 
4835
              DRIZZLE_YYABORT;
 
4836
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4837
            lex->duplicates= DUP_ERROR;
 
4838
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4245
4839
              DRIZZLE_YYABORT;
4246
4840
          }
4247
 
          SET_SYM update_list
 
4841
          SET update_list
4248
4842
          {
4249
 
            if (Lex->select_lex.get_table_list()->derived)
 
4843
            LEX *lex= Lex;
 
4844
            if (lex->select_lex.get_table_list()->derived)
4250
4845
            {
4251
4846
              /* it is single table update and it is update of derived table */
4252
4847
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4253
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4848
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4254
4849
              DRIZZLE_YYABORT;
4255
4850
            }
4256
4851
            /*
4257
4852
              In case of multi-update setting write lock for all tables may
4258
4853
              be too pessimistic. We will decrease lock level if possible in
4259
 
              multi_update().
 
4854
              mysql_multi_update().
4260
4855
            */
4261
4856
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4262
4857
          }
4269
4864
        ;
4270
4865
 
4271
4866
update_elem:
4272
 
          simple_ident equal expr_or_default
 
4867
          simple_ident_nospvar equal expr_or_default
4273
4868
          {
4274
4869
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4275
4870
              DRIZZLE_YYABORT;
4282
4877
        ;
4283
4878
 
4284
4879
insert_update_elem:
4285
 
          simple_ident equal expr_or_default
 
4880
          simple_ident_nospvar equal expr_or_default
4286
4881
          {
4287
 
          if (Lex->update_list.push_back($1) ||
4288
 
              Lex->value_list.push_back($3))
 
4882
          LEX *lex= Lex;
 
4883
          if (lex->update_list.push_back($1) ||
 
4884
              lex->value_list.push_back($3))
4289
4885
              DRIZZLE_YYABORT;
4290
4886
          }
4291
4887
        ;
4295
4891
delete:
4296
4892
          DELETE_SYM
4297
4893
          {
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();
 
4894
            LEX *lex= Lex;
 
4895
            lex->sql_command= SQLCOM_DELETE;
 
4896
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4897
            if (lex->statement == NULL)
 
4898
              DRIZZLE_YYABORT;
 
4899
            mysql_init_select(lex);
 
4900
            lex->lock_option= TL_WRITE_DEFAULT;
 
4901
            lex->ignore= 0;
 
4902
            lex->select_lex.init_order();
4303
4903
          }
4304
4904
          opt_delete_options single_multi
4305
4905
        ;
4327
4927
truncate:
4328
4928
          TRUNCATE_SYM opt_table_sym table_name
4329
4929
          {
4330
 
            Lex->statement= new statement::Truncate(YYSession);
4331
 
            Lex->select_lex.options= 0;
4332
 
            Lex->select_lex.init_order();
 
4930
            LEX* lex= Lex;
 
4931
            lex->sql_command= SQLCOM_TRUNCATE;
 
4932
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4933
            if (lex->statement == NULL)
 
4934
              DRIZZLE_YYABORT;
 
4935
            lex->select_lex.options= 0;
 
4936
            lex->select_lex.init_order();
4333
4937
          }
4334
4938
        ;
4335
4939
 
4343
4947
show:
4344
4948
          SHOW
4345
4949
          {
4346
 
            Lex->lock_option= TL_READ;
4347
 
            init_select(Lex);
4348
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4950
            LEX *lex=Lex;
 
4951
            lex->wild=0;
 
4952
            lex->lock_option= TL_READ;
 
4953
            mysql_init_select(lex);
 
4954
            lex->current_select->parsing_place= SELECT_LIST;
4349
4955
          }
4350
4956
          show_param
4351
4957
          {}
4355
4961
show_param:
4356
4962
           DATABASES show_wild
4357
4963
           {
4358
 
             if (not show::buildScemas(YYSession))
4359
 
               DRIZZLE_YYABORT;
 
4964
             LEX *lex= Lex;
 
4965
             Session *session= YYSession;
 
4966
 
 
4967
             lex->sql_command= SQLCOM_SELECT;
 
4968
             lex->statement=
 
4969
               new(std::nothrow) statement::Show(session);
 
4970
             if (lex->statement == NULL)
 
4971
               DRIZZLE_YYABORT;
 
4972
 
 
4973
             std::string column_name= "Database";
 
4974
             if (Lex->wild)
 
4975
             {
 
4976
               column_name.append(" (");
 
4977
               column_name.append(Lex->wild->ptr());
 
4978
               column_name.append(")");
 
4979
             }
 
4980
 
 
4981
             if (Lex->current_select->where)
 
4982
             {
 
4983
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
4984
                 DRIZZLE_YYABORT;
 
4985
             }
 
4986
             else
 
4987
             {
 
4988
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
4989
                 DRIZZLE_YYABORT;
 
4990
             }
 
4991
 
 
4992
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4993
             my_field->is_autogenerated_name= false;
 
4994
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4995
 
 
4996
             if (session->add_item_to_list(my_field))
 
4997
               DRIZZLE_YYABORT;
 
4998
 
 
4999
              if (session->add_order_to_list(my_field, true))
 
5000
                DRIZZLE_YYABORT;
4360
5001
           }
4361
5002
           /* SHOW TABLES */
4362
5003
         | TABLES opt_db show_wild
4363
5004
           {
4364
 
             if (not show::buildTables(YYSession, $2))
4365
 
               DRIZZLE_YYABORT;
 
5005
             LEX *lex= Lex;
 
5006
             Session *session= YYSession;
 
5007
 
 
5008
             lex->sql_command= SQLCOM_SELECT;
 
5009
 
 
5010
             statement::Show *select=
 
5011
               new(std::nothrow) statement::Show(YYSession);
 
5012
 
 
5013
             lex->statement= select;
 
5014
 
 
5015
             if (lex->statement == NULL)
 
5016
               DRIZZLE_YYABORT;
 
5017
 
 
5018
 
 
5019
              std::string column_name= "Tables_in_";
 
5020
 
 
5021
              util::string::const_shared_ptr schema(session->schema());
 
5022
              if ($2)
 
5023
              {
 
5024
                SchemaIdentifier identifier($2);
 
5025
                column_name.append($2);
 
5026
                lex->select_lex.db= $2;
 
5027
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
5028
                {
 
5029
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
5030
                }
 
5031
                select->setShowPredicate($2, "");
 
5032
              }
 
5033
              else if (schema and not schema->empty())
 
5034
              {
 
5035
                column_name.append(*schema);
 
5036
                select->setShowPredicate(*schema, "");
 
5037
              }
 
5038
              else
 
5039
              {
 
5040
                my_error(ER_NO_DB_ERROR, MYF(0));
 
5041
                DRIZZLE_YYABORT;
 
5042
              }
 
5043
 
 
5044
 
 
5045
             if (Lex->wild)
 
5046
             {
 
5047
               column_name.append(" (");
 
5048
               column_name.append(Lex->wild->ptr());
 
5049
               column_name.append(")");
 
5050
             }
 
5051
 
 
5052
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
5053
               DRIZZLE_YYABORT;
 
5054
 
 
5055
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5056
             my_field->is_autogenerated_name= false;
 
5057
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
5058
 
 
5059
             if (session->add_item_to_list(my_field))
 
5060
               DRIZZLE_YYABORT;
 
5061
 
 
5062
              if (session->add_order_to_list(my_field, true))
 
5063
                DRIZZLE_YYABORT;
4366
5064
           }
4367
5065
           /* SHOW TEMPORARY TABLES */
4368
5066
         | TEMPORARY_SYM TABLES show_wild
4369
5067
           {
4370
 
             if (not show::buildTemporaryTables(YYSession))
4371
 
               DRIZZLE_YYABORT;
 
5068
             LEX *lex= Lex;
 
5069
             Session *session= YYSession;
 
5070
 
 
5071
             lex->sql_command= SQLCOM_SELECT;
 
5072
 
 
5073
             statement::Show *select=
 
5074
               new(std::nothrow) statement::Show(YYSession);
 
5075
 
 
5076
             lex->statement= select;
 
5077
 
 
5078
             if (lex->statement == NULL)
 
5079
               DRIZZLE_YYABORT;
 
5080
 
 
5081
 
 
5082
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
 
5083
               DRIZZLE_YYABORT;
 
5084
 
 
5085
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5086
                                                           context,
 
5087
                                                           NULL, NULL, "*")))
 
5088
               DRIZZLE_YYABORT;
 
5089
             (session->lex->current_select->with_wild)++;
 
5090
 
4372
5091
           }
4373
5092
           /* SHOW TABLE STATUS */
4374
5093
         | TABLE_SYM STATUS_SYM opt_db show_wild
4375
5094
           {
4376
 
             if (not show::buildTableStatus(YYSession, $3))
4377
 
               DRIZZLE_YYABORT;
 
5095
             LEX *lex= Lex;
 
5096
             lex->sql_command= SQLCOM_SELECT;
 
5097
             statement::Show *select=
 
5098
               new(std::nothrow) statement::Show(YYSession);
 
5099
 
 
5100
             lex->statement= select;
 
5101
 
 
5102
             if (lex->statement == NULL)
 
5103
               DRIZZLE_YYABORT;
 
5104
 
 
5105
             Session *session= YYSession;
 
5106
 
 
5107
             std::string column_name= "Tables_in_";
 
5108
 
 
5109
             util::string::const_shared_ptr schema(session->schema());
 
5110
             if ($3)
 
5111
             {
 
5112
               lex->select_lex.db= $3;
 
5113
 
 
5114
               SchemaIdentifier identifier($3);
 
5115
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
5116
               {
 
5117
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
5118
               }
 
5119
 
 
5120
               select->setShowPredicate($3, "");
 
5121
             }
 
5122
             else if (schema)
 
5123
             {
 
5124
               select->setShowPredicate(*schema, "");
 
5125
             }
 
5126
             else
 
5127
             {
 
5128
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5129
               DRIZZLE_YYABORT;
 
5130
             }
 
5131
 
 
5132
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
5133
               DRIZZLE_YYABORT;
 
5134
 
 
5135
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5136
                                                           context,
 
5137
                                                           NULL, NULL, "*")))
 
5138
               DRIZZLE_YYABORT;
 
5139
             (session->lex->current_select->with_wild)++;
4378
5140
           }
4379
5141
           /* SHOW COLUMNS FROM table_name */
4380
5142
        | COLUMNS from_or_in table_ident opt_db show_wild
4381
 
           {
4382
 
             if (not show::buildColumns(YYSession, $4, $3))
4383
 
               DRIZZLE_YYABORT;
4384
 
           }
 
5143
          {
 
5144
             LEX *lex= Lex;
 
5145
             Session *session= YYSession;
 
5146
             statement::Show *select;
 
5147
 
 
5148
             lex->sql_command= SQLCOM_SELECT;
 
5149
 
 
5150
             select= new(std::nothrow) statement::Show(session);
 
5151
 
 
5152
             lex->statement= select;
 
5153
 
 
5154
             if (lex->statement == NULL)
 
5155
               DRIZZLE_YYABORT;
 
5156
 
 
5157
             util::string::const_shared_ptr schema(session->schema());
 
5158
             if ($4)
 
5159
             {
 
5160
              select->setShowPredicate($4, $3->table.str);
 
5161
             }
 
5162
             else if ($3->db.str)
 
5163
             {
 
5164
              select->setShowPredicate($3->db.str, $3->table.str);
 
5165
             }
 
5166
             else if (schema)
 
5167
             {
 
5168
               select->setShowPredicate(*schema, $3->table.str);
 
5169
             }
 
5170
             else
 
5171
             {
 
5172
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5173
               DRIZZLE_YYABORT;
 
5174
             }
 
5175
 
 
5176
             {
 
5177
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5178
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5179
               {
 
5180
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5181
                            select->getShowSchema().c_str(), 
 
5182
                            $3->table.str);
 
5183
               }
 
5184
             }
 
5185
 
 
5186
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5187
               DRIZZLE_YYABORT;
 
5188
 
 
5189
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5190
                                                           context,
 
5191
                                                           NULL, NULL, "*")))
 
5192
               DRIZZLE_YYABORT;
 
5193
             (session->lex->current_select->with_wild)++;
 
5194
 
 
5195
          }
4385
5196
          /* SHOW INDEXES from table */
4386
5197
        | 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
 
           }
 
5198
          {
 
5199
             LEX *lex= Lex;
 
5200
             Session *session= YYSession;
 
5201
             statement::Show *select;
 
5202
 
 
5203
             lex->sql_command= SQLCOM_SELECT;
 
5204
 
 
5205
             select= new(std::nothrow) statement::Show(session);
 
5206
 
 
5207
             lex->statement= select;
 
5208
 
 
5209
             if (lex->statement == NULL)
 
5210
               DRIZZLE_YYABORT;
 
5211
 
 
5212
             util::string::const_shared_ptr schema(session->schema());
 
5213
             if ($4)
 
5214
             {
 
5215
              select->setShowPredicate($4, $3->table.str);
 
5216
             }
 
5217
             else if ($3->db.str)
 
5218
             {
 
5219
              select->setShowPredicate($3->db.str, $3->table.str);
 
5220
             }
 
5221
             else if (schema)
 
5222
             {
 
5223
               select->setShowPredicate(*schema, $3->table.str);
 
5224
             }
 
5225
             else
 
5226
             {
 
5227
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5228
               DRIZZLE_YYABORT;
 
5229
             }
 
5230
 
 
5231
             {
 
5232
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5233
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5234
               {
 
5235
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5236
                            select->getShowSchema().c_str(), 
 
5237
                            $3->table.str);
 
5238
               }
 
5239
             }
 
5240
 
 
5241
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
5242
               DRIZZLE_YYABORT;
 
5243
 
 
5244
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5245
                                                           context,
 
5246
                                                           NULL, NULL, "*")))
 
5247
               DRIZZLE_YYABORT;
 
5248
             (session->lex->current_select->with_wild)++;
 
5249
          }
4391
5250
        | COUNT_SYM '(' '*' ')' WARNINGS
4392
5251
          {
4393
 
            show::buildSelectWarning(YYSession);
 
5252
            (void) create_select_for_variable("warning_count");
 
5253
            LEX *lex= Lex;
 
5254
            lex->statement= new(std::nothrow) statement::Show(YYSession);
 
5255
            if (lex->statement == NULL)
 
5256
              DRIZZLE_YYABORT;
4394
5257
          }
4395
5258
        | COUNT_SYM '(' '*' ')' ERRORS
4396
5259
          {
4397
 
            show::buildSelectError(YYSession);
 
5260
            (void) create_select_for_variable("error_count");
 
5261
            LEX *lex= Lex;
 
5262
            lex->statement= new(std::nothrow) statement::Show(YYSession);
 
5263
            if (lex->statement == NULL)
 
5264
              DRIZZLE_YYABORT;
4398
5265
          }
4399
5266
        | WARNINGS opt_limit_clause_init
4400
5267
          {
4401
 
            show::buildWarnings(YYSession);
 
5268
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5269
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
5270
            if (Lex->statement == NULL)
 
5271
              DRIZZLE_YYABORT;
4402
5272
          }
4403
5273
        | ERRORS opt_limit_clause_init
4404
5274
          {
4405
 
            show::buildErrors(YYSession);
 
5275
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5276
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
5277
            if (Lex->statement == NULL)
 
5278
              DRIZZLE_YYABORT;
4406
5279
          }
4407
5280
        | 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
 
          }
 
5281
           {
 
5282
             LEX *lex= Lex;
 
5283
             lex->sql_command= SQLCOM_SELECT;
 
5284
             lex->statement=
 
5285
               new(std::nothrow) statement::Show(YYSession);
 
5286
             if (lex->statement == NULL)
 
5287
               DRIZZLE_YYABORT;
 
5288
 
 
5289
             Session *session= YYSession;
 
5290
 
 
5291
             if ($1 == OPT_GLOBAL)
 
5292
             {
 
5293
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5294
                 DRIZZLE_YYABORT;
 
5295
             }
 
5296
             else
 
5297
             {
 
5298
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5299
                 DRIZZLE_YYABORT;
 
5300
             }
 
5301
 
 
5302
             std::string key("Variable_name");
 
5303
             std::string value("Value");
 
5304
 
 
5305
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5306
             my_field->is_autogenerated_name= false;
 
5307
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5308
 
 
5309
             if (session->add_item_to_list(my_field))
 
5310
               DRIZZLE_YYABORT;
 
5311
 
 
5312
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5313
             my_field->is_autogenerated_name= false;
 
5314
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5315
 
 
5316
             if (session->add_item_to_list(my_field))
 
5317
               DRIZZLE_YYABORT;
 
5318
           }
4417
5319
        | CREATE TABLE_SYM table_ident
4418
 
          {
4419
 
            if (not show::buildCreateTable(YYSession, $3))
4420
 
              DRIZZLE_YYABORT;
4421
 
          }
 
5320
           {
 
5321
             LEX *lex= Lex;
 
5322
             lex->sql_command= SQLCOM_SELECT;
 
5323
             statement::Show *select=
 
5324
               new(std::nothrow) statement::Show(YYSession);
 
5325
 
 
5326
             lex->statement= select;
 
5327
 
 
5328
             if (lex->statement == NULL)
 
5329
               DRIZZLE_YYABORT;
 
5330
 
 
5331
             Session *session= YYSession;
 
5332
 
 
5333
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
 
5334
               DRIZZLE_YYABORT;
 
5335
 
 
5336
             util::string::const_shared_ptr schema(session->schema());
 
5337
             if ($3->db.str)
 
5338
             {
 
5339
               select->setShowPredicate($3->db.str, $3->table.str);
 
5340
             }
 
5341
             else if (schema)
 
5342
             {
 
5343
               select->setShowPredicate(*schema, $3->table.str);
 
5344
             }
 
5345
             else
 
5346
             {
 
5347
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5348
               DRIZZLE_YYABORT;
 
5349
             }
 
5350
 
 
5351
             std::string key("Table");
 
5352
             std::string value("Create Table");
 
5353
 
 
5354
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5355
             my_field->is_autogenerated_name= false;
 
5356
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5357
 
 
5358
             if (session->add_item_to_list(my_field))
 
5359
               DRIZZLE_YYABORT;
 
5360
 
 
5361
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5362
             my_field->is_autogenerated_name= false;
 
5363
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5364
 
 
5365
             if (session->add_item_to_list(my_field))
 
5366
               DRIZZLE_YYABORT;
 
5367
           }
4422
5368
        | PROCESSLIST_SYM
4423
5369
          {
4424
 
            if (not show::buildProcesslist(YYSession))
4425
 
              DRIZZLE_YYABORT;
 
5370
           {
 
5371
             LEX *lex= Lex;
 
5372
             lex->sql_command= SQLCOM_SELECT;
 
5373
             lex->statement=
 
5374
               new(std::nothrow) statement::Show(YYSession);
 
5375
             if (lex->statement == NULL)
 
5376
               DRIZZLE_YYABORT;
 
5377
 
 
5378
             Session *session= YYSession;
 
5379
 
 
5380
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
5381
               DRIZZLE_YYABORT;
 
5382
 
 
5383
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5384
                                                           context,
 
5385
                                                           NULL, NULL, "*")))
 
5386
               DRIZZLE_YYABORT;
 
5387
             (session->lex->current_select->with_wild)++;
 
5388
           }
4426
5389
          }
4427
5390
        | opt_var_type  VARIABLES show_wild
4428
 
          {
4429
 
            if (not show::buildVariables(YYSession, $1))
4430
 
              DRIZZLE_YYABORT;
4431
 
          }
 
5391
           {
 
5392
             LEX *lex= Lex;
 
5393
             lex->sql_command= SQLCOM_SELECT;
 
5394
             lex->statement=
 
5395
               new(std::nothrow) statement::Show(YYSession);
 
5396
             if (lex->statement == NULL)
 
5397
               DRIZZLE_YYABORT;
 
5398
 
 
5399
             Session *session= YYSession;
 
5400
 
 
5401
             if ($1 == OPT_GLOBAL)
 
5402
             {
 
5403
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5404
                 DRIZZLE_YYABORT;
 
5405
             }
 
5406
             else
 
5407
             {
 
5408
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5409
                 DRIZZLE_YYABORT;
 
5410
             }
 
5411
 
 
5412
             std::string key("Variable_name");
 
5413
             std::string value("Value");
 
5414
 
 
5415
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5416
             my_field->is_autogenerated_name= false;
 
5417
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5418
 
 
5419
             if (session->add_item_to_list(my_field))
 
5420
               DRIZZLE_YYABORT;
 
5421
 
 
5422
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5423
             my_field->is_autogenerated_name= false;
 
5424
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5425
 
 
5426
             if (session->add_item_to_list(my_field))
 
5427
               DRIZZLE_YYABORT;
 
5428
           }
4432
5429
        | CREATE DATABASE opt_if_not_exists ident
4433
 
          {
4434
 
            if (not show::buildCreateSchema(YYSession, $4))
4435
 
              DRIZZLE_YYABORT;
4436
 
          }
 
5430
           {
 
5431
             LEX *lex= Lex;
 
5432
             lex->sql_command= SQLCOM_SELECT;
 
5433
             statement::Show *select=
 
5434
               new(std::nothrow) statement::Show(YYSession);
 
5435
 
 
5436
             lex->statement= select;
 
5437
 
 
5438
             if (lex->statement == NULL)
 
5439
               DRIZZLE_YYABORT;
 
5440
 
 
5441
             Session *session= YYSession;
 
5442
 
 
5443
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
 
5444
               DRIZZLE_YYABORT;
 
5445
 
 
5446
             util::string::const_shared_ptr schema(session->schema());
 
5447
             if ($4.str)
 
5448
             {
 
5449
              select->setShowPredicate($4.str);
 
5450
             }
 
5451
             else if (schema)
 
5452
             {
 
5453
               select->setShowPredicate(*schema);
 
5454
             }
 
5455
             else
 
5456
             {
 
5457
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5458
               DRIZZLE_YYABORT;
 
5459
             }
 
5460
 
 
5461
             std::string key("Database");
 
5462
             std::string value("Create Database");
 
5463
 
 
5464
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5465
             my_field->is_autogenerated_name= false;
 
5466
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5467
 
 
5468
             if (session->add_item_to_list(my_field))
 
5469
               DRIZZLE_YYABORT;
 
5470
 
 
5471
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5472
             my_field->is_autogenerated_name= false;
 
5473
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5474
 
 
5475
             if (session->add_item_to_list(my_field))
 
5476
               DRIZZLE_YYABORT;
 
5477
           }
4437
5478
 
4438
5479
opt_db:
4439
5480
          /* empty */  { $$= 0; }
4466
5507
describe:
4467
5508
          describe_command table_ident
4468
5509
          {
4469
 
            if (not show::buildDescribe(YYSession, $2))
4470
 
            {
 
5510
            Session *session= YYSession;
 
5511
            statement::Show *select;
 
5512
            LEX *lex= Lex;
 
5513
            lex->lock_option= TL_READ;
 
5514
            mysql_init_select(lex);
 
5515
            lex->current_select->parsing_place= SELECT_LIST;
 
5516
            lex->sql_command= SQLCOM_SELECT;
 
5517
            select= new(std::nothrow) statement::Show(session);
 
5518
            lex->statement= select;
 
5519
            if (lex->statement == NULL)
4471
5520
              DRIZZLE_YYABORT;
4472
 
            }
 
5521
            lex->select_lex.db= 0;
 
5522
 
 
5523
             util::string::const_shared_ptr schema(session->schema());
 
5524
             if ($2->db.str)
 
5525
             {
 
5526
               select->setShowPredicate($2->db.str, $2->table.str);
 
5527
             }
 
5528
             else if (schema)
 
5529
             {
 
5530
               select->setShowPredicate(*schema, $2->table.str);
 
5531
             }
 
5532
             else
 
5533
             {
 
5534
               my_error(ER_NO_DB_ERROR, MYF(0));
 
5535
               DRIZZLE_YYABORT;
 
5536
             }
 
5537
 
 
5538
             {
 
5539
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5540
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5541
               {
 
5542
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5543
                            select->getShowSchema().c_str(), 
 
5544
                            $2->table.str);
 
5545
               }
 
5546
             }
 
5547
 
 
5548
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5549
               DRIZZLE_YYABORT;
 
5550
 
 
5551
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5552
                                                           context,
 
5553
                                                           NULL, NULL, "*")))
 
5554
             {
 
5555
               DRIZZLE_YYABORT;
 
5556
             }
 
5557
             (session->lex->current_select->with_wild)++;
 
5558
 
4473
5559
          }
4474
5560
          opt_describe_column {}
4475
5561
        | describe_command opt_extended_describe
4476
5562
          { Lex->describe|= DESCRIBE_NORMAL; }
4477
5563
          select
4478
5564
          {
4479
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5565
            LEX *lex=Lex;
 
5566
            lex->select_lex.options|= SELECT_DESCRIBE;
4480
5567
          }
4481
5568
        ;
4482
5569
 
4507
5594
flush:
4508
5595
          FLUSH_SYM
4509
5596
          {
4510
 
            Lex->statement= new statement::Flush(YYSession);
 
5597
            LEX *lex=Lex;
 
5598
            lex->sql_command= SQLCOM_FLUSH;
 
5599
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5600
            if (lex->statement == NULL)
 
5601
              DRIZZLE_YYABORT;
 
5602
            lex->type= 0;
4511
5603
          }
4512
5604
          flush_options
4513
5605
          {}
4557
5649
kill:
4558
5650
          KILL_SYM kill_option expr
4559
5651
          {
4560
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5652
            LEX *lex=Lex;
 
5653
 
 
5654
            if ($2)
 
5655
            {
 
5656
              Lex->type= ONLY_KILL_QUERY;
 
5657
            }
 
5658
            else
 
5659
            {
 
5660
              Lex->type= 0;
 
5661
            }
 
5662
 
 
5663
            lex->value_list.empty();
 
5664
            lex->value_list.push_front($3);
 
5665
            lex->sql_command= SQLCOM_KILL;
 
5666
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5667
            if (lex->statement == NULL)
 
5668
              DRIZZLE_YYABORT;
4561
5669
          }
4562
5670
        ;
4563
5671
 
4564
5672
kill_option:
4565
 
          /* empty */ { $$= false; }
4566
 
        | CONNECTION_SYM { $$= false; }
4567
 
        | QUERY_SYM      { $$= true; }
 
5673
          /* empty */ { $$= 0; }
 
5674
        | CONNECTION_SYM { $$= 0; }
 
5675
        | QUERY_SYM      { $$= 1; }
4568
5676
        ;
4569
5677
 
4570
5678
/* change database */
4571
5679
 
4572
5680
use:
4573
 
          USE_SYM schema_name
 
5681
          USE_SYM ident
4574
5682
          {
4575
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4576
 
            Lex->select_lex.db= $2.str;
 
5683
            LEX *lex=Lex;
 
5684
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5685
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5686
            if (lex->statement == NULL)
 
5687
              DRIZZLE_YYABORT;
 
5688
            lex->select_lex.db= $2.str;
4577
5689
          }
4578
5690
        ;
4579
5691
 
4582
5694
load:
4583
5695
          LOAD data_file
4584
5696
          {
4585
 
            statement::Load *statement= new statement::Load(YYSession);
4586
 
            Lex->statement= statement;
4587
 
 
4588
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5697
            Session *session= YYSession;
 
5698
            LEX *lex= session->lex;
 
5699
 
 
5700
            lex->sql_command= SQLCOM_LOAD;
 
5701
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5702
            lex->statement= statement;
 
5703
            if (lex->statement == NULL)
 
5704
              DRIZZLE_YYABORT;
 
5705
 
 
5706
            Lex_input_stream *lip= session->m_lip;
4589
5707
            statement->fname_start= lip->get_ptr();
4590
5708
          }
4591
5709
          load_data_lock INFILE TEXT_STRING_filesystem
4592
5710
          {
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)))
 
5711
            LEX *lex=Lex;
 
5712
            lex->lock_option= $4;
 
5713
            lex->duplicates= DUP_ERROR;
 
5714
            lex->ignore= 0;
 
5715
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4597
5716
              DRIZZLE_YYABORT;
4598
5717
          }
4599
5718
          opt_duplicate INTO
4600
5719
          {
4601
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5720
            Session *session= YYSession;
 
5721
            Lex_input_stream *lip= session->m_lip;
4602
5722
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4603
5723
          }
4604
5724
          TABLE_SYM table_ident
4605
5725
          {
 
5726
            LEX *lex=Lex;
4606
5727
            if (!Lex->current_select->add_table_to_list(YYSession,
4607
5728
                    $12, NULL, TL_OPTION_UPDATING,
4608
 
                    Lex->lock_option))
 
5729
                    lex->lock_option))
4609
5730
              DRIZZLE_YYABORT;
4610
 
            Lex->field_list.empty();
4611
 
            Lex->update_list.empty();
4612
 
            Lex->value_list.empty();
 
5731
            lex->field_list.empty();
 
5732
            lex->update_list.empty();
 
5733
            lex->value_list.empty();
4613
5734
          }
4614
5735
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4615
5736
          opt_load_data_set_spec
4633
5754
        | IGNORE_SYM { Lex->ignore= 1; }
4634
5755
        ;
4635
5756
 
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
5757
opt_field_term:
4646
5758
          /* empty */
4647
5759
        | COLUMNS field_term_list
4660
5772
          }
4661
5773
        | OPTIONALLY ENCLOSED BY text_string
4662
5774
          {
4663
 
            assert(Lex->exchange != 0);
4664
 
            Lex->exchange->enclosed= $4;
4665
 
            Lex->exchange->opt_enclosed= 1;
 
5775
            LEX *lex= Lex;
 
5776
            assert(lex->exchange != 0);
 
5777
            lex->exchange->enclosed= $4;
 
5778
            lex->exchange->opt_enclosed= 1;
4666
5779
          }
4667
5780
        | ENCLOSED BY text_string
4668
5781
          {
4727
5840
        ;
4728
5841
 
4729
5842
field_or_var:
4730
 
          simple_ident {$$= $1;}
4731
 
        | '@' user_variable_ident
 
5843
          simple_ident_nospvar {$$= $1;}
 
5844
        | '@' ident_or_text
4732
5845
          { $$= new Item_user_var_as_out_param($2); }
4733
5846
        ;
4734
5847
 
4735
5848
opt_load_data_set_spec:
4736
5849
          /* empty */ {}
4737
 
        | SET_SYM insert_update_list {}
 
5850
        | SET insert_update_list {}
4738
5851
        ;
4739
5852
 
4740
5853
/* Common definitions */
4742
5855
text_literal:
4743
5856
        TEXT_STRING_literal
4744
5857
        {
4745
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5858
          Session *session= YYSession;
 
5859
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4746
5860
        }
4747
5861
        | text_literal TEXT_STRING_literal
4748
5862
          {
4798
5912
            $$ = new Item_null();
4799
5913
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4800
5914
          }
4801
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4802
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5915
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5916
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4803
5917
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4804
5918
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4805
5919
        | DATE_SYM text_literal { $$ = $2; }
4842
5956
**********************************************************************/
4843
5957
 
4844
5958
insert_ident:
4845
 
          simple_ident { $$=$1; }
 
5959
          simple_ident_nospvar { $$=$1; }
4846
5960
        | table_wild { $$=$1; }
4847
5961
        ;
4848
5962
 
4849
5963
table_wild:
4850
5964
          ident '.' '*'
4851
5965
          {
4852
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5966
            Select_Lex *sel= Lex->current_select;
 
5967
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5968
            sel->with_wild++;
4853
5969
          }
4854
5970
        | ident '.' ident '.' '*'
4855
5971
          {
4856
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5972
            Select_Lex *sel= Lex->current_select;
 
5973
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
5974
            sel->with_wild++;
4857
5975
          }
4858
5976
        ;
4859
5977
 
4864
5982
simple_ident:
4865
5983
          ident
4866
5984
          {
4867
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5985
            {
 
5986
              Select_Lex *sel=Lex->current_select;
 
5987
              $$= (sel->parsing_place != IN_HAVING ||
 
5988
                  sel->get_in_sum_expr() > 0) ?
 
5989
                  (Item*) new Item_field(Lex->current_context(),
 
5990
                                         (const char *)NULL, NULL, $1.str) :
 
5991
                  (Item*) new Item_ref(Lex->current_context(),
 
5992
                                       (const char *)NULL, NULL, $1.str);
 
5993
            }
 
5994
          }
 
5995
        | simple_ident_q { $$= $1; }
 
5996
        ;
 
5997
 
 
5998
simple_ident_nospvar:
 
5999
          ident
 
6000
          {
 
6001
            Select_Lex *sel=Lex->current_select;
 
6002
            $$= (sel->parsing_place != IN_HAVING ||
 
6003
                sel->get_in_sum_expr() > 0) ?
 
6004
                (Item*) new Item_field(Lex->current_context(),
 
6005
                                       (const char *)NULL, NULL, $1.str) :
 
6006
                (Item*) new Item_ref(Lex->current_context(),
 
6007
                                     (const char *)NULL, NULL, $1.str);
4868
6008
          }
4869
6009
        | simple_ident_q { $$= $1; }
4870
6010
        ;
4872
6012
simple_ident_q:
4873
6013
          ident '.' ident
4874
6014
          {
4875
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
6015
            Session *session= YYSession;
 
6016
            LEX *lex= session->lex;
 
6017
 
 
6018
            {
 
6019
              Select_Lex *sel= lex->current_select;
 
6020
              if (sel->no_table_names_allowed)
 
6021
              {
 
6022
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6023
                         MYF(0), $1.str, session->where);
 
6024
              }
 
6025
              $$= (sel->parsing_place != IN_HAVING ||
 
6026
                  sel->get_in_sum_expr() > 0) ?
 
6027
                  (Item*) new Item_field(Lex->current_context(),
 
6028
                                         (const char *)NULL, $1.str, $3.str) :
 
6029
                  (Item*) new Item_ref(Lex->current_context(),
 
6030
                                       (const char *)NULL, $1.str, $3.str);
 
6031
            }
4876
6032
          }
4877
6033
        | '.' ident '.' ident
4878
6034
          {
4879
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
6035
            Session *session= YYSession;
 
6036
            LEX *lex= session->lex;
 
6037
            Select_Lex *sel= lex->current_select;
 
6038
            if (sel->no_table_names_allowed)
 
6039
            {
 
6040
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6041
                       MYF(0), $2.str, session->where);
 
6042
            }
 
6043
            $$= (sel->parsing_place != IN_HAVING ||
 
6044
                sel->get_in_sum_expr() > 0) ?
 
6045
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
6046
                (Item*) new Item_ref(Lex->current_context(),
 
6047
                                     (const char *)NULL, $2.str, $4.str);
4880
6048
          }
4881
6049
        | ident '.' ident '.' ident
4882
6050
          {
4883
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
6051
            Session *session= YYSession;
 
6052
            LEX *lex= session->lex;
 
6053
            Select_Lex *sel= lex->current_select;
 
6054
            if (sel->no_table_names_allowed)
 
6055
            {
 
6056
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6057
                       MYF(0), $3.str, session->where);
 
6058
            }
 
6059
            $$= (sel->parsing_place != IN_HAVING ||
 
6060
                sel->get_in_sum_expr() > 0) ?
 
6061
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
6062
                                       $5.str) :
 
6063
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
6064
                                     $5.str);
4884
6065
          }
4885
6066
        ;
4886
6067
 
4887
6068
field_ident:
4888
 
          ident 
4889
 
          {
4890
 
            $$=$1;
4891
 
          }
 
6069
          ident { $$=$1;}
4892
6070
        | ident '.' ident '.' ident
4893
6071
          {
4894
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4895
 
              DRIZZLE_YYABORT;
4896
 
 
 
6072
            TableList *table=
 
6073
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
6074
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
 
6075
            {
 
6076
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
6077
              DRIZZLE_YYABORT;
 
6078
            }
 
6079
            if (my_strcasecmp(table_alias_charset, $3.str,
 
6080
                              table->getTableName()))
 
6081
            {
 
6082
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
6083
              DRIZZLE_YYABORT;
 
6084
            }
4897
6085
            $$=$5;
4898
6086
          }
4899
6087
        | ident '.' ident
4900
6088
          {
4901
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
6089
            TableList *table=
 
6090
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
6091
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
6092
            {
 
6093
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6094
              DRIZZLE_YYABORT;
4903
 
 
 
6095
            }
4904
6096
            $$=$3;
4905
6097
          }
4906
 
        | '.' ident 
4907
 
          { /* For Delphi */
4908
 
            $$=$2;
4909
 
          }
 
6098
        | '.' ident { $$=$2;} /* For Delphi */
4910
6099
        ;
4911
6100
 
4912
6101
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
 
6102
          ident { $$=new Table_ident($1); }
 
6103
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
6104
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4933
6105
        ;
4934
6106
 
4935
6107
IDENT_sys:
4936
 
          IDENT 
4937
 
          {
4938
 
            $$= $1;
4939
 
          }
 
6108
          IDENT { $$= $1; }
4940
6109
        | IDENT_QUOTED
4941
6110
          {
4942
6111
            const CHARSET_INFO * const cs= system_charset_info;
4979
6148
          IDENT_sys    { $$=$1; }
4980
6149
        | keyword
4981
6150
          {
4982
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
6151
            Session *session= YYSession;
 
6152
            $$.str= session->strmake($1.str, $1.length);
4983
6153
            $$.length= $1.length;
4984
6154
          }
4985
6155
        ;
4986
6156
 
4987
6157
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          {}
 
6158
          ident           { $$=$1;}
 
6159
        | TEXT_STRING_sys { $$=$1;}
 
6160
        | LEX_HOSTNAME { $$=$1;}
5001
6161
        ;
5002
6162
 
5003
6163
/* Keyword that we allow for identifiers (except SP labels) */
5004
6164
keyword:
5005
6165
          keyword_sp            {}
5006
6166
        | BEGIN_SYM             {}
 
6167
        | BYTE_SYM              {}
5007
6168
        | CHECKSUM_SYM          {}
5008
6169
        | CLOSE_SYM             {}
5009
6170
        | COMMENT_SYM           {}
5010
6171
        | COMMIT_SYM            {}
5011
6172
        | CONTAINS_SYM          {}
5012
6173
        | DEALLOCATE_SYM        {}
5013
 
        | DO_SYM                {}
5014
6174
        | END                   {}
5015
6175
        | FLUSH_SYM             {}
5016
6176
        | NO_SYM                {}
5019
6179
        | SAVEPOINT_SYM         {}
5020
6180
        | SECURITY_SYM          {}
5021
6181
        | SERVER_SYM            {}
5022
 
        | SIGNED_SYM            {}
5023
6182
        | START_SYM             {}
5024
6183
        | STOP_SYM              {}
5025
6184
        | TRUNCATE_SYM          {}
5039
6198
        | ANY_SYM                  {}
5040
6199
        | AT_SYM                   {}
5041
6200
        | AUTO_INC                 {}
 
6201
        | AVG_ROW_LENGTH           {}
5042
6202
        | AVG_SYM                  {}
5043
6203
        | BIT_SYM                  {}
5044
6204
        | BOOL_SYM                 {}
5048
6208
        | CHAIN_SYM                {}
5049
6209
        | COALESCE                 {}
5050
6210
        | COLLATION_SYM            {}
 
6211
        | COLUMN_FORMAT_SYM        {}
5051
6212
        | COLUMNS                  {}
5052
6213
        | COMMITTED_SYM            {}
5053
6214
        | COMPACT_SYM              {}
5054
6215
        | COMPRESSED_SYM           {}
5055
6216
        | CONCURRENT               {}
5056
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
6217
        | CONNECTION_SYM           {}
5057
6218
        | CONSISTENT_SYM           {}
5058
6219
        | CUBE_SYM                 {}
5059
6220
        | DATA_SYM                 {}
5060
6221
        | DATABASES                {}
 
6222
        | DATAFILE_SYM             {}
5061
6223
        | DATETIME_SYM             {}
5062
 
        | DATE_SYM                 {} /* Create conflict */
 
6224
        | DATE_SYM                 {}
5063
6225
        | DAY_SYM                  {}
5064
6226
        | DISABLE_SYM              {}
5065
6227
        | DISCARD                  {}
5090
6252
        | KEY_BLOCK_SIZE           {}
5091
6253
        | LAST_SYM                 {}
5092
6254
        | LEVEL_SYM                {}
 
6255
        | LIST_SYM                 {}
5093
6256
        | LOCAL_SYM                {}
5094
6257
        | LOCKS_SYM                {}
5095
6258
        | LOGS_SYM                 {}
 
6259
        | MAX_ROWS                 {}
 
6260
        | MAX_SIZE_SYM             {}
5096
6261
        | MAX_VALUE_SYM            {}
5097
6262
        | MEDIUM_SYM               {}
5098
6263
        | MERGE_SYM                {}
5099
6264
        | MICROSECOND_SYM          {}
5100
6265
        | MINUTE_SYM               {}
 
6266
        | MIN_ROWS                 {}
5101
6267
        | MODIFY_SYM               {}
5102
6268
        | MODE_SYM                 {}
5103
6269
        | MONTH_SYM                {}
5112
6278
        | ONE_SHOT_SYM             {}
5113
6279
        | ONE_SYM                  {}
5114
6280
        | ONLINE_SYM               {}
 
6281
        | PAGE_SYM                 {}
5115
6282
        | PARTIAL                  {}
 
6283
        | PHASE_SYM                {}
5116
6284
        | PREV_SYM                 {}
5117
6285
        | PROCESS                  {}
5118
6286
        | PROCESSLIST_SYM          {}
5119
6287
        | QUARTER_SYM              {}
5120
 
        | QUERY_SYM                {} // Causes conflict
 
6288
        | QUERY_SYM                {}
 
6289
        | READ_ONLY_SYM            {}
5121
6290
        | REDUNDANT_SYM            {}
5122
6291
        | REPEATABLE_SYM           {}
5123
6292
        | RETURNS_SYM              {}
 
6293
        | REVERSE_SYM              {}
5124
6294
        | ROLLUP_SYM               {}
5125
6295
        | ROUTINE_SYM              {}
5126
6296
        | ROWS_SYM                 {}
5133
6303
        | SIMPLE_SYM               {}
5134
6304
        | SHARE_SYM                {}
5135
6305
        | SNAPSHOT_SYM             {}
 
6306
        | SQL_BUFFER_RESULT        {}
5136
6307
        | STATUS_SYM               {}
 
6308
        | STORAGE_SYM              {}
5137
6309
        | STRING_SYM               {}
5138
6310
        | SUBDATE_SYM              {}
5139
6311
        | SUBJECT_SYM              {}
5140
6312
        | SUSPEND_SYM              {}
 
6313
        | SWAPS_SYM                {}
 
6314
        | SWITCHES_SYM             {}
5141
6315
        | TABLES                   {}
5142
6316
        | TABLESPACE               {}
5143
6317
        | TEMPORARY_SYM            {}
5144
6318
        | TEXT_SYM                 {}
5145
6319
        | TRANSACTION_SYM          {}
5146
6320
        | TIME_SYM                 {}
 
6321
        | TIMESTAMP_SYM            {}
5147
6322
        | TIMESTAMP_ADD            {}
5148
6323
        | TIMESTAMP_DIFF           {}
 
6324
        | TYPES_SYM                {}
5149
6325
        | TYPE_SYM                 {}
5150
6326
        | UNCOMMITTED_SYM          {}
5151
6327
        | UNDOFILE_SYM             {}
5152
6328
        | UNKNOWN_SYM              {}
5153
 
        | UUID_SYM                 {}
5154
6329
        | USER                     {}
5155
6330
        | VARIABLES                {}
5156
6331
        | VALUE_SYM                {}
5163
6338
/* Option functions */
5164
6339
 
5165
6340
set:
5166
 
          SET_SYM opt_option
 
6341
          SET opt_option
5167
6342
          {
5168
 
            Lex->statement= new statement::SetOption(YYSession);
 
6343
            LEX *lex=Lex;
 
6344
            lex->sql_command= SQLCOM_SET_OPTION;
 
6345
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
6346
            lex->statement= statement;
 
6347
            if (lex->statement == NULL)
 
6348
              DRIZZLE_YYABORT;
 
6349
            mysql_init_select(lex);
 
6350
            lex->option_type=OPT_SESSION;
 
6351
            lex->var_list.empty();
5169
6352
          }
5170
6353
          option_value_list
5171
6354
          {}
5182
6365
        ;
5183
6366
 
5184
6367
option_type_value:
5185
 
          { }
 
6368
          {
 
6369
          }
5186
6370
          ext_option_value
5187
 
          { }
 
6371
          {
 
6372
          }
5188
6373
        ;
5189
6374
 
5190
6375
option_type:
5221
6406
sys_option_value:
5222
6407
          option_type internal_variable_name equal set_expr_or_default
5223
6408
          {
 
6409
            LEX *lex=Lex;
 
6410
 
5224
6411
            if ($2.var)
5225
6412
            { /* System variable */
5226
6413
              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)));
 
6414
                lex->option_type= $1;
 
6415
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6416
                                      &$2.base_name, $4));
5231
6417
            }
5232
6418
          }
5233
6419
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5234
6420
          {
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))));
 
6421
            LEX *lex=Lex;
 
6422
            lex->option_type= $1;
 
6423
            lex->var_list.push_back(new set_var(lex->option_type,
 
6424
                                                find_sys_var("tx_isolation"),
 
6425
                                                &null_lex_str,
 
6426
                                                new Item_int((int32_t) $5)));
5241
6427
          }
5242
6428
        ;
5243
6429
 
5244
6430
option_value:
5245
 
          '@' user_variable_ident equal expr
 
6431
          '@' ident_or_text equal expr
5246
6432
          {
5247
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6433
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5248
6434
          }
5249
6435
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5250
6436
          {
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; }
 
6437
            LEX *lex=Lex;
 
6438
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6439
          }
5268
6440
        ;
5269
6441
 
5270
6442
internal_variable_name:
5271
 
          internal_variable_ident
 
6443
          ident
5272
6444
          {
5273
6445
            /* We have to lookup here since local vars can shadow sysvars */
5274
6446
            {
5275
6447
              /* Not an SP local variable */
5276
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6448
              sys_var *tmp=find_sys_var($1.str, $1.length);
5277
6449
              if (!tmp)
5278
6450
                DRIZZLE_YYABORT;
5279
6451
              $$.var= tmp;
5305
6477
unlock:
5306
6478
          UNLOCK_SYM
5307
6479
          {
5308
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6480
            LEX *lex= Lex;
 
6481
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6482
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6483
            if (lex->statement == NULL)
 
6484
              DRIZZLE_YYABORT;
5309
6485
          }
5310
6486
          table_or_tables
5311
6487
          {}
5314
6490
begin:
5315
6491
          BEGIN_SYM
5316
6492
          {
5317
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6493
            LEX *lex=Lex;
 
6494
            lex->sql_command = SQLCOM_BEGIN;
 
6495
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6496
            if (lex->statement == NULL)
 
6497
              DRIZZLE_YYABORT;
5318
6498
          }
5319
6499
          opt_work {}
5320
6500
        ;
5346
6526
commit:
5347
6527
          COMMIT_SYM opt_work opt_chain opt_release
5348
6528
          {
5349
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6529
            LEX *lex=Lex;
 
6530
            lex->sql_command= SQLCOM_COMMIT;
 
6531
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6532
            lex->statement= statement;
 
6533
            if (lex->statement == NULL)
 
6534
              DRIZZLE_YYABORT;
 
6535
            statement->tx_chain= $3;
 
6536
            statement->tx_release= $4;
5350
6537
          }
5351
6538
        ;
5352
6539
 
5353
6540
rollback:
5354
6541
          ROLLBACK_SYM opt_work opt_chain opt_release
5355
6542
          {
5356
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6543
            LEX *lex=Lex;
 
6544
            lex->sql_command= SQLCOM_ROLLBACK;
 
6545
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6546
            lex->statement= statement;
 
6547
            if (lex->statement == NULL)
 
6548
              DRIZZLE_YYABORT;
 
6549
            statement->tx_chain= $3;
 
6550
            statement->tx_release= $4;
5357
6551
          }
5358
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6552
        | ROLLBACK_SYM opt_work
 
6553
          TO_SYM opt_savepoint ident
5359
6554
          {
5360
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6555
            LEX *lex=Lex;
 
6556
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6557
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6558
            if (lex->statement == NULL)
 
6559
              DRIZZLE_YYABORT;
 
6560
            lex->ident= $5;
5361
6561
          }
5362
6562
        ;
5363
6563
 
5364
6564
savepoint:
5365
 
          SAVEPOINT_SYM savepoint_ident
 
6565
          SAVEPOINT_SYM ident
5366
6566
          {
5367
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6567
            LEX *lex=Lex;
 
6568
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6569
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6570
            if (lex->statement == NULL)
 
6571
              DRIZZLE_YYABORT;
 
6572
            lex->ident= $2;
5368
6573
          }
5369
6574
        ;
5370
6575
 
5371
6576
release:
5372
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6577
          RELEASE_SYM SAVEPOINT_SYM ident
5373
6578
          {
5374
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6579
            LEX *lex=Lex;
 
6580
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6581
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6582
            if (lex->statement == NULL)
 
6583
              DRIZZLE_YYABORT;
 
6584
            lex->ident= $3;
5375
6585
          }
5376
6586
        ;
5377
6587
 
5378
 
savepoint_ident:
5379
 
               IDENT_sys
5380
 
               ;
5381
 
 
5382
6588
/*
5383
6589
   UNIONS : glue selects together
5384
6590
*/
5392
6598
union_list:
5393
6599
          UNION_SYM union_option
5394
6600
          {
5395
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6601
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5396
6602
              DRIZZLE_YYABORT;
5397
6603
          }
5398
6604
          select_init
5413
6619
 
5414
6620
union_order_or_limit:
5415
6621
          {
5416
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5417
 
            Select_Lex *sel= Lex->current_select;
 
6622
            Session *session= YYSession;
 
6623
            LEX *lex= session->lex;
 
6624
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6625
            Select_Lex *sel= lex->current_select;
5418
6626
            Select_Lex_Unit *unit= sel->master_unit();
5419
6627
            Select_Lex *fake= unit->fake_select_lex;
5420
6628
            if (fake)
5421
6629
            {
5422
6630
              unit->global_parameters= fake;
5423
6631
              fake->no_table_names_allowed= 1;
5424
 
              Lex->current_select= fake;
 
6632
              lex->current_select= fake;
5425
6633
            }
5426
 
            YYSession->setWhere("global ORDER clause");
 
6634
            session->where= "global ORDER clause";
5427
6635
          }
5428
6636
          order_or_limit
5429
6637
          {
5430
 
            YYSession->lex->current_select->no_table_names_allowed= 0;
5431
 
            YYSession->setWhere("");
 
6638
            Session *session= YYSession;
 
6639
            session->lex->current_select->no_table_names_allowed= 0;
 
6640
            session->where= "";
5432
6641
          }
5433
6642
        ;
5434
6643
 
5459
6668
        | query_expression_body
5460
6669
          UNION_SYM union_option
5461
6670
          {
5462
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6671
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5463
6672
              DRIZZLE_YYABORT;
5464
6673
          }
5465
6674
          query_specification
5479
6688
 
5480
6689
subselect_start:
5481
6690
          {
5482
 
            if (not Lex->expr_allows_subselect)
 
6691
            LEX *lex=Lex;
 
6692
            if (!lex->expr_allows_subselect)
5483
6693
            {
5484
 
              parser::my_parse_error(YYSession->m_lip);
 
6694
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6695
              my_parse_error(&pass);
5485
6696
              DRIZZLE_YYABORT;
5486
6697
            }
5487
6698
            /*
5491
6702
              (SELECT .. ) UNION ...  becomes
5492
6703
              SELECT * FROM ((SELECT ...) UNION ...)
5493
6704
            */
5494
 
            if (new_select(Lex, 1))
 
6705
            if (mysql_new_select(Lex, 1))
5495
6706
              DRIZZLE_YYABORT;
5496
6707
          }
5497
6708
        ;
5498
6709
 
5499
6710
subselect_end:
5500
6711
          {
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;
 
6712
            LEX *lex=Lex;
 
6713
            lex->pop_context();
 
6714
            Select_Lex *child= lex->current_select;
 
6715
            lex->current_select = lex->current_select->return_after_parsing();
 
6716
            lex->nest_level--;
 
6717
            lex->current_select->n_child_sum_items += child->n_sum_items;
5506
6718
            /*
5507
6719
              A subselect can add fields to an outer select. Reserve space for
5508
6720
              them.
5509
6721
            */
5510
 
            Lex->current_select->select_n_where_fields+=
 
6722
            lex->current_select->select_n_where_fields+=
5511
6723
            child->select_n_where_fields;
5512
6724
          }
5513
6725
        ;