~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

Fix merge issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
** The type will be void*, so it must be  cast to (Session*) when used.
26
26
** Use the YYSession macro for this.
27
27
*/
28
 
 
29
 
#define YYSession (session)
 
28
#define YYPARSE_PARAM yysession
 
29
#define YYLEX_PARAM yysession
 
30
#define YYSession (static_cast<Session *>(yysession))
30
31
 
31
32
#define YYENABLE_NLS 0
32
33
#define YYLTYPE_IS_TRIVIAL 0
33
34
 
 
35
#define DRIZZLE_YACC
34
36
#define YYINITDEPTH 100
35
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
36
 
#define Lex (session->getLex())
 
38
#define Lex (YYSession->lex)
37
39
 
38
 
#include <config.h>
 
40
#include "config.h"
39
41
#include <cstdio>
40
 
#include <drizzled/parser.h>
 
42
#include "drizzled/parser.h"
41
43
 
42
 
int yylex(union ParserType *yylval, drizzled::Session *session);
 
44
int yylex(void *yylval, void *yysession);
43
45
 
44
46
#define yyoverflow(A,B,C,D,E,F)               \
45
47
  {                                           \
46
 
    unsigned long val= *(F);                          \
 
48
    ulong val= *(F);                          \
47
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
48
50
    {                                         \
49
 
      yyerror(NULL, (char*) (A));                   \
 
51
      yyerror((char*) (A));                   \
50
52
      return 2;                               \
51
53
    }                                         \
52
54
    else                                      \
58
60
#define DRIZZLE_YYABORT                         \
59
61
  do                                          \
60
62
  {                                           \
 
63
    LEX::cleanup_lex_after_parse_error(YYSession);\
61
64
    YYABORT;                                  \
62
65
  } while (0)
63
66
 
64
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
65
68
  if (!(A))                             \
66
69
  {                                     \
67
 
    parser::my_parse_error(YYSession->m_lip);\
 
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    my_parse_error(&pass);\
68
72
    DRIZZLE_YYABORT;                      \
69
73
  }
70
74
 
 
75
 
 
76
#define YYDEBUG 0
 
77
 
71
78
namespace drizzled
72
79
{
73
80
 
75
82
class Item;
76
83
class Item_num;
77
84
 
78
 
namespace item
79
 
{
80
 
class Boolean;
81
 
class True;
82
 
class False;
83
 
}
84
 
 
 
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
}
85
126
 
86
127
/**
87
128
  @brief Bison callback to report a syntax/OOM error
98
139
 
99
140
  This function is not for use in semantic actions and is internal to
100
141
  the parser, as it performs some pre-return cleanup.
101
 
  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
102
143
  push an error into the error stack and DRIZZLE_YYABORT
103
144
  to abort from the parser.
104
145
*/
105
146
 
106
 
static void base_sql_error(drizzled::Session *session, const char *s)
107
 
{
108
 
  parser::errorOn(session, s);
 
147
static void DRIZZLEerror(const char *s)
 
148
{
 
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;
109
333
}
110
334
 
111
335
} /* namespace drizzled; */
112
336
 
113
337
using namespace drizzled;
114
338
%}
115
 
%union ParserType {
116
 
  bool boolean;
 
339
%union {
117
340
  int  num;
118
 
  unsigned long ulong_num;
 
341
  ulong ulong_num;
119
342
  uint64_t ulonglong_number;
120
343
  int64_t longlong_number;
121
344
  drizzled::LEX_STRING lex_str;
131
354
  drizzled::Key_part_spec *key_part;
132
355
  const drizzled::plugin::Function *udf;
133
356
  drizzled::TableList *table_list;
134
 
  drizzled::enum_field_types field_val;
135
 
  drizzled::sys_var_with_base variable;
136
 
  drizzled::sql_var_t var_type;
 
357
  struct drizzled::sys_var_with_base variable;
 
358
  enum drizzled::sql_var_t var_type;
137
359
  drizzled::Key::Keytype key_type;
138
 
  drizzled::ha_key_alg key_alg;
139
 
  drizzled::ha_rkey_function ha_rkey_mode;
140
 
  drizzled::enum_tx_isolation tx_isolation;
141
 
  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;
142
365
  const drizzled::CHARSET_INFO *charset;
143
366
  drizzled::thr_lock_type lock_type;
144
367
  drizzled::interval_type interval, interval_time_st;
145
 
  drizzled::type::timestamp_t date_time_type;
 
368
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
146
369
  drizzled::Select_Lex *select_lex;
147
370
  drizzled::chooser_compare_func_creator boolfunc2creator;
148
 
  drizzled::st_lex *lex;
149
 
  drizzled::index_hint_type index_hint;
150
 
  drizzled::enum_filetype filetype;
151
 
  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;
152
375
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
153
 
  drizzled::execute_string_t execute_string;
154
376
}
155
377
 
156
378
%{
157
379
namespace drizzled
158
380
{
159
 
bool my_yyoverflow(short **a, union ParserType **b, unsigned long *yystacksize);
 
381
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
160
382
}
161
383
%}
162
384
 
163
 
%debug
164
 
%require "2.2"
165
 
%pure-parser
166
 
%name-prefix="base_sql_"
167
 
%parse-param { drizzled::Session *session }
168
 
%lex-param { drizzled::Session *session }
169
 
%verbose
170
 
 
171
 
 
 
385
%pure_parser                                    /* We have threads */
172
386
/*
173
 
  Currently there are 70 shift/reduce conflicts.
 
387
  Currently there are 88 shift/reduce conflicts.
174
388
  We should not introduce new conflicts any more.
175
389
*/
176
 
%expect 70
 
390
%expect 94
177
391
 
178
392
/*
179
393
   Comments for TOKENS.
194
408
 
195
409
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
196
410
%token  ACTION                        /* SQL-2003-N */
197
 
%token  ADD_SYM                           /* SQL-2003-R */
 
411
%token  ADD                           /* SQL-2003-R */
198
412
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
199
413
%token  AFTER_SYM                     /* SQL-2003-N */
200
414
%token  AGGREGATE_SYM
201
415
%token  ALL                           /* SQL-2003-R */
202
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
416
%token  ALTER                         /* SQL-2003-R */
203
417
%token  ANALYZE_SYM
204
418
%token  AND_SYM                       /* SQL-2003-R */
205
419
%token  ANY_SYM                       /* SQL-2003-R */
208
422
%token  ASENSITIVE_SYM                /* FUTURE-USE */
209
423
%token  AT_SYM                        /* SQL-2003-R */
210
424
%token  AUTO_INC
 
425
%token  AVG_ROW_LENGTH
211
426
%token  AVG_SYM                       /* SQL-2003-N */
212
427
%token  BEFORE_SYM                    /* SQL-2003-N */
213
428
%token  BEGIN_SYM                     /* SQL-2003-R */
222
437
%token  BOTH                          /* SQL-2003-R */
223
438
%token  BTREE_SYM
224
439
%token  BY                            /* SQL-2003-R */
 
440
%token  BYTE_SYM
225
441
%token  CALL_SYM                      /* SQL-2003-R */
226
442
%token  CASCADE                       /* SQL-2003-N */
227
443
%token  CASCADED                      /* SQL-2003-R */
228
444
%token  CASE_SYM                      /* SQL-2003-R */
229
445
%token  CAST_SYM                      /* SQL-2003-R */
230
 
%token  CATALOG_SYM
231
446
%token  CHAIN_SYM                     /* SQL-2003-N */
232
 
%token  CHANGE_SYM
 
447
%token  CHANGE
233
448
%token  CHAR_SYM                      /* SQL-2003-R */
234
449
%token  CHECKSUM_SYM
235
450
%token  CHECK_SYM                     /* SQL-2003-R */
250
465
%token  CONSISTENT_SYM
251
466
%token  CONSTRAINT                    /* SQL-2003-R */
252
467
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
468
%token  CONTINUE_SYM                  /* SQL-2003-R */
253
469
%token  CONVERT_SYM                   /* SQL-2003-N */
254
470
%token  COUNT_SYM                     /* SQL-2003-N */
255
471
%token  CREATE                        /* SQL-2003-R */
260
476
%token  CURSOR_SYM                    /* SQL-2003-R */
261
477
%token  DATABASE
262
478
%token  DATABASES
 
479
%token  DATAFILE_SYM
263
480
%token  DATA_SYM                      /* SQL-2003-N */
264
481
%token  DATETIME_SYM
265
482
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
283
500
%token  DISCARD
284
501
%token  DISTINCT                      /* SQL-2003-R */
285
502
%token  DIV_SYM
286
 
%token  DO_SYM
287
503
%token  DOUBLE_SYM                    /* SQL-2003-R */
288
504
%token  DROP                          /* SQL-2003-R */
289
505
%token  DUMPFILE
291
507
%token  DYNAMIC_SYM                   /* SQL-2003-R */
292
508
%token  EACH_SYM                      /* SQL-2003-R */
293
509
%token  ELSE                          /* SQL-2003-R */
 
510
%token  ELSEIF_SYM
294
511
%token  ENABLE_SYM
295
512
%token  ENCLOSED
296
513
%token  END                           /* SQL-2003-R */
298
515
%token  END_OF_INPUT                  /* INTERNAL */
299
516
%token  ENGINE_SYM
300
517
%token  ENUM_SYM
 
518
%token  EQ                            /* OPERATOR */
301
519
%token  EQUAL_SYM                     /* OPERATOR */
302
520
%token  ERRORS
303
521
%token  ESCAPED
304
522
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
523
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
 
524
%token  EXECUTE_SYM
307
525
%token  EXISTS                        /* SQL-2003-R */
308
526
%token  EXTENDED_SYM
309
527
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
528
%token  FALSE_SYM                     /* SQL-2003-R */
 
529
%token  FETCH_SYM                     /* SQL-2003-R */
 
530
%token  COLUMN_FORMAT_SYM
311
531
%token  FILE_SYM
312
532
%token  FIRST_SYM                     /* SQL-2003-N */
313
533
%token  FIXED_SYM
324
544
%token  GLOBAL_SYM                    /* SQL-2003-R */
325
545
%token  GROUP_SYM                     /* SQL-2003-R */
326
546
%token  GROUP_CONCAT_SYM
 
547
%token  GT_SYM                        /* OPERATOR */
327
548
%token  HASH_SYM
328
549
%token  HAVING                        /* SQL-2003-R */
329
550
%token  HEX_NUM
333
554
%token  HOUR_SYM                      /* SQL-2003-R */
334
555
%token  IDENT
335
556
%token  IDENTIFIED_SYM
336
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
337
557
%token  IDENT_QUOTED
338
558
%token  IF
339
559
%token  IGNORE_SYM
366
586
%token  LIKE                          /* SQL-2003-R */
367
587
%token  LIMIT
368
588
%token  LINES
 
589
%token  LIST_SYM
369
590
%token  LOAD
370
591
%token  LOCAL_SYM                     /* SQL-2003-R */
 
592
%token  LOCATOR_SYM                   /* SQL-2003-N */
371
593
%token  LOCKS_SYM
372
594
%token  LOCK_SYM
373
595
%token  LOGS_SYM
374
596
%token  LONG_NUM
375
597
%token  LONG_SYM
 
598
%token  LOOP_SYM
 
599
%token  LT                            /* OPERATOR */
376
600
%token  MATCH                         /* SQL-2003-R */
 
601
%token  MAX_ROWS
 
602
%token  MAX_SIZE_SYM
377
603
%token  MAX_SYM                       /* SQL-2003-N */
378
604
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
379
605
%token  MEDIUM_SYM
382
608
%token  MINUTE_MICROSECOND_SYM
383
609
%token  MINUTE_SECOND_SYM
384
610
%token  MINUTE_SYM                    /* SQL-2003-R */
 
611
%token  MIN_ROWS
385
612
%token  MIN_SYM                       /* SQL-2003-N */
386
613
%token  MODE_SYM
387
614
%token  MODIFIES_SYM                  /* SQL-2003-R */
393
620
%token  NATIONAL_SYM                  /* SQL-2003-R */
394
621
%token  NATURAL                       /* SQL-2003-R */
395
622
%token  NE                            /* OPERATOR */
 
623
%token  NEG
396
624
%token  NEW_SYM                       /* SQL-2003-R */
397
625
%token  NEXT_SYM                      /* SQL-2003-N */
398
626
%token  NONE_SYM                      /* SQL-2003-R */
417
645
%token  OUTER
418
646
%token  OUTFILE
419
647
%token  OUT_SYM                       /* SQL-2003-R */
 
648
%token  PAGE_SYM
420
649
%token  PARTIAL                       /* SQL-2003-N */
 
650
%token  PHASE_SYM
421
651
%token  POSITION_SYM                  /* SQL-2003-N */
422
652
%token  PRECISION                     /* SQL-2003-R */
423
653
%token  PREV_SYM
428
658
%token  QUERY_SYM
429
659
%token  RANGE_SYM                     /* SQL-2003-R */
430
660
%token  READS_SYM                     /* SQL-2003-R */
 
661
%token  READ_ONLY_SYM
431
662
%token  READ_SYM                      /* SQL-2003-N */
432
663
%token  READ_WRITE_SYM
433
664
%token  REAL                          /* SQL-2003-R */
434
665
%token  REDUNDANT_SYM
435
 
%token  REGEXP_SYM
436
666
%token  REFERENCES                    /* SQL-2003-R */
437
667
%token  RELEASE_SYM                   /* SQL-2003-R */
438
668
%token  RENAME
439
669
%token  REPEATABLE_SYM                /* SQL-2003-N */
440
670
%token  REPEAT_SYM                    /* MYSQL-FUNC */
441
671
%token  REPLACE                       /* MYSQL-FUNC */
442
 
%token  REPLICATION
443
672
%token  RESTRICT
444
673
%token  RETURNS_SYM                   /* SQL-2003-R */
445
674
%token  RETURN_SYM                    /* SQL-2003-R */
 
675
%token  REVERSE_SYM
446
676
%token  REVOKE                        /* SQL-2003-R */
447
677
%token  RIGHT                         /* SQL-2003-R */
448
678
%token  ROLLBACK_SYM                  /* SQL-2003-R */
462
692
%token  SERIAL_SYM
463
693
%token  SESSION_SYM                   /* SQL-2003-N */
464
694
%token  SERVER_SYM
465
 
%token  SET_SYM                           /* SQL-2003-R */
 
695
%token  SERVER_OPTIONS
 
696
%token  SET                           /* SQL-2003-R */
466
697
%token  SET_VAR
467
698
%token  SHARE_SYM
468
699
%token  SHOW
469
 
%token  SIGNED_SYM
470
700
%token  SIMPLE_SYM                    /* SQL-2003-N */
471
701
%token  SNAPSHOT_SYM
472
702
%token  SPECIFIC_SYM                  /* SQL-2003-R */
484
714
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
485
715
%token  STD_SYM
486
716
%token  STOP_SYM
 
717
%token  STORAGE_SYM
487
718
%token  STORED_SYM
488
719
%token  STRAIGHT_JOIN
489
720
%token  STRING_SYM
492
723
%token  SUBSTRING                     /* SQL-2003-N */
493
724
%token  SUM_SYM                       /* SQL-2003-N */
494
725
%token  SUSPEND_SYM
 
726
%token  SWAPS_SYM
 
727
%token  SWITCHES_SYM
495
728
%token  SYSDATE
496
729
%token  TABLES
497
730
%token  TABLESPACE
502
735
%token  TEXT_STRING
503
736
%token  TEXT_SYM
504
737
%token  THEN_SYM                      /* SQL-2003-R */
505
 
%token  TIME_SYM                 /* SQL-2003-R */
506
738
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
507
739
%token  TIMESTAMP_ADD
508
740
%token  TIMESTAMP_DIFF
512
744
%token  TRIM                          /* SQL-2003-N */
513
745
%token  TRUE_SYM                      /* SQL-2003-R */
514
746
%token  TRUNCATE_SYM
 
747
%token  TYPES_SYM
515
748
%token  TYPE_SYM                      /* SQL-2003-N */
516
749
%token  ULONGLONG_NUM
517
750
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
521
754
%token  UNIQUE_SYM
522
755
%token  UNKNOWN_SYM                   /* SQL-2003-R */
523
756
%token  UNLOCK_SYM
524
 
%token  UNSIGNED_SYM
525
757
%token  UPDATE_SYM                    /* SQL-2003-R */
526
758
%token  USAGE                         /* SQL-2003-N */
527
759
%token  USER                          /* SQL-2003-R */
529
761
%token  USING                         /* SQL-2003-R */
530
762
%token  UTC_DATE_SYM
531
763
%token  UTC_TIMESTAMP_SYM
532
 
%token  UUID_SYM
533
764
%token  VALUES                        /* SQL-2003-R */
534
765
%token  VALUE_SYM                     /* SQL-2003-R */
535
766
%token  VARBINARY
538
769
%token  VARIANCE_SYM
539
770
%token  VARYING                       /* SQL-2003-R */
540
771
%token  VAR_SAMP_SYM
541
 
%token  WAIT_SYM
542
772
%token  WARNINGS
543
773
%token  WEEK_SYM
544
774
%token  WHEN_SYM                      /* SQL-2003-R */
550
780
%token  XOR
551
781
%token  YEAR_MONTH_SYM
552
782
%token  YEAR_SYM                      /* SQL-2003-R */
553
 
%token  ZEROFILL_SYM
554
783
 
555
 
/* Lowest to highest */
556
784
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
557
785
/* A dummy token to force the priority of table_ref production in a join. */
558
 
%left  TABLE_REF_PRIORITY
559
 
%left  SET_VAR
560
 
%left  OR_SYM
561
 
%left  XOR
562
 
%left  AND_SYM
563
 
%right NOT_SYM
564
 
%right '='
565
 
%nonassoc EQUAL_SYM GE '>' LE '<' NE
566
 
%nonassoc LIKE REGEXP_SYM
567
 
%nonassoc BETWEEN_SYM
568
 
%nonassoc IN_SYM
569
 
%nonassoc IS NULL_SYM TRUE_SYM FALSE_SYM
 
786
%left   TABLE_REF_PRIORITY
 
787
%left   SET_VAR
 
788
%left   OR_SYM
 
789
%left   XOR
 
790
%left   AND_SYM
 
791
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
 
792
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
570
793
%left   '-' '+'
571
794
%left   '*' '/' '%' DIV_SYM MOD_SYM
 
795
%left   NEG
 
796
%right  NOT_SYM
572
797
%right  BINARY COLLATE_SYM
573
798
%left  INTERVAL_SYM
574
 
%right UMINUS
575
 
%left  '(' ')'
576
 
%left  '{' '}'
577
799
 
578
800
%type <lex_str>
579
801
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
580
 
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
581
 
        ident
582
 
        ident_or_text
583
 
        internal_variable_ident
584
 
        user_variable_ident
585
 
        row_format_or_text
 
802
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
586
803
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
587
 
        schema_name
588
 
        catalog_name
589
804
        opt_component
590
 
        engine_option_value
591
 
        savepoint_ident
592
 
        BIN_NUM TEXT_STRING_filesystem
 
805
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
806
        execute_var_or_string
593
807
        opt_constraint constraint opt_ident
594
808
 
595
 
%type <execute_string>
596
 
        execute_var_or_string
597
 
 
598
809
%type <lex_str_ptr>
599
810
        opt_table_alias
600
811
 
607
818
%type <string>
608
819
        text_string opt_gconcat_separator
609
820
 
610
 
%type <field_val>
611
 
      field_definition
612
 
      int_type
613
 
      real_type
614
 
 
615
 
%type <boolean>
616
 
        opt_wait
617
 
        opt_concurrent
618
 
        opt_status
619
 
        opt_zerofill
 
821
%type <num>
 
822
        type int_type real_type order_dir field_def
 
823
        if_exists opt_table_options
620
824
        opt_if_not_exists
621
 
        if_exists 
622
 
        opt_temporary 
623
 
        opt_field_number_signed
624
 
 
625
 
%type <num>
626
 
        order_dir
627
 
        field_def
628
 
        opt_table_options
629
 
        all_or_any opt_distinct
 
825
        opt_temporary all_or_any opt_distinct
630
826
        union_option
631
827
        start_transaction_opts opt_chain opt_release
632
828
        union_opt select_derived_init option_type2
633
 
        kill_option
634
829
 
635
830
%type <m_fk_option>
636
831
        delete_option
652
847
        table_wild simple_expr udf_expr
653
848
        expr_or_default set_expr_or_default
654
849
        signed_literal now_or_signed_literal opt_escape
655
 
        simple_ident_q
 
850
        simple_ident_nospvar simple_ident_q
656
851
        field_or_var limit_option
657
852
        function_call_keyword
658
853
        function_call_nonkeyword
692
887
 
693
888
%type <interval_time_st> interval_time_stamp
694
889
 
 
890
%type <column_format_type> column_format_types
 
891
 
695
892
%type <tx_isolation> isolation_types
696
893
 
697
894
%type <cast_type> cast_type
698
895
 
699
 
%type <symbol>
700
 
        keyword
701
 
        keyword_sp
702
 
        keyword_exception_for_variable
703
 
        row_format
 
896
%type <symbol> keyword keyword_sp
704
897
 
705
898
%type <charset>
706
899
        collation_name
728
921
        opt_precision opt_ignore opt_column
729
922
        set unlock string_list
730
923
        ref_list opt_match_clause opt_on_update_delete use
731
 
        opt_delete_option varchar
 
924
        opt_delete_options opt_delete_option varchar
732
925
        opt_outer table_list table_name
733
926
        opt_option opt_place
734
927
        opt_attribute opt_attribute_list attribute
735
928
        flush_options flush_option
736
929
        equal optional_braces
737
930
        normal_join
738
 
        table_to_table_list table_to_table opt_table_list
 
931
        table_to_table_list table_to_table opt_table_list opt_as
 
932
        single_multi
739
933
        union_clause union_list
740
934
        precision subselect_start
741
935
        subselect_end select_var_list select_var_list_init opt_len
742
936
        opt_extended_describe
743
937
        statement
744
 
        execute
745
938
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
746
939
        init_key_options key_options key_opts key_opt key_using_alg
 
940
        execute
747
941
END_OF_INPUT
748
942
 
749
943
%type <index_hint> index_hint_type
750
944
%type <num> index_hint_clause
751
945
%type <filetype> data_file
752
946
 
 
947
%type <NONE>
 
948
        '-' '+' '*' '/' '%' '(' ')'
 
949
        ',' '!' '{' '}' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
 
950
        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM DELETE_SYM
753
951
%%
754
952
 
755
953
/*
776
974
query:
777
975
          END_OF_INPUT
778
976
          {
779
 
            if (!(YYSession->getLex()->select_lex.options & OPTION_FOUND_COMMENT))
 
977
            Session *session= YYSession;
 
978
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
780
979
            {
781
980
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
782
981
              DRIZZLE_YYABORT;
783
982
            }
784
983
            else
785
984
            {
786
 
              YYSession->getLex()->statement= new statement::EmptyQuery(YYSession);
 
985
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
986
              session->lex->statement=
 
987
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
988
              if (session->lex->statement == NULL)
 
989
                DRIZZLE_YYABORT;
787
990
            }
788
991
          }
789
992
        | verb_clause END_OF_INPUT {}
827
1030
/* create a table */
828
1031
 
829
1032
create:
830
 
          CREATE CATALOG_SYM catalog_name
831
 
          {
832
 
            Lex->statement= new statement::catalog::Create(YYSession, $3);
833
 
          }
834
 
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
835
 
          {
836
 
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
 
1033
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1034
          {
 
1035
            Session *session= YYSession;
 
1036
            LEX *lex= session->lex;
 
1037
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1038
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1039
            lex->statement= statement;
 
1040
            if (lex->statement == NULL)
 
1041
              DRIZZLE_YYABORT;
 
1042
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1043
                                                   TL_OPTION_UPDATING,
 
1044
                                                   TL_WRITE))
 
1045
              DRIZZLE_YYABORT;
 
1046
            lex->col_list.empty();
 
1047
            statement->change=NULL;
 
1048
            statement->is_if_not_exists= $4;
 
1049
            statement->create_info.db_type= NULL;
 
1050
            statement->create_info.default_table_charset= NULL;
 
1051
            lex->name.str= 0;
837
1052
 
838
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
839
 
                                                     TL_OPTION_UPDATING,
840
 
                                                     TL_WRITE))
841
 
              DRIZZLE_YYABORT;
842
 
            Lex->col_list.clear();
 
1053
            message::Table &proto= statement->create_table_message;
 
1054
           
 
1055
            proto.set_name($5->table.str);
 
1056
            if ($2)
 
1057
              proto.set_type(message::Table::TEMPORARY);
 
1058
            else
 
1059
              proto.set_type(message::Table::STANDARD);
843
1060
          }
844
 
          create_table_definition
 
1061
          create2
845
1062
          {
846
 
            Lex->current_select= &Lex->select_lex;
 
1063
            LEX *lex= YYSession->lex;
 
1064
            lex->current_select= &lex->select_lex;
847
1065
          }
848
1066
        | CREATE build_method
849
1067
          {
850
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1068
            LEX *lex=Lex;
 
1069
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1070
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1071
            lex->statement= statement;
 
1072
            if (lex->statement == NULL)
 
1073
              DRIZZLE_YYABORT;
 
1074
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1075
            statement->alter_info.build_method= $2;
 
1076
            lex->col_list.empty();
 
1077
            statement->change=NULL;
851
1078
          }
852
1079
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
853
1080
          {
854
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
855
 
                                                            NULL,
856
 
                                                            TL_OPTION_UPDATING))
 
1081
            LEX *lex=Lex;
 
1082
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1083
 
 
1084
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1085
                                                        NULL,
 
1086
                                                        TL_OPTION_UPDATING))
857
1087
              DRIZZLE_YYABORT;
858
 
 
859
 
            parser::buildKey(Lex, $4, $6);
 
1088
            Key *key;
 
1089
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1090
            statement->alter_info.key_list.push_back(key);
 
1091
            lex->col_list.empty();
860
1092
          }
861
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1093
        | CREATE DATABASE opt_if_not_exists ident
862
1094
          {
863
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1095
            LEX *lex=Lex;
 
1096
 
 
1097
            lex->sql_command=SQLCOM_CREATE_DB;
 
1098
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1099
            lex->statement= statement;
 
1100
            if (lex->statement == NULL)
 
1101
              DRIZZLE_YYABORT;
 
1102
            statement->is_if_not_exists= $3;
864
1103
          }
865
1104
          opt_create_database_options
866
1105
          {
868
1107
          }
869
1108
        ;
870
1109
 
871
 
create_table_definition:
872
 
          '(' field_list ')' opt_create_table_options  create_select_as
873
 
          { }
874
 
        | '(' create_select ')'
875
 
           {
876
 
             Lex->current_select->set_braces(1);
877
 
           }
 
1110
create2:
 
1111
          '(' create2a {}
 
1112
        | opt_create_table_options
 
1113
          create3 {}
 
1114
        | LIKE table_ident opt_create_table_options
 
1115
          {
 
1116
            Session *session= YYSession;
 
1117
            LEX *lex= session->lex;
 
1118
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1119
 
 
1120
            statement->is_create_table_like= true;
 
1121
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1122
              DRIZZLE_YYABORT;
 
1123
          }
 
1124
        | '(' LIKE table_ident ')'
 
1125
          {
 
1126
            Session *session= YYSession;
 
1127
            LEX *lex= session->lex;
 
1128
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1129
 
 
1130
            statement->is_create_table_like= true;
 
1131
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1132
              DRIZZLE_YYABORT;
 
1133
          }
 
1134
        ;
 
1135
 
 
1136
create2a:
 
1137
          field_list ')' opt_create_table_options
 
1138
          create3 {}
 
1139
        |  create_select ')'
 
1140
           { Lex->current_select->set_braces(1);}
878
1141
           union_opt {}
879
 
        |  '(' create_like ')' opt_create_table_options
880
 
          { }
881
 
        | create_like opt_create_table_options
882
 
          { }
883
 
        | opt_create_table_options create_select_as 
884
 
          { }
885
1142
        ;
886
1143
 
887
 
create_select_as:
 
1144
create3:
888
1145
          /* empty */ {}
889
 
        | opt_duplicate_as create_select
890
 
          {
891
 
            Lex->current_select->set_braces(0);
892
 
          }
 
1146
        | opt_duplicate opt_as create_select
 
1147
          { Lex->current_select->set_braces(0);}
893
1148
          union_clause {}
894
 
        | opt_duplicate_as '(' create_select ')'
895
 
          {
896
 
            Lex->current_select->set_braces(1);
897
 
          }
 
1149
        | opt_duplicate opt_as '(' create_select ')'
 
1150
          { Lex->current_select->set_braces(1);}
898
1151
          union_opt {}
899
1152
        ;
900
1153
 
901
 
create_like:
902
 
          LIKE table_ident
903
 
          {
904
 
            ((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
905
 
 
906
 
            if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
907
 
              DRIZZLE_YYABORT;
908
 
          }
909
 
        ;
910
 
 
911
1154
create_select:
912
 
          stored_select
913
 
          {
914
 
          }
915
 
        ;
916
 
 
917
 
/*
918
 
  This rule is used for both CREATE TABLE .. SELECT,  AND INSERT ... SELECT
919
 
*/
920
 
stored_select:
921
1155
          SELECT_SYM
922
1156
          {
923
 
            Lex->lock_option= TL_READ;
924
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1157
            LEX *lex=Lex;
 
1158
            lex->lock_option= TL_READ;
 
1159
            if (lex->sql_command == SQLCOM_INSERT)
925
1160
            {
926
 
              delete Lex->statement;
927
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1161
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1162
              delete lex->statement;
 
1163
              lex->statement=
 
1164
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1165
              if (lex->statement == NULL)
 
1166
                DRIZZLE_YYABORT;
928
1167
            }
929
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1168
            else if (lex->sql_command == SQLCOM_REPLACE)
930
1169
            {
931
 
              delete Lex->statement;
932
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1170
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1171
              delete lex->statement;
 
1172
              lex->statement=
 
1173
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1174
              if (lex->statement == NULL)
 
1175
                DRIZZLE_YYABORT;
933
1176
            }
934
1177
            /*
935
1178
              The following work only with the local list, the global list
936
1179
              is created correctly in this case
937
1180
            */
938
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
939
 
            init_select(Lex);
940
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1181
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1182
            mysql_init_select(lex);
 
1183
            lex->current_select->parsing_place= SELECT_LIST;
941
1184
          }
942
1185
          select_options select_item_list
943
1186
          {
953
1196
          }
954
1197
        ;
955
1198
 
 
1199
opt_as:
 
1200
          /* empty */ {}
 
1201
        | AS {}
 
1202
        ;
 
1203
 
956
1204
opt_create_database_options:
957
1205
          /* empty */ {}
958
1206
        | default_collation_schema {}
966
1214
 
967
1215
custom_database_option:
968
1216
          ident_or_text
969
 
          {
970
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
971
 
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
972
 
          }
973
 
        | REPLICATION opt_equal TRUE_SYM
974
 
          {
975
 
            parser::buildReplicationOption(Lex, true);
976
 
          }
977
 
        | REPLICATION opt_equal FALSE_SYM
978
 
          {
979
 
            parser::buildReplicationOption(Lex, false);
980
 
          }
 
1217
        {
 
1218
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1219
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1220
 
 
1221
          opt->set_name($1.str);
 
1222
        }
981
1223
        | ident_or_text equal ident_or_text
982
 
          {
983
 
            parser::buildSchemaOption(Lex, $1.str, $3);
984
 
          }
 
1224
        {
 
1225
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1226
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1227
 
 
1228
          opt->set_name($1.str);
 
1229
          opt->set_state($3.str);
 
1230
        }
985
1231
        | ident_or_text equal ulonglong_num
986
 
          {
987
 
            parser::buildSchemaOption(Lex, $1.str, $3);
988
 
          }
 
1232
        {
 
1233
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1234
          char number_as_string[22];
 
1235
 
 
1236
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1237
 
 
1238
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1239
 
 
1240
          opt->set_name($1.str);
 
1241
          opt->set_state(number_as_string);
 
1242
        }
989
1243
        ;
990
1244
 
991
1245
opt_table_options:
995
1249
 
996
1250
opt_if_not_exists:
997
1251
          /* empty */ { $$= false; }
998
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1252
        | IF not EXISTS { $$= true; }
999
1253
        ;
1000
1254
 
1001
1255
opt_create_table_options:
1019
1273
custom_engine_option:
1020
1274
        ENGINE_SYM equal ident_or_text
1021
1275
          {
1022
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1276
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1277
 
 
1278
            statement->is_engine_set= true;
 
1279
 
 
1280
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1023
1281
          }
1024
1282
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1025
1283
          {
1026
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1284
            message::Table::TableOptions *tableopts;
 
1285
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1286
 
 
1287
            tableopts->set_comment($3.str);
1027
1288
          }
1028
1289
        | AUTO_INC opt_equal ulonglong_num
1029
1290
          {
1030
 
            Lex->table()->mutable_options()->set_auto_increment_value($3);
1031
 
          }
1032
 
        | REPLICATION opt_equal TRUE_SYM
1033
 
          {
1034
 
            Lex->table()->mutable_options()->set_dont_replicate(false);
1035
 
          }
1036
 
        | REPLICATION opt_equal FALSE_SYM
1037
 
          {
1038
 
            Lex->table()->mutable_options()->set_dont_replicate(true);
1039
 
          }
1040
 
        |  ROW_FORMAT_SYM equal row_format_or_text
1041
 
          {
1042
 
            parser::buildEngineOption(Lex, "ROW_FORMAT", $3);
1043
 
          }
1044
 
        |  FILE_SYM equal TEXT_STRING_sys
1045
 
          {
1046
 
            parser::buildEngineOption(Lex, "FILE", $3);
1047
 
          }
1048
 
        |  ident_or_text equal engine_option_value
1049
 
          {
1050
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1291
            message::Table::TableOptions *tableopts;
 
1292
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1293
 
 
1294
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1295
 
 
1296
            statement->create_info.auto_increment_value=$3;
 
1297
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1298
            tableopts->set_auto_increment_value($3);
 
1299
          }
 
1300
        |  ident_or_text equal ident_or_text
 
1301
          {
 
1302
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1303
 
 
1304
            opt->set_name($1.str);
 
1305
            opt->set_state($3.str);
1051
1306
          }
1052
1307
        | ident_or_text equal ulonglong_num
1053
1308
          {
1054
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1309
            char number_as_string[22];
 
1310
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1311
 
 
1312
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1313
            opt->set_name($1.str);
 
1314
            opt->set_state(number_as_string);
1055
1315
          }
1056
1316
        | default_collation
1057
1317
        ;
1059
1319
default_collation:
1060
1320
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1061
1321
          {
1062
 
            if (not parser::buildCollation(Lex, $4))
1063
 
            {
1064
 
              DRIZZLE_YYABORT;
1065
 
            }
 
1322
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1323
 
 
1324
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1325
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1326
                 cinfo->default_table_charset && $4 &&
 
1327
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1328
              {
 
1329
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1330
                         $4->name, cinfo->default_table_charset->csname);
 
1331
                DRIZZLE_YYABORT;
 
1332
              }
 
1333
              statement->create_info.default_table_charset= $4;
 
1334
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1066
1335
          }
1067
1336
        ;
1068
1337
 
1069
1338
default_collation_schema:
1070
1339
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1071
1340
          {
1072
 
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
1073
 
          }
1074
 
        ;
1075
 
 
1076
 
row_format:
1077
 
          COMPACT_SYM  {}
1078
 
        | COMPRESSED_SYM  {}
1079
 
        | DEFAULT  {}
1080
 
        | DYNAMIC_SYM  {}
1081
 
        | FIXED_SYM  {}
1082
 
        | REDUNDANT_SYM  {}
1083
 
        ;
1084
 
 
1085
 
row_format_or_text:
1086
 
          row_format
1087
 
          {
1088
 
            $$.str= YYSession->strmake($1.str, $1.length);
1089
 
            $$.length= $1.length;
1090
 
          }
1091
 
        ;
 
1341
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1342
 
 
1343
            message::Schema &schema_message= statement->schema_message;
 
1344
            schema_message.set_collation($4->name);
 
1345
          }
 
1346
        ;
 
1347
 
 
1348
column_format_types:
 
1349
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1350
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1351
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1352
 
1092
1353
 
1093
1354
opt_select_from:
1094
1355
          opt_limit_clause {}
1109
1370
          field_spec opt_check_constraint
1110
1371
        | field_spec references
1111
1372
          {
1112
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1373
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1113
1374
          }
1114
1375
        ;
1115
1376
 
1116
1377
key_def:
1117
1378
          key_type opt_ident key_alg '(' key_list ')' key_options
1118
1379
          {
1119
 
            parser::buildKey(Lex, $1, $2);
 
1380
            LEX *lex=Lex;
 
1381
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1382
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1383
                              lex->col_list);
 
1384
            statement->alter_info.key_list.push_back(key);
 
1385
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1120
1386
          }
1121
1387
        | opt_constraint constraint_key_type opt_ident key_alg
1122
1388
          '(' key_list ')' key_options
1123
1389
          {
1124
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1390
            LEX *lex=Lex;
 
1391
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1392
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1393
                              lex->col_list);
 
1394
            statement->alter_info.key_list.push_back(key);
 
1395
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1125
1396
          }
1126
1397
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1127
1398
          {
1128
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1399
            LEX *lex=Lex;
 
1400
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1401
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
 
1402
                                      $8,
 
1403
                                      lex->ref_list,
 
1404
                                      statement->fk_delete_opt,
 
1405
                                      statement->fk_update_opt,
 
1406
                                      statement->fk_match_option);
 
1407
 
 
1408
            statement->alter_info.key_list.push_back(key);
 
1409
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1410
                         &default_key_create_info, 1,
 
1411
                         lex->col_list);
 
1412
            statement->alter_info.key_list.push_back(key);
 
1413
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1414
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1415
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1129
1416
          }
1130
1417
        | constraint opt_check_constraint
1131
1418
          {
1132
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1419
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1133
1420
          }
1134
1421
        | opt_constraint check_constraint
1135
1422
          {
1136
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1423
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1137
1424
          }
1138
1425
        ;
1139
1426
 
1158
1445
field_spec:
1159
1446
          field_ident
1160
1447
          {
1161
 
            parser::buildCreateFieldIdent(Lex);
 
1448
            LEX *lex=Lex;
 
1449
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1450
            lex->length=lex->dec=0;
 
1451
            lex->type=0;
 
1452
            statement->default_value= statement->on_update_value= 0;
 
1453
            statement->comment= null_lex_str;
 
1454
            lex->charset=NULL;
 
1455
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1456
 
 
1457
            message::AlterTable &alter_proto=
 
1458
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1459
            statement->current_proto_field= alter_proto.add_added_field();
1162
1460
          }
1163
1461
          field_def
1164
1462
          {
 
1463
            LEX *lex=Lex;
1165
1464
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1166
1465
 
1167
 
            if (Lex->field())
1168
 
            {
1169
 
              Lex->field()->set_name($1.str);
1170
 
            }
 
1466
            if (statement->current_proto_field)
 
1467
              statement->current_proto_field->set_name($1.str);
1171
1468
 
1172
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1173
 
                                  Lex->length, Lex->dec, Lex->type,
 
1469
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1470
                                  lex->length,lex->dec,lex->type,
1174
1471
                                  statement->column_format,
1175
1472
                                  statement->default_value, statement->on_update_value,
1176
1473
                                  &statement->comment,
1177
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1474
                                  statement->change, &lex->interval_list, lex->charset))
1178
1475
              DRIZZLE_YYABORT;
1179
1476
 
1180
 
            Lex->setField(NULL);
 
1477
            statement->current_proto_field= NULL;
1181
1478
          }
1182
1479
        ;
1183
 
 
1184
1480
field_def:
1185
 
          field_definition opt_attribute {}
 
1481
          type opt_attribute {}
1186
1482
        ;
1187
1483
 
1188
 
field_definition:
1189
 
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1190
 
          { 
1191
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
 
1484
type:
 
1485
        int_type
 
1486
        {
 
1487
          $$=$1;
 
1488
          Lex->length=(char*) 0; /* use default length */
 
1489
          statement::CreateTable *statement=
 
1490
            (statement::CreateTable *)Lex->statement;
 
1491
 
 
1492
          if (statement->current_proto_field)
 
1493
          {
 
1494
            if ($1 == DRIZZLE_TYPE_LONG)
 
1495
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1496
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1497
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1498
            else
 
1499
              abort();
 
1500
          }
1192
1501
          }
1193
1502
        | real_type opt_precision
1194
1503
          {
1195
 
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
1196
 
            $$= parser::buildDoubleColumn(Lex);
1197
 
          }
1198
 
        | char '(' NUM ')'
1199
 
          {
1200
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1201
 
          }
1202
 
        | char
1203
 
          {
1204
 
            $$= parser::buildVarcharColumn(Lex, "1");
1205
 
          }
1206
 
        | varchar '(' NUM ')'
1207
 
          {
1208
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1209
 
          }
1210
 
        | VARBINARY '(' NUM ')'
1211
 
          {
1212
 
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
1213
 
          }
1214
 
        | DATE_SYM
 
1504
            $$=$1;
 
1505
 
 
1506
            statement::CreateTable *statement=
 
1507
              (statement::CreateTable *)Lex->statement;
 
1508
 
 
1509
            if (statement->current_proto_field)
 
1510
            {
 
1511
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1512
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1513
            }
 
1514
          }
 
1515
          | char '(' NUM ')'
 
1516
            {
 
1517
              Lex->length=$3.str;
 
1518
              $$=DRIZZLE_TYPE_VARCHAR;
 
1519
 
 
1520
            statement::CreateTable *statement=
 
1521
              (statement::CreateTable *)Lex->statement;
 
1522
 
 
1523
            if (statement->current_proto_field)
 
1524
            {
 
1525
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1526
              message::Table::Field::StringFieldOptions *string_field_options;
 
1527
 
 
1528
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1529
 
 
1530
              string_field_options->set_length(atoi($3.str));
 
1531
            }
 
1532
            }
 
1533
          | char
 
1534
            {
 
1535
              Lex->length=(char*) "1";
 
1536
              $$=DRIZZLE_TYPE_VARCHAR;
 
1537
 
 
1538
            statement::CreateTable *statement=
 
1539
              (statement::CreateTable *)Lex->statement;
 
1540
 
 
1541
            if (statement->current_proto_field)
 
1542
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1543
            }
 
1544
          | varchar '(' NUM ')'
 
1545
            {
 
1546
              Lex->length=$3.str;
 
1547
              $$= DRIZZLE_TYPE_VARCHAR;
 
1548
 
 
1549
            statement::CreateTable *statement=
 
1550
              (statement::CreateTable *)Lex->statement;
 
1551
 
 
1552
            if (statement->current_proto_field)
 
1553
            {
 
1554
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1555
 
 
1556
              message::Table::Field::StringFieldOptions *string_field_options;
 
1557
 
 
1558
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1559
 
 
1560
              string_field_options->set_length(atoi($3.str));
 
1561
            }
 
1562
            }
 
1563
          | VARBINARY '(' NUM ')'
 
1564
            {
 
1565
              Lex->length=$3.str;
 
1566
              Lex->charset=&my_charset_bin;
 
1567
              $$= DRIZZLE_TYPE_VARCHAR;
 
1568
 
 
1569
            statement::CreateTable *statement=
 
1570
              (statement::CreateTable *)Lex->statement;
 
1571
 
 
1572
            if (statement->current_proto_field)
 
1573
            {
 
1574
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1575
              message::Table::Field::StringFieldOptions *string_field_options;
 
1576
 
 
1577
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1578
 
 
1579
              string_field_options->set_length(atoi($3.str));
 
1580
              string_field_options->set_collation_id(my_charset_bin.number);
 
1581
              string_field_options->set_collation(my_charset_bin.name);
 
1582
            }
 
1583
            }
 
1584
          | DATE_SYM
1215
1585
          {
1216
1586
            $$=DRIZZLE_TYPE_DATE;
1217
1587
 
1218
 
            if (Lex->field())
1219
 
              Lex->field()->set_type(message::Table::Field::DATE);
1220
 
          }
1221
 
        | TIME_SYM
1222
 
          {
1223
 
            $$=DRIZZLE_TYPE_TIME;
1224
 
 
1225
 
            if (Lex->field())
1226
 
              Lex->field()->set_type(message::Table::Field::TIME);
1227
 
          }
1228
 
        | TIMESTAMP_SYM
1229
 
          {
1230
 
            $$=parser::buildTimestampColumn(Lex, NULL);
1231
 
          }
1232
 
        | TIMESTAMP_SYM '(' NUM ')'
1233
 
          {
1234
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1235
 
          }
1236
 
        | DATETIME_SYM
 
1588
            statement::CreateTable *statement=
 
1589
              (statement::CreateTable *)Lex->statement;
 
1590
 
 
1591
            if (statement->current_proto_field)
 
1592
              statement->current_proto_field->set_type(message::Table::Field::DATE);
 
1593
          }
 
1594
          | TIMESTAMP_SYM
 
1595
          {
 
1596
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1597
 
 
1598
            statement::CreateTable *statement=
 
1599
              (statement::CreateTable *)Lex->statement;
 
1600
 
 
1601
            if (statement->current_proto_field)
 
1602
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
 
1603
          }
 
1604
          | DATETIME_SYM
1237
1605
          {
1238
1606
            $$=DRIZZLE_TYPE_DATETIME;
1239
1607
 
1240
 
            if (Lex->field())
1241
 
              Lex->field()->set_type(message::Table::Field::DATETIME);
1242
 
          }
1243
 
        | BLOB_SYM
1244
 
          {
1245
 
            $$= parser::buildBlobColumn(Lex);
1246
 
          }
1247
 
        | TEXT_SYM
1248
 
          {
1249
 
            $$=DRIZZLE_TYPE_BLOB;
1250
 
            Lex->length=(char*) 0; /* use default length */
1251
 
 
1252
 
          if (Lex->field())
1253
 
            Lex->field()->set_type(message::Table::Field::BLOB);
1254
 
          }
1255
 
        | DECIMAL_SYM float_options
1256
 
          {
1257
 
            $$= parser::buildDecimalColumn(Lex);
1258
 
          }
1259
 
        | NUMERIC_SYM float_options
1260
 
          {
1261
 
            $$= parser::buildDecimalColumn(Lex);
1262
 
          }
1263
 
        | FIXED_SYM float_options
1264
 
          {
1265
 
            $$= parser::buildDecimalColumn(Lex);
1266
 
          }
1267
 
        | ENUM_SYM
1268
 
          {
1269
 
            Lex->interval_list.clear();
1270
 
          }
1271
 
          '(' string_list ')'
 
1608
            statement::CreateTable *statement=
 
1609
              (statement::CreateTable *)Lex->statement;
 
1610
 
 
1611
            if (statement->current_proto_field)
 
1612
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1613
          }
 
1614
          | BLOB_SYM
 
1615
            {
 
1616
              Lex->charset=&my_charset_bin;
 
1617
              $$=DRIZZLE_TYPE_BLOB;
 
1618
              Lex->length=(char*) 0; /* use default length */
 
1619
 
 
1620
              statement::CreateTable *statement=
 
1621
                (statement::CreateTable *)Lex->statement;
 
1622
 
 
1623
              if (statement->current_proto_field)
 
1624
              {
 
1625
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1626
                message::Table::Field::StringFieldOptions *string_field_options;
 
1627
 
 
1628
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1629
                string_field_options->set_collation_id(my_charset_bin.number);
 
1630
                string_field_options->set_collation(my_charset_bin.name);
 
1631
              }
 
1632
            }
 
1633
          | TEXT_SYM
 
1634
            {
 
1635
              $$=DRIZZLE_TYPE_BLOB;
 
1636
              Lex->length=(char*) 0; /* use default length */
 
1637
 
 
1638
            statement::CreateTable *statement=
 
1639
              (statement::CreateTable *)Lex->statement;
 
1640
 
 
1641
            if (statement->current_proto_field)
 
1642
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1643
            }
 
1644
          | DECIMAL_SYM float_options
 
1645
          {
 
1646
            $$=DRIZZLE_TYPE_DECIMAL;
 
1647
 
 
1648
            statement::CreateTable *statement=
 
1649
              (statement::CreateTable *)Lex->statement;
 
1650
 
 
1651
            if (statement->current_proto_field)
 
1652
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1653
          }
 
1654
          | NUMERIC_SYM float_options
 
1655
          {
 
1656
            $$=DRIZZLE_TYPE_DECIMAL;
 
1657
 
 
1658
            statement::CreateTable *statement=
 
1659
              (statement::CreateTable *)Lex->statement;
 
1660
 
 
1661
            if (statement->current_proto_field)
 
1662
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1663
          }
 
1664
          | FIXED_SYM float_options
 
1665
          {
 
1666
            $$=DRIZZLE_TYPE_DECIMAL;
 
1667
 
 
1668
            statement::CreateTable *statement=
 
1669
              (statement::CreateTable *)Lex->statement;
 
1670
 
 
1671
            if (statement->current_proto_field)
 
1672
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1673
          }
 
1674
          | ENUM_SYM
 
1675
            {Lex->interval_list.empty();}
 
1676
            '(' string_list ')'
1272
1677
          {
1273
1678
            $$=DRIZZLE_TYPE_ENUM;
1274
1679
 
1275
 
            if (Lex->field())
1276
 
              Lex->field()->set_type(message::Table::Field::ENUM);
1277
 
          }
1278
 
        | UUID_SYM
1279
 
          {
1280
 
            $$= parser::buildUuidColumn(Lex);
1281
 
          }
1282
 
        | BOOLEAN_SYM
1283
 
          {
1284
 
            $$= parser::buildBooleanColumn(Lex);
 
1680
            statement::CreateTable *statement=
 
1681
              (statement::CreateTable *)Lex->statement;
 
1682
 
 
1683
            if (statement->current_proto_field)
 
1684
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1285
1685
          }
1286
1686
        | SERIAL_SYM
1287
1687
          {
1288
 
            $$= parser::buildSerialColumn(Lex);
 
1688
            $$=DRIZZLE_TYPE_LONGLONG;
 
1689
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1690
 
 
1691
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1692
            if (statement->current_proto_field)
 
1693
            {
 
1694
              message::Table::Field::FieldConstraints *constraints;
 
1695
              constraints= statement->current_proto_field->mutable_constraints();
 
1696
              constraints->set_is_nullable(false);
 
1697
 
 
1698
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1699
            }
1289
1700
          }
1290
1701
        ;
1291
1702
 
1299
1710
        ;
1300
1711
 
1301
1712
int_type:
1302
 
          INT_SYM 
1303
 
          {
1304
 
            $$= DRIZZLE_TYPE_LONG;
1305
 
          }
1306
 
        | BOOL_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_LONG;
1309
 
          }
1310
 
        | BIGINT_SYM
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_LONGLONG;
1313
 
          }
 
1713
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1714
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1314
1715
        ;
1315
1716
 
1316
1717
real_type:
1319
1720
            $$= DRIZZLE_TYPE_DOUBLE;
1320
1721
          }
1321
1722
        | DOUBLE_SYM
1322
 
          {
1323
 
            $$= DRIZZLE_TYPE_DOUBLE;
1324
 
          }
 
1723
          { $$=DRIZZLE_TYPE_DOUBLE; }
1325
1724
        | DOUBLE_SYM PRECISION
1326
 
          {
1327
 
            $$= DRIZZLE_TYPE_DOUBLE;
1328
 
          }
 
1725
          { $$=DRIZZLE_TYPE_DOUBLE; }
1329
1726
        ;
1330
1727
 
1331
1728
float_options:
1340
1737
precision:
1341
1738
          '(' NUM ',' NUM ')'
1342
1739
          {
1343
 
            Lex->length= $2.str;
1344
 
            Lex->dec= $4.str;
 
1740
            LEX *lex=Lex;
 
1741
            lex->length=$2.str;
 
1742
            lex->dec=$4.str;
1345
1743
          }
1346
1744
        ;
1347
1745
 
1350
1748
        | '(' NUM ')' { Lex->length= $2.str; }
1351
1749
        ;
1352
1750
 
1353
 
opt_field_number_signed:
1354
 
          /* empty */ { $$= false; }
1355
 
        | SIGNED_SYM { $$= false; }
1356
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1357
 
        ;
1358
 
 
1359
 
ignored_field_number_length:
1360
 
          /* empty */ { }
1361
 
        | '(' NUM ')' { }
1362
 
        ;
1363
 
 
1364
 
opt_zerofill:
1365
 
          /* empty */ { $$= false; }
1366
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1367
 
        ;
1368
 
 
1369
1751
opt_precision:
1370
 
          /* empty */
1371
 
          { Lex->dec=Lex->length= (char*)0; }
1372
 
        | '(' NUM ')'
1373
 
          { Lex->length=Lex->dec= (char*)0; }
1374
 
        | precision
1375
 
          {}
 
1752
          /* empty */ {}
 
1753
        | precision {}
1376
1754
        ;
1377
1755
 
1378
1756
opt_attribute:
1388
1766
attribute:
1389
1767
          NULL_SYM
1390
1768
          {
 
1769
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1391
1770
            Lex->type&= ~ NOT_NULL_FLAG;
 
1771
 
 
1772
            if (statement->current_proto_field)
 
1773
            {
 
1774
              message::Table::Field::FieldConstraints *constraints;
 
1775
              constraints= statement->current_proto_field->mutable_constraints();
 
1776
              constraints->set_is_nullable(true);
 
1777
            }
 
1778
          }
 
1779
        | COLUMN_FORMAT_SYM column_format_types
 
1780
          {
 
1781
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1782
 
 
1783
            statement->column_format= $2;
 
1784
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1392
1785
          }
1393
1786
        | not NULL_SYM
1394
1787
          {
 
1788
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1395
1789
            Lex->type|= NOT_NULL_FLAG;
1396
1790
 
1397
 
            if (Lex->field())
 
1791
            if (statement->current_proto_field)
1398
1792
            {
1399
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1793
              message::Table::Field::FieldConstraints *constraints;
 
1794
              constraints= statement->current_proto_field->mutable_constraints();
 
1795
              constraints->set_is_nullable(false);
1400
1796
            }
1401
1797
          }
1402
1798
        | DEFAULT now_or_signed_literal
1407
1803
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1408
1804
          }
1409
1805
        | ON UPDATE_SYM NOW_SYM optional_braces
1410
 
          {
1411
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1412
 
          }
 
1806
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1413
1807
        | AUTO_INC
1414
1808
          {
1415
 
            parser::buildAutoOnColumn(Lex);
 
1809
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1810
 
 
1811
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1812
            if (statement->current_proto_field)
 
1813
            {
 
1814
              message::Table::Field::FieldConstraints *constraints;
 
1815
 
 
1816
              constraints= statement->current_proto_field->mutable_constraints();
 
1817
              constraints->set_is_nullable(false);
 
1818
            }
1416
1819
          }
1417
1820
        | SERIAL_SYM DEFAULT VALUE_SYM
1418
1821
          {
1419
 
            (void)parser::buildSerialColumn(Lex);
 
1822
            LEX *lex=Lex;
 
1823
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1824
 
 
1825
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1826
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1827
 
 
1828
            if (statement->current_proto_field)
 
1829
            {
 
1830
              message::Table::Field::FieldConstraints *constraints;
 
1831
              constraints= statement->current_proto_field->mutable_constraints();
 
1832
              constraints->set_is_nullable(false);
 
1833
            }
1420
1834
          }
1421
1835
        | opt_primary KEY_SYM
1422
1836
          {
1423
 
            parser::buildPrimaryOnColumn(Lex);
 
1837
            LEX *lex=Lex;
 
1838
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1839
 
 
1840
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1841
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1842
 
 
1843
            if (statement->current_proto_field)
 
1844
            {
 
1845
              message::Table::Field::FieldConstraints *constraints;
 
1846
              constraints= statement->current_proto_field->mutable_constraints();
 
1847
              constraints->set_is_nullable(false);
 
1848
            }
1424
1849
          }
1425
1850
        | UNIQUE_SYM
1426
1851
          {
1427
 
            parser::buildKeyOnColumn(Lex);
 
1852
            LEX *lex=Lex;
 
1853
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1854
 
 
1855
            lex->type|= UNIQUE_FLAG;
 
1856
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1428
1857
          }
1429
1858
        | UNIQUE_SYM KEY_SYM
1430
1859
          {
1431
 
            parser::buildKeyOnColumn(Lex);
 
1860
            LEX *lex=Lex;
 
1861
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1862
 
 
1863
            lex->type|= UNIQUE_KEY_FLAG;
 
1864
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1432
1865
          }
1433
1866
        | COMMENT_SYM TEXT_STRING_sys
1434
1867
          {
1435
1868
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1436
1869
            statement->comment= $2;
1437
1870
 
1438
 
            if (Lex->field())
1439
 
              Lex->field()->set_comment($2.str);
 
1871
            if (statement->current_proto_field)
 
1872
              statement->current_proto_field->set_comment($2.str);
1440
1873
          }
1441
1874
        | COLLATE_SYM collation_name
1442
1875
          {
1487
1920
        ;
1488
1921
 
1489
1922
references:
1490
 
          REFERENCES table_ident opt_ref_list opt_match_clause opt_on_update_delete
 
1923
          REFERENCES
 
1924
          table_ident
 
1925
          opt_ref_list
 
1926
          opt_match_clause
 
1927
          opt_on_update_delete
1491
1928
          {
1492
1929
            $$=$2;
1493
1930
          }
1495
1932
 
1496
1933
opt_ref_list:
1497
1934
          /* empty */
1498
 
          { Lex->ref_list.clear(); }
 
1935
          { Lex->ref_list.empty(); }
1499
1936
        | '(' ref_list ')'
1500
1937
        ;
1501
1938
 
1504
1941
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1505
1942
        | ident
1506
1943
          {
1507
 
            Lex->ref_list.clear();
1508
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1944
            LEX *lex= Lex;
 
1945
            lex->ref_list.empty();
 
1946
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1509
1947
          }
1510
1948
        ;
1511
1949
 
1553
1991
delete_option:
1554
1992
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1555
1993
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1556
 
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
 
1994
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1557
1995
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1558
 
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
 
1996
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_DEFAULT;  }
1559
1997
        ;
1560
1998
 
1561
1999
key_type:
1595
2033
        ;
1596
2034
 
1597
2035
/*
1598
 
  For now, key_alg initializies Lex->key_create_info.
 
2036
  For now, key_alg initializies lex->key_create_info.
1599
2037
  In the future, when all key options are after key definition,
1600
2038
  we can remove key_alg and move init_key_options to key_options
1601
2039
*/
1617
2055
 
1618
2056
key_using_alg:
1619
2057
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2058
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1620
2059
        ;
1621
2060
 
1622
2061
key_opt:
1669
2108
*/
1670
2109
 
1671
2110
alter:
1672
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2111
          ALTER build_method opt_ignore TABLE_SYM table_ident
1673
2112
          {
1674
 
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5, $2);
1675
 
            Lex->statement= statement;
1676
 
            Lex->duplicates= DUP_ERROR;
1677
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
1678
 
            {
1679
 
              DRIZZLE_YYABORT;
1680
 
            }
1681
 
 
1682
 
            Lex->col_list.clear();
1683
 
            Lex->select_lex.init_order();
1684
 
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
 
2113
            Session *session= YYSession;
 
2114
            LEX *lex= session->lex;
 
2115
            lex->name.str= 0;
 
2116
            lex->name.length= 0;
 
2117
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2118
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2119
            lex->statement= statement;
 
2120
            if (lex->statement == NULL)
 
2121
              DRIZZLE_YYABORT;
 
2122
            lex->duplicates= DUP_ERROR;
 
2123
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2124
                                                   TL_OPTION_UPDATING))
 
2125
              DRIZZLE_YYABORT;
 
2126
            lex->col_list.empty();
 
2127
            lex->select_lex.init_order();
 
2128
            lex->select_lex.db=
 
2129
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2130
            statement->alter_info.build_method= $2;
1685
2131
          }
1686
2132
          alter_commands
1687
2133
          {}
1688
 
        | ALTER_SYM DATABASE schema_name
 
2134
        | ALTER DATABASE ident_or_empty
1689
2135
          {
1690
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2136
            LEX *lex=Lex;
 
2137
            lex->sql_command=SQLCOM_ALTER_DB;
 
2138
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2139
            if (lex->statement == NULL)
 
2140
              DRIZZLE_YYABORT;
1691
2141
          }
1692
2142
          default_collation_schema
1693
2143
          {
1694
 
            Lex->name= $3;
1695
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2144
            LEX *lex=Lex;
 
2145
            lex->name= $3;
 
2146
            if (lex->name.str == NULL &&
 
2147
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1696
2148
              DRIZZLE_YYABORT;
1697
2149
          }
1698
2150
        ;
1699
2151
 
 
2152
ident_or_empty:
 
2153
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2154
        | ident { $$= $1; }
 
2155
        ;
 
2156
 
1700
2157
alter_commands:
1701
2158
          /* empty */
1702
2159
        | DISCARD TABLESPACE
1733
2190
        ;
1734
2191
 
1735
2192
add_column:
1736
 
          ADD_SYM opt_column
 
2193
          ADD opt_column
1737
2194
          {
1738
2195
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
2196
 
1744
2201
 
1745
2202
alter_list_item:
1746
2203
          add_column column_def opt_place { }
1747
 
        | ADD_SYM key_def
 
2204
        | ADD key_def
1748
2205
          {
1749
2206
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1750
2207
 
1757
2214
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1758
2215
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1759
2216
          }
1760
 
        | CHANGE_SYM opt_column field_ident
 
2217
        | CHANGE opt_column field_ident
1761
2218
          {
1762
2219
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1763
2220
            statement->change= $3.str;
1766
2223
          field_spec opt_place
1767
2224
        | MODIFY_SYM opt_column field_ident
1768
2225
          {
 
2226
            LEX *lex=Lex;
1769
2227
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1770
 
            Lex->length= Lex->dec=0;
1771
 
            Lex->type= 0;
 
2228
            lex->length=lex->dec=0; lex->type=0;
1772
2229
            statement->default_value= statement->on_update_value= 0;
1773
2230
            statement->comment= null_lex_str;
1774
 
            Lex->charset= NULL;
 
2231
            lex->charset= NULL;
1775
2232
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1776
2233
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1777
2234
 
1778
 
            Lex->setField(NULL);
 
2235
            statement->current_proto_field= NULL;
1779
2236
          }
1780
2237
          field_def
1781
2238
          {
 
2239
            LEX *lex=Lex;
1782
2240
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1783
2241
 
1784
 
            if (add_field_to_list(Lex->session,&$3,
 
2242
            if (add_field_to_list(lex->session,&$3,
1785
2243
                                  (enum enum_field_types) $5,
1786
 
                                  Lex->length, Lex->dec, Lex->type,
 
2244
                                  lex->length, lex->dec, lex->type,
1787
2245
                                  statement->column_format,
1788
2246
                                  statement->default_value,
1789
2247
                                  statement->on_update_value,
1790
2248
                                  &statement->comment,
1791
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2249
                                  $3.str, &lex->interval_list, lex->charset))
1792
2250
              DRIZZLE_YYABORT;
1793
2251
          }
1794
2252
          opt_place
1801
2259
          }
1802
2260
        | DROP FOREIGN KEY_SYM opt_ident
1803
2261
          {
1804
 
            parser::buildAddAlterDropIndex(Lex, $4.str, true);
 
2262
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2263
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY,
 
2264
                                                                    $4.str));
 
2265
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2266
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1805
2267
          }
1806
2268
        | DROP PRIMARY_SYM KEY_SYM
1807
2269
          {
1808
 
            parser::buildAddAlterDropIndex(Lex, "PRIMARY");
 
2270
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2271
 
 
2272
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2273
                                                               "PRIMARY"));
 
2274
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1809
2275
          }
1810
2276
        | DROP key_or_index field_ident
1811
2277
          {
1812
 
            parser::buildAddAlterDropIndex(Lex, $3.str);
 
2278
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2279
 
 
2280
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2281
                                                                    $3.str));
 
2282
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1813
2283
          }
1814
2284
        | DISABLE_SYM KEYS
1815
2285
          {
1825
2295
            statement->alter_info.keys_onoff= ENABLE;
1826
2296
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1827
2297
          }
1828
 
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
 
2298
        | ALTER opt_column field_ident SET DEFAULT signed_literal
1829
2299
          {
1830
2300
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1831
2301
 
1832
2302
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
1833
2303
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1834
2304
          }
1835
 
        | ALTER_SYM opt_column field_ident DROP DEFAULT
 
2305
        | ALTER opt_column field_ident DROP DEFAULT
1836
2306
          {
1837
2307
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1838
2308
 
1841
2311
          }
1842
2312
        | RENAME opt_to table_ident
1843
2313
          {
 
2314
            LEX *lex=Lex;
1844
2315
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1845
2316
            size_t dummy;
1846
2317
 
1847
 
            Lex->select_lex.db=$3->db.str;
1848
 
            if (Lex->select_lex.db == NULL &&
1849
 
                Lex->copy_db_to(&Lex->select_lex.db, &dummy))
 
2318
            lex->select_lex.db=$3->db.str;
 
2319
            if (lex->select_lex.db == NULL &&
 
2320
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1850
2321
            {
1851
2322
              DRIZZLE_YYABORT;
1852
2323
            }
1857
2328
              DRIZZLE_YYABORT;
1858
2329
            }
1859
2330
 
1860
 
            Lex->name= $3->table;
 
2331
            lex->name= $3->table;
1861
2332
            statement->alter_info.flags.set(ALTER_RENAME);
1862
2333
          }
1863
2334
        | CONVERT_SYM TO_SYM collation_name_or_default
1864
2335
          {
1865
2336
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1866
2337
 
1867
 
            statement->create_info().table_charset=
1868
 
            statement->create_info().default_table_charset= $3;
1869
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2338
            statement->create_info.table_charset=
 
2339
            statement->create_info.default_table_charset= $3;
 
2340
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1870
2341
              HA_CREATE_USED_DEFAULT_CHARSET);
1871
2342
            statement->alter_info.flags.set(ALTER_CONVERT);
1872
2343
          }
1904
2375
          /* empty */ {}
1905
2376
        | AFTER_SYM ident
1906
2377
          {
1907
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2378
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2379
 
 
2380
            store_position_for_column($2.str);
 
2381
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1908
2382
          }
1909
2383
        | FIRST_SYM
1910
2384
          {
1911
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2385
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2386
 
 
2387
            store_position_for_column(first_keyword);
 
2388
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1912
2389
          }
1913
2390
        ;
1914
2391
 
1915
2392
opt_to:
1916
2393
          /* empty */ {}
1917
2394
        | TO_SYM {}
 
2395
        | EQ {}
1918
2396
        | AS {}
1919
2397
        ;
1920
2398
 
1921
2399
start:
1922
2400
          START_SYM TRANSACTION_SYM start_transaction_opts
1923
2401
          {
1924
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2402
            LEX *lex= Lex;
 
2403
            lex->sql_command= SQLCOM_BEGIN;
 
2404
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2405
            if (lex->statement == NULL)
 
2406
              DRIZZLE_YYABORT;
1925
2407
          }
1926
2408
        ;
1927
2409
 
1936
2418
analyze:
1937
2419
          ANALYZE_SYM table_or_tables
1938
2420
          {
1939
 
            Lex->statement= new statement::Analyze(YYSession);
 
2421
            LEX *lex=Lex;
 
2422
            lex->sql_command = SQLCOM_ANALYZE;
 
2423
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2424
            if (lex->statement == NULL)
 
2425
              DRIZZLE_YYABORT;
1940
2426
          }
1941
2427
          table_list
1942
2428
          {}
1945
2431
check:
1946
2432
          CHECK_SYM table_or_tables
1947
2433
          {
1948
 
            Lex->statement= new statement::Check(YYSession);
 
2434
            LEX *lex=Lex;
 
2435
 
 
2436
            lex->sql_command = SQLCOM_CHECK;
 
2437
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2438
            if (lex->statement == NULL)
 
2439
              DRIZZLE_YYABORT;
1949
2440
          }
1950
2441
          table_list
1951
2442
          {}
1954
2445
rename:
1955
2446
          RENAME table_or_tables
1956
2447
          {
1957
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2448
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2449
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2450
            if (Lex->statement == NULL)
 
2451
              DRIZZLE_YYABORT;
1958
2452
          }
1959
2453
          table_to_table_list
1960
2454
          {}
1968
2462
table_to_table:
1969
2463
          table_ident TO_SYM table_ident
1970
2464
          {
1971
 
            Select_Lex *sl= Lex->current_select;
1972
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2465
            LEX *lex=Lex;
 
2466
            Select_Lex *sl= lex->current_select;
 
2467
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1973
2468
                                       TL_IGNORE) ||
1974
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2469
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1975
2470
                                       TL_IGNORE))
1976
2471
              DRIZZLE_YYABORT;
1977
2472
          }
1985
2480
select:
1986
2481
          select_init
1987
2482
          {
1988
 
            Lex->statement= new statement::Select(YYSession);
 
2483
            LEX *lex= Lex;
 
2484
            lex->sql_command= SQLCOM_SELECT;
 
2485
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2486
            if (lex->statement == NULL)
 
2487
              DRIZZLE_YYABORT;
1989
2488
          }
1990
2489
        ;
1991
2490
 
1998
2497
select_paren:
1999
2498
          SELECT_SYM select_part2
2000
2499
          {
2001
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2500
            if (setup_select_in_parentheses(YYSession, Lex))
2002
2501
              DRIZZLE_YYABORT;
2003
2502
          }
2004
2503
        | '(' select_paren ')'
2008
2507
select_paren_derived:
2009
2508
          SELECT_SYM select_part2_derived
2010
2509
          {
2011
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2510
            if (setup_select_in_parentheses(YYSession, Lex))
2012
2511
              DRIZZLE_YYABORT;
2013
2512
          }
2014
2513
        | '(' select_paren_derived ')'
2017
2516
select_init2:
2018
2517
          select_part2
2019
2518
          {
2020
 
            Select_Lex * sel= Lex->current_select;
2021
 
            if (Lex->current_select->set_braces(0))
 
2519
            LEX *lex= Lex;
 
2520
            Select_Lex * sel= lex->current_select;
 
2521
            if (lex->current_select->set_braces(0))
2022
2522
            {
2023
 
              parser::my_parse_error(YYSession->m_lip);
 
2523
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2524
              my_parse_error(&pass);
2024
2525
              DRIZZLE_YYABORT;
2025
2526
            }
2026
2527
            if (sel->linkage == UNION_TYPE &&
2027
2528
                sel->master_unit()->first_select()->braces)
2028
2529
            {
2029
 
              parser::my_parse_error(YYSession->m_lip);
 
2530
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2531
              my_parse_error(&pass);
2030
2532
              DRIZZLE_YYABORT;
2031
2533
            }
2032
2534
          }
2035
2537
 
2036
2538
select_part2:
2037
2539
          {
2038
 
            Select_Lex *sel= Lex->current_select;
 
2540
            LEX *lex= Lex;
 
2541
            Select_Lex *sel= lex->current_select;
2039
2542
            if (sel->linkage != UNION_TYPE)
2040
 
              init_select(Lex);
2041
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2543
              mysql_init_select(lex);
 
2544
            lex->current_select->parsing_place= SELECT_LIST;
2042
2545
          }
2043
2546
          select_options select_item_list
2044
2547
          {
2068
2571
select_options:
2069
2572
          /* empty*/
2070
2573
        | select_option_list
2071
 
          { }
 
2574
          {
 
2575
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2576
                Lex->current_select->options & SELECT_ALL)
 
2577
            {
 
2578
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2579
              DRIZZLE_YYABORT;
 
2580
            }
 
2581
          }
2072
2582
        ;
2073
2583
 
2074
2584
select_option_list:
2076
2586
        | select_option
2077
2587
        ;
2078
2588
 
2079
 
select_option_distinct_or_all:
2080
 
          DISTINCT
2081
 
          {
2082
 
            Lex->current_select->options|= SELECT_DISTINCT; 
2083
 
 
2084
 
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
2085
 
            {
2086
 
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2087
 
              DRIZZLE_YYABORT;
2088
 
            }
2089
 
          }
2090
 
        | ALL
2091
 
          {
2092
 
            Lex->current_select->options|= SELECT_ALL; 
2093
 
 
2094
 
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
2095
 
            {
2096
 
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2097
 
              DRIZZLE_YYABORT;
2098
 
            }
2099
 
          }
2100
 
        ;
2101
 
 
2102
 
select_option_small_or_big:
2103
 
          SQL_SMALL_RESULT
2104
 
          {
2105
 
            Lex->current_select->options|= SELECT_SMALL_RESULT;
2106
 
 
2107
 
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
2108
 
            {
2109
 
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2110
 
              DRIZZLE_YYABORT;
2111
 
            }
2112
 
          }
2113
 
        | SQL_BIG_RESULT
2114
 
          {
2115
 
            Lex->current_select->options|= SELECT_BIG_RESULT;
2116
 
 
2117
 
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
2118
 
            {
2119
 
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2120
 
              DRIZZLE_YYABORT;
2121
 
            }
2122
 
          }
2123
 
        ;
2124
 
 
2125
 
 
2126
2589
select_option:
2127
2590
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2591
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2592
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2593
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2128
2594
        | SQL_BUFFER_RESULT
2129
2595
          {
2130
 
            if (check_simple_select(YYSession))
 
2596
            if (check_simple_select())
2131
2597
              DRIZZLE_YYABORT;
2132
2598
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2133
2599
          }
2134
 
        | select_option_small_or_big
2135
 
          { }
2136
 
        | select_option_distinct_or_all
2137
 
          { }
2138
2600
        | SQL_CALC_FOUND_ROWS
2139
2601
          {
2140
 
            if (check_simple_select(YYSession))
 
2602
            if (check_simple_select())
2141
2603
              DRIZZLE_YYABORT;
2142
2604
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2143
2605
          }
 
2606
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2144
2607
        ;
2145
2608
 
2146
2609
select_lock_type:
2147
2610
          /* empty */
2148
2611
        | FOR_SYM UPDATE_SYM
2149
2612
          {
2150
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2613
            LEX *lex=Lex;
 
2614
            lex->current_select->set_lock_for_tables(TL_WRITE);
2151
2615
          }
2152
2616
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2153
2617
          {
2154
 
            Lex->current_select->
 
2618
            LEX *lex=Lex;
 
2619
            lex->current_select->
2155
2620
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2156
2621
          }
2157
2622
        ;
2161
2626
        | select_item
2162
2627
        | '*'
2163
2628
          {
2164
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->getLex()->current_select->context, NULL, NULL, "*")))
 
2629
            Session *session= YYSession;
 
2630
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2631
                                                          context,
 
2632
                                                          NULL, NULL, "*")))
2165
2633
              DRIZZLE_YYABORT;
2166
 
 
2167
 
            (YYSession->getLex()->current_select->with_wild)++;
 
2634
            (session->lex->current_select->with_wild)++;
2168
2635
          }
2169
2636
        ;
2170
2637
 
2171
2638
select_item:
2172
2639
          remember_name table_wild remember_end
2173
2640
          {
2174
 
            if (YYSession->add_item_to_list($2))
 
2641
            Session *session= YYSession;
 
2642
 
 
2643
            if (session->add_item_to_list($2))
2175
2644
              DRIZZLE_YYABORT;
2176
2645
          }
2177
2646
        | remember_name expr remember_end select_alias
2178
2647
          {
 
2648
            Session *session= YYSession;
2179
2649
            assert($1 < $3);
2180
2650
 
2181
 
            if (YYSession->add_item_to_list($2))
 
2651
            if (session->add_item_to_list($2))
2182
2652
              DRIZZLE_YYABORT;
2183
 
 
2184
2653
            if ($4.str)
2185
2654
            {
2186
2655
              $2->is_autogenerated_name= false;
2188
2657
            }
2189
2658
            else if (!$2->name)
2190
2659
            {
2191
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2660
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2192
2661
            }
2193
2662
          }
2194
2663
        ;
2195
2664
 
2196
2665
remember_name:
2197
2666
          {
2198
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2667
            Session *session= YYSession;
 
2668
            Lex_input_stream *lip= session->m_lip;
2199
2669
            $$= (char*) lip->get_cpp_tok_start();
2200
2670
          }
2201
2671
        ;
2202
2672
 
2203
2673
remember_end:
2204
2674
          {
2205
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2675
            Session *session= YYSession;
 
2676
            Lex_input_stream *lip= session->m_lip;
2206
2677
            $$= (char*) lip->get_cpp_tok_end();
2207
2678
          }
2208
2679
        ;
2341
2812
          { $$= new Item_func_isnotnull($1); }
2342
2813
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
2343
2814
          { $$= new Item_func_equal($1,$3); }
2344
 
        | bool_pri comp_op predicate %prec '='
 
2815
        | bool_pri comp_op predicate %prec EQ
2345
2816
          { $$= (*$2)(0)->create($1,$3); }
2346
 
        | bool_pri comp_op all_or_any '(' subselect ')' %prec '='
 
2817
        | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
2347
2818
          { $$= all_any_subquery_creator($1, $2, $3, $5); }
2348
2819
        | predicate
2349
2820
        ;
2355
2826
          }
2356
2827
        | bit_expr not IN_SYM '(' subselect ')'
2357
2828
          {
2358
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2359
 
            $$= negate_expression(YYSession, item);
 
2829
            Session *session= YYSession;
 
2830
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2831
            $$= negate_expression(session, item);
2360
2832
          }
2361
2833
        | bit_expr IN_SYM '(' expr ')'
2362
2834
          {
2363
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2835
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2364
2836
          }
2365
2837
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2366
2838
          {
2370
2842
          }
2371
2843
        | bit_expr not IN_SYM '(' expr ')'
2372
2844
          {
2373
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2845
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2374
2846
          }
2375
2847
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2376
2848
          {
2381
2853
            $$= item;
2382
2854
          }
2383
2855
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2384
 
          {
2385
 
            $$= new Item_func_between($1,$3,$5);
2386
 
          }
 
2856
          { $$= new Item_func_between($1,$3,$5); }
2387
2857
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2388
2858
          {
2389
2859
            Item_func_between *item= new Item_func_between($1,$4,$6);
2391
2861
            $$= item;
2392
2862
          }
2393
2863
        | bit_expr LIKE simple_expr opt_escape
2394
 
          { 
2395
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
2396
 
          }
 
2864
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2397
2865
        | bit_expr not LIKE simple_expr opt_escape
2398
 
          { 
2399
 
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used));
2400
 
          }
2401
 
        | bit_expr REGEXP_SYM bit_expr
2402
 
          { 
2403
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2404
 
            args->push_back($1);
2405
 
            args->push_back($3);
2406
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2407
 
            {
2408
 
              DRIZZLE_YYABORT;
2409
 
            }
2410
 
          }
2411
 
        | bit_expr not REGEXP_SYM bit_expr
2412
 
          { 
2413
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2414
 
            args->push_back($1);
2415
 
            args->push_back($4);
2416
 
            args->push_back(new (YYSession->mem_root) Item_int(1));
2417
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2418
 
            {
2419
 
              DRIZZLE_YYABORT;
2420
 
            }
2421
 
          }
 
2866
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2422
2867
        | bit_expr
2423
2868
        ;
2424
2869
 
2457
2902
        ;
2458
2903
 
2459
2904
comp_op:
2460
 
          '='     { $$ = &comp_eq_creator; }
 
2905
          EQ     { $$ = &comp_eq_creator; }
2461
2906
        | GE     { $$ = &comp_ge_creator; }
2462
 
        | '>' { $$ = &comp_gt_creator; }
 
2907
        | GT_SYM { $$ = &comp_gt_creator; }
2463
2908
        | LE     { $$ = &comp_le_creator; }
2464
 
        | '<'     { $$ = &comp_lt_creator; }
 
2909
        | LT     { $$ = &comp_lt_creator; }
2465
2910
        | NE     { $$ = &comp_ne_creator; }
2466
2911
        ;
2467
2912
 
2476
2921
        | function_call_nonkeyword
2477
2922
        | function_call_generic
2478
2923
        | function_call_conflict
2479
 
        | simple_expr COLLATE_SYM ident_or_text %prec UMINUS
 
2924
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2480
2925
          {
2481
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
2926
            Session *session= YYSession;
 
2927
            Item *i1= new (session->mem_root) Item_string($3.str,
2482
2928
                                                      $3.length,
2483
 
                                                      YYSession->charset());
2484
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
2929
                                                      session->charset());
 
2930
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2485
2931
          }
2486
2932
        | literal
2487
2933
        | variable
2489
2935
          {
2490
2936
            Lex->setSumExprUsed();
2491
2937
          }
2492
 
        | '+' simple_expr %prec UMINUS { $$= $2; }
2493
 
        | '-' simple_expr %prec UMINUS
 
2938
        | '+' simple_expr %prec NEG { $$= $2; }
 
2939
        | '-' simple_expr %prec NEG
2494
2940
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2495
2941
        | '(' subselect ')'
2496
2942
          {
2512
2958
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
2513
2959
          }
2514
2960
        | '{' ident expr '}' { $$= $3; }
2515
 
        | BINARY simple_expr %prec UMINUS
 
2961
        | BINARY simple_expr %prec NEG
2516
2962
          {
2517
2963
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
2518
2964
                                 &my_charset_bin);
2519
2965
          }
2520
2966
        | CAST_SYM '(' expr AS cast_type ')'
2521
2967
          {
2522
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2523
 
                                 Lex->charset);
 
2968
            LEX *lex= Lex;
 
2969
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
2970
                                 lex->charset);
2524
2971
            if (!$$)
2525
2972
              DRIZZLE_YYABORT;
2526
2973
          }
2538
2985
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2539
2986
                                                         $3);
2540
2987
          }
2541
 
        | VALUES '(' simple_ident ')'
 
2988
        | VALUES '(' simple_ident_nospvar ')'
2542
2989
          {
2543
2990
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2544
2991
                                                        $3);
2559
3006
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
2560
3007
        | CURRENT_USER optional_braces
2561
3008
          {
2562
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3009
            std::string user_str("user");
 
3010
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2563
3011
            {
2564
3012
              DRIZZLE_YYABORT;
2565
3013
            }
2575
3023
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
2576
3024
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2577
3025
          {
2578
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3026
            Session *session= YYSession;
 
3027
            List<Item> *list= new (session->mem_root) List<Item>;
2579
3028
            list->push_front($5);
2580
3029
            list->push_front($3);
2581
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2582
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3030
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3031
            $$= new (session->mem_root) Item_func_interval(item);
2583
3032
          }
2584
3033
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2585
3034
          {
 
3035
            Session *session= YYSession;
2586
3036
            $7->push_front($5);
2587
3037
            $7->push_front($3);
2588
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2589
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3038
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3039
            $$= new (session->mem_root) Item_func_interval(item);
2590
3040
          }
2591
3041
        | LEFT '(' expr ',' expr ')'
2592
3042
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2618
3068
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2619
3069
        | USER '(' ')'
2620
3070
          {
2621
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3071
            std::string user_str("user");
 
3072
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2622
3073
            {
2623
3074
              DRIZZLE_YYABORT;
2624
3075
            }
2679
3130
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2680
3131
        | SUBSTRING '(' expr ',' expr ',' expr ')'
2681
3132
          {
 
3133
            std::string reverse_str("substr");
2682
3134
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2683
3135
            args->push_back($3);
2684
3136
            args->push_back($5);
2685
3137
            args->push_back($7);
2686
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3138
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2687
3139
            {
2688
3140
              DRIZZLE_YYABORT;
2689
3141
            }
2690
3142
          }
2691
3143
        | SUBSTRING '(' expr ',' expr ')'
2692
3144
          {
 
3145
            std::string reverse_str("substr");
2693
3146
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2694
3147
            args->push_back($3);
2695
3148
            args->push_back($5);
2696
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3149
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2697
3150
            {
2698
3151
              DRIZZLE_YYABORT;
2699
3152
            }
2700
3153
          }
2701
3154
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
2702
3155
          {
 
3156
            std::string reverse_str("substr");
2703
3157
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2704
3158
            args->push_back($3);
2705
3159
            args->push_back($5);
2706
3160
            args->push_back($7);
2707
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3161
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2708
3162
            {
2709
3163
              DRIZZLE_YYABORT;
2710
3164
            }
2711
3165
          }
2712
3166
        | SUBSTRING '(' expr FROM expr ')'
2713
3167
          {
 
3168
            std::string reverse_str("substr");
2714
3169
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2715
3170
            args->push_back($3);
2716
3171
            args->push_back($5);
2717
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3172
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2718
3173
            {
2719
3174
              DRIZZLE_YYABORT;
2720
3175
            }
2757
3212
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2758
3213
        | DATABASE '(' ')'
2759
3214
          {
2760
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
2761
 
            {
2762
 
              DRIZZLE_YYABORT;
2763
 
            }
2764
 
            Lex->setCacheable(false);
2765
 
          }
2766
 
        | CATALOG_SYM '(' ')'
2767
 
          {
2768
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
2769
 
            {
2770
 
              DRIZZLE_YYABORT;
2771
 
            }
2772
 
            Lex->setCacheable(false);
2773
 
          }
2774
 
        | EXECUTE_SYM '(' expr ')' opt_wait
2775
 
          {
2776
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2777
 
            args->push_back($3);
2778
 
 
2779
 
            if ($5)
2780
 
            {
2781
 
              args->push_back(new (YYSession->mem_root) Item_int(1));
2782
 
            }
2783
 
 
2784
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
2785
 
            {
2786
 
              DRIZZLE_YYABORT;
2787
 
            }
2788
 
          }
 
3215
            std::string database_str("database");
 
3216
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
 
3217
            {
 
3218
              DRIZZLE_YYABORT;
 
3219
            }
 
3220
            Lex->setCacheable(false);
 
3221
          }
2789
3222
        | IF '(' expr ',' expr ',' expr ')'
2790
3223
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
2791
 
        | KILL_SYM kill_option '(' expr ')'
2792
 
          {
2793
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2794
 
            args->push_back($4);
2795
 
 
2796
 
            if ($2)
2797
 
            {
2798
 
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2799
 
            }
2800
 
 
2801
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "kill", args)))
2802
 
            {
2803
 
              DRIZZLE_YYABORT;
2804
 
            }
2805
 
          }
2806
3224
        | MICROSECOND_SYM '(' expr ')'
2807
3225
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
2808
3226
        | MOD_SYM '(' expr ',' expr ')'
2813
3231
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
2814
3232
        | REPLACE '(' expr ',' expr ',' expr ')'
2815
3233
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3234
        | REVERSE_SYM '(' expr ')'
 
3235
          {
 
3236
            std::string reverse_str("reverse");
 
3237
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3238
            args->push_back($3);
 
3239
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
3240
            {
 
3241
              DRIZZLE_YYABORT;
 
3242
            }
 
3243
          }
2816
3244
        | TRUNCATE_SYM '(' expr ',' expr ')'
2817
3245
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2818
 
        | WAIT_SYM '(' expr ')'
2819
 
          {
2820
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2821
 
            args->push_back($3);
2822
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "wait", args)))
2823
 
            {
2824
 
              DRIZZLE_YYABORT;
2825
 
            }
2826
 
          }
2827
 
        | UUID_SYM '(' ')'
2828
 
          {
2829
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
2830
 
            {
2831
 
              DRIZZLE_YYABORT;
2832
 
            }
2833
 
            Lex->setCacheable(false);
2834
 
          }
2835
 
        | WAIT_SYM '(' expr ',' expr ')'
2836
 
          {
2837
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2838
 
            args->push_back($3);
2839
 
            args->push_back($5);
2840
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "wait", args)))
2841
 
            {
2842
 
              DRIZZLE_YYABORT;
2843
 
            }
2844
 
          }
2845
3246
        ;
2846
3247
 
2847
3248
/*
2862
3263
          }
2863
3264
          opt_udf_expr_list ')'
2864
3265
          {
 
3266
            Session *session= YYSession;
2865
3267
            Create_func *builder;
2866
3268
            Item *item= NULL;
2867
3269
 
2877
3279
            builder= find_native_function_builder($1);
2878
3280
            if (builder)
2879
3281
            {
2880
 
              item= builder->create(YYSession, $1, $4);
 
3282
              item= builder->create(session, $1, $4);
2881
3283
            }
2882
3284
            else
2883
3285
            {
2885
3287
              const plugin::Function *udf= $<udf>3;
2886
3288
              if (udf)
2887
3289
              {
2888
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3290
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2889
3291
              } else {
2890
3292
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2891
3293
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
2988
3390
            sel->in_sum_expr--;
2989
3391
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
2990
3392
                                          sel->gorder_list, $7);
2991
 
            $5->clear();
 
3393
            $5->empty();
2992
3394
          }
2993
3395
        ;
2994
3396
 
3002
3404
        ;
3003
3405
 
3004
3406
variable_aux:
3005
 
          user_variable_ident SET_VAR expr
 
3407
          ident_or_text SET_VAR expr
3006
3408
          {
3007
3409
            $$= new Item_func_set_user_var($1, $3);
3008
3410
            Lex->setCacheable(false);
3009
3411
          }
3010
 
        | user_variable_ident
 
3412
        | ident_or_text
3011
3413
          {
3012
3414
            $$= new Item_func_get_user_var(*YYSession, $1);
3013
3415
            Lex->setCacheable(false);
3014
3416
          }
3015
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3417
        | '@' opt_var_ident_type ident_or_text opt_component
3016
3418
          {
3017
3419
            /* disallow "SELECT @@global.global.variable" */
3018
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3420
            if ($3.str && $4.str && check_reserved_words(&$3))
3019
3421
            {
3020
 
              parser::my_parse_error(YYSession->m_lip);
 
3422
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3423
              my_parse_error(&pass);
3021
3424
              DRIZZLE_YYABORT;
3022
3425
            }
3023
3426
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3026
3429
        ;
3027
3430
 
3028
3431
opt_distinct:
3029
 
          /* empty */ { $$ = false; }
3030
 
        | DISTINCT    { $$ = true; }
 
3432
          /* empty */ { $$ = 0; }
 
3433
        | DISTINCT    { $$ = 1; }
3031
3434
        ;
3032
3435
 
3033
3436
opt_gconcat_separator:
3049
3452
            select->gorder_list=
3050
3453
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
3051
3454
                                     sizeof(st_sql_list));
3052
 
            select->order_list.clear();
 
3455
            select->order_list.empty();
3053
3456
          }
3054
3457
        ;
3055
3458
 
3056
3459
in_sum_expr:
3057
3460
          opt_all
3058
3461
          {
3059
 
            if (Lex->current_select->inc_in_sum_expr())
 
3462
            LEX *lex= Lex;
 
3463
            if (lex->current_select->inc_in_sum_expr())
3060
3464
            {
3061
 
              parser::my_parse_error(YYSession->m_lip);
 
3465
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3466
              my_parse_error(&pass);
3062
3467
              DRIZZLE_YYABORT;
3063
3468
            }
3064
3469
          }
3072
3477
cast_type:
3073
3478
          BINARY opt_len
3074
3479
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3075
 
        | BOOLEAN_SYM
3076
 
          { $$=ITEM_CAST_BOOLEAN; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3077
 
        | SIGNED_SYM
3078
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3079
 
        | SIGNED_SYM INT_SYM
3080
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3081
 
        | INT_SYM
3082
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3083
 
        | UNSIGNED_SYM
3084
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3085
 
        | UNSIGNED_SYM INT_SYM
3086
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3087
3480
        | CHAR_SYM opt_len
3088
3481
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3089
3482
        | DATE_SYM
3090
3483
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3091
 
        | TIME_SYM
3092
 
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3093
3484
        | DATETIME_SYM
3094
3485
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3095
3486
        | DECIMAL_SYM float_options
3140
3531
          table_factor { $$=$1; }
3141
3532
        | join_table
3142
3533
          {
3143
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3534
            LEX *lex= Lex;
 
3535
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3144
3536
              DRIZZLE_YYABORT;
3145
3537
          }
3146
3538
        ;
3287
3679
          }
3288
3680
          expr
3289
3681
          {
3290
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3682
            LEX *lex= Lex;
 
3683
            if (!($$= lex->current_select->convert_right_join()))
3291
3684
              DRIZZLE_YYABORT;
3292
3685
            add_join_on($$, $8);
3293
3686
            Lex->pop_context();
3299
3692
          }
3300
3693
          USING '(' using_list ')'
3301
3694
          {
3302
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3695
            LEX *lex= Lex;
 
3696
            if (!($$= lex->current_select->convert_right_join()))
3303
3697
              DRIZZLE_YYABORT;
3304
3698
            add_join_natural($$,$5,$9,Lex->current_select);
3305
3699
          }
3307
3701
          {
3308
3702
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3309
3703
            add_join_natural($6,$1,NULL,Lex->current_select);
3310
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3704
            LEX *lex= Lex;
 
3705
            if (!($$= lex->current_select->convert_right_join()))
3311
3706
              DRIZZLE_YYABORT;
3312
3707
          }
3313
3708
        ;
3315
3710
normal_join:
3316
3711
          JOIN_SYM {}
3317
3712
        | INNER_SYM JOIN_SYM {}
3318
 
        | CROSS JOIN_SYM
3319
 
          {
3320
 
            Lex->is_cross= true;
3321
 
            Lex->current_select->is_cross= true;
3322
 
          }
 
3713
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3323
3714
        ;
3324
3715
 
3325
3716
/*
3344
3735
          }
3345
3736
        | select_derived_init get_select_lex select_derived2
3346
3737
          {
3347
 
            Select_Lex *sel= Lex->current_select;
 
3738
            LEX *lex= Lex;
 
3739
            Select_Lex *sel= lex->current_select;
3348
3740
            if ($1)
3349
3741
            {
3350
3742
              if (sel->set_braces(1))
3351
3743
              {
3352
 
                parser::my_parse_error(YYSession->m_lip);
 
3744
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3745
                my_parse_error(&pass);
3353
3746
                DRIZZLE_YYABORT;
3354
3747
              }
3355
3748
              /* select in braces, can't contain global parameters */
3357
3750
                sel->master_unit()->global_parameters=
3358
3751
                   sel->master_unit()->fake_select_lex;
3359
3752
            }
3360
 
            if ($2->init_nested_join(Lex->session))
 
3753
            if ($2->init_nested_join(lex->session))
3361
3754
              DRIZZLE_YYABORT;
3362
3755
            $$= 0;
3363
3756
            /* incomplete derived tables return NULL, we must be
3399
3792
              /* Handle case of derived table, alias may be NULL if there
3400
3793
                 are no outer parentheses, add_table_to_list() will throw
3401
3794
                 error in this case */
3402
 
              Select_Lex *sel= Lex->current_select;
 
3795
              LEX *lex=Lex;
 
3796
              Select_Lex *sel= lex->current_select;
3403
3797
              Select_Lex_Unit *unit= sel->master_unit();
3404
 
              Lex->current_select= sel= unit->outer_select();
3405
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3798
              lex->current_select= sel= unit->outer_select();
 
3799
              if (!($$= sel->add_table_to_list(lex->session,
3406
3800
                                               new Table_ident(unit), $5, 0,
3407
3801
                                               TL_READ)))
3408
3802
 
3409
3803
                DRIZZLE_YYABORT;
3410
3804
              sel->add_joined_table($$);
3411
 
              Lex->pop_context();
 
3805
              lex->pop_context();
3412
3806
            }
3413
3807
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3414
3808
            {
3415
3809
              /* simple nested joins cannot have aliases or unions */
3416
 
              parser::my_parse_error(YYSession->m_lip);
 
3810
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3811
              my_parse_error(&pass);
3417
3812
              DRIZZLE_YYABORT;
3418
3813
            }
3419
3814
            else
3427
3822
          UNION_SYM
3428
3823
          union_option
3429
3824
          {
3430
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3825
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3431
3826
              DRIZZLE_YYABORT;
3432
3827
          }
3433
3828
          query_specification
3445
3840
select_init2_derived:
3446
3841
          select_part2_derived
3447
3842
          {
3448
 
            Select_Lex * sel= Lex->current_select;
3449
 
            if (Lex->current_select->set_braces(0))
 
3843
            LEX *lex= Lex;
 
3844
            Select_Lex * sel= lex->current_select;
 
3845
            if (lex->current_select->set_braces(0))
3450
3846
            {
3451
 
              parser::my_parse_error(YYSession->m_lip);
 
3847
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3848
              my_parse_error(&pass);
3452
3849
              DRIZZLE_YYABORT;
3453
3850
            }
3454
3851
            if (sel->linkage == UNION_TYPE &&
3455
3852
                sel->master_unit()->first_select()->braces)
3456
3853
            {
3457
 
              parser::my_parse_error(YYSession->m_lip);
 
3854
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3855
              my_parse_error(&pass);
3458
3856
              DRIZZLE_YYABORT;
3459
3857
            }
3460
3858
          }
3463
3861
/* The equivalent of select_part2 for nested queries. */
3464
3862
select_part2_derived:
3465
3863
          {
3466
 
            Select_Lex *sel= Lex->current_select;
 
3864
            LEX *lex= Lex;
 
3865
            Select_Lex *sel= lex->current_select;
3467
3866
            if (sel->linkage != UNION_TYPE)
3468
 
              init_select(Lex);
3469
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3867
              mysql_init_select(lex);
 
3868
            lex->current_select->parsing_place= SELECT_LIST;
3470
3869
          }
3471
3870
          select_options select_item_list
3472
3871
          {
3479
3878
select_derived:
3480
3879
          get_select_lex
3481
3880
          {
3482
 
            if ($1->init_nested_join(Lex->session))
 
3881
            LEX *lex= Lex;
 
3882
            if ($1->init_nested_join(lex->session))
3483
3883
              DRIZZLE_YYABORT;
3484
3884
          }
3485
3885
          derived_table_list
3486
3886
          {
 
3887
            LEX *lex= Lex;
3487
3888
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3488
3889
               for derived tables, both must equal NULL */
3489
3890
 
3490
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
3891
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3491
3892
              DRIZZLE_YYABORT;
3492
 
 
3493
3893
            if (!$3 && $$)
3494
3894
            {
3495
 
              parser::my_parse_error(YYSession->m_lip);
 
3895
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3896
              my_parse_error(&pass);
3496
3897
              DRIZZLE_YYABORT;
3497
3898
            }
3498
3899
          }
3500
3901
 
3501
3902
select_derived2:
3502
3903
          {
3503
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3504
 
            if (not Lex->expr_allows_subselect)
 
3904
            LEX *lex= Lex;
 
3905
            lex->derived_tables|= DERIVED_SUBQUERY;
 
3906
            if (!lex->expr_allows_subselect)
3505
3907
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
3908
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3909
              my_parse_error(&pass);
3507
3910
              DRIZZLE_YYABORT;
3508
3911
            }
3509
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
3912
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
3913
                mysql_new_select(lex, 1))
3510
3914
              DRIZZLE_YYABORT;
3511
 
            init_select(Lex);
3512
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3513
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3915
            mysql_init_select(lex);
 
3916
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3917
            lex->current_select->parsing_place= SELECT_LIST;
3514
3918
          }
3515
3919
          select_options select_item_list
3516
3920
          {
3526
3930
select_derived_init:
3527
3931
          SELECT_SYM
3528
3932
          {
3529
 
            Select_Lex *sel= Lex->current_select;
 
3933
            LEX *lex= Lex;
 
3934
 
 
3935
            Select_Lex *sel= lex->current_select;
3530
3936
            TableList *embedding;
3531
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
3937
            if (!sel->embedding || sel->end_nested_join(lex->session))
3532
3938
            {
3533
3939
              /* we are not in parentheses */
3534
 
              parser::my_parse_error(YYSession->m_lip);
 
3940
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3941
              my_parse_error(&pass);
3535
3942
              DRIZZLE_YYABORT;
3536
3943
            }
3537
3944
            embedding= Lex->current_select->embedding;
3673
4080
table_alias:
3674
4081
          /* empty */
3675
4082
        | AS
 
4083
        | EQ
3676
4084
        ;
3677
4085
 
3678
4086
opt_table_alias:
3679
4087
          /* empty */ { $$=0; }
3680
4088
        | table_alias ident
3681
 
          {
3682
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3683
 
          }
 
4089
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3684
4090
        ;
3685
4091
 
3686
4092
opt_all:
3760
4166
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3761
4167
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3762
4168
            */
3763
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4169
            LEX *lex= Lex;
 
4170
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3764
4171
            {
3765
4172
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3766
4173
                       "global union parameters");
3767
4174
              DRIZZLE_YYABORT;
3768
4175
            }
3769
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4176
            lex->current_select->olap= ROLLUP_TYPE;
3770
4177
          }
3771
4178
        ;
3772
4179
 
3784
4191
        ;
3785
4192
 
3786
4193
alter_order_item:
3787
 
          simple_ident order_dir
 
4194
          simple_ident_nospvar order_dir
3788
4195
          {
 
4196
            Session *session= YYSession;
3789
4197
            bool ascending= ($2 == 1) ? true : false;
3790
 
            if (YYSession->add_order_to_list($1, ascending))
 
4198
            if (session->add_order_to_list($1, ascending))
3791
4199
              DRIZZLE_YYABORT;
3792
4200
          }
3793
4201
        ;
3804
4212
order_clause:
3805
4213
          ORDER_SYM BY
3806
4214
          {
3807
 
            if (not parser::buildOrderBy(Lex))
 
4215
            LEX *lex=Lex;
 
4216
            Select_Lex *sel= lex->current_select;
 
4217
            Select_Lex_Unit *unit= sel-> master_unit();
 
4218
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4219
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4220
                (sel->linkage != UNION_TYPE || sel->braces))
 
4221
            {
 
4222
              my_error(ER_WRONG_USAGE, MYF(0),
 
4223
                       "CUBE/ROLLUP", "ORDER BY");
3808
4224
              DRIZZLE_YYABORT;
 
4225
            }
 
4226
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4227
            {
 
4228
              /*
 
4229
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4230
                executed in the same way as the query
 
4231
                SELECT ... ORDER BY order_list
 
4232
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4233
                Otherwise we create a fake Select_Lex if it has not been created
 
4234
                yet.
 
4235
              */
 
4236
              Select_Lex *first_sl= unit->first_select();
 
4237
              if (!unit->is_union() &&
 
4238
                  (first_sl->order_list.elements ||
 
4239
                   first_sl->select_limit) &&           
 
4240
                  unit->add_fake_select_lex(lex->session))
 
4241
                DRIZZLE_YYABORT;
 
4242
            }
3809
4243
          }
3810
4244
          order_list
3811
4245
        ;
3812
4246
 
3813
4247
order_list:
3814
4248
          order_list ',' order_ident order_dir
3815
 
          {
3816
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3817
 
              DRIZZLE_YYABORT;
3818
 
          }
 
4249
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3819
4250
        | order_ident order_dir
3820
 
          {
3821
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3822
 
              DRIZZLE_YYABORT;
3823
 
          }
 
4251
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3824
4252
        ;
3825
4253
 
3826
4254
order_dir:
3832
4260
opt_limit_clause_init:
3833
4261
          /* empty */
3834
4262
          {
3835
 
            Select_Lex *sel= Lex->current_select;
 
4263
            LEX *lex= Lex;
 
4264
            Select_Lex *sel= lex->current_select;
3836
4265
            sel->offset_limit= 0;
3837
4266
            sel->select_limit= 0;
3838
4267
          }
3881
4310
delete_limit_clause:
3882
4311
          /* empty */
3883
4312
          {
3884
 
            Lex->current_select->select_limit= 0;
 
4313
            LEX *lex=Lex;
 
4314
            lex->current_select->select_limit= 0;
3885
4315
          }
3886
4316
        | LIMIT limit_option
3887
4317
          {
3892
4322
        ;
3893
4323
 
3894
4324
ulong_num:
3895
 
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3896
 
        | HEX_NUM       { $$= (unsigned long) strtol($1.str, (char**) 0, 16); }
3897
 
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3898
 
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3899
 
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3900
 
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4325
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4326
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4327
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4328
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4329
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4330
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3901
4331
        ;
3902
4332
 
3903
4333
ulonglong_num:
3910
4340
 
3911
4341
select_var_list_init:
3912
4342
          {
3913
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4343
            LEX *lex=Lex;
 
4344
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3914
4345
              DRIZZLE_YYABORT;
3915
4346
          }
3916
4347
          select_var_list
3923
4354
        ;
3924
4355
 
3925
4356
select_var_ident: 
3926
 
          '@' user_variable_ident
 
4357
          '@' ident_or_text
3927
4358
          {
3928
 
            if (Lex->result)
3929
 
            {
3930
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3931
 
            }
 
4359
            LEX *lex=Lex;
 
4360
            if (lex->result)
 
4361
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3932
4362
            else
3933
 
            {
3934
4363
              /*
3935
4364
                The parser won't create select_result instance only
3936
4365
                if it's an EXPLAIN.
3937
4366
              */
3938
 
              assert(Lex->describe);
3939
 
            }
 
4367
              assert(lex->describe);
3940
4368
          }
3941
4369
        ;
3942
4370
 
3949
4377
into_destination:
3950
4378
          OUTFILE TEXT_STRING_filesystem
3951
4379
          {
3952
 
            Lex->setCacheable(false);
3953
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3954
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4380
            LEX *lex= Lex;
 
4381
            lex->setCacheable(false);
 
4382
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4383
                !(lex->result= new select_export(lex->exchange)))
3955
4384
              DRIZZLE_YYABORT;
3956
4385
          }
3957
4386
          opt_field_term opt_line_term
3958
4387
        | DUMPFILE TEXT_STRING_filesystem
3959
4388
          {
3960
 
            if (not Lex->describe)
 
4389
            LEX *lex=Lex;
 
4390
            if (!lex->describe)
3961
4391
            {
3962
 
              Lex->setCacheable(false);
3963
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4392
              lex->setCacheable(false);
 
4393
              if (!(lex->exchange= new file_exchange($2.str,1)))
3964
4394
                DRIZZLE_YYABORT;
3965
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4395
              if (!(lex->result= new select_dump(lex->exchange)))
3966
4396
                DRIZZLE_YYABORT;
3967
4397
            }
3968
4398
          }
3975
4405
*/
3976
4406
 
3977
4407
drop:
3978
 
          DROP CATALOG_SYM catalog_name
3979
 
          {
3980
 
            Lex->statement= new statement::catalog::Drop(YYSession, $3);
3981
 
          }
3982
 
        | DROP opt_temporary table_or_tables if_exists table_list
3983
 
          {
3984
 
            statement::DropTable *statement= new statement::DropTable(YYSession);
3985
 
            Lex->statement= statement;
 
4408
          DROP opt_temporary table_or_tables if_exists table_list
 
4409
          {
 
4410
            LEX *lex=Lex;
 
4411
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4412
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4413
            lex->statement= statement;
 
4414
            if (lex->statement == NULL)
 
4415
              DRIZZLE_YYABORT;
3986
4416
            statement->drop_temporary= $2;
3987
4417
            statement->drop_if_exists= $4;
3988
4418
          }
3989
4419
        | DROP build_method INDEX_SYM ident ON table_ident {}
3990
4420
          {
3991
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
3992
 
            Lex->statement= statement;
 
4421
            LEX *lex=Lex;
 
4422
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4423
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4424
            lex->statement= statement;
 
4425
            if (lex->statement == NULL)
 
4426
              DRIZZLE_YYABORT;
3993
4427
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
3994
4428
            statement->alter_info.build_method= $2;
3995
4429
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
3996
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
3997
 
                                                          TL_OPTION_UPDATING))
 
4430
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4431
                                                        TL_OPTION_UPDATING))
3998
4432
              DRIZZLE_YYABORT;
3999
4433
          }
4000
 
        | DROP DATABASE if_exists schema_name
 
4434
        | DROP DATABASE if_exists ident
4001
4435
          {
4002
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4003
 
            Lex->statement= statement;
 
4436
            LEX *lex=Lex;
 
4437
            lex->sql_command= SQLCOM_DROP_DB;
 
4438
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4439
            lex->statement= statement;
 
4440
            if (lex->statement == NULL)
 
4441
              DRIZZLE_YYABORT;
4004
4442
            statement->drop_if_exists=$3;
4005
 
            Lex->name= $4;
 
4443
            lex->name= $4;
4006
4444
          }
4007
 
        ;
4008
 
 
4009
4445
table_list:
4010
4446
          table_name
4011
4447
        | table_list ',' table_name
4020
4456
        ;
4021
4457
 
4022
4458
if_exists:
4023
 
          /* empty */ { $$= false; }
4024
 
        | IF EXISTS { $$= true; }
 
4459
          /* empty */ { $$= 0; }
 
4460
        | IF EXISTS { $$= 1; }
4025
4461
        ;
4026
4462
 
4027
4463
opt_temporary:
4028
 
          /* empty */ { $$= false; }
4029
 
        | TEMPORARY_SYM { $$= true; }
 
4464
          /* empty */ { $$= 0; }
 
4465
        | TEMPORARY_SYM { $$= 1; }
4030
4466
        ;
4031
4467
 
4032
4468
/*
4033
4469
  Execute a string as dynamic SQL.
4034
 
*/
 
4470
  */
4035
4471
 
4036
4472
execute:
4037
 
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
4038
 
        {
4039
 
          Lex->statement= new statement::Execute(YYSession, $2, $3, $4, $5);
4040
 
        }
 
4473
       EXECUTE_SYM
 
4474
       {
 
4475
          LEX *lex= Lex;
 
4476
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession);
 
4477
          lex->statement= statement;
 
4478
          if (lex->statement == NULL)
 
4479
            DRIZZLE_YYABORT;
 
4480
       }
 
4481
       execute_var_or_string
4041
4482
 
4042
4483
 
4043
4484
execute_var_or_string:
4044
 
         user_variable_ident
 
4485
         ident_or_text
4045
4486
         {
4046
 
            $$.set($1);
 
4487
          statement::Execute *statement= (statement::Execute *)Lex->statement;
 
4488
          statement->setQuery($1);
4047
4489
         }
4048
 
        | '@' user_variable_ident
 
4490
        | '@' ident_or_text
4049
4491
        {
4050
 
            $$.set($2, true);
 
4492
          statement::Execute *statement= (statement::Execute *)Lex->statement;
 
4493
          statement->setVar();
 
4494
          statement->setQuery($2);
4051
4495
        }
4052
4496
 
4053
 
opt_status:
4054
 
          /* empty */ { $$= false; }
4055
 
        | WITH NO_SYM RETURN_SYM { $$= true; }
4056
 
        ;
4057
 
 
4058
 
opt_concurrent:
4059
 
          /* empty */ { $$= false; }
4060
 
        | CONCURRENT { $$= true; }
4061
 
        ;
4062
 
 
4063
 
opt_wait:
4064
 
          /* empty */ { $$= false; }
4065
 
        | WAIT_SYM { $$= true; }
4066
 
        ;
4067
 
 
4068
4497
/*
4069
4498
** Insert : add new data to table
4070
4499
*/
4072
4501
insert:
4073
4502
          INSERT
4074
4503
          {
4075
 
            Lex->statement= new statement::Insert(YYSession);
4076
 
            Lex->duplicates= DUP_ERROR;
4077
 
            init_select(Lex);
 
4504
            LEX *lex= Lex;
 
4505
            lex->sql_command= SQLCOM_INSERT;
 
4506
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4507
            if (lex->statement == NULL)
 
4508
              DRIZZLE_YYABORT;
 
4509
            lex->duplicates= DUP_ERROR;
 
4510
            mysql_init_select(lex);
4078
4511
            /* for subselects */
4079
 
            Lex->lock_option= TL_READ;
 
4512
            lex->lock_option= TL_READ;
4080
4513
          }
4081
4514
          opt_ignore insert2
4082
4515
          {
4090
4523
replace:
4091
4524
          REPLACE
4092
4525
          {
4093
 
            Lex->statement= new statement::Replace(YYSession);
4094
 
            Lex->duplicates= DUP_REPLACE;
4095
 
            init_select(Lex);
 
4526
            LEX *lex= Lex;
 
4527
            lex->sql_command= SQLCOM_REPLACE;
 
4528
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4529
            if (lex->statement == NULL)
 
4530
              DRIZZLE_YYABORT;
 
4531
            lex->duplicates= DUP_REPLACE;
 
4532
            mysql_init_select(lex);
4096
4533
          }
4097
4534
          insert2
4098
4535
          {
4111
4548
insert_table:
4112
4549
          table_name
4113
4550
          {
4114
 
            Lex->field_list.clear();
4115
 
            Lex->many_values.clear();
4116
 
            Lex->insert_list=0;
 
4551
            LEX *lex=Lex;
 
4552
            lex->field_list.empty();
 
4553
            lex->many_values.empty();
 
4554
            lex->insert_list=0;
4117
4555
          };
4118
4556
 
4119
4557
insert_field_spec:
4120
4558
          insert_values {}
4121
4559
        | '(' ')' insert_values {}
4122
4560
        | '(' fields ')' insert_values {}
4123
 
        | SET_SYM
 
4561
        | SET
4124
4562
          {
4125
 
            if (not (Lex->insert_list = new List_item) ||
4126
 
                Lex->many_values.push_back(Lex->insert_list))
 
4563
            LEX *lex=Lex;
 
4564
            if (!(lex->insert_list = new List_item) ||
 
4565
                lex->many_values.push_back(lex->insert_list))
4127
4566
              DRIZZLE_YYABORT;
4128
4567
          }
4129
4568
          ident_eq_list
4137
4576
insert_values:
4138
4577
          VALUES values_list {}
4139
4578
        | VALUE_SYM values_list {}
4140
 
        | stored_select
4141
 
          {
4142
 
            Lex->current_select->set_braces(0);
4143
 
          }
 
4579
        | create_select
 
4580
          { Lex->current_select->set_braces(0);}
4144
4581
          union_clause {}
4145
 
        | '(' stored_select ')'
4146
 
          {
4147
 
            Lex->current_select->set_braces(1);
4148
 
          }
 
4582
        | '(' create_select ')'
 
4583
          { Lex->current_select->set_braces(1);}
4149
4584
          union_opt {}
4150
4585
        ;
4151
4586
 
4160
4595
        ;
4161
4596
 
4162
4597
ident_eq_value:
4163
 
          simple_ident equal expr_or_default
 
4598
          simple_ident_nospvar equal expr_or_default
4164
4599
          {
4165
 
            if (Lex->field_list.push_back($1) ||
4166
 
                Lex->insert_list->push_back($3))
 
4600
            LEX *lex=Lex;
 
4601
            if (lex->field_list.push_back($1) ||
 
4602
                lex->insert_list->push_back($3))
4167
4603
              DRIZZLE_YYABORT;
4168
4604
          }
4169
4605
        ;
4170
4606
 
4171
4607
equal:
4172
 
          '=' {}
 
4608
          EQ {}
4173
4609
        | SET_VAR {}
4174
4610
        ;
4175
4611
 
4186
4622
          }
4187
4623
          opt_values ')'
4188
4624
          {
4189
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4625
            LEX *lex=Lex;
 
4626
            if (lex->many_values.push_back(lex->insert_list))
4190
4627
              DRIZZLE_YYABORT;
4191
4628
          }
4192
4629
        ;
4223
4660
/* Update rows in a table */
4224
4661
 
4225
4662
update:
4226
 
          UPDATE_SYM opt_ignore table_ident SET_SYM update_list
4227
 
          {
4228
 
            init_select(Lex);
4229
 
            Lex->statement= new statement::Update(YYSession);
4230
 
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
4231
 
            Lex->duplicates= DUP_ERROR;
4232
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4233
 
              DRIZZLE_YYABORT;
4234
 
 
4235
 
            if (Lex->select_lex.get_table_list()->derived)
 
4663
          UPDATE_SYM opt_ignore table_ident
 
4664
          {
 
4665
            LEX *lex= Lex;
 
4666
            mysql_init_select(lex);
 
4667
            lex->sql_command= SQLCOM_UPDATE;
 
4668
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4669
            if (lex->statement == NULL)
 
4670
              DRIZZLE_YYABORT;
 
4671
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4672
            lex->duplicates= DUP_ERROR;
 
4673
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4674
              DRIZZLE_YYABORT;
 
4675
          }
 
4676
          SET update_list
 
4677
          {
 
4678
            LEX *lex= Lex;
 
4679
            if (lex->select_lex.get_table_list()->derived)
4236
4680
            {
4237
4681
              /* it is single table update and it is update of derived table */
4238
4682
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4239
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4683
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4240
4684
              DRIZZLE_YYABORT;
4241
4685
            }
4242
4686
            /*
4243
4687
              In case of multi-update setting write lock for all tables may
4244
4688
              be too pessimistic. We will decrease lock level if possible in
4245
 
              multi_update().
 
4689
              mysql_multi_update().
4246
4690
            */
4247
4691
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4248
4692
          }
4255
4699
        ;
4256
4700
 
4257
4701
update_elem:
4258
 
          simple_ident equal expr_or_default
 
4702
          simple_ident_nospvar equal expr_or_default
4259
4703
          {
4260
4704
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4261
4705
              DRIZZLE_YYABORT;
4268
4712
        ;
4269
4713
 
4270
4714
insert_update_elem:
4271
 
          simple_ident equal expr_or_default
 
4715
          simple_ident_nospvar equal expr_or_default
4272
4716
          {
4273
 
          if (Lex->update_list.push_back($1) ||
4274
 
              Lex->value_list.push_back($3))
 
4717
          LEX *lex= Lex;
 
4718
          if (lex->update_list.push_back($1) ||
 
4719
              lex->value_list.push_back($3))
4275
4720
              DRIZZLE_YYABORT;
4276
4721
          }
4277
4722
        ;
4279
4724
/* Delete rows from a table */
4280
4725
 
4281
4726
delete:
4282
 
          DELETE_SYM opt_delete_option FROM table_ident
 
4727
          DELETE_SYM
4283
4728
          {
4284
 
            Lex->statement= new statement::Delete(YYSession);
4285
 
            init_select(Lex);
4286
 
            Lex->lock_option= TL_WRITE_DEFAULT;
4287
 
            Lex->select_lex.init_order();
 
4729
            LEX *lex= Lex;
 
4730
            lex->sql_command= SQLCOM_DELETE;
 
4731
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4732
            if (lex->statement == NULL)
 
4733
              DRIZZLE_YYABORT;
 
4734
            mysql_init_select(lex);
 
4735
            lex->lock_option= TL_WRITE_DEFAULT;
 
4736
            lex->ignore= 0;
 
4737
            lex->select_lex.init_order();
 
4738
          }
 
4739
          opt_delete_options single_multi
 
4740
        ;
4288
4741
 
4289
 
            if (!Lex->current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING,
 
4742
single_multi:
 
4743
          FROM table_ident
 
4744
          {
 
4745
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4290
4746
                                           Lex->lock_option))
4291
4747
              DRIZZLE_YYABORT;
4292
4748
          }
4294
4750
          delete_limit_clause {}
4295
4751
        ;
4296
4752
 
 
4753
opt_delete_options:
 
4754
          /* empty */ {}
 
4755
        | opt_delete_option opt_delete_options {}
 
4756
        ;
 
4757
 
4297
4758
opt_delete_option:
4298
 
           /* empty */ { Lex->ignore= 0; }
4299
 
         | IGNORE_SYM  { Lex->ignore= 1; }
 
4759
         IGNORE_SYM   { Lex->ignore= 1; }
4300
4760
        ;
4301
4761
 
4302
4762
truncate:
4303
4763
          TRUNCATE_SYM opt_table_sym table_name
4304
4764
          {
4305
 
            Lex->statement= new statement::Truncate(YYSession);
4306
 
            Lex->select_lex.options= 0;
4307
 
            Lex->select_lex.init_order();
 
4765
            LEX* lex= Lex;
 
4766
            lex->sql_command= SQLCOM_TRUNCATE;
 
4767
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4768
            if (lex->statement == NULL)
 
4769
              DRIZZLE_YYABORT;
 
4770
            lex->select_lex.options= 0;
 
4771
            lex->select_lex.init_order();
4308
4772
          }
4309
4773
        ;
4310
4774
 
4318
4782
show:
4319
4783
          SHOW
4320
4784
          {
4321
 
            Lex->lock_option= TL_READ;
4322
 
            init_select(Lex);
4323
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4785
            LEX *lex=Lex;
 
4786
            lex->wild=0;
 
4787
            lex->lock_option= TL_READ;
 
4788
            mysql_init_select(lex);
 
4789
            lex->current_select->parsing_place= SELECT_LIST;
4324
4790
          }
4325
4791
          show_param
4326
4792
          {}
4327
4793
        ;
4328
4794
 
4329
 
/* SHOW SCHEMAS */
4330
4795
show_param:
4331
4796
           DATABASES show_wild
4332
4797
           {
4333
 
             if (not show::buildScemas(YYSession))
4334
 
               DRIZZLE_YYABORT;
 
4798
             LEX *lex= Lex;
 
4799
             Session *session= YYSession;
 
4800
 
 
4801
             lex->sql_command= SQLCOM_SELECT;
 
4802
             lex->statement=
 
4803
               new(std::nothrow) statement::Select(session);
 
4804
             if (lex->statement == NULL)
 
4805
               DRIZZLE_YYABORT;
 
4806
 
 
4807
             std::string column_name= "Database";
 
4808
             if (Lex->wild)
 
4809
             {
 
4810
               column_name.append(" (");
 
4811
               column_name.append(Lex->wild->ptr());
 
4812
               column_name.append(")");
 
4813
             }
 
4814
 
 
4815
             if (Lex->current_select->where)
 
4816
             {
 
4817
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
4818
                 DRIZZLE_YYABORT;
 
4819
             }
 
4820
             else
 
4821
             {
 
4822
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
4823
                 DRIZZLE_YYABORT;
 
4824
             }
 
4825
 
 
4826
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4827
             my_field->is_autogenerated_name= false;
 
4828
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4829
 
 
4830
             if (session->add_item_to_list(my_field))
 
4831
               DRIZZLE_YYABORT;
 
4832
 
 
4833
              if (session->add_order_to_list(my_field, true))
 
4834
                DRIZZLE_YYABORT;
4335
4835
           }
4336
 
           /* SHOW TABLES */
4337
4836
         | TABLES opt_db show_wild
4338
4837
           {
4339
 
             if (not show::buildTables(YYSession, $2))
4340
 
               DRIZZLE_YYABORT;
 
4838
             LEX *lex= Lex;
 
4839
             Session *session= YYSession;
 
4840
 
 
4841
             lex->sql_command= SQLCOM_SELECT;
 
4842
 
 
4843
             statement::Select *select=
 
4844
               new(std::nothrow) statement::Select(YYSession);
 
4845
 
 
4846
             lex->statement= select;
 
4847
 
 
4848
             if (lex->statement == NULL)
 
4849
               DRIZZLE_YYABORT;
 
4850
 
 
4851
 
 
4852
              std::string column_name= "Tables_in_";
 
4853
 
 
4854
              if ($2)
 
4855
              {
 
4856
                SchemaIdentifier identifier($2);
 
4857
                column_name.append($2);
 
4858
                lex->select_lex.db= $2;
 
4859
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4860
                {
 
4861
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
4862
                }
 
4863
                select->setShowPredicate($2, "");
 
4864
              }
 
4865
              else if (not session->db.empty())
 
4866
              {
 
4867
                column_name.append(session->db);
 
4868
                select->setShowPredicate(session->db, "");
 
4869
              }
 
4870
              else
 
4871
              {
 
4872
                 my_error(ER_NO_DB_ERROR, MYF(0));
 
4873
              }
 
4874
 
 
4875
 
 
4876
             if (Lex->wild)
 
4877
             {
 
4878
               column_name.append(" (");
 
4879
               column_name.append(Lex->wild->ptr());
 
4880
               column_name.append(")");
 
4881
             }
 
4882
 
 
4883
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
4884
               DRIZZLE_YYABORT;
 
4885
 
 
4886
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4887
             my_field->is_autogenerated_name= false;
 
4888
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4889
 
 
4890
             if (session->add_item_to_list(my_field))
 
4891
               DRIZZLE_YYABORT;
 
4892
 
 
4893
              if (session->add_order_to_list(my_field, true))
 
4894
                DRIZZLE_YYABORT;
4341
4895
           }
4342
 
           /* SHOW TEMPORARY TABLES */
4343
4896
         | TEMPORARY_SYM TABLES show_wild
4344
4897
           {
4345
 
             if (not show::buildTemporaryTables(YYSession))
4346
 
               DRIZZLE_YYABORT;
 
4898
             LEX *lex= Lex;
 
4899
             Session *session= YYSession;
 
4900
 
 
4901
             lex->sql_command= SQLCOM_SELECT;
 
4902
 
 
4903
             statement::Select *select=
 
4904
               new(std::nothrow) statement::Select(YYSession);
 
4905
 
 
4906
             lex->statement= select;
 
4907
 
 
4908
             if (lex->statement == NULL)
 
4909
               DRIZZLE_YYABORT;
 
4910
 
 
4911
 
 
4912
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
 
4913
               DRIZZLE_YYABORT;
 
4914
 
 
4915
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4916
                                                           context,
 
4917
                                                           NULL, NULL, "*")))
 
4918
               DRIZZLE_YYABORT;
 
4919
             (session->lex->current_select->with_wild)++;
 
4920
 
4347
4921
           }
4348
 
           /* SHOW TABLE STATUS */
4349
4922
         | TABLE_SYM STATUS_SYM opt_db show_wild
4350
4923
           {
4351
 
             if (not show::buildTableStatus(YYSession, $3))
4352
 
               DRIZZLE_YYABORT;
 
4924
             LEX *lex= Lex;
 
4925
             lex->sql_command= SQLCOM_SELECT;
 
4926
             statement::Select *select=
 
4927
               new(std::nothrow) statement::Select(YYSession);
 
4928
 
 
4929
             lex->statement= select;
 
4930
 
 
4931
             if (lex->statement == NULL)
 
4932
               DRIZZLE_YYABORT;
 
4933
 
 
4934
             Session *session= YYSession;
 
4935
 
 
4936
             std::string column_name= "Tables_in_";
 
4937
 
 
4938
             if ($3)
 
4939
             {
 
4940
               lex->select_lex.db= $3;
 
4941
 
 
4942
               SchemaIdentifier identifier($3);
 
4943
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4944
               {
 
4945
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
4946
               }
 
4947
 
 
4948
               select->setShowPredicate($3, "");
 
4949
             }
 
4950
             else
 
4951
             {
 
4952
               select->setShowPredicate(session->db, "");
 
4953
             }
 
4954
 
 
4955
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
4956
               DRIZZLE_YYABORT;
 
4957
 
 
4958
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4959
                                                           context,
 
4960
                                                           NULL, NULL, "*")))
 
4961
               DRIZZLE_YYABORT;
 
4962
             (session->lex->current_select->with_wild)++;
4353
4963
           }
4354
 
           /* SHOW COLUMNS FROM table_name */
4355
4964
        | COLUMNS from_or_in table_ident opt_db show_wild
4356
 
           {
4357
 
             if (not show::buildColumns(YYSession, $4, $3))
4358
 
               DRIZZLE_YYABORT;
4359
 
           }
4360
 
          /* SHOW INDEXES from table */
 
4965
          {
 
4966
             LEX *lex= Lex;
 
4967
             Session *session= YYSession;
 
4968
             statement::Select *select;
 
4969
 
 
4970
             lex->sql_command= SQLCOM_SELECT;
 
4971
 
 
4972
             select= new(std::nothrow) statement::Select(session);
 
4973
 
 
4974
             lex->statement= select;
 
4975
 
 
4976
             if (lex->statement == NULL)
 
4977
               DRIZZLE_YYABORT;
 
4978
 
 
4979
             if ($4)
 
4980
              select->setShowPredicate($4, $3->table.str);
 
4981
             else if ($3->db.str)
 
4982
              select->setShowPredicate($3->db.str, $3->table.str);
 
4983
             else
 
4984
              select->setShowPredicate(session->db, $3->table.str);
 
4985
 
 
4986
             {
 
4987
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4988
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4989
               {
 
4990
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
4991
                            select->getShowSchema().c_str(), 
 
4992
                            $3->table.str);
 
4993
               }
 
4994
             }
 
4995
 
 
4996
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
4997
               DRIZZLE_YYABORT;
 
4998
 
 
4999
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5000
                                                           context,
 
5001
                                                           NULL, NULL, "*")))
 
5002
               DRIZZLE_YYABORT;
 
5003
             (session->lex->current_select->with_wild)++;
 
5004
 
 
5005
          }
4361
5006
        | keys_or_index from_or_in table_ident opt_db where_clause
4362
 
           {
4363
 
             if (not show::buildIndex(YYSession, $4, $3))
4364
 
               DRIZZLE_YYABORT;
4365
 
           }
 
5007
          {
 
5008
             LEX *lex= Lex;
 
5009
             Session *session= YYSession;
 
5010
             statement::Select *select;
 
5011
 
 
5012
             lex->sql_command= SQLCOM_SELECT;
 
5013
 
 
5014
             select= new(std::nothrow) statement::Select(session);
 
5015
 
 
5016
             lex->statement= select;
 
5017
 
 
5018
             if (lex->statement == NULL)
 
5019
               DRIZZLE_YYABORT;
 
5020
 
 
5021
             if ($4)
 
5022
              select->setShowPredicate($4, $3->table.str);
 
5023
             else if ($3->db.str)
 
5024
              select->setShowPredicate($3->db.str, $3->table.str);
 
5025
             else
 
5026
              select->setShowPredicate(session->db, $3->table.str);
 
5027
 
 
5028
             {
 
5029
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
5030
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5031
               {
 
5032
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5033
                            select->getShowSchema().c_str(), 
 
5034
                            $3->table.str);
 
5035
               }
 
5036
             }
 
5037
 
 
5038
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
5039
               DRIZZLE_YYABORT;
 
5040
 
 
5041
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5042
                                                           context,
 
5043
                                                           NULL, NULL, "*")))
 
5044
               DRIZZLE_YYABORT;
 
5045
             (session->lex->current_select->with_wild)++;
 
5046
          }
4366
5047
        | COUNT_SYM '(' '*' ')' WARNINGS
4367
5048
          {
4368
 
            show::buildSelectWarning(YYSession);
 
5049
            (void) create_select_for_variable("warning_count");
 
5050
            LEX *lex= Lex;
 
5051
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5052
            if (lex->statement == NULL)
 
5053
              DRIZZLE_YYABORT;
4369
5054
          }
4370
5055
        | COUNT_SYM '(' '*' ')' ERRORS
4371
5056
          {
4372
 
            show::buildSelectError(YYSession);
 
5057
            (void) create_select_for_variable("error_count");
 
5058
            LEX *lex= Lex;
 
5059
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5060
            if (lex->statement == NULL)
 
5061
              DRIZZLE_YYABORT;
4373
5062
          }
4374
5063
        | WARNINGS opt_limit_clause_init
4375
5064
          {
4376
 
            show::buildWarnings(YYSession);
 
5065
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5066
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
5067
            if (Lex->statement == NULL)
 
5068
              DRIZZLE_YYABORT;
4377
5069
          }
4378
5070
        | ERRORS opt_limit_clause_init
4379
5071
          {
4380
 
            show::buildErrors(YYSession);
 
5072
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5073
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
5074
            if (Lex->statement == NULL)
 
5075
              DRIZZLE_YYABORT;
4381
5076
          }
4382
5077
        | opt_var_type STATUS_SYM show_wild
4383
 
          {
4384
 
            if (not show::buildStatus(YYSession, $1))
4385
 
              DRIZZLE_YYABORT;
4386
 
          }
4387
 
        | engine_option_value STATUS_SYM
4388
 
          {
4389
 
            if (not show::buildEngineStatus(YYSession, $1))
4390
 
              DRIZZLE_YYABORT;
4391
 
          }
 
5078
           {
 
5079
             LEX *lex= Lex;
 
5080
             lex->sql_command= SQLCOM_SELECT;
 
5081
             lex->statement=
 
5082
               new(std::nothrow) statement::Select(YYSession);
 
5083
             if (lex->statement == NULL)
 
5084
               DRIZZLE_YYABORT;
 
5085
 
 
5086
             Session *session= YYSession;
 
5087
 
 
5088
             if ($1 == OPT_GLOBAL)
 
5089
             {
 
5090
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5091
                 DRIZZLE_YYABORT;
 
5092
             }
 
5093
             else
 
5094
             {
 
5095
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5096
                 DRIZZLE_YYABORT;
 
5097
             }
 
5098
 
 
5099
             std::string key("Variable_name");
 
5100
             std::string value("Value");
 
5101
 
 
5102
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5103
             my_field->is_autogenerated_name= false;
 
5104
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5105
 
 
5106
             if (session->add_item_to_list(my_field))
 
5107
               DRIZZLE_YYABORT;
 
5108
 
 
5109
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5110
             my_field->is_autogenerated_name= false;
 
5111
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5112
 
 
5113
             if (session->add_item_to_list(my_field))
 
5114
               DRIZZLE_YYABORT;
 
5115
           }
4392
5116
        | CREATE TABLE_SYM table_ident
4393
 
          {
4394
 
            if (not show::buildCreateTable(YYSession, $3))
4395
 
              DRIZZLE_YYABORT;
4396
 
          }
 
5117
           {
 
5118
             LEX *lex= Lex;
 
5119
             lex->sql_command= SQLCOM_SELECT;
 
5120
             statement::Select *select=
 
5121
               new(std::nothrow) statement::Select(YYSession);
 
5122
 
 
5123
             lex->statement= select;
 
5124
 
 
5125
             if (lex->statement == NULL)
 
5126
               DRIZZLE_YYABORT;
 
5127
 
 
5128
             Session *session= YYSession;
 
5129
 
 
5130
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
 
5131
               DRIZZLE_YYABORT;
 
5132
 
 
5133
             if ($3->db.str)
 
5134
              select->setShowPredicate($3->db.str, $3->table.str);
 
5135
             else
 
5136
              select->setShowPredicate(session->db, $3->table.str);
 
5137
 
 
5138
             std::string key("Table");
 
5139
             std::string value("Create Table");
 
5140
 
 
5141
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5142
             my_field->is_autogenerated_name= false;
 
5143
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5144
 
 
5145
             if (session->add_item_to_list(my_field))
 
5146
               DRIZZLE_YYABORT;
 
5147
 
 
5148
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5149
             my_field->is_autogenerated_name= false;
 
5150
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5151
 
 
5152
             if (session->add_item_to_list(my_field))
 
5153
               DRIZZLE_YYABORT;
 
5154
           }
4397
5155
        | PROCESSLIST_SYM
4398
5156
          {
4399
 
            if (not show::buildProcesslist(YYSession))
4400
 
              DRIZZLE_YYABORT;
 
5157
           {
 
5158
             LEX *lex= Lex;
 
5159
             lex->sql_command= SQLCOM_SELECT;
 
5160
             lex->statement=
 
5161
               new(std::nothrow) statement::Select(YYSession);
 
5162
             if (lex->statement == NULL)
 
5163
               DRIZZLE_YYABORT;
 
5164
 
 
5165
             Session *session= YYSession;
 
5166
 
 
5167
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
5168
               DRIZZLE_YYABORT;
 
5169
 
 
5170
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5171
                                                           context,
 
5172
                                                           NULL, NULL, "*")))
 
5173
               DRIZZLE_YYABORT;
 
5174
             (session->lex->current_select->with_wild)++;
 
5175
           }
4401
5176
          }
4402
5177
        | opt_var_type  VARIABLES show_wild
4403
 
          {
4404
 
            if (not show::buildVariables(YYSession, $1))
4405
 
              DRIZZLE_YYABORT;
4406
 
          }
 
5178
           {
 
5179
             LEX *lex= Lex;
 
5180
             lex->sql_command= SQLCOM_SELECT;
 
5181
             lex->statement=
 
5182
               new(std::nothrow) statement::Select(YYSession);
 
5183
             if (lex->statement == NULL)
 
5184
               DRIZZLE_YYABORT;
 
5185
 
 
5186
             Session *session= YYSession;
 
5187
 
 
5188
             if ($1 == OPT_GLOBAL)
 
5189
             {
 
5190
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5191
                 DRIZZLE_YYABORT;
 
5192
             }
 
5193
             else
 
5194
             {
 
5195
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5196
                 DRIZZLE_YYABORT;
 
5197
             }
 
5198
 
 
5199
             std::string key("Variable_name");
 
5200
             std::string value("Value");
 
5201
 
 
5202
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5203
             my_field->is_autogenerated_name= false;
 
5204
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5205
 
 
5206
             if (session->add_item_to_list(my_field))
 
5207
               DRIZZLE_YYABORT;
 
5208
 
 
5209
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5210
             my_field->is_autogenerated_name= false;
 
5211
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5212
 
 
5213
             if (session->add_item_to_list(my_field))
 
5214
               DRIZZLE_YYABORT;
 
5215
           }
4407
5216
        | CREATE DATABASE opt_if_not_exists ident
4408
 
          {
4409
 
            if (not show::buildCreateSchema(YYSession, $4))
4410
 
              DRIZZLE_YYABORT;
4411
 
          }
 
5217
           {
 
5218
             LEX *lex= Lex;
 
5219
             lex->sql_command= SQLCOM_SELECT;
 
5220
             statement::Select *select=
 
5221
               new(std::nothrow) statement::Select(YYSession);
 
5222
 
 
5223
             lex->statement= select;
 
5224
 
 
5225
             if (lex->statement == NULL)
 
5226
               DRIZZLE_YYABORT;
 
5227
 
 
5228
             Session *session= YYSession;
 
5229
 
 
5230
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
 
5231
               DRIZZLE_YYABORT;
 
5232
 
 
5233
             if ($4.str)
 
5234
              select->setShowPredicate($4.str);
 
5235
             else
 
5236
              select->setShowPredicate(session->db);
 
5237
 
 
5238
             std::string key("Database");
 
5239
             std::string value("Create Database");
 
5240
 
 
5241
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5242
             my_field->is_autogenerated_name= false;
 
5243
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5244
 
 
5245
             if (session->add_item_to_list(my_field))
 
5246
               DRIZZLE_YYABORT;
 
5247
 
 
5248
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5249
             my_field->is_autogenerated_name= false;
 
5250
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5251
 
 
5252
             if (session->add_item_to_list(my_field))
 
5253
               DRIZZLE_YYABORT;
 
5254
           }
4412
5255
 
4413
5256
opt_db:
4414
5257
          /* empty */  { $$= 0; }
4441
5284
describe:
4442
5285
          describe_command table_ident
4443
5286
          {
4444
 
            if (not show::buildDescribe(YYSession, $2))
4445
 
            {
 
5287
            Session *session= YYSession;
 
5288
            statement::Select *select;
 
5289
            LEX *lex= Lex;
 
5290
            lex->lock_option= TL_READ;
 
5291
            mysql_init_select(lex);
 
5292
            lex->current_select->parsing_place= SELECT_LIST;
 
5293
            lex->sql_command= SQLCOM_SELECT;
 
5294
            select= new(std::nothrow) statement::Select(session);
 
5295
            lex->statement= select;
 
5296
            if (lex->statement == NULL)
4446
5297
              DRIZZLE_YYABORT;
4447
 
            }
 
5298
            lex->select_lex.db= 0;
 
5299
 
 
5300
             if ($2->db.str)
 
5301
              select->setShowPredicate($2->db.str, $2->table.str);
 
5302
             else
 
5303
              select->setShowPredicate(session->db, $2->table.str);
 
5304
 
 
5305
             {
 
5306
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5307
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5308
               {
 
5309
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5310
                            select->getShowSchema().c_str(), 
 
5311
                            $2->table.str);
 
5312
               }
 
5313
             }
 
5314
 
 
5315
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5316
               DRIZZLE_YYABORT;
 
5317
 
 
5318
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5319
                                                           context,
 
5320
                                                           NULL, NULL, "*")))
 
5321
               DRIZZLE_YYABORT;
 
5322
             (session->lex->current_select->with_wild)++;
 
5323
 
4448
5324
          }
4449
5325
          opt_describe_column {}
4450
5326
        | describe_command opt_extended_describe
4451
5327
          { Lex->describe|= DESCRIBE_NORMAL; }
4452
5328
          select
4453
5329
          {
4454
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5330
            LEX *lex=Lex;
 
5331
            lex->select_lex.options|= SELECT_DESCRIBE;
4455
5332
          }
4456
5333
        ;
4457
5334
 
4482
5359
flush:
4483
5360
          FLUSH_SYM
4484
5361
          {
4485
 
            Lex->statement= new statement::Flush(YYSession);
 
5362
            LEX *lex=Lex;
 
5363
            lex->sql_command= SQLCOM_FLUSH;
 
5364
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5365
            if (lex->statement == NULL)
 
5366
              DRIZZLE_YYABORT;
 
5367
            lex->type= 0;
4486
5368
          }
4487
5369
          flush_options
4488
5370
          {}
4515
5397
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4516
5398
            statement->setFlushStatus(true);
4517
5399
          }
4518
 
        | GLOBAL_SYM STATUS_SYM
4519
 
          {
4520
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4521
 
            statement->setFlushGlobalStatus(true);
4522
 
          }
4523
5400
        ;
4524
5401
 
4525
5402
opt_table_list:
4532
5409
kill:
4533
5410
          KILL_SYM kill_option expr
4534
5411
          {
4535
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5412
            LEX *lex=Lex;
 
5413
            lex->value_list.empty();
 
5414
            lex->value_list.push_front($3);
 
5415
            lex->sql_command= SQLCOM_KILL;
 
5416
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5417
            if (lex->statement == NULL)
 
5418
              DRIZZLE_YYABORT;
4536
5419
          }
4537
5420
        ;
4538
5421
 
4539
5422
kill_option:
4540
 
          /* empty */ { $$= false; }
4541
 
        | CONNECTION_SYM { $$= false; }
4542
 
        | QUERY_SYM      { $$= true; }
 
5423
          /* empty */ { Lex->type= 0; }
 
5424
        | CONNECTION_SYM { Lex->type= 0; }
 
5425
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
4543
5426
        ;
4544
5427
 
4545
5428
/* change database */
4546
5429
 
4547
5430
use:
4548
 
          USE_SYM schema_name
 
5431
          USE_SYM ident
4549
5432
          {
4550
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4551
 
            Lex->select_lex.db= $2.str;
 
5433
            LEX *lex=Lex;
 
5434
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5435
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5436
            if (lex->statement == NULL)
 
5437
              DRIZZLE_YYABORT;
 
5438
            lex->select_lex.db= $2.str;
4552
5439
          }
4553
5440
        ;
4554
5441
 
4557
5444
load:
4558
5445
          LOAD data_file
4559
5446
          {
4560
 
            statement::Load *statement= new statement::Load(YYSession);
4561
 
            Lex->statement= statement;
4562
 
 
4563
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5447
            Session *session= YYSession;
 
5448
            LEX *lex= session->lex;
 
5449
 
 
5450
            lex->sql_command= SQLCOM_LOAD;
 
5451
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5452
            lex->statement= statement;
 
5453
            if (lex->statement == NULL)
 
5454
              DRIZZLE_YYABORT;
 
5455
 
 
5456
            Lex_input_stream *lip= session->m_lip;
4564
5457
            statement->fname_start= lip->get_ptr();
4565
5458
          }
4566
5459
          load_data_lock INFILE TEXT_STRING_filesystem
4567
5460
          {
4568
 
            Lex->lock_option= $4;
4569
 
            Lex->duplicates= DUP_ERROR;
4570
 
            Lex->ignore= 0;
4571
 
            if (not (Lex->exchange= new file_exchange($6.str, 0, $2)))
 
5461
            LEX *lex=Lex;
 
5462
            lex->lock_option= $4;
 
5463
            lex->duplicates= DUP_ERROR;
 
5464
            lex->ignore= 0;
 
5465
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4572
5466
              DRIZZLE_YYABORT;
4573
5467
          }
4574
5468
          opt_duplicate INTO
4575
5469
          {
4576
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5470
            Session *session= YYSession;
 
5471
            Lex_input_stream *lip= session->m_lip;
4577
5472
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4578
5473
          }
4579
5474
          TABLE_SYM table_ident
4580
5475
          {
 
5476
            LEX *lex=Lex;
4581
5477
            if (!Lex->current_select->add_table_to_list(YYSession,
4582
5478
                    $12, NULL, TL_OPTION_UPDATING,
4583
 
                    Lex->lock_option))
 
5479
                    lex->lock_option))
4584
5480
              DRIZZLE_YYABORT;
4585
 
            Lex->field_list.clear();
4586
 
            Lex->update_list.clear();
4587
 
            Lex->value_list.clear();
 
5481
            lex->field_list.empty();
 
5482
            lex->update_list.empty();
 
5483
            lex->value_list.empty();
4588
5484
          }
4589
5485
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4590
5486
          opt_load_data_set_spec
4608
5504
        | IGNORE_SYM { Lex->ignore= 1; }
4609
5505
        ;
4610
5506
 
4611
 
opt_duplicate_as:
4612
 
          /* empty */ { Lex->duplicates=DUP_ERROR; }
4613
 
        | AS { Lex->duplicates=DUP_ERROR; }
4614
 
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
4615
 
        | IGNORE_SYM { Lex->ignore= true; }
4616
 
        | REPLACE AS { Lex->duplicates=DUP_REPLACE; }
4617
 
        | IGNORE_SYM AS { Lex->ignore= true; }
4618
 
        ;
4619
 
 
4620
5507
opt_field_term:
4621
5508
          /* empty */
4622
5509
        | COLUMNS field_term_list
4635
5522
          }
4636
5523
        | OPTIONALLY ENCLOSED BY text_string
4637
5524
          {
4638
 
            assert(Lex->exchange != 0);
4639
 
            Lex->exchange->enclosed= $4;
4640
 
            Lex->exchange->opt_enclosed= 1;
 
5525
            LEX *lex= Lex;
 
5526
            assert(lex->exchange != 0);
 
5527
            lex->exchange->enclosed= $4;
 
5528
            lex->exchange->opt_enclosed= 1;
4641
5529
          }
4642
5530
        | ENCLOSED BY text_string
4643
5531
          {
4702
5590
        ;
4703
5591
 
4704
5592
field_or_var:
4705
 
          simple_ident {$$= $1;}
4706
 
        | '@' user_variable_ident
 
5593
          simple_ident_nospvar {$$= $1;}
 
5594
        | '@' ident_or_text
4707
5595
          { $$= new Item_user_var_as_out_param($2); }
4708
5596
        ;
4709
5597
 
4710
5598
opt_load_data_set_spec:
4711
5599
          /* empty */ {}
4712
 
        | SET_SYM insert_update_list {}
 
5600
        | SET insert_update_list {}
4713
5601
        ;
4714
5602
 
4715
5603
/* Common definitions */
4717
5605
text_literal:
4718
5606
        TEXT_STRING_literal
4719
5607
        {
4720
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5608
          Session *session= YYSession;
 
5609
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4721
5610
        }
4722
5611
        | text_literal TEXT_STRING_literal
4723
5612
          {
4773
5662
            $$ = new Item_null();
4774
5663
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4775
5664
          }
4776
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4777
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5665
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5666
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4778
5667
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4779
5668
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4780
5669
        | DATE_SYM text_literal { $$ = $2; }
4817
5706
**********************************************************************/
4818
5707
 
4819
5708
insert_ident:
4820
 
          simple_ident { $$=$1; }
 
5709
          simple_ident_nospvar { $$=$1; }
4821
5710
        | table_wild { $$=$1; }
4822
5711
        ;
4823
5712
 
4824
5713
table_wild:
4825
5714
          ident '.' '*'
4826
5715
          {
4827
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5716
            Select_Lex *sel= Lex->current_select;
 
5717
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5718
            sel->with_wild++;
4828
5719
          }
4829
5720
        | ident '.' ident '.' '*'
4830
5721
          {
4831
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5722
            Select_Lex *sel= Lex->current_select;
 
5723
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
5724
            sel->with_wild++;
4832
5725
          }
4833
5726
        ;
4834
5727
 
4839
5732
simple_ident:
4840
5733
          ident
4841
5734
          {
4842
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5735
            {
 
5736
              Select_Lex *sel=Lex->current_select;
 
5737
              $$= (sel->parsing_place != IN_HAVING ||
 
5738
                  sel->get_in_sum_expr() > 0) ?
 
5739
                  (Item*) new Item_field(Lex->current_context(),
 
5740
                                         (const char *)NULL, NULL, $1.str) :
 
5741
                  (Item*) new Item_ref(Lex->current_context(),
 
5742
                                       (const char *)NULL, NULL, $1.str);
 
5743
            }
 
5744
          }
 
5745
        | simple_ident_q { $$= $1; }
 
5746
        ;
 
5747
 
 
5748
simple_ident_nospvar:
 
5749
          ident
 
5750
          {
 
5751
            Select_Lex *sel=Lex->current_select;
 
5752
            $$= (sel->parsing_place != IN_HAVING ||
 
5753
                sel->get_in_sum_expr() > 0) ?
 
5754
                (Item*) new Item_field(Lex->current_context(),
 
5755
                                       (const char *)NULL, NULL, $1.str) :
 
5756
                (Item*) new Item_ref(Lex->current_context(),
 
5757
                                     (const char *)NULL, NULL, $1.str);
4843
5758
          }
4844
5759
        | simple_ident_q { $$= $1; }
4845
5760
        ;
4847
5762
simple_ident_q:
4848
5763
          ident '.' ident
4849
5764
          {
4850
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5765
            Session *session= YYSession;
 
5766
            LEX *lex= session->lex;
 
5767
 
 
5768
            {
 
5769
              Select_Lex *sel= lex->current_select;
 
5770
              if (sel->no_table_names_allowed)
 
5771
              {
 
5772
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5773
                         MYF(0), $1.str, session->where);
 
5774
              }
 
5775
              $$= (sel->parsing_place != IN_HAVING ||
 
5776
                  sel->get_in_sum_expr() > 0) ?
 
5777
                  (Item*) new Item_field(Lex->current_context(),
 
5778
                                         (const char *)NULL, $1.str, $3.str) :
 
5779
                  (Item*) new Item_ref(Lex->current_context(),
 
5780
                                       (const char *)NULL, $1.str, $3.str);
 
5781
            }
4851
5782
          }
4852
5783
        | '.' ident '.' ident
4853
5784
          {
4854
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5785
            Session *session= YYSession;
 
5786
            LEX *lex= session->lex;
 
5787
            Select_Lex *sel= lex->current_select;
 
5788
            if (sel->no_table_names_allowed)
 
5789
            {
 
5790
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5791
                       MYF(0), $2.str, session->where);
 
5792
            }
 
5793
            $$= (sel->parsing_place != IN_HAVING ||
 
5794
                sel->get_in_sum_expr() > 0) ?
 
5795
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5796
                (Item*) new Item_ref(Lex->current_context(),
 
5797
                                     (const char *)NULL, $2.str, $4.str);
4855
5798
          }
4856
5799
        | ident '.' ident '.' ident
4857
5800
          {
4858
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5801
            Session *session= YYSession;
 
5802
            LEX *lex= session->lex;
 
5803
            Select_Lex *sel= lex->current_select;
 
5804
            if (sel->no_table_names_allowed)
 
5805
            {
 
5806
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5807
                       MYF(0), $3.str, session->where);
 
5808
            }
 
5809
            $$= (sel->parsing_place != IN_HAVING ||
 
5810
                sel->get_in_sum_expr() > 0) ?
 
5811
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5812
                                       $5.str) :
 
5813
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5814
                                     $5.str);
4859
5815
          }
4860
5816
        ;
4861
5817
 
4862
5818
field_ident:
4863
 
          ident 
4864
 
          {
4865
 
            $$=$1;
4866
 
          }
 
5819
          ident { $$=$1;}
4867
5820
        | ident '.' ident '.' ident
4868
5821
          {
4869
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4870
 
              DRIZZLE_YYABORT;
4871
 
 
 
5822
            TableList *table=
 
5823
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5824
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5825
            {
 
5826
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5827
              DRIZZLE_YYABORT;
 
5828
            }
 
5829
            if (my_strcasecmp(table_alias_charset, $3.str,
 
5830
                              table->table_name))
 
5831
            {
 
5832
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
5833
              DRIZZLE_YYABORT;
 
5834
            }
4872
5835
            $$=$5;
4873
5836
          }
4874
5837
        | ident '.' ident
4875
5838
          {
4876
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5839
            TableList *table=
 
5840
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5841
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
5842
            {
 
5843
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4877
5844
              DRIZZLE_YYABORT;
4878
 
 
 
5845
            }
4879
5846
            $$=$3;
4880
5847
          }
4881
 
        | '.' ident 
4882
 
          { /* For Delphi */
4883
 
            $$=$2;
4884
 
          }
 
5848
        | '.' ident { $$=$2;} /* For Delphi */
4885
5849
        ;
4886
5850
 
4887
5851
table_ident:
4888
 
          ident
4889
 
          {
4890
 
            $$= new Table_ident($1);
4891
 
          }
4892
 
        | schema_name '.' ident
4893
 
          {
4894
 
            $$=new Table_ident($1,$3);
4895
 
          }
4896
 
        | '.' ident
4897
 
        { /* For Delphi */
4898
 
          $$= new Table_ident($2);
4899
 
        }
4900
 
        ;
4901
 
 
4902
 
schema_name:
4903
 
          ident
4904
 
        ;
4905
 
 
4906
 
catalog_name:
4907
 
          ident
 
5852
          ident { $$=new Table_ident($1); }
 
5853
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
5854
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4908
5855
        ;
4909
5856
 
4910
5857
IDENT_sys:
4911
 
          IDENT 
4912
 
          {
4913
 
            $$= $1;
4914
 
          }
 
5858
          IDENT { $$= $1; }
4915
5859
        | IDENT_QUOTED
4916
5860
          {
4917
5861
            const CHARSET_INFO * const cs= system_charset_info;
4954
5898
          IDENT_sys    { $$=$1; }
4955
5899
        | keyword
4956
5900
          {
4957
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
5901
            Session *session= YYSession;
 
5902
            $$.str= session->strmake($1.str, $1.length);
4958
5903
            $$.length= $1.length;
4959
5904
          }
4960
5905
        ;
4961
5906
 
4962
5907
ident_or_text:
4963
 
          IDENT_sys           { $$=$1;}
4964
 
        | TEXT_STRING_sys { $$=$1;}
4965
 
        ;
4966
 
 
4967
 
engine_option_value:
4968
 
          IDENT_sys           { $$=$1;}
4969
 
        | TEXT_STRING_sys { $$=$1;}
4970
 
        ;
4971
 
 
4972
 
keyword_exception_for_variable:
4973
 
          TIMESTAMP_SYM         {}
4974
 
        | SQL_BUFFER_RESULT     {}
4975
 
        | IDENTITY_SYM          {}
 
5908
          ident           { $$=$1;}
 
5909
        | TEXT_STRING_sys { $$=$1;}
 
5910
        | LEX_HOSTNAME { $$=$1;}
4976
5911
        ;
4977
5912
 
4978
5913
/* Keyword that we allow for identifiers (except SP labels) */
4979
5914
keyword:
4980
5915
          keyword_sp            {}
4981
5916
        | BEGIN_SYM             {}
 
5917
        | BYTE_SYM              {}
4982
5918
        | CHECKSUM_SYM          {}
4983
5919
        | CLOSE_SYM             {}
4984
5920
        | COMMENT_SYM           {}
4985
5921
        | COMMIT_SYM            {}
4986
5922
        | CONTAINS_SYM          {}
4987
5923
        | DEALLOCATE_SYM        {}
4988
 
        | DO_SYM                {}
4989
5924
        | END                   {}
4990
5925
        | FLUSH_SYM             {}
4991
5926
        | NO_SYM                {}
4994
5929
        | SAVEPOINT_SYM         {}
4995
5930
        | SECURITY_SYM          {}
4996
5931
        | SERVER_SYM            {}
4997
 
        | SIGNED_SYM            {}
4998
5932
        | START_SYM             {}
4999
5933
        | STOP_SYM              {}
5000
5934
        | TRUNCATE_SYM          {}
5014
5948
        | ANY_SYM                  {}
5015
5949
        | AT_SYM                   {}
5016
5950
        | AUTO_INC                 {}
 
5951
        | AVG_ROW_LENGTH           {}
5017
5952
        | AVG_SYM                  {}
5018
5953
        | BIT_SYM                  {}
5019
5954
        | BOOL_SYM                 {}
5023
5958
        | CHAIN_SYM                {}
5024
5959
        | COALESCE                 {}
5025
5960
        | COLLATION_SYM            {}
 
5961
        | COLUMN_FORMAT_SYM        {}
5026
5962
        | COLUMNS                  {}
5027
5963
        | COMMITTED_SYM            {}
5028
5964
        | COMPACT_SYM              {}
5029
5965
        | COMPRESSED_SYM           {}
5030
5966
        | CONCURRENT               {}
5031
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
5967
        | CONNECTION_SYM           {}
5032
5968
        | CONSISTENT_SYM           {}
5033
5969
        | CUBE_SYM                 {}
5034
5970
        | DATA_SYM                 {}
5035
5971
        | DATABASES                {}
 
5972
        | DATAFILE_SYM             {}
5036
5973
        | DATETIME_SYM             {}
5037
 
        | DATE_SYM                 {} /* Create conflict */
 
5974
        | DATE_SYM                 {}
5038
5975
        | DAY_SYM                  {}
5039
5976
        | DISABLE_SYM              {}
5040
5977
        | DISCARD                  {}
5065
6002
        | KEY_BLOCK_SIZE           {}
5066
6003
        | LAST_SYM                 {}
5067
6004
        | LEVEL_SYM                {}
 
6005
        | LIST_SYM                 {}
5068
6006
        | LOCAL_SYM                {}
5069
6007
        | LOCKS_SYM                {}
5070
6008
        | LOGS_SYM                 {}
 
6009
        | MAX_ROWS                 {}
 
6010
        | MAX_SIZE_SYM             {}
5071
6011
        | MAX_VALUE_SYM            {}
5072
6012
        | MEDIUM_SYM               {}
5073
6013
        | MERGE_SYM                {}
5074
6014
        | MICROSECOND_SYM          {}
5075
6015
        | MINUTE_SYM               {}
 
6016
        | MIN_ROWS                 {}
5076
6017
        | MODIFY_SYM               {}
5077
6018
        | MODE_SYM                 {}
5078
6019
        | MONTH_SYM                {}
5087
6028
        | ONE_SHOT_SYM             {}
5088
6029
        | ONE_SYM                  {}
5089
6030
        | ONLINE_SYM               {}
 
6031
        | PAGE_SYM                 {}
5090
6032
        | PARTIAL                  {}
 
6033
        | PHASE_SYM                {}
5091
6034
        | PREV_SYM                 {}
5092
6035
        | PROCESS                  {}
5093
6036
        | PROCESSLIST_SYM          {}
5094
6037
        | QUARTER_SYM              {}
5095
 
        | QUERY_SYM                {} // Causes conflict
 
6038
        | QUERY_SYM                {}
 
6039
        | READ_ONLY_SYM            {}
5096
6040
        | REDUNDANT_SYM            {}
5097
6041
        | REPEATABLE_SYM           {}
5098
6042
        | RETURNS_SYM              {}
 
6043
        | REVERSE_SYM              {}
5099
6044
        | ROLLUP_SYM               {}
5100
6045
        | ROUTINE_SYM              {}
5101
6046
        | ROWS_SYM                 {}
5108
6053
        | SIMPLE_SYM               {}
5109
6054
        | SHARE_SYM                {}
5110
6055
        | SNAPSHOT_SYM             {}
 
6056
        | SQL_BUFFER_RESULT        {}
5111
6057
        | STATUS_SYM               {}
 
6058
        | STORAGE_SYM              {}
5112
6059
        | STRING_SYM               {}
5113
6060
        | SUBDATE_SYM              {}
5114
6061
        | SUBJECT_SYM              {}
5115
6062
        | SUSPEND_SYM              {}
 
6063
        | SWAPS_SYM                {}
 
6064
        | SWITCHES_SYM             {}
5116
6065
        | TABLES                   {}
5117
6066
        | TABLESPACE               {}
5118
6067
        | TEMPORARY_SYM            {}
5119
6068
        | TEXT_SYM                 {}
5120
6069
        | TRANSACTION_SYM          {}
5121
 
        | TIME_SYM                 {}
 
6070
        | TIMESTAMP_SYM            {}
5122
6071
        | TIMESTAMP_ADD            {}
5123
6072
        | TIMESTAMP_DIFF           {}
 
6073
        | TYPES_SYM                {}
5124
6074
        | TYPE_SYM                 {}
5125
6075
        | UNCOMMITTED_SYM          {}
5126
6076
        | UNDOFILE_SYM             {}
5127
6077
        | UNKNOWN_SYM              {}
5128
 
        | UUID_SYM                 {}
5129
6078
        | USER                     {}
5130
6079
        | VARIABLES                {}
5131
6080
        | VALUE_SYM                {}
5138
6087
/* Option functions */
5139
6088
 
5140
6089
set:
5141
 
          SET_SYM opt_option
 
6090
          SET opt_option
5142
6091
          {
5143
 
            Lex->statement= new statement::SetOption(YYSession);
 
6092
            LEX *lex=Lex;
 
6093
            lex->sql_command= SQLCOM_SET_OPTION;
 
6094
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
6095
            lex->statement= statement;
 
6096
            if (lex->statement == NULL)
 
6097
              DRIZZLE_YYABORT;
 
6098
            mysql_init_select(lex);
 
6099
            lex->option_type=OPT_SESSION;
 
6100
            lex->var_list.empty();
5144
6101
          }
5145
6102
          option_value_list
5146
6103
          {}
5157
6114
        ;
5158
6115
 
5159
6116
option_type_value:
5160
 
          { }
 
6117
          {
 
6118
          }
5161
6119
          ext_option_value
5162
 
          { }
 
6120
          {
 
6121
          }
5163
6122
        ;
5164
6123
 
5165
6124
option_type:
5196
6155
sys_option_value:
5197
6156
          option_type internal_variable_name equal set_expr_or_default
5198
6157
          {
 
6158
            LEX *lex=Lex;
 
6159
 
5199
6160
            if ($2.var)
5200
6161
            { /* System variable */
5201
6162
              if ($1)
5202
 
              {
5203
 
                Lex->option_type= $1;
5204
 
              }
5205
 
              Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type, $2.var, &$2.base_name, $4)));
 
6163
                lex->option_type= $1;
 
6164
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6165
                                      &$2.base_name, $4));
5206
6166
            }
5207
6167
          }
5208
6168
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5209
6169
          {
5210
 
            Lex->option_type= $1;
5211
 
            Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type,
5212
 
                                              find_sys_var("tx_isolation"),
5213
 
                                              &null_lex_str,
5214
 
                                              new Item_int((int32_t)
5215
 
                                              $5))));
 
6170
            LEX *lex=Lex;
 
6171
            lex->option_type= $1;
 
6172
            lex->var_list.push_back(new set_var(lex->option_type,
 
6173
                                                find_sys_var(YYSession, "tx_isolation"),
 
6174
                                                &null_lex_str,
 
6175
                                                new Item_int((int32_t) $5)));
5216
6176
          }
5217
6177
        ;
5218
6178
 
5219
6179
option_value:
5220
 
          '@' user_variable_ident equal expr
 
6180
          '@' ident_or_text equal expr
5221
6181
          {
5222
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6182
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5223
6183
          }
5224
6184
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5225
6185
          {
5226
 
            Lex->var_list.push_back(SetVarPtr(new set_var($3, $4.var, &$4.base_name, $6)));
5227
 
          }
5228
 
        ;
5229
 
 
5230
 
user_variable_ident:
5231
 
          internal_variable_ident { $$=$1;}
5232
 
        | TEXT_STRING_sys { $$=$1;}
5233
 
        | LEX_HOSTNAME { $$=$1;}
5234
 
        ;
5235
 
 
5236
 
internal_variable_ident:
5237
 
          keyword_exception_for_variable
5238
 
          {
5239
 
            $$.str= YYSession->strmake($1.str, $1.length);
5240
 
            $$.length= $1.length;
5241
 
          }
5242
 
        | IDENT_sys    { $$=$1; }
 
6186
            LEX *lex=Lex;
 
6187
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6188
          }
5243
6189
        ;
5244
6190
 
5245
6191
internal_variable_name:
5246
 
          internal_variable_ident
 
6192
          ident
5247
6193
          {
 
6194
            Session *session= YYSession;
 
6195
 
5248
6196
            /* We have to lookup here since local vars can shadow sysvars */
5249
6197
            {
5250
6198
              /* Not an SP local variable */
5251
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6199
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
5252
6200
              if (!tmp)
5253
6201
                DRIZZLE_YYABORT;
5254
6202
              $$.var= tmp;
5280
6228
unlock:
5281
6229
          UNLOCK_SYM
5282
6230
          {
5283
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6231
            LEX *lex= Lex;
 
6232
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6233
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6234
            if (lex->statement == NULL)
 
6235
              DRIZZLE_YYABORT;
5284
6236
          }
5285
6237
          table_or_tables
5286
6238
          {}
5289
6241
begin:
5290
6242
          BEGIN_SYM
5291
6243
          {
5292
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6244
            LEX *lex=Lex;
 
6245
            lex->sql_command = SQLCOM_BEGIN;
 
6246
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6247
            if (lex->statement == NULL)
 
6248
              DRIZZLE_YYABORT;
5293
6249
          }
5294
6250
          opt_work {}
5295
6251
        ;
5321
6277
commit:
5322
6278
          COMMIT_SYM opt_work opt_chain opt_release
5323
6279
          {
5324
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6280
            LEX *lex=Lex;
 
6281
            lex->sql_command= SQLCOM_COMMIT;
 
6282
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6283
            lex->statement= statement;
 
6284
            if (lex->statement == NULL)
 
6285
              DRIZZLE_YYABORT;
 
6286
            statement->tx_chain= $3;
 
6287
            statement->tx_release= $4;
5325
6288
          }
5326
6289
        ;
5327
6290
 
5328
6291
rollback:
5329
6292
          ROLLBACK_SYM opt_work opt_chain opt_release
5330
6293
          {
5331
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6294
            LEX *lex=Lex;
 
6295
            lex->sql_command= SQLCOM_ROLLBACK;
 
6296
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6297
            lex->statement= statement;
 
6298
            if (lex->statement == NULL)
 
6299
              DRIZZLE_YYABORT;
 
6300
            statement->tx_chain= $3;
 
6301
            statement->tx_release= $4;
5332
6302
          }
5333
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6303
        | ROLLBACK_SYM opt_work
 
6304
          TO_SYM opt_savepoint ident
5334
6305
          {
5335
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6306
            LEX *lex=Lex;
 
6307
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6308
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6309
            if (lex->statement == NULL)
 
6310
              DRIZZLE_YYABORT;
 
6311
            lex->ident= $5;
5336
6312
          }
5337
6313
        ;
5338
6314
 
5339
6315
savepoint:
5340
 
          SAVEPOINT_SYM savepoint_ident
 
6316
          SAVEPOINT_SYM ident
5341
6317
          {
5342
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6318
            LEX *lex=Lex;
 
6319
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6320
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6321
            if (lex->statement == NULL)
 
6322
              DRIZZLE_YYABORT;
 
6323
            lex->ident= $2;
5343
6324
          }
5344
6325
        ;
5345
6326
 
5346
6327
release:
5347
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6328
          RELEASE_SYM SAVEPOINT_SYM ident
5348
6329
          {
5349
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6330
            LEX *lex=Lex;
 
6331
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6332
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6333
            if (lex->statement == NULL)
 
6334
              DRIZZLE_YYABORT;
 
6335
            lex->ident= $3;
5350
6336
          }
5351
6337
        ;
5352
6338
 
5353
 
savepoint_ident:
5354
 
               IDENT_sys
5355
 
               ;
5356
 
 
5357
6339
/*
5358
6340
   UNIONS : glue selects together
5359
6341
*/
5367
6349
union_list:
5368
6350
          UNION_SYM union_option
5369
6351
          {
5370
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6352
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5371
6353
              DRIZZLE_YYABORT;
5372
6354
          }
5373
6355
          select_init
5388
6370
 
5389
6371
union_order_or_limit:
5390
6372
          {
5391
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5392
 
            Select_Lex *sel= Lex->current_select;
 
6373
            Session *session= YYSession;
 
6374
            LEX *lex= session->lex;
 
6375
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6376
            Select_Lex *sel= lex->current_select;
5393
6377
            Select_Lex_Unit *unit= sel->master_unit();
5394
6378
            Select_Lex *fake= unit->fake_select_lex;
5395
6379
            if (fake)
5396
6380
            {
5397
6381
              unit->global_parameters= fake;
5398
6382
              fake->no_table_names_allowed= 1;
5399
 
              Lex->current_select= fake;
 
6383
              lex->current_select= fake;
5400
6384
            }
5401
 
            YYSession->setWhere("global ORDER clause");
 
6385
            session->where= "global ORDER clause";
5402
6386
          }
5403
6387
          order_or_limit
5404
6388
          {
5405
 
            YYSession->getLex()->current_select->no_table_names_allowed= 0;
5406
 
            YYSession->setWhere("");
 
6389
            Session *session= YYSession;
 
6390
            session->lex->current_select->no_table_names_allowed= 0;
 
6391
            session->where= "";
5407
6392
          }
5408
6393
        ;
5409
6394
 
5434
6419
        | query_expression_body
5435
6420
          UNION_SYM union_option
5436
6421
          {
5437
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6422
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5438
6423
              DRIZZLE_YYABORT;
5439
6424
          }
5440
6425
          query_specification
5454
6439
 
5455
6440
subselect_start:
5456
6441
          {
5457
 
            if (not Lex->expr_allows_subselect)
 
6442
            LEX *lex=Lex;
 
6443
            if (!lex->expr_allows_subselect)
5458
6444
            {
5459
 
              parser::my_parse_error(YYSession->m_lip);
 
6445
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6446
              my_parse_error(&pass);
5460
6447
              DRIZZLE_YYABORT;
5461
6448
            }
5462
6449
            /*
5466
6453
              (SELECT .. ) UNION ...  becomes
5467
6454
              SELECT * FROM ((SELECT ...) UNION ...)
5468
6455
            */
5469
 
            if (new_select(Lex, 1))
 
6456
            if (mysql_new_select(Lex, 1))
5470
6457
              DRIZZLE_YYABORT;
5471
6458
          }
5472
6459
        ;
5473
6460
 
5474
6461
subselect_end:
5475
6462
          {
5476
 
            Lex->pop_context();
5477
 
            Select_Lex *child= Lex->current_select;
5478
 
            Lex->current_select= Lex->current_select->return_after_parsing();
5479
 
            Lex->nest_level--;
5480
 
            Lex->current_select->n_child_sum_items += child->n_sum_items;
 
6463
            LEX *lex=Lex;
 
6464
            lex->pop_context();
 
6465
            Select_Lex *child= lex->current_select;
 
6466
            lex->current_select = lex->current_select->return_after_parsing();
 
6467
            lex->nest_level--;
 
6468
            lex->current_select->n_child_sum_items += child->n_sum_items;
5481
6469
            /*
5482
6470
              A subselect can add fields to an outer select. Reserve space for
5483
6471
              them.
5484
6472
            */
5485
 
            Lex->current_select->select_n_where_fields+=
 
6473
            lex->current_select->select_n_where_fields+=
5486
6474
            child->select_n_where_fields;
5487
6475
          }
5488
6476
        ;