~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Jay Pipes
  • Date: 2010-03-09 20:02:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1339.
  • Revision ID: jpipes@serialcoder-20100309200229-dfrliy4fads9vyf4
Fixes Bug #535296 by only incrementing ha_commit_count when its a normal transaction commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* sql_yacc.yy */
17
17
 
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())
37
 
 
38
 
#include <config.h>
39
 
#include <cstdio>
40
 
#include <drizzled/parser.h>
41
 
 
42
 
int yylex(union ParserType *yylval, drizzled::Session *session);
 
38
#define Lex (YYSession->lex)
 
39
 
 
40
#include "config.h"
 
41
#include "drizzled/parser.h"
 
42
 
 
43
int yylex(void *yylval, void *yysession);
43
44
 
44
45
#define yyoverflow(A,B,C,D,E,F)               \
45
46
  {                                           \
46
 
    unsigned long val= *(F);                          \
 
47
    ulong val= *(F);                          \
47
48
    if (drizzled::my_yyoverflow((B), (D), &val)) \
48
49
    {                                         \
49
 
      yyerror(NULL, (char*) (A));                   \
 
50
      yyerror((char*) (A));                   \
50
51
      return 2;                               \
51
52
    }                                         \
52
53
    else                                      \
58
59
#define DRIZZLE_YYABORT                         \
59
60
  do                                          \
60
61
  {                                           \
 
62
    LEX::cleanup_lex_after_parse_error(YYSession);\
61
63
    YYABORT;                                  \
62
64
  } while (0)
63
65
 
64
66
#define DRIZZLE_YYABORT_UNLESS(A)         \
65
67
  if (!(A))                             \
66
68
  {                                     \
67
 
    parser::my_parse_error(YYSession->m_lip);\
 
69
    my_parse_error(ER(ER_SYNTAX_ERROR));\
68
70
    DRIZZLE_YYABORT;                      \
69
71
  }
70
72
 
 
73
 
 
74
#define YYDEBUG 0
 
75
 
71
76
namespace drizzled
72
77
{
73
78
 
75
80
class Item;
76
81
class Item_num;
77
82
 
78
 
namespace item
79
 
{
80
 
class Boolean;
81
 
class True;
82
 
class False;
83
 
}
84
 
 
 
83
 
 
84
static bool check_reserved_words(LEX_STRING *name)
 
85
{
 
86
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
 
87
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
 
88
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
 
89
    return true;
 
90
  return false;
 
91
}
 
92
 
 
93
/**
 
94
  @brief Push an error message into MySQL error stack with line
 
95
  and position information.
 
96
 
 
97
  This function provides semantic action implementers with a way
 
98
  to push the famous "You have a syntax error near..." error
 
99
  message into the error stack, which is normally produced only if
 
100
  a parse error is discovered internally by the Bison generated
 
101
  parser.
 
102
*/
 
103
 
 
104
static void my_parse_error(const char *s)
 
105
{
 
106
  Session *session= current_session;
 
107
  Lex_input_stream *lip= session->m_lip;
 
108
 
 
109
  const char *yytext= lip->get_tok_start();
 
110
  /* Push an error into the error stack */
 
111
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
112
                  (yytext ? yytext : ""),
 
113
                  lip->yylineno);
 
114
}
85
115
 
86
116
/**
87
117
  @brief Bison callback to report a syntax/OOM error
98
128
 
99
129
  This function is not for use in semantic actions and is internal to
100
130
  the parser, as it performs some pre-return cleanup.
101
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
131
  In semantic actions, please use my_parse_error or my_error to
102
132
  push an error into the error stack and DRIZZLE_YYABORT
103
133
  to abort from the parser.
104
134
*/
105
135
 
106
 
static void base_sql_error(drizzled::Session *session, const char *s)
107
 
{
108
 
  parser::errorOn(session, s);
 
136
static void DRIZZLEerror(const char *s)
 
137
{
 
138
  Session *session= current_session;
 
139
 
 
140
  /*
 
141
    Restore the original LEX if it was replaced when parsing
 
142
    a stored procedure. We must ensure that a parsing error
 
143
    does not leave any side effects in the Session.
 
144
  */
 
145
  LEX::cleanup_lex_after_parse_error(session);
 
146
 
 
147
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
148
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
149
    s= ER(ER_SYNTAX_ERROR);
 
150
  my_parse_error(s);
 
151
}
 
152
 
 
153
/**
 
154
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
155
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
156
  This function returns the proper item for the SQL expression
 
157
  <code>left [NOT] IN ( expr )</code>
 
158
  @param session the current thread
 
159
  @param left the in predicand
 
160
  @param equal true for IN predicates, false for NOT IN predicates
 
161
  @param expr first and only expression of the in value list
 
162
  @return an expression representing the IN predicate.
 
163
*/
 
164
static Item* handle_sql2003_note184_exception(Session *session,
 
165
                                              Item* left, bool equal,
 
166
                                              Item *expr)
 
167
{
 
168
  /*
 
169
    Relevant references for this issue:
 
170
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
171
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
172
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
173
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
174
    - SQL:2003 Feature F561, "Full value expressions".
 
175
 
 
176
    The exception in SQL:2003 Note 184 means:
 
177
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
178
    should be re-interpreted as an Item_in_subselect, which corresponds
 
179
    to a <table subquery> when used inside an <in predicate>.
 
180
 
 
181
    Our reading of Note 184 is reccursive, so that all:
 
182
    - IN (( <subquery> ))
 
183
    - IN ((( <subquery> )))
 
184
    - IN '('^N <subquery> ')'^N
 
185
    - etc
 
186
    should be interpreted as a <table subquery>, no matter how deep in the
 
187
    expression the <subquery> is.
 
188
  */
 
189
 
 
190
  Item *result;
 
191
 
 
192
  if (expr->type() == Item::SUBSELECT_ITEM)
 
193
  {
 
194
    Item_subselect *expr2 = (Item_subselect*) expr;
 
195
 
 
196
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
197
    {
 
198
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
199
      Select_Lex *subselect;
 
200
 
 
201
      /*
 
202
        Implement the mandated change, by altering the semantic tree:
 
203
          left IN Item_singlerow_subselect(subselect)
 
204
        is modified to
 
205
          left IN (subselect)
 
206
        which is represented as
 
207
          Item_in_subselect(left, subselect)
 
208
      */
 
209
      subselect= expr3->invalidate_and_restore_select_lex();
 
210
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
211
 
 
212
      if (! equal)
 
213
        result = negate_expression(session, result);
 
214
 
 
215
      return(result);
 
216
    }
 
217
  }
 
218
 
 
219
  if (equal)
 
220
    result= new (session->mem_root) Item_func_eq(left, expr);
 
221
  else
 
222
    result= new (session->mem_root) Item_func_ne(left, expr);
 
223
 
 
224
  return(result);
 
225
}
 
226
 
 
227
/**
 
228
   @brief Creates a new Select_Lex for a UNION branch.
 
229
 
 
230
   Sets up and initializes a Select_Lex structure for a query once the parser
 
231
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
232
   the new Select_Lex becomes the current one..=
 
233
 
 
234
   @lex The parser state.
 
235
 
 
236
   @is_union_distinct True if the union preceding the new select statement
 
237
   uses UNION DISTINCT.
 
238
 
 
239
   @return <code>false</code> if successful, <code>true</code> if an error was
 
240
   reported. In the latter case parsing should stop.
 
241
 */
 
242
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
243
{
 
244
  if (lex->result)
 
245
  {
 
246
    /* Only the last SELECT can have  INTO...... */
 
247
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
248
    return true;
 
249
  }
 
250
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
251
  {
 
252
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
253
    return true;
 
254
  }
 
255
  /* This counter shouldn't be incremented for UNION parts */
 
256
  lex->nest_level--;
 
257
  if (mysql_new_select(lex, 0))
 
258
    return true;
 
259
  mysql_init_select(lex);
 
260
  lex->current_select->linkage=UNION_TYPE;
 
261
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
262
    lex->current_select->master_unit()->union_distinct=
 
263
      lex->current_select;
 
264
  return false;
 
265
}
 
266
 
 
267
/**
 
268
   @brief Initializes a Select_Lex for a query within parentheses (aka
 
269
   braces).
 
270
 
 
271
   @return false if successful, true if an error was reported. In the latter
 
272
   case parsing should stop.
 
273
 */
 
274
static bool setup_select_in_parentheses(LEX *lex)
 
275
{
 
276
  Select_Lex * sel= lex->current_select;
 
277
  if (sel->set_braces(1))
 
278
  {
 
279
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
280
    return true;
 
281
  }
 
282
  if (sel->linkage == UNION_TYPE &&
 
283
      !sel->master_unit()->first_select()->braces &&
 
284
      sel->master_unit()->first_select()->linkage ==
 
285
      UNION_TYPE)
 
286
  {
 
287
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
288
    return true;
 
289
  }
 
290
  if (sel->linkage == UNION_TYPE &&
 
291
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
292
      sel->master_unit()->fake_select_lex)
 
293
  {
 
294
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
295
    return true;
 
296
  }
 
297
  /* select in braces, can't contain global parameters */
 
298
  if (sel->master_unit()->fake_select_lex)
 
299
    sel->master_unit()->global_parameters=
 
300
      sel->master_unit()->fake_select_lex;
 
301
  return false;
 
302
}
 
303
 
 
304
static Item* reserved_keyword_function(const std::string &name, List<Item> *item_list)
 
305
{
 
306
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
 
307
  Item *item= NULL;
 
308
 
 
309
  if (udf)
 
310
  {
 
311
    item= Create_udf_func::s_singleton.create(current_session, udf, item_list);
 
312
  } else {
 
313
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
314
  }
 
315
 
 
316
  return item;
109
317
}
110
318
 
111
319
} /* namespace drizzled; */
112
320
 
113
321
using namespace drizzled;
114
322
%}
115
 
%union ParserType {
116
 
  bool boolean;
 
323
%union {
117
324
  int  num;
118
 
  unsigned long ulong_num;
 
325
  ulong ulong_num;
119
326
  uint64_t ulonglong_number;
120
327
  int64_t longlong_number;
121
328
  drizzled::LEX_STRING lex_str;
131
338
  drizzled::Key_part_spec *key_part;
132
339
  const drizzled::plugin::Function *udf;
133
340
  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;
 
341
  struct drizzled::sys_var_with_base variable;
 
342
  enum drizzled::sql_var_t var_type;
137
343
  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;
 
344
  enum drizzled::ha_key_alg key_alg;
 
345
  enum drizzled::row_type row_type;
 
346
  enum drizzled::column_format_type column_format_type;
 
347
  enum drizzled::ha_rkey_function ha_rkey_mode;
 
348
  enum drizzled::enum_tx_isolation tx_isolation;
 
349
  enum drizzled::Cast_target cast_type;
142
350
  const drizzled::CHARSET_INFO *charset;
143
351
  drizzled::thr_lock_type lock_type;
144
352
  drizzled::interval_type interval, interval_time_st;
145
 
  drizzled::type::timestamp_t date_time_type;
 
353
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
146
354
  drizzled::Select_Lex *select_lex;
147
355
  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;
152
 
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
153
 
  drizzled::execute_string_t execute_string;
 
356
  struct drizzled::st_lex *lex;
 
357
  enum drizzled::index_hint_type index_hint;
 
358
  enum drizzled::enum_filetype filetype;
 
359
  enum drizzled::ha_build_method build_method;
 
360
  enum drizzled::Foreign_key::fk_option m_fk_option;
154
361
}
155
362
 
156
363
%{
157
364
namespace drizzled
158
365
{
159
 
bool my_yyoverflow(short **a, union ParserType **b, unsigned long *yystacksize);
 
366
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
160
367
}
161
368
%}
162
369
 
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
 
 
 
370
%pure_parser                                    /* We have threads */
172
371
/*
173
 
  Currently there are 70 shift/reduce conflicts.
 
372
  Currently there are 88 shift/reduce conflicts.
174
373
  We should not introduce new conflicts any more.
175
374
*/
176
 
%expect 70
 
375
%expect 88
177
376
 
178
377
/*
179
378
   Comments for TOKENS.
194
393
 
195
394
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
196
395
%token  ACTION                        /* SQL-2003-N */
197
 
%token  ADD_SYM                           /* SQL-2003-R */
 
396
%token  ADD                           /* SQL-2003-R */
198
397
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
199
398
%token  AFTER_SYM                     /* SQL-2003-N */
200
399
%token  AGGREGATE_SYM
201
400
%token  ALL                           /* SQL-2003-R */
202
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
401
%token  ALTER                         /* SQL-2003-R */
203
402
%token  ANALYZE_SYM
204
403
%token  AND_SYM                       /* SQL-2003-R */
205
404
%token  ANY_SYM                       /* SQL-2003-R */
208
407
%token  ASENSITIVE_SYM                /* FUTURE-USE */
209
408
%token  AT_SYM                        /* SQL-2003-R */
210
409
%token  AUTO_INC
 
410
%token  AVG_ROW_LENGTH
211
411
%token  AVG_SYM                       /* SQL-2003-N */
212
412
%token  BEFORE_SYM                    /* SQL-2003-N */
213
413
%token  BEGIN_SYM                     /* SQL-2003-R */
217
417
%token  BIN_NUM
218
418
%token  BIT_SYM                       /* MYSQL-FUNC */
219
419
%token  BLOB_SYM                      /* SQL-2003-R */
 
420
%token  BLOCK_SIZE_SYM
 
421
%token  BLOCK_SYM
220
422
%token  BOOLEAN_SYM                   /* SQL-2003-R */
221
423
%token  BOOL_SYM
222
424
%token  BOTH                          /* SQL-2003-R */
223
425
%token  BTREE_SYM
224
426
%token  BY                            /* SQL-2003-R */
 
427
%token  BYTE_SYM
225
428
%token  CALL_SYM                      /* SQL-2003-R */
226
429
%token  CASCADE                       /* SQL-2003-N */
227
430
%token  CASCADED                      /* SQL-2003-R */
228
431
%token  CASE_SYM                      /* SQL-2003-R */
229
432
%token  CAST_SYM                      /* SQL-2003-R */
230
 
%token  CATALOG_SYM
231
433
%token  CHAIN_SYM                     /* SQL-2003-N */
232
 
%token  CHANGE_SYM
 
434
%token  CHANGE
233
435
%token  CHAR_SYM                      /* SQL-2003-R */
234
436
%token  CHECKSUM_SYM
235
437
%token  CHECK_SYM                     /* SQL-2003-R */
250
452
%token  CONSISTENT_SYM
251
453
%token  CONSTRAINT                    /* SQL-2003-R */
252
454
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
455
%token  CONTINUE_SYM                  /* SQL-2003-R */
253
456
%token  CONVERT_SYM                   /* SQL-2003-N */
254
457
%token  COUNT_SYM                     /* SQL-2003-N */
255
458
%token  CREATE                        /* SQL-2003-R */
260
463
%token  CURSOR_SYM                    /* SQL-2003-R */
261
464
%token  DATABASE
262
465
%token  DATABASES
 
466
%token  DATAFILE_SYM
263
467
%token  DATA_SYM                      /* SQL-2003-N */
264
468
%token  DATETIME_SYM
265
469
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
283
487
%token  DISCARD
284
488
%token  DISTINCT                      /* SQL-2003-R */
285
489
%token  DIV_SYM
286
 
%token  DO_SYM
287
490
%token  DOUBLE_SYM                    /* SQL-2003-R */
288
491
%token  DROP                          /* SQL-2003-R */
289
492
%token  DUMPFILE
291
494
%token  DYNAMIC_SYM                   /* SQL-2003-R */
292
495
%token  EACH_SYM                      /* SQL-2003-R */
293
496
%token  ELSE                          /* SQL-2003-R */
 
497
%token  ELSEIF_SYM
294
498
%token  ENABLE_SYM
295
499
%token  ENCLOSED
296
500
%token  END                           /* SQL-2003-R */
298
502
%token  END_OF_INPUT                  /* INTERNAL */
299
503
%token  ENGINE_SYM
300
504
%token  ENUM_SYM
 
505
%token  EQ                            /* OPERATOR */
301
506
%token  EQUAL_SYM                     /* OPERATOR */
302
507
%token  ERRORS
303
508
%token  ESCAPED
304
509
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
510
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
307
511
%token  EXISTS                        /* SQL-2003-R */
308
512
%token  EXTENDED_SYM
309
513
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
514
%token  FALSE_SYM                     /* SQL-2003-R */
 
515
%token  FETCH_SYM                     /* SQL-2003-R */
 
516
%token  COLUMN_FORMAT_SYM
311
517
%token  FILE_SYM
312
518
%token  FIRST_SYM                     /* SQL-2003-N */
313
519
%token  FIXED_SYM
324
530
%token  GLOBAL_SYM                    /* SQL-2003-R */
325
531
%token  GROUP_SYM                     /* SQL-2003-R */
326
532
%token  GROUP_CONCAT_SYM
 
533
%token  GT_SYM                        /* OPERATOR */
327
534
%token  HASH_SYM
328
535
%token  HAVING                        /* SQL-2003-R */
329
536
%token  HEX_NUM
333
540
%token  HOUR_SYM                      /* SQL-2003-R */
334
541
%token  IDENT
335
542
%token  IDENTIFIED_SYM
336
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
337
543
%token  IDENT_QUOTED
338
544
%token  IF
339
545
%token  IGNORE_SYM
366
572
%token  LIKE                          /* SQL-2003-R */
367
573
%token  LIMIT
368
574
%token  LINES
 
575
%token  LIST_SYM
369
576
%token  LOAD
370
577
%token  LOCAL_SYM                     /* SQL-2003-R */
 
578
%token  LOCATOR_SYM                   /* SQL-2003-N */
371
579
%token  LOCKS_SYM
372
580
%token  LOCK_SYM
373
581
%token  LOGS_SYM
374
582
%token  LONG_NUM
375
583
%token  LONG_SYM
 
584
%token  LOOP_SYM
 
585
%token  LT                            /* OPERATOR */
376
586
%token  MATCH                         /* SQL-2003-R */
 
587
%token  MAX_ROWS
 
588
%token  MAX_SIZE_SYM
377
589
%token  MAX_SYM                       /* SQL-2003-N */
378
590
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
379
591
%token  MEDIUM_SYM
382
594
%token  MINUTE_MICROSECOND_SYM
383
595
%token  MINUTE_SECOND_SYM
384
596
%token  MINUTE_SYM                    /* SQL-2003-R */
 
597
%token  MIN_ROWS
385
598
%token  MIN_SYM                       /* SQL-2003-N */
386
599
%token  MODE_SYM
387
600
%token  MODIFIES_SYM                  /* SQL-2003-R */
393
606
%token  NATIONAL_SYM                  /* SQL-2003-R */
394
607
%token  NATURAL                       /* SQL-2003-R */
395
608
%token  NE                            /* OPERATOR */
 
609
%token  NEG
396
610
%token  NEW_SYM                       /* SQL-2003-R */
397
611
%token  NEXT_SYM                      /* SQL-2003-N */
398
612
%token  NONE_SYM                      /* SQL-2003-R */
417
631
%token  OUTER
418
632
%token  OUTFILE
419
633
%token  OUT_SYM                       /* SQL-2003-R */
 
634
%token  PAGE_SYM
420
635
%token  PARTIAL                       /* SQL-2003-N */
 
636
%token  PHASE_SYM
421
637
%token  POSITION_SYM                  /* SQL-2003-N */
422
638
%token  PRECISION                     /* SQL-2003-R */
423
639
%token  PREV_SYM
428
644
%token  QUERY_SYM
429
645
%token  RANGE_SYM                     /* SQL-2003-R */
430
646
%token  READS_SYM                     /* SQL-2003-R */
 
647
%token  READ_ONLY_SYM
431
648
%token  READ_SYM                      /* SQL-2003-N */
432
649
%token  READ_WRITE_SYM
433
650
%token  REAL                          /* SQL-2003-R */
434
651
%token  REDUNDANT_SYM
435
 
%token  REGEXP_SYM
436
652
%token  REFERENCES                    /* SQL-2003-R */
437
653
%token  RELEASE_SYM                   /* SQL-2003-R */
438
654
%token  RENAME
439
655
%token  REPEATABLE_SYM                /* SQL-2003-N */
440
656
%token  REPEAT_SYM                    /* MYSQL-FUNC */
441
657
%token  REPLACE                       /* MYSQL-FUNC */
442
 
%token  REPLICATION
443
658
%token  RESTRICT
444
659
%token  RETURNS_SYM                   /* SQL-2003-R */
445
660
%token  RETURN_SYM                    /* SQL-2003-R */
 
661
%token  REVERSE_SYM
446
662
%token  REVOKE                        /* SQL-2003-R */
447
663
%token  RIGHT                         /* SQL-2003-R */
448
664
%token  ROLLBACK_SYM                  /* SQL-2003-R */
462
678
%token  SERIAL_SYM
463
679
%token  SESSION_SYM                   /* SQL-2003-N */
464
680
%token  SERVER_SYM
465
 
%token  SET_SYM                           /* SQL-2003-R */
 
681
%token  SERVER_OPTIONS
 
682
%token  SET                           /* SQL-2003-R */
466
683
%token  SET_VAR
467
684
%token  SHARE_SYM
468
685
%token  SHOW
469
 
%token  SIGNED_SYM
 
686
%token  SHUTDOWN
470
687
%token  SIMPLE_SYM                    /* SQL-2003-N */
471
688
%token  SNAPSHOT_SYM
472
689
%token  SPECIFIC_SYM                  /* SQL-2003-R */
484
701
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
485
702
%token  STD_SYM
486
703
%token  STOP_SYM
 
704
%token  STORAGE_SYM
487
705
%token  STORED_SYM
488
706
%token  STRAIGHT_JOIN
489
707
%token  STRING_SYM
492
710
%token  SUBSTRING                     /* SQL-2003-N */
493
711
%token  SUM_SYM                       /* SQL-2003-N */
494
712
%token  SUSPEND_SYM
 
713
%token  SWAPS_SYM
 
714
%token  SWITCHES_SYM
495
715
%token  SYSDATE
496
716
%token  TABLES
497
717
%token  TABLESPACE
502
722
%token  TEXT_STRING
503
723
%token  TEXT_SYM
504
724
%token  THEN_SYM                      /* SQL-2003-R */
505
 
%token  TIME_SYM                 /* SQL-2003-R */
506
725
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
507
726
%token  TIMESTAMP_ADD
508
727
%token  TIMESTAMP_DIFF
512
731
%token  TRIM                          /* SQL-2003-N */
513
732
%token  TRUE_SYM                      /* SQL-2003-R */
514
733
%token  TRUNCATE_SYM
 
734
%token  TYPES_SYM
515
735
%token  TYPE_SYM                      /* SQL-2003-N */
516
736
%token  ULONGLONG_NUM
517
737
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
521
741
%token  UNIQUE_SYM
522
742
%token  UNKNOWN_SYM                   /* SQL-2003-R */
523
743
%token  UNLOCK_SYM
524
 
%token  UNSIGNED_SYM
525
744
%token  UPDATE_SYM                    /* SQL-2003-R */
526
745
%token  USAGE                         /* SQL-2003-N */
527
746
%token  USER                          /* SQL-2003-R */
529
748
%token  USING                         /* SQL-2003-R */
530
749
%token  UTC_DATE_SYM
531
750
%token  UTC_TIMESTAMP_SYM
532
 
%token  UUID_SYM
533
751
%token  VALUES                        /* SQL-2003-R */
534
752
%token  VALUE_SYM                     /* SQL-2003-R */
535
753
%token  VARBINARY
538
756
%token  VARIANCE_SYM
539
757
%token  VARYING                       /* SQL-2003-R */
540
758
%token  VAR_SAMP_SYM
541
 
%token  WAIT_SYM
542
759
%token  WARNINGS
543
760
%token  WEEK_SYM
544
761
%token  WHEN_SYM                      /* SQL-2003-R */
550
767
%token  XOR
551
768
%token  YEAR_MONTH_SYM
552
769
%token  YEAR_SYM                      /* SQL-2003-R */
553
 
%token  ZEROFILL_SYM
554
770
 
555
 
/* Lowest to highest */
556
771
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
557
772
/* 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
 
773
%left   TABLE_REF_PRIORITY
 
774
%left   SET_VAR
 
775
%left   OR_SYM
 
776
%left   XOR
 
777
%left   AND_SYM
 
778
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
 
779
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
570
780
%left   '-' '+'
571
781
%left   '*' '/' '%' DIV_SYM MOD_SYM
 
782
%left   NEG
 
783
%right  NOT_SYM
572
784
%right  BINARY COLLATE_SYM
573
785
%left  INTERVAL_SYM
574
 
%right UMINUS
575
 
%left  '(' ')'
576
 
%left  '{' '}'
577
786
 
578
787
%type <lex_str>
579
788
        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
 
789
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
586
790
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
587
 
        schema_name
588
 
        catalog_name
589
791
        opt_component
590
 
        engine_option_value
591
 
        savepoint_ident
592
 
        BIN_NUM TEXT_STRING_filesystem
 
792
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
593
793
        opt_constraint constraint opt_ident
594
794
 
595
 
%type <execute_string>
596
 
        execute_var_or_string
597
 
 
598
795
%type <lex_str_ptr>
599
796
        opt_table_alias
600
797
 
607
804
%type <string>
608
805
        text_string opt_gconcat_separator
609
806
 
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
 
807
%type <num>
 
808
        type int_type real_type order_dir field_def
 
809
        if_exists opt_table_options
620
810
        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
 
811
        opt_temporary all_or_any opt_distinct
630
812
        union_option
631
813
        start_transaction_opts opt_chain opt_release
632
814
        union_opt select_derived_init option_type2
633
 
        kill_option
634
815
 
635
816
%type <m_fk_option>
636
817
        delete_option
652
833
        table_wild simple_expr udf_expr
653
834
        expr_or_default set_expr_or_default
654
835
        signed_literal now_or_signed_literal opt_escape
655
 
        simple_ident_q
 
836
        simple_ident_nospvar simple_ident_q
656
837
        field_or_var limit_option
657
838
        function_call_keyword
658
839
        function_call_nonkeyword
692
873
 
693
874
%type <interval_time_st> interval_time_stamp
694
875
 
 
876
%type <row_type> row_types
 
877
 
 
878
%type <column_format_type> column_format_types
 
879
 
695
880
%type <tx_isolation> isolation_types
696
881
 
697
882
%type <cast_type> cast_type
698
883
 
699
 
%type <symbol>
700
 
        keyword
701
 
        keyword_sp
702
 
        keyword_exception_for_variable
703
 
        row_format
 
884
%type <symbol> keyword keyword_sp
704
885
 
705
886
%type <charset>
706
887
        collation_name
721
902
        insert_values update delete truncate rename
722
903
        show describe load alter flush
723
904
        begin commit rollback savepoint release
724
 
        analyze check start
 
905
        analyze check start checksum
725
906
        field_list field_list_item field_spec kill column_def key_def
726
907
        select_item_list select_item values_list no_braces
727
908
        opt_limit_clause delete_limit_clause fields opt_values values
728
909
        opt_precision opt_ignore opt_column
729
910
        set unlock string_list
730
911
        ref_list opt_match_clause opt_on_update_delete use
731
 
        opt_delete_option varchar
 
912
        opt_delete_options opt_delete_option varchar
732
913
        opt_outer table_list table_name
733
914
        opt_option opt_place
734
915
        opt_attribute opt_attribute_list attribute
735
916
        flush_options flush_option
736
917
        equal optional_braces
737
918
        normal_join
738
 
        table_to_table_list table_to_table opt_table_list
 
919
        table_to_table_list table_to_table opt_table_list opt_as
 
920
        single_multi
739
921
        union_clause union_list
740
922
        precision subselect_start
741
923
        subselect_end select_var_list select_var_list_init opt_len
742
924
        opt_extended_describe
743
925
        statement
744
 
        execute
745
926
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
746
927
        init_key_options key_options key_opts key_opt key_using_alg
747
928
END_OF_INPUT
750
931
%type <num> index_hint_clause
751
932
%type <filetype> data_file
752
933
 
 
934
%type <NONE>
 
935
        '-' '+' '*' '/' '%' '(' ')'
 
936
        ',' '!' '{' '}' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
 
937
        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM DELETE_SYM
753
938
%%
754
939
 
755
940
/*
776
961
query:
777
962
          END_OF_INPUT
778
963
          {
779
 
            if (!(YYSession->getLex()->select_lex.options & OPTION_FOUND_COMMENT))
 
964
            Session *session= YYSession;
 
965
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
780
966
            {
781
967
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
782
968
              DRIZZLE_YYABORT;
783
969
            }
784
970
            else
785
971
            {
786
 
              YYSession->getLex()->statement= new statement::EmptyQuery(YYSession);
 
972
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
973
              session->lex->statement=
 
974
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
975
              if (session->lex->statement == NULL)
 
976
                DRIZZLE_YYABORT;
787
977
            }
788
978
          }
789
979
        | verb_clause END_OF_INPUT {}
799
989
          alter
800
990
        | analyze
801
991
        | check
 
992
        | checksum
802
993
        | commit
803
994
        | create
804
995
        | delete
805
996
        | describe
806
997
        | drop
807
 
        | execute
808
998
        | flush
809
999
        | insert
810
1000
        | kill
827
1017
/* create a table */
828
1018
 
829
1019
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);
 
1020
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1021
          {
 
1022
            Session *session= YYSession;
 
1023
            LEX *lex= session->lex;
 
1024
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1025
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1026
            lex->statement= statement;
 
1027
            if (lex->statement == NULL)
 
1028
              DRIZZLE_YYABORT;
 
1029
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1030
                                                   TL_OPTION_UPDATING,
 
1031
                                                   TL_WRITE))
 
1032
              DRIZZLE_YYABORT;
 
1033
            lex->col_list.empty();
 
1034
            statement->change=NULL;
 
1035
            statement->is_if_not_exists= $4;
 
1036
            statement->create_info.db_type= NULL;
 
1037
            statement->create_info.default_table_charset= NULL;
 
1038
            lex->name.str= 0;
837
1039
 
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();
 
1040
            message::Table &proto= statement->create_table_proto;
 
1041
           
 
1042
            proto.set_name($5->table.str);
 
1043
            if($2)
 
1044
              proto.set_type(message::Table::TEMPORARY);
 
1045
            else
 
1046
              proto.set_type(message::Table::STANDARD);
843
1047
          }
844
 
          create_table_definition
 
1048
          create2
845
1049
          {
846
 
            Lex->current_select= &Lex->select_lex;
 
1050
            LEX *lex= YYSession->lex;
 
1051
            lex->current_select= &lex->select_lex;
847
1052
          }
848
1053
        | CREATE build_method
849
1054
          {
850
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1055
            LEX *lex=Lex;
 
1056
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1057
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1058
            lex->statement= statement;
 
1059
            if (lex->statement == NULL)
 
1060
              DRIZZLE_YYABORT;
 
1061
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1062
            statement->alter_info.build_method= $2;
 
1063
            lex->col_list.empty();
 
1064
            statement->change=NULL;
851
1065
          }
852
1066
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
853
1067
          {
854
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
855
 
                                                            NULL,
856
 
                                                            TL_OPTION_UPDATING))
 
1068
            LEX *lex=Lex;
 
1069
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1070
 
 
1071
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1072
                                                        NULL,
 
1073
                                                        TL_OPTION_UPDATING))
857
1074
              DRIZZLE_YYABORT;
858
 
 
859
 
            parser::buildKey(Lex, $4, $6);
 
1075
            Key *key;
 
1076
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1077
            statement->alter_info.key_list.push_back(key);
 
1078
            lex->col_list.empty();
860
1079
          }
861
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1080
        | CREATE DATABASE opt_if_not_exists ident
862
1081
          {
863
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1082
            LEX *lex=Lex;
 
1083
 
 
1084
            lex->sql_command=SQLCOM_CREATE_DB;
 
1085
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1086
            lex->statement= statement;
 
1087
            if (lex->statement == NULL)
 
1088
              DRIZZLE_YYABORT;
 
1089
            statement->is_if_not_exists= $3;
864
1090
          }
865
1091
          opt_create_database_options
866
1092
          {
868
1094
          }
869
1095
        ;
870
1096
 
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
 
           }
 
1097
create2:
 
1098
          '(' create2a {}
 
1099
        | opt_create_table_options
 
1100
          create3 {}
 
1101
        | LIKE table_ident opt_create_table_options
 
1102
          {
 
1103
            Session *session= YYSession;
 
1104
            LEX *lex= session->lex;
 
1105
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1106
 
 
1107
            statement->is_create_table_like= true;
 
1108
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1109
              DRIZZLE_YYABORT;
 
1110
          }
 
1111
        | '(' LIKE table_ident ')'
 
1112
          {
 
1113
            Session *session= YYSession;
 
1114
            LEX *lex= session->lex;
 
1115
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1116
 
 
1117
            statement->is_create_table_like= true;
 
1118
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1119
              DRIZZLE_YYABORT;
 
1120
          }
 
1121
        ;
 
1122
 
 
1123
create2a:
 
1124
          field_list ')' opt_create_table_options
 
1125
          create3 {}
 
1126
        |  create_select ')'
 
1127
           { Lex->current_select->set_braces(1);}
878
1128
           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
1129
        ;
886
1130
 
887
 
create_select_as:
 
1131
create3:
888
1132
          /* empty */ {}
889
 
        | opt_duplicate_as create_select
890
 
          {
891
 
            Lex->current_select->set_braces(0);
892
 
          }
 
1133
        | opt_duplicate opt_as create_select
 
1134
          { Lex->current_select->set_braces(0);}
893
1135
          union_clause {}
894
 
        | opt_duplicate_as '(' create_select ')'
895
 
          {
896
 
            Lex->current_select->set_braces(1);
897
 
          }
 
1136
        | opt_duplicate opt_as '(' create_select ')'
 
1137
          { Lex->current_select->set_braces(1);}
898
1138
          union_opt {}
899
1139
        ;
900
1140
 
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
1141
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
1142
          SELECT_SYM
922
1143
          {
923
 
            Lex->lock_option= TL_READ;
924
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1144
            LEX *lex=Lex;
 
1145
            lex->lock_option= TL_READ;
 
1146
            if (lex->sql_command == SQLCOM_INSERT)
925
1147
            {
926
 
              delete Lex->statement;
927
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1148
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1149
              delete lex->statement;
 
1150
              lex->statement=
 
1151
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1152
              if (lex->statement == NULL)
 
1153
                DRIZZLE_YYABORT;
928
1154
            }
929
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1155
            else if (lex->sql_command == SQLCOM_REPLACE)
930
1156
            {
931
 
              delete Lex->statement;
932
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1157
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1158
              delete lex->statement;
 
1159
              lex->statement=
 
1160
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1161
              if (lex->statement == NULL)
 
1162
                DRIZZLE_YYABORT;
933
1163
            }
934
1164
            /*
935
1165
              The following work only with the local list, the global list
936
1166
              is created correctly in this case
937
1167
            */
938
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
939
 
            init_select(Lex);
940
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1168
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1169
            mysql_init_select(lex);
 
1170
            lex->current_select->parsing_place= SELECT_LIST;
941
1171
          }
942
1172
          select_options select_item_list
943
1173
          {
953
1183
          }
954
1184
        ;
955
1185
 
 
1186
opt_as:
 
1187
          /* empty */ {}
 
1188
        | AS {}
 
1189
        ;
 
1190
 
956
1191
opt_create_database_options:
957
1192
          /* empty */ {}
958
1193
        | default_collation_schema {}
959
 
        | opt_database_custom_options {}
960
 
        ;
961
 
 
962
 
opt_database_custom_options:
963
 
        custom_database_option
964
 
        | custom_database_option ',' opt_database_custom_options
965
 
        ;
966
 
 
967
 
custom_database_option:
968
 
          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
 
          }
981
 
        | ident_or_text equal ident_or_text
982
 
          {
983
 
            parser::buildSchemaOption(Lex, $1.str, $3);
984
 
          }
985
 
        | ident_or_text equal ulonglong_num
986
 
          {
987
 
            parser::buildSchemaOption(Lex, $1.str, $3);
988
 
          }
989
1194
        ;
990
1195
 
991
1196
opt_table_options:
995
1200
 
996
1201
opt_if_not_exists:
997
1202
          /* empty */ { $$= false; }
998
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1203
        | IF not EXISTS { $$= true; }
999
1204
        ;
1000
1205
 
1001
1206
opt_create_table_options:
1012
1217
          create_table_option
1013
1218
        | create_table_option     create_table_options
1014
1219
        | create_table_option ',' create_table_options
 
1220
        ;
1015
1221
 
1016
1222
create_table_option:
1017
 
          custom_engine_option;
1018
 
 
1019
 
custom_engine_option:
1020
 
        ENGINE_SYM equal ident_or_text
1021
 
          {
1022
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1223
          ENGINE_SYM opt_equal ident_or_text
 
1224
          {
 
1225
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1226
            message::Table::StorageEngine *protoengine;
 
1227
            protoengine= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_engine();
 
1228
 
 
1229
            statement->is_engine_set= true;
 
1230
 
 
1231
            protoengine->set_name($3.str);
 
1232
          }
 
1233
        | BLOCK_SIZE_SYM opt_equal ulong_num
 
1234
          {
 
1235
            message::Table::TableOptions *tableopts;
 
1236
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1237
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1238
 
 
1239
            tableopts->set_block_size($3);
 
1240
            statement->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
1023
1241
          }
1024
1242
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1025
1243
          {
1026
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1244
            message::Table::TableOptions *tableopts;
 
1245
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1246
 
 
1247
            tableopts->set_comment($3.str);
1027
1248
          }
1028
1249
        | AUTO_INC opt_equal ulonglong_num
1029
1250
          {
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);
1051
 
          }
1052
 
        | ident_or_text equal ulonglong_num
1053
 
          {
1054
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1251
            message::Table::TableOptions *tableopts;
 
1252
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1253
 
 
1254
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1255
 
 
1256
            statement->create_info.auto_increment_value=$3;
 
1257
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1258
            tableopts->set_auto_increment_value($3);
 
1259
          }
 
1260
        | ROW_FORMAT_SYM opt_equal row_types
 
1261
          {
 
1262
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1263
 
 
1264
            statement->create_info.row_type= $3;
 
1265
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1266
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1055
1267
          }
1056
1268
        | default_collation
 
1269
        | KEY_BLOCK_SIZE opt_equal ulong_num
 
1270
          {
 
1271
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1272
 
 
1273
            statement->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1274
 
 
1275
            message::Table::TableOptions *tableopts;
 
1276
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1277
            tableopts->set_key_block_size($3);
 
1278
          }
1057
1279
        ;
1058
1280
 
1059
1281
default_collation:
1060
1282
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1061
1283
          {
1062
 
            if (not parser::buildCollation(Lex, $4))
1063
 
            {
1064
 
              DRIZZLE_YYABORT;
1065
 
            }
 
1284
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1285
 
 
1286
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1287
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1288
                 cinfo->default_table_charset && $4 &&
 
1289
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1290
              {
 
1291
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1292
                         $4->name, cinfo->default_table_charset->csname);
 
1293
                DRIZZLE_YYABORT;
 
1294
              }
 
1295
              statement->create_info.default_table_charset= $4;
 
1296
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1066
1297
          }
1067
1298
        ;
1068
1299
 
1069
1300
default_collation_schema:
1070
1301
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1071
1302
          {
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
 
          }
 
1303
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1304
 
 
1305
            message::Schema &schema_message= statement->schema_message;
 
1306
            schema_message.set_collation($4->name);
 
1307
          }
 
1308
        ;
 
1309
 
 
1310
column_format_types:
 
1311
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1312
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1313
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1314
 
 
1315
row_types:
 
1316
          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
 
1317
        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
 
1318
        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
 
1319
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
 
1320
        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
 
1321
        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
 
1322
        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
1091
1323
        ;
1092
1324
 
1093
1325
opt_select_from:
1109
1341
          field_spec opt_check_constraint
1110
1342
        | field_spec references
1111
1343
          {
1112
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1344
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1113
1345
          }
1114
1346
        ;
1115
1347
 
1116
1348
key_def:
1117
1349
          key_type opt_ident key_alg '(' key_list ')' key_options
1118
1350
          {
1119
 
            parser::buildKey(Lex, $1, $2);
 
1351
            LEX *lex=Lex;
 
1352
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1353
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1354
                              lex->col_list);
 
1355
            statement->alter_info.key_list.push_back(key);
 
1356
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1120
1357
          }
1121
1358
        | opt_constraint constraint_key_type opt_ident key_alg
1122
1359
          '(' key_list ')' key_options
1123
1360
          {
1124
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1361
            LEX *lex=Lex;
 
1362
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1363
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1364
                              lex->col_list);
 
1365
            statement->alter_info.key_list.push_back(key);
 
1366
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1125
1367
          }
1126
1368
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1127
1369
          {
1128
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1370
            LEX *lex=Lex;
 
1371
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1372
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
 
1373
                                      $8,
 
1374
                                      lex->ref_list,
 
1375
                                      statement->fk_delete_opt,
 
1376
                                      statement->fk_update_opt,
 
1377
                                      statement->fk_match_option);
 
1378
            statement->alter_info.key_list.push_back(key);
 
1379
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1380
                         &default_key_create_info, 1,
 
1381
                         lex->col_list);
 
1382
            statement->alter_info.key_list.push_back(key);
 
1383
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1384
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1385
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1129
1386
          }
1130
1387
        | constraint opt_check_constraint
1131
1388
          {
1132
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1389
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1133
1390
          }
1134
1391
        | opt_constraint check_constraint
1135
1392
          {
1136
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1393
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1137
1394
          }
1138
1395
        ;
1139
1396
 
1158
1415
field_spec:
1159
1416
          field_ident
1160
1417
          {
1161
 
            parser::buildCreateFieldIdent(Lex);
 
1418
            LEX *lex=Lex;
 
1419
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1420
            lex->length=lex->dec=0;
 
1421
            lex->type=0;
 
1422
            statement->default_value= statement->on_update_value= 0;
 
1423
            statement->comment= null_lex_str;
 
1424
            lex->charset=NULL;
 
1425
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1426
 
 
1427
            message::AlterTable &alter_proto=
 
1428
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1429
            statement->current_proto_field= alter_proto.add_added_field();
1162
1430
          }
1163
1431
          field_def
1164
1432
          {
 
1433
            LEX *lex=Lex;
1165
1434
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1166
1435
 
1167
 
            if (Lex->field())
1168
 
            {
1169
 
              Lex->field()->set_name($1.str);
1170
 
            }
 
1436
            if (statement->current_proto_field)
 
1437
              statement->current_proto_field->set_name($1.str);
1171
1438
 
1172
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1173
 
                                  Lex->length, Lex->dec, Lex->type,
 
1439
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1440
                                  lex->length,lex->dec,lex->type,
1174
1441
                                  statement->column_format,
1175
1442
                                  statement->default_value, statement->on_update_value,
1176
1443
                                  &statement->comment,
1177
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1444
                                  statement->change, &lex->interval_list, lex->charset))
1178
1445
              DRIZZLE_YYABORT;
1179
1446
 
1180
 
            Lex->setField(NULL);
 
1447
            statement->current_proto_field= NULL;
1181
1448
          }
1182
1449
        ;
1183
 
 
1184
1450
field_def:
1185
 
          field_definition opt_attribute {}
 
1451
          type opt_attribute {}
1186
1452
        ;
1187
1453
 
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));
 
1454
type:
 
1455
        int_type
 
1456
        {
 
1457
          $$=$1;
 
1458
          Lex->length=(char*) 0; /* use default length */
 
1459
          statement::CreateTable *statement=
 
1460
            (statement::CreateTable *)Lex->statement;
 
1461
 
 
1462
          if (statement->current_proto_field)
 
1463
          {
 
1464
            if ($1 == DRIZZLE_TYPE_LONG)
 
1465
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1466
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1467
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1468
            else
 
1469
              abort();
 
1470
          }
1192
1471
          }
1193
1472
        | real_type opt_precision
1194
1473
          {
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
 
1474
            $$=$1;
 
1475
 
 
1476
            statement::CreateTable *statement=
 
1477
              (statement::CreateTable *)Lex->statement;
 
1478
 
 
1479
            if (statement->current_proto_field)
 
1480
            {
 
1481
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1482
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1483
            }
 
1484
          }
 
1485
          | char '(' NUM ')'
 
1486
            {
 
1487
              Lex->length=$3.str;
 
1488
              $$=DRIZZLE_TYPE_VARCHAR;
 
1489
 
 
1490
            statement::CreateTable *statement=
 
1491
              (statement::CreateTable *)Lex->statement;
 
1492
 
 
1493
            if (statement->current_proto_field)
 
1494
            {
 
1495
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1496
              message::Table::Field::StringFieldOptions *string_field_options;
 
1497
 
 
1498
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1499
 
 
1500
              string_field_options->set_length(atoi($3.str));
 
1501
            }
 
1502
            }
 
1503
          | char
 
1504
            {
 
1505
              Lex->length=(char*) "1";
 
1506
              $$=DRIZZLE_TYPE_VARCHAR;
 
1507
 
 
1508
            statement::CreateTable *statement=
 
1509
              (statement::CreateTable *)Lex->statement;
 
1510
 
 
1511
            if (statement->current_proto_field)
 
1512
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1513
            }
 
1514
          | varchar '(' NUM ')'
 
1515
            {
 
1516
              Lex->length=$3.str;
 
1517
              $$= DRIZZLE_TYPE_VARCHAR;
 
1518
 
 
1519
            statement::CreateTable *statement=
 
1520
              (statement::CreateTable *)Lex->statement;
 
1521
 
 
1522
            if (statement->current_proto_field)
 
1523
            {
 
1524
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1525
 
 
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
          | VARBINARY '(' NUM ')'
 
1534
            {
 
1535
              Lex->length=$3.str;
 
1536
              Lex->charset=&my_charset_bin;
 
1537
              $$= DRIZZLE_TYPE_VARCHAR;
 
1538
 
 
1539
            statement::CreateTable *statement=
 
1540
              (statement::CreateTable *)Lex->statement;
 
1541
 
 
1542
            if (statement->current_proto_field)
 
1543
            {
 
1544
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1545
              message::Table::Field::StringFieldOptions *string_field_options;
 
1546
 
 
1547
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1548
 
 
1549
              string_field_options->set_length(atoi($3.str));
 
1550
              string_field_options->set_collation_id(my_charset_bin.number);
 
1551
              string_field_options->set_collation(my_charset_bin.name);
 
1552
            }
 
1553
            }
 
1554
          | DATE_SYM
1215
1555
          {
1216
1556
            $$=DRIZZLE_TYPE_DATE;
1217
1557
 
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
 
1558
            statement::CreateTable *statement=
 
1559
              (statement::CreateTable *)Lex->statement;
 
1560
 
 
1561
            if (statement->current_proto_field)
 
1562
              statement->current_proto_field->set_type(message::Table::Field::DATE);
 
1563
          }
 
1564
          | TIMESTAMP_SYM
 
1565
          {
 
1566
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1567
 
 
1568
            statement::CreateTable *statement=
 
1569
              (statement::CreateTable *)Lex->statement;
 
1570
 
 
1571
            if (statement->current_proto_field)
 
1572
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
 
1573
          }
 
1574
          | DATETIME_SYM
1237
1575
          {
1238
1576
            $$=DRIZZLE_TYPE_DATETIME;
1239
1577
 
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 ')'
 
1578
            statement::CreateTable *statement=
 
1579
              (statement::CreateTable *)Lex->statement;
 
1580
 
 
1581
            if (statement->current_proto_field)
 
1582
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1583
          }
 
1584
          | BLOB_SYM
 
1585
            {
 
1586
              Lex->charset=&my_charset_bin;
 
1587
              $$=DRIZZLE_TYPE_BLOB;
 
1588
              Lex->length=(char*) 0; /* use default length */
 
1589
 
 
1590
            statement::CreateTable *statement=
 
1591
              (statement::CreateTable *)Lex->statement;
 
1592
 
 
1593
            if (statement->current_proto_field)
 
1594
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1595
            }
 
1596
          | TEXT_SYM
 
1597
            {
 
1598
              $$=DRIZZLE_TYPE_BLOB;
 
1599
              Lex->length=(char*) 0; /* use default length */
 
1600
 
 
1601
            statement::CreateTable *statement=
 
1602
              (statement::CreateTable *)Lex->statement;
 
1603
 
 
1604
            if (statement->current_proto_field)
 
1605
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1606
            }
 
1607
          | DECIMAL_SYM float_options
 
1608
          {
 
1609
            $$=DRIZZLE_TYPE_DECIMAL;
 
1610
 
 
1611
            statement::CreateTable *statement=
 
1612
              (statement::CreateTable *)Lex->statement;
 
1613
 
 
1614
            if (statement->current_proto_field)
 
1615
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1616
          }
 
1617
          | NUMERIC_SYM float_options
 
1618
          {
 
1619
            $$=DRIZZLE_TYPE_DECIMAL;
 
1620
 
 
1621
            statement::CreateTable *statement=
 
1622
              (statement::CreateTable *)Lex->statement;
 
1623
 
 
1624
            if (statement->current_proto_field)
 
1625
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1626
          }
 
1627
          | FIXED_SYM float_options
 
1628
          {
 
1629
            $$=DRIZZLE_TYPE_DECIMAL;
 
1630
 
 
1631
            statement::CreateTable *statement=
 
1632
              (statement::CreateTable *)Lex->statement;
 
1633
 
 
1634
            if (statement->current_proto_field)
 
1635
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1636
          }
 
1637
          | ENUM_SYM
 
1638
            {Lex->interval_list.empty();}
 
1639
            '(' string_list ')'
1272
1640
          {
1273
1641
            $$=DRIZZLE_TYPE_ENUM;
1274
1642
 
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);
 
1643
            statement::CreateTable *statement=
 
1644
              (statement::CreateTable *)Lex->statement;
 
1645
 
 
1646
            if (statement->current_proto_field)
 
1647
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1285
1648
          }
1286
1649
        | SERIAL_SYM
1287
1650
          {
1288
 
            $$= parser::buildSerialColumn(Lex);
 
1651
            $$=DRIZZLE_TYPE_LONGLONG;
 
1652
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1653
 
 
1654
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1655
            if (statement->current_proto_field)
 
1656
            {
 
1657
              message::Table::Field::FieldConstraints *constraints;
 
1658
              constraints= statement->current_proto_field->mutable_constraints();
 
1659
              constraints->set_is_nullable(false);
 
1660
 
 
1661
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1662
            }
1289
1663
          }
1290
1664
        ;
1291
1665
 
1299
1673
        ;
1300
1674
 
1301
1675
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
 
          }
 
1676
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1677
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1314
1678
        ;
1315
1679
 
1316
1680
real_type:
1319
1683
            $$= DRIZZLE_TYPE_DOUBLE;
1320
1684
          }
1321
1685
        | DOUBLE_SYM
1322
 
          {
1323
 
            $$= DRIZZLE_TYPE_DOUBLE;
1324
 
          }
 
1686
          { $$=DRIZZLE_TYPE_DOUBLE; }
1325
1687
        | DOUBLE_SYM PRECISION
1326
 
          {
1327
 
            $$= DRIZZLE_TYPE_DOUBLE;
1328
 
          }
 
1688
          { $$=DRIZZLE_TYPE_DOUBLE; }
1329
1689
        ;
1330
1690
 
1331
1691
float_options:
1340
1700
precision:
1341
1701
          '(' NUM ',' NUM ')'
1342
1702
          {
1343
 
            Lex->length= $2.str;
1344
 
            Lex->dec= $4.str;
 
1703
            LEX *lex=Lex;
 
1704
            lex->length=$2.str;
 
1705
            lex->dec=$4.str;
1345
1706
          }
1346
1707
        ;
1347
1708
 
1350
1711
        | '(' NUM ')' { Lex->length= $2.str; }
1351
1712
        ;
1352
1713
 
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
1714
opt_precision:
1370
 
          /* empty */
1371
 
          { Lex->dec=Lex->length= (char*)0; }
1372
 
        | '(' NUM ')'
1373
 
          { Lex->length=Lex->dec= (char*)0; }
1374
 
        | precision
1375
 
          {}
 
1715
          /* empty */ {}
 
1716
        | precision {}
1376
1717
        ;
1377
1718
 
1378
1719
opt_attribute:
1388
1729
attribute:
1389
1730
          NULL_SYM
1390
1731
          {
 
1732
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1391
1733
            Lex->type&= ~ NOT_NULL_FLAG;
 
1734
 
 
1735
            if (statement->current_proto_field)
 
1736
            {
 
1737
              message::Table::Field::FieldConstraints *constraints;
 
1738
              constraints= statement->current_proto_field->mutable_constraints();
 
1739
              constraints->set_is_nullable(true);
 
1740
            }
 
1741
          }
 
1742
        | COLUMN_FORMAT_SYM column_format_types
 
1743
          {
 
1744
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1745
 
 
1746
            statement->column_format= $2;
 
1747
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1392
1748
          }
1393
1749
        | not NULL_SYM
1394
1750
          {
 
1751
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1395
1752
            Lex->type|= NOT_NULL_FLAG;
1396
1753
 
1397
 
            if (Lex->field())
 
1754
            if (statement->current_proto_field)
1398
1755
            {
1399
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1756
              message::Table::Field::FieldConstraints *constraints;
 
1757
              constraints= statement->current_proto_field->mutable_constraints();
 
1758
              constraints->set_is_nullable(false);
1400
1759
            }
1401
1760
          }
1402
1761
        | DEFAULT now_or_signed_literal
1407
1766
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1408
1767
          }
1409
1768
        | ON UPDATE_SYM NOW_SYM optional_braces
1410
 
          {
1411
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1412
 
          }
 
1769
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1413
1770
        | AUTO_INC
1414
1771
          {
1415
 
            parser::buildAutoOnColumn(Lex);
 
1772
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1773
 
 
1774
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1775
            if (statement->current_proto_field)
 
1776
            {
 
1777
              message::Table::Field::FieldConstraints *constraints;
 
1778
 
 
1779
              constraints= statement->current_proto_field->mutable_constraints();
 
1780
              constraints->set_is_nullable(false);
 
1781
            }
1416
1782
          }
1417
1783
        | SERIAL_SYM DEFAULT VALUE_SYM
1418
1784
          {
1419
 
            (void)parser::buildSerialColumn(Lex);
 
1785
            LEX *lex=Lex;
 
1786
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1787
 
 
1788
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1789
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1790
 
 
1791
            if (statement->current_proto_field)
 
1792
            {
 
1793
              message::Table::Field::FieldConstraints *constraints;
 
1794
              constraints= statement->current_proto_field->mutable_constraints();
 
1795
              constraints->set_is_nullable(false);
 
1796
            }
1420
1797
          }
1421
1798
        | opt_primary KEY_SYM
1422
1799
          {
1423
 
            parser::buildPrimaryOnColumn(Lex);
 
1800
            LEX *lex=Lex;
 
1801
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1802
 
 
1803
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1804
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1805
 
 
1806
            if (statement->current_proto_field)
 
1807
            {
 
1808
              message::Table::Field::FieldConstraints *constraints;
 
1809
              constraints= statement->current_proto_field->mutable_constraints();
 
1810
              constraints->set_is_nullable(false);
 
1811
            }
1424
1812
          }
1425
1813
        | UNIQUE_SYM
1426
1814
          {
1427
 
            parser::buildKeyOnColumn(Lex);
 
1815
            LEX *lex=Lex;
 
1816
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1817
 
 
1818
            lex->type|= UNIQUE_FLAG;
 
1819
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1428
1820
          }
1429
1821
        | UNIQUE_SYM KEY_SYM
1430
1822
          {
1431
 
            parser::buildKeyOnColumn(Lex);
 
1823
            LEX *lex=Lex;
 
1824
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1825
 
 
1826
            lex->type|= UNIQUE_KEY_FLAG;
 
1827
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1432
1828
          }
1433
1829
        | COMMENT_SYM TEXT_STRING_sys
1434
1830
          {
1435
1831
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1436
1832
            statement->comment= $2;
1437
1833
 
1438
 
            if (Lex->field())
1439
 
              Lex->field()->set_comment($2.str);
 
1834
            if (statement->current_proto_field)
 
1835
              statement->current_proto_field->set_comment($2.str);
1440
1836
          }
1441
1837
        | COLLATE_SYM collation_name
1442
1838
          {
1487
1883
        ;
1488
1884
 
1489
1885
references:
1490
 
          REFERENCES table_ident opt_ref_list opt_match_clause opt_on_update_delete
 
1886
          REFERENCES
 
1887
          table_ident
 
1888
          opt_ref_list
 
1889
          opt_match_clause
 
1890
          opt_on_update_delete
1491
1891
          {
1492
1892
            $$=$2;
1493
1893
          }
1495
1895
 
1496
1896
opt_ref_list:
1497
1897
          /* empty */
1498
 
          { Lex->ref_list.clear(); }
 
1898
          { Lex->ref_list.empty(); }
1499
1899
        | '(' ref_list ')'
1500
1900
        ;
1501
1901
 
1504
1904
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1505
1905
        | ident
1506
1906
          {
1507
 
            Lex->ref_list.clear();
1508
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1907
            LEX *lex= Lex;
 
1908
            lex->ref_list.empty();
 
1909
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1509
1910
          }
1510
1911
        ;
1511
1912
 
1512
1913
opt_match_clause:
1513
1914
          /* empty */
1514
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
 
1915
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
1515
1916
        | MATCH FULL
1516
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
 
1917
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
1517
1918
        | MATCH PARTIAL
1518
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
 
1919
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
1519
1920
        | MATCH SIMPLE_SYM
1520
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
 
1921
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
1521
1922
        ;
1522
1923
 
1523
1924
opt_on_update_delete:
1524
1925
          /* empty */
1525
1926
          {
1526
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1527
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1927
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1928
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1528
1929
          }
1529
1930
        | ON UPDATE_SYM delete_option
1530
1931
          {
1531
1932
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1532
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1933
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1533
1934
          }
1534
1935
        | ON DELETE_SYM delete_option
1535
1936
          {
1536
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1937
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1537
1938
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1538
1939
          }
1539
1940
        | ON UPDATE_SYM delete_option
1551
1952
        ;
1552
1953
 
1553
1954
delete_option:
1554
 
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1555
 
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1556
 
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1557
 
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1558
 
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
 
1955
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
 
1956
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
 
1957
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
 
1958
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
 
1959
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
1559
1960
        ;
1560
1961
 
1561
1962
key_type:
1595
1996
        ;
1596
1997
 
1597
1998
/*
1598
 
  For now, key_alg initializies Lex->key_create_info.
 
1999
  For now, key_alg initializies lex->key_create_info.
1599
2000
  In the future, when all key options are after key definition,
1600
2001
  we can remove key_alg and move init_key_options to key_options
1601
2002
*/
1617
2018
 
1618
2019
key_using_alg:
1619
2020
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2021
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1620
2022
        ;
1621
2023
 
1622
2024
key_opt:
1669
2071
*/
1670
2072
 
1671
2073
alter:
1672
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2074
          ALTER build_method opt_ignore TABLE_SYM table_ident
1673
2075
          {
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());
 
2076
            Session *session= YYSession;
 
2077
            LEX *lex= session->lex;
 
2078
            lex->name.str= 0;
 
2079
            lex->name.length= 0;
 
2080
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2081
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2082
            lex->statement= statement;
 
2083
            if (lex->statement == NULL)
 
2084
              DRIZZLE_YYABORT;
 
2085
            lex->duplicates= DUP_ERROR;
 
2086
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2087
                                                   TL_OPTION_UPDATING))
 
2088
              DRIZZLE_YYABORT;
 
2089
            lex->col_list.empty();
 
2090
            lex->select_lex.init_order();
 
2091
            lex->select_lex.db=
 
2092
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2093
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
 
2094
            statement->alter_info.build_method= $2;
1685
2095
          }
1686
2096
          alter_commands
1687
2097
          {}
1688
 
        | ALTER_SYM DATABASE schema_name
 
2098
        | ALTER DATABASE ident_or_empty
1689
2099
          {
1690
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2100
            LEX *lex=Lex;
 
2101
            lex->sql_command=SQLCOM_ALTER_DB;
 
2102
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2103
            if (lex->statement == NULL)
 
2104
              DRIZZLE_YYABORT;
1691
2105
          }
1692
2106
          default_collation_schema
1693
2107
          {
1694
 
            Lex->name= $3;
1695
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2108
            LEX *lex=Lex;
 
2109
            lex->name= $3;
 
2110
            if (lex->name.str == NULL &&
 
2111
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1696
2112
              DRIZZLE_YYABORT;
1697
2113
          }
1698
2114
        ;
1699
2115
 
 
2116
ident_or_empty:
 
2117
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2118
        | ident { $$= $1; }
 
2119
        ;
 
2120
 
1700
2121
alter_commands:
1701
2122
          /* empty */
1702
2123
        | DISCARD TABLESPACE
1733
2154
        ;
1734
2155
 
1735
2156
add_column:
1736
 
          ADD_SYM opt_column
 
2157
          ADD opt_column
1737
2158
          {
1738
2159
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
2160
 
1744
2165
 
1745
2166
alter_list_item:
1746
2167
          add_column column_def opt_place { }
1747
 
        | ADD_SYM key_def
 
2168
        | ADD key_def
1748
2169
          {
1749
2170
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1750
2171
 
1757
2178
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1758
2179
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1759
2180
          }
1760
 
        | CHANGE_SYM opt_column field_ident
 
2181
        | CHANGE opt_column field_ident
1761
2182
          {
1762
2183
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1763
2184
            statement->change= $3.str;
1766
2187
          field_spec opt_place
1767
2188
        | MODIFY_SYM opt_column field_ident
1768
2189
          {
 
2190
            LEX *lex=Lex;
1769
2191
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1770
 
            Lex->length= Lex->dec=0;
1771
 
            Lex->type= 0;
 
2192
            lex->length=lex->dec=0; lex->type=0;
1772
2193
            statement->default_value= statement->on_update_value= 0;
1773
2194
            statement->comment= null_lex_str;
1774
 
            Lex->charset= NULL;
 
2195
            lex->charset= NULL;
1775
2196
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1776
2197
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1777
2198
 
1778
 
            Lex->setField(NULL);
 
2199
            statement->current_proto_field= NULL;
1779
2200
          }
1780
2201
          field_def
1781
2202
          {
 
2203
            LEX *lex=Lex;
1782
2204
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1783
2205
 
1784
 
            if (add_field_to_list(Lex->session,&$3,
 
2206
            if (add_field_to_list(lex->session,&$3,
1785
2207
                                  (enum enum_field_types) $5,
1786
 
                                  Lex->length, Lex->dec, Lex->type,
 
2208
                                  lex->length, lex->dec, lex->type,
1787
2209
                                  statement->column_format,
1788
2210
                                  statement->default_value,
1789
2211
                                  statement->on_update_value,
1790
2212
                                  &statement->comment,
1791
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2213
                                  $3.str, &lex->interval_list, lex->charset))
1792
2214
              DRIZZLE_YYABORT;
1793
2215
          }
1794
2216
          opt_place
1801
2223
          }
1802
2224
        | DROP FOREIGN KEY_SYM opt_ident
1803
2225
          {
1804
 
            parser::buildAddAlterDropIndex(Lex, $4.str, true);
 
2226
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2227
 
 
2228
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2229
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1805
2230
          }
1806
2231
        | DROP PRIMARY_SYM KEY_SYM
1807
2232
          {
1808
 
            parser::buildAddAlterDropIndex(Lex, "PRIMARY");
 
2233
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2234
 
 
2235
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2236
                                                               "PRIMARY"));
 
2237
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1809
2238
          }
1810
2239
        | DROP key_or_index field_ident
1811
2240
          {
1812
 
            parser::buildAddAlterDropIndex(Lex, $3.str);
 
2241
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2242
 
 
2243
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2244
                                                                    $3.str));
 
2245
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1813
2246
          }
1814
2247
        | DISABLE_SYM KEYS
1815
2248
          {
1825
2258
            statement->alter_info.keys_onoff= ENABLE;
1826
2259
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1827
2260
          }
1828
 
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
 
2261
        | ALTER opt_column field_ident SET DEFAULT signed_literal
1829
2262
          {
1830
2263
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1831
2264
 
1832
2265
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
1833
2266
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1834
2267
          }
1835
 
        | ALTER_SYM opt_column field_ident DROP DEFAULT
 
2268
        | ALTER opt_column field_ident DROP DEFAULT
1836
2269
          {
1837
2270
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1838
2271
 
1841
2274
          }
1842
2275
        | RENAME opt_to table_ident
1843
2276
          {
 
2277
            LEX *lex=Lex;
1844
2278
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1845
2279
            size_t dummy;
1846
2280
 
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))
 
2281
            lex->select_lex.db=$3->db.str;
 
2282
            if (lex->select_lex.db == NULL &&
 
2283
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1850
2284
            {
1851
2285
              DRIZZLE_YYABORT;
1852
2286
            }
1857
2291
              DRIZZLE_YYABORT;
1858
2292
            }
1859
2293
 
1860
 
            Lex->name= $3->table;
 
2294
            lex->name= $3->table;
1861
2295
            statement->alter_info.flags.set(ALTER_RENAME);
1862
2296
          }
1863
2297
        | CONVERT_SYM TO_SYM collation_name_or_default
1864
2298
          {
1865
2299
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1866
2300
 
1867
 
            statement->create_info().table_charset=
1868
 
            statement->create_info().default_table_charset= $3;
1869
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2301
            statement->create_info.table_charset=
 
2302
            statement->create_info.default_table_charset= $3;
 
2303
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1870
2304
              HA_CREATE_USED_DEFAULT_CHARSET);
1871
2305
            statement->alter_info.flags.set(ALTER_CONVERT);
1872
2306
          }
1904
2338
          /* empty */ {}
1905
2339
        | AFTER_SYM ident
1906
2340
          {
1907
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2341
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2342
 
 
2343
            store_position_for_column($2.str);
 
2344
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1908
2345
          }
1909
2346
        | FIRST_SYM
1910
2347
          {
1911
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2348
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2349
 
 
2350
            store_position_for_column(first_keyword);
 
2351
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1912
2352
          }
1913
2353
        ;
1914
2354
 
1915
2355
opt_to:
1916
2356
          /* empty */ {}
1917
2357
        | TO_SYM {}
 
2358
        | EQ {}
1918
2359
        | AS {}
1919
2360
        ;
1920
2361
 
1921
2362
start:
1922
2363
          START_SYM TRANSACTION_SYM start_transaction_opts
1923
2364
          {
1924
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2365
            LEX *lex= Lex;
 
2366
            lex->sql_command= SQLCOM_BEGIN;
 
2367
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2368
            if (lex->statement == NULL)
 
2369
              DRIZZLE_YYABORT;
1925
2370
          }
1926
2371
        ;
1927
2372
 
1933
2378
          }
1934
2379
        ;
1935
2380
 
 
2381
 
 
2382
checksum:
 
2383
          CHECKSUM_SYM table_or_tables
 
2384
          {
 
2385
            LEX *lex=Lex;
 
2386
            lex->sql_command = SQLCOM_CHECKSUM;
 
2387
            lex->statement= new(std::nothrow) statement::Checksum(YYSession);
 
2388
            if (lex->statement == NULL)
 
2389
              DRIZZLE_YYABORT;
 
2390
          }
 
2391
          table_list
 
2392
          {}
 
2393
        ;
 
2394
 
 
2395
 
1936
2396
analyze:
1937
2397
          ANALYZE_SYM table_or_tables
1938
2398
          {
1939
 
            Lex->statement= new statement::Analyze(YYSession);
 
2399
            LEX *lex=Lex;
 
2400
            lex->sql_command = SQLCOM_ANALYZE;
 
2401
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2402
            if (lex->statement == NULL)
 
2403
              DRIZZLE_YYABORT;
1940
2404
          }
1941
2405
          table_list
1942
2406
          {}
1945
2409
check:
1946
2410
          CHECK_SYM table_or_tables
1947
2411
          {
1948
 
            Lex->statement= new statement::Check(YYSession);
 
2412
            LEX *lex=Lex;
 
2413
 
 
2414
            lex->sql_command = SQLCOM_CHECK;
 
2415
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2416
            if (lex->statement == NULL)
 
2417
              DRIZZLE_YYABORT;
1949
2418
          }
1950
2419
          table_list
1951
2420
          {}
1954
2423
rename:
1955
2424
          RENAME table_or_tables
1956
2425
          {
1957
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2426
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2427
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2428
            if (Lex->statement == NULL)
 
2429
              DRIZZLE_YYABORT;
1958
2430
          }
1959
2431
          table_to_table_list
1960
2432
          {}
1968
2440
table_to_table:
1969
2441
          table_ident TO_SYM table_ident
1970
2442
          {
1971
 
            Select_Lex *sl= Lex->current_select;
1972
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2443
            LEX *lex=Lex;
 
2444
            Select_Lex *sl= lex->current_select;
 
2445
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1973
2446
                                       TL_IGNORE) ||
1974
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2447
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1975
2448
                                       TL_IGNORE))
1976
2449
              DRIZZLE_YYABORT;
1977
2450
          }
1985
2458
select:
1986
2459
          select_init
1987
2460
          {
1988
 
            Lex->statement= new statement::Select(YYSession);
 
2461
            LEX *lex= Lex;
 
2462
            lex->sql_command= SQLCOM_SELECT;
 
2463
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2464
            if (lex->statement == NULL)
 
2465
              DRIZZLE_YYABORT;
1989
2466
          }
1990
2467
        ;
1991
2468
 
1998
2475
select_paren:
1999
2476
          SELECT_SYM select_part2
2000
2477
          {
2001
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2478
            if (setup_select_in_parentheses(Lex))
2002
2479
              DRIZZLE_YYABORT;
2003
2480
          }
2004
2481
        | '(' select_paren ')'
2008
2485
select_paren_derived:
2009
2486
          SELECT_SYM select_part2_derived
2010
2487
          {
2011
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2488
            if (setup_select_in_parentheses(Lex))
2012
2489
              DRIZZLE_YYABORT;
2013
2490
          }
2014
2491
        | '(' select_paren_derived ')'
2017
2494
select_init2:
2018
2495
          select_part2
2019
2496
          {
2020
 
            Select_Lex * sel= Lex->current_select;
2021
 
            if (Lex->current_select->set_braces(0))
 
2497
            LEX *lex= Lex;
 
2498
            Select_Lex * sel= lex->current_select;
 
2499
            if (lex->current_select->set_braces(0))
2022
2500
            {
2023
 
              parser::my_parse_error(YYSession->m_lip);
 
2501
              my_parse_error(ER(ER_SYNTAX_ERROR));
2024
2502
              DRIZZLE_YYABORT;
2025
2503
            }
2026
2504
            if (sel->linkage == UNION_TYPE &&
2027
2505
                sel->master_unit()->first_select()->braces)
2028
2506
            {
2029
 
              parser::my_parse_error(YYSession->m_lip);
 
2507
              my_parse_error(ER(ER_SYNTAX_ERROR));
2030
2508
              DRIZZLE_YYABORT;
2031
2509
            }
2032
2510
          }
2035
2513
 
2036
2514
select_part2:
2037
2515
          {
2038
 
            Select_Lex *sel= Lex->current_select;
 
2516
            LEX *lex= Lex;
 
2517
            Select_Lex *sel= lex->current_select;
2039
2518
            if (sel->linkage != UNION_TYPE)
2040
 
              init_select(Lex);
2041
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2519
              mysql_init_select(lex);
 
2520
            lex->current_select->parsing_place= SELECT_LIST;
2042
2521
          }
2043
2522
          select_options select_item_list
2044
2523
          {
2068
2547
select_options:
2069
2548
          /* empty*/
2070
2549
        | select_option_list
2071
 
          { }
 
2550
          {
 
2551
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2552
                Lex->current_select->options & SELECT_ALL)
 
2553
            {
 
2554
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2555
              DRIZZLE_YYABORT;
 
2556
            }
 
2557
          }
2072
2558
        ;
2073
2559
 
2074
2560
select_option_list:
2076
2562
        | select_option
2077
2563
        ;
2078
2564
 
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
2565
select_option:
2127
2566
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2567
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2568
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2569
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2128
2570
        | SQL_BUFFER_RESULT
2129
2571
          {
2130
 
            if (check_simple_select(YYSession))
 
2572
            if (check_simple_select())
2131
2573
              DRIZZLE_YYABORT;
2132
2574
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2133
2575
          }
2134
 
        | select_option_small_or_big
2135
 
          { }
2136
 
        | select_option_distinct_or_all
2137
 
          { }
2138
2576
        | SQL_CALC_FOUND_ROWS
2139
2577
          {
2140
 
            if (check_simple_select(YYSession))
 
2578
            if (check_simple_select())
2141
2579
              DRIZZLE_YYABORT;
2142
2580
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2143
2581
          }
 
2582
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2144
2583
        ;
2145
2584
 
2146
2585
select_lock_type:
2147
2586
          /* empty */
2148
2587
        | FOR_SYM UPDATE_SYM
2149
2588
          {
2150
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2589
            LEX *lex=Lex;
 
2590
            lex->current_select->set_lock_for_tables(TL_WRITE);
2151
2591
          }
2152
2592
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2153
2593
          {
2154
 
            Lex->current_select->
 
2594
            LEX *lex=Lex;
 
2595
            lex->current_select->
2155
2596
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2156
2597
          }
2157
2598
        ;
2161
2602
        | select_item
2162
2603
        | '*'
2163
2604
          {
2164
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->getLex()->current_select->context, NULL, NULL, "*")))
 
2605
            Session *session= YYSession;
 
2606
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2607
                                                          context,
 
2608
                                                          NULL, NULL, "*")))
2165
2609
              DRIZZLE_YYABORT;
2166
 
 
2167
 
            (YYSession->getLex()->current_select->with_wild)++;
 
2610
            (session->lex->current_select->with_wild)++;
2168
2611
          }
2169
2612
        ;
2170
2613
 
2171
2614
select_item:
2172
2615
          remember_name table_wild remember_end
2173
2616
          {
2174
 
            if (YYSession->add_item_to_list($2))
 
2617
            Session *session= YYSession;
 
2618
 
 
2619
            if (session->add_item_to_list($2))
2175
2620
              DRIZZLE_YYABORT;
2176
2621
          }
2177
2622
        | remember_name expr remember_end select_alias
2178
2623
          {
 
2624
            Session *session= YYSession;
2179
2625
            assert($1 < $3);
2180
2626
 
2181
 
            if (YYSession->add_item_to_list($2))
 
2627
            if (session->add_item_to_list($2))
2182
2628
              DRIZZLE_YYABORT;
2183
 
 
2184
2629
            if ($4.str)
2185
2630
            {
2186
2631
              $2->is_autogenerated_name= false;
2188
2633
            }
2189
2634
            else if (!$2->name)
2190
2635
            {
2191
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2636
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2192
2637
            }
2193
2638
          }
2194
2639
        ;
2195
2640
 
2196
2641
remember_name:
2197
2642
          {
2198
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2643
            Session *session= YYSession;
 
2644
            Lex_input_stream *lip= session->m_lip;
2199
2645
            $$= (char*) lip->get_cpp_tok_start();
2200
2646
          }
2201
2647
        ;
2202
2648
 
2203
2649
remember_end:
2204
2650
          {
2205
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2651
            Session *session= YYSession;
 
2652
            Lex_input_stream *lip= session->m_lip;
2206
2653
            $$= (char*) lip->get_cpp_tok_end();
2207
2654
          }
2208
2655
        ;
2341
2788
          { $$= new Item_func_isnotnull($1); }
2342
2789
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
2343
2790
          { $$= new Item_func_equal($1,$3); }
2344
 
        | bool_pri comp_op predicate %prec '='
 
2791
        | bool_pri comp_op predicate %prec EQ
2345
2792
          { $$= (*$2)(0)->create($1,$3); }
2346
 
        | bool_pri comp_op all_or_any '(' subselect ')' %prec '='
 
2793
        | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
2347
2794
          { $$= all_any_subquery_creator($1, $2, $3, $5); }
2348
2795
        | predicate
2349
2796
        ;
2355
2802
          }
2356
2803
        | bit_expr not IN_SYM '(' subselect ')'
2357
2804
          {
2358
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2359
 
            $$= negate_expression(YYSession, item);
 
2805
            Session *session= YYSession;
 
2806
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2807
            $$= negate_expression(session, item);
2360
2808
          }
2361
2809
        | bit_expr IN_SYM '(' expr ')'
2362
2810
          {
2363
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2811
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2364
2812
          }
2365
2813
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2366
2814
          {
2370
2818
          }
2371
2819
        | bit_expr not IN_SYM '(' expr ')'
2372
2820
          {
2373
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2821
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2374
2822
          }
2375
2823
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2376
2824
          {
2381
2829
            $$= item;
2382
2830
          }
2383
2831
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2384
 
          {
2385
 
            $$= new Item_func_between($1,$3,$5);
2386
 
          }
 
2832
          { $$= new Item_func_between($1,$3,$5); }
2387
2833
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2388
2834
          {
2389
2835
            Item_func_between *item= new Item_func_between($1,$4,$6);
2391
2837
            $$= item;
2392
2838
          }
2393
2839
        | bit_expr LIKE simple_expr opt_escape
2394
 
          { 
2395
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
2396
 
          }
 
2840
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2397
2841
        | 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
 
          }
 
2842
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2422
2843
        | bit_expr
2423
2844
        ;
2424
2845
 
2434
2855
        | bit_expr '*' bit_expr %prec '*'
2435
2856
          { $$= new Item_func_mul($1,$3); }
2436
2857
        | bit_expr '/' bit_expr %prec '/'
2437
 
          { $$= new Item_func_div(YYSession,$1,$3); }
 
2858
          { $$= new Item_func_div($1,$3); }
2438
2859
        | bit_expr '%' bit_expr %prec '%'
2439
2860
          { $$= new Item_func_mod($1,$3); }
2440
2861
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2457
2878
        ;
2458
2879
 
2459
2880
comp_op:
2460
 
          '='     { $$ = &comp_eq_creator; }
 
2881
          EQ     { $$ = &comp_eq_creator; }
2461
2882
        | GE     { $$ = &comp_ge_creator; }
2462
 
        | '>' { $$ = &comp_gt_creator; }
 
2883
        | GT_SYM { $$ = &comp_gt_creator; }
2463
2884
        | LE     { $$ = &comp_le_creator; }
2464
 
        | '<'     { $$ = &comp_lt_creator; }
 
2885
        | LT     { $$ = &comp_lt_creator; }
2465
2886
        | NE     { $$ = &comp_ne_creator; }
2466
2887
        ;
2467
2888
 
2476
2897
        | function_call_nonkeyword
2477
2898
        | function_call_generic
2478
2899
        | function_call_conflict
2479
 
        | simple_expr COLLATE_SYM ident_or_text %prec UMINUS
 
2900
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2480
2901
          {
2481
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
2902
            Session *session= YYSession;
 
2903
            Item *i1= new (session->mem_root) Item_string($3.str,
2482
2904
                                                      $3.length,
2483
 
                                                      YYSession->charset());
2484
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
2905
                                                      session->charset());
 
2906
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2485
2907
          }
2486
2908
        | literal
2487
2909
        | variable
2488
2910
        | sum_expr
2489
 
          {
2490
 
            Lex->setSumExprUsed();
2491
 
          }
2492
 
        | '+' simple_expr %prec UMINUS { $$= $2; }
2493
 
        | '-' simple_expr %prec UMINUS
 
2911
        | '+' simple_expr %prec NEG { $$= $2; }
 
2912
        | '-' simple_expr %prec NEG
2494
2913
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2495
2914
        | '(' subselect ')'
2496
2915
          {
2512
2931
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
2513
2932
          }
2514
2933
        | '{' ident expr '}' { $$= $3; }
2515
 
        | BINARY simple_expr %prec UMINUS
 
2934
        | BINARY simple_expr %prec NEG
2516
2935
          {
2517
2936
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
2518
2937
                                 &my_charset_bin);
2519
2938
          }
2520
2939
        | CAST_SYM '(' expr AS cast_type ')'
2521
2940
          {
2522
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2523
 
                                 Lex->charset);
 
2941
            LEX *lex= Lex;
 
2942
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
2943
                                 lex->charset);
2524
2944
            if (!$$)
2525
2945
              DRIZZLE_YYABORT;
2526
2946
          }
2538
2958
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2539
2959
                                                         $3);
2540
2960
          }
2541
 
        | VALUES '(' simple_ident ')'
 
2961
        | VALUES '(' simple_ident_nospvar ')'
2542
2962
          {
2543
2963
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2544
2964
                                                        $3);
2559
2979
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
2560
2980
        | CURRENT_USER optional_braces
2561
2981
          {
2562
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
2563
 
            {
2564
 
              DRIZZLE_YYABORT;
2565
 
            }
2566
 
            Lex->setCacheable(false);
 
2982
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
2567
2983
          }
2568
2984
        | DATE_SYM '(' expr ')'
2569
2985
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
2572
2988
        | HOUR_SYM '(' expr ')'
2573
2989
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
2574
2990
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
2575
 
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
 
2991
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
2576
2992
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2577
2993
          {
2578
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
2994
            Session *session= YYSession;
 
2995
            List<Item> *list= new (session->mem_root) List<Item>;
2579
2996
            list->push_front($5);
2580
2997
            list->push_front($3);
2581
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2582
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
2998
            Item_row *item= new (session->mem_root) Item_row(*list);
 
2999
            $$= new (session->mem_root) Item_func_interval(item);
2583
3000
          }
2584
3001
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2585
3002
          {
 
3003
            Session *session= YYSession;
2586
3004
            $7->push_front($5);
2587
3005
            $7->push_front($3);
2588
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2589
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3006
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3007
            $$= new (session->mem_root) Item_func_interval(item);
2590
3008
          }
2591
3009
        | LEFT '(' expr ',' expr ')'
2592
3010
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2618
3036
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2619
3037
        | USER '(' ')'
2620
3038
          {
2621
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
2622
 
            {
2623
 
              DRIZZLE_YYABORT;
2624
 
            }
2625
 
            Lex->setCacheable(false);
 
3039
            $$= new (YYSession->mem_root) Item_func_user();
2626
3040
          }
2627
3041
        | YEAR_SYM '(' expr ')'
2628
3042
          { $$= new (YYSession->mem_root) Item_func_year($3); }
2650
3064
        | CURDATE optional_braces
2651
3065
          {
2652
3066
            $$= new (YYSession->mem_root) Item_func_curdate_local();
2653
 
            Lex->setCacheable(false);
2654
3067
          }
2655
3068
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
2656
3069
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
2661
3074
        | NOW_SYM optional_braces
2662
3075
          {
2663
3076
            $$= new (YYSession->mem_root) Item_func_now_local();
2664
 
            Lex->setCacheable(false);
2665
3077
          }
2666
3078
        | NOW_SYM '(' expr ')'
2667
3079
          {
2668
3080
            $$= new (YYSession->mem_root) Item_func_now_local($3);
2669
 
            Lex->setCacheable(false);
2670
3081
          }
2671
3082
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
2672
3083
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
2679
3090
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2680
3091
        | SUBSTRING '(' expr ',' expr ',' expr ')'
2681
3092
          {
 
3093
            std::string reverse_str("substr");
2682
3094
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2683
3095
            args->push_back($3);
2684
3096
            args->push_back($5);
2685
3097
            args->push_back($7);
2686
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3098
            if (! ($$= reserved_keyword_function(reverse_str, args)))
2687
3099
            {
2688
3100
              DRIZZLE_YYABORT;
2689
3101
            }
2690
3102
          }
2691
3103
        | SUBSTRING '(' expr ',' expr ')'
2692
3104
          {
 
3105
            std::string reverse_str("substr");
2693
3106
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2694
3107
            args->push_back($3);
2695
3108
            args->push_back($5);
2696
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3109
            if (! ($$= reserved_keyword_function(reverse_str, args)))
2697
3110
            {
2698
3111
              DRIZZLE_YYABORT;
2699
3112
            }
2700
3113
          }
2701
3114
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
2702
3115
          {
 
3116
            std::string reverse_str("substr");
2703
3117
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2704
3118
            args->push_back($3);
2705
3119
            args->push_back($5);
2706
3120
            args->push_back($7);
2707
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3121
            if (! ($$= reserved_keyword_function(reverse_str, args)))
2708
3122
            {
2709
3123
              DRIZZLE_YYABORT;
2710
3124
            }
2711
3125
          }
2712
3126
        | SUBSTRING '(' expr FROM expr ')'
2713
3127
          {
 
3128
            std::string reverse_str("substr");
2714
3129
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2715
3130
            args->push_back($3);
2716
3131
            args->push_back($5);
2717
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3132
            if (! ($$= reserved_keyword_function(reverse_str, args)))
2718
3133
            {
2719
3134
              DRIZZLE_YYABORT;
2720
3135
            }
2721
3136
          }
2722
3137
        | SYSDATE optional_braces
2723
 
          { 
2724
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
2725
 
            Lex->setCacheable(false);
2726
 
          }
 
3138
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
2727
3139
        | SYSDATE '(' expr ')'
2728
 
          { 
2729
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
2730
 
            Lex->setCacheable(false);
2731
 
          }
 
3140
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
2732
3141
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
2733
3142
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
2734
3143
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
2736
3145
        | UTC_DATE_SYM optional_braces
2737
3146
          {
2738
3147
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
2739
 
            Lex->setCacheable(false);
2740
3148
          }
2741
3149
        | UTC_TIMESTAMP_SYM optional_braces
2742
3150
          {
2743
3151
            $$= new (YYSession->mem_root) Item_func_now_utc();
2744
 
            Lex->setCacheable(false);
2745
3152
          }
2746
3153
        ;
2747
3154
 
2757
3164
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2758
3165
        | DATABASE '(' ')'
2759
3166
          {
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
 
          }
 
3167
            std::string database_str("database");
 
3168
            if (! ($$= reserved_keyword_function(database_str, NULL)))
 
3169
            {
 
3170
              DRIZZLE_YYABORT;
 
3171
            }
 
3172
          }
2789
3173
        | IF '(' expr ',' expr ',' expr ')'
2790
3174
          { $$= 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
3175
        | MICROSECOND_SYM '(' expr ')'
2807
3176
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
2808
3177
        | MOD_SYM '(' expr ',' expr ')'
2810
3179
        | QUARTER_SYM '(' expr ')'
2811
3180
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
2812
3181
        | REPEAT_SYM '(' expr ',' expr ')'
2813
 
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
 
3182
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
2814
3183
        | REPLACE '(' expr ',' expr ',' expr ')'
2815
 
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3184
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
 
3185
        | REVERSE_SYM '(' expr ')'
 
3186
          {
 
3187
            std::string reverse_str("reverse");
 
3188
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3189
            args->push_back($3);
 
3190
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3191
            {
 
3192
              DRIZZLE_YYABORT;
 
3193
            }
 
3194
          }
2816
3195
        | TRUNCATE_SYM '(' expr ',' expr ')'
2817
3196
          { $$= 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
3197
        ;
2846
3198
 
2847
3199
/*
2862
3214
          }
2863
3215
          opt_udf_expr_list ')'
2864
3216
          {
 
3217
            Session *session= YYSession;
2865
3218
            Create_func *builder;
2866
3219
            Item *item= NULL;
2867
3220
 
2877
3230
            builder= find_native_function_builder($1);
2878
3231
            if (builder)
2879
3232
            {
2880
 
              item= builder->create(YYSession, $1, $4);
 
3233
              item= builder->create(session, $1, $4);
2881
3234
            }
2882
3235
            else
2883
3236
            {
2885
3238
              const plugin::Function *udf= $<udf>3;
2886
3239
              if (udf)
2887
3240
              {
2888
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3241
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2889
3242
              } else {
2890
3243
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2891
3244
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
2896
3249
            {
2897
3250
              DRIZZLE_YYABORT;
2898
3251
            }
2899
 
            Lex->setCacheable(false);
2900
3252
          }
2901
3253
        ;
2902
3254
 
2988
3340
            sel->in_sum_expr--;
2989
3341
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
2990
3342
                                          sel->gorder_list, $7);
2991
 
            $5->clear();
 
3343
            $5->empty();
2992
3344
          }
2993
3345
        ;
2994
3346
 
3002
3354
        ;
3003
3355
 
3004
3356
variable_aux:
3005
 
          user_variable_ident SET_VAR expr
 
3357
          ident_or_text SET_VAR expr
3006
3358
          {
3007
3359
            $$= new Item_func_set_user_var($1, $3);
3008
 
            Lex->setCacheable(false);
3009
3360
          }
3010
 
        | user_variable_ident
 
3361
        | ident_or_text
3011
3362
          {
3012
 
            $$= new Item_func_get_user_var(*YYSession, $1);
3013
 
            Lex->setCacheable(false);
 
3363
            $$= new Item_func_get_user_var($1);
3014
3364
          }
3015
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3365
        | '@' opt_var_ident_type ident_or_text opt_component
3016
3366
          {
3017
3367
            /* disallow "SELECT @@global.global.variable" */
3018
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3368
            if ($3.str && $4.str && check_reserved_words(&$3))
3019
3369
            {
3020
 
              parser::my_parse_error(YYSession->m_lip);
 
3370
              my_parse_error(ER(ER_SYNTAX_ERROR));
3021
3371
              DRIZZLE_YYABORT;
3022
3372
            }
3023
3373
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3026
3376
        ;
3027
3377
 
3028
3378
opt_distinct:
3029
 
          /* empty */ { $$ = false; }
3030
 
        | DISTINCT    { $$ = true; }
 
3379
          /* empty */ { $$ = 0; }
 
3380
        | DISTINCT    { $$ = 1; }
3031
3381
        ;
3032
3382
 
3033
3383
opt_gconcat_separator:
3049
3399
            select->gorder_list=
3050
3400
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
3051
3401
                                     sizeof(st_sql_list));
3052
 
            select->order_list.clear();
 
3402
            select->order_list.empty();
3053
3403
          }
3054
3404
        ;
3055
3405
 
3056
3406
in_sum_expr:
3057
3407
          opt_all
3058
3408
          {
3059
 
            if (Lex->current_select->inc_in_sum_expr())
 
3409
            LEX *lex= Lex;
 
3410
            if (lex->current_select->inc_in_sum_expr())
3060
3411
            {
3061
 
              parser::my_parse_error(YYSession->m_lip);
 
3412
              my_parse_error(ER(ER_SYNTAX_ERROR));
3062
3413
              DRIZZLE_YYABORT;
3063
3414
            }
3064
3415
          }
3072
3423
cast_type:
3073
3424
          BINARY opt_len
3074
3425
          { $$=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
3426
        | CHAR_SYM opt_len
3088
3427
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3089
3428
        | DATE_SYM
3090
3429
          { $$=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
3430
        | DATETIME_SYM
3094
3431
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3095
3432
        | DECIMAL_SYM float_options
3140
3477
          table_factor { $$=$1; }
3141
3478
        | join_table
3142
3479
          {
3143
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3480
            LEX *lex= Lex;
 
3481
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3144
3482
              DRIZZLE_YYABORT;
3145
3483
          }
3146
3484
        ;
3186
3524
            left-associative joins.
3187
3525
          */
3188
3526
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
3189
 
          { 
3190
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
3191
 
            Lex->is_cross= false;
3192
 
          }
 
3527
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); }
3193
3528
        | table_ref STRAIGHT_JOIN table_factor
3194
 
          { 
3195
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
3196
 
          }
 
3529
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
3197
3530
        | table_ref normal_join table_ref
3198
3531
          ON
3199
3532
          {
3200
3533
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3201
 
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
3202
3534
            /* Change the current name resolution context to a local context. */
3203
3535
            if (push_new_name_resolution_context(YYSession, $1, $3))
3204
3536
              DRIZZLE_YYABORT;
3287
3619
          }
3288
3620
          expr
3289
3621
          {
3290
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3622
            LEX *lex= Lex;
 
3623
            if (!($$= lex->current_select->convert_right_join()))
3291
3624
              DRIZZLE_YYABORT;
3292
3625
            add_join_on($$, $8);
3293
3626
            Lex->pop_context();
3299
3632
          }
3300
3633
          USING '(' using_list ')'
3301
3634
          {
3302
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3635
            LEX *lex= Lex;
 
3636
            if (!($$= lex->current_select->convert_right_join()))
3303
3637
              DRIZZLE_YYABORT;
3304
3638
            add_join_natural($$,$5,$9,Lex->current_select);
3305
3639
          }
3307
3641
          {
3308
3642
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3309
3643
            add_join_natural($6,$1,NULL,Lex->current_select);
3310
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3644
            LEX *lex= Lex;
 
3645
            if (!($$= lex->current_select->convert_right_join()))
3311
3646
              DRIZZLE_YYABORT;
3312
3647
          }
3313
3648
        ;
3315
3650
normal_join:
3316
3651
          JOIN_SYM {}
3317
3652
        | INNER_SYM JOIN_SYM {}
3318
 
        | CROSS JOIN_SYM
3319
 
          {
3320
 
            Lex->is_cross= true;
3321
 
            Lex->current_select->is_cross= true;
3322
 
          }
 
3653
        | CROSS JOIN_SYM {}
3323
3654
        ;
3324
3655
 
3325
3656
/*
3332
3663
/* Warning - may return NULL in case of incomplete SELECT */
3333
3664
table_factor:
3334
3665
          {
 
3666
            Select_Lex *sel= Lex->current_select;
 
3667
            sel->table_join_options= 0;
3335
3668
          }
3336
3669
          table_ident opt_table_alias opt_key_definition
3337
3670
          {
3338
3671
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3339
 
                             0,
 
3672
                             Lex->current_select->get_table_join_options(),
3340
3673
                             Lex->lock_option,
3341
3674
                             Lex->current_select->pop_index_hints())))
3342
3675
              DRIZZLE_YYABORT;
3344
3677
          }
3345
3678
        | select_derived_init get_select_lex select_derived2
3346
3679
          {
3347
 
            Select_Lex *sel= Lex->current_select;
 
3680
            LEX *lex= Lex;
 
3681
            Select_Lex *sel= lex->current_select;
3348
3682
            if ($1)
3349
3683
            {
3350
3684
              if (sel->set_braces(1))
3351
3685
              {
3352
 
                parser::my_parse_error(YYSession->m_lip);
 
3686
                my_parse_error(ER(ER_SYNTAX_ERROR));
3353
3687
                DRIZZLE_YYABORT;
3354
3688
              }
3355
3689
              /* select in braces, can't contain global parameters */
3357
3691
                sel->master_unit()->global_parameters=
3358
3692
                   sel->master_unit()->fake_select_lex;
3359
3693
            }
3360
 
            if ($2->init_nested_join(Lex->session))
 
3694
            if ($2->init_nested_join(lex->session))
3361
3695
              DRIZZLE_YYABORT;
3362
3696
            $$= 0;
3363
3697
            /* incomplete derived tables return NULL, we must be
3386
3720
            /* Use $2 instead of Lex->current_select as derived table will
3387
3721
               alter value of Lex->current_select. */
3388
3722
            if (!($3 || $5) && $2->embedding &&
3389
 
                !$2->embedding->getNestedJoin()->join_list.elements)
 
3723
                !$2->embedding->nested_join->join_list.elements)
3390
3724
            {
3391
3725
              /* we have a derived table ($3 == NULL) but no alias,
3392
3726
                 Since we are nested in further parentheses so we
3399
3733
              /* Handle case of derived table, alias may be NULL if there
3400
3734
                 are no outer parentheses, add_table_to_list() will throw
3401
3735
                 error in this case */
3402
 
              Select_Lex *sel= Lex->current_select;
 
3736
              LEX *lex=Lex;
 
3737
              Select_Lex *sel= lex->current_select;
3403
3738
              Select_Lex_Unit *unit= sel->master_unit();
3404
 
              Lex->current_select= sel= unit->outer_select();
3405
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3739
              lex->current_select= sel= unit->outer_select();
 
3740
              if (!($$= sel->add_table_to_list(lex->session,
3406
3741
                                               new Table_ident(unit), $5, 0,
3407
3742
                                               TL_READ)))
3408
3743
 
3409
3744
                DRIZZLE_YYABORT;
3410
3745
              sel->add_joined_table($$);
3411
 
              Lex->pop_context();
 
3746
              lex->pop_context();
3412
3747
            }
3413
3748
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3414
3749
            {
3415
3750
              /* simple nested joins cannot have aliases or unions */
3416
 
              parser::my_parse_error(YYSession->m_lip);
 
3751
              my_parse_error(ER(ER_SYNTAX_ERROR));
3417
3752
              DRIZZLE_YYABORT;
3418
3753
            }
3419
3754
            else
3427
3762
          UNION_SYM
3428
3763
          union_option
3429
3764
          {
3430
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3765
            if (add_select_to_union_list(Lex, (bool)$3))
3431
3766
              DRIZZLE_YYABORT;
3432
3767
          }
3433
3768
          query_specification
3445
3780
select_init2_derived:
3446
3781
          select_part2_derived
3447
3782
          {
3448
 
            Select_Lex * sel= Lex->current_select;
3449
 
            if (Lex->current_select->set_braces(0))
 
3783
            LEX *lex= Lex;
 
3784
            Select_Lex * sel= lex->current_select;
 
3785
            if (lex->current_select->set_braces(0))
3450
3786
            {
3451
 
              parser::my_parse_error(YYSession->m_lip);
 
3787
              my_parse_error(ER(ER_SYNTAX_ERROR));
3452
3788
              DRIZZLE_YYABORT;
3453
3789
            }
3454
3790
            if (sel->linkage == UNION_TYPE &&
3455
3791
                sel->master_unit()->first_select()->braces)
3456
3792
            {
3457
 
              parser::my_parse_error(YYSession->m_lip);
 
3793
              my_parse_error(ER(ER_SYNTAX_ERROR));
3458
3794
              DRIZZLE_YYABORT;
3459
3795
            }
3460
3796
          }
3463
3799
/* The equivalent of select_part2 for nested queries. */
3464
3800
select_part2_derived:
3465
3801
          {
3466
 
            Select_Lex *sel= Lex->current_select;
 
3802
            LEX *lex= Lex;
 
3803
            Select_Lex *sel= lex->current_select;
3467
3804
            if (sel->linkage != UNION_TYPE)
3468
 
              init_select(Lex);
3469
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3805
              mysql_init_select(lex);
 
3806
            lex->current_select->parsing_place= SELECT_LIST;
3470
3807
          }
3471
3808
          select_options select_item_list
3472
3809
          {
3479
3816
select_derived:
3480
3817
          get_select_lex
3481
3818
          {
3482
 
            if ($1->init_nested_join(Lex->session))
 
3819
            LEX *lex= Lex;
 
3820
            if ($1->init_nested_join(lex->session))
3483
3821
              DRIZZLE_YYABORT;
3484
3822
          }
3485
3823
          derived_table_list
3486
3824
          {
 
3825
            LEX *lex= Lex;
3487
3826
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3488
3827
               for derived tables, both must equal NULL */
3489
3828
 
3490
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
3829
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3491
3830
              DRIZZLE_YYABORT;
3492
 
 
3493
3831
            if (!$3 && $$)
3494
3832
            {
3495
 
              parser::my_parse_error(YYSession->m_lip);
 
3833
              my_parse_error(ER(ER_SYNTAX_ERROR));
3496
3834
              DRIZZLE_YYABORT;
3497
3835
            }
3498
3836
          }
3500
3838
 
3501
3839
select_derived2:
3502
3840
          {
3503
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3504
 
            if (not Lex->expr_allows_subselect)
 
3841
            LEX *lex= Lex;
 
3842
            lex->derived_tables|= DERIVED_SUBQUERY;
 
3843
            if (!lex->expr_allows_subselect)
3505
3844
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
3845
              my_parse_error(ER(ER_SYNTAX_ERROR));
3507
3846
              DRIZZLE_YYABORT;
3508
3847
            }
3509
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
3848
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
3849
                mysql_new_select(lex, 1))
3510
3850
              DRIZZLE_YYABORT;
3511
 
            init_select(Lex);
3512
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3513
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3851
            mysql_init_select(lex);
 
3852
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3853
            lex->current_select->parsing_place= SELECT_LIST;
3514
3854
          }
3515
3855
          select_options select_item_list
3516
3856
          {
3526
3866
select_derived_init:
3527
3867
          SELECT_SYM
3528
3868
          {
3529
 
            Select_Lex *sel= Lex->current_select;
 
3869
            LEX *lex= Lex;
 
3870
 
 
3871
            Select_Lex *sel= lex->current_select;
3530
3872
            TableList *embedding;
3531
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
3873
            if (!sel->embedding || sel->end_nested_join(lex->session))
3532
3874
            {
3533
3875
              /* we are not in parentheses */
3534
 
              parser::my_parse_error(YYSession->m_lip);
 
3876
              my_parse_error(ER(ER_SYNTAX_ERROR));
3535
3877
              DRIZZLE_YYABORT;
3536
3878
            }
3537
3879
            embedding= Lex->current_select->embedding;
3538
3880
            $$= embedding &&
3539
 
                !embedding->getNestedJoin()->join_list.elements;
 
3881
                !embedding->nested_join->join_list.elements;
3540
3882
            /* return true if we are deeply nested */
3541
3883
          }
3542
3884
        ;
3673
4015
table_alias:
3674
4016
          /* empty */
3675
4017
        | AS
 
4018
        | EQ
3676
4019
        ;
3677
4020
 
3678
4021
opt_table_alias:
3679
4022
          /* empty */ { $$=0; }
3680
4023
        | table_alias ident
3681
 
          {
3682
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3683
 
          }
 
4024
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3684
4025
        ;
3685
4026
 
3686
4027
opt_all:
3760
4101
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3761
4102
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3762
4103
            */
3763
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4104
            LEX *lex= Lex;
 
4105
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3764
4106
            {
3765
4107
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3766
4108
                       "global union parameters");
3767
4109
              DRIZZLE_YYABORT;
3768
4110
            }
3769
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4111
            lex->current_select->olap= ROLLUP_TYPE;
3770
4112
          }
3771
4113
        ;
3772
4114
 
3784
4126
        ;
3785
4127
 
3786
4128
alter_order_item:
3787
 
          simple_ident order_dir
 
4129
          simple_ident_nospvar order_dir
3788
4130
          {
 
4131
            Session *session= YYSession;
3789
4132
            bool ascending= ($2 == 1) ? true : false;
3790
 
            if (YYSession->add_order_to_list($1, ascending))
 
4133
            if (session->add_order_to_list($1, ascending))
3791
4134
              DRIZZLE_YYABORT;
3792
4135
          }
3793
4136
        ;
3804
4147
order_clause:
3805
4148
          ORDER_SYM BY
3806
4149
          {
3807
 
            if (not parser::buildOrderBy(Lex))
 
4150
            LEX *lex=Lex;
 
4151
            Select_Lex *sel= lex->current_select;
 
4152
            Select_Lex_Unit *unit= sel-> master_unit();
 
4153
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4154
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4155
                (sel->linkage != UNION_TYPE || sel->braces))
 
4156
            {
 
4157
              my_error(ER_WRONG_USAGE, MYF(0),
 
4158
                       "CUBE/ROLLUP", "ORDER BY");
3808
4159
              DRIZZLE_YYABORT;
 
4160
            }
 
4161
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4162
            {
 
4163
              /*
 
4164
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4165
                executed in the same way as the query
 
4166
                SELECT ... ORDER BY order_list
 
4167
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4168
                Otherwise we create a fake Select_Lex if it has not been created
 
4169
                yet.
 
4170
              */
 
4171
              Select_Lex *first_sl= unit->first_select();
 
4172
              if (!unit->is_union() &&
 
4173
                  (first_sl->order_list.elements ||
 
4174
                   first_sl->select_limit) &&           
 
4175
                  unit->add_fake_select_lex(lex->session))
 
4176
                DRIZZLE_YYABORT;
 
4177
            }
3809
4178
          }
3810
4179
          order_list
3811
4180
        ;
3812
4181
 
3813
4182
order_list:
3814
4183
          order_list ',' order_ident order_dir
3815
 
          {
3816
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3817
 
              DRIZZLE_YYABORT;
3818
 
          }
 
4184
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3819
4185
        | order_ident order_dir
3820
 
          {
3821
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3822
 
              DRIZZLE_YYABORT;
3823
 
          }
 
4186
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3824
4187
        ;
3825
4188
 
3826
4189
order_dir:
3832
4195
opt_limit_clause_init:
3833
4196
          /* empty */
3834
4197
          {
3835
 
            Select_Lex *sel= Lex->current_select;
 
4198
            LEX *lex= Lex;
 
4199
            Select_Lex *sel= lex->current_select;
3836
4200
            sel->offset_limit= 0;
3837
4201
            sel->select_limit= 0;
3838
4202
          }
3881
4245
delete_limit_clause:
3882
4246
          /* empty */
3883
4247
          {
3884
 
            Lex->current_select->select_limit= 0;
 
4248
            LEX *lex=Lex;
 
4249
            lex->current_select->select_limit= 0;
3885
4250
          }
3886
4251
        | LIMIT limit_option
3887
4252
          {
3892
4257
        ;
3893
4258
 
3894
4259
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); }
 
4260
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4261
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4262
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4263
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4264
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4265
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3901
4266
        ;
3902
4267
 
3903
4268
ulonglong_num:
3910
4275
 
3911
4276
select_var_list_init:
3912
4277
          {
3913
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4278
            LEX *lex=Lex;
 
4279
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3914
4280
              DRIZZLE_YYABORT;
3915
4281
          }
3916
4282
          select_var_list
3923
4289
        ;
3924
4290
 
3925
4291
select_var_ident: 
3926
 
          '@' user_variable_ident
 
4292
          '@' ident_or_text
3927
4293
          {
3928
 
            if (Lex->result)
3929
 
            {
3930
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3931
 
            }
 
4294
            LEX *lex=Lex;
 
4295
            if (lex->result)
 
4296
              ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
3932
4297
            else
3933
 
            {
3934
4298
              /*
3935
4299
                The parser won't create select_result instance only
3936
4300
                if it's an EXPLAIN.
3937
4301
              */
3938
 
              assert(Lex->describe);
3939
 
            }
 
4302
              assert(lex->describe);
3940
4303
          }
3941
4304
        ;
3942
4305
 
3949
4312
into_destination:
3950
4313
          OUTFILE TEXT_STRING_filesystem
3951
4314
          {
3952
 
            Lex->setCacheable(false);
3953
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3954
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4315
            LEX *lex= Lex;
 
4316
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4317
                !(lex->result= new select_export(lex->exchange)))
3955
4318
              DRIZZLE_YYABORT;
3956
4319
          }
3957
4320
          opt_field_term opt_line_term
3958
4321
        | DUMPFILE TEXT_STRING_filesystem
3959
4322
          {
3960
 
            if (not Lex->describe)
 
4323
            LEX *lex=Lex;
 
4324
            if (!lex->describe)
3961
4325
            {
3962
 
              Lex->setCacheable(false);
3963
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4326
              if (!(lex->exchange= new file_exchange($2.str,1)))
3964
4327
                DRIZZLE_YYABORT;
3965
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4328
              if (!(lex->result= new select_dump(lex->exchange)))
3966
4329
                DRIZZLE_YYABORT;
3967
4330
            }
3968
4331
          }
3969
4332
        | select_var_list_init
3970
 
          {Lex->setCacheable(false);}
 
4333
          { }
3971
4334
        ;
3972
4335
 
3973
4336
/*
3975
4338
*/
3976
4339
 
3977
4340
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;
 
4341
          DROP opt_temporary table_or_tables if_exists table_list
 
4342
          {
 
4343
            LEX *lex=Lex;
 
4344
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4345
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4346
            lex->statement= statement;
 
4347
            if (lex->statement == NULL)
 
4348
              DRIZZLE_YYABORT;
3986
4349
            statement->drop_temporary= $2;
3987
4350
            statement->drop_if_exists= $4;
3988
4351
          }
3989
4352
        | DROP build_method INDEX_SYM ident ON table_ident {}
3990
4353
          {
3991
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
3992
 
            Lex->statement= statement;
 
4354
            LEX *lex=Lex;
 
4355
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4356
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4357
            lex->statement= statement;
 
4358
            if (lex->statement == NULL)
 
4359
              DRIZZLE_YYABORT;
3993
4360
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
3994
4361
            statement->alter_info.build_method= $2;
3995
4362
            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))
 
4363
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4364
                                                        TL_OPTION_UPDATING))
3998
4365
              DRIZZLE_YYABORT;
3999
4366
          }
4000
 
        | DROP DATABASE if_exists schema_name
 
4367
        | DROP DATABASE if_exists ident
4001
4368
          {
4002
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4003
 
            Lex->statement= statement;
 
4369
            LEX *lex=Lex;
 
4370
            lex->sql_command= SQLCOM_DROP_DB;
 
4371
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4372
            lex->statement= statement;
 
4373
            if (lex->statement == NULL)
 
4374
              DRIZZLE_YYABORT;
4004
4375
            statement->drop_if_exists=$3;
4005
 
            Lex->name= $4;
 
4376
            lex->name= $4;
4006
4377
          }
4007
 
        ;
4008
 
 
4009
4378
table_list:
4010
4379
          table_name
4011
4380
        | table_list ',' table_name
4020
4389
        ;
4021
4390
 
4022
4391
if_exists:
4023
 
          /* empty */ { $$= false; }
4024
 
        | IF EXISTS { $$= true; }
 
4392
          /* empty */ { $$= 0; }
 
4393
        | IF EXISTS { $$= 1; }
4025
4394
        ;
4026
4395
 
4027
4396
opt_temporary:
4028
 
          /* empty */ { $$= false; }
4029
 
        | TEMPORARY_SYM { $$= true; }
4030
 
        ;
4031
 
 
4032
 
/*
4033
 
  Execute a string as dynamic SQL.
4034
 
*/
4035
 
 
4036
 
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
 
        }
4041
 
 
4042
 
 
4043
 
execute_var_or_string:
4044
 
         user_variable_ident
4045
 
         {
4046
 
            $$.set($1);
4047
 
         }
4048
 
        | '@' user_variable_ident
4049
 
        {
4050
 
            $$.set($2, true);
4051
 
        }
4052
 
 
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
 
 
 
4397
          /* empty */ { $$= 0; }
 
4398
        | TEMPORARY_SYM { $$= 1; }
 
4399
        ;
4068
4400
/*
4069
4401
** Insert : add new data to table
4070
4402
*/
4072
4404
insert:
4073
4405
          INSERT
4074
4406
          {
4075
 
            Lex->statement= new statement::Insert(YYSession);
4076
 
            Lex->duplicates= DUP_ERROR;
4077
 
            init_select(Lex);
 
4407
            LEX *lex= Lex;
 
4408
            lex->sql_command= SQLCOM_INSERT;
 
4409
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4410
            if (lex->statement == NULL)
 
4411
              DRIZZLE_YYABORT;
 
4412
            lex->duplicates= DUP_ERROR;
 
4413
            mysql_init_select(lex);
4078
4414
            /* for subselects */
4079
 
            Lex->lock_option= TL_READ;
 
4415
            lex->lock_option= TL_READ;
4080
4416
          }
4081
4417
          opt_ignore insert2
4082
4418
          {
4090
4426
replace:
4091
4427
          REPLACE
4092
4428
          {
4093
 
            Lex->statement= new statement::Replace(YYSession);
4094
 
            Lex->duplicates= DUP_REPLACE;
4095
 
            init_select(Lex);
 
4429
            LEX *lex= Lex;
 
4430
            lex->sql_command= SQLCOM_REPLACE;
 
4431
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4432
            if (lex->statement == NULL)
 
4433
              DRIZZLE_YYABORT;
 
4434
            lex->duplicates= DUP_REPLACE;
 
4435
            mysql_init_select(lex);
4096
4436
          }
4097
4437
          insert2
4098
4438
          {
4111
4451
insert_table:
4112
4452
          table_name
4113
4453
          {
4114
 
            Lex->field_list.clear();
4115
 
            Lex->many_values.clear();
4116
 
            Lex->insert_list=0;
 
4454
            LEX *lex=Lex;
 
4455
            lex->field_list.empty();
 
4456
            lex->many_values.empty();
 
4457
            lex->insert_list=0;
4117
4458
          };
4118
4459
 
4119
4460
insert_field_spec:
4120
4461
          insert_values {}
4121
4462
        | '(' ')' insert_values {}
4122
4463
        | '(' fields ')' insert_values {}
4123
 
        | SET_SYM
 
4464
        | SET
4124
4465
          {
4125
 
            if (not (Lex->insert_list = new List_item) ||
4126
 
                Lex->many_values.push_back(Lex->insert_list))
 
4466
            LEX *lex=Lex;
 
4467
            if (!(lex->insert_list = new List_item) ||
 
4468
                lex->many_values.push_back(lex->insert_list))
4127
4469
              DRIZZLE_YYABORT;
4128
4470
          }
4129
4471
          ident_eq_list
4137
4479
insert_values:
4138
4480
          VALUES values_list {}
4139
4481
        | VALUE_SYM values_list {}
4140
 
        | stored_select
4141
 
          {
4142
 
            Lex->current_select->set_braces(0);
4143
 
          }
 
4482
        | create_select
 
4483
          { Lex->current_select->set_braces(0);}
4144
4484
          union_clause {}
4145
 
        | '(' stored_select ')'
4146
 
          {
4147
 
            Lex->current_select->set_braces(1);
4148
 
          }
 
4485
        | '(' create_select ')'
 
4486
          { Lex->current_select->set_braces(1);}
4149
4487
          union_opt {}
4150
4488
        ;
4151
4489
 
4160
4498
        ;
4161
4499
 
4162
4500
ident_eq_value:
4163
 
          simple_ident equal expr_or_default
 
4501
          simple_ident_nospvar equal expr_or_default
4164
4502
          {
4165
 
            if (Lex->field_list.push_back($1) ||
4166
 
                Lex->insert_list->push_back($3))
 
4503
            LEX *lex=Lex;
 
4504
            if (lex->field_list.push_back($1) ||
 
4505
                lex->insert_list->push_back($3))
4167
4506
              DRIZZLE_YYABORT;
4168
4507
          }
4169
4508
        ;
4170
4509
 
4171
4510
equal:
4172
 
          '=' {}
 
4511
          EQ {}
4173
4512
        | SET_VAR {}
4174
4513
        ;
4175
4514
 
4186
4525
          }
4187
4526
          opt_values ')'
4188
4527
          {
4189
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4528
            LEX *lex=Lex;
 
4529
            if (lex->many_values.push_back(lex->insert_list))
4190
4530
              DRIZZLE_YYABORT;
4191
4531
          }
4192
4532
        ;
4223
4563
/* Update rows in a table */
4224
4564
 
4225
4565
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)
 
4566
          UPDATE_SYM opt_ignore table_ident
 
4567
          {
 
4568
            LEX *lex= Lex;
 
4569
            mysql_init_select(lex);
 
4570
            lex->sql_command= SQLCOM_UPDATE;
 
4571
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4572
            if (lex->statement == NULL)
 
4573
              DRIZZLE_YYABORT;
 
4574
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4575
            lex->duplicates= DUP_ERROR;
 
4576
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4577
              DRIZZLE_YYABORT;
 
4578
          }
 
4579
          SET update_list
 
4580
          {
 
4581
            LEX *lex= Lex;
 
4582
            if (lex->select_lex.get_table_list()->derived)
4236
4583
            {
4237
4584
              /* it is single table update and it is update of derived table */
4238
4585
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4239
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4586
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4240
4587
              DRIZZLE_YYABORT;
4241
4588
            }
4242
4589
            /*
4243
4590
              In case of multi-update setting write lock for all tables may
4244
4591
              be too pessimistic. We will decrease lock level if possible in
4245
 
              multi_update().
 
4592
              mysql_multi_update().
4246
4593
            */
4247
4594
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4248
4595
          }
4255
4602
        ;
4256
4603
 
4257
4604
update_elem:
4258
 
          simple_ident equal expr_or_default
 
4605
          simple_ident_nospvar equal expr_or_default
4259
4606
          {
4260
4607
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4261
4608
              DRIZZLE_YYABORT;
4268
4615
        ;
4269
4616
 
4270
4617
insert_update_elem:
4271
 
          simple_ident equal expr_or_default
 
4618
          simple_ident_nospvar equal expr_or_default
4272
4619
          {
4273
 
          if (Lex->update_list.push_back($1) ||
4274
 
              Lex->value_list.push_back($3))
 
4620
          LEX *lex= Lex;
 
4621
          if (lex->update_list.push_back($1) ||
 
4622
              lex->value_list.push_back($3))
4275
4623
              DRIZZLE_YYABORT;
4276
4624
          }
4277
4625
        ;
4279
4627
/* Delete rows from a table */
4280
4628
 
4281
4629
delete:
4282
 
          DELETE_SYM opt_delete_option FROM table_ident
 
4630
          DELETE_SYM
4283
4631
          {
4284
 
            Lex->statement= new statement::Delete(YYSession);
4285
 
            init_select(Lex);
4286
 
            Lex->lock_option= TL_WRITE_DEFAULT;
4287
 
            Lex->select_lex.init_order();
 
4632
            LEX *lex= Lex;
 
4633
            lex->sql_command= SQLCOM_DELETE;
 
4634
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4635
            if (lex->statement == NULL)
 
4636
              DRIZZLE_YYABORT;
 
4637
            mysql_init_select(lex);
 
4638
            lex->lock_option= TL_WRITE_DEFAULT;
 
4639
            lex->ignore= 0;
 
4640
            lex->select_lex.init_order();
 
4641
          }
 
4642
          opt_delete_options single_multi
 
4643
        ;
4288
4644
 
4289
 
            if (!Lex->current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING,
 
4645
single_multi:
 
4646
          FROM table_ident
 
4647
          {
 
4648
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4290
4649
                                           Lex->lock_option))
4291
4650
              DRIZZLE_YYABORT;
4292
4651
          }
4294
4653
          delete_limit_clause {}
4295
4654
        ;
4296
4655
 
 
4656
opt_delete_options:
 
4657
          /* empty */ {}
 
4658
        | opt_delete_option opt_delete_options {}
 
4659
        ;
 
4660
 
4297
4661
opt_delete_option:
4298
 
           /* empty */ { Lex->ignore= 0; }
4299
 
         | IGNORE_SYM  { Lex->ignore= 1; }
 
4662
         IGNORE_SYM   { Lex->ignore= 1; }
4300
4663
        ;
4301
4664
 
4302
4665
truncate:
4303
4666
          TRUNCATE_SYM opt_table_sym table_name
4304
4667
          {
4305
 
            Lex->statement= new statement::Truncate(YYSession);
4306
 
            Lex->select_lex.options= 0;
4307
 
            Lex->select_lex.init_order();
 
4668
            LEX* lex= Lex;
 
4669
            lex->sql_command= SQLCOM_TRUNCATE;
 
4670
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4671
            if (lex->statement == NULL)
 
4672
              DRIZZLE_YYABORT;
 
4673
            lex->select_lex.options= 0;
 
4674
            lex->select_lex.init_order();
4308
4675
          }
4309
4676
        ;
4310
4677
 
4318
4685
show:
4319
4686
          SHOW
4320
4687
          {
4321
 
            Lex->lock_option= TL_READ;
4322
 
            init_select(Lex);
4323
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4688
            LEX *lex=Lex;
 
4689
            lex->wild=0;
 
4690
            lex->lock_option= TL_READ;
 
4691
            mysql_init_select(lex);
 
4692
            lex->current_select->parsing_place= SELECT_LIST;
4324
4693
          }
4325
4694
          show_param
4326
4695
          {}
4327
4696
        ;
4328
4697
 
4329
 
/* SHOW SCHEMAS */
4330
4698
show_param:
4331
4699
           DATABASES show_wild
4332
4700
           {
4333
 
             if (not show::buildScemas(YYSession))
 
4701
             LEX *lex= Lex;
 
4702
             lex->sql_command= SQLCOM_SELECT;
 
4703
             lex->statement=
 
4704
               new(std::nothrow) statement::Select(YYSession);
 
4705
             if (lex->statement == NULL)
 
4706
               DRIZZLE_YYABORT;
 
4707
 
 
4708
             Session *session= YYSession;
 
4709
 
 
4710
             std::string column_name= "Database";
 
4711
             if (Lex->wild)
 
4712
             {
 
4713
               column_name.append(" (");
 
4714
               column_name.append(Lex->wild->ptr());
 
4715
               column_name.append(")");
 
4716
             }
 
4717
 
 
4718
             if (Lex->current_select->where)
 
4719
             {
 
4720
               if (prepare_new_schema_table(YYSession, lex, "SCHEMAS"))
 
4721
                 DRIZZLE_YYABORT;
 
4722
             }
 
4723
             else
 
4724
             {
 
4725
               if (prepare_new_schema_table(YYSession, lex, "SCHEMA_NAMES"))
 
4726
                 DRIZZLE_YYABORT;
 
4727
             }
 
4728
 
 
4729
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4730
             my_field->is_autogenerated_name= false;
 
4731
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4732
 
 
4733
             if (session->add_item_to_list(my_field))
4334
4734
               DRIZZLE_YYABORT;
4335
4735
           }
4336
 
           /* SHOW TABLES */
4337
4736
         | TABLES opt_db show_wild
4338
4737
           {
4339
 
             if (not show::buildTables(YYSession, $2))
4340
 
               DRIZZLE_YYABORT;
4341
 
           }
4342
 
           /* SHOW TEMPORARY TABLES */
4343
 
         | TEMPORARY_SYM TABLES show_wild
4344
 
           {
4345
 
             if (not show::buildTemporaryTables(YYSession))
4346
 
               DRIZZLE_YYABORT;
4347
 
           }
4348
 
           /* SHOW TABLE STATUS */
 
4738
             LEX *lex= Lex;
 
4739
             lex->sql_command= SQLCOM_SELECT;
 
4740
             lex->statement=
 
4741
               new(std::nothrow) statement::Select(YYSession);
 
4742
             if (lex->statement == NULL)
 
4743
               DRIZZLE_YYABORT;
 
4744
 
 
4745
              Session *session= YYSession;
 
4746
 
 
4747
              std::string column_name= "Tables_in_";
 
4748
 
 
4749
              if ($2)
 
4750
              {
 
4751
                column_name.append($2);
 
4752
                lex->select_lex.db= $2;
 
4753
                if (not plugin::StorageEngine::doesSchemaExist($2))
 
4754
                {
 
4755
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
4756
                }
 
4757
              }
 
4758
              else
 
4759
              {
 
4760
                column_name.append(session->db);
 
4761
              }
 
4762
 
 
4763
             if (Lex->wild)
 
4764
             {
 
4765
               column_name.append(" (");
 
4766
               column_name.append(Lex->wild->ptr());
 
4767
               column_name.append(")");
 
4768
             }
 
4769
 
 
4770
             if (Lex->current_select->where)
 
4771
             {
 
4772
               if (prepare_new_schema_table(YYSession, lex, "TABLES"))
 
4773
                 DRIZZLE_YYABORT;
 
4774
             }
 
4775
             else
 
4776
             {
 
4777
               if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
4778
                 DRIZZLE_YYABORT;
 
4779
             }
 
4780
 
 
4781
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4782
             my_field->is_autogenerated_name= false;
 
4783
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4784
 
 
4785
             if (session->add_item_to_list(my_field))
 
4786
               DRIZZLE_YYABORT;
 
4787
           }
4349
4788
         | TABLE_SYM STATUS_SYM opt_db show_wild
4350
4789
           {
4351
 
             if (not show::buildTableStatus(YYSession, $3))
4352
 
               DRIZZLE_YYABORT;
 
4790
             LEX *lex= Lex;
 
4791
             lex->sql_command= SQLCOM_SELECT;
 
4792
             lex->statement=
 
4793
               new(std::nothrow) statement::Select(YYSession);
 
4794
             if (lex->statement == NULL)
 
4795
               DRIZZLE_YYABORT;
 
4796
 
 
4797
             Session *session= YYSession;
 
4798
 
 
4799
             std::string column_name= "Tables_in_";
 
4800
 
 
4801
             if ($3)
 
4802
             {
 
4803
               lex->select_lex.db= $3;
 
4804
 
 
4805
               if (not plugin::StorageEngine::doesSchemaExist($3))
 
4806
               {
 
4807
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
4808
               }
 
4809
             }
 
4810
 
 
4811
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
4812
               DRIZZLE_YYABORT;
 
4813
 
 
4814
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4815
                                                           context,
 
4816
                                                           NULL, NULL, "*")))
 
4817
               DRIZZLE_YYABORT;
 
4818
             (session->lex->current_select->with_wild)++;
4353
4819
           }
4354
 
           /* SHOW COLUMNS FROM table_name */
4355
4820
        | 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 */
 
4821
          {
 
4822
             LEX *lex= Lex;
 
4823
             Session *session= YYSession;
 
4824
             statement::Select *select;
 
4825
 
 
4826
             lex->sql_command= SQLCOM_SELECT;
 
4827
 
 
4828
             select= new(std::nothrow) statement::Select(session);
 
4829
 
 
4830
             lex->statement= select;
 
4831
 
 
4832
             if (lex->statement == NULL)
 
4833
               DRIZZLE_YYABORT;
 
4834
 
 
4835
             if ($4)
 
4836
              select->setShowPredicate($4, $3->table.str);
 
4837
             else if ($3->db.str)
 
4838
              select->setShowPredicate($3->db.str, $3->table.str);
 
4839
             else
 
4840
              select->setShowPredicate(session->db, $3->table.str);
 
4841
 
 
4842
             {
 
4843
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4844
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4845
               {
 
4846
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
4847
                            select->getShowSchema().c_str(), 
 
4848
                            $3->table.str);
 
4849
               }
 
4850
             }
 
4851
 
 
4852
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
4853
               DRIZZLE_YYABORT;
 
4854
 
 
4855
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4856
                                                           context,
 
4857
                                                           NULL, NULL, "*")))
 
4858
               DRIZZLE_YYABORT;
 
4859
             (session->lex->current_select->with_wild)++;
 
4860
 
 
4861
          }
4361
4862
        | 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
 
           }
 
4863
          {
 
4864
             LEX *lex= Lex;
 
4865
             Session *session= YYSession;
 
4866
             statement::Select *select;
 
4867
 
 
4868
             lex->sql_command= SQLCOM_SELECT;
 
4869
 
 
4870
             select= new(std::nothrow) statement::Select(session);
 
4871
 
 
4872
             lex->statement= select;
 
4873
 
 
4874
             if (lex->statement == NULL)
 
4875
               DRIZZLE_YYABORT;
 
4876
 
 
4877
             if ($4)
 
4878
              select->setShowPredicate($4, $3->table.str);
 
4879
             else if ($3->db.str)
 
4880
              select->setShowPredicate($3->db.str, $3->table.str);
 
4881
             else
 
4882
              select->setShowPredicate(session->db, $3->table.str);
 
4883
 
 
4884
             {
 
4885
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4886
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4887
               {
 
4888
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
4889
                            select->getShowSchema().c_str(), 
 
4890
                            $3->table.str);
 
4891
               }
 
4892
             }
 
4893
 
 
4894
             if (prepare_new_schema_table(session, lex, "show_indexes"))
 
4895
               DRIZZLE_YYABORT;
 
4896
 
 
4897
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4898
                                                           context,
 
4899
                                                           NULL, NULL, "*")))
 
4900
               DRIZZLE_YYABORT;
 
4901
             (session->lex->current_select->with_wild)++;
 
4902
          }
4366
4903
        | COUNT_SYM '(' '*' ')' WARNINGS
4367
4904
          {
4368
 
            show::buildSelectWarning(YYSession);
 
4905
            (void) create_select_for_variable("warning_count");
 
4906
            LEX *lex= Lex;
 
4907
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4908
            if (lex->statement == NULL)
 
4909
              DRIZZLE_YYABORT;
4369
4910
          }
4370
4911
        | COUNT_SYM '(' '*' ')' ERRORS
4371
4912
          {
4372
 
            show::buildSelectError(YYSession);
 
4913
            (void) create_select_for_variable("error_count");
 
4914
            LEX *lex= Lex;
 
4915
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4916
            if (lex->statement == NULL)
 
4917
              DRIZZLE_YYABORT;
4373
4918
          }
4374
4919
        | WARNINGS opt_limit_clause_init
4375
4920
          {
4376
 
            show::buildWarnings(YYSession);
 
4921
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
4922
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
4923
            if (Lex->statement == NULL)
 
4924
              DRIZZLE_YYABORT;
4377
4925
          }
4378
4926
        | ERRORS opt_limit_clause_init
4379
4927
          {
4380
 
            show::buildErrors(YYSession);
 
4928
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
4929
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
4930
            if (Lex->statement == NULL)
 
4931
              DRIZZLE_YYABORT;
4381
4932
          }
4382
4933
        | 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
 
          }
4392
 
        | CREATE TABLE_SYM table_ident
4393
 
          {
4394
 
            if (not show::buildCreateTable(YYSession, $3))
4395
 
              DRIZZLE_YYABORT;
4396
 
          }
 
4934
           {
 
4935
             LEX *lex= Lex;
 
4936
             lex->sql_command= SQLCOM_SELECT;
 
4937
             lex->statement=
 
4938
               new(std::nothrow) statement::Select(YYSession);
 
4939
             if (lex->statement == NULL)
 
4940
               DRIZZLE_YYABORT;
 
4941
 
 
4942
             Session *session= YYSession;
 
4943
 
 
4944
             if ($1 == OPT_GLOBAL)
 
4945
             {
 
4946
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
4947
                 DRIZZLE_YYABORT;
 
4948
             }
 
4949
             else
 
4950
             {
 
4951
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
4952
                 DRIZZLE_YYABORT;
 
4953
             }
 
4954
 
 
4955
             std::string key("Variable_name");
 
4956
             std::string value("Value");
 
4957
 
 
4958
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
4959
             my_field->is_autogenerated_name= false;
 
4960
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
4961
 
 
4962
             if (session->add_item_to_list(my_field))
 
4963
               DRIZZLE_YYABORT;
 
4964
 
 
4965
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
4966
             my_field->is_autogenerated_name= false;
 
4967
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
4968
 
 
4969
             if (session->add_item_to_list(my_field))
 
4970
               DRIZZLE_YYABORT;
 
4971
           }
4397
4972
        | PROCESSLIST_SYM
4398
4973
          {
4399
 
            if (not show::buildProcesslist(YYSession))
4400
 
              DRIZZLE_YYABORT;
 
4974
           {
 
4975
             LEX *lex= Lex;
 
4976
             lex->sql_command= SQLCOM_SELECT;
 
4977
             lex->statement=
 
4978
               new(std::nothrow) statement::Select(YYSession);
 
4979
             if (lex->statement == NULL)
 
4980
               DRIZZLE_YYABORT;
 
4981
 
 
4982
             Session *session= YYSession;
 
4983
 
 
4984
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
4985
               DRIZZLE_YYABORT;
 
4986
 
 
4987
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4988
                                                           context,
 
4989
                                                           NULL, NULL, "*")))
 
4990
               DRIZZLE_YYABORT;
 
4991
             (session->lex->current_select->with_wild)++;
 
4992
           }
4401
4993
          }
4402
4994
        | opt_var_type  VARIABLES show_wild
4403
 
          {
4404
 
            if (not show::buildVariables(YYSession, $1))
4405
 
              DRIZZLE_YYABORT;
4406
 
          }
 
4995
           {
 
4996
             LEX *lex= Lex;
 
4997
             lex->sql_command= SQLCOM_SELECT;
 
4998
             lex->statement=
 
4999
               new(std::nothrow) statement::Select(YYSession);
 
5000
             if (lex->statement == NULL)
 
5001
               DRIZZLE_YYABORT;
 
5002
 
 
5003
             Session *session= YYSession;
 
5004
 
 
5005
             if ($1 == OPT_GLOBAL)
 
5006
             {
 
5007
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5008
                 DRIZZLE_YYABORT;
 
5009
             }
 
5010
             else
 
5011
             {
 
5012
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5013
                 DRIZZLE_YYABORT;
 
5014
             }
 
5015
 
 
5016
             std::string key("Variable_name");
 
5017
             std::string value("Value");
 
5018
 
 
5019
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5020
             my_field->is_autogenerated_name= false;
 
5021
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5022
 
 
5023
             if (session->add_item_to_list(my_field))
 
5024
               DRIZZLE_YYABORT;
 
5025
 
 
5026
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5027
             my_field->is_autogenerated_name= false;
 
5028
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5029
 
 
5030
             if (session->add_item_to_list(my_field))
 
5031
               DRIZZLE_YYABORT;
 
5032
           }
4407
5033
        | CREATE DATABASE opt_if_not_exists ident
4408
5034
          {
4409
 
            if (not show::buildCreateSchema(YYSession, $4))
 
5035
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
 
5036
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
 
5037
            Lex->statement= statement;
 
5038
            if (Lex->statement == NULL)
 
5039
              DRIZZLE_YYABORT;
 
5040
            statement->is_if_not_exists= $3;
 
5041
            Lex->name= $4;
 
5042
          }
 
5043
        | CREATE TABLE_SYM table_ident
 
5044
          {
 
5045
            LEX *lex= Lex;
 
5046
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
5047
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
 
5048
            if (lex->statement == NULL)
 
5049
              DRIZZLE_YYABORT;
 
5050
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4410
5051
              DRIZZLE_YYABORT;
4411
5052
          }
4412
5053
 
4441
5082
describe:
4442
5083
          describe_command table_ident
4443
5084
          {
4444
 
            if (not show::buildDescribe(YYSession, $2))
4445
 
            {
 
5085
            Session *session= YYSession;
 
5086
            statement::Select *select;
 
5087
            LEX *lex= Lex;
 
5088
            lex->lock_option= TL_READ;
 
5089
            mysql_init_select(lex);
 
5090
            lex->current_select->parsing_place= SELECT_LIST;
 
5091
            lex->sql_command= SQLCOM_SELECT;
 
5092
            select= new(std::nothrow) statement::Select(session);
 
5093
            lex->statement= select;
 
5094
            if (lex->statement == NULL)
4446
5095
              DRIZZLE_YYABORT;
4447
 
            }
 
5096
            lex->select_lex.db= 0;
 
5097
 
 
5098
             if ($2->db.str)
 
5099
              select->setShowPredicate($2->db.str, $2->table.str);
 
5100
             else
 
5101
              select->setShowPredicate(session->db, $2->table.str);
 
5102
 
 
5103
             {
 
5104
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5105
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5106
               {
 
5107
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5108
                            select->getShowSchema().c_str(), 
 
5109
                            $2->table.str);
 
5110
               }
 
5111
             }
 
5112
 
 
5113
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5114
               DRIZZLE_YYABORT;
 
5115
 
 
5116
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5117
                                                           context,
 
5118
                                                           NULL, NULL, "*")))
 
5119
               DRIZZLE_YYABORT;
 
5120
             (session->lex->current_select->with_wild)++;
 
5121
 
4448
5122
          }
4449
5123
          opt_describe_column {}
4450
5124
        | describe_command opt_extended_describe
4451
5125
          { Lex->describe|= DESCRIBE_NORMAL; }
4452
5126
          select
4453
5127
          {
4454
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5128
            LEX *lex=Lex;
 
5129
            lex->select_lex.options|= SELECT_DESCRIBE;
4455
5130
          }
4456
5131
        ;
4457
5132
 
4482
5157
flush:
4483
5158
          FLUSH_SYM
4484
5159
          {
4485
 
            Lex->statement= new statement::Flush(YYSession);
 
5160
            LEX *lex=Lex;
 
5161
            lex->sql_command= SQLCOM_FLUSH;
 
5162
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5163
            if (lex->statement == NULL)
 
5164
              DRIZZLE_YYABORT;
 
5165
            lex->type= 0;
4486
5166
          }
4487
5167
          flush_options
4488
5168
          {}
4515
5195
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4516
5196
            statement->setFlushStatus(true);
4517
5197
          }
4518
 
        | GLOBAL_SYM STATUS_SYM
4519
 
          {
4520
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4521
 
            statement->setFlushGlobalStatus(true);
4522
 
          }
4523
5198
        ;
4524
5199
 
4525
5200
opt_table_list:
4532
5207
kill:
4533
5208
          KILL_SYM kill_option expr
4534
5209
          {
4535
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5210
            LEX *lex=Lex;
 
5211
            lex->value_list.empty();
 
5212
            lex->value_list.push_front($3);
 
5213
            lex->sql_command= SQLCOM_KILL;
 
5214
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5215
            if (lex->statement == NULL)
 
5216
              DRIZZLE_YYABORT;
4536
5217
          }
4537
5218
        ;
4538
5219
 
4539
5220
kill_option:
4540
 
          /* empty */ { $$= false; }
4541
 
        | CONNECTION_SYM { $$= false; }
4542
 
        | QUERY_SYM      { $$= true; }
 
5221
          /* empty */ { Lex->type= 0; }
 
5222
        | CONNECTION_SYM { Lex->type= 0; }
 
5223
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
4543
5224
        ;
4544
5225
 
4545
5226
/* change database */
4546
5227
 
4547
5228
use:
4548
 
          USE_SYM schema_name
 
5229
          USE_SYM ident
4549
5230
          {
4550
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4551
 
            Lex->select_lex.db= $2.str;
 
5231
            LEX *lex=Lex;
 
5232
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5233
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5234
            if (lex->statement == NULL)
 
5235
              DRIZZLE_YYABORT;
 
5236
            lex->select_lex.db= $2.str;
4552
5237
          }
4553
5238
        ;
4554
5239
 
4557
5242
load:
4558
5243
          LOAD data_file
4559
5244
          {
4560
 
            statement::Load *statement= new statement::Load(YYSession);
4561
 
            Lex->statement= statement;
4562
 
 
4563
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5245
            Session *session= YYSession;
 
5246
            LEX *lex= session->lex;
 
5247
 
 
5248
            lex->sql_command= SQLCOM_LOAD;
 
5249
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5250
            lex->statement= statement;
 
5251
            if (lex->statement == NULL)
 
5252
              DRIZZLE_YYABORT;
 
5253
 
 
5254
            Lex_input_stream *lip= session->m_lip;
4564
5255
            statement->fname_start= lip->get_ptr();
4565
5256
          }
4566
5257
          load_data_lock INFILE TEXT_STRING_filesystem
4567
5258
          {
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)))
 
5259
            LEX *lex=Lex;
 
5260
            lex->lock_option= $4;
 
5261
            lex->duplicates= DUP_ERROR;
 
5262
            lex->ignore= 0;
 
5263
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4572
5264
              DRIZZLE_YYABORT;
4573
5265
          }
4574
5266
          opt_duplicate INTO
4575
5267
          {
4576
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5268
            Session *session= YYSession;
 
5269
            Lex_input_stream *lip= session->m_lip;
4577
5270
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4578
5271
          }
4579
5272
          TABLE_SYM table_ident
4580
5273
          {
 
5274
            LEX *lex=Lex;
4581
5275
            if (!Lex->current_select->add_table_to_list(YYSession,
4582
5276
                    $12, NULL, TL_OPTION_UPDATING,
4583
 
                    Lex->lock_option))
 
5277
                    lex->lock_option))
4584
5278
              DRIZZLE_YYABORT;
4585
 
            Lex->field_list.clear();
4586
 
            Lex->update_list.clear();
4587
 
            Lex->value_list.clear();
 
5279
            lex->field_list.empty();
 
5280
            lex->update_list.empty();
 
5281
            lex->value_list.empty();
4588
5282
          }
4589
5283
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4590
5284
          opt_load_data_set_spec
4608
5302
        | IGNORE_SYM { Lex->ignore= 1; }
4609
5303
        ;
4610
5304
 
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
5305
opt_field_term:
4621
5306
          /* empty */
4622
5307
        | COLUMNS field_term_list
4635
5320
          }
4636
5321
        | OPTIONALLY ENCLOSED BY text_string
4637
5322
          {
4638
 
            assert(Lex->exchange != 0);
4639
 
            Lex->exchange->enclosed= $4;
4640
 
            Lex->exchange->opt_enclosed= 1;
 
5323
            LEX *lex= Lex;
 
5324
            assert(lex->exchange != 0);
 
5325
            lex->exchange->enclosed= $4;
 
5326
            lex->exchange->opt_enclosed= 1;
4641
5327
          }
4642
5328
        | ENCLOSED BY text_string
4643
5329
          {
4702
5388
        ;
4703
5389
 
4704
5390
field_or_var:
4705
 
          simple_ident {$$= $1;}
4706
 
        | '@' user_variable_ident
 
5391
          simple_ident_nospvar {$$= $1;}
 
5392
        | '@' ident_or_text
4707
5393
          { $$= new Item_user_var_as_out_param($2); }
4708
5394
        ;
4709
5395
 
4710
5396
opt_load_data_set_spec:
4711
5397
          /* empty */ {}
4712
 
        | SET_SYM insert_update_list {}
 
5398
        | SET insert_update_list {}
4713
5399
        ;
4714
5400
 
4715
5401
/* Common definitions */
4717
5403
text_literal:
4718
5404
        TEXT_STRING_literal
4719
5405
        {
4720
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5406
          Session *session= YYSession;
 
5407
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4721
5408
        }
4722
5409
        | text_literal TEXT_STRING_literal
4723
5410
          {
4773
5460
            $$ = new Item_null();
4774
5461
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4775
5462
          }
4776
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4777
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5463
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5464
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4778
5465
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4779
5466
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4780
5467
        | DATE_SYM text_literal { $$ = $2; }
4817
5504
**********************************************************************/
4818
5505
 
4819
5506
insert_ident:
4820
 
          simple_ident { $$=$1; }
 
5507
          simple_ident_nospvar { $$=$1; }
4821
5508
        | table_wild { $$=$1; }
4822
5509
        ;
4823
5510
 
4824
5511
table_wild:
4825
5512
          ident '.' '*'
4826
5513
          {
4827
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5514
            Select_Lex *sel= Lex->current_select;
 
5515
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5516
            sel->with_wild++;
4828
5517
          }
4829
5518
        | ident '.' ident '.' '*'
4830
5519
          {
4831
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5520
            Select_Lex *sel= Lex->current_select;
 
5521
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
5522
            sel->with_wild++;
4832
5523
          }
4833
5524
        ;
4834
5525
 
4839
5530
simple_ident:
4840
5531
          ident
4841
5532
          {
4842
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5533
            {
 
5534
              Select_Lex *sel=Lex->current_select;
 
5535
              $$= (sel->parsing_place != IN_HAVING ||
 
5536
                  sel->get_in_sum_expr() > 0) ?
 
5537
                  (Item*) new Item_field(Lex->current_context(),
 
5538
                                         (const char *)NULL, NULL, $1.str) :
 
5539
                  (Item*) new Item_ref(Lex->current_context(),
 
5540
                                       (const char *)NULL, NULL, $1.str);
 
5541
            }
 
5542
          }
 
5543
        | simple_ident_q { $$= $1; }
 
5544
        ;
 
5545
 
 
5546
simple_ident_nospvar:
 
5547
          ident
 
5548
          {
 
5549
            Select_Lex *sel=Lex->current_select;
 
5550
            $$= (sel->parsing_place != IN_HAVING ||
 
5551
                sel->get_in_sum_expr() > 0) ?
 
5552
                (Item*) new Item_field(Lex->current_context(),
 
5553
                                       (const char *)NULL, NULL, $1.str) :
 
5554
                (Item*) new Item_ref(Lex->current_context(),
 
5555
                                     (const char *)NULL, NULL, $1.str);
4843
5556
          }
4844
5557
        | simple_ident_q { $$= $1; }
4845
5558
        ;
4847
5560
simple_ident_q:
4848
5561
          ident '.' ident
4849
5562
          {
4850
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5563
            Session *session= YYSession;
 
5564
            LEX *lex= session->lex;
 
5565
 
 
5566
            {
 
5567
              Select_Lex *sel= lex->current_select;
 
5568
              if (sel->no_table_names_allowed)
 
5569
              {
 
5570
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5571
                         MYF(0), $1.str, session->where);
 
5572
              }
 
5573
              $$= (sel->parsing_place != IN_HAVING ||
 
5574
                  sel->get_in_sum_expr() > 0) ?
 
5575
                  (Item*) new Item_field(Lex->current_context(),
 
5576
                                         (const char *)NULL, $1.str, $3.str) :
 
5577
                  (Item*) new Item_ref(Lex->current_context(),
 
5578
                                       (const char *)NULL, $1.str, $3.str);
 
5579
            }
4851
5580
          }
4852
5581
        | '.' ident '.' ident
4853
5582
          {
4854
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5583
            Session *session= YYSession;
 
5584
            LEX *lex= session->lex;
 
5585
            Select_Lex *sel= lex->current_select;
 
5586
            if (sel->no_table_names_allowed)
 
5587
            {
 
5588
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5589
                       MYF(0), $2.str, session->where);
 
5590
            }
 
5591
            $$= (sel->parsing_place != IN_HAVING ||
 
5592
                sel->get_in_sum_expr() > 0) ?
 
5593
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5594
                (Item*) new Item_ref(Lex->current_context(),
 
5595
                                     (const char *)NULL, $2.str, $4.str);
4855
5596
          }
4856
5597
        | ident '.' ident '.' ident
4857
5598
          {
4858
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5599
            Session *session= YYSession;
 
5600
            LEX *lex= session->lex;
 
5601
            Select_Lex *sel= lex->current_select;
 
5602
            if (sel->no_table_names_allowed)
 
5603
            {
 
5604
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5605
                       MYF(0), $3.str, session->where);
 
5606
            }
 
5607
            $$= (sel->parsing_place != IN_HAVING ||
 
5608
                sel->get_in_sum_expr() > 0) ?
 
5609
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5610
                                       $5.str) :
 
5611
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5612
                                     $5.str);
4859
5613
          }
4860
5614
        ;
4861
5615
 
4862
5616
field_ident:
4863
 
          ident 
4864
 
          {
4865
 
            $$=$1;
4866
 
          }
 
5617
          ident { $$=$1;}
4867
5618
        | ident '.' ident '.' ident
4868
5619
          {
4869
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4870
 
              DRIZZLE_YYABORT;
4871
 
 
 
5620
            TableList *table=
 
5621
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5622
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5623
            {
 
5624
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5625
              DRIZZLE_YYABORT;
 
5626
            }
 
5627
            if (my_strcasecmp(table_alias_charset, $3.str,
 
5628
                              table->table_name))
 
5629
            {
 
5630
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
5631
              DRIZZLE_YYABORT;
 
5632
            }
4872
5633
            $$=$5;
4873
5634
          }
4874
5635
        | ident '.' ident
4875
5636
          {
4876
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5637
            TableList *table=
 
5638
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5639
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
5640
            {
 
5641
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4877
5642
              DRIZZLE_YYABORT;
4878
 
 
 
5643
            }
4879
5644
            $$=$3;
4880
5645
          }
4881
 
        | '.' ident 
4882
 
          { /* For Delphi */
4883
 
            $$=$2;
4884
 
          }
 
5646
        | '.' ident { $$=$2;} /* For Delphi */
4885
5647
        ;
4886
5648
 
4887
5649
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
 
5650
          ident { $$=new Table_ident($1); }
 
5651
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
5652
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4908
5653
        ;
4909
5654
 
4910
5655
IDENT_sys:
4911
 
          IDENT 
4912
 
          {
4913
 
            $$= $1;
4914
 
          }
 
5656
          IDENT { $$= $1; }
4915
5657
        | IDENT_QUOTED
4916
5658
          {
4917
5659
            const CHARSET_INFO * const cs= system_charset_info;
4954
5696
          IDENT_sys    { $$=$1; }
4955
5697
        | keyword
4956
5698
          {
4957
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
5699
            Session *session= YYSession;
 
5700
            $$.str= session->strmake($1.str, $1.length);
4958
5701
            $$.length= $1.length;
4959
5702
          }
4960
5703
        ;
4961
5704
 
4962
5705
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          {}
 
5706
          ident           { $$=$1;}
 
5707
        | TEXT_STRING_sys { $$=$1;}
 
5708
        | LEX_HOSTNAME { $$=$1;}
4976
5709
        ;
4977
5710
 
4978
5711
/* Keyword that we allow for identifiers (except SP labels) */
4979
5712
keyword:
4980
5713
          keyword_sp            {}
4981
5714
        | BEGIN_SYM             {}
 
5715
        | BYTE_SYM              {}
4982
5716
        | CHECKSUM_SYM          {}
4983
5717
        | CLOSE_SYM             {}
4984
5718
        | COMMENT_SYM           {}
4985
5719
        | COMMIT_SYM            {}
4986
5720
        | CONTAINS_SYM          {}
4987
5721
        | DEALLOCATE_SYM        {}
4988
 
        | DO_SYM                {}
4989
5722
        | END                   {}
4990
5723
        | FLUSH_SYM             {}
4991
5724
        | NO_SYM                {}
4994
5727
        | SAVEPOINT_SYM         {}
4995
5728
        | SECURITY_SYM          {}
4996
5729
        | SERVER_SYM            {}
4997
 
        | SIGNED_SYM            {}
4998
5730
        | START_SYM             {}
4999
5731
        | STOP_SYM              {}
5000
5732
        | TRUNCATE_SYM          {}
5014
5746
        | ANY_SYM                  {}
5015
5747
        | AT_SYM                   {}
5016
5748
        | AUTO_INC                 {}
 
5749
        | AVG_ROW_LENGTH           {}
5017
5750
        | AVG_SYM                  {}
5018
5751
        | BIT_SYM                  {}
 
5752
        | BLOCK_SIZE_SYM           {}
 
5753
        | BLOCK_SYM                {}
5019
5754
        | BOOL_SYM                 {}
5020
5755
        | BOOLEAN_SYM              {}
5021
5756
        | BTREE_SYM                {}
5023
5758
        | CHAIN_SYM                {}
5024
5759
        | COALESCE                 {}
5025
5760
        | COLLATION_SYM            {}
 
5761
        | COLUMN_FORMAT_SYM        {}
5026
5762
        | COLUMNS                  {}
5027
5763
        | COMMITTED_SYM            {}
5028
5764
        | COMPACT_SYM              {}
5029
5765
        | COMPRESSED_SYM           {}
5030
5766
        | CONCURRENT               {}
5031
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
5767
        | CONNECTION_SYM           {}
5032
5768
        | CONSISTENT_SYM           {}
5033
5769
        | CUBE_SYM                 {}
5034
5770
        | DATA_SYM                 {}
5035
5771
        | DATABASES                {}
 
5772
        | DATAFILE_SYM             {}
5036
5773
        | DATETIME_SYM             {}
5037
 
        | DATE_SYM                 {} /* Create conflict */
 
5774
        | DATE_SYM                 {}
5038
5775
        | DAY_SYM                  {}
5039
5776
        | DISABLE_SYM              {}
5040
5777
        | DISCARD                  {}
5065
5802
        | KEY_BLOCK_SIZE           {}
5066
5803
        | LAST_SYM                 {}
5067
5804
        | LEVEL_SYM                {}
 
5805
        | LIST_SYM                 {}
5068
5806
        | LOCAL_SYM                {}
5069
5807
        | LOCKS_SYM                {}
5070
5808
        | LOGS_SYM                 {}
 
5809
        | MAX_ROWS                 {}
 
5810
        | MAX_SIZE_SYM             {}
5071
5811
        | MAX_VALUE_SYM            {}
5072
5812
        | MEDIUM_SYM               {}
5073
5813
        | MERGE_SYM                {}
5074
5814
        | MICROSECOND_SYM          {}
5075
5815
        | MINUTE_SYM               {}
 
5816
        | MIN_ROWS                 {}
5076
5817
        | MODIFY_SYM               {}
5077
5818
        | MODE_SYM                 {}
5078
5819
        | MONTH_SYM                {}
5087
5828
        | ONE_SHOT_SYM             {}
5088
5829
        | ONE_SYM                  {}
5089
5830
        | ONLINE_SYM               {}
 
5831
        | PAGE_SYM                 {}
5090
5832
        | PARTIAL                  {}
 
5833
        | PHASE_SYM                {}
5091
5834
        | PREV_SYM                 {}
5092
5835
        | PROCESS                  {}
5093
5836
        | PROCESSLIST_SYM          {}
5094
5837
        | QUARTER_SYM              {}
5095
 
        | QUERY_SYM                {} // Causes conflict
 
5838
        | QUERY_SYM                {}
 
5839
        | READ_ONLY_SYM            {}
5096
5840
        | REDUNDANT_SYM            {}
5097
5841
        | REPEATABLE_SYM           {}
5098
5842
        | RETURNS_SYM              {}
 
5843
        | REVERSE_SYM              {}
5099
5844
        | ROLLUP_SYM               {}
5100
5845
        | ROUTINE_SYM              {}
5101
5846
        | ROWS_SYM                 {}
5107
5852
        | SESSION_SYM              {}
5108
5853
        | SIMPLE_SYM               {}
5109
5854
        | SHARE_SYM                {}
 
5855
        | SHUTDOWN                 {}
5110
5856
        | SNAPSHOT_SYM             {}
 
5857
        | SQL_BUFFER_RESULT        {}
5111
5858
        | STATUS_SYM               {}
 
5859
        | STORAGE_SYM              {}
5112
5860
        | STRING_SYM               {}
5113
5861
        | SUBDATE_SYM              {}
5114
5862
        | SUBJECT_SYM              {}
5115
5863
        | SUSPEND_SYM              {}
 
5864
        | SWAPS_SYM                {}
 
5865
        | SWITCHES_SYM             {}
5116
5866
        | TABLES                   {}
5117
5867
        | TABLESPACE               {}
5118
5868
        | TEMPORARY_SYM            {}
5119
5869
        | TEXT_SYM                 {}
5120
5870
        | TRANSACTION_SYM          {}
5121
 
        | TIME_SYM                 {}
 
5871
        | TIMESTAMP_SYM            {}
5122
5872
        | TIMESTAMP_ADD            {}
5123
5873
        | TIMESTAMP_DIFF           {}
 
5874
        | TYPES_SYM                {}
5124
5875
        | TYPE_SYM                 {}
5125
5876
        | UNCOMMITTED_SYM          {}
5126
5877
        | UNDOFILE_SYM             {}
5127
5878
        | UNKNOWN_SYM              {}
5128
 
        | UUID_SYM                 {}
5129
5879
        | USER                     {}
5130
5880
        | VARIABLES                {}
5131
5881
        | VALUE_SYM                {}
5138
5888
/* Option functions */
5139
5889
 
5140
5890
set:
5141
 
          SET_SYM opt_option
 
5891
          SET opt_option
5142
5892
          {
5143
 
            Lex->statement= new statement::SetOption(YYSession);
 
5893
            LEX *lex=Lex;
 
5894
            lex->sql_command= SQLCOM_SET_OPTION;
 
5895
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
5896
            lex->statement= statement;
 
5897
            if (lex->statement == NULL)
 
5898
              DRIZZLE_YYABORT;
 
5899
            mysql_init_select(lex);
 
5900
            lex->option_type=OPT_SESSION;
 
5901
            lex->var_list.empty();
5144
5902
          }
5145
5903
          option_value_list
5146
5904
          {}
5157
5915
        ;
5158
5916
 
5159
5917
option_type_value:
5160
 
          { }
 
5918
          {
 
5919
          }
5161
5920
          ext_option_value
5162
 
          { }
 
5921
          {
 
5922
          }
5163
5923
        ;
5164
5924
 
5165
5925
option_type:
5196
5956
sys_option_value:
5197
5957
          option_type internal_variable_name equal set_expr_or_default
5198
5958
          {
 
5959
            LEX *lex=Lex;
 
5960
 
5199
5961
            if ($2.var)
5200
5962
            { /* System variable */
5201
5963
              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)));
 
5964
                lex->option_type= $1;
 
5965
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
5966
                                      &$2.base_name, $4));
5206
5967
            }
5207
5968
          }
5208
5969
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5209
5970
          {
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))));
 
5971
            LEX *lex=Lex;
 
5972
            lex->option_type= $1;
 
5973
            lex->var_list.push_back(new set_var(lex->option_type,
 
5974
                                                find_sys_var(YYSession, "tx_isolation"),
 
5975
                                                &null_lex_str,
 
5976
                                                new Item_int((int32_t) $5)));
5216
5977
          }
5217
5978
        ;
5218
5979
 
5219
5980
option_value:
5220
 
          '@' user_variable_ident equal expr
 
5981
          '@' ident_or_text equal expr
5221
5982
          {
5222
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
5983
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5223
5984
          }
5224
5985
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5225
5986
          {
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; }
 
5987
            LEX *lex=Lex;
 
5988
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
5989
          }
5243
5990
        ;
5244
5991
 
5245
5992
internal_variable_name:
5246
 
          internal_variable_ident
 
5993
          ident
5247
5994
          {
 
5995
            Session *session= YYSession;
 
5996
 
5248
5997
            /* We have to lookup here since local vars can shadow sysvars */
5249
5998
            {
5250
5999
              /* Not an SP local variable */
5251
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6000
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
5252
6001
              if (!tmp)
5253
6002
                DRIZZLE_YYABORT;
5254
6003
              $$.var= tmp;
5280
6029
unlock:
5281
6030
          UNLOCK_SYM
5282
6031
          {
5283
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6032
            LEX *lex= Lex;
 
6033
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6034
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6035
            if (lex->statement == NULL)
 
6036
              DRIZZLE_YYABORT;
5284
6037
          }
5285
6038
          table_or_tables
5286
6039
          {}
5289
6042
begin:
5290
6043
          BEGIN_SYM
5291
6044
          {
5292
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6045
            LEX *lex=Lex;
 
6046
            lex->sql_command = SQLCOM_BEGIN;
 
6047
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6048
            if (lex->statement == NULL)
 
6049
              DRIZZLE_YYABORT;
5293
6050
          }
5294
6051
          opt_work {}
5295
6052
        ;
5321
6078
commit:
5322
6079
          COMMIT_SYM opt_work opt_chain opt_release
5323
6080
          {
5324
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6081
            LEX *lex=Lex;
 
6082
            lex->sql_command= SQLCOM_COMMIT;
 
6083
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6084
            lex->statement= statement;
 
6085
            if (lex->statement == NULL)
 
6086
              DRIZZLE_YYABORT;
 
6087
            statement->tx_chain= $3;
 
6088
            statement->tx_release= $4;
5325
6089
          }
5326
6090
        ;
5327
6091
 
5328
6092
rollback:
5329
6093
          ROLLBACK_SYM opt_work opt_chain opt_release
5330
6094
          {
5331
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6095
            LEX *lex=Lex;
 
6096
            lex->sql_command= SQLCOM_ROLLBACK;
 
6097
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6098
            lex->statement= statement;
 
6099
            if (lex->statement == NULL)
 
6100
              DRIZZLE_YYABORT;
 
6101
            statement->tx_chain= $3;
 
6102
            statement->tx_release= $4;
5332
6103
          }
5333
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6104
        | ROLLBACK_SYM opt_work
 
6105
          TO_SYM opt_savepoint ident
5334
6106
          {
5335
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6107
            LEX *lex=Lex;
 
6108
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6109
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6110
            if (lex->statement == NULL)
 
6111
              DRIZZLE_YYABORT;
 
6112
            lex->ident= $5;
5336
6113
          }
5337
6114
        ;
5338
6115
 
5339
6116
savepoint:
5340
 
          SAVEPOINT_SYM savepoint_ident
 
6117
          SAVEPOINT_SYM ident
5341
6118
          {
5342
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6119
            LEX *lex=Lex;
 
6120
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6121
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6122
            if (lex->statement == NULL)
 
6123
              DRIZZLE_YYABORT;
 
6124
            lex->ident= $2;
5343
6125
          }
5344
6126
        ;
5345
6127
 
5346
6128
release:
5347
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6129
          RELEASE_SYM SAVEPOINT_SYM ident
5348
6130
          {
5349
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6131
            LEX *lex=Lex;
 
6132
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6133
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6134
            if (lex->statement == NULL)
 
6135
              DRIZZLE_YYABORT;
 
6136
            lex->ident= $3;
5350
6137
          }
5351
6138
        ;
5352
6139
 
5353
 
savepoint_ident:
5354
 
               IDENT_sys
5355
 
               ;
5356
 
 
5357
6140
/*
5358
6141
   UNIONS : glue selects together
5359
6142
*/
5367
6150
union_list:
5368
6151
          UNION_SYM union_option
5369
6152
          {
5370
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6153
            if (add_select_to_union_list(Lex, (bool)$2))
5371
6154
              DRIZZLE_YYABORT;
5372
6155
          }
5373
6156
          select_init
5388
6171
 
5389
6172
union_order_or_limit:
5390
6173
          {
5391
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5392
 
            Select_Lex *sel= Lex->current_select;
 
6174
            Session *session= YYSession;
 
6175
            LEX *lex= session->lex;
 
6176
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6177
            Select_Lex *sel= lex->current_select;
5393
6178
            Select_Lex_Unit *unit= sel->master_unit();
5394
6179
            Select_Lex *fake= unit->fake_select_lex;
5395
6180
            if (fake)
5396
6181
            {
5397
6182
              unit->global_parameters= fake;
5398
6183
              fake->no_table_names_allowed= 1;
5399
 
              Lex->current_select= fake;
 
6184
              lex->current_select= fake;
5400
6185
            }
5401
 
            YYSession->setWhere("global ORDER clause");
 
6186
            session->where= "global ORDER clause";
5402
6187
          }
5403
6188
          order_or_limit
5404
6189
          {
5405
 
            YYSession->getLex()->current_select->no_table_names_allowed= 0;
5406
 
            YYSession->setWhere("");
 
6190
            Session *session= YYSession;
 
6191
            session->lex->current_select->no_table_names_allowed= 0;
 
6192
            session->where= "";
5407
6193
          }
5408
6194
        ;
5409
6195
 
5434
6220
        | query_expression_body
5435
6221
          UNION_SYM union_option
5436
6222
          {
5437
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6223
            if (add_select_to_union_list(Lex, (bool)$3))
5438
6224
              DRIZZLE_YYABORT;
5439
6225
          }
5440
6226
          query_specification
5454
6240
 
5455
6241
subselect_start:
5456
6242
          {
5457
 
            if (not Lex->expr_allows_subselect)
 
6243
            LEX *lex=Lex;
 
6244
            if (!lex->expr_allows_subselect)
5458
6245
            {
5459
 
              parser::my_parse_error(YYSession->m_lip);
 
6246
              my_parse_error(ER(ER_SYNTAX_ERROR));
5460
6247
              DRIZZLE_YYABORT;
5461
6248
            }
5462
6249
            /*
5466
6253
              (SELECT .. ) UNION ...  becomes
5467
6254
              SELECT * FROM ((SELECT ...) UNION ...)
5468
6255
            */
5469
 
            if (new_select(Lex, 1))
 
6256
            if (mysql_new_select(Lex, 1))
5470
6257
              DRIZZLE_YYABORT;
5471
6258
          }
5472
6259
        ;
5473
6260
 
5474
6261
subselect_end:
5475
6262
          {
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;
 
6263
            LEX *lex=Lex;
 
6264
            lex->pop_context();
 
6265
            Select_Lex *child= lex->current_select;
 
6266
            lex->current_select = lex->current_select->return_after_parsing();
 
6267
            lex->nest_level--;
 
6268
            lex->current_select->n_child_sum_items += child->n_sum_items;
5481
6269
            /*
5482
6270
              A subselect can add fields to an outer select. Reserve space for
5483
6271
              them.
5484
6272
            */
5485
 
            Lex->current_select->select_n_where_fields+=
 
6273
            lex->current_select->select_n_where_fields+=
5486
6274
            child->select_n_where_fields;
5487
6275
          }
5488
6276
        ;