~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

Fix pidfile argument.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* sql_yacc.yy */
17
17
 
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
 
  drizzled::execute_string_t execute_string;
159
376
}
160
377
 
161
378
%{
162
379
namespace drizzled
163
380
{
164
 
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
 
381
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
165
382
}
166
383
%}
167
384
 
168
 
%debug
169
385
%pure_parser                                    /* We have threads */
170
 
 
171
386
/*
172
 
  Currently there are 70 shift/reduce conflicts.
 
387
  Currently there are 88 shift/reduce conflicts.
173
388
  We should not introduce new conflicts any more.
174
389
*/
175
 
%expect 70
 
390
%expect 94
176
391
 
177
392
/*
178
393
   Comments for TOKENS.
193
408
 
194
409
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
195
410
%token  ACTION                        /* SQL-2003-N */
196
 
%token  ADD_SYM                           /* SQL-2003-R */
 
411
%token  ADD                           /* SQL-2003-R */
197
412
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
198
413
%token  AFTER_SYM                     /* SQL-2003-N */
199
414
%token  AGGREGATE_SYM
200
415
%token  ALL                           /* SQL-2003-R */
201
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
416
%token  ALTER                         /* SQL-2003-R */
202
417
%token  ANALYZE_SYM
203
418
%token  AND_SYM                       /* SQL-2003-R */
204
419
%token  ANY_SYM                       /* SQL-2003-R */
207
422
%token  ASENSITIVE_SYM                /* FUTURE-USE */
208
423
%token  AT_SYM                        /* SQL-2003-R */
209
424
%token  AUTO_INC
 
425
%token  AVG_ROW_LENGTH
210
426
%token  AVG_SYM                       /* SQL-2003-N */
211
427
%token  BEFORE_SYM                    /* SQL-2003-N */
212
428
%token  BEGIN_SYM                     /* SQL-2003-R */
221
437
%token  BOTH                          /* SQL-2003-R */
222
438
%token  BTREE_SYM
223
439
%token  BY                            /* SQL-2003-R */
 
440
%token  BYTE_SYM
224
441
%token  CALL_SYM                      /* SQL-2003-R */
225
442
%token  CASCADE                       /* SQL-2003-N */
226
443
%token  CASCADED                      /* SQL-2003-R */
227
444
%token  CASE_SYM                      /* SQL-2003-R */
228
445
%token  CAST_SYM                      /* SQL-2003-R */
229
 
%token  CATALOG_SYM
230
446
%token  CHAIN_SYM                     /* SQL-2003-N */
231
 
%token  CHANGE_SYM
 
447
%token  CHANGE
232
448
%token  CHAR_SYM                      /* SQL-2003-R */
233
449
%token  CHECKSUM_SYM
234
450
%token  CHECK_SYM                     /* SQL-2003-R */
249
465
%token  CONSISTENT_SYM
250
466
%token  CONSTRAINT                    /* SQL-2003-R */
251
467
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
468
%token  CONTINUE_SYM                  /* SQL-2003-R */
252
469
%token  CONVERT_SYM                   /* SQL-2003-N */
253
470
%token  COUNT_SYM                     /* SQL-2003-N */
254
471
%token  CREATE                        /* SQL-2003-R */
259
476
%token  CURSOR_SYM                    /* SQL-2003-R */
260
477
%token  DATABASE
261
478
%token  DATABASES
 
479
%token  DATAFILE_SYM
262
480
%token  DATA_SYM                      /* SQL-2003-N */
263
481
%token  DATETIME_SYM
264
482
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
282
500
%token  DISCARD
283
501
%token  DISTINCT                      /* SQL-2003-R */
284
502
%token  DIV_SYM
285
 
%token  DO_SYM
286
503
%token  DOUBLE_SYM                    /* SQL-2003-R */
287
504
%token  DROP                          /* SQL-2003-R */
288
505
%token  DUMPFILE
290
507
%token  DYNAMIC_SYM                   /* SQL-2003-R */
291
508
%token  EACH_SYM                      /* SQL-2003-R */
292
509
%token  ELSE                          /* SQL-2003-R */
 
510
%token  ELSEIF_SYM
293
511
%token  ENABLE_SYM
294
512
%token  ENCLOSED
295
513
%token  END                           /* SQL-2003-R */
303
521
%token  ESCAPED
304
522
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
523
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
307
524
%token  EXISTS                        /* SQL-2003-R */
308
525
%token  EXTENDED_SYM
309
526
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
527
%token  FALSE_SYM                     /* SQL-2003-R */
 
528
%token  FETCH_SYM                     /* SQL-2003-R */
 
529
%token  COLUMN_FORMAT_SYM
311
530
%token  FILE_SYM
312
531
%token  FIRST_SYM                     /* SQL-2003-N */
313
532
%token  FIXED_SYM
334
553
%token  HOUR_SYM                      /* SQL-2003-R */
335
554
%token  IDENT
336
555
%token  IDENTIFIED_SYM
337
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
338
556
%token  IDENT_QUOTED
339
557
%token  IF
340
558
%token  IGNORE_SYM
367
585
%token  LIKE                          /* SQL-2003-R */
368
586
%token  LIMIT
369
587
%token  LINES
 
588
%token  LIST_SYM
370
589
%token  LOAD
371
590
%token  LOCAL_SYM                     /* SQL-2003-R */
 
591
%token  LOCATOR_SYM                   /* SQL-2003-N */
372
592
%token  LOCKS_SYM
373
593
%token  LOCK_SYM
374
594
%token  LOGS_SYM
375
595
%token  LONG_NUM
376
596
%token  LONG_SYM
 
597
%token  LOOP_SYM
377
598
%token  LT                            /* OPERATOR */
378
599
%token  MATCH                         /* SQL-2003-R */
 
600
%token  MAX_ROWS
 
601
%token  MAX_SIZE_SYM
379
602
%token  MAX_SYM                       /* SQL-2003-N */
380
603
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
381
604
%token  MEDIUM_SYM
384
607
%token  MINUTE_MICROSECOND_SYM
385
608
%token  MINUTE_SECOND_SYM
386
609
%token  MINUTE_SYM                    /* SQL-2003-R */
 
610
%token  MIN_ROWS
387
611
%token  MIN_SYM                       /* SQL-2003-N */
388
612
%token  MODE_SYM
389
613
%token  MODIFIES_SYM                  /* SQL-2003-R */
420
644
%token  OUTER
421
645
%token  OUTFILE
422
646
%token  OUT_SYM                       /* SQL-2003-R */
 
647
%token  PAGE_SYM
423
648
%token  PARTIAL                       /* SQL-2003-N */
 
649
%token  PHASE_SYM
424
650
%token  POSITION_SYM                  /* SQL-2003-N */
425
651
%token  PRECISION                     /* SQL-2003-R */
426
652
%token  PREV_SYM
431
657
%token  QUERY_SYM
432
658
%token  RANGE_SYM                     /* SQL-2003-R */
433
659
%token  READS_SYM                     /* SQL-2003-R */
 
660
%token  READ_ONLY_SYM
434
661
%token  READ_SYM                      /* SQL-2003-N */
435
662
%token  READ_WRITE_SYM
436
663
%token  REAL                          /* SQL-2003-R */
437
664
%token  REDUNDANT_SYM
438
 
%token  REGEXP_SYM
439
665
%token  REFERENCES                    /* SQL-2003-R */
440
666
%token  RELEASE_SYM                   /* SQL-2003-R */
441
667
%token  RENAME
445
671
%token  RESTRICT
446
672
%token  RETURNS_SYM                   /* SQL-2003-R */
447
673
%token  RETURN_SYM                    /* SQL-2003-R */
 
674
%token  REVERSE_SYM
448
675
%token  REVOKE                        /* SQL-2003-R */
449
676
%token  RIGHT                         /* SQL-2003-R */
450
677
%token  ROLLBACK_SYM                  /* SQL-2003-R */
464
691
%token  SERIAL_SYM
465
692
%token  SESSION_SYM                   /* SQL-2003-N */
466
693
%token  SERVER_SYM
467
 
%token  SET_SYM                           /* SQL-2003-R */
 
694
%token  SERVER_OPTIONS
 
695
%token  SET                           /* SQL-2003-R */
468
696
%token  SET_VAR
469
697
%token  SHARE_SYM
470
698
%token  SHOW
471
 
%token  SIGNED_SYM
472
699
%token  SIMPLE_SYM                    /* SQL-2003-N */
473
700
%token  SNAPSHOT_SYM
474
701
%token  SPECIFIC_SYM                  /* SQL-2003-R */
486
713
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
487
714
%token  STD_SYM
488
715
%token  STOP_SYM
 
716
%token  STORAGE_SYM
489
717
%token  STORED_SYM
490
718
%token  STRAIGHT_JOIN
491
719
%token  STRING_SYM
494
722
%token  SUBSTRING                     /* SQL-2003-N */
495
723
%token  SUM_SYM                       /* SQL-2003-N */
496
724
%token  SUSPEND_SYM
 
725
%token  SWAPS_SYM
 
726
%token  SWITCHES_SYM
497
727
%token  SYSDATE
498
728
%token  TABLES
499
729
%token  TABLESPACE
504
734
%token  TEXT_STRING
505
735
%token  TEXT_SYM
506
736
%token  THEN_SYM                      /* SQL-2003-R */
507
 
%token  TIME_SYM                 /* SQL-2003-R */
508
737
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
509
738
%token  TIMESTAMP_ADD
510
739
%token  TIMESTAMP_DIFF
514
743
%token  TRIM                          /* SQL-2003-N */
515
744
%token  TRUE_SYM                      /* SQL-2003-R */
516
745
%token  TRUNCATE_SYM
 
746
%token  TYPES_SYM
517
747
%token  TYPE_SYM                      /* SQL-2003-N */
518
748
%token  ULONGLONG_NUM
519
749
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
523
753
%token  UNIQUE_SYM
524
754
%token  UNKNOWN_SYM                   /* SQL-2003-R */
525
755
%token  UNLOCK_SYM
526
 
%token  UNSIGNED_SYM
527
756
%token  UPDATE_SYM                    /* SQL-2003-R */
528
757
%token  USAGE                         /* SQL-2003-N */
529
758
%token  USER                          /* SQL-2003-R */
531
760
%token  USING                         /* SQL-2003-R */
532
761
%token  UTC_DATE_SYM
533
762
%token  UTC_TIMESTAMP_SYM
534
 
%token  UUID_SYM
535
763
%token  VALUES                        /* SQL-2003-R */
536
764
%token  VALUE_SYM                     /* SQL-2003-R */
537
765
%token  VARBINARY
540
768
%token  VARIANCE_SYM
541
769
%token  VARYING                       /* SQL-2003-R */
542
770
%token  VAR_SAMP_SYM
543
 
%token  WAIT_SYM
544
771
%token  WARNINGS
545
772
%token  WEEK_SYM
546
773
%token  WHEN_SYM                      /* SQL-2003-R */
552
779
%token  XOR
553
780
%token  YEAR_MONTH_SYM
554
781
%token  YEAR_SYM                      /* SQL-2003-R */
555
 
%token  ZEROFILL_SYM
556
782
 
557
783
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
558
784
/* A dummy token to force the priority of table_ref production in a join. */
562
788
%left   XOR
563
789
%left   AND_SYM
564
790
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
565
 
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP_SYM IN_SYM
 
791
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
566
792
%left   '-' '+'
567
793
%left   '*' '/' '%' DIV_SYM MOD_SYM
568
794
%left   NEG
572
798
 
573
799
%type <lex_str>
574
800
        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
 
801
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
581
802
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
582
 
        schema_name
583
 
        catalog_name
584
803
        opt_component
585
 
        engine_option_value
586
 
        savepoint_ident
587
 
        BIN_NUM TEXT_STRING_filesystem
 
804
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
588
805
        opt_constraint constraint opt_ident
589
806
 
590
 
%type <execute_string>
591
 
        execute_var_or_string
592
 
 
593
807
%type <lex_str_ptr>
594
808
        opt_table_alias
595
809
 
602
816
%type <string>
603
817
        text_string opt_gconcat_separator
604
818
 
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
 
819
%type <num>
 
820
        type int_type real_type order_dir field_def
 
821
        if_exists opt_table_options
615
822
        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
 
823
        opt_temporary all_or_any opt_distinct
625
824
        union_option
626
825
        start_transaction_opts opt_chain opt_release
627
826
        union_opt select_derived_init option_type2
628
 
        kill_option
629
827
 
630
828
%type <m_fk_option>
631
829
        delete_option
647
845
        table_wild simple_expr udf_expr
648
846
        expr_or_default set_expr_or_default
649
847
        signed_literal now_or_signed_literal opt_escape
650
 
        simple_ident_q
 
848
        simple_ident_nospvar simple_ident_q
651
849
        field_or_var limit_option
652
850
        function_call_keyword
653
851
        function_call_nonkeyword
687
885
 
688
886
%type <interval_time_st> interval_time_stamp
689
887
 
 
888
%type <column_format_type> column_format_types
 
889
 
690
890
%type <tx_isolation> isolation_types
691
891
 
692
892
%type <cast_type> cast_type
693
893
 
694
 
%type <symbol>
695
 
        keyword
696
 
        keyword_sp
697
 
        keyword_exception_for_variable
698
 
        row_format
 
894
%type <symbol> keyword keyword_sp
699
895
 
700
896
%type <charset>
701
897
        collation_name
730
926
        flush_options flush_option
731
927
        equal optional_braces
732
928
        normal_join
733
 
        table_to_table_list table_to_table opt_table_list
 
929
        table_to_table_list table_to_table opt_table_list opt_as
734
930
        single_multi
735
931
        union_clause union_list
736
932
        precision subselect_start
737
933
        subselect_end select_var_list select_var_list_init opt_len
738
934
        opt_extended_describe
739
935
        statement
740
 
        execute
741
936
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
742
937
        init_key_options key_options key_opts key_opt key_using_alg
743
938
END_OF_INPUT
784
979
            }
785
980
            else
786
981
            {
787
 
              session->lex->statement= new statement::EmptyQuery(YYSession);
 
982
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
983
              session->lex->statement=
 
984
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
985
              if (session->lex->statement == NULL)
 
986
                DRIZZLE_YYABORT;
788
987
            }
789
988
          }
790
989
        | verb_clause END_OF_INPUT {}
805
1004
        | delete
806
1005
        | describe
807
1006
        | drop
808
 
        | execute
809
1007
        | flush
810
1008
        | insert
811
1009
        | kill
828
1026
/* create a table */
829
1027
 
830
1028
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);
 
1029
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1030
          {
 
1031
            Session *session= YYSession;
 
1032
            LEX *lex= session->lex;
 
1033
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1034
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1035
            lex->statement= statement;
 
1036
            if (lex->statement == NULL)
 
1037
              DRIZZLE_YYABORT;
 
1038
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1039
                                                   TL_OPTION_UPDATING,
 
1040
                                                   TL_WRITE))
 
1041
              DRIZZLE_YYABORT;
 
1042
            lex->col_list.empty();
 
1043
            statement->change=NULL;
 
1044
            statement->is_if_not_exists= $4;
 
1045
            statement->create_info.db_type= NULL;
 
1046
            statement->create_info.default_table_charset= NULL;
 
1047
            lex->name.str= 0;
838
1048
 
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();
 
1049
            message::Table &proto= statement->create_table_message;
 
1050
           
 
1051
            proto.set_name($5->table.str);
 
1052
            if ($2)
 
1053
              proto.set_type(message::Table::TEMPORARY);
 
1054
            else
 
1055
              proto.set_type(message::Table::STANDARD);
844
1056
          }
845
 
          create_table_definition
 
1057
          create2
846
1058
          {
847
 
            Lex->current_select= &Lex->select_lex;
 
1059
            LEX *lex= YYSession->lex;
 
1060
            lex->current_select= &lex->select_lex;
848
1061
          }
849
1062
        | CREATE build_method
850
1063
          {
851
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1064
            LEX *lex=Lex;
 
1065
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1066
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1067
            lex->statement= statement;
 
1068
            if (lex->statement == NULL)
 
1069
              DRIZZLE_YYABORT;
 
1070
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1071
            statement->alter_info.build_method= $2;
 
1072
            lex->col_list.empty();
 
1073
            statement->change=NULL;
852
1074
          }
853
1075
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
1076
          {
855
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
856
 
                                                            NULL,
857
 
                                                            TL_OPTION_UPDATING))
 
1077
            LEX *lex=Lex;
 
1078
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1079
 
 
1080
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1081
                                                        NULL,
 
1082
                                                        TL_OPTION_UPDATING))
858
1083
              DRIZZLE_YYABORT;
859
 
 
860
 
            parser::buildKey(Lex, $4, $6);
 
1084
            Key *key;
 
1085
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1086
            statement->alter_info.key_list.push_back(key);
 
1087
            lex->col_list.empty();
861
1088
          }
862
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1089
        | CREATE DATABASE opt_if_not_exists ident
863
1090
          {
864
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1091
            LEX *lex=Lex;
 
1092
 
 
1093
            lex->sql_command=SQLCOM_CREATE_DB;
 
1094
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1095
            lex->statement= statement;
 
1096
            if (lex->statement == NULL)
 
1097
              DRIZZLE_YYABORT;
 
1098
            statement->is_if_not_exists= $3;
865
1099
          }
866
1100
          opt_create_database_options
867
1101
          {
869
1103
          }
870
1104
        ;
871
1105
 
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
 
           }
 
1106
create2:
 
1107
          '(' create2a {}
 
1108
        | opt_create_table_options
 
1109
          create3 {}
 
1110
        | LIKE table_ident opt_create_table_options
 
1111
          {
 
1112
            Session *session= YYSession;
 
1113
            LEX *lex= session->lex;
 
1114
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1115
 
 
1116
            statement->is_create_table_like= true;
 
1117
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1118
              DRIZZLE_YYABORT;
 
1119
          }
 
1120
        | '(' LIKE table_ident ')'
 
1121
          {
 
1122
            Session *session= YYSession;
 
1123
            LEX *lex= session->lex;
 
1124
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1125
 
 
1126
            statement->is_create_table_like= true;
 
1127
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1128
              DRIZZLE_YYABORT;
 
1129
          }
 
1130
        ;
 
1131
 
 
1132
create2a:
 
1133
          field_list ')' opt_create_table_options
 
1134
          create3 {}
 
1135
        |  create_select ')'
 
1136
           { Lex->current_select->set_braces(1);}
879
1137
           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
1138
        ;
887
1139
 
888
 
create_select_as:
 
1140
create3:
889
1141
          /* empty */ {}
890
 
        | opt_duplicate_as create_select
891
 
          {
892
 
            Lex->current_select->set_braces(0);
893
 
          }
 
1142
        | opt_duplicate opt_as create_select
 
1143
          { Lex->current_select->set_braces(0);}
894
1144
          union_clause {}
895
 
        | opt_duplicate_as '(' create_select ')'
896
 
          {
897
 
            Lex->current_select->set_braces(1);
898
 
          }
 
1145
        | opt_duplicate opt_as '(' create_select ')'
 
1146
          { Lex->current_select->set_braces(1);}
899
1147
          union_opt {}
900
1148
        ;
901
1149
 
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
1150
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
1151
          SELECT_SYM
923
1152
          {
924
 
            Lex->lock_option= TL_READ;
925
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1153
            LEX *lex=Lex;
 
1154
            lex->lock_option= TL_READ;
 
1155
            if (lex->sql_command == SQLCOM_INSERT)
926
1156
            {
927
 
              delete Lex->statement;
928
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1157
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1158
              delete lex->statement;
 
1159
              lex->statement=
 
1160
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1161
              if (lex->statement == NULL)
 
1162
                DRIZZLE_YYABORT;
929
1163
            }
930
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1164
            else if (lex->sql_command == SQLCOM_REPLACE)
931
1165
            {
932
 
              delete Lex->statement;
933
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1166
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1167
              delete lex->statement;
 
1168
              lex->statement=
 
1169
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1170
              if (lex->statement == NULL)
 
1171
                DRIZZLE_YYABORT;
934
1172
            }
935
1173
            /*
936
1174
              The following work only with the local list, the global list
937
1175
              is created correctly in this case
938
1176
            */
939
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
 
            init_select(Lex);
941
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1177
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1178
            mysql_init_select(lex);
 
1179
            lex->current_select->parsing_place= SELECT_LIST;
942
1180
          }
943
1181
          select_options select_item_list
944
1182
          {
954
1192
          }
955
1193
        ;
956
1194
 
 
1195
opt_as:
 
1196
          /* empty */ {}
 
1197
        | AS {}
 
1198
        ;
 
1199
 
957
1200
opt_create_database_options:
958
1201
          /* empty */ {}
959
1202
        | default_collation_schema {}
967
1210
 
968
1211
custom_database_option:
969
1212
          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
 
          }
 
1213
        {
 
1214
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1215
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1216
 
 
1217
          opt->set_name($1.str);
 
1218
        }
974
1219
        | ident_or_text equal ident_or_text
975
 
          {
976
 
            parser::buildSchemaOption(Lex, $1.str, $3);
977
 
          }
 
1220
        {
 
1221
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1222
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1223
 
 
1224
          opt->set_name($1.str);
 
1225
          opt->set_state($3.str);
 
1226
        }
978
1227
        | ident_or_text equal ulonglong_num
979
 
          {
980
 
            parser::buildSchemaOption(Lex, $1.str, $3);
981
 
          }
 
1228
        {
 
1229
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1230
          char number_as_string[22];
 
1231
 
 
1232
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1233
 
 
1234
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1235
 
 
1236
          opt->set_name($1.str);
 
1237
          opt->set_state(number_as_string);
 
1238
        }
982
1239
        ;
983
1240
 
984
1241
opt_table_options:
988
1245
 
989
1246
opt_if_not_exists:
990
1247
          /* empty */ { $$= false; }
991
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1248
        | IF not EXISTS { $$= true; }
992
1249
        ;
993
1250
 
994
1251
opt_create_table_options:
1012
1269
custom_engine_option:
1013
1270
        ENGINE_SYM equal ident_or_text
1014
1271
          {
1015
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1272
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1273
 
 
1274
            statement->is_engine_set= true;
 
1275
 
 
1276
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1016
1277
          }
1017
1278
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1018
1279
          {
1019
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1280
            message::Table::TableOptions *tableopts;
 
1281
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1282
 
 
1283
            tableopts->set_comment($3.str);
1020
1284
          }
1021
1285
        | AUTO_INC opt_equal ulonglong_num
1022
1286
          {
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);
 
1287
            message::Table::TableOptions *tableopts;
 
1288
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1289
 
 
1290
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1291
 
 
1292
            statement->create_info.auto_increment_value=$3;
 
1293
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1294
            tableopts->set_auto_increment_value($3);
 
1295
          }
 
1296
        |  ident_or_text equal ident_or_text
 
1297
          {
 
1298
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1299
 
 
1300
            opt->set_name($1.str);
 
1301
            opt->set_state($3.str);
1036
1302
          }
1037
1303
        | ident_or_text equal ulonglong_num
1038
1304
          {
1039
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1305
            char number_as_string[22];
 
1306
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1307
 
 
1308
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1309
            opt->set_name($1.str);
 
1310
            opt->set_state(number_as_string);
1040
1311
          }
1041
1312
        | default_collation
1042
1313
        ;
1044
1315
default_collation:
1045
1316
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1046
1317
          {
1047
 
            if (not parser::buildCollation(Lex, $4))
1048
 
            {
1049
 
              DRIZZLE_YYABORT;
1050
 
            }
 
1318
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1319
 
 
1320
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1321
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1322
                 cinfo->default_table_charset && $4 &&
 
1323
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1324
              {
 
1325
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1326
                         $4->name, cinfo->default_table_charset->csname);
 
1327
                DRIZZLE_YYABORT;
 
1328
              }
 
1329
              statement->create_info.default_table_charset= $4;
 
1330
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1051
1331
          }
1052
1332
        ;
1053
1333
 
1054
1334
default_collation_schema:
1055
1335
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1056
1336
          {
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
 
        ;
 
1337
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1338
 
 
1339
            message::Schema &schema_message= statement->schema_message;
 
1340
            schema_message.set_collation($4->name);
 
1341
          }
 
1342
        ;
 
1343
 
 
1344
column_format_types:
 
1345
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1346
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1347
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1348
 
1077
1349
 
1078
1350
opt_select_from:
1079
1351
          opt_limit_clause {}
1101
1373
key_def:
1102
1374
          key_type opt_ident key_alg '(' key_list ')' key_options
1103
1375
          {
1104
 
            parser::buildKey(Lex, $1, $2);
 
1376
            LEX *lex=Lex;
 
1377
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1378
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1379
                              lex->col_list);
 
1380
            statement->alter_info.key_list.push_back(key);
 
1381
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1105
1382
          }
1106
1383
        | opt_constraint constraint_key_type opt_ident key_alg
1107
1384
          '(' key_list ')' key_options
1108
1385
          {
1109
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1386
            LEX *lex=Lex;
 
1387
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1388
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1389
                              lex->col_list);
 
1390
            statement->alter_info.key_list.push_back(key);
 
1391
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1110
1392
          }
1111
1393
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1112
1394
          {
1113
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1395
            LEX *lex=Lex;
 
1396
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1397
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
 
1398
                                      $8,
 
1399
                                      lex->ref_list,
 
1400
                                      statement->fk_delete_opt,
 
1401
                                      statement->fk_update_opt,
 
1402
                                      statement->fk_match_option);
 
1403
 
 
1404
            statement->alter_info.key_list.push_back(key);
 
1405
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1406
                         &default_key_create_info, 1,
 
1407
                         lex->col_list);
 
1408
            statement->alter_info.key_list.push_back(key);
 
1409
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1410
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1411
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1114
1412
          }
1115
1413
        | constraint opt_check_constraint
1116
1414
          {
1143
1441
field_spec:
1144
1442
          field_ident
1145
1443
          {
1146
 
            parser::buildCreateFieldIdent(Lex);
 
1444
            LEX *lex=Lex;
 
1445
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1446
            lex->length=lex->dec=0;
 
1447
            lex->type=0;
 
1448
            statement->default_value= statement->on_update_value= 0;
 
1449
            statement->comment= null_lex_str;
 
1450
            lex->charset=NULL;
 
1451
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1452
 
 
1453
            message::AlterTable &alter_proto=
 
1454
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1455
            statement->current_proto_field= alter_proto.add_added_field();
1147
1456
          }
1148
1457
          field_def
1149
1458
          {
 
1459
            LEX *lex=Lex;
1150
1460
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1151
1461
 
1152
 
            if (Lex->field())
1153
 
            {
1154
 
              Lex->field()->set_name($1.str);
1155
 
            }
 
1462
            if (statement->current_proto_field)
 
1463
              statement->current_proto_field->set_name($1.str);
1156
1464
 
1157
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
 
                                  Lex->length, Lex->dec, Lex->type,
 
1465
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1466
                                  lex->length,lex->dec,lex->type,
1159
1467
                                  statement->column_format,
1160
1468
                                  statement->default_value, statement->on_update_value,
1161
1469
                                  &statement->comment,
1162
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1470
                                  statement->change, &lex->interval_list, lex->charset))
1163
1471
              DRIZZLE_YYABORT;
1164
1472
 
1165
 
            Lex->setField(NULL);
 
1473
            statement->current_proto_field= NULL;
1166
1474
          }
1167
1475
        ;
1168
 
 
1169
1476
field_def:
1170
 
          field_definition opt_attribute {}
 
1477
          type opt_attribute {}
1171
1478
        ;
1172
1479
 
1173
 
field_definition:
1174
 
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1175
 
          { 
1176
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
 
1480
type:
 
1481
        int_type
 
1482
        {
 
1483
          $$=$1;
 
1484
          Lex->length=(char*) 0; /* use default length */
 
1485
          statement::CreateTable *statement=
 
1486
            (statement::CreateTable *)Lex->statement;
 
1487
 
 
1488
          if (statement->current_proto_field)
 
1489
          {
 
1490
            if ($1 == DRIZZLE_TYPE_LONG)
 
1491
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1492
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1493
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1494
            else
 
1495
              abort();
 
1496
          }
1177
1497
          }
1178
1498
        | real_type opt_precision
1179
1499
          {
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
 
1500
            $$=$1;
 
1501
 
 
1502
            statement::CreateTable *statement=
 
1503
              (statement::CreateTable *)Lex->statement;
 
1504
 
 
1505
            if (statement->current_proto_field)
 
1506
            {
 
1507
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1508
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1509
            }
 
1510
          }
 
1511
          | char '(' NUM ')'
 
1512
            {
 
1513
              Lex->length=$3.str;
 
1514
              $$=DRIZZLE_TYPE_VARCHAR;
 
1515
 
 
1516
            statement::CreateTable *statement=
 
1517
              (statement::CreateTable *)Lex->statement;
 
1518
 
 
1519
            if (statement->current_proto_field)
 
1520
            {
 
1521
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1522
              message::Table::Field::StringFieldOptions *string_field_options;
 
1523
 
 
1524
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1525
 
 
1526
              string_field_options->set_length(atoi($3.str));
 
1527
            }
 
1528
            }
 
1529
          | char
 
1530
            {
 
1531
              Lex->length=(char*) "1";
 
1532
              $$=DRIZZLE_TYPE_VARCHAR;
 
1533
 
 
1534
            statement::CreateTable *statement=
 
1535
              (statement::CreateTable *)Lex->statement;
 
1536
 
 
1537
            if (statement->current_proto_field)
 
1538
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1539
            }
 
1540
          | varchar '(' NUM ')'
 
1541
            {
 
1542
              Lex->length=$3.str;
 
1543
              $$= DRIZZLE_TYPE_VARCHAR;
 
1544
 
 
1545
            statement::CreateTable *statement=
 
1546
              (statement::CreateTable *)Lex->statement;
 
1547
 
 
1548
            if (statement->current_proto_field)
 
1549
            {
 
1550
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1551
 
 
1552
              message::Table::Field::StringFieldOptions *string_field_options;
 
1553
 
 
1554
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1555
 
 
1556
              string_field_options->set_length(atoi($3.str));
 
1557
            }
 
1558
            }
 
1559
          | VARBINARY '(' NUM ')'
 
1560
            {
 
1561
              Lex->length=$3.str;
 
1562
              Lex->charset=&my_charset_bin;
 
1563
              $$= DRIZZLE_TYPE_VARCHAR;
 
1564
 
 
1565
            statement::CreateTable *statement=
 
1566
              (statement::CreateTable *)Lex->statement;
 
1567
 
 
1568
            if (statement->current_proto_field)
 
1569
            {
 
1570
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1571
              message::Table::Field::StringFieldOptions *string_field_options;
 
1572
 
 
1573
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1574
 
 
1575
              string_field_options->set_length(atoi($3.str));
 
1576
              string_field_options->set_collation_id(my_charset_bin.number);
 
1577
              string_field_options->set_collation(my_charset_bin.name);
 
1578
            }
 
1579
            }
 
1580
          | DATE_SYM
1200
1581
          {
1201
1582
            $$=DRIZZLE_TYPE_DATE;
1202
1583
 
1203
 
            if (Lex->field())
1204
 
              Lex->field()->set_type(message::Table::Field::DATE);
1205
 
          }
1206
 
        | TIME_SYM
1207
 
          {
1208
 
            $$=DRIZZLE_TYPE_TIME;
1209
 
 
1210
 
            if (Lex->field())
1211
 
              Lex->field()->set_type(message::Table::Field::TIME);
1212
 
          }
1213
 
        | TIMESTAMP_SYM
1214
 
          {
1215
 
            $$=parser::buildTimestampColumn(Lex, NULL);
1216
 
          }
1217
 
        | TIMESTAMP_SYM '(' NUM ')'
1218
 
          {
1219
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1220
 
          }
1221
 
        | DATETIME_SYM
 
1584
            statement::CreateTable *statement=
 
1585
              (statement::CreateTable *)Lex->statement;
 
1586
 
 
1587
            if (statement->current_proto_field)
 
1588
              statement->current_proto_field->set_type(message::Table::Field::DATE);
 
1589
          }
 
1590
          | TIMESTAMP_SYM
 
1591
          {
 
1592
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1593
 
 
1594
            statement::CreateTable *statement=
 
1595
              (statement::CreateTable *)Lex->statement;
 
1596
 
 
1597
            if (statement->current_proto_field)
 
1598
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
 
1599
          }
 
1600
          | DATETIME_SYM
1222
1601
          {
1223
1602
            $$=DRIZZLE_TYPE_DATETIME;
1224
1603
 
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 ')'
 
1604
            statement::CreateTable *statement=
 
1605
              (statement::CreateTable *)Lex->statement;
 
1606
 
 
1607
            if (statement->current_proto_field)
 
1608
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1609
          }
 
1610
          | BLOB_SYM
 
1611
            {
 
1612
              Lex->charset=&my_charset_bin;
 
1613
              $$=DRIZZLE_TYPE_BLOB;
 
1614
              Lex->length=(char*) 0; /* use default length */
 
1615
 
 
1616
              statement::CreateTable *statement=
 
1617
                (statement::CreateTable *)Lex->statement;
 
1618
 
 
1619
              if (statement->current_proto_field)
 
1620
              {
 
1621
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1622
                message::Table::Field::StringFieldOptions *string_field_options;
 
1623
 
 
1624
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1625
                string_field_options->set_collation_id(my_charset_bin.number);
 
1626
                string_field_options->set_collation(my_charset_bin.name);
 
1627
              }
 
1628
            }
 
1629
          | TEXT_SYM
 
1630
            {
 
1631
              $$=DRIZZLE_TYPE_BLOB;
 
1632
              Lex->length=(char*) 0; /* use default length */
 
1633
 
 
1634
            statement::CreateTable *statement=
 
1635
              (statement::CreateTable *)Lex->statement;
 
1636
 
 
1637
            if (statement->current_proto_field)
 
1638
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1639
            }
 
1640
          | DECIMAL_SYM float_options
 
1641
          {
 
1642
            $$=DRIZZLE_TYPE_DECIMAL;
 
1643
 
 
1644
            statement::CreateTable *statement=
 
1645
              (statement::CreateTable *)Lex->statement;
 
1646
 
 
1647
            if (statement->current_proto_field)
 
1648
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1649
          }
 
1650
          | NUMERIC_SYM float_options
 
1651
          {
 
1652
            $$=DRIZZLE_TYPE_DECIMAL;
 
1653
 
 
1654
            statement::CreateTable *statement=
 
1655
              (statement::CreateTable *)Lex->statement;
 
1656
 
 
1657
            if (statement->current_proto_field)
 
1658
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1659
          }
 
1660
          | FIXED_SYM float_options
 
1661
          {
 
1662
            $$=DRIZZLE_TYPE_DECIMAL;
 
1663
 
 
1664
            statement::CreateTable *statement=
 
1665
              (statement::CreateTable *)Lex->statement;
 
1666
 
 
1667
            if (statement->current_proto_field)
 
1668
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1669
          }
 
1670
          | ENUM_SYM
 
1671
            {Lex->interval_list.empty();}
 
1672
            '(' string_list ')'
1257
1673
          {
1258
1674
            $$=DRIZZLE_TYPE_ENUM;
1259
1675
 
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);
 
1676
            statement::CreateTable *statement=
 
1677
              (statement::CreateTable *)Lex->statement;
 
1678
 
 
1679
            if (statement->current_proto_field)
 
1680
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1270
1681
          }
1271
1682
        | SERIAL_SYM
1272
1683
          {
1273
 
            $$= parser::buildSerialColumn(Lex);
 
1684
            $$=DRIZZLE_TYPE_LONGLONG;
 
1685
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1686
 
 
1687
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1688
            if (statement->current_proto_field)
 
1689
            {
 
1690
              message::Table::Field::FieldConstraints *constraints;
 
1691
              constraints= statement->current_proto_field->mutable_constraints();
 
1692
              constraints->set_is_nullable(false);
 
1693
 
 
1694
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1695
            }
1274
1696
          }
1275
1697
        ;
1276
1698
 
1284
1706
        ;
1285
1707
 
1286
1708
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
 
          }
 
1709
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1710
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1299
1711
        ;
1300
1712
 
1301
1713
real_type:
1304
1716
            $$= DRIZZLE_TYPE_DOUBLE;
1305
1717
          }
1306
1718
        | DOUBLE_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_DOUBLE;
1309
 
          }
 
1719
          { $$=DRIZZLE_TYPE_DOUBLE; }
1310
1720
        | DOUBLE_SYM PRECISION
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_DOUBLE;
1313
 
          }
 
1721
          { $$=DRIZZLE_TYPE_DOUBLE; }
1314
1722
        ;
1315
1723
 
1316
1724
float_options:
1325
1733
precision:
1326
1734
          '(' NUM ',' NUM ')'
1327
1735
          {
1328
 
            Lex->length= $2.str;
1329
 
            Lex->dec= $4.str;
 
1736
            LEX *lex=Lex;
 
1737
            lex->length=$2.str;
 
1738
            lex->dec=$4.str;
1330
1739
          }
1331
1740
        ;
1332
1741
 
1335
1744
        | '(' NUM ')' { Lex->length= $2.str; }
1336
1745
        ;
1337
1746
 
1338
 
opt_field_number_signed:
1339
 
          /* empty */ { $$= false; }
1340
 
        | SIGNED_SYM { $$= false; }
1341
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1342
 
        ;
1343
 
 
1344
 
ignored_field_number_length:
1345
 
          /* empty */ { }
1346
 
        | '(' NUM ')' { }
1347
 
        ;
1348
 
 
1349
 
opt_zerofill:
1350
 
          /* empty */ { $$= false; }
1351
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1352
 
        ;
1353
 
 
1354
1747
opt_precision:
1355
 
          /* empty */
1356
 
          { Lex->dec=Lex->length= (char*)0; }
1357
 
        | '(' NUM ')'
1358
 
          { Lex->length=Lex->dec= (char*)0; }
1359
 
        | precision
1360
 
          {}
 
1748
          /* empty */ {}
 
1749
        | precision {}
1361
1750
        ;
1362
1751
 
1363
1752
opt_attribute:
1373
1762
attribute:
1374
1763
          NULL_SYM
1375
1764
          {
 
1765
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1376
1766
            Lex->type&= ~ NOT_NULL_FLAG;
 
1767
 
 
1768
            if (statement->current_proto_field)
 
1769
            {
 
1770
              message::Table::Field::FieldConstraints *constraints;
 
1771
              constraints= statement->current_proto_field->mutable_constraints();
 
1772
              constraints->set_is_nullable(true);
 
1773
            }
 
1774
          }
 
1775
        | COLUMN_FORMAT_SYM column_format_types
 
1776
          {
 
1777
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1778
 
 
1779
            statement->column_format= $2;
 
1780
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1377
1781
          }
1378
1782
        | not NULL_SYM
1379
1783
          {
 
1784
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1380
1785
            Lex->type|= NOT_NULL_FLAG;
1381
1786
 
1382
 
            if (Lex->field())
 
1787
            if (statement->current_proto_field)
1383
1788
            {
1384
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1789
              message::Table::Field::FieldConstraints *constraints;
 
1790
              constraints= statement->current_proto_field->mutable_constraints();
 
1791
              constraints->set_is_nullable(false);
1385
1792
            }
1386
1793
          }
1387
1794
        | DEFAULT now_or_signed_literal
1392
1799
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1393
1800
          }
1394
1801
        | ON UPDATE_SYM NOW_SYM optional_braces
1395
 
          {
1396
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1397
 
          }
 
1802
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1398
1803
        | AUTO_INC
1399
1804
          {
1400
 
            parser::buildAutoOnColumn(Lex);
 
1805
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1806
 
 
1807
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1808
            if (statement->current_proto_field)
 
1809
            {
 
1810
              message::Table::Field::FieldConstraints *constraints;
 
1811
 
 
1812
              constraints= statement->current_proto_field->mutable_constraints();
 
1813
              constraints->set_is_nullable(false);
 
1814
            }
1401
1815
          }
1402
1816
        | SERIAL_SYM DEFAULT VALUE_SYM
1403
1817
          {
1404
 
            (void)parser::buildSerialColumn(Lex);
 
1818
            LEX *lex=Lex;
 
1819
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1820
 
 
1821
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1822
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1823
 
 
1824
            if (statement->current_proto_field)
 
1825
            {
 
1826
              message::Table::Field::FieldConstraints *constraints;
 
1827
              constraints= statement->current_proto_field->mutable_constraints();
 
1828
              constraints->set_is_nullable(false);
 
1829
            }
1405
1830
          }
1406
1831
        | opt_primary KEY_SYM
1407
1832
          {
1408
 
            parser::buildPrimaryOnColumn(Lex);
 
1833
            LEX *lex=Lex;
 
1834
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1835
 
 
1836
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1837
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1838
 
 
1839
            if (statement->current_proto_field)
 
1840
            {
 
1841
              message::Table::Field::FieldConstraints *constraints;
 
1842
              constraints= statement->current_proto_field->mutable_constraints();
 
1843
              constraints->set_is_nullable(false);
 
1844
            }
1409
1845
          }
1410
1846
        | UNIQUE_SYM
1411
1847
          {
1412
 
            parser::buildKeyOnColumn(Lex);
 
1848
            LEX *lex=Lex;
 
1849
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1850
 
 
1851
            lex->type|= UNIQUE_FLAG;
 
1852
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1413
1853
          }
1414
1854
        | UNIQUE_SYM KEY_SYM
1415
1855
          {
1416
 
            parser::buildKeyOnColumn(Lex);
 
1856
            LEX *lex=Lex;
 
1857
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1858
 
 
1859
            lex->type|= UNIQUE_KEY_FLAG;
 
1860
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1417
1861
          }
1418
1862
        | COMMENT_SYM TEXT_STRING_sys
1419
1863
          {
1420
1864
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1421
1865
            statement->comment= $2;
1422
1866
 
1423
 
            if (Lex->field())
1424
 
              Lex->field()->set_comment($2.str);
 
1867
            if (statement->current_proto_field)
 
1868
              statement->current_proto_field->set_comment($2.str);
1425
1869
          }
1426
1870
        | COLLATE_SYM collation_name
1427
1871
          {
1493
1937
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1494
1938
        | ident
1495
1939
          {
1496
 
            Lex->ref_list.empty();
1497
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1940
            LEX *lex= Lex;
 
1941
            lex->ref_list.empty();
 
1942
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1498
1943
          }
1499
1944
        ;
1500
1945
 
1542
1987
delete_option:
1543
1988
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1544
1989
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1545
 
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
 
1990
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1546
1991
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1547
 
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
 
1992
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_DEFAULT;  }
1548
1993
        ;
1549
1994
 
1550
1995
key_type:
1584
2029
        ;
1585
2030
 
1586
2031
/*
1587
 
  For now, key_alg initializies Lex->key_create_info.
 
2032
  For now, key_alg initializies lex->key_create_info.
1588
2033
  In the future, when all key options are after key definition,
1589
2034
  we can remove key_alg and move init_key_options to key_options
1590
2035
*/
1606
2051
 
1607
2052
key_using_alg:
1608
2053
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2054
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1609
2055
        ;
1610
2056
 
1611
2057
key_opt:
1658
2104
*/
1659
2105
 
1660
2106
alter:
1661
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2107
          ALTER build_method opt_ignore TABLE_SYM table_ident
1662
2108
          {
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());
 
2109
            Session *session= YYSession;
 
2110
            LEX *lex= session->lex;
 
2111
            lex->name.str= 0;
 
2112
            lex->name.length= 0;
 
2113
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2114
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2115
            lex->statement= statement;
 
2116
            if (lex->statement == NULL)
 
2117
              DRIZZLE_YYABORT;
 
2118
            lex->duplicates= DUP_ERROR;
 
2119
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2120
                                                   TL_OPTION_UPDATING))
 
2121
              DRIZZLE_YYABORT;
 
2122
            lex->col_list.empty();
 
2123
            lex->select_lex.init_order();
 
2124
            lex->select_lex.db=
 
2125
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2126
            statement->alter_info.build_method= $2;
1674
2127
          }
1675
2128
          alter_commands
1676
2129
          {}
1677
 
        | ALTER_SYM DATABASE schema_name
 
2130
        | ALTER DATABASE ident_or_empty
1678
2131
          {
1679
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2132
            LEX *lex=Lex;
 
2133
            lex->sql_command=SQLCOM_ALTER_DB;
 
2134
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2135
            if (lex->statement == NULL)
 
2136
              DRIZZLE_YYABORT;
1680
2137
          }
1681
2138
          default_collation_schema
1682
2139
          {
1683
 
            Lex->name= $3;
1684
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2140
            LEX *lex=Lex;
 
2141
            lex->name= $3;
 
2142
            if (lex->name.str == NULL &&
 
2143
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1685
2144
              DRIZZLE_YYABORT;
1686
2145
          }
1687
2146
        ;
1688
2147
 
 
2148
ident_or_empty:
 
2149
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2150
        | ident { $$= $1; }
 
2151
        ;
 
2152
 
1689
2153
alter_commands:
1690
2154
          /* empty */
1691
2155
        | DISCARD TABLESPACE
1722
2186
        ;
1723
2187
 
1724
2188
add_column:
1725
 
          ADD_SYM opt_column
 
2189
          ADD opt_column
1726
2190
          {
1727
2191
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1728
2192
 
1733
2197
 
1734
2198
alter_list_item:
1735
2199
          add_column column_def opt_place { }
1736
 
        | ADD_SYM key_def
 
2200
        | ADD key_def
1737
2201
          {
1738
2202
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
2203
 
1746
2210
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1747
2211
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1748
2212
          }
1749
 
        | CHANGE_SYM opt_column field_ident
 
2213
        | CHANGE opt_column field_ident
1750
2214
          {
1751
2215
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1752
2216
            statement->change= $3.str;
1755
2219
          field_spec opt_place
1756
2220
        | MODIFY_SYM opt_column field_ident
1757
2221
          {
 
2222
            LEX *lex=Lex;
1758
2223
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1759
 
            Lex->length= Lex->dec=0;
1760
 
            Lex->type= 0;
 
2224
            lex->length=lex->dec=0; lex->type=0;
1761
2225
            statement->default_value= statement->on_update_value= 0;
1762
2226
            statement->comment= null_lex_str;
1763
 
            Lex->charset= NULL;
 
2227
            lex->charset= NULL;
1764
2228
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1765
2229
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1766
2230
 
1767
 
            Lex->setField(NULL);
 
2231
            statement->current_proto_field= NULL;
1768
2232
          }
1769
2233
          field_def
1770
2234
          {
 
2235
            LEX *lex=Lex;
1771
2236
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1772
2237
 
1773
 
            if (add_field_to_list(Lex->session,&$3,
 
2238
            if (add_field_to_list(lex->session,&$3,
1774
2239
                                  (enum enum_field_types) $5,
1775
 
                                  Lex->length, Lex->dec, Lex->type,
 
2240
                                  lex->length, lex->dec, lex->type,
1776
2241
                                  statement->column_format,
1777
2242
                                  statement->default_value,
1778
2243
                                  statement->on_update_value,
1779
2244
                                  &statement->comment,
1780
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2245
                                  $3.str, &lex->interval_list, lex->charset))
1781
2246
              DRIZZLE_YYABORT;
1782
2247
          }
1783
2248
          opt_place
1826
2291
            statement->alter_info.keys_onoff= ENABLE;
1827
2292
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1828
2293
          }
1829
 
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
 
2294
        | ALTER opt_column field_ident SET DEFAULT signed_literal
1830
2295
          {
1831
2296
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1832
2297
 
1833
2298
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
1834
2299
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1835
2300
          }
1836
 
        | ALTER_SYM opt_column field_ident DROP DEFAULT
 
2301
        | ALTER opt_column field_ident DROP DEFAULT
1837
2302
          {
1838
2303
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1839
2304
 
1842
2307
          }
1843
2308
        | RENAME opt_to table_ident
1844
2309
          {
 
2310
            LEX *lex=Lex;
1845
2311
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1846
2312
            size_t dummy;
1847
2313
 
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))
 
2314
            lex->select_lex.db=$3->db.str;
 
2315
            if (lex->select_lex.db == NULL &&
 
2316
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1851
2317
            {
1852
2318
              DRIZZLE_YYABORT;
1853
2319
            }
1858
2324
              DRIZZLE_YYABORT;
1859
2325
            }
1860
2326
 
1861
 
            Lex->name= $3->table;
 
2327
            lex->name= $3->table;
1862
2328
            statement->alter_info.flags.set(ALTER_RENAME);
1863
2329
          }
1864
2330
        | CONVERT_SYM TO_SYM collation_name_or_default
1865
2331
          {
1866
2332
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
2333
 
1868
 
            statement->create_info().table_charset=
1869
 
            statement->create_info().default_table_charset= $3;
1870
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2334
            statement->create_info.table_charset=
 
2335
            statement->create_info.default_table_charset= $3;
 
2336
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1871
2337
              HA_CREATE_USED_DEFAULT_CHARSET);
1872
2338
            statement->alter_info.flags.set(ALTER_CONVERT);
1873
2339
          }
1905
2371
          /* empty */ {}
1906
2372
        | AFTER_SYM ident
1907
2373
          {
1908
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2374
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2375
 
 
2376
            store_position_for_column($2.str);
 
2377
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1909
2378
          }
1910
2379
        | FIRST_SYM
1911
2380
          {
1912
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2381
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2382
 
 
2383
            store_position_for_column(first_keyword);
 
2384
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1913
2385
          }
1914
2386
        ;
1915
2387
 
1923
2395
start:
1924
2396
          START_SYM TRANSACTION_SYM start_transaction_opts
1925
2397
          {
1926
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2398
            LEX *lex= Lex;
 
2399
            lex->sql_command= SQLCOM_BEGIN;
 
2400
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2401
            if (lex->statement == NULL)
 
2402
              DRIZZLE_YYABORT;
1927
2403
          }
1928
2404
        ;
1929
2405
 
1938
2414
analyze:
1939
2415
          ANALYZE_SYM table_or_tables
1940
2416
          {
1941
 
            Lex->statement= new statement::Analyze(YYSession);
 
2417
            LEX *lex=Lex;
 
2418
            lex->sql_command = SQLCOM_ANALYZE;
 
2419
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2420
            if (lex->statement == NULL)
 
2421
              DRIZZLE_YYABORT;
1942
2422
          }
1943
2423
          table_list
1944
2424
          {}
1947
2427
check:
1948
2428
          CHECK_SYM table_or_tables
1949
2429
          {
1950
 
            Lex->statement= new statement::Check(YYSession);
 
2430
            LEX *lex=Lex;
 
2431
 
 
2432
            lex->sql_command = SQLCOM_CHECK;
 
2433
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2434
            if (lex->statement == NULL)
 
2435
              DRIZZLE_YYABORT;
1951
2436
          }
1952
2437
          table_list
1953
2438
          {}
1956
2441
rename:
1957
2442
          RENAME table_or_tables
1958
2443
          {
1959
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2444
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2445
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2446
            if (Lex->statement == NULL)
 
2447
              DRIZZLE_YYABORT;
1960
2448
          }
1961
2449
          table_to_table_list
1962
2450
          {}
1970
2458
table_to_table:
1971
2459
          table_ident TO_SYM table_ident
1972
2460
          {
1973
 
            Select_Lex *sl= Lex->current_select;
1974
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2461
            LEX *lex=Lex;
 
2462
            Select_Lex *sl= lex->current_select;
 
2463
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1975
2464
                                       TL_IGNORE) ||
1976
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2465
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1977
2466
                                       TL_IGNORE))
1978
2467
              DRIZZLE_YYABORT;
1979
2468
          }
1987
2476
select:
1988
2477
          select_init
1989
2478
          {
1990
 
            Lex->statement= new statement::Select(YYSession);
 
2479
            LEX *lex= Lex;
 
2480
            lex->sql_command= SQLCOM_SELECT;
 
2481
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2482
            if (lex->statement == NULL)
 
2483
              DRIZZLE_YYABORT;
1991
2484
          }
1992
2485
        ;
1993
2486
 
2000
2493
select_paren:
2001
2494
          SELECT_SYM select_part2
2002
2495
          {
2003
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2496
            if (setup_select_in_parentheses(YYSession, Lex))
2004
2497
              DRIZZLE_YYABORT;
2005
2498
          }
2006
2499
        | '(' select_paren ')'
2010
2503
select_paren_derived:
2011
2504
          SELECT_SYM select_part2_derived
2012
2505
          {
2013
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2506
            if (setup_select_in_parentheses(YYSession, Lex))
2014
2507
              DRIZZLE_YYABORT;
2015
2508
          }
2016
2509
        | '(' select_paren_derived ')'
2019
2512
select_init2:
2020
2513
          select_part2
2021
2514
          {
2022
 
            Select_Lex * sel= Lex->current_select;
2023
 
            if (Lex->current_select->set_braces(0))
 
2515
            LEX *lex= Lex;
 
2516
            Select_Lex * sel= lex->current_select;
 
2517
            if (lex->current_select->set_braces(0))
2024
2518
            {
2025
 
              parser::my_parse_error(YYSession->m_lip);
 
2519
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2520
              my_parse_error(&pass);
2026
2521
              DRIZZLE_YYABORT;
2027
2522
            }
2028
2523
            if (sel->linkage == UNION_TYPE &&
2029
2524
                sel->master_unit()->first_select()->braces)
2030
2525
            {
2031
 
              parser::my_parse_error(YYSession->m_lip);
 
2526
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2527
              my_parse_error(&pass);
2032
2528
              DRIZZLE_YYABORT;
2033
2529
            }
2034
2530
          }
2037
2533
 
2038
2534
select_part2:
2039
2535
          {
2040
 
            Select_Lex *sel= Lex->current_select;
 
2536
            LEX *lex= Lex;
 
2537
            Select_Lex *sel= lex->current_select;
2041
2538
            if (sel->linkage != UNION_TYPE)
2042
 
              init_select(Lex);
2043
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2539
              mysql_init_select(lex);
 
2540
            lex->current_select->parsing_place= SELECT_LIST;
2044
2541
          }
2045
2542
          select_options select_item_list
2046
2543
          {
2070
2567
select_options:
2071
2568
          /* empty*/
2072
2569
        | select_option_list
2073
 
          { }
 
2570
          {
 
2571
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2572
                Lex->current_select->options & SELECT_ALL)
 
2573
            {
 
2574
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2575
              DRIZZLE_YYABORT;
 
2576
            }
 
2577
          }
2074
2578
        ;
2075
2579
 
2076
2580
select_option_list:
2078
2582
        | select_option
2079
2583
        ;
2080
2584
 
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
2585
select_option:
2129
2586
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2587
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2588
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2589
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2130
2590
        | SQL_BUFFER_RESULT
2131
2591
          {
2132
 
            if (check_simple_select(YYSession))
 
2592
            if (check_simple_select())
2133
2593
              DRIZZLE_YYABORT;
2134
2594
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2135
2595
          }
2136
 
        | select_option_small_or_big
2137
 
          { }
2138
 
        | select_option_distinct_or_all
2139
 
          { }
2140
2596
        | SQL_CALC_FOUND_ROWS
2141
2597
          {
2142
 
            if (check_simple_select(YYSession))
 
2598
            if (check_simple_select())
2143
2599
              DRIZZLE_YYABORT;
2144
2600
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2145
2601
          }
 
2602
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2146
2603
        ;
2147
2604
 
2148
2605
select_lock_type:
2149
2606
          /* empty */
2150
2607
        | FOR_SYM UPDATE_SYM
2151
2608
          {
2152
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2609
            LEX *lex=Lex;
 
2610
            lex->current_select->set_lock_for_tables(TL_WRITE);
2153
2611
          }
2154
2612
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2155
2613
          {
2156
 
            Lex->current_select->
 
2614
            LEX *lex=Lex;
 
2615
            lex->current_select->
2157
2616
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2158
2617
          }
2159
2618
        ;
2163
2622
        | select_item
2164
2623
        | '*'
2165
2624
          {
2166
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
2625
            Session *session= YYSession;
 
2626
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
2167
2627
                                                          context,
2168
2628
                                                          NULL, NULL, "*")))
2169
2629
              DRIZZLE_YYABORT;
2170
 
            (YYSession->lex->current_select->with_wild)++;
 
2630
            (session->lex->current_select->with_wild)++;
2171
2631
          }
2172
2632
        ;
2173
2633
 
2174
2634
select_item:
2175
2635
          remember_name table_wild remember_end
2176
2636
          {
2177
 
            if (YYSession->add_item_to_list($2))
 
2637
            Session *session= YYSession;
 
2638
 
 
2639
            if (session->add_item_to_list($2))
2178
2640
              DRIZZLE_YYABORT;
2179
2641
          }
2180
2642
        | remember_name expr remember_end select_alias
2181
2643
          {
 
2644
            Session *session= YYSession;
2182
2645
            assert($1 < $3);
2183
2646
 
2184
 
            if (YYSession->add_item_to_list($2))
 
2647
            if (session->add_item_to_list($2))
2185
2648
              DRIZZLE_YYABORT;
2186
 
 
2187
2649
            if ($4.str)
2188
2650
            {
2189
2651
              $2->is_autogenerated_name= false;
2191
2653
            }
2192
2654
            else if (!$2->name)
2193
2655
            {
2194
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2656
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2195
2657
            }
2196
2658
          }
2197
2659
        ;
2198
2660
 
2199
2661
remember_name:
2200
2662
          {
2201
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2663
            Session *session= YYSession;
 
2664
            Lex_input_stream *lip= session->m_lip;
2202
2665
            $$= (char*) lip->get_cpp_tok_start();
2203
2666
          }
2204
2667
        ;
2205
2668
 
2206
2669
remember_end:
2207
2670
          {
2208
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2671
            Session *session= YYSession;
 
2672
            Lex_input_stream *lip= session->m_lip;
2209
2673
            $$= (char*) lip->get_cpp_tok_end();
2210
2674
          }
2211
2675
        ;
2358
2822
          }
2359
2823
        | bit_expr not IN_SYM '(' subselect ')'
2360
2824
          {
2361
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2362
 
            $$= negate_expression(YYSession, item);
 
2825
            Session *session= YYSession;
 
2826
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2827
            $$= negate_expression(session, item);
2363
2828
          }
2364
2829
        | bit_expr IN_SYM '(' expr ')'
2365
2830
          {
2366
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2831
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2367
2832
          }
2368
2833
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2369
2834
          {
2373
2838
          }
2374
2839
        | bit_expr not IN_SYM '(' expr ')'
2375
2840
          {
2376
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2841
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2377
2842
          }
2378
2843
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2379
2844
          {
2384
2849
            $$= item;
2385
2850
          }
2386
2851
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2387
 
          {
2388
 
            $$= new Item_func_between($1,$3,$5);
2389
 
          }
 
2852
          { $$= new Item_func_between($1,$3,$5); }
2390
2853
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2391
2854
          {
2392
2855
            Item_func_between *item= new Item_func_between($1,$4,$6);
2394
2857
            $$= item;
2395
2858
          }
2396
2859
        | bit_expr LIKE simple_expr opt_escape
2397
 
          { 
2398
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
2399
 
          }
 
2860
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2400
2861
        | bit_expr not LIKE simple_expr opt_escape
2401
 
          { 
2402
 
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used));
2403
 
          }
2404
 
        | bit_expr REGEXP_SYM bit_expr
2405
 
          { 
2406
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2407
 
            args->push_back($1);
2408
 
            args->push_back($3);
2409
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2410
 
            {
2411
 
              DRIZZLE_YYABORT;
2412
 
            }
2413
 
          }
2414
 
        | bit_expr not REGEXP_SYM bit_expr
2415
 
          { 
2416
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2417
 
            args->push_back($1);
2418
 
            args->push_back($4);
2419
 
            args->push_back(new (YYSession->mem_root) Item_int(1));
2420
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2421
 
            {
2422
 
              DRIZZLE_YYABORT;
2423
 
            }
2424
 
          }
 
2862
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2425
2863
        | bit_expr
2426
2864
        ;
2427
2865
 
2481
2919
        | function_call_conflict
2482
2920
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2483
2921
          {
2484
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
2922
            Session *session= YYSession;
 
2923
            Item *i1= new (session->mem_root) Item_string($3.str,
2485
2924
                                                      $3.length,
2486
 
                                                      YYSession->charset());
2487
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
2925
                                                      session->charset());
 
2926
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2488
2927
          }
2489
2928
        | literal
2490
2929
        | variable
2522
2961
          }
2523
2962
        | CAST_SYM '(' expr AS cast_type ')'
2524
2963
          {
2525
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2526
 
                                 Lex->charset);
 
2964
            LEX *lex= Lex;
 
2965
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
2966
                                 lex->charset);
2527
2967
            if (!$$)
2528
2968
              DRIZZLE_YYABORT;
2529
2969
          }
2541
2981
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2542
2982
                                                         $3);
2543
2983
          }
2544
 
        | VALUES '(' simple_ident ')'
 
2984
        | VALUES '(' simple_ident_nospvar ')'
2545
2985
          {
2546
2986
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2547
2987
                                                        $3);
2563
3003
        | CURRENT_USER optional_braces
2564
3004
          {
2565
3005
            std::string user_str("user");
2566
 
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
 
3006
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2567
3007
            {
2568
3008
              DRIZZLE_YYABORT;
2569
3009
            }
2579
3019
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
2580
3020
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2581
3021
          {
2582
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3022
            Session *session= YYSession;
 
3023
            List<Item> *list= new (session->mem_root) List<Item>;
2583
3024
            list->push_front($5);
2584
3025
            list->push_front($3);
2585
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2586
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3026
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3027
            $$= new (session->mem_root) Item_func_interval(item);
2587
3028
          }
2588
3029
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2589
3030
          {
 
3031
            Session *session= YYSession;
2590
3032
            $7->push_front($5);
2591
3033
            $7->push_front($3);
2592
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2593
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3034
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3035
            $$= new (session->mem_root) Item_func_interval(item);
2594
3036
          }
2595
3037
        | LEFT '(' expr ',' expr ')'
2596
3038
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2622
3064
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2623
3065
        | USER '(' ')'
2624
3066
          {
2625
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3067
            std::string user_str("user");
 
3068
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2626
3069
            {
2627
3070
              DRIZZLE_YYABORT;
2628
3071
            }
2688
3131
            args->push_back($3);
2689
3132
            args->push_back($5);
2690
3133
            args->push_back($7);
2691
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3134
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2692
3135
            {
2693
3136
              DRIZZLE_YYABORT;
2694
3137
            }
2699
3142
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2700
3143
            args->push_back($3);
2701
3144
            args->push_back($5);
2702
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3145
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2703
3146
            {
2704
3147
              DRIZZLE_YYABORT;
2705
3148
            }
2711
3154
            args->push_back($3);
2712
3155
            args->push_back($5);
2713
3156
            args->push_back($7);
2714
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3157
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2715
3158
            {
2716
3159
              DRIZZLE_YYABORT;
2717
3160
            }
2722
3165
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2723
3166
            args->push_back($3);
2724
3167
            args->push_back($5);
2725
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
 
3168
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2726
3169
            {
2727
3170
              DRIZZLE_YYABORT;
2728
3171
            }
2765
3208
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2766
3209
        | DATABASE '(' ')'
2767
3210
          {
2768
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
2769
 
            {
2770
 
              DRIZZLE_YYABORT;
2771
 
            }
2772
 
            Lex->setCacheable(false);
2773
 
          }
2774
 
        | CATALOG_SYM '(' ')'
2775
 
          {
2776
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
2777
 
            {
2778
 
              DRIZZLE_YYABORT;
2779
 
            }
2780
 
            Lex->setCacheable(false);
2781
 
          }
2782
 
        | EXECUTE_SYM '(' expr ')' opt_wait
2783
 
          {
2784
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2785
 
            args->push_back($3);
2786
 
 
2787
 
            if ($5)
2788
 
            {
2789
 
              args->push_back(new (YYSession->mem_root) Item_int(1));
2790
 
            }
2791
 
 
2792
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
2793
 
            {
2794
 
              DRIZZLE_YYABORT;
2795
 
            }
2796
 
          }
 
3211
            std::string database_str("database");
 
3212
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
 
3213
            {
 
3214
              DRIZZLE_YYABORT;
 
3215
            }
 
3216
            Lex->setCacheable(false);
 
3217
          }
2797
3218
        | IF '(' expr ',' expr ',' expr ')'
2798
3219
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
2799
 
        | KILL_SYM kill_option '(' expr ')'
2800
 
          {
2801
 
            std::string kill_str("kill");
2802
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2803
 
            args->push_back($4);
2804
 
 
2805
 
            if ($2)
2806
 
            {
2807
 
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2808
 
            }
2809
 
 
2810
 
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
2811
 
            {
2812
 
              DRIZZLE_YYABORT;
2813
 
            }
2814
 
          }
2815
3220
        | MICROSECOND_SYM '(' expr ')'
2816
3221
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
2817
3222
        | MOD_SYM '(' expr ',' expr ')'
2822
3227
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
2823
3228
        | REPLACE '(' expr ',' expr ',' expr ')'
2824
3229
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3230
        | REVERSE_SYM '(' expr ')'
 
3231
          {
 
3232
            std::string reverse_str("reverse");
 
3233
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3234
            args->push_back($3);
 
3235
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
3236
            {
 
3237
              DRIZZLE_YYABORT;
 
3238
            }
 
3239
          }
2825
3240
        | TRUNCATE_SYM '(' expr ',' expr ')'
2826
3241
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2827
 
        | WAIT_SYM '(' expr ')'
2828
 
          {
2829
 
            std::string wait_str("wait");
2830
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2831
 
            args->push_back($3);
2832
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
2833
 
            {
2834
 
              DRIZZLE_YYABORT;
2835
 
            }
2836
 
          }
2837
 
        | UUID_SYM '(' ')'
2838
 
          {
2839
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
2840
 
            {
2841
 
              DRIZZLE_YYABORT;
2842
 
            }
2843
 
            Lex->setCacheable(false);
2844
 
          }
2845
 
        | WAIT_SYM '(' expr ',' expr ')'
2846
 
          {
2847
 
            std::string wait_str("wait");
2848
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2849
 
            args->push_back($3);
2850
 
            args->push_back($5);
2851
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
2852
 
            {
2853
 
              DRIZZLE_YYABORT;
2854
 
            }
2855
 
          }
2856
3242
        ;
2857
3243
 
2858
3244
/*
2873
3259
          }
2874
3260
          opt_udf_expr_list ')'
2875
3261
          {
 
3262
            Session *session= YYSession;
2876
3263
            Create_func *builder;
2877
3264
            Item *item= NULL;
2878
3265
 
2888
3275
            builder= find_native_function_builder($1);
2889
3276
            if (builder)
2890
3277
            {
2891
 
              item= builder->create(YYSession, $1, $4);
 
3278
              item= builder->create(session, $1, $4);
2892
3279
            }
2893
3280
            else
2894
3281
            {
2896
3283
              const plugin::Function *udf= $<udf>3;
2897
3284
              if (udf)
2898
3285
              {
2899
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3286
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2900
3287
              } else {
2901
3288
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2902
3289
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3013
3400
        ;
3014
3401
 
3015
3402
variable_aux:
3016
 
          user_variable_ident SET_VAR expr
 
3403
          ident_or_text SET_VAR expr
3017
3404
          {
3018
3405
            $$= new Item_func_set_user_var($1, $3);
3019
3406
            Lex->setCacheable(false);
3020
3407
          }
3021
 
        | user_variable_ident
 
3408
        | ident_or_text
3022
3409
          {
3023
3410
            $$= new Item_func_get_user_var(*YYSession, $1);
3024
3411
            Lex->setCacheable(false);
3025
3412
          }
3026
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3413
        | '@' opt_var_ident_type ident_or_text opt_component
3027
3414
          {
3028
3415
            /* disallow "SELECT @@global.global.variable" */
3029
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3416
            if ($3.str && $4.str && check_reserved_words(&$3))
3030
3417
            {
3031
 
              parser::my_parse_error(YYSession->m_lip);
 
3418
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3419
              my_parse_error(&pass);
3032
3420
              DRIZZLE_YYABORT;
3033
3421
            }
3034
3422
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3037
3425
        ;
3038
3426
 
3039
3427
opt_distinct:
3040
 
          /* empty */ { $$ = false; }
3041
 
        | DISTINCT    { $$ = true; }
 
3428
          /* empty */ { $$ = 0; }
 
3429
        | DISTINCT    { $$ = 1; }
3042
3430
        ;
3043
3431
 
3044
3432
opt_gconcat_separator:
3067
3455
in_sum_expr:
3068
3456
          opt_all
3069
3457
          {
3070
 
            if (Lex->current_select->inc_in_sum_expr())
 
3458
            LEX *lex= Lex;
 
3459
            if (lex->current_select->inc_in_sum_expr())
3071
3460
            {
3072
 
              parser::my_parse_error(YYSession->m_lip);
 
3461
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3462
              my_parse_error(&pass);
3073
3463
              DRIZZLE_YYABORT;
3074
3464
            }
3075
3465
          }
3083
3473
cast_type:
3084
3474
          BINARY opt_len
3085
3475
          { $$=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
3476
        | CHAR_SYM opt_len
3099
3477
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3100
3478
        | DATE_SYM
3101
3479
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3102
 
        | TIME_SYM
3103
 
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3104
3480
        | DATETIME_SYM
3105
3481
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3106
3482
        | DECIMAL_SYM float_options
3151
3527
          table_factor { $$=$1; }
3152
3528
        | join_table
3153
3529
          {
3154
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3530
            LEX *lex= Lex;
 
3531
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3155
3532
              DRIZZLE_YYABORT;
3156
3533
          }
3157
3534
        ;
3298
3675
          }
3299
3676
          expr
3300
3677
          {
3301
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3678
            LEX *lex= Lex;
 
3679
            if (!($$= lex->current_select->convert_right_join()))
3302
3680
              DRIZZLE_YYABORT;
3303
3681
            add_join_on($$, $8);
3304
3682
            Lex->pop_context();
3310
3688
          }
3311
3689
          USING '(' using_list ')'
3312
3690
          {
3313
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3691
            LEX *lex= Lex;
 
3692
            if (!($$= lex->current_select->convert_right_join()))
3314
3693
              DRIZZLE_YYABORT;
3315
3694
            add_join_natural($$,$5,$9,Lex->current_select);
3316
3695
          }
3318
3697
          {
3319
3698
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3320
3699
            add_join_natural($6,$1,NULL,Lex->current_select);
3321
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3700
            LEX *lex= Lex;
 
3701
            if (!($$= lex->current_select->convert_right_join()))
3322
3702
              DRIZZLE_YYABORT;
3323
3703
          }
3324
3704
        ;
3326
3706
normal_join:
3327
3707
          JOIN_SYM {}
3328
3708
        | INNER_SYM JOIN_SYM {}
3329
 
        | CROSS JOIN_SYM
3330
 
          {
3331
 
            Lex->is_cross= true;
3332
 
            Lex->current_select->is_cross= true;
3333
 
          }
 
3709
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3334
3710
        ;
3335
3711
 
3336
3712
/*
3343
3719
/* Warning - may return NULL in case of incomplete SELECT */
3344
3720
table_factor:
3345
3721
          {
 
3722
            Select_Lex *sel= Lex->current_select;
 
3723
            sel->table_join_options= 0;
3346
3724
          }
3347
3725
          table_ident opt_table_alias opt_key_definition
3348
3726
          {
3349
3727
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3350
 
                             0,
 
3728
                             Lex->current_select->get_table_join_options(),
3351
3729
                             Lex->lock_option,
3352
3730
                             Lex->current_select->pop_index_hints())))
3353
3731
              DRIZZLE_YYABORT;
3355
3733
          }
3356
3734
        | select_derived_init get_select_lex select_derived2
3357
3735
          {
3358
 
            Select_Lex *sel= Lex->current_select;
 
3736
            LEX *lex= Lex;
 
3737
            Select_Lex *sel= lex->current_select;
3359
3738
            if ($1)
3360
3739
            {
3361
3740
              if (sel->set_braces(1))
3362
3741
              {
3363
 
                parser::my_parse_error(YYSession->m_lip);
 
3742
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3743
                my_parse_error(&pass);
3364
3744
                DRIZZLE_YYABORT;
3365
3745
              }
3366
3746
              /* select in braces, can't contain global parameters */
3368
3748
                sel->master_unit()->global_parameters=
3369
3749
                   sel->master_unit()->fake_select_lex;
3370
3750
            }
3371
 
            if ($2->init_nested_join(Lex->session))
 
3751
            if ($2->init_nested_join(lex->session))
3372
3752
              DRIZZLE_YYABORT;
3373
3753
            $$= 0;
3374
3754
            /* incomplete derived tables return NULL, we must be
3410
3790
              /* Handle case of derived table, alias may be NULL if there
3411
3791
                 are no outer parentheses, add_table_to_list() will throw
3412
3792
                 error in this case */
3413
 
              Select_Lex *sel= Lex->current_select;
 
3793
              LEX *lex=Lex;
 
3794
              Select_Lex *sel= lex->current_select;
3414
3795
              Select_Lex_Unit *unit= sel->master_unit();
3415
 
              Lex->current_select= sel= unit->outer_select();
3416
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3796
              lex->current_select= sel= unit->outer_select();
 
3797
              if (!($$= sel->add_table_to_list(lex->session,
3417
3798
                                               new Table_ident(unit), $5, 0,
3418
3799
                                               TL_READ)))
3419
3800
 
3420
3801
                DRIZZLE_YYABORT;
3421
3802
              sel->add_joined_table($$);
3422
 
              Lex->pop_context();
 
3803
              lex->pop_context();
3423
3804
            }
3424
3805
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3425
3806
            {
3426
3807
              /* simple nested joins cannot have aliases or unions */
3427
 
              parser::my_parse_error(YYSession->m_lip);
 
3808
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3809
              my_parse_error(&pass);
3428
3810
              DRIZZLE_YYABORT;
3429
3811
            }
3430
3812
            else
3438
3820
          UNION_SYM
3439
3821
          union_option
3440
3822
          {
3441
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3823
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3442
3824
              DRIZZLE_YYABORT;
3443
3825
          }
3444
3826
          query_specification
3456
3838
select_init2_derived:
3457
3839
          select_part2_derived
3458
3840
          {
3459
 
            Select_Lex * sel= Lex->current_select;
3460
 
            if (Lex->current_select->set_braces(0))
 
3841
            LEX *lex= Lex;
 
3842
            Select_Lex * sel= lex->current_select;
 
3843
            if (lex->current_select->set_braces(0))
3461
3844
            {
3462
 
              parser::my_parse_error(YYSession->m_lip);
 
3845
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3846
              my_parse_error(&pass);
3463
3847
              DRIZZLE_YYABORT;
3464
3848
            }
3465
3849
            if (sel->linkage == UNION_TYPE &&
3466
3850
                sel->master_unit()->first_select()->braces)
3467
3851
            {
3468
 
              parser::my_parse_error(YYSession->m_lip);
 
3852
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3853
              my_parse_error(&pass);
3469
3854
              DRIZZLE_YYABORT;
3470
3855
            }
3471
3856
          }
3474
3859
/* The equivalent of select_part2 for nested queries. */
3475
3860
select_part2_derived:
3476
3861
          {
3477
 
            Select_Lex *sel= Lex->current_select;
 
3862
            LEX *lex= Lex;
 
3863
            Select_Lex *sel= lex->current_select;
3478
3864
            if (sel->linkage != UNION_TYPE)
3479
 
              init_select(Lex);
3480
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3865
              mysql_init_select(lex);
 
3866
            lex->current_select->parsing_place= SELECT_LIST;
3481
3867
          }
3482
3868
          select_options select_item_list
3483
3869
          {
3490
3876
select_derived:
3491
3877
          get_select_lex
3492
3878
          {
3493
 
            if ($1->init_nested_join(Lex->session))
 
3879
            LEX *lex= Lex;
 
3880
            if ($1->init_nested_join(lex->session))
3494
3881
              DRIZZLE_YYABORT;
3495
3882
          }
3496
3883
          derived_table_list
3497
3884
          {
 
3885
            LEX *lex= Lex;
3498
3886
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3499
3887
               for derived tables, both must equal NULL */
3500
3888
 
3501
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
3889
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3502
3890
              DRIZZLE_YYABORT;
3503
 
 
3504
3891
            if (!$3 && $$)
3505
3892
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
3893
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3894
              my_parse_error(&pass);
3507
3895
              DRIZZLE_YYABORT;
3508
3896
            }
3509
3897
          }
3511
3899
 
3512
3900
select_derived2:
3513
3901
          {
3514
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3515
 
            if (not Lex->expr_allows_subselect)
 
3902
            LEX *lex= Lex;
 
3903
            lex->derived_tables|= DERIVED_SUBQUERY;
 
3904
            if (!lex->expr_allows_subselect)
3516
3905
            {
3517
 
              parser::my_parse_error(YYSession->m_lip);
 
3906
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3907
              my_parse_error(&pass);
3518
3908
              DRIZZLE_YYABORT;
3519
3909
            }
3520
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
3910
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
3911
                mysql_new_select(lex, 1))
3521
3912
              DRIZZLE_YYABORT;
3522
 
            init_select(Lex);
3523
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3524
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3913
            mysql_init_select(lex);
 
3914
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3915
            lex->current_select->parsing_place= SELECT_LIST;
3525
3916
          }
3526
3917
          select_options select_item_list
3527
3918
          {
3537
3928
select_derived_init:
3538
3929
          SELECT_SYM
3539
3930
          {
3540
 
            Select_Lex *sel= Lex->current_select;
 
3931
            LEX *lex= Lex;
 
3932
 
 
3933
            Select_Lex *sel= lex->current_select;
3541
3934
            TableList *embedding;
3542
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
3935
            if (!sel->embedding || sel->end_nested_join(lex->session))
3543
3936
            {
3544
3937
              /* we are not in parentheses */
3545
 
              parser::my_parse_error(YYSession->m_lip);
 
3938
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3939
              my_parse_error(&pass);
3546
3940
              DRIZZLE_YYABORT;
3547
3941
            }
3548
3942
            embedding= Lex->current_select->embedding;
3690
4084
opt_table_alias:
3691
4085
          /* empty */ { $$=0; }
3692
4086
        | table_alias ident
3693
 
          {
3694
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3695
 
          }
 
4087
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3696
4088
        ;
3697
4089
 
3698
4090
opt_all:
3772
4164
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3773
4165
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3774
4166
            */
3775
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4167
            LEX *lex= Lex;
 
4168
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3776
4169
            {
3777
4170
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3778
4171
                       "global union parameters");
3779
4172
              DRIZZLE_YYABORT;
3780
4173
            }
3781
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4174
            lex->current_select->olap= ROLLUP_TYPE;
3782
4175
          }
3783
4176
        ;
3784
4177
 
3796
4189
        ;
3797
4190
 
3798
4191
alter_order_item:
3799
 
          simple_ident order_dir
 
4192
          simple_ident_nospvar order_dir
3800
4193
          {
 
4194
            Session *session= YYSession;
3801
4195
            bool ascending= ($2 == 1) ? true : false;
3802
 
            if (YYSession->add_order_to_list($1, ascending))
 
4196
            if (session->add_order_to_list($1, ascending))
3803
4197
              DRIZZLE_YYABORT;
3804
4198
          }
3805
4199
        ;
3816
4210
order_clause:
3817
4211
          ORDER_SYM BY
3818
4212
          {
3819
 
            if (not parser::buildOrderBy(Lex))
 
4213
            LEX *lex=Lex;
 
4214
            Select_Lex *sel= lex->current_select;
 
4215
            Select_Lex_Unit *unit= sel-> master_unit();
 
4216
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4217
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4218
                (sel->linkage != UNION_TYPE || sel->braces))
 
4219
            {
 
4220
              my_error(ER_WRONG_USAGE, MYF(0),
 
4221
                       "CUBE/ROLLUP", "ORDER BY");
3820
4222
              DRIZZLE_YYABORT;
 
4223
            }
 
4224
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4225
            {
 
4226
              /*
 
4227
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4228
                executed in the same way as the query
 
4229
                SELECT ... ORDER BY order_list
 
4230
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4231
                Otherwise we create a fake Select_Lex if it has not been created
 
4232
                yet.
 
4233
              */
 
4234
              Select_Lex *first_sl= unit->first_select();
 
4235
              if (!unit->is_union() &&
 
4236
                  (first_sl->order_list.elements ||
 
4237
                   first_sl->select_limit) &&           
 
4238
                  unit->add_fake_select_lex(lex->session))
 
4239
                DRIZZLE_YYABORT;
 
4240
            }
3821
4241
          }
3822
4242
          order_list
3823
4243
        ;
3824
4244
 
3825
4245
order_list:
3826
4246
          order_list ',' order_ident order_dir
3827
 
          {
3828
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3829
 
              DRIZZLE_YYABORT;
3830
 
          }
 
4247
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3831
4248
        | order_ident order_dir
3832
 
          {
3833
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3834
 
              DRIZZLE_YYABORT;
3835
 
          }
 
4249
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3836
4250
        ;
3837
4251
 
3838
4252
order_dir:
3844
4258
opt_limit_clause_init:
3845
4259
          /* empty */
3846
4260
          {
3847
 
            Select_Lex *sel= Lex->current_select;
 
4261
            LEX *lex= Lex;
 
4262
            Select_Lex *sel= lex->current_select;
3848
4263
            sel->offset_limit= 0;
3849
4264
            sel->select_limit= 0;
3850
4265
          }
3893
4308
delete_limit_clause:
3894
4309
          /* empty */
3895
4310
          {
3896
 
            Lex->current_select->select_limit= 0;
 
4311
            LEX *lex=Lex;
 
4312
            lex->current_select->select_limit= 0;
3897
4313
          }
3898
4314
        | LIMIT limit_option
3899
4315
          {
3904
4320
        ;
3905
4321
 
3906
4322
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); }
 
4323
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4324
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4325
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4326
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4327
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4328
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3913
4329
        ;
3914
4330
 
3915
4331
ulonglong_num:
3922
4338
 
3923
4339
select_var_list_init:
3924
4340
          {
3925
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4341
            LEX *lex=Lex;
 
4342
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3926
4343
              DRIZZLE_YYABORT;
3927
4344
          }
3928
4345
          select_var_list
3935
4352
        ;
3936
4353
 
3937
4354
select_var_ident: 
3938
 
          '@' user_variable_ident
 
4355
          '@' ident_or_text
3939
4356
          {
3940
 
            if (Lex->result)
3941
 
            {
3942
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3943
 
            }
 
4357
            LEX *lex=Lex;
 
4358
            if (lex->result)
 
4359
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3944
4360
            else
3945
 
            {
3946
4361
              /*
3947
4362
                The parser won't create select_result instance only
3948
4363
                if it's an EXPLAIN.
3949
4364
              */
3950
 
              assert(Lex->describe);
3951
 
            }
 
4365
              assert(lex->describe);
3952
4366
          }
3953
4367
        ;
3954
4368
 
3961
4375
into_destination:
3962
4376
          OUTFILE TEXT_STRING_filesystem
3963
4377
          {
3964
 
            Lex->setCacheable(false);
3965
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3966
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4378
            LEX *lex= Lex;
 
4379
            lex->setCacheable(false);
 
4380
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4381
                !(lex->result= new select_export(lex->exchange)))
3967
4382
              DRIZZLE_YYABORT;
3968
4383
          }
3969
4384
          opt_field_term opt_line_term
3970
4385
        | DUMPFILE TEXT_STRING_filesystem
3971
4386
          {
3972
 
            if (not Lex->describe)
 
4387
            LEX *lex=Lex;
 
4388
            if (!lex->describe)
3973
4389
            {
3974
 
              Lex->setCacheable(false);
3975
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4390
              lex->setCacheable(false);
 
4391
              if (!(lex->exchange= new file_exchange($2.str,1)))
3976
4392
                DRIZZLE_YYABORT;
3977
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4393
              if (!(lex->result= new select_dump(lex->exchange)))
3978
4394
                DRIZZLE_YYABORT;
3979
4395
            }
3980
4396
          }
3987
4403
*/
3988
4404
 
3989
4405
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;
 
4406
          DROP opt_temporary table_or_tables if_exists table_list
 
4407
          {
 
4408
            LEX *lex=Lex;
 
4409
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4410
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4411
            lex->statement= statement;
 
4412
            if (lex->statement == NULL)
 
4413
              DRIZZLE_YYABORT;
3998
4414
            statement->drop_temporary= $2;
3999
4415
            statement->drop_if_exists= $4;
4000
4416
          }
4001
4417
        | DROP build_method INDEX_SYM ident ON table_ident {}
4002
4418
          {
4003
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
4004
 
            Lex->statement= statement;
 
4419
            LEX *lex=Lex;
 
4420
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4421
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4422
            lex->statement= statement;
 
4423
            if (lex->statement == NULL)
 
4424
              DRIZZLE_YYABORT;
4005
4425
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4006
4426
            statement->alter_info.build_method= $2;
4007
4427
            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))
 
4428
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4429
                                                        TL_OPTION_UPDATING))
4010
4430
              DRIZZLE_YYABORT;
4011
4431
          }
4012
 
        | DROP DATABASE if_exists schema_name
 
4432
        | DROP DATABASE if_exists ident
4013
4433
          {
4014
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4015
 
            Lex->statement= statement;
 
4434
            LEX *lex=Lex;
 
4435
            lex->sql_command= SQLCOM_DROP_DB;
 
4436
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4437
            lex->statement= statement;
 
4438
            if (lex->statement == NULL)
 
4439
              DRIZZLE_YYABORT;
4016
4440
            statement->drop_if_exists=$3;
4017
 
            Lex->name= $4;
 
4441
            lex->name= $4;
4018
4442
          }
4019
 
        ;
4020
 
 
4021
4443
table_list:
4022
4444
          table_name
4023
4445
        | table_list ',' table_name
4032
4454
        ;
4033
4455
 
4034
4456
if_exists:
4035
 
          /* empty */ { $$= false; }
4036
 
        | IF EXISTS { $$= true; }
 
4457
          /* empty */ { $$= 0; }
 
4458
        | IF EXISTS { $$= 1; }
4037
4459
        ;
4038
4460
 
4039
4461
opt_temporary:
4040
 
          /* empty */ { $$= false; }
4041
 
        | TEMPORARY_SYM { $$= true; }
4042
 
        ;
4043
 
 
4044
 
/*
4045
 
  Execute a string as dynamic SQL.
4046
 
*/
4047
 
 
4048
 
execute:
4049
 
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
4050
 
        {
4051
 
          Lex->statement= new statement::Execute(YYSession, $2, $3, $4, $5);
4052
 
        }
4053
 
 
4054
 
 
4055
 
execute_var_or_string:
4056
 
         user_variable_ident
4057
 
         {
4058
 
            $$.set($1);
4059
 
         }
4060
 
        | '@' user_variable_ident
4061
 
        {
4062
 
            $$.set($2, true);
4063
 
        }
4064
 
 
4065
 
opt_status:
4066
 
          /* empty */ { $$= false; }
4067
 
        | WITH NO_SYM RETURN_SYM { $$= true; }
4068
 
        ;
4069
 
 
4070
 
opt_concurrent:
4071
 
          /* empty */ { $$= false; }
4072
 
        | CONCURRENT { $$= true; }
4073
 
        ;
4074
 
 
4075
 
opt_wait:
4076
 
          /* empty */ { $$= false; }
4077
 
        | WAIT_SYM { $$= true; }
4078
 
        ;
4079
 
 
 
4462
          /* empty */ { $$= 0; }
 
4463
        | TEMPORARY_SYM { $$= 1; }
 
4464
        ;
4080
4465
/*
4081
4466
** Insert : add new data to table
4082
4467
*/
4084
4469
insert:
4085
4470
          INSERT
4086
4471
          {
4087
 
            Lex->statement= new statement::Insert(YYSession);
4088
 
            Lex->duplicates= DUP_ERROR;
4089
 
            init_select(Lex);
 
4472
            LEX *lex= Lex;
 
4473
            lex->sql_command= SQLCOM_INSERT;
 
4474
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4475
            if (lex->statement == NULL)
 
4476
              DRIZZLE_YYABORT;
 
4477
            lex->duplicates= DUP_ERROR;
 
4478
            mysql_init_select(lex);
4090
4479
            /* for subselects */
4091
 
            Lex->lock_option= TL_READ;
 
4480
            lex->lock_option= TL_READ;
4092
4481
          }
4093
4482
          opt_ignore insert2
4094
4483
          {
4102
4491
replace:
4103
4492
          REPLACE
4104
4493
          {
4105
 
            Lex->statement= new statement::Replace(YYSession);
4106
 
            Lex->duplicates= DUP_REPLACE;
4107
 
            init_select(Lex);
 
4494
            LEX *lex= Lex;
 
4495
            lex->sql_command= SQLCOM_REPLACE;
 
4496
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4497
            if (lex->statement == NULL)
 
4498
              DRIZZLE_YYABORT;
 
4499
            lex->duplicates= DUP_REPLACE;
 
4500
            mysql_init_select(lex);
4108
4501
          }
4109
4502
          insert2
4110
4503
          {
4123
4516
insert_table:
4124
4517
          table_name
4125
4518
          {
4126
 
            Lex->field_list.empty();
4127
 
            Lex->many_values.empty();
4128
 
            Lex->insert_list=0;
 
4519
            LEX *lex=Lex;
 
4520
            lex->field_list.empty();
 
4521
            lex->many_values.empty();
 
4522
            lex->insert_list=0;
4129
4523
          };
4130
4524
 
4131
4525
insert_field_spec:
4132
4526
          insert_values {}
4133
4527
        | '(' ')' insert_values {}
4134
4528
        | '(' fields ')' insert_values {}
4135
 
        | SET_SYM
 
4529
        | SET
4136
4530
          {
4137
 
            if (not (Lex->insert_list = new List_item) ||
4138
 
                Lex->many_values.push_back(Lex->insert_list))
 
4531
            LEX *lex=Lex;
 
4532
            if (!(lex->insert_list = new List_item) ||
 
4533
                lex->many_values.push_back(lex->insert_list))
4139
4534
              DRIZZLE_YYABORT;
4140
4535
          }
4141
4536
          ident_eq_list
4149
4544
insert_values:
4150
4545
          VALUES values_list {}
4151
4546
        | VALUE_SYM values_list {}
4152
 
        | stored_select
4153
 
          {
4154
 
            Lex->current_select->set_braces(0);
4155
 
          }
 
4547
        | create_select
 
4548
          { Lex->current_select->set_braces(0);}
4156
4549
          union_clause {}
4157
 
        | '(' stored_select ')'
4158
 
          {
4159
 
            Lex->current_select->set_braces(1);
4160
 
          }
 
4550
        | '(' create_select ')'
 
4551
          { Lex->current_select->set_braces(1);}
4161
4552
          union_opt {}
4162
4553
        ;
4163
4554
 
4172
4563
        ;
4173
4564
 
4174
4565
ident_eq_value:
4175
 
          simple_ident equal expr_or_default
 
4566
          simple_ident_nospvar equal expr_or_default
4176
4567
          {
4177
 
            if (Lex->field_list.push_back($1) ||
4178
 
                Lex->insert_list->push_back($3))
 
4568
            LEX *lex=Lex;
 
4569
            if (lex->field_list.push_back($1) ||
 
4570
                lex->insert_list->push_back($3))
4179
4571
              DRIZZLE_YYABORT;
4180
4572
          }
4181
4573
        ;
4198
4590
          }
4199
4591
          opt_values ')'
4200
4592
          {
4201
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4593
            LEX *lex=Lex;
 
4594
            if (lex->many_values.push_back(lex->insert_list))
4202
4595
              DRIZZLE_YYABORT;
4203
4596
          }
4204
4597
        ;
4237
4630
update:
4238
4631
          UPDATE_SYM opt_ignore table_ident
4239
4632
          {
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))
 
4633
            LEX *lex= Lex;
 
4634
            mysql_init_select(lex);
 
4635
            lex->sql_command= SQLCOM_UPDATE;
 
4636
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4637
            if (lex->statement == NULL)
 
4638
              DRIZZLE_YYABORT;
 
4639
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4640
            lex->duplicates= DUP_ERROR;
 
4641
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4245
4642
              DRIZZLE_YYABORT;
4246
4643
          }
4247
 
          SET_SYM update_list
 
4644
          SET update_list
4248
4645
          {
4249
 
            if (Lex->select_lex.get_table_list()->derived)
 
4646
            LEX *lex= Lex;
 
4647
            if (lex->select_lex.get_table_list()->derived)
4250
4648
            {
4251
4649
              /* it is single table update and it is update of derived table */
4252
4650
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4253
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4651
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4254
4652
              DRIZZLE_YYABORT;
4255
4653
            }
4256
4654
            /*
4257
4655
              In case of multi-update setting write lock for all tables may
4258
4656
              be too pessimistic. We will decrease lock level if possible in
4259
 
              multi_update().
 
4657
              mysql_multi_update().
4260
4658
            */
4261
4659
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4262
4660
          }
4269
4667
        ;
4270
4668
 
4271
4669
update_elem:
4272
 
          simple_ident equal expr_or_default
 
4670
          simple_ident_nospvar equal expr_or_default
4273
4671
          {
4274
4672
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4275
4673
              DRIZZLE_YYABORT;
4282
4680
        ;
4283
4681
 
4284
4682
insert_update_elem:
4285
 
          simple_ident equal expr_or_default
 
4683
          simple_ident_nospvar equal expr_or_default
4286
4684
          {
4287
 
          if (Lex->update_list.push_back($1) ||
4288
 
              Lex->value_list.push_back($3))
 
4685
          LEX *lex= Lex;
 
4686
          if (lex->update_list.push_back($1) ||
 
4687
              lex->value_list.push_back($3))
4289
4688
              DRIZZLE_YYABORT;
4290
4689
          }
4291
4690
        ;
4295
4694
delete:
4296
4695
          DELETE_SYM
4297
4696
          {
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();
 
4697
            LEX *lex= Lex;
 
4698
            lex->sql_command= SQLCOM_DELETE;
 
4699
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4700
            if (lex->statement == NULL)
 
4701
              DRIZZLE_YYABORT;
 
4702
            mysql_init_select(lex);
 
4703
            lex->lock_option= TL_WRITE_DEFAULT;
 
4704
            lex->ignore= 0;
 
4705
            lex->select_lex.init_order();
4303
4706
          }
4304
4707
          opt_delete_options single_multi
4305
4708
        ;
4327
4730
truncate:
4328
4731
          TRUNCATE_SYM opt_table_sym table_name
4329
4732
          {
4330
 
            Lex->statement= new statement::Truncate(YYSession);
4331
 
            Lex->select_lex.options= 0;
4332
 
            Lex->select_lex.init_order();
 
4733
            LEX* lex= Lex;
 
4734
            lex->sql_command= SQLCOM_TRUNCATE;
 
4735
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4736
            if (lex->statement == NULL)
 
4737
              DRIZZLE_YYABORT;
 
4738
            lex->select_lex.options= 0;
 
4739
            lex->select_lex.init_order();
4333
4740
          }
4334
4741
        ;
4335
4742
 
4343
4750
show:
4344
4751
          SHOW
4345
4752
          {
4346
 
            Lex->lock_option= TL_READ;
4347
 
            init_select(Lex);
4348
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4753
            LEX *lex=Lex;
 
4754
            lex->wild=0;
 
4755
            lex->lock_option= TL_READ;
 
4756
            mysql_init_select(lex);
 
4757
            lex->current_select->parsing_place= SELECT_LIST;
4349
4758
          }
4350
4759
          show_param
4351
4760
          {}
4352
4761
        ;
4353
4762
 
4354
 
/* SHOW SCHEMAS */
4355
4763
show_param:
4356
4764
           DATABASES show_wild
4357
4765
           {
4358
 
             if (not show::buildScemas(YYSession))
4359
 
               DRIZZLE_YYABORT;
 
4766
             LEX *lex= Lex;
 
4767
             Session *session= YYSession;
 
4768
 
 
4769
             lex->sql_command= SQLCOM_SELECT;
 
4770
             lex->statement=
 
4771
               new(std::nothrow) statement::Select(session);
 
4772
             if (lex->statement == NULL)
 
4773
               DRIZZLE_YYABORT;
 
4774
 
 
4775
             std::string column_name= "Database";
 
4776
             if (Lex->wild)
 
4777
             {
 
4778
               column_name.append(" (");
 
4779
               column_name.append(Lex->wild->ptr());
 
4780
               column_name.append(")");
 
4781
             }
 
4782
 
 
4783
             if (Lex->current_select->where)
 
4784
             {
 
4785
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
4786
                 DRIZZLE_YYABORT;
 
4787
             }
 
4788
             else
 
4789
             {
 
4790
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
4791
                 DRIZZLE_YYABORT;
 
4792
             }
 
4793
 
 
4794
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4795
             my_field->is_autogenerated_name= false;
 
4796
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4797
 
 
4798
             if (session->add_item_to_list(my_field))
 
4799
               DRIZZLE_YYABORT;
 
4800
 
 
4801
              if (session->add_order_to_list(my_field, true))
 
4802
                DRIZZLE_YYABORT;
4360
4803
           }
4361
 
           /* SHOW TABLES */
4362
4804
         | TABLES opt_db show_wild
4363
4805
           {
4364
 
             if (not show::buildTables(YYSession, $2))
4365
 
               DRIZZLE_YYABORT;
 
4806
             LEX *lex= Lex;
 
4807
             Session *session= YYSession;
 
4808
 
 
4809
             lex->sql_command= SQLCOM_SELECT;
 
4810
 
 
4811
             statement::Select *select=
 
4812
               new(std::nothrow) statement::Select(YYSession);
 
4813
 
 
4814
             lex->statement= select;
 
4815
 
 
4816
             if (lex->statement == NULL)
 
4817
               DRIZZLE_YYABORT;
 
4818
 
 
4819
 
 
4820
              std::string column_name= "Tables_in_";
 
4821
 
 
4822
              if ($2)
 
4823
              {
 
4824
                SchemaIdentifier identifier($2);
 
4825
                column_name.append($2);
 
4826
                lex->select_lex.db= $2;
 
4827
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4828
                {
 
4829
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
4830
                }
 
4831
                select->setShowPredicate($2, "");
 
4832
              }
 
4833
              else if (not session->db.empty())
 
4834
              {
 
4835
                column_name.append(session->db);
 
4836
                select->setShowPredicate(session->db, "");
 
4837
              }
 
4838
              else
 
4839
              {
 
4840
                 my_error(ER_NO_DB_ERROR, MYF(0));
 
4841
              }
 
4842
 
 
4843
 
 
4844
             if (Lex->wild)
 
4845
             {
 
4846
               column_name.append(" (");
 
4847
               column_name.append(Lex->wild->ptr());
 
4848
               column_name.append(")");
 
4849
             }
 
4850
 
 
4851
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
4852
               DRIZZLE_YYABORT;
 
4853
 
 
4854
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4855
             my_field->is_autogenerated_name= false;
 
4856
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4857
 
 
4858
             if (session->add_item_to_list(my_field))
 
4859
               DRIZZLE_YYABORT;
 
4860
 
 
4861
              if (session->add_order_to_list(my_field, true))
 
4862
                DRIZZLE_YYABORT;
4366
4863
           }
4367
 
           /* SHOW TEMPORARY TABLES */
4368
4864
         | TEMPORARY_SYM TABLES show_wild
4369
4865
           {
4370
 
             if (not show::buildTemporaryTables(YYSession))
4371
 
               DRIZZLE_YYABORT;
 
4866
             LEX *lex= Lex;
 
4867
             Session *session= YYSession;
 
4868
 
 
4869
             lex->sql_command= SQLCOM_SELECT;
 
4870
 
 
4871
             statement::Select *select=
 
4872
               new(std::nothrow) statement::Select(YYSession);
 
4873
 
 
4874
             lex->statement= select;
 
4875
 
 
4876
             if (lex->statement == NULL)
 
4877
               DRIZZLE_YYABORT;
 
4878
 
 
4879
 
 
4880
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
 
4881
               DRIZZLE_YYABORT;
 
4882
 
 
4883
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4884
                                                           context,
 
4885
                                                           NULL, NULL, "*")))
 
4886
               DRIZZLE_YYABORT;
 
4887
             (session->lex->current_select->with_wild)++;
 
4888
 
4372
4889
           }
4373
 
           /* SHOW TABLE STATUS */
4374
4890
         | TABLE_SYM STATUS_SYM opt_db show_wild
4375
4891
           {
4376
 
             if (not show::buildTableStatus(YYSession, $3))
4377
 
               DRIZZLE_YYABORT;
 
4892
             LEX *lex= Lex;
 
4893
             lex->sql_command= SQLCOM_SELECT;
 
4894
             statement::Select *select=
 
4895
               new(std::nothrow) statement::Select(YYSession);
 
4896
 
 
4897
             lex->statement= select;
 
4898
 
 
4899
             if (lex->statement == NULL)
 
4900
               DRIZZLE_YYABORT;
 
4901
 
 
4902
             Session *session= YYSession;
 
4903
 
 
4904
             std::string column_name= "Tables_in_";
 
4905
 
 
4906
             if ($3)
 
4907
             {
 
4908
               lex->select_lex.db= $3;
 
4909
 
 
4910
               SchemaIdentifier identifier($3);
 
4911
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4912
               {
 
4913
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
4914
               }
 
4915
 
 
4916
               select->setShowPredicate($3, "");
 
4917
             }
 
4918
             else
 
4919
             {
 
4920
               select->setShowPredicate(session->db, "");
 
4921
             }
 
4922
 
 
4923
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
4924
               DRIZZLE_YYABORT;
 
4925
 
 
4926
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4927
                                                           context,
 
4928
                                                           NULL, NULL, "*")))
 
4929
               DRIZZLE_YYABORT;
 
4930
             (session->lex->current_select->with_wild)++;
4378
4931
           }
4379
 
           /* SHOW COLUMNS FROM table_name */
4380
4932
        | COLUMNS from_or_in table_ident opt_db show_wild
4381
 
           {
4382
 
             if (not show::buildColumns(YYSession, $4, $3))
4383
 
               DRIZZLE_YYABORT;
4384
 
           }
4385
 
          /* SHOW INDEXES from table */
 
4933
          {
 
4934
             LEX *lex= Lex;
 
4935
             Session *session= YYSession;
 
4936
             statement::Select *select;
 
4937
 
 
4938
             lex->sql_command= SQLCOM_SELECT;
 
4939
 
 
4940
             select= new(std::nothrow) statement::Select(session);
 
4941
 
 
4942
             lex->statement= select;
 
4943
 
 
4944
             if (lex->statement == NULL)
 
4945
               DRIZZLE_YYABORT;
 
4946
 
 
4947
             if ($4)
 
4948
              select->setShowPredicate($4, $3->table.str);
 
4949
             else if ($3->db.str)
 
4950
              select->setShowPredicate($3->db.str, $3->table.str);
 
4951
             else
 
4952
              select->setShowPredicate(session->db, $3->table.str);
 
4953
 
 
4954
             {
 
4955
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4956
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4957
               {
 
4958
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
4959
                            select->getShowSchema().c_str(), 
 
4960
                            $3->table.str);
 
4961
               }
 
4962
             }
 
4963
 
 
4964
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
4965
               DRIZZLE_YYABORT;
 
4966
 
 
4967
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4968
                                                           context,
 
4969
                                                           NULL, NULL, "*")))
 
4970
               DRIZZLE_YYABORT;
 
4971
             (session->lex->current_select->with_wild)++;
 
4972
 
 
4973
          }
4386
4974
        | 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
 
           }
 
4975
          {
 
4976
             LEX *lex= Lex;
 
4977
             Session *session= YYSession;
 
4978
             statement::Select *select;
 
4979
 
 
4980
             lex->sql_command= SQLCOM_SELECT;
 
4981
 
 
4982
             select= new(std::nothrow) statement::Select(session);
 
4983
 
 
4984
             lex->statement= select;
 
4985
 
 
4986
             if (lex->statement == NULL)
 
4987
               DRIZZLE_YYABORT;
 
4988
 
 
4989
             if ($4)
 
4990
              select->setShowPredicate($4, $3->table.str);
 
4991
             else if ($3->db.str)
 
4992
              select->setShowPredicate($3->db.str, $3->table.str);
 
4993
             else
 
4994
              select->setShowPredicate(session->db, $3->table.str);
 
4995
 
 
4996
             {
 
4997
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4998
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4999
               {
 
5000
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5001
                            select->getShowSchema().c_str(), 
 
5002
                            $3->table.str);
 
5003
               }
 
5004
             }
 
5005
 
 
5006
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
5007
               DRIZZLE_YYABORT;
 
5008
 
 
5009
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5010
                                                           context,
 
5011
                                                           NULL, NULL, "*")))
 
5012
               DRIZZLE_YYABORT;
 
5013
             (session->lex->current_select->with_wild)++;
 
5014
          }
4391
5015
        | COUNT_SYM '(' '*' ')' WARNINGS
4392
5016
          {
4393
 
            show::buildSelectWarning(YYSession);
 
5017
            (void) create_select_for_variable("warning_count");
 
5018
            LEX *lex= Lex;
 
5019
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5020
            if (lex->statement == NULL)
 
5021
              DRIZZLE_YYABORT;
4394
5022
          }
4395
5023
        | COUNT_SYM '(' '*' ')' ERRORS
4396
5024
          {
4397
 
            show::buildSelectError(YYSession);
 
5025
            (void) create_select_for_variable("error_count");
 
5026
            LEX *lex= Lex;
 
5027
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5028
            if (lex->statement == NULL)
 
5029
              DRIZZLE_YYABORT;
4398
5030
          }
4399
5031
        | WARNINGS opt_limit_clause_init
4400
5032
          {
4401
 
            show::buildWarnings(YYSession);
 
5033
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5034
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
5035
            if (Lex->statement == NULL)
 
5036
              DRIZZLE_YYABORT;
4402
5037
          }
4403
5038
        | ERRORS opt_limit_clause_init
4404
5039
          {
4405
 
            show::buildErrors(YYSession);
 
5040
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5041
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
5042
            if (Lex->statement == NULL)
 
5043
              DRIZZLE_YYABORT;
4406
5044
          }
4407
5045
        | 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
 
          }
4417
 
        | CREATE TABLE_SYM table_ident
4418
 
          {
4419
 
            if (not show::buildCreateTable(YYSession, $3))
4420
 
              DRIZZLE_YYABORT;
4421
 
          }
 
5046
           {
 
5047
             LEX *lex= Lex;
 
5048
             lex->sql_command= SQLCOM_SELECT;
 
5049
             lex->statement=
 
5050
               new(std::nothrow) statement::Select(YYSession);
 
5051
             if (lex->statement == NULL)
 
5052
               DRIZZLE_YYABORT;
 
5053
 
 
5054
             Session *session= YYSession;
 
5055
 
 
5056
             if ($1 == OPT_GLOBAL)
 
5057
             {
 
5058
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5059
                 DRIZZLE_YYABORT;
 
5060
             }
 
5061
             else
 
5062
             {
 
5063
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5064
                 DRIZZLE_YYABORT;
 
5065
             }
 
5066
 
 
5067
             std::string key("Variable_name");
 
5068
             std::string value("Value");
 
5069
 
 
5070
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5071
             my_field->is_autogenerated_name= false;
 
5072
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5073
 
 
5074
             if (session->add_item_to_list(my_field))
 
5075
               DRIZZLE_YYABORT;
 
5076
 
 
5077
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5078
             my_field->is_autogenerated_name= false;
 
5079
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5080
 
 
5081
             if (session->add_item_to_list(my_field))
 
5082
               DRIZZLE_YYABORT;
 
5083
           }
4422
5084
        | PROCESSLIST_SYM
4423
5085
          {
4424
 
            if (not show::buildProcesslist(YYSession))
4425
 
              DRIZZLE_YYABORT;
 
5086
           {
 
5087
             LEX *lex= Lex;
 
5088
             lex->sql_command= SQLCOM_SELECT;
 
5089
             lex->statement=
 
5090
               new(std::nothrow) statement::Select(YYSession);
 
5091
             if (lex->statement == NULL)
 
5092
               DRIZZLE_YYABORT;
 
5093
 
 
5094
             Session *session= YYSession;
 
5095
 
 
5096
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
5097
               DRIZZLE_YYABORT;
 
5098
 
 
5099
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5100
                                                           context,
 
5101
                                                           NULL, NULL, "*")))
 
5102
               DRIZZLE_YYABORT;
 
5103
             (session->lex->current_select->with_wild)++;
 
5104
           }
4426
5105
          }
4427
5106
        | opt_var_type  VARIABLES show_wild
4428
 
          {
4429
 
            if (not show::buildVariables(YYSession, $1))
4430
 
              DRIZZLE_YYABORT;
4431
 
          }
 
5107
           {
 
5108
             LEX *lex= Lex;
 
5109
             lex->sql_command= SQLCOM_SELECT;
 
5110
             lex->statement=
 
5111
               new(std::nothrow) statement::Select(YYSession);
 
5112
             if (lex->statement == NULL)
 
5113
               DRIZZLE_YYABORT;
 
5114
 
 
5115
             Session *session= YYSession;
 
5116
 
 
5117
             if ($1 == OPT_GLOBAL)
 
5118
             {
 
5119
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5120
                 DRIZZLE_YYABORT;
 
5121
             }
 
5122
             else
 
5123
             {
 
5124
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5125
                 DRIZZLE_YYABORT;
 
5126
             }
 
5127
 
 
5128
             std::string key("Variable_name");
 
5129
             std::string value("Value");
 
5130
 
 
5131
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5132
             my_field->is_autogenerated_name= false;
 
5133
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5134
 
 
5135
             if (session->add_item_to_list(my_field))
 
5136
               DRIZZLE_YYABORT;
 
5137
 
 
5138
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5139
             my_field->is_autogenerated_name= false;
 
5140
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5141
 
 
5142
             if (session->add_item_to_list(my_field))
 
5143
               DRIZZLE_YYABORT;
 
5144
           }
4432
5145
        | CREATE DATABASE opt_if_not_exists ident
4433
5146
          {
4434
 
            if (not show::buildCreateSchema(YYSession, $4))
 
5147
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
 
5148
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
 
5149
            Lex->statement= statement;
 
5150
            if (Lex->statement == NULL)
 
5151
              DRIZZLE_YYABORT;
 
5152
            statement->is_if_not_exists= $3;
 
5153
            Lex->name= $4;
 
5154
          }
 
5155
        | CREATE TABLE_SYM table_ident
 
5156
          {
 
5157
            LEX *lex= Lex;
 
5158
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
5159
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
 
5160
            if (lex->statement == NULL)
 
5161
              DRIZZLE_YYABORT;
 
5162
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4435
5163
              DRIZZLE_YYABORT;
4436
5164
          }
4437
5165
 
4466
5194
describe:
4467
5195
          describe_command table_ident
4468
5196
          {
4469
 
            if (not show::buildDescribe(YYSession, $2))
4470
 
            {
 
5197
            Session *session= YYSession;
 
5198
            statement::Select *select;
 
5199
            LEX *lex= Lex;
 
5200
            lex->lock_option= TL_READ;
 
5201
            mysql_init_select(lex);
 
5202
            lex->current_select->parsing_place= SELECT_LIST;
 
5203
            lex->sql_command= SQLCOM_SELECT;
 
5204
            select= new(std::nothrow) statement::Select(session);
 
5205
            lex->statement= select;
 
5206
            if (lex->statement == NULL)
4471
5207
              DRIZZLE_YYABORT;
4472
 
            }
 
5208
            lex->select_lex.db= 0;
 
5209
 
 
5210
             if ($2->db.str)
 
5211
              select->setShowPredicate($2->db.str, $2->table.str);
 
5212
             else
 
5213
              select->setShowPredicate(session->db, $2->table.str);
 
5214
 
 
5215
             {
 
5216
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5217
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5218
               {
 
5219
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5220
                            select->getShowSchema().c_str(), 
 
5221
                            $2->table.str);
 
5222
               }
 
5223
             }
 
5224
 
 
5225
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5226
               DRIZZLE_YYABORT;
 
5227
 
 
5228
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5229
                                                           context,
 
5230
                                                           NULL, NULL, "*")))
 
5231
               DRIZZLE_YYABORT;
 
5232
             (session->lex->current_select->with_wild)++;
 
5233
 
4473
5234
          }
4474
5235
          opt_describe_column {}
4475
5236
        | describe_command opt_extended_describe
4476
5237
          { Lex->describe|= DESCRIBE_NORMAL; }
4477
5238
          select
4478
5239
          {
4479
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5240
            LEX *lex=Lex;
 
5241
            lex->select_lex.options|= SELECT_DESCRIBE;
4480
5242
          }
4481
5243
        ;
4482
5244
 
4507
5269
flush:
4508
5270
          FLUSH_SYM
4509
5271
          {
4510
 
            Lex->statement= new statement::Flush(YYSession);
 
5272
            LEX *lex=Lex;
 
5273
            lex->sql_command= SQLCOM_FLUSH;
 
5274
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5275
            if (lex->statement == NULL)
 
5276
              DRIZZLE_YYABORT;
 
5277
            lex->type= 0;
4511
5278
          }
4512
5279
          flush_options
4513
5280
          {}
4540
5307
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4541
5308
            statement->setFlushStatus(true);
4542
5309
          }
4543
 
        | GLOBAL_SYM STATUS_SYM
4544
 
          {
4545
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4546
 
            statement->setFlushGlobalStatus(true);
4547
 
          }
4548
5310
        ;
4549
5311
 
4550
5312
opt_table_list:
4557
5319
kill:
4558
5320
          KILL_SYM kill_option expr
4559
5321
          {
4560
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5322
            LEX *lex=Lex;
 
5323
            lex->value_list.empty();
 
5324
            lex->value_list.push_front($3);
 
5325
            lex->sql_command= SQLCOM_KILL;
 
5326
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5327
            if (lex->statement == NULL)
 
5328
              DRIZZLE_YYABORT;
4561
5329
          }
4562
5330
        ;
4563
5331
 
4564
5332
kill_option:
4565
 
          /* empty */ { $$= false; }
4566
 
        | CONNECTION_SYM { $$= false; }
4567
 
        | QUERY_SYM      { $$= true; }
 
5333
          /* empty */ { Lex->type= 0; }
 
5334
        | CONNECTION_SYM { Lex->type= 0; }
 
5335
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
4568
5336
        ;
4569
5337
 
4570
5338
/* change database */
4571
5339
 
4572
5340
use:
4573
 
          USE_SYM schema_name
 
5341
          USE_SYM ident
4574
5342
          {
4575
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4576
 
            Lex->select_lex.db= $2.str;
 
5343
            LEX *lex=Lex;
 
5344
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5345
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5346
            if (lex->statement == NULL)
 
5347
              DRIZZLE_YYABORT;
 
5348
            lex->select_lex.db= $2.str;
4577
5349
          }
4578
5350
        ;
4579
5351
 
4582
5354
load:
4583
5355
          LOAD data_file
4584
5356
          {
4585
 
            statement::Load *statement= new statement::Load(YYSession);
4586
 
            Lex->statement= statement;
4587
 
 
4588
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5357
            Session *session= YYSession;
 
5358
            LEX *lex= session->lex;
 
5359
 
 
5360
            lex->sql_command= SQLCOM_LOAD;
 
5361
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5362
            lex->statement= statement;
 
5363
            if (lex->statement == NULL)
 
5364
              DRIZZLE_YYABORT;
 
5365
 
 
5366
            Lex_input_stream *lip= session->m_lip;
4589
5367
            statement->fname_start= lip->get_ptr();
4590
5368
          }
4591
5369
          load_data_lock INFILE TEXT_STRING_filesystem
4592
5370
          {
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)))
 
5371
            LEX *lex=Lex;
 
5372
            lex->lock_option= $4;
 
5373
            lex->duplicates= DUP_ERROR;
 
5374
            lex->ignore= 0;
 
5375
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4597
5376
              DRIZZLE_YYABORT;
4598
5377
          }
4599
5378
          opt_duplicate INTO
4600
5379
          {
4601
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5380
            Session *session= YYSession;
 
5381
            Lex_input_stream *lip= session->m_lip;
4602
5382
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4603
5383
          }
4604
5384
          TABLE_SYM table_ident
4605
5385
          {
 
5386
            LEX *lex=Lex;
4606
5387
            if (!Lex->current_select->add_table_to_list(YYSession,
4607
5388
                    $12, NULL, TL_OPTION_UPDATING,
4608
 
                    Lex->lock_option))
 
5389
                    lex->lock_option))
4609
5390
              DRIZZLE_YYABORT;
4610
 
            Lex->field_list.empty();
4611
 
            Lex->update_list.empty();
4612
 
            Lex->value_list.empty();
 
5391
            lex->field_list.empty();
 
5392
            lex->update_list.empty();
 
5393
            lex->value_list.empty();
4613
5394
          }
4614
5395
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4615
5396
          opt_load_data_set_spec
4633
5414
        | IGNORE_SYM { Lex->ignore= 1; }
4634
5415
        ;
4635
5416
 
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
5417
opt_field_term:
4646
5418
          /* empty */
4647
5419
        | COLUMNS field_term_list
4660
5432
          }
4661
5433
        | OPTIONALLY ENCLOSED BY text_string
4662
5434
          {
4663
 
            assert(Lex->exchange != 0);
4664
 
            Lex->exchange->enclosed= $4;
4665
 
            Lex->exchange->opt_enclosed= 1;
 
5435
            LEX *lex= Lex;
 
5436
            assert(lex->exchange != 0);
 
5437
            lex->exchange->enclosed= $4;
 
5438
            lex->exchange->opt_enclosed= 1;
4666
5439
          }
4667
5440
        | ENCLOSED BY text_string
4668
5441
          {
4727
5500
        ;
4728
5501
 
4729
5502
field_or_var:
4730
 
          simple_ident {$$= $1;}
4731
 
        | '@' user_variable_ident
 
5503
          simple_ident_nospvar {$$= $1;}
 
5504
        | '@' ident_or_text
4732
5505
          { $$= new Item_user_var_as_out_param($2); }
4733
5506
        ;
4734
5507
 
4735
5508
opt_load_data_set_spec:
4736
5509
          /* empty */ {}
4737
 
        | SET_SYM insert_update_list {}
 
5510
        | SET insert_update_list {}
4738
5511
        ;
4739
5512
 
4740
5513
/* Common definitions */
4742
5515
text_literal:
4743
5516
        TEXT_STRING_literal
4744
5517
        {
4745
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5518
          Session *session= YYSession;
 
5519
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4746
5520
        }
4747
5521
        | text_literal TEXT_STRING_literal
4748
5522
          {
4798
5572
            $$ = new Item_null();
4799
5573
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4800
5574
          }
4801
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4802
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5575
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5576
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4803
5577
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4804
5578
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4805
5579
        | DATE_SYM text_literal { $$ = $2; }
4842
5616
**********************************************************************/
4843
5617
 
4844
5618
insert_ident:
4845
 
          simple_ident { $$=$1; }
 
5619
          simple_ident_nospvar { $$=$1; }
4846
5620
        | table_wild { $$=$1; }
4847
5621
        ;
4848
5622
 
4849
5623
table_wild:
4850
5624
          ident '.' '*'
4851
5625
          {
4852
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5626
            Select_Lex *sel= Lex->current_select;
 
5627
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5628
            sel->with_wild++;
4853
5629
          }
4854
5630
        | ident '.' ident '.' '*'
4855
5631
          {
4856
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5632
            Select_Lex *sel= Lex->current_select;
 
5633
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
5634
            sel->with_wild++;
4857
5635
          }
4858
5636
        ;
4859
5637
 
4864
5642
simple_ident:
4865
5643
          ident
4866
5644
          {
4867
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5645
            {
 
5646
              Select_Lex *sel=Lex->current_select;
 
5647
              $$= (sel->parsing_place != IN_HAVING ||
 
5648
                  sel->get_in_sum_expr() > 0) ?
 
5649
                  (Item*) new Item_field(Lex->current_context(),
 
5650
                                         (const char *)NULL, NULL, $1.str) :
 
5651
                  (Item*) new Item_ref(Lex->current_context(),
 
5652
                                       (const char *)NULL, NULL, $1.str);
 
5653
            }
 
5654
          }
 
5655
        | simple_ident_q { $$= $1; }
 
5656
        ;
 
5657
 
 
5658
simple_ident_nospvar:
 
5659
          ident
 
5660
          {
 
5661
            Select_Lex *sel=Lex->current_select;
 
5662
            $$= (sel->parsing_place != IN_HAVING ||
 
5663
                sel->get_in_sum_expr() > 0) ?
 
5664
                (Item*) new Item_field(Lex->current_context(),
 
5665
                                       (const char *)NULL, NULL, $1.str) :
 
5666
                (Item*) new Item_ref(Lex->current_context(),
 
5667
                                     (const char *)NULL, NULL, $1.str);
4868
5668
          }
4869
5669
        | simple_ident_q { $$= $1; }
4870
5670
        ;
4872
5672
simple_ident_q:
4873
5673
          ident '.' ident
4874
5674
          {
4875
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5675
            Session *session= YYSession;
 
5676
            LEX *lex= session->lex;
 
5677
 
 
5678
            {
 
5679
              Select_Lex *sel= lex->current_select;
 
5680
              if (sel->no_table_names_allowed)
 
5681
              {
 
5682
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5683
                         MYF(0), $1.str, session->where);
 
5684
              }
 
5685
              $$= (sel->parsing_place != IN_HAVING ||
 
5686
                  sel->get_in_sum_expr() > 0) ?
 
5687
                  (Item*) new Item_field(Lex->current_context(),
 
5688
                                         (const char *)NULL, $1.str, $3.str) :
 
5689
                  (Item*) new Item_ref(Lex->current_context(),
 
5690
                                       (const char *)NULL, $1.str, $3.str);
 
5691
            }
4876
5692
          }
4877
5693
        | '.' ident '.' ident
4878
5694
          {
4879
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5695
            Session *session= YYSession;
 
5696
            LEX *lex= session->lex;
 
5697
            Select_Lex *sel= lex->current_select;
 
5698
            if (sel->no_table_names_allowed)
 
5699
            {
 
5700
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5701
                       MYF(0), $2.str, session->where);
 
5702
            }
 
5703
            $$= (sel->parsing_place != IN_HAVING ||
 
5704
                sel->get_in_sum_expr() > 0) ?
 
5705
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5706
                (Item*) new Item_ref(Lex->current_context(),
 
5707
                                     (const char *)NULL, $2.str, $4.str);
4880
5708
          }
4881
5709
        | ident '.' ident '.' ident
4882
5710
          {
4883
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5711
            Session *session= YYSession;
 
5712
            LEX *lex= session->lex;
 
5713
            Select_Lex *sel= lex->current_select;
 
5714
            if (sel->no_table_names_allowed)
 
5715
            {
 
5716
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5717
                       MYF(0), $3.str, session->where);
 
5718
            }
 
5719
            $$= (sel->parsing_place != IN_HAVING ||
 
5720
                sel->get_in_sum_expr() > 0) ?
 
5721
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5722
                                       $5.str) :
 
5723
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5724
                                     $5.str);
4884
5725
          }
4885
5726
        ;
4886
5727
 
4887
5728
field_ident:
4888
 
          ident 
4889
 
          {
4890
 
            $$=$1;
4891
 
          }
 
5729
          ident { $$=$1;}
4892
5730
        | ident '.' ident '.' ident
4893
5731
          {
4894
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4895
 
              DRIZZLE_YYABORT;
4896
 
 
 
5732
            TableList *table=
 
5733
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5734
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5735
            {
 
5736
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5737
              DRIZZLE_YYABORT;
 
5738
            }
 
5739
            if (my_strcasecmp(table_alias_charset, $3.str,
 
5740
                              table->table_name))
 
5741
            {
 
5742
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
5743
              DRIZZLE_YYABORT;
 
5744
            }
4897
5745
            $$=$5;
4898
5746
          }
4899
5747
        | ident '.' ident
4900
5748
          {
4901
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5749
            TableList *table=
 
5750
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5751
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
5752
            {
 
5753
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
5754
              DRIZZLE_YYABORT;
4903
 
 
 
5755
            }
4904
5756
            $$=$3;
4905
5757
          }
4906
 
        | '.' ident 
4907
 
          { /* For Delphi */
4908
 
            $$=$2;
4909
 
          }
 
5758
        | '.' ident { $$=$2;} /* For Delphi */
4910
5759
        ;
4911
5760
 
4912
5761
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
 
5762
          ident { $$=new Table_ident($1); }
 
5763
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
5764
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4933
5765
        ;
4934
5766
 
4935
5767
IDENT_sys:
4936
 
          IDENT 
4937
 
          {
4938
 
            $$= $1;
4939
 
          }
 
5768
          IDENT { $$= $1; }
4940
5769
        | IDENT_QUOTED
4941
5770
          {
4942
5771
            const CHARSET_INFO * const cs= system_charset_info;
4979
5808
          IDENT_sys    { $$=$1; }
4980
5809
        | keyword
4981
5810
          {
4982
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
5811
            Session *session= YYSession;
 
5812
            $$.str= session->strmake($1.str, $1.length);
4983
5813
            $$.length= $1.length;
4984
5814
          }
4985
5815
        ;
4986
5816
 
4987
5817
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          {}
 
5818
          ident           { $$=$1;}
 
5819
        | TEXT_STRING_sys { $$=$1;}
 
5820
        | LEX_HOSTNAME { $$=$1;}
5001
5821
        ;
5002
5822
 
5003
5823
/* Keyword that we allow for identifiers (except SP labels) */
5004
5824
keyword:
5005
5825
          keyword_sp            {}
5006
5826
        | BEGIN_SYM             {}
 
5827
        | BYTE_SYM              {}
5007
5828
        | CHECKSUM_SYM          {}
5008
5829
        | CLOSE_SYM             {}
5009
5830
        | COMMENT_SYM           {}
5010
5831
        | COMMIT_SYM            {}
5011
5832
        | CONTAINS_SYM          {}
5012
5833
        | DEALLOCATE_SYM        {}
5013
 
        | DO_SYM                {}
5014
5834
        | END                   {}
5015
5835
        | FLUSH_SYM             {}
5016
5836
        | NO_SYM                {}
5019
5839
        | SAVEPOINT_SYM         {}
5020
5840
        | SECURITY_SYM          {}
5021
5841
        | SERVER_SYM            {}
5022
 
        | SIGNED_SYM            {}
5023
5842
        | START_SYM             {}
5024
5843
        | STOP_SYM              {}
5025
5844
        | TRUNCATE_SYM          {}
5039
5858
        | ANY_SYM                  {}
5040
5859
        | AT_SYM                   {}
5041
5860
        | AUTO_INC                 {}
 
5861
        | AVG_ROW_LENGTH           {}
5042
5862
        | AVG_SYM                  {}
5043
5863
        | BIT_SYM                  {}
5044
5864
        | BOOL_SYM                 {}
5048
5868
        | CHAIN_SYM                {}
5049
5869
        | COALESCE                 {}
5050
5870
        | COLLATION_SYM            {}
 
5871
        | COLUMN_FORMAT_SYM        {}
5051
5872
        | COLUMNS                  {}
5052
5873
        | COMMITTED_SYM            {}
5053
5874
        | COMPACT_SYM              {}
5054
5875
        | COMPRESSED_SYM           {}
5055
5876
        | CONCURRENT               {}
5056
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
5877
        | CONNECTION_SYM           {}
5057
5878
        | CONSISTENT_SYM           {}
5058
5879
        | CUBE_SYM                 {}
5059
5880
        | DATA_SYM                 {}
5060
5881
        | DATABASES                {}
 
5882
        | DATAFILE_SYM             {}
5061
5883
        | DATETIME_SYM             {}
5062
 
        | DATE_SYM                 {} /* Create conflict */
 
5884
        | DATE_SYM                 {}
5063
5885
        | DAY_SYM                  {}
5064
5886
        | DISABLE_SYM              {}
5065
5887
        | DISCARD                  {}
5090
5912
        | KEY_BLOCK_SIZE           {}
5091
5913
        | LAST_SYM                 {}
5092
5914
        | LEVEL_SYM                {}
 
5915
        | LIST_SYM                 {}
5093
5916
        | LOCAL_SYM                {}
5094
5917
        | LOCKS_SYM                {}
5095
5918
        | LOGS_SYM                 {}
 
5919
        | MAX_ROWS                 {}
 
5920
        | MAX_SIZE_SYM             {}
5096
5921
        | MAX_VALUE_SYM            {}
5097
5922
        | MEDIUM_SYM               {}
5098
5923
        | MERGE_SYM                {}
5099
5924
        | MICROSECOND_SYM          {}
5100
5925
        | MINUTE_SYM               {}
 
5926
        | MIN_ROWS                 {}
5101
5927
        | MODIFY_SYM               {}
5102
5928
        | MODE_SYM                 {}
5103
5929
        | MONTH_SYM                {}
5112
5938
        | ONE_SHOT_SYM             {}
5113
5939
        | ONE_SYM                  {}
5114
5940
        | ONLINE_SYM               {}
 
5941
        | PAGE_SYM                 {}
5115
5942
        | PARTIAL                  {}
 
5943
        | PHASE_SYM                {}
5116
5944
        | PREV_SYM                 {}
5117
5945
        | PROCESS                  {}
5118
5946
        | PROCESSLIST_SYM          {}
5119
5947
        | QUARTER_SYM              {}
5120
 
        | QUERY_SYM                {} // Causes conflict
 
5948
        | QUERY_SYM                {}
 
5949
        | READ_ONLY_SYM            {}
5121
5950
        | REDUNDANT_SYM            {}
5122
5951
        | REPEATABLE_SYM           {}
5123
5952
        | RETURNS_SYM              {}
 
5953
        | REVERSE_SYM              {}
5124
5954
        | ROLLUP_SYM               {}
5125
5955
        | ROUTINE_SYM              {}
5126
5956
        | ROWS_SYM                 {}
5133
5963
        | SIMPLE_SYM               {}
5134
5964
        | SHARE_SYM                {}
5135
5965
        | SNAPSHOT_SYM             {}
 
5966
        | SQL_BUFFER_RESULT        {}
5136
5967
        | STATUS_SYM               {}
 
5968
        | STORAGE_SYM              {}
5137
5969
        | STRING_SYM               {}
5138
5970
        | SUBDATE_SYM              {}
5139
5971
        | SUBJECT_SYM              {}
5140
5972
        | SUSPEND_SYM              {}
 
5973
        | SWAPS_SYM                {}
 
5974
        | SWITCHES_SYM             {}
5141
5975
        | TABLES                   {}
5142
5976
        | TABLESPACE               {}
5143
5977
        | TEMPORARY_SYM            {}
5144
5978
        | TEXT_SYM                 {}
5145
5979
        | TRANSACTION_SYM          {}
5146
 
        | TIME_SYM                 {}
 
5980
        | TIMESTAMP_SYM            {}
5147
5981
        | TIMESTAMP_ADD            {}
5148
5982
        | TIMESTAMP_DIFF           {}
 
5983
        | TYPES_SYM                {}
5149
5984
        | TYPE_SYM                 {}
5150
5985
        | UNCOMMITTED_SYM          {}
5151
5986
        | UNDOFILE_SYM             {}
5152
5987
        | UNKNOWN_SYM              {}
5153
 
        | UUID_SYM                 {}
5154
5988
        | USER                     {}
5155
5989
        | VARIABLES                {}
5156
5990
        | VALUE_SYM                {}
5163
5997
/* Option functions */
5164
5998
 
5165
5999
set:
5166
 
          SET_SYM opt_option
 
6000
          SET opt_option
5167
6001
          {
5168
 
            Lex->statement= new statement::SetOption(YYSession);
 
6002
            LEX *lex=Lex;
 
6003
            lex->sql_command= SQLCOM_SET_OPTION;
 
6004
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
6005
            lex->statement= statement;
 
6006
            if (lex->statement == NULL)
 
6007
              DRIZZLE_YYABORT;
 
6008
            mysql_init_select(lex);
 
6009
            lex->option_type=OPT_SESSION;
 
6010
            lex->var_list.empty();
5169
6011
          }
5170
6012
          option_value_list
5171
6013
          {}
5182
6024
        ;
5183
6025
 
5184
6026
option_type_value:
5185
 
          { }
 
6027
          {
 
6028
          }
5186
6029
          ext_option_value
5187
 
          { }
 
6030
          {
 
6031
          }
5188
6032
        ;
5189
6033
 
5190
6034
option_type:
5221
6065
sys_option_value:
5222
6066
          option_type internal_variable_name equal set_expr_or_default
5223
6067
          {
 
6068
            LEX *lex=Lex;
 
6069
 
5224
6070
            if ($2.var)
5225
6071
            { /* System variable */
5226
6072
              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)));
 
6073
                lex->option_type= $1;
 
6074
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6075
                                      &$2.base_name, $4));
5231
6076
            }
5232
6077
          }
5233
6078
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5234
6079
          {
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))));
 
6080
            LEX *lex=Lex;
 
6081
            lex->option_type= $1;
 
6082
            lex->var_list.push_back(new set_var(lex->option_type,
 
6083
                                                find_sys_var(YYSession, "tx_isolation"),
 
6084
                                                &null_lex_str,
 
6085
                                                new Item_int((int32_t) $5)));
5241
6086
          }
5242
6087
        ;
5243
6088
 
5244
6089
option_value:
5245
 
          '@' user_variable_ident equal expr
 
6090
          '@' ident_or_text equal expr
5246
6091
          {
5247
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6092
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5248
6093
          }
5249
6094
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5250
6095
          {
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; }
 
6096
            LEX *lex=Lex;
 
6097
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6098
          }
5268
6099
        ;
5269
6100
 
5270
6101
internal_variable_name:
5271
 
          internal_variable_ident
 
6102
          ident
5272
6103
          {
 
6104
            Session *session= YYSession;
 
6105
 
5273
6106
            /* We have to lookup here since local vars can shadow sysvars */
5274
6107
            {
5275
6108
              /* Not an SP local variable */
5276
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6109
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
5277
6110
              if (!tmp)
5278
6111
                DRIZZLE_YYABORT;
5279
6112
              $$.var= tmp;
5305
6138
unlock:
5306
6139
          UNLOCK_SYM
5307
6140
          {
5308
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6141
            LEX *lex= Lex;
 
6142
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6143
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6144
            if (lex->statement == NULL)
 
6145
              DRIZZLE_YYABORT;
5309
6146
          }
5310
6147
          table_or_tables
5311
6148
          {}
5314
6151
begin:
5315
6152
          BEGIN_SYM
5316
6153
          {
5317
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6154
            LEX *lex=Lex;
 
6155
            lex->sql_command = SQLCOM_BEGIN;
 
6156
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6157
            if (lex->statement == NULL)
 
6158
              DRIZZLE_YYABORT;
5318
6159
          }
5319
6160
          opt_work {}
5320
6161
        ;
5346
6187
commit:
5347
6188
          COMMIT_SYM opt_work opt_chain opt_release
5348
6189
          {
5349
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6190
            LEX *lex=Lex;
 
6191
            lex->sql_command= SQLCOM_COMMIT;
 
6192
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6193
            lex->statement= statement;
 
6194
            if (lex->statement == NULL)
 
6195
              DRIZZLE_YYABORT;
 
6196
            statement->tx_chain= $3;
 
6197
            statement->tx_release= $4;
5350
6198
          }
5351
6199
        ;
5352
6200
 
5353
6201
rollback:
5354
6202
          ROLLBACK_SYM opt_work opt_chain opt_release
5355
6203
          {
5356
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6204
            LEX *lex=Lex;
 
6205
            lex->sql_command= SQLCOM_ROLLBACK;
 
6206
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6207
            lex->statement= statement;
 
6208
            if (lex->statement == NULL)
 
6209
              DRIZZLE_YYABORT;
 
6210
            statement->tx_chain= $3;
 
6211
            statement->tx_release= $4;
5357
6212
          }
5358
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6213
        | ROLLBACK_SYM opt_work
 
6214
          TO_SYM opt_savepoint ident
5359
6215
          {
5360
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6216
            LEX *lex=Lex;
 
6217
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6218
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6219
            if (lex->statement == NULL)
 
6220
              DRIZZLE_YYABORT;
 
6221
            lex->ident= $5;
5361
6222
          }
5362
6223
        ;
5363
6224
 
5364
6225
savepoint:
5365
 
          SAVEPOINT_SYM savepoint_ident
 
6226
          SAVEPOINT_SYM ident
5366
6227
          {
5367
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6228
            LEX *lex=Lex;
 
6229
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6230
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6231
            if (lex->statement == NULL)
 
6232
              DRIZZLE_YYABORT;
 
6233
            lex->ident= $2;
5368
6234
          }
5369
6235
        ;
5370
6236
 
5371
6237
release:
5372
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6238
          RELEASE_SYM SAVEPOINT_SYM ident
5373
6239
          {
5374
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6240
            LEX *lex=Lex;
 
6241
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6242
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6243
            if (lex->statement == NULL)
 
6244
              DRIZZLE_YYABORT;
 
6245
            lex->ident= $3;
5375
6246
          }
5376
6247
        ;
5377
6248
 
5378
 
savepoint_ident:
5379
 
               IDENT_sys
5380
 
               ;
5381
 
 
5382
6249
/*
5383
6250
   UNIONS : glue selects together
5384
6251
*/
5392
6259
union_list:
5393
6260
          UNION_SYM union_option
5394
6261
          {
5395
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6262
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5396
6263
              DRIZZLE_YYABORT;
5397
6264
          }
5398
6265
          select_init
5413
6280
 
5414
6281
union_order_or_limit:
5415
6282
          {
5416
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5417
 
            Select_Lex *sel= Lex->current_select;
 
6283
            Session *session= YYSession;
 
6284
            LEX *lex= session->lex;
 
6285
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6286
            Select_Lex *sel= lex->current_select;
5418
6287
            Select_Lex_Unit *unit= sel->master_unit();
5419
6288
            Select_Lex *fake= unit->fake_select_lex;
5420
6289
            if (fake)
5421
6290
            {
5422
6291
              unit->global_parameters= fake;
5423
6292
              fake->no_table_names_allowed= 1;
5424
 
              Lex->current_select= fake;
 
6293
              lex->current_select= fake;
5425
6294
            }
5426
 
            YYSession->setWhere("global ORDER clause");
 
6295
            session->where= "global ORDER clause";
5427
6296
          }
5428
6297
          order_or_limit
5429
6298
          {
5430
 
            YYSession->lex->current_select->no_table_names_allowed= 0;
5431
 
            YYSession->setWhere("");
 
6299
            Session *session= YYSession;
 
6300
            session->lex->current_select->no_table_names_allowed= 0;
 
6301
            session->where= "";
5432
6302
          }
5433
6303
        ;
5434
6304
 
5459
6329
        | query_expression_body
5460
6330
          UNION_SYM union_option
5461
6331
          {
5462
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6332
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5463
6333
              DRIZZLE_YYABORT;
5464
6334
          }
5465
6335
          query_specification
5479
6349
 
5480
6350
subselect_start:
5481
6351
          {
5482
 
            if (not Lex->expr_allows_subselect)
 
6352
            LEX *lex=Lex;
 
6353
            if (!lex->expr_allows_subselect)
5483
6354
            {
5484
 
              parser::my_parse_error(YYSession->m_lip);
 
6355
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6356
              my_parse_error(&pass);
5485
6357
              DRIZZLE_YYABORT;
5486
6358
            }
5487
6359
            /*
5491
6363
              (SELECT .. ) UNION ...  becomes
5492
6364
              SELECT * FROM ((SELECT ...) UNION ...)
5493
6365
            */
5494
 
            if (new_select(Lex, 1))
 
6366
            if (mysql_new_select(Lex, 1))
5495
6367
              DRIZZLE_YYABORT;
5496
6368
          }
5497
6369
        ;
5498
6370
 
5499
6371
subselect_end:
5500
6372
          {
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;
 
6373
            LEX *lex=Lex;
 
6374
            lex->pop_context();
 
6375
            Select_Lex *child= lex->current_select;
 
6376
            lex->current_select = lex->current_select->return_after_parsing();
 
6377
            lex->nest_level--;
 
6378
            lex->current_select->n_child_sum_items += child->n_sum_items;
5506
6379
            /*
5507
6380
              A subselect can add fields to an outer select. Reserve space for
5508
6381
              them.
5509
6382
            */
5510
 
            Lex->current_select->select_n_where_fields+=
 
6383
            lex->current_select->select_n_where_fields+=
5511
6384
            child->select_n_where_fields;
5512
6385
          }
5513
6386
        ;