~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2010-08-09 18:04:12 UTC
  • mfrom: (1689.3.7 staging)
  • Revision ID: brian@gaz-20100809180412-olurwh51ojllev6p
Merge in heap conversion, and case insensitive patch, and remove need for
M_HASH in session.

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())
 
38
#define Lex (YYSession->lex)
37
39
 
38
 
#include <config.h>
 
40
#include "config.h"
39
41
#include <cstdio>
40
 
#include <drizzled/parser.h>
 
42
#include "drizzled/parser.h"
41
43
 
42
 
int yylex(union ParserType *yylval, drizzled::Session *session);
 
44
int yylex(void *yylval, void *yysession);
43
45
 
44
46
#define yyoverflow(A,B,C,D,E,F)               \
45
47
  {                                           \
46
 
    unsigned long val= *(F);                          \
 
48
    ulong val= *(F);                          \
47
49
    if (drizzled::my_yyoverflow((B), (D), &val)) \
48
50
    {                                         \
49
 
      yyerror(NULL, (char*) (A));                   \
 
51
      yyerror((char*) (A));                   \
50
52
      return 2;                               \
51
53
    }                                         \
52
54
    else                                      \
58
60
#define DRIZZLE_YYABORT                         \
59
61
  do                                          \
60
62
  {                                           \
 
63
    LEX::cleanup_lex_after_parse_error(YYSession);\
61
64
    YYABORT;                                  \
62
65
  } while (0)
63
66
 
64
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
65
68
  if (!(A))                             \
66
69
  {                                     \
67
 
    parser::my_parse_error(YYSession->m_lip);\
 
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    my_parse_error(&pass);\
68
72
    DRIZZLE_YYABORT;                      \
69
73
  }
70
74
 
 
75
 
 
76
#define YYDEBUG 0
 
77
 
71
78
namespace drizzled
72
79
{
73
80
 
75
82
class Item;
76
83
class Item_num;
77
84
 
78
 
namespace item
79
 
{
80
 
class Boolean;
81
 
class True;
82
 
class False;
83
 
}
84
 
 
 
85
 
 
86
static bool check_reserved_words(LEX_STRING *name)
 
87
{
 
88
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
 
89
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
 
90
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
 
91
    return true;
 
92
  return false;
 
93
}
 
94
 
 
95
/**
 
96
  @brief Push an error message into MySQL error stack with line
 
97
  and position information.
 
98
 
 
99
  This function provides semantic action implementers with a way
 
100
  to push the famous "You have a syntax error near..." error
 
101
  message into the error stack, which is normally produced only if
 
102
  a parse error is discovered internally by the Bison generated
 
103
  parser.
 
104
*/
 
105
 
 
106
struct my_parse_error_st {
 
107
  const char *s;
 
108
  Session *session;
 
109
};
 
110
 
 
111
static void my_parse_error(void *arg)
 
112
{
 
113
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
 
114
 
 
115
  const char *s= ptr->s;
 
116
  Session *session= ptr->session;
 
117
 
 
118
  Lex_input_stream *lip= session->m_lip;
 
119
 
 
120
  const char *yytext= lip->get_tok_start();
 
121
  /* Push an error into the error stack */
 
122
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
123
                  (yytext ? yytext : ""),
 
124
                  lip->yylineno);
 
125
}
85
126
 
86
127
/**
87
128
  @brief Bison callback to report a syntax/OOM error
98
139
 
99
140
  This function is not for use in semantic actions and is internal to
100
141
  the parser, as it performs some pre-return cleanup.
101
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
142
  In semantic actions, please use my_parse_error or my_error to
102
143
  push an error into the error stack and DRIZZLE_YYABORT
103
144
  to abort from the parser.
104
145
*/
105
146
 
106
 
static void base_sql_error(drizzled::Session *session, const char *s)
107
 
{
108
 
  parser::errorOn(session, s);
 
147
static void DRIZZLEerror(const char *s)
 
148
{
 
149
  Session *session= current_session;
 
150
 
 
151
  /*
 
152
    Restore the original LEX if it was replaced when parsing
 
153
    a stored procedure. We must ensure that a parsing error
 
154
    does not leave any side effects in the Session.
 
155
  */
 
156
  LEX::cleanup_lex_after_parse_error(session);
 
157
 
 
158
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
159
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
160
    s= ER(ER_SYNTAX_ERROR);
 
161
 
 
162
  struct my_parse_error_st pass= { s, session };
 
163
  my_parse_error(&pass);
 
164
}
 
165
 
 
166
/**
 
167
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
168
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
169
  This function returns the proper item for the SQL expression
 
170
  <code>left [NOT] IN ( expr )</code>
 
171
  @param session the current thread
 
172
  @param left the in predicand
 
173
  @param equal true for IN predicates, false for NOT IN predicates
 
174
  @param expr first and only expression of the in value list
 
175
  @return an expression representing the IN predicate.
 
176
*/
 
177
static Item* handle_sql2003_note184_exception(Session *session,
 
178
                                              Item* left, bool equal,
 
179
                                              Item *expr)
 
180
{
 
181
  /*
 
182
    Relevant references for this issue:
 
183
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
184
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
185
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
186
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
187
    - SQL:2003 Feature F561, "Full value expressions".
 
188
 
 
189
    The exception in SQL:2003 Note 184 means:
 
190
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
191
    should be re-interpreted as an Item_in_subselect, which corresponds
 
192
    to a <table subquery> when used inside an <in predicate>.
 
193
 
 
194
    Our reading of Note 184 is reccursive, so that all:
 
195
    - IN (( <subquery> ))
 
196
    - IN ((( <subquery> )))
 
197
    - IN '('^N <subquery> ')'^N
 
198
    - etc
 
199
    should be interpreted as a <table subquery>, no matter how deep in the
 
200
    expression the <subquery> is.
 
201
  */
 
202
 
 
203
  Item *result;
 
204
 
 
205
  if (expr->type() == Item::SUBSELECT_ITEM)
 
206
  {
 
207
    Item_subselect *expr2 = (Item_subselect*) expr;
 
208
 
 
209
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
210
    {
 
211
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
212
      Select_Lex *subselect;
 
213
 
 
214
      /*
 
215
        Implement the mandated change, by altering the semantic tree:
 
216
          left IN Item_singlerow_subselect(subselect)
 
217
        is modified to
 
218
          left IN (subselect)
 
219
        which is represented as
 
220
          Item_in_subselect(left, subselect)
 
221
      */
 
222
      subselect= expr3->invalidate_and_restore_select_lex();
 
223
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
224
 
 
225
      if (! equal)
 
226
        result = negate_expression(session, result);
 
227
 
 
228
      return(result);
 
229
    }
 
230
  }
 
231
 
 
232
  if (equal)
 
233
    result= new (session->mem_root) Item_func_eq(left, expr);
 
234
  else
 
235
    result= new (session->mem_root) Item_func_ne(left, expr);
 
236
 
 
237
  return(result);
 
238
}
 
239
 
 
240
/**
 
241
   @brief Creates a new Select_Lex for a UNION branch.
 
242
 
 
243
   Sets up and initializes a Select_Lex structure for a query once the parser
 
244
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
245
   the new Select_Lex becomes the current one..=
 
246
 
 
247
   @lex The parser state.
 
248
 
 
249
   @is_union_distinct True if the union preceding the new select statement
 
250
   uses UNION DISTINCT.
 
251
 
 
252
   @return <code>false</code> if successful, <code>true</code> if an error was
 
253
   reported. In the latter case parsing should stop.
 
254
 */
 
255
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
 
256
{
 
257
  if (lex->result)
 
258
  {
 
259
    /* Only the last SELECT can have  INTO...... */
 
260
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
261
    return true;
 
262
  }
 
263
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
264
  {
 
265
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
266
    my_parse_error(&pass);
 
267
    return true;
 
268
  }
 
269
  /* This counter shouldn't be incremented for UNION parts */
 
270
  lex->nest_level--;
 
271
  if (mysql_new_select(lex, 0))
 
272
    return true;
 
273
  mysql_init_select(lex);
 
274
  lex->current_select->linkage=UNION_TYPE;
 
275
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
276
    lex->current_select->master_unit()->union_distinct=
 
277
      lex->current_select;
 
278
  return false;
 
279
}
 
280
 
 
281
/**
 
282
   @brief Initializes a Select_Lex for a query within parentheses (aka
 
283
   braces).
 
284
 
 
285
   @return false if successful, true if an error was reported. In the latter
 
286
   case parsing should stop.
 
287
 */
 
288
static bool setup_select_in_parentheses(Session *session, LEX *lex)
 
289
{
 
290
  Select_Lex * sel= lex->current_select;
 
291
  if (sel->set_braces(1))
 
292
  {
 
293
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
294
    my_parse_error(&pass);
 
295
    return true;
 
296
  }
 
297
  if (sel->linkage == UNION_TYPE &&
 
298
      !sel->master_unit()->first_select()->braces &&
 
299
      sel->master_unit()->first_select()->linkage ==
 
300
      UNION_TYPE)
 
301
  {
 
302
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
303
    my_parse_error(&pass);
 
304
    return true;
 
305
  }
 
306
  if (sel->linkage == UNION_TYPE &&
 
307
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
308
      sel->master_unit()->fake_select_lex)
 
309
  {
 
310
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
311
    return true;
 
312
  }
 
313
  /* select in braces, can't contain global parameters */
 
314
  if (sel->master_unit()->fake_select_lex)
 
315
    sel->master_unit()->global_parameters=
 
316
      sel->master_unit()->fake_select_lex;
 
317
  return false;
 
318
}
 
319
 
 
320
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
 
321
{
 
322
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
 
323
  Item *item= NULL;
 
324
 
 
325
  if (udf)
 
326
  {
 
327
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
 
328
  } else {
 
329
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
330
  }
 
331
 
 
332
  return item;
109
333
}
110
334
 
111
335
} /* namespace drizzled; */
112
336
 
113
337
using namespace drizzled;
114
338
%}
115
 
%union ParserType {
116
 
  bool boolean;
 
339
%union {
117
340
  int  num;
118
 
  unsigned long ulong_num;
 
341
  ulong ulong_num;
119
342
  uint64_t ulonglong_number;
120
343
  int64_t longlong_number;
121
344
  drizzled::LEX_STRING lex_str;
131
354
  drizzled::Key_part_spec *key_part;
132
355
  const drizzled::plugin::Function *udf;
133
356
  drizzled::TableList *table_list;
134
 
  drizzled::enum_field_types field_val;
135
 
  drizzled::sys_var_with_base variable;
136
 
  drizzled::sql_var_t var_type;
 
357
  struct drizzled::sys_var_with_base variable;
 
358
  enum drizzled::sql_var_t var_type;
137
359
  drizzled::Key::Keytype key_type;
138
 
  drizzled::ha_key_alg key_alg;
139
 
  drizzled::ha_rkey_function ha_rkey_mode;
140
 
  drizzled::enum_tx_isolation tx_isolation;
141
 
  drizzled::Cast_target cast_type;
 
360
  enum drizzled::ha_key_alg key_alg;
 
361
  enum drizzled::column_format_type column_format_type;
 
362
  enum drizzled::ha_rkey_function ha_rkey_mode;
 
363
  enum drizzled::enum_tx_isolation tx_isolation;
 
364
  enum drizzled::Cast_target cast_type;
142
365
  const drizzled::CHARSET_INFO *charset;
143
366
  drizzled::thr_lock_type lock_type;
144
367
  drizzled::interval_type interval, interval_time_st;
145
 
  drizzled::type::timestamp_t date_time_type;
 
368
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
146
369
  drizzled::Select_Lex *select_lex;
147
370
  drizzled::chooser_compare_func_creator boolfunc2creator;
148
 
  drizzled::st_lex *lex;
149
 
  drizzled::index_hint_type index_hint;
150
 
  drizzled::enum_filetype filetype;
151
 
  drizzled::ha_build_method build_method;
152
 
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
153
 
  drizzled::execute_string_t execute_string;
 
371
  struct drizzled::st_lex *lex;
 
372
  enum drizzled::index_hint_type index_hint;
 
373
  enum drizzled::enum_filetype filetype;
 
374
  enum drizzled::ha_build_method build_method;
 
375
  enum drizzled::Foreign_key::fk_option m_fk_option;
154
376
}
155
377
 
156
378
%{
157
379
namespace drizzled
158
380
{
159
 
bool my_yyoverflow(short **a, union ParserType **b, unsigned long *yystacksize);
 
381
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
160
382
}
161
383
%}
162
384
 
163
 
%debug
164
 
%require "2.2"
165
 
%pure-parser
166
 
%name-prefix="base_sql_"
167
 
%parse-param { drizzled::Session *session }
168
 
%lex-param { drizzled::Session *session }
169
 
%verbose
170
 
 
171
 
 
 
385
%pure_parser                                    /* We have threads */
172
386
/*
173
 
  Currently there are 70 shift/reduce conflicts.
 
387
  Currently there are 88 shift/reduce conflicts.
174
388
  We should not introduce new conflicts any more.
175
389
*/
176
 
%expect 70
 
390
%expect 94
177
391
 
178
392
/*
179
393
   Comments for TOKENS.
194
408
 
195
409
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
196
410
%token  ACTION                        /* SQL-2003-N */
197
 
%token  ADD_SYM                           /* SQL-2003-R */
 
411
%token  ADD                           /* SQL-2003-R */
198
412
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
199
413
%token  AFTER_SYM                     /* SQL-2003-N */
200
414
%token  AGGREGATE_SYM
201
415
%token  ALL                           /* SQL-2003-R */
202
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
416
%token  ALTER                         /* SQL-2003-R */
203
417
%token  ANALYZE_SYM
204
418
%token  AND_SYM                       /* SQL-2003-R */
205
419
%token  ANY_SYM                       /* SQL-2003-R */
208
422
%token  ASENSITIVE_SYM                /* FUTURE-USE */
209
423
%token  AT_SYM                        /* SQL-2003-R */
210
424
%token  AUTO_INC
 
425
%token  AVG_ROW_LENGTH
211
426
%token  AVG_SYM                       /* SQL-2003-N */
212
427
%token  BEFORE_SYM                    /* SQL-2003-N */
213
428
%token  BEGIN_SYM                     /* SQL-2003-R */
222
437
%token  BOTH                          /* SQL-2003-R */
223
438
%token  BTREE_SYM
224
439
%token  BY                            /* SQL-2003-R */
 
440
%token  BYTE_SYM
225
441
%token  CALL_SYM                      /* SQL-2003-R */
226
442
%token  CASCADE                       /* SQL-2003-N */
227
443
%token  CASCADED                      /* SQL-2003-R */
228
444
%token  CASE_SYM                      /* SQL-2003-R */
229
445
%token  CAST_SYM                      /* SQL-2003-R */
230
 
%token  CATALOG_SYM
231
446
%token  CHAIN_SYM                     /* SQL-2003-N */
232
 
%token  CHANGE_SYM
 
447
%token  CHANGE
233
448
%token  CHAR_SYM                      /* SQL-2003-R */
234
449
%token  CHECKSUM_SYM
235
450
%token  CHECK_SYM                     /* SQL-2003-R */
250
465
%token  CONSISTENT_SYM
251
466
%token  CONSTRAINT                    /* SQL-2003-R */
252
467
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
468
%token  CONTINUE_SYM                  /* SQL-2003-R */
253
469
%token  CONVERT_SYM                   /* SQL-2003-N */
254
470
%token  COUNT_SYM                     /* SQL-2003-N */
255
471
%token  CREATE                        /* SQL-2003-R */
260
476
%token  CURSOR_SYM                    /* SQL-2003-R */
261
477
%token  DATABASE
262
478
%token  DATABASES
 
479
%token  DATAFILE_SYM
263
480
%token  DATA_SYM                      /* SQL-2003-N */
264
481
%token  DATETIME_SYM
265
482
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
283
500
%token  DISCARD
284
501
%token  DISTINCT                      /* SQL-2003-R */
285
502
%token  DIV_SYM
286
 
%token  DO_SYM
287
503
%token  DOUBLE_SYM                    /* SQL-2003-R */
288
504
%token  DROP                          /* SQL-2003-R */
289
505
%token  DUMPFILE
291
507
%token  DYNAMIC_SYM                   /* SQL-2003-R */
292
508
%token  EACH_SYM                      /* SQL-2003-R */
293
509
%token  ELSE                          /* SQL-2003-R */
 
510
%token  ELSEIF_SYM
294
511
%token  ENABLE_SYM
295
512
%token  ENCLOSED
296
513
%token  END                           /* SQL-2003-R */
298
515
%token  END_OF_INPUT                  /* INTERNAL */
299
516
%token  ENGINE_SYM
300
517
%token  ENUM_SYM
 
518
%token  EQ                            /* OPERATOR */
301
519
%token  EQUAL_SYM                     /* OPERATOR */
302
520
%token  ERRORS
303
521
%token  ESCAPED
304
522
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
523
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
307
524
%token  EXISTS                        /* SQL-2003-R */
308
525
%token  EXTENDED_SYM
309
526
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
527
%token  FALSE_SYM                     /* SQL-2003-R */
 
528
%token  FETCH_SYM                     /* SQL-2003-R */
 
529
%token  COLUMN_FORMAT_SYM
311
530
%token  FILE_SYM
312
531
%token  FIRST_SYM                     /* SQL-2003-N */
313
532
%token  FIXED_SYM
324
543
%token  GLOBAL_SYM                    /* SQL-2003-R */
325
544
%token  GROUP_SYM                     /* SQL-2003-R */
326
545
%token  GROUP_CONCAT_SYM
 
546
%token  GT_SYM                        /* OPERATOR */
327
547
%token  HASH_SYM
328
548
%token  HAVING                        /* SQL-2003-R */
329
549
%token  HEX_NUM
333
553
%token  HOUR_SYM                      /* SQL-2003-R */
334
554
%token  IDENT
335
555
%token  IDENTIFIED_SYM
336
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
337
556
%token  IDENT_QUOTED
338
557
%token  IF
339
558
%token  IGNORE_SYM
366
585
%token  LIKE                          /* SQL-2003-R */
367
586
%token  LIMIT
368
587
%token  LINES
 
588
%token  LIST_SYM
369
589
%token  LOAD
370
590
%token  LOCAL_SYM                     /* SQL-2003-R */
 
591
%token  LOCATOR_SYM                   /* SQL-2003-N */
371
592
%token  LOCKS_SYM
372
593
%token  LOCK_SYM
373
594
%token  LOGS_SYM
374
595
%token  LONG_NUM
375
596
%token  LONG_SYM
 
597
%token  LOOP_SYM
 
598
%token  LT                            /* OPERATOR */
376
599
%token  MATCH                         /* SQL-2003-R */
 
600
%token  MAX_ROWS
 
601
%token  MAX_SIZE_SYM
377
602
%token  MAX_SYM                       /* SQL-2003-N */
378
603
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
379
604
%token  MEDIUM_SYM
382
607
%token  MINUTE_MICROSECOND_SYM
383
608
%token  MINUTE_SECOND_SYM
384
609
%token  MINUTE_SYM                    /* SQL-2003-R */
 
610
%token  MIN_ROWS
385
611
%token  MIN_SYM                       /* SQL-2003-N */
386
612
%token  MODE_SYM
387
613
%token  MODIFIES_SYM                  /* SQL-2003-R */
393
619
%token  NATIONAL_SYM                  /* SQL-2003-R */
394
620
%token  NATURAL                       /* SQL-2003-R */
395
621
%token  NE                            /* OPERATOR */
 
622
%token  NEG
396
623
%token  NEW_SYM                       /* SQL-2003-R */
397
624
%token  NEXT_SYM                      /* SQL-2003-N */
398
625
%token  NONE_SYM                      /* SQL-2003-R */
417
644
%token  OUTER
418
645
%token  OUTFILE
419
646
%token  OUT_SYM                       /* SQL-2003-R */
 
647
%token  PAGE_SYM
420
648
%token  PARTIAL                       /* SQL-2003-N */
 
649
%token  PHASE_SYM
421
650
%token  POSITION_SYM                  /* SQL-2003-N */
422
651
%token  PRECISION                     /* SQL-2003-R */
423
652
%token  PREV_SYM
428
657
%token  QUERY_SYM
429
658
%token  RANGE_SYM                     /* SQL-2003-R */
430
659
%token  READS_SYM                     /* SQL-2003-R */
 
660
%token  READ_ONLY_SYM
431
661
%token  READ_SYM                      /* SQL-2003-N */
432
662
%token  READ_WRITE_SYM
433
663
%token  REAL                          /* SQL-2003-R */
434
664
%token  REDUNDANT_SYM
435
 
%token  REGEXP_SYM
436
665
%token  REFERENCES                    /* SQL-2003-R */
437
666
%token  RELEASE_SYM                   /* SQL-2003-R */
438
667
%token  RENAME
439
668
%token  REPEATABLE_SYM                /* SQL-2003-N */
440
669
%token  REPEAT_SYM                    /* MYSQL-FUNC */
441
670
%token  REPLACE                       /* MYSQL-FUNC */
442
 
%token  REPLICATION
443
671
%token  RESTRICT
444
672
%token  RETURNS_SYM                   /* SQL-2003-R */
445
673
%token  RETURN_SYM                    /* SQL-2003-R */
 
674
%token  REVERSE_SYM
446
675
%token  REVOKE                        /* SQL-2003-R */
447
676
%token  RIGHT                         /* SQL-2003-R */
448
677
%token  ROLLBACK_SYM                  /* SQL-2003-R */
462
691
%token  SERIAL_SYM
463
692
%token  SESSION_SYM                   /* SQL-2003-N */
464
693
%token  SERVER_SYM
465
 
%token  SET_SYM                           /* SQL-2003-R */
 
694
%token  SERVER_OPTIONS
 
695
%token  SET                           /* SQL-2003-R */
466
696
%token  SET_VAR
467
697
%token  SHARE_SYM
468
698
%token  SHOW
469
 
%token  SIGNED_SYM
 
699
%token  SHUTDOWN
470
700
%token  SIMPLE_SYM                    /* SQL-2003-N */
471
701
%token  SNAPSHOT_SYM
472
702
%token  SPECIFIC_SYM                  /* SQL-2003-R */
484
714
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
485
715
%token  STD_SYM
486
716
%token  STOP_SYM
 
717
%token  STORAGE_SYM
487
718
%token  STORED_SYM
488
719
%token  STRAIGHT_JOIN
489
720
%token  STRING_SYM
492
723
%token  SUBSTRING                     /* SQL-2003-N */
493
724
%token  SUM_SYM                       /* SQL-2003-N */
494
725
%token  SUSPEND_SYM
 
726
%token  SWAPS_SYM
 
727
%token  SWITCHES_SYM
495
728
%token  SYSDATE
496
729
%token  TABLES
497
730
%token  TABLESPACE
502
735
%token  TEXT_STRING
503
736
%token  TEXT_SYM
504
737
%token  THEN_SYM                      /* SQL-2003-R */
505
 
%token  TIME_SYM                 /* SQL-2003-R */
506
738
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
507
739
%token  TIMESTAMP_ADD
508
740
%token  TIMESTAMP_DIFF
512
744
%token  TRIM                          /* SQL-2003-N */
513
745
%token  TRUE_SYM                      /* SQL-2003-R */
514
746
%token  TRUNCATE_SYM
 
747
%token  TYPES_SYM
515
748
%token  TYPE_SYM                      /* SQL-2003-N */
516
749
%token  ULONGLONG_NUM
517
750
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
521
754
%token  UNIQUE_SYM
522
755
%token  UNKNOWN_SYM                   /* SQL-2003-R */
523
756
%token  UNLOCK_SYM
524
 
%token  UNSIGNED_SYM
525
757
%token  UPDATE_SYM                    /* SQL-2003-R */
526
758
%token  USAGE                         /* SQL-2003-N */
527
759
%token  USER                          /* SQL-2003-R */
529
761
%token  USING                         /* SQL-2003-R */
530
762
%token  UTC_DATE_SYM
531
763
%token  UTC_TIMESTAMP_SYM
532
 
%token  UUID_SYM
533
764
%token  VALUES                        /* SQL-2003-R */
534
765
%token  VALUE_SYM                     /* SQL-2003-R */
535
766
%token  VARBINARY
538
769
%token  VARIANCE_SYM
539
770
%token  VARYING                       /* SQL-2003-R */
540
771
%token  VAR_SAMP_SYM
541
 
%token  WAIT_SYM
542
772
%token  WARNINGS
543
773
%token  WEEK_SYM
544
774
%token  WHEN_SYM                      /* SQL-2003-R */
550
780
%token  XOR
551
781
%token  YEAR_MONTH_SYM
552
782
%token  YEAR_SYM                      /* SQL-2003-R */
553
 
%token  ZEROFILL_SYM
554
783
 
555
 
/* Lowest to highest */
556
784
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
557
785
/* A dummy token to force the priority of table_ref production in a join. */
558
 
%left  TABLE_REF_PRIORITY
559
 
%left  SET_VAR
560
 
%left  OR_SYM
561
 
%left  XOR
562
 
%left  AND_SYM
563
 
%right NOT_SYM
564
 
%right '='
565
 
%nonassoc EQUAL_SYM GE '>' LE '<' NE
566
 
%nonassoc LIKE REGEXP_SYM
567
 
%nonassoc BETWEEN_SYM
568
 
%nonassoc IN_SYM
569
 
%nonassoc IS NULL_SYM TRUE_SYM FALSE_SYM
 
786
%left   TABLE_REF_PRIORITY
 
787
%left   SET_VAR
 
788
%left   OR_SYM
 
789
%left   XOR
 
790
%left   AND_SYM
 
791
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
 
792
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
570
793
%left   '-' '+'
571
794
%left   '*' '/' '%' DIV_SYM MOD_SYM
 
795
%left   NEG
 
796
%right  NOT_SYM
572
797
%right  BINARY COLLATE_SYM
573
798
%left  INTERVAL_SYM
574
 
%right UMINUS
575
 
%left  '(' ')'
576
 
%left  '{' '}'
577
799
 
578
800
%type <lex_str>
579
801
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
580
 
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
581
 
        ident
582
 
        ident_or_text
583
 
        internal_variable_ident
584
 
        user_variable_ident
585
 
        row_format_or_text
 
802
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
586
803
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
587
 
        schema_name
588
 
        catalog_name
589
804
        opt_component
590
 
        engine_option_value
591
 
        savepoint_ident
592
 
        BIN_NUM TEXT_STRING_filesystem
 
805
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
593
806
        opt_constraint constraint opt_ident
594
807
 
595
 
%type <execute_string>
596
 
        execute_var_or_string
597
 
 
598
808
%type <lex_str_ptr>
599
809
        opt_table_alias
600
810
 
607
817
%type <string>
608
818
        text_string opt_gconcat_separator
609
819
 
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
 
820
%type <num>
 
821
        type int_type real_type order_dir field_def
 
822
        if_exists opt_table_options
620
823
        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
 
824
        opt_temporary all_or_any opt_distinct
630
825
        union_option
631
826
        start_transaction_opts opt_chain opt_release
632
827
        union_opt select_derived_init option_type2
633
 
        kill_option
634
828
 
635
829
%type <m_fk_option>
636
830
        delete_option
652
846
        table_wild simple_expr udf_expr
653
847
        expr_or_default set_expr_or_default
654
848
        signed_literal now_or_signed_literal opt_escape
655
 
        simple_ident_q
 
849
        simple_ident_nospvar simple_ident_q
656
850
        field_or_var limit_option
657
851
        function_call_keyword
658
852
        function_call_nonkeyword
692
886
 
693
887
%type <interval_time_st> interval_time_stamp
694
888
 
 
889
%type <column_format_type> column_format_types
 
890
 
695
891
%type <tx_isolation> isolation_types
696
892
 
697
893
%type <cast_type> cast_type
698
894
 
699
 
%type <symbol>
700
 
        keyword
701
 
        keyword_sp
702
 
        keyword_exception_for_variable
703
 
        row_format
 
895
%type <symbol> keyword keyword_sp
704
896
 
705
897
%type <charset>
706
898
        collation_name
728
920
        opt_precision opt_ignore opt_column
729
921
        set unlock string_list
730
922
        ref_list opt_match_clause opt_on_update_delete use
731
 
        opt_delete_option varchar
 
923
        opt_delete_options opt_delete_option varchar
732
924
        opt_outer table_list table_name
733
925
        opt_option opt_place
734
926
        opt_attribute opt_attribute_list attribute
735
927
        flush_options flush_option
736
928
        equal optional_braces
737
929
        normal_join
738
 
        table_to_table_list table_to_table opt_table_list
 
930
        table_to_table_list table_to_table opt_table_list opt_as
 
931
        single_multi
739
932
        union_clause union_list
740
933
        precision subselect_start
741
934
        subselect_end select_var_list select_var_list_init opt_len
742
935
        opt_extended_describe
743
936
        statement
744
 
        execute
745
937
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
746
938
        init_key_options key_options key_opts key_opt key_using_alg
747
939
END_OF_INPUT
750
942
%type <num> index_hint_clause
751
943
%type <filetype> data_file
752
944
 
 
945
%type <NONE>
 
946
        '-' '+' '*' '/' '%' '(' ')'
 
947
        ',' '!' '{' '}' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
 
948
        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM DELETE_SYM
753
949
%%
754
950
 
755
951
/*
776
972
query:
777
973
          END_OF_INPUT
778
974
          {
779
 
            if (!(YYSession->getLex()->select_lex.options & OPTION_FOUND_COMMENT))
 
975
            Session *session= YYSession;
 
976
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
780
977
            {
781
978
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
782
979
              DRIZZLE_YYABORT;
783
980
            }
784
981
            else
785
982
            {
786
 
              YYSession->getLex()->statement= new statement::EmptyQuery(YYSession);
 
983
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
984
              session->lex->statement=
 
985
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
986
              if (session->lex->statement == NULL)
 
987
                DRIZZLE_YYABORT;
787
988
            }
788
989
          }
789
990
        | verb_clause END_OF_INPUT {}
804
1005
        | delete
805
1006
        | describe
806
1007
        | drop
807
 
        | execute
808
1008
        | flush
809
1009
        | insert
810
1010
        | kill
827
1027
/* create a table */
828
1028
 
829
1029
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);
 
1030
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1031
          {
 
1032
            Session *session= YYSession;
 
1033
            LEX *lex= session->lex;
 
1034
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1035
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1036
            lex->statement= statement;
 
1037
            if (lex->statement == NULL)
 
1038
              DRIZZLE_YYABORT;
 
1039
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1040
                                                   TL_OPTION_UPDATING,
 
1041
                                                   TL_WRITE))
 
1042
              DRIZZLE_YYABORT;
 
1043
            lex->col_list.empty();
 
1044
            statement->change=NULL;
 
1045
            statement->is_if_not_exists= $4;
 
1046
            statement->create_info.db_type= NULL;
 
1047
            statement->create_info.default_table_charset= NULL;
 
1048
            lex->name.str= 0;
837
1049
 
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();
 
1050
            message::Table &proto= statement->create_table_message;
 
1051
           
 
1052
            proto.set_name($5->table.str);
 
1053
            if ($2)
 
1054
              proto.set_type(message::Table::TEMPORARY);
 
1055
            else
 
1056
              proto.set_type(message::Table::STANDARD);
843
1057
          }
844
 
          create_table_definition
 
1058
          create2
845
1059
          {
846
 
            Lex->current_select= &Lex->select_lex;
 
1060
            LEX *lex= YYSession->lex;
 
1061
            lex->current_select= &lex->select_lex;
847
1062
          }
848
1063
        | CREATE build_method
849
1064
          {
850
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
1065
            LEX *lex=Lex;
 
1066
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1067
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1068
            lex->statement= statement;
 
1069
            if (lex->statement == NULL)
 
1070
              DRIZZLE_YYABORT;
 
1071
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1072
            statement->alter_info.build_method= $2;
 
1073
            lex->col_list.empty();
 
1074
            statement->change=NULL;
851
1075
          }
852
1076
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
853
1077
          {
854
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
855
 
                                                            NULL,
856
 
                                                            TL_OPTION_UPDATING))
 
1078
            LEX *lex=Lex;
 
1079
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1080
 
 
1081
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1082
                                                        NULL,
 
1083
                                                        TL_OPTION_UPDATING))
857
1084
              DRIZZLE_YYABORT;
858
 
 
859
 
            parser::buildKey(Lex, $4, $6);
 
1085
            Key *key;
 
1086
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1087
            statement->alter_info.key_list.push_back(key);
 
1088
            lex->col_list.empty();
860
1089
          }
861
 
        | CREATE DATABASE opt_if_not_exists schema_name
 
1090
        | CREATE DATABASE opt_if_not_exists ident
862
1091
          {
863
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1092
            LEX *lex=Lex;
 
1093
 
 
1094
            lex->sql_command=SQLCOM_CREATE_DB;
 
1095
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1096
            lex->statement= statement;
 
1097
            if (lex->statement == NULL)
 
1098
              DRIZZLE_YYABORT;
 
1099
            statement->is_if_not_exists= $3;
864
1100
          }
865
1101
          opt_create_database_options
866
1102
          {
868
1104
          }
869
1105
        ;
870
1106
 
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
 
           }
 
1107
create2:
 
1108
          '(' create2a {}
 
1109
        | opt_create_table_options
 
1110
          create3 {}
 
1111
        | LIKE table_ident opt_create_table_options
 
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, $2, NULL, 0, TL_READ))
 
1119
              DRIZZLE_YYABORT;
 
1120
          }
 
1121
        | '(' LIKE table_ident ')'
 
1122
          {
 
1123
            Session *session= YYSession;
 
1124
            LEX *lex= session->lex;
 
1125
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1126
 
 
1127
            statement->is_create_table_like= true;
 
1128
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1129
              DRIZZLE_YYABORT;
 
1130
          }
 
1131
        ;
 
1132
 
 
1133
create2a:
 
1134
          field_list ')' opt_create_table_options
 
1135
          create3 {}
 
1136
        |  create_select ')'
 
1137
           { Lex->current_select->set_braces(1);}
878
1138
           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
1139
        ;
886
1140
 
887
 
create_select_as:
 
1141
create3:
888
1142
          /* empty */ {}
889
 
        | opt_duplicate_as create_select
890
 
          {
891
 
            Lex->current_select->set_braces(0);
892
 
          }
 
1143
        | opt_duplicate opt_as create_select
 
1144
          { Lex->current_select->set_braces(0);}
893
1145
          union_clause {}
894
 
        | opt_duplicate_as '(' create_select ')'
895
 
          {
896
 
            Lex->current_select->set_braces(1);
897
 
          }
 
1146
        | opt_duplicate opt_as '(' create_select ')'
 
1147
          { Lex->current_select->set_braces(1);}
898
1148
          union_opt {}
899
1149
        ;
900
1150
 
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
1151
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
1152
          SELECT_SYM
922
1153
          {
923
 
            Lex->lock_option= TL_READ;
924
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
1154
            LEX *lex=Lex;
 
1155
            lex->lock_option= TL_READ;
 
1156
            if (lex->sql_command == SQLCOM_INSERT)
925
1157
            {
926
 
              delete Lex->statement;
927
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
1158
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1159
              delete lex->statement;
 
1160
              lex->statement=
 
1161
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1162
              if (lex->statement == NULL)
 
1163
                DRIZZLE_YYABORT;
928
1164
            }
929
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
1165
            else if (lex->sql_command == SQLCOM_REPLACE)
930
1166
            {
931
 
              delete Lex->statement;
932
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
1167
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1168
              delete lex->statement;
 
1169
              lex->statement=
 
1170
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1171
              if (lex->statement == NULL)
 
1172
                DRIZZLE_YYABORT;
933
1173
            }
934
1174
            /*
935
1175
              The following work only with the local list, the global list
936
1176
              is created correctly in this case
937
1177
            */
938
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
939
 
            init_select(Lex);
940
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1178
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1179
            mysql_init_select(lex);
 
1180
            lex->current_select->parsing_place= SELECT_LIST;
941
1181
          }
942
1182
          select_options select_item_list
943
1183
          {
953
1193
          }
954
1194
        ;
955
1195
 
 
1196
opt_as:
 
1197
          /* empty */ {}
 
1198
        | AS {}
 
1199
        ;
 
1200
 
956
1201
opt_create_database_options:
957
1202
          /* empty */ {}
958
1203
        | default_collation_schema {}
966
1211
 
967
1212
custom_database_option:
968
1213
          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
 
          }
 
1214
        {
 
1215
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1216
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1217
 
 
1218
          opt->set_name($1.str);
 
1219
        }
981
1220
        | ident_or_text equal ident_or_text
982
 
          {
983
 
            parser::buildSchemaOption(Lex, $1.str, $3);
984
 
          }
 
1221
        {
 
1222
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1223
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1224
 
 
1225
          opt->set_name($1.str);
 
1226
          opt->set_state($3.str);
 
1227
        }
985
1228
        | ident_or_text equal ulonglong_num
986
 
          {
987
 
            parser::buildSchemaOption(Lex, $1.str, $3);
988
 
          }
 
1229
        {
 
1230
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1231
          char number_as_string[22];
 
1232
 
 
1233
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1234
 
 
1235
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1236
 
 
1237
          opt->set_name($1.str);
 
1238
          opt->set_state(number_as_string);
 
1239
        }
989
1240
        ;
990
1241
 
991
1242
opt_table_options:
995
1246
 
996
1247
opt_if_not_exists:
997
1248
          /* empty */ { $$= false; }
998
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1249
        | IF not EXISTS { $$= true; }
999
1250
        ;
1000
1251
 
1001
1252
opt_create_table_options:
1019
1270
custom_engine_option:
1020
1271
        ENGINE_SYM equal ident_or_text
1021
1272
          {
1022
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1273
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1274
 
 
1275
            statement->is_engine_set= true;
 
1276
 
 
1277
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1023
1278
          }
1024
1279
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1025
1280
          {
1026
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1281
            message::Table::TableOptions *tableopts;
 
1282
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1283
 
 
1284
            tableopts->set_comment($3.str);
1027
1285
          }
1028
1286
        | AUTO_INC opt_equal ulonglong_num
1029
1287
          {
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);
 
1288
            message::Table::TableOptions *tableopts;
 
1289
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1290
 
 
1291
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1292
 
 
1293
            statement->create_info.auto_increment_value=$3;
 
1294
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1295
            tableopts->set_auto_increment_value($3);
 
1296
          }
 
1297
        |  ident_or_text equal ident_or_text
 
1298
          {
 
1299
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1300
 
 
1301
            opt->set_name($1.str);
 
1302
            opt->set_state($3.str);
1051
1303
          }
1052
1304
        | ident_or_text equal ulonglong_num
1053
1305
          {
1054
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1306
            char number_as_string[22];
 
1307
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1308
 
 
1309
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1310
            opt->set_name($1.str);
 
1311
            opt->set_state(number_as_string);
1055
1312
          }
1056
1313
        | default_collation
1057
1314
        ;
1059
1316
default_collation:
1060
1317
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1061
1318
          {
1062
 
            if (not parser::buildCollation(Lex, $4))
1063
 
            {
1064
 
              DRIZZLE_YYABORT;
1065
 
            }
 
1319
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1320
 
 
1321
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1322
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1323
                 cinfo->default_table_charset && $4 &&
 
1324
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1325
              {
 
1326
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1327
                         $4->name, cinfo->default_table_charset->csname);
 
1328
                DRIZZLE_YYABORT;
 
1329
              }
 
1330
              statement->create_info.default_table_charset= $4;
 
1331
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1066
1332
          }
1067
1333
        ;
1068
1334
 
1069
1335
default_collation_schema:
1070
1336
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1071
1337
          {
1072
 
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
1073
 
          }
1074
 
        ;
1075
 
 
1076
 
row_format:
1077
 
          COMPACT_SYM  {}
1078
 
        | COMPRESSED_SYM  {}
1079
 
        | DEFAULT  {}
1080
 
        | DYNAMIC_SYM  {}
1081
 
        | FIXED_SYM  {}
1082
 
        | REDUNDANT_SYM  {}
1083
 
        ;
1084
 
 
1085
 
row_format_or_text:
1086
 
          row_format
1087
 
          {
1088
 
            $$.str= YYSession->strmake($1.str, $1.length);
1089
 
            $$.length= $1.length;
1090
 
          }
1091
 
        ;
 
1338
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1339
 
 
1340
            message::Schema &schema_message= statement->schema_message;
 
1341
            schema_message.set_collation($4->name);
 
1342
          }
 
1343
        ;
 
1344
 
 
1345
column_format_types:
 
1346
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1347
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1348
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1349
 
1092
1350
 
1093
1351
opt_select_from:
1094
1352
          opt_limit_clause {}
1109
1367
          field_spec opt_check_constraint
1110
1368
        | field_spec references
1111
1369
          {
1112
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1370
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1113
1371
          }
1114
1372
        ;
1115
1373
 
1116
1374
key_def:
1117
1375
          key_type opt_ident key_alg '(' key_list ')' key_options
1118
1376
          {
1119
 
            parser::buildKey(Lex, $1, $2);
 
1377
            LEX *lex=Lex;
 
1378
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1379
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1380
                              lex->col_list);
 
1381
            statement->alter_info.key_list.push_back(key);
 
1382
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1120
1383
          }
1121
1384
        | opt_constraint constraint_key_type opt_ident key_alg
1122
1385
          '(' key_list ')' key_options
1123
1386
          {
1124
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1387
            LEX *lex=Lex;
 
1388
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1389
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1390
                              lex->col_list);
 
1391
            statement->alter_info.key_list.push_back(key);
 
1392
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1125
1393
          }
1126
1394
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1127
1395
          {
1128
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1396
            LEX *lex=Lex;
 
1397
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1398
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
 
1399
                                      $8,
 
1400
                                      lex->ref_list,
 
1401
                                      statement->fk_delete_opt,
 
1402
                                      statement->fk_update_opt,
 
1403
                                      statement->fk_match_option);
 
1404
            statement->alter_info.key_list.push_back(key);
 
1405
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1406
                         &default_key_create_info, 1,
 
1407
                         lex->col_list);
 
1408
            statement->alter_info.key_list.push_back(key);
 
1409
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1410
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1411
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1129
1412
          }
1130
1413
        | constraint opt_check_constraint
1131
1414
          {
1132
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1415
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1133
1416
          }
1134
1417
        | opt_constraint check_constraint
1135
1418
          {
1136
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1419
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1137
1420
          }
1138
1421
        ;
1139
1422
 
1158
1441
field_spec:
1159
1442
          field_ident
1160
1443
          {
1161
 
            parser::buildCreateFieldIdent(Lex);
 
1444
            LEX *lex=Lex;
 
1445
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1446
            lex->length=lex->dec=0;
 
1447
            lex->type=0;
 
1448
            statement->default_value= statement->on_update_value= 0;
 
1449
            statement->comment= null_lex_str;
 
1450
            lex->charset=NULL;
 
1451
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1452
 
 
1453
            message::AlterTable &alter_proto=
 
1454
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1455
            statement->current_proto_field= alter_proto.add_added_field();
1162
1456
          }
1163
1457
          field_def
1164
1458
          {
 
1459
            LEX *lex=Lex;
1165
1460
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1166
1461
 
1167
 
            if (Lex->field())
1168
 
            {
1169
 
              Lex->field()->set_name($1.str);
1170
 
            }
 
1462
            if (statement->current_proto_field)
 
1463
              statement->current_proto_field->set_name($1.str);
1171
1464
 
1172
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1173
 
                                  Lex->length, Lex->dec, Lex->type,
 
1465
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1466
                                  lex->length,lex->dec,lex->type,
1174
1467
                                  statement->column_format,
1175
1468
                                  statement->default_value, statement->on_update_value,
1176
1469
                                  &statement->comment,
1177
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1470
                                  statement->change, &lex->interval_list, lex->charset))
1178
1471
              DRIZZLE_YYABORT;
1179
1472
 
1180
 
            Lex->setField(NULL);
 
1473
            statement->current_proto_field= NULL;
1181
1474
          }
1182
1475
        ;
1183
 
 
1184
1476
field_def:
1185
 
          field_definition opt_attribute {}
 
1477
          type opt_attribute {}
1186
1478
        ;
1187
1479
 
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));
 
1480
type:
 
1481
        int_type
 
1482
        {
 
1483
          $$=$1;
 
1484
          Lex->length=(char*) 0; /* use default length */
 
1485
          statement::CreateTable *statement=
 
1486
            (statement::CreateTable *)Lex->statement;
 
1487
 
 
1488
          if (statement->current_proto_field)
 
1489
          {
 
1490
            if ($1 == DRIZZLE_TYPE_LONG)
 
1491
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1492
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1493
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1494
            else
 
1495
              abort();
 
1496
          }
1192
1497
          }
1193
1498
        | real_type opt_precision
1194
1499
          {
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
 
1500
            $$=$1;
 
1501
 
 
1502
            statement::CreateTable *statement=
 
1503
              (statement::CreateTable *)Lex->statement;
 
1504
 
 
1505
            if (statement->current_proto_field)
 
1506
            {
 
1507
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1508
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1509
            }
 
1510
          }
 
1511
          | char '(' NUM ')'
 
1512
            {
 
1513
              Lex->length=$3.str;
 
1514
              $$=DRIZZLE_TYPE_VARCHAR;
 
1515
 
 
1516
            statement::CreateTable *statement=
 
1517
              (statement::CreateTable *)Lex->statement;
 
1518
 
 
1519
            if (statement->current_proto_field)
 
1520
            {
 
1521
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1522
              message::Table::Field::StringFieldOptions *string_field_options;
 
1523
 
 
1524
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1525
 
 
1526
              string_field_options->set_length(atoi($3.str));
 
1527
            }
 
1528
            }
 
1529
          | char
 
1530
            {
 
1531
              Lex->length=(char*) "1";
 
1532
              $$=DRIZZLE_TYPE_VARCHAR;
 
1533
 
 
1534
            statement::CreateTable *statement=
 
1535
              (statement::CreateTable *)Lex->statement;
 
1536
 
 
1537
            if (statement->current_proto_field)
 
1538
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1539
            }
 
1540
          | varchar '(' NUM ')'
 
1541
            {
 
1542
              Lex->length=$3.str;
 
1543
              $$= DRIZZLE_TYPE_VARCHAR;
 
1544
 
 
1545
            statement::CreateTable *statement=
 
1546
              (statement::CreateTable *)Lex->statement;
 
1547
 
 
1548
            if (statement->current_proto_field)
 
1549
            {
 
1550
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1551
 
 
1552
              message::Table::Field::StringFieldOptions *string_field_options;
 
1553
 
 
1554
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1555
 
 
1556
              string_field_options->set_length(atoi($3.str));
 
1557
            }
 
1558
            }
 
1559
          | VARBINARY '(' NUM ')'
 
1560
            {
 
1561
              Lex->length=$3.str;
 
1562
              Lex->charset=&my_charset_bin;
 
1563
              $$= DRIZZLE_TYPE_VARCHAR;
 
1564
 
 
1565
            statement::CreateTable *statement=
 
1566
              (statement::CreateTable *)Lex->statement;
 
1567
 
 
1568
            if (statement->current_proto_field)
 
1569
            {
 
1570
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1571
              message::Table::Field::StringFieldOptions *string_field_options;
 
1572
 
 
1573
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1574
 
 
1575
              string_field_options->set_length(atoi($3.str));
 
1576
              string_field_options->set_collation_id(my_charset_bin.number);
 
1577
              string_field_options->set_collation(my_charset_bin.name);
 
1578
            }
 
1579
            }
 
1580
          | DATE_SYM
1215
1581
          {
1216
1582
            $$=DRIZZLE_TYPE_DATE;
1217
1583
 
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
 
1584
            statement::CreateTable *statement=
 
1585
              (statement::CreateTable *)Lex->statement;
 
1586
 
 
1587
            if (statement->current_proto_field)
 
1588
              statement->current_proto_field->set_type(message::Table::Field::DATE);
 
1589
          }
 
1590
          | TIMESTAMP_SYM
 
1591
          {
 
1592
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1593
 
 
1594
            statement::CreateTable *statement=
 
1595
              (statement::CreateTable *)Lex->statement;
 
1596
 
 
1597
            if (statement->current_proto_field)
 
1598
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
 
1599
          }
 
1600
          | DATETIME_SYM
1237
1601
          {
1238
1602
            $$=DRIZZLE_TYPE_DATETIME;
1239
1603
 
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 ')'
 
1604
            statement::CreateTable *statement=
 
1605
              (statement::CreateTable *)Lex->statement;
 
1606
 
 
1607
            if (statement->current_proto_field)
 
1608
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1609
          }
 
1610
          | BLOB_SYM
 
1611
            {
 
1612
              Lex->charset=&my_charset_bin;
 
1613
              $$=DRIZZLE_TYPE_BLOB;
 
1614
              Lex->length=(char*) 0; /* use default length */
 
1615
 
 
1616
              statement::CreateTable *statement=
 
1617
                (statement::CreateTable *)Lex->statement;
 
1618
 
 
1619
              if (statement->current_proto_field)
 
1620
              {
 
1621
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1622
                message::Table::Field::StringFieldOptions *string_field_options;
 
1623
 
 
1624
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1625
                string_field_options->set_collation_id(my_charset_bin.number);
 
1626
                string_field_options->set_collation(my_charset_bin.name);
 
1627
              }
 
1628
            }
 
1629
          | TEXT_SYM
 
1630
            {
 
1631
              $$=DRIZZLE_TYPE_BLOB;
 
1632
              Lex->length=(char*) 0; /* use default length */
 
1633
 
 
1634
            statement::CreateTable *statement=
 
1635
              (statement::CreateTable *)Lex->statement;
 
1636
 
 
1637
            if (statement->current_proto_field)
 
1638
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1639
            }
 
1640
          | DECIMAL_SYM float_options
 
1641
          {
 
1642
            $$=DRIZZLE_TYPE_DECIMAL;
 
1643
 
 
1644
            statement::CreateTable *statement=
 
1645
              (statement::CreateTable *)Lex->statement;
 
1646
 
 
1647
            if (statement->current_proto_field)
 
1648
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1649
          }
 
1650
          | NUMERIC_SYM float_options
 
1651
          {
 
1652
            $$=DRIZZLE_TYPE_DECIMAL;
 
1653
 
 
1654
            statement::CreateTable *statement=
 
1655
              (statement::CreateTable *)Lex->statement;
 
1656
 
 
1657
            if (statement->current_proto_field)
 
1658
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1659
          }
 
1660
          | FIXED_SYM float_options
 
1661
          {
 
1662
            $$=DRIZZLE_TYPE_DECIMAL;
 
1663
 
 
1664
            statement::CreateTable *statement=
 
1665
              (statement::CreateTable *)Lex->statement;
 
1666
 
 
1667
            if (statement->current_proto_field)
 
1668
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1669
          }
 
1670
          | ENUM_SYM
 
1671
            {Lex->interval_list.empty();}
 
1672
            '(' string_list ')'
1272
1673
          {
1273
1674
            $$=DRIZZLE_TYPE_ENUM;
1274
1675
 
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);
 
1676
            statement::CreateTable *statement=
 
1677
              (statement::CreateTable *)Lex->statement;
 
1678
 
 
1679
            if (statement->current_proto_field)
 
1680
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1285
1681
          }
1286
1682
        | SERIAL_SYM
1287
1683
          {
1288
 
            $$= parser::buildSerialColumn(Lex);
 
1684
            $$=DRIZZLE_TYPE_LONGLONG;
 
1685
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1686
 
 
1687
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1688
            if (statement->current_proto_field)
 
1689
            {
 
1690
              message::Table::Field::FieldConstraints *constraints;
 
1691
              constraints= statement->current_proto_field->mutable_constraints();
 
1692
              constraints->set_is_nullable(false);
 
1693
 
 
1694
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1695
            }
1289
1696
          }
1290
1697
        ;
1291
1698
 
1299
1706
        ;
1300
1707
 
1301
1708
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
 
          }
 
1709
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1710
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1314
1711
        ;
1315
1712
 
1316
1713
real_type:
1319
1716
            $$= DRIZZLE_TYPE_DOUBLE;
1320
1717
          }
1321
1718
        | DOUBLE_SYM
1322
 
          {
1323
 
            $$= DRIZZLE_TYPE_DOUBLE;
1324
 
          }
 
1719
          { $$=DRIZZLE_TYPE_DOUBLE; }
1325
1720
        | DOUBLE_SYM PRECISION
1326
 
          {
1327
 
            $$= DRIZZLE_TYPE_DOUBLE;
1328
 
          }
 
1721
          { $$=DRIZZLE_TYPE_DOUBLE; }
1329
1722
        ;
1330
1723
 
1331
1724
float_options:
1340
1733
precision:
1341
1734
          '(' NUM ',' NUM ')'
1342
1735
          {
1343
 
            Lex->length= $2.str;
1344
 
            Lex->dec= $4.str;
 
1736
            LEX *lex=Lex;
 
1737
            lex->length=$2.str;
 
1738
            lex->dec=$4.str;
1345
1739
          }
1346
1740
        ;
1347
1741
 
1350
1744
        | '(' NUM ')' { Lex->length= $2.str; }
1351
1745
        ;
1352
1746
 
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
1747
opt_precision:
1370
 
          /* empty */
1371
 
          { Lex->dec=Lex->length= (char*)0; }
1372
 
        | '(' NUM ')'
1373
 
          { Lex->length=Lex->dec= (char*)0; }
1374
 
        | precision
1375
 
          {}
 
1748
          /* empty */ {}
 
1749
        | precision {}
1376
1750
        ;
1377
1751
 
1378
1752
opt_attribute:
1388
1762
attribute:
1389
1763
          NULL_SYM
1390
1764
          {
 
1765
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1391
1766
            Lex->type&= ~ NOT_NULL_FLAG;
 
1767
 
 
1768
            if (statement->current_proto_field)
 
1769
            {
 
1770
              message::Table::Field::FieldConstraints *constraints;
 
1771
              constraints= statement->current_proto_field->mutable_constraints();
 
1772
              constraints->set_is_nullable(true);
 
1773
            }
 
1774
          }
 
1775
        | COLUMN_FORMAT_SYM column_format_types
 
1776
          {
 
1777
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1778
 
 
1779
            statement->column_format= $2;
 
1780
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1392
1781
          }
1393
1782
        | not NULL_SYM
1394
1783
          {
 
1784
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1395
1785
            Lex->type|= NOT_NULL_FLAG;
1396
1786
 
1397
 
            if (Lex->field())
 
1787
            if (statement->current_proto_field)
1398
1788
            {
1399
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1789
              message::Table::Field::FieldConstraints *constraints;
 
1790
              constraints= statement->current_proto_field->mutable_constraints();
 
1791
              constraints->set_is_nullable(false);
1400
1792
            }
1401
1793
          }
1402
1794
        | DEFAULT now_or_signed_literal
1407
1799
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1408
1800
          }
1409
1801
        | ON UPDATE_SYM NOW_SYM optional_braces
1410
 
          {
1411
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1412
 
          }
 
1802
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1413
1803
        | AUTO_INC
1414
1804
          {
1415
 
            parser::buildAutoOnColumn(Lex);
 
1805
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1806
 
 
1807
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1808
            if (statement->current_proto_field)
 
1809
            {
 
1810
              message::Table::Field::FieldConstraints *constraints;
 
1811
 
 
1812
              constraints= statement->current_proto_field->mutable_constraints();
 
1813
              constraints->set_is_nullable(false);
 
1814
            }
1416
1815
          }
1417
1816
        | SERIAL_SYM DEFAULT VALUE_SYM
1418
1817
          {
1419
 
            (void)parser::buildSerialColumn(Lex);
 
1818
            LEX *lex=Lex;
 
1819
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1820
 
 
1821
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1822
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1823
 
 
1824
            if (statement->current_proto_field)
 
1825
            {
 
1826
              message::Table::Field::FieldConstraints *constraints;
 
1827
              constraints= statement->current_proto_field->mutable_constraints();
 
1828
              constraints->set_is_nullable(false);
 
1829
            }
1420
1830
          }
1421
1831
        | opt_primary KEY_SYM
1422
1832
          {
1423
 
            parser::buildPrimaryOnColumn(Lex);
 
1833
            LEX *lex=Lex;
 
1834
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1835
 
 
1836
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1837
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1838
 
 
1839
            if (statement->current_proto_field)
 
1840
            {
 
1841
              message::Table::Field::FieldConstraints *constraints;
 
1842
              constraints= statement->current_proto_field->mutable_constraints();
 
1843
              constraints->set_is_nullable(false);
 
1844
            }
1424
1845
          }
1425
1846
        | UNIQUE_SYM
1426
1847
          {
1427
 
            parser::buildKeyOnColumn(Lex);
 
1848
            LEX *lex=Lex;
 
1849
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1850
 
 
1851
            lex->type|= UNIQUE_FLAG;
 
1852
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1428
1853
          }
1429
1854
        | UNIQUE_SYM KEY_SYM
1430
1855
          {
1431
 
            parser::buildKeyOnColumn(Lex);
 
1856
            LEX *lex=Lex;
 
1857
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1858
 
 
1859
            lex->type|= UNIQUE_KEY_FLAG;
 
1860
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1432
1861
          }
1433
1862
        | COMMENT_SYM TEXT_STRING_sys
1434
1863
          {
1435
1864
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1436
1865
            statement->comment= $2;
1437
1866
 
1438
 
            if (Lex->field())
1439
 
              Lex->field()->set_comment($2.str);
 
1867
            if (statement->current_proto_field)
 
1868
              statement->current_proto_field->set_comment($2.str);
1440
1869
          }
1441
1870
        | COLLATE_SYM collation_name
1442
1871
          {
1487
1916
        ;
1488
1917
 
1489
1918
references:
1490
 
          REFERENCES table_ident opt_ref_list opt_match_clause opt_on_update_delete
 
1919
          REFERENCES
 
1920
          table_ident
 
1921
          opt_ref_list
 
1922
          opt_match_clause
 
1923
          opt_on_update_delete
1491
1924
          {
1492
1925
            $$=$2;
1493
1926
          }
1495
1928
 
1496
1929
opt_ref_list:
1497
1930
          /* empty */
1498
 
          { Lex->ref_list.clear(); }
 
1931
          { Lex->ref_list.empty(); }
1499
1932
        | '(' ref_list ')'
1500
1933
        ;
1501
1934
 
1504
1937
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1505
1938
        | ident
1506
1939
          {
1507
 
            Lex->ref_list.clear();
1508
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1940
            LEX *lex= Lex;
 
1941
            lex->ref_list.empty();
 
1942
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1509
1943
          }
1510
1944
        ;
1511
1945
 
1512
1946
opt_match_clause:
1513
1947
          /* empty */
1514
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
 
1948
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
1515
1949
        | MATCH FULL
1516
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
 
1950
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
1517
1951
        | MATCH PARTIAL
1518
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
 
1952
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
1519
1953
        | MATCH SIMPLE_SYM
1520
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
 
1954
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
1521
1955
        ;
1522
1956
 
1523
1957
opt_on_update_delete:
1524
1958
          /* empty */
1525
1959
          {
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;
 
1960
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1961
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1528
1962
          }
1529
1963
        | ON UPDATE_SYM delete_option
1530
1964
          {
1531
1965
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1532
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1966
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1533
1967
          }
1534
1968
        | ON DELETE_SYM delete_option
1535
1969
          {
1536
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1970
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1537
1971
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1538
1972
          }
1539
1973
        | ON UPDATE_SYM delete_option
1551
1985
        ;
1552
1986
 
1553
1987
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;  }
 
1988
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
 
1989
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
 
1990
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
 
1991
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
 
1992
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
1559
1993
        ;
1560
1994
 
1561
1995
key_type:
1595
2029
        ;
1596
2030
 
1597
2031
/*
1598
 
  For now, key_alg initializies Lex->key_create_info.
 
2032
  For now, key_alg initializies lex->key_create_info.
1599
2033
  In the future, when all key options are after key definition,
1600
2034
  we can remove key_alg and move init_key_options to key_options
1601
2035
*/
1617
2051
 
1618
2052
key_using_alg:
1619
2053
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2054
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
1620
2055
        ;
1621
2056
 
1622
2057
key_opt:
1669
2104
*/
1670
2105
 
1671
2106
alter:
1672
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2107
          ALTER build_method opt_ignore TABLE_SYM table_ident
1673
2108
          {
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());
 
2109
            Session *session= YYSession;
 
2110
            LEX *lex= session->lex;
 
2111
            lex->name.str= 0;
 
2112
            lex->name.length= 0;
 
2113
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2114
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2115
            lex->statement= statement;
 
2116
            if (lex->statement == NULL)
 
2117
              DRIZZLE_YYABORT;
 
2118
            lex->duplicates= DUP_ERROR;
 
2119
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2120
                                                   TL_OPTION_UPDATING))
 
2121
              DRIZZLE_YYABORT;
 
2122
            lex->col_list.empty();
 
2123
            lex->select_lex.init_order();
 
2124
            lex->select_lex.db=
 
2125
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2126
            statement->alter_info.build_method= $2;
1685
2127
          }
1686
2128
          alter_commands
1687
2129
          {}
1688
 
        | ALTER_SYM DATABASE schema_name
 
2130
        | ALTER DATABASE ident_or_empty
1689
2131
          {
1690
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2132
            LEX *lex=Lex;
 
2133
            lex->sql_command=SQLCOM_ALTER_DB;
 
2134
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2135
            if (lex->statement == NULL)
 
2136
              DRIZZLE_YYABORT;
1691
2137
          }
1692
2138
          default_collation_schema
1693
2139
          {
1694
 
            Lex->name= $3;
1695
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2140
            LEX *lex=Lex;
 
2141
            lex->name= $3;
 
2142
            if (lex->name.str == NULL &&
 
2143
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1696
2144
              DRIZZLE_YYABORT;
1697
2145
          }
1698
2146
        ;
1699
2147
 
 
2148
ident_or_empty:
 
2149
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2150
        | ident { $$= $1; }
 
2151
        ;
 
2152
 
1700
2153
alter_commands:
1701
2154
          /* empty */
1702
2155
        | DISCARD TABLESPACE
1733
2186
        ;
1734
2187
 
1735
2188
add_column:
1736
 
          ADD_SYM opt_column
 
2189
          ADD opt_column
1737
2190
          {
1738
2191
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
2192
 
1744
2197
 
1745
2198
alter_list_item:
1746
2199
          add_column column_def opt_place { }
1747
 
        | ADD_SYM key_def
 
2200
        | ADD key_def
1748
2201
          {
1749
2202
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1750
2203
 
1757
2210
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1758
2211
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1759
2212
          }
1760
 
        | CHANGE_SYM opt_column field_ident
 
2213
        | CHANGE opt_column field_ident
1761
2214
          {
1762
2215
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1763
2216
            statement->change= $3.str;
1766
2219
          field_spec opt_place
1767
2220
        | MODIFY_SYM opt_column field_ident
1768
2221
          {
 
2222
            LEX *lex=Lex;
1769
2223
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1770
 
            Lex->length= Lex->dec=0;
1771
 
            Lex->type= 0;
 
2224
            lex->length=lex->dec=0; lex->type=0;
1772
2225
            statement->default_value= statement->on_update_value= 0;
1773
2226
            statement->comment= null_lex_str;
1774
 
            Lex->charset= NULL;
 
2227
            lex->charset= NULL;
1775
2228
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1776
2229
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1777
2230
 
1778
 
            Lex->setField(NULL);
 
2231
            statement->current_proto_field= NULL;
1779
2232
          }
1780
2233
          field_def
1781
2234
          {
 
2235
            LEX *lex=Lex;
1782
2236
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1783
2237
 
1784
 
            if (add_field_to_list(Lex->session,&$3,
 
2238
            if (add_field_to_list(lex->session,&$3,
1785
2239
                                  (enum enum_field_types) $5,
1786
 
                                  Lex->length, Lex->dec, Lex->type,
 
2240
                                  lex->length, lex->dec, lex->type,
1787
2241
                                  statement->column_format,
1788
2242
                                  statement->default_value,
1789
2243
                                  statement->on_update_value,
1790
2244
                                  &statement->comment,
1791
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2245
                                  $3.str, &lex->interval_list, lex->charset))
1792
2246
              DRIZZLE_YYABORT;
1793
2247
          }
1794
2248
          opt_place
1801
2255
          }
1802
2256
        | DROP FOREIGN KEY_SYM opt_ident
1803
2257
          {
1804
 
            parser::buildAddAlterDropIndex(Lex, $4.str, true);
 
2258
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2259
 
 
2260
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2261
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1805
2262
          }
1806
2263
        | DROP PRIMARY_SYM KEY_SYM
1807
2264
          {
1808
 
            parser::buildAddAlterDropIndex(Lex, "PRIMARY");
 
2265
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2266
 
 
2267
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2268
                                                               "PRIMARY"));
 
2269
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1809
2270
          }
1810
2271
        | DROP key_or_index field_ident
1811
2272
          {
1812
 
            parser::buildAddAlterDropIndex(Lex, $3.str);
 
2273
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2274
 
 
2275
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2276
                                                                    $3.str));
 
2277
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1813
2278
          }
1814
2279
        | DISABLE_SYM KEYS
1815
2280
          {
1825
2290
            statement->alter_info.keys_onoff= ENABLE;
1826
2291
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1827
2292
          }
1828
 
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
 
2293
        | ALTER opt_column field_ident SET DEFAULT signed_literal
1829
2294
          {
1830
2295
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1831
2296
 
1832
2297
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
1833
2298
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1834
2299
          }
1835
 
        | ALTER_SYM opt_column field_ident DROP DEFAULT
 
2300
        | ALTER opt_column field_ident DROP DEFAULT
1836
2301
          {
1837
2302
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1838
2303
 
1841
2306
          }
1842
2307
        | RENAME opt_to table_ident
1843
2308
          {
 
2309
            LEX *lex=Lex;
1844
2310
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1845
2311
            size_t dummy;
1846
2312
 
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))
 
2313
            lex->select_lex.db=$3->db.str;
 
2314
            if (lex->select_lex.db == NULL &&
 
2315
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1850
2316
            {
1851
2317
              DRIZZLE_YYABORT;
1852
2318
            }
1857
2323
              DRIZZLE_YYABORT;
1858
2324
            }
1859
2325
 
1860
 
            Lex->name= $3->table;
 
2326
            lex->name= $3->table;
1861
2327
            statement->alter_info.flags.set(ALTER_RENAME);
1862
2328
          }
1863
2329
        | CONVERT_SYM TO_SYM collation_name_or_default
1864
2330
          {
1865
2331
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1866
2332
 
1867
 
            statement->create_info().table_charset=
1868
 
            statement->create_info().default_table_charset= $3;
1869
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2333
            statement->create_info.table_charset=
 
2334
            statement->create_info.default_table_charset= $3;
 
2335
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1870
2336
              HA_CREATE_USED_DEFAULT_CHARSET);
1871
2337
            statement->alter_info.flags.set(ALTER_CONVERT);
1872
2338
          }
1904
2370
          /* empty */ {}
1905
2371
        | AFTER_SYM ident
1906
2372
          {
1907
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2373
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2374
 
 
2375
            store_position_for_column($2.str);
 
2376
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1908
2377
          }
1909
2378
        | FIRST_SYM
1910
2379
          {
1911
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2380
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2381
 
 
2382
            store_position_for_column(first_keyword);
 
2383
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
1912
2384
          }
1913
2385
        ;
1914
2386
 
1915
2387
opt_to:
1916
2388
          /* empty */ {}
1917
2389
        | TO_SYM {}
 
2390
        | EQ {}
1918
2391
        | AS {}
1919
2392
        ;
1920
2393
 
1921
2394
start:
1922
2395
          START_SYM TRANSACTION_SYM start_transaction_opts
1923
2396
          {
1924
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2397
            LEX *lex= Lex;
 
2398
            lex->sql_command= SQLCOM_BEGIN;
 
2399
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2400
            if (lex->statement == NULL)
 
2401
              DRIZZLE_YYABORT;
1925
2402
          }
1926
2403
        ;
1927
2404
 
1936
2413
analyze:
1937
2414
          ANALYZE_SYM table_or_tables
1938
2415
          {
1939
 
            Lex->statement= new statement::Analyze(YYSession);
 
2416
            LEX *lex=Lex;
 
2417
            lex->sql_command = SQLCOM_ANALYZE;
 
2418
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2419
            if (lex->statement == NULL)
 
2420
              DRIZZLE_YYABORT;
1940
2421
          }
1941
2422
          table_list
1942
2423
          {}
1945
2426
check:
1946
2427
          CHECK_SYM table_or_tables
1947
2428
          {
1948
 
            Lex->statement= new statement::Check(YYSession);
 
2429
            LEX *lex=Lex;
 
2430
 
 
2431
            lex->sql_command = SQLCOM_CHECK;
 
2432
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2433
            if (lex->statement == NULL)
 
2434
              DRIZZLE_YYABORT;
1949
2435
          }
1950
2436
          table_list
1951
2437
          {}
1954
2440
rename:
1955
2441
          RENAME table_or_tables
1956
2442
          {
1957
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2443
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2444
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2445
            if (Lex->statement == NULL)
 
2446
              DRIZZLE_YYABORT;
1958
2447
          }
1959
2448
          table_to_table_list
1960
2449
          {}
1968
2457
table_to_table:
1969
2458
          table_ident TO_SYM table_ident
1970
2459
          {
1971
 
            Select_Lex *sl= Lex->current_select;
1972
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2460
            LEX *lex=Lex;
 
2461
            Select_Lex *sl= lex->current_select;
 
2462
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1973
2463
                                       TL_IGNORE) ||
1974
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2464
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1975
2465
                                       TL_IGNORE))
1976
2466
              DRIZZLE_YYABORT;
1977
2467
          }
1985
2475
select:
1986
2476
          select_init
1987
2477
          {
1988
 
            Lex->statement= new statement::Select(YYSession);
 
2478
            LEX *lex= Lex;
 
2479
            lex->sql_command= SQLCOM_SELECT;
 
2480
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2481
            if (lex->statement == NULL)
 
2482
              DRIZZLE_YYABORT;
1989
2483
          }
1990
2484
        ;
1991
2485
 
1998
2492
select_paren:
1999
2493
          SELECT_SYM select_part2
2000
2494
          {
2001
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2495
            if (setup_select_in_parentheses(YYSession, Lex))
2002
2496
              DRIZZLE_YYABORT;
2003
2497
          }
2004
2498
        | '(' select_paren ')'
2008
2502
select_paren_derived:
2009
2503
          SELECT_SYM select_part2_derived
2010
2504
          {
2011
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2505
            if (setup_select_in_parentheses(YYSession, Lex))
2012
2506
              DRIZZLE_YYABORT;
2013
2507
          }
2014
2508
        | '(' select_paren_derived ')'
2017
2511
select_init2:
2018
2512
          select_part2
2019
2513
          {
2020
 
            Select_Lex * sel= Lex->current_select;
2021
 
            if (Lex->current_select->set_braces(0))
 
2514
            LEX *lex= Lex;
 
2515
            Select_Lex * sel= lex->current_select;
 
2516
            if (lex->current_select->set_braces(0))
2022
2517
            {
2023
 
              parser::my_parse_error(YYSession->m_lip);
 
2518
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2519
              my_parse_error(&pass);
2024
2520
              DRIZZLE_YYABORT;
2025
2521
            }
2026
2522
            if (sel->linkage == UNION_TYPE &&
2027
2523
                sel->master_unit()->first_select()->braces)
2028
2524
            {
2029
 
              parser::my_parse_error(YYSession->m_lip);
 
2525
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2526
              my_parse_error(&pass);
2030
2527
              DRIZZLE_YYABORT;
2031
2528
            }
2032
2529
          }
2035
2532
 
2036
2533
select_part2:
2037
2534
          {
2038
 
            Select_Lex *sel= Lex->current_select;
 
2535
            LEX *lex= Lex;
 
2536
            Select_Lex *sel= lex->current_select;
2039
2537
            if (sel->linkage != UNION_TYPE)
2040
 
              init_select(Lex);
2041
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2538
              mysql_init_select(lex);
 
2539
            lex->current_select->parsing_place= SELECT_LIST;
2042
2540
          }
2043
2541
          select_options select_item_list
2044
2542
          {
2068
2566
select_options:
2069
2567
          /* empty*/
2070
2568
        | select_option_list
2071
 
          { }
 
2569
          {
 
2570
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2571
                Lex->current_select->options & SELECT_ALL)
 
2572
            {
 
2573
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2574
              DRIZZLE_YYABORT;
 
2575
            }
 
2576
          }
2072
2577
        ;
2073
2578
 
2074
2579
select_option_list:
2076
2581
        | select_option
2077
2582
        ;
2078
2583
 
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
2584
select_option:
2127
2585
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2586
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2587
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2588
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2128
2589
        | SQL_BUFFER_RESULT
2129
2590
          {
2130
 
            if (check_simple_select(YYSession))
 
2591
            if (check_simple_select())
2131
2592
              DRIZZLE_YYABORT;
2132
2593
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2133
2594
          }
2134
 
        | select_option_small_or_big
2135
 
          { }
2136
 
        | select_option_distinct_or_all
2137
 
          { }
2138
2595
        | SQL_CALC_FOUND_ROWS
2139
2596
          {
2140
 
            if (check_simple_select(YYSession))
 
2597
            if (check_simple_select())
2141
2598
              DRIZZLE_YYABORT;
2142
2599
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2143
2600
          }
 
2601
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2144
2602
        ;
2145
2603
 
2146
2604
select_lock_type:
2147
2605
          /* empty */
2148
2606
        | FOR_SYM UPDATE_SYM
2149
2607
          {
2150
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2608
            LEX *lex=Lex;
 
2609
            lex->current_select->set_lock_for_tables(TL_WRITE);
2151
2610
          }
2152
2611
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2153
2612
          {
2154
 
            Lex->current_select->
 
2613
            LEX *lex=Lex;
 
2614
            lex->current_select->
2155
2615
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2156
2616
          }
2157
2617
        ;
2161
2621
        | select_item
2162
2622
        | '*'
2163
2623
          {
2164
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->getLex()->current_select->context, NULL, NULL, "*")))
 
2624
            Session *session= YYSession;
 
2625
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2626
                                                          context,
 
2627
                                                          NULL, NULL, "*")))
2165
2628
              DRIZZLE_YYABORT;
2166
 
 
2167
 
            (YYSession->getLex()->current_select->with_wild)++;
 
2629
            (session->lex->current_select->with_wild)++;
2168
2630
          }
2169
2631
        ;
2170
2632
 
2171
2633
select_item:
2172
2634
          remember_name table_wild remember_end
2173
2635
          {
2174
 
            if (YYSession->add_item_to_list($2))
 
2636
            Session *session= YYSession;
 
2637
 
 
2638
            if (session->add_item_to_list($2))
2175
2639
              DRIZZLE_YYABORT;
2176
2640
          }
2177
2641
        | remember_name expr remember_end select_alias
2178
2642
          {
 
2643
            Session *session= YYSession;
2179
2644
            assert($1 < $3);
2180
2645
 
2181
 
            if (YYSession->add_item_to_list($2))
 
2646
            if (session->add_item_to_list($2))
2182
2647
              DRIZZLE_YYABORT;
2183
 
 
2184
2648
            if ($4.str)
2185
2649
            {
2186
2650
              $2->is_autogenerated_name= false;
2188
2652
            }
2189
2653
            else if (!$2->name)
2190
2654
            {
2191
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2655
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2192
2656
            }
2193
2657
          }
2194
2658
        ;
2195
2659
 
2196
2660
remember_name:
2197
2661
          {
2198
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2662
            Session *session= YYSession;
 
2663
            Lex_input_stream *lip= session->m_lip;
2199
2664
            $$= (char*) lip->get_cpp_tok_start();
2200
2665
          }
2201
2666
        ;
2202
2667
 
2203
2668
remember_end:
2204
2669
          {
2205
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2670
            Session *session= YYSession;
 
2671
            Lex_input_stream *lip= session->m_lip;
2206
2672
            $$= (char*) lip->get_cpp_tok_end();
2207
2673
          }
2208
2674
        ;
2341
2807
          { $$= new Item_func_isnotnull($1); }
2342
2808
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
2343
2809
          { $$= new Item_func_equal($1,$3); }
2344
 
        | bool_pri comp_op predicate %prec '='
 
2810
        | bool_pri comp_op predicate %prec EQ
2345
2811
          { $$= (*$2)(0)->create($1,$3); }
2346
 
        | bool_pri comp_op all_or_any '(' subselect ')' %prec '='
 
2812
        | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
2347
2813
          { $$= all_any_subquery_creator($1, $2, $3, $5); }
2348
2814
        | predicate
2349
2815
        ;
2355
2821
          }
2356
2822
        | bit_expr not IN_SYM '(' subselect ')'
2357
2823
          {
2358
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2359
 
            $$= negate_expression(YYSession, item);
 
2824
            Session *session= YYSession;
 
2825
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2826
            $$= negate_expression(session, item);
2360
2827
          }
2361
2828
        | bit_expr IN_SYM '(' expr ')'
2362
2829
          {
2363
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2830
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2364
2831
          }
2365
2832
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2366
2833
          {
2370
2837
          }
2371
2838
        | bit_expr not IN_SYM '(' expr ')'
2372
2839
          {
2373
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2840
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2374
2841
          }
2375
2842
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2376
2843
          {
2381
2848
            $$= item;
2382
2849
          }
2383
2850
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2384
 
          {
2385
 
            $$= new Item_func_between($1,$3,$5);
2386
 
          }
 
2851
          { $$= new Item_func_between($1,$3,$5); }
2387
2852
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2388
2853
          {
2389
2854
            Item_func_between *item= new Item_func_between($1,$4,$6);
2391
2856
            $$= item;
2392
2857
          }
2393
2858
        | bit_expr LIKE simple_expr opt_escape
2394
 
          { 
2395
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
2396
 
          }
 
2859
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2397
2860
        | 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
 
          }
 
2861
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2422
2862
        | bit_expr
2423
2863
        ;
2424
2864
 
2457
2897
        ;
2458
2898
 
2459
2899
comp_op:
2460
 
          '='     { $$ = &comp_eq_creator; }
 
2900
          EQ     { $$ = &comp_eq_creator; }
2461
2901
        | GE     { $$ = &comp_ge_creator; }
2462
 
        | '>' { $$ = &comp_gt_creator; }
 
2902
        | GT_SYM { $$ = &comp_gt_creator; }
2463
2903
        | LE     { $$ = &comp_le_creator; }
2464
 
        | '<'     { $$ = &comp_lt_creator; }
 
2904
        | LT     { $$ = &comp_lt_creator; }
2465
2905
        | NE     { $$ = &comp_ne_creator; }
2466
2906
        ;
2467
2907
 
2476
2916
        | function_call_nonkeyword
2477
2917
        | function_call_generic
2478
2918
        | function_call_conflict
2479
 
        | simple_expr COLLATE_SYM ident_or_text %prec UMINUS
 
2919
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2480
2920
          {
2481
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
2921
            Session *session= YYSession;
 
2922
            Item *i1= new (session->mem_root) Item_string($3.str,
2482
2923
                                                      $3.length,
2483
 
                                                      YYSession->charset());
2484
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
2924
                                                      session->charset());
 
2925
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2485
2926
          }
2486
2927
        | literal
2487
2928
        | variable
2488
2929
        | sum_expr
2489
 
          {
2490
 
            Lex->setSumExprUsed();
2491
 
          }
2492
 
        | '+' simple_expr %prec UMINUS { $$= $2; }
2493
 
        | '-' simple_expr %prec UMINUS
 
2930
        | '+' simple_expr %prec NEG { $$= $2; }
 
2931
        | '-' simple_expr %prec NEG
2494
2932
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2495
2933
        | '(' subselect ')'
2496
2934
          {
2512
2950
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
2513
2951
          }
2514
2952
        | '{' ident expr '}' { $$= $3; }
2515
 
        | BINARY simple_expr %prec UMINUS
 
2953
        | BINARY simple_expr %prec NEG
2516
2954
          {
2517
2955
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
2518
2956
                                 &my_charset_bin);
2519
2957
          }
2520
2958
        | CAST_SYM '(' expr AS cast_type ')'
2521
2959
          {
2522
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2523
 
                                 Lex->charset);
 
2960
            LEX *lex= Lex;
 
2961
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
2962
                                 lex->charset);
2524
2963
            if (!$$)
2525
2964
              DRIZZLE_YYABORT;
2526
2965
          }
2538
2977
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2539
2978
                                                         $3);
2540
2979
          }
2541
 
        | VALUES '(' simple_ident ')'
 
2980
        | VALUES '(' simple_ident_nospvar ')'
2542
2981
          {
2543
2982
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2544
2983
                                                        $3);
2559
2998
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
2560
2999
        | CURRENT_USER optional_braces
2561
3000
          {
2562
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3001
            std::string user_str("user");
 
3002
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2563
3003
            {
2564
3004
              DRIZZLE_YYABORT;
2565
3005
            }
2566
 
            Lex->setCacheable(false);
2567
3006
          }
2568
3007
        | DATE_SYM '(' expr ')'
2569
3008
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
2575
3014
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
2576
3015
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2577
3016
          {
2578
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3017
            Session *session= YYSession;
 
3018
            List<Item> *list= new (session->mem_root) List<Item>;
2579
3019
            list->push_front($5);
2580
3020
            list->push_front($3);
2581
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2582
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3021
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3022
            $$= new (session->mem_root) Item_func_interval(item);
2583
3023
          }
2584
3024
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2585
3025
          {
 
3026
            Session *session= YYSession;
2586
3027
            $7->push_front($5);
2587
3028
            $7->push_front($3);
2588
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2589
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3029
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3030
            $$= new (session->mem_root) Item_func_interval(item);
2590
3031
          }
2591
3032
        | LEFT '(' expr ',' expr ')'
2592
3033
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2618
3059
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2619
3060
        | USER '(' ')'
2620
3061
          {
2621
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
 
3062
            std::string user_str("user");
 
3063
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
2622
3064
            {
2623
3065
              DRIZZLE_YYABORT;
2624
3066
            }
2625
 
            Lex->setCacheable(false);
2626
3067
          }
2627
3068
        | YEAR_SYM '(' expr ')'
2628
3069
          { $$= new (YYSession->mem_root) Item_func_year($3); }
2650
3091
        | CURDATE optional_braces
2651
3092
          {
2652
3093
            $$= new (YYSession->mem_root) Item_func_curdate_local();
2653
 
            Lex->setCacheable(false);
2654
3094
          }
2655
3095
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
2656
3096
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
2661
3101
        | NOW_SYM optional_braces
2662
3102
          {
2663
3103
            $$= new (YYSession->mem_root) Item_func_now_local();
2664
 
            Lex->setCacheable(false);
2665
3104
          }
2666
3105
        | NOW_SYM '(' expr ')'
2667
3106
          {
2668
3107
            $$= new (YYSession->mem_root) Item_func_now_local($3);
2669
 
            Lex->setCacheable(false);
2670
3108
          }
2671
3109
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
2672
3110
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
2679
3117
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2680
3118
        | SUBSTRING '(' expr ',' expr ',' expr ')'
2681
3119
          {
 
3120
            std::string reverse_str("substr");
2682
3121
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2683
3122
            args->push_back($3);
2684
3123
            args->push_back($5);
2685
3124
            args->push_back($7);
2686
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3125
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2687
3126
            {
2688
3127
              DRIZZLE_YYABORT;
2689
3128
            }
2690
3129
          }
2691
3130
        | SUBSTRING '(' expr ',' expr ')'
2692
3131
          {
 
3132
            std::string reverse_str("substr");
2693
3133
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2694
3134
            args->push_back($3);
2695
3135
            args->push_back($5);
2696
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3136
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2697
3137
            {
2698
3138
              DRIZZLE_YYABORT;
2699
3139
            }
2700
3140
          }
2701
3141
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
2702
3142
          {
 
3143
            std::string reverse_str("substr");
2703
3144
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2704
3145
            args->push_back($3);
2705
3146
            args->push_back($5);
2706
3147
            args->push_back($7);
2707
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3148
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2708
3149
            {
2709
3150
              DRIZZLE_YYABORT;
2710
3151
            }
2711
3152
          }
2712
3153
        | SUBSTRING '(' expr FROM expr ')'
2713
3154
          {
 
3155
            std::string reverse_str("substr");
2714
3156
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2715
3157
            args->push_back($3);
2716
3158
            args->push_back($5);
2717
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
 
3159
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2718
3160
            {
2719
3161
              DRIZZLE_YYABORT;
2720
3162
            }
2721
3163
          }
2722
3164
        | SYSDATE optional_braces
2723
 
          { 
2724
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
2725
 
            Lex->setCacheable(false);
2726
 
          }
 
3165
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
2727
3166
        | SYSDATE '(' expr ')'
2728
 
          { 
2729
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
2730
 
            Lex->setCacheable(false);
2731
 
          }
 
3167
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
2732
3168
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
2733
3169
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
2734
3170
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
2736
3172
        | UTC_DATE_SYM optional_braces
2737
3173
          {
2738
3174
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
2739
 
            Lex->setCacheable(false);
2740
3175
          }
2741
3176
        | UTC_TIMESTAMP_SYM optional_braces
2742
3177
          {
2743
3178
            $$= new (YYSession->mem_root) Item_func_now_utc();
2744
 
            Lex->setCacheable(false);
2745
3179
          }
2746
3180
        ;
2747
3181
 
2757
3191
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2758
3192
        | DATABASE '(' ')'
2759
3193
          {
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
 
          }
 
3194
            std::string database_str("database");
 
3195
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
 
3196
            {
 
3197
              DRIZZLE_YYABORT;
 
3198
            }
 
3199
          }
2789
3200
        | IF '(' expr ',' expr ',' expr ')'
2790
3201
          { $$= 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
3202
        | MICROSECOND_SYM '(' expr ')'
2807
3203
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
2808
3204
        | MOD_SYM '(' expr ',' expr ')'
2813
3209
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
2814
3210
        | REPLACE '(' expr ',' expr ',' expr ')'
2815
3211
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3212
        | REVERSE_SYM '(' expr ')'
 
3213
          {
 
3214
            std::string reverse_str("reverse");
 
3215
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3216
            args->push_back($3);
 
3217
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
3218
            {
 
3219
              DRIZZLE_YYABORT;
 
3220
            }
 
3221
          }
2816
3222
        | TRUNCATE_SYM '(' expr ',' expr ')'
2817
3223
          { $$= 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
3224
        ;
2846
3225
 
2847
3226
/*
2862
3241
          }
2863
3242
          opt_udf_expr_list ')'
2864
3243
          {
 
3244
            Session *session= YYSession;
2865
3245
            Create_func *builder;
2866
3246
            Item *item= NULL;
2867
3247
 
2877
3257
            builder= find_native_function_builder($1);
2878
3258
            if (builder)
2879
3259
            {
2880
 
              item= builder->create(YYSession, $1, $4);
 
3260
              item= builder->create(session, $1, $4);
2881
3261
            }
2882
3262
            else
2883
3263
            {
2885
3265
              const plugin::Function *udf= $<udf>3;
2886
3266
              if (udf)
2887
3267
              {
2888
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3268
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2889
3269
              } else {
2890
3270
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2891
3271
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
2896
3276
            {
2897
3277
              DRIZZLE_YYABORT;
2898
3278
            }
2899
 
            Lex->setCacheable(false);
2900
3279
          }
2901
3280
        ;
2902
3281
 
2988
3367
            sel->in_sum_expr--;
2989
3368
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
2990
3369
                                          sel->gorder_list, $7);
2991
 
            $5->clear();
 
3370
            $5->empty();
2992
3371
          }
2993
3372
        ;
2994
3373
 
3002
3381
        ;
3003
3382
 
3004
3383
variable_aux:
3005
 
          user_variable_ident SET_VAR expr
 
3384
          ident_or_text SET_VAR expr
3006
3385
          {
3007
3386
            $$= new Item_func_set_user_var($1, $3);
3008
 
            Lex->setCacheable(false);
3009
3387
          }
3010
 
        | user_variable_ident
 
3388
        | ident_or_text
3011
3389
          {
3012
3390
            $$= new Item_func_get_user_var(*YYSession, $1);
3013
 
            Lex->setCacheable(false);
3014
3391
          }
3015
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3392
        | '@' opt_var_ident_type ident_or_text opt_component
3016
3393
          {
3017
3394
            /* disallow "SELECT @@global.global.variable" */
3018
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3395
            if ($3.str && $4.str && check_reserved_words(&$3))
3019
3396
            {
3020
 
              parser::my_parse_error(YYSession->m_lip);
 
3397
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3398
              my_parse_error(&pass);
3021
3399
              DRIZZLE_YYABORT;
3022
3400
            }
3023
3401
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3026
3404
        ;
3027
3405
 
3028
3406
opt_distinct:
3029
 
          /* empty */ { $$ = false; }
3030
 
        | DISTINCT    { $$ = true; }
 
3407
          /* empty */ { $$ = 0; }
 
3408
        | DISTINCT    { $$ = 1; }
3031
3409
        ;
3032
3410
 
3033
3411
opt_gconcat_separator:
3049
3427
            select->gorder_list=
3050
3428
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
3051
3429
                                     sizeof(st_sql_list));
3052
 
            select->order_list.clear();
 
3430
            select->order_list.empty();
3053
3431
          }
3054
3432
        ;
3055
3433
 
3056
3434
in_sum_expr:
3057
3435
          opt_all
3058
3436
          {
3059
 
            if (Lex->current_select->inc_in_sum_expr())
 
3437
            LEX *lex= Lex;
 
3438
            if (lex->current_select->inc_in_sum_expr())
3060
3439
            {
3061
 
              parser::my_parse_error(YYSession->m_lip);
 
3440
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3441
              my_parse_error(&pass);
3062
3442
              DRIZZLE_YYABORT;
3063
3443
            }
3064
3444
          }
3072
3452
cast_type:
3073
3453
          BINARY opt_len
3074
3454
          { $$=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
3455
        | CHAR_SYM opt_len
3088
3456
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3089
3457
        | DATE_SYM
3090
3458
          { $$=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
3459
        | DATETIME_SYM
3094
3460
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3095
3461
        | DECIMAL_SYM float_options
3140
3506
          table_factor { $$=$1; }
3141
3507
        | join_table
3142
3508
          {
3143
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3509
            LEX *lex= Lex;
 
3510
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3144
3511
              DRIZZLE_YYABORT;
3145
3512
          }
3146
3513
        ;
3287
3654
          }
3288
3655
          expr
3289
3656
          {
3290
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3657
            LEX *lex= Lex;
 
3658
            if (!($$= lex->current_select->convert_right_join()))
3291
3659
              DRIZZLE_YYABORT;
3292
3660
            add_join_on($$, $8);
3293
3661
            Lex->pop_context();
3299
3667
          }
3300
3668
          USING '(' using_list ')'
3301
3669
          {
3302
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3670
            LEX *lex= Lex;
 
3671
            if (!($$= lex->current_select->convert_right_join()))
3303
3672
              DRIZZLE_YYABORT;
3304
3673
            add_join_natural($$,$5,$9,Lex->current_select);
3305
3674
          }
3307
3676
          {
3308
3677
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3309
3678
            add_join_natural($6,$1,NULL,Lex->current_select);
3310
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3679
            LEX *lex= Lex;
 
3680
            if (!($$= lex->current_select->convert_right_join()))
3311
3681
              DRIZZLE_YYABORT;
3312
3682
          }
3313
3683
        ;
3315
3685
normal_join:
3316
3686
          JOIN_SYM {}
3317
3687
        | INNER_SYM JOIN_SYM {}
3318
 
        | CROSS JOIN_SYM
3319
 
          {
3320
 
            Lex->is_cross= true;
3321
 
            Lex->current_select->is_cross= true;
3322
 
          }
 
3688
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3323
3689
        ;
3324
3690
 
3325
3691
/*
3332
3698
/* Warning - may return NULL in case of incomplete SELECT */
3333
3699
table_factor:
3334
3700
          {
 
3701
            Select_Lex *sel= Lex->current_select;
 
3702
            sel->table_join_options= 0;
3335
3703
          }
3336
3704
          table_ident opt_table_alias opt_key_definition
3337
3705
          {
3338
3706
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3339
 
                             0,
 
3707
                             Lex->current_select->get_table_join_options(),
3340
3708
                             Lex->lock_option,
3341
3709
                             Lex->current_select->pop_index_hints())))
3342
3710
              DRIZZLE_YYABORT;
3344
3712
          }
3345
3713
        | select_derived_init get_select_lex select_derived2
3346
3714
          {
3347
 
            Select_Lex *sel= Lex->current_select;
 
3715
            LEX *lex= Lex;
 
3716
            Select_Lex *sel= lex->current_select;
3348
3717
            if ($1)
3349
3718
            {
3350
3719
              if (sel->set_braces(1))
3351
3720
              {
3352
 
                parser::my_parse_error(YYSession->m_lip);
 
3721
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3722
                my_parse_error(&pass);
3353
3723
                DRIZZLE_YYABORT;
3354
3724
              }
3355
3725
              /* select in braces, can't contain global parameters */
3357
3727
                sel->master_unit()->global_parameters=
3358
3728
                   sel->master_unit()->fake_select_lex;
3359
3729
            }
3360
 
            if ($2->init_nested_join(Lex->session))
 
3730
            if ($2->init_nested_join(lex->session))
3361
3731
              DRIZZLE_YYABORT;
3362
3732
            $$= 0;
3363
3733
            /* incomplete derived tables return NULL, we must be
3399
3769
              /* Handle case of derived table, alias may be NULL if there
3400
3770
                 are no outer parentheses, add_table_to_list() will throw
3401
3771
                 error in this case */
3402
 
              Select_Lex *sel= Lex->current_select;
 
3772
              LEX *lex=Lex;
 
3773
              Select_Lex *sel= lex->current_select;
3403
3774
              Select_Lex_Unit *unit= sel->master_unit();
3404
 
              Lex->current_select= sel= unit->outer_select();
3405
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3775
              lex->current_select= sel= unit->outer_select();
 
3776
              if (!($$= sel->add_table_to_list(lex->session,
3406
3777
                                               new Table_ident(unit), $5, 0,
3407
3778
                                               TL_READ)))
3408
3779
 
3409
3780
                DRIZZLE_YYABORT;
3410
3781
              sel->add_joined_table($$);
3411
 
              Lex->pop_context();
 
3782
              lex->pop_context();
3412
3783
            }
3413
3784
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3414
3785
            {
3415
3786
              /* simple nested joins cannot have aliases or unions */
3416
 
              parser::my_parse_error(YYSession->m_lip);
 
3787
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3788
              my_parse_error(&pass);
3417
3789
              DRIZZLE_YYABORT;
3418
3790
            }
3419
3791
            else
3427
3799
          UNION_SYM
3428
3800
          union_option
3429
3801
          {
3430
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3802
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3431
3803
              DRIZZLE_YYABORT;
3432
3804
          }
3433
3805
          query_specification
3445
3817
select_init2_derived:
3446
3818
          select_part2_derived
3447
3819
          {
3448
 
            Select_Lex * sel= Lex->current_select;
3449
 
            if (Lex->current_select->set_braces(0))
 
3820
            LEX *lex= Lex;
 
3821
            Select_Lex * sel= lex->current_select;
 
3822
            if (lex->current_select->set_braces(0))
3450
3823
            {
3451
 
              parser::my_parse_error(YYSession->m_lip);
 
3824
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3825
              my_parse_error(&pass);
3452
3826
              DRIZZLE_YYABORT;
3453
3827
            }
3454
3828
            if (sel->linkage == UNION_TYPE &&
3455
3829
                sel->master_unit()->first_select()->braces)
3456
3830
            {
3457
 
              parser::my_parse_error(YYSession->m_lip);
 
3831
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3832
              my_parse_error(&pass);
3458
3833
              DRIZZLE_YYABORT;
3459
3834
            }
3460
3835
          }
3463
3838
/* The equivalent of select_part2 for nested queries. */
3464
3839
select_part2_derived:
3465
3840
          {
3466
 
            Select_Lex *sel= Lex->current_select;
 
3841
            LEX *lex= Lex;
 
3842
            Select_Lex *sel= lex->current_select;
3467
3843
            if (sel->linkage != UNION_TYPE)
3468
 
              init_select(Lex);
3469
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3844
              mysql_init_select(lex);
 
3845
            lex->current_select->parsing_place= SELECT_LIST;
3470
3846
          }
3471
3847
          select_options select_item_list
3472
3848
          {
3479
3855
select_derived:
3480
3856
          get_select_lex
3481
3857
          {
3482
 
            if ($1->init_nested_join(Lex->session))
 
3858
            LEX *lex= Lex;
 
3859
            if ($1->init_nested_join(lex->session))
3483
3860
              DRIZZLE_YYABORT;
3484
3861
          }
3485
3862
          derived_table_list
3486
3863
          {
 
3864
            LEX *lex= Lex;
3487
3865
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3488
3866
               for derived tables, both must equal NULL */
3489
3867
 
3490
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
3868
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3491
3869
              DRIZZLE_YYABORT;
3492
 
 
3493
3870
            if (!$3 && $$)
3494
3871
            {
3495
 
              parser::my_parse_error(YYSession->m_lip);
 
3872
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3873
              my_parse_error(&pass);
3496
3874
              DRIZZLE_YYABORT;
3497
3875
            }
3498
3876
          }
3500
3878
 
3501
3879
select_derived2:
3502
3880
          {
3503
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3504
 
            if (not Lex->expr_allows_subselect)
 
3881
            LEX *lex= Lex;
 
3882
            lex->derived_tables|= DERIVED_SUBQUERY;
 
3883
            if (!lex->expr_allows_subselect)
3505
3884
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
3885
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3886
              my_parse_error(&pass);
3507
3887
              DRIZZLE_YYABORT;
3508
3888
            }
3509
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
3889
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
3890
                mysql_new_select(lex, 1))
3510
3891
              DRIZZLE_YYABORT;
3511
 
            init_select(Lex);
3512
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3513
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3892
            mysql_init_select(lex);
 
3893
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3894
            lex->current_select->parsing_place= SELECT_LIST;
3514
3895
          }
3515
3896
          select_options select_item_list
3516
3897
          {
3526
3907
select_derived_init:
3527
3908
          SELECT_SYM
3528
3909
          {
3529
 
            Select_Lex *sel= Lex->current_select;
 
3910
            LEX *lex= Lex;
 
3911
 
 
3912
            Select_Lex *sel= lex->current_select;
3530
3913
            TableList *embedding;
3531
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
3914
            if (!sel->embedding || sel->end_nested_join(lex->session))
3532
3915
            {
3533
3916
              /* we are not in parentheses */
3534
 
              parser::my_parse_error(YYSession->m_lip);
 
3917
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3918
              my_parse_error(&pass);
3535
3919
              DRIZZLE_YYABORT;
3536
3920
            }
3537
3921
            embedding= Lex->current_select->embedding;
3673
4057
table_alias:
3674
4058
          /* empty */
3675
4059
        | AS
 
4060
        | EQ
3676
4061
        ;
3677
4062
 
3678
4063
opt_table_alias:
3679
4064
          /* empty */ { $$=0; }
3680
4065
        | table_alias ident
3681
 
          {
3682
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3683
 
          }
 
4066
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
3684
4067
        ;
3685
4068
 
3686
4069
opt_all:
3760
4143
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3761
4144
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3762
4145
            */
3763
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4146
            LEX *lex= Lex;
 
4147
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3764
4148
            {
3765
4149
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3766
4150
                       "global union parameters");
3767
4151
              DRIZZLE_YYABORT;
3768
4152
            }
3769
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4153
            lex->current_select->olap= ROLLUP_TYPE;
3770
4154
          }
3771
4155
        ;
3772
4156
 
3784
4168
        ;
3785
4169
 
3786
4170
alter_order_item:
3787
 
          simple_ident order_dir
 
4171
          simple_ident_nospvar order_dir
3788
4172
          {
 
4173
            Session *session= YYSession;
3789
4174
            bool ascending= ($2 == 1) ? true : false;
3790
 
            if (YYSession->add_order_to_list($1, ascending))
 
4175
            if (session->add_order_to_list($1, ascending))
3791
4176
              DRIZZLE_YYABORT;
3792
4177
          }
3793
4178
        ;
3804
4189
order_clause:
3805
4190
          ORDER_SYM BY
3806
4191
          {
3807
 
            if (not parser::buildOrderBy(Lex))
 
4192
            LEX *lex=Lex;
 
4193
            Select_Lex *sel= lex->current_select;
 
4194
            Select_Lex_Unit *unit= sel-> master_unit();
 
4195
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4196
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4197
                (sel->linkage != UNION_TYPE || sel->braces))
 
4198
            {
 
4199
              my_error(ER_WRONG_USAGE, MYF(0),
 
4200
                       "CUBE/ROLLUP", "ORDER BY");
3808
4201
              DRIZZLE_YYABORT;
 
4202
            }
 
4203
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4204
            {
 
4205
              /*
 
4206
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4207
                executed in the same way as the query
 
4208
                SELECT ... ORDER BY order_list
 
4209
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4210
                Otherwise we create a fake Select_Lex if it has not been created
 
4211
                yet.
 
4212
              */
 
4213
              Select_Lex *first_sl= unit->first_select();
 
4214
              if (!unit->is_union() &&
 
4215
                  (first_sl->order_list.elements ||
 
4216
                   first_sl->select_limit) &&           
 
4217
                  unit->add_fake_select_lex(lex->session))
 
4218
                DRIZZLE_YYABORT;
 
4219
            }
3809
4220
          }
3810
4221
          order_list
3811
4222
        ;
3812
4223
 
3813
4224
order_list:
3814
4225
          order_list ',' order_ident order_dir
3815
 
          {
3816
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3817
 
              DRIZZLE_YYABORT;
3818
 
          }
 
4226
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3819
4227
        | order_ident order_dir
3820
 
          {
3821
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3822
 
              DRIZZLE_YYABORT;
3823
 
          }
 
4228
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3824
4229
        ;
3825
4230
 
3826
4231
order_dir:
3832
4237
opt_limit_clause_init:
3833
4238
          /* empty */
3834
4239
          {
3835
 
            Select_Lex *sel= Lex->current_select;
 
4240
            LEX *lex= Lex;
 
4241
            Select_Lex *sel= lex->current_select;
3836
4242
            sel->offset_limit= 0;
3837
4243
            sel->select_limit= 0;
3838
4244
          }
3881
4287
delete_limit_clause:
3882
4288
          /* empty */
3883
4289
          {
3884
 
            Lex->current_select->select_limit= 0;
 
4290
            LEX *lex=Lex;
 
4291
            lex->current_select->select_limit= 0;
3885
4292
          }
3886
4293
        | LIMIT limit_option
3887
4294
          {
3892
4299
        ;
3893
4300
 
3894
4301
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); }
 
4302
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4303
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4304
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4305
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4306
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4307
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
3901
4308
        ;
3902
4309
 
3903
4310
ulonglong_num:
3910
4317
 
3911
4318
select_var_list_init:
3912
4319
          {
3913
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4320
            LEX *lex=Lex;
 
4321
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3914
4322
              DRIZZLE_YYABORT;
3915
4323
          }
3916
4324
          select_var_list
3923
4331
        ;
3924
4332
 
3925
4333
select_var_ident: 
3926
 
          '@' user_variable_ident
 
4334
          '@' ident_or_text
3927
4335
          {
3928
 
            if (Lex->result)
3929
 
            {
3930
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3931
 
            }
 
4336
            LEX *lex=Lex;
 
4337
            if (lex->result)
 
4338
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3932
4339
            else
3933
 
            {
3934
4340
              /*
3935
4341
                The parser won't create select_result instance only
3936
4342
                if it's an EXPLAIN.
3937
4343
              */
3938
 
              assert(Lex->describe);
3939
 
            }
 
4344
              assert(lex->describe);
3940
4345
          }
3941
4346
        ;
3942
4347
 
3949
4354
into_destination:
3950
4355
          OUTFILE TEXT_STRING_filesystem
3951
4356
          {
3952
 
            Lex->setCacheable(false);
3953
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3954
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4357
            LEX *lex= Lex;
 
4358
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4359
                !(lex->result= new select_export(lex->exchange)))
3955
4360
              DRIZZLE_YYABORT;
3956
4361
          }
3957
4362
          opt_field_term opt_line_term
3958
4363
        | DUMPFILE TEXT_STRING_filesystem
3959
4364
          {
3960
 
            if (not Lex->describe)
 
4365
            LEX *lex=Lex;
 
4366
            if (!lex->describe)
3961
4367
            {
3962
 
              Lex->setCacheable(false);
3963
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4368
              if (!(lex->exchange= new file_exchange($2.str,1)))
3964
4369
                DRIZZLE_YYABORT;
3965
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4370
              if (!(lex->result= new select_dump(lex->exchange)))
3966
4371
                DRIZZLE_YYABORT;
3967
4372
            }
3968
4373
          }
3969
4374
        | select_var_list_init
3970
 
          {Lex->setCacheable(false);}
 
4375
          { }
3971
4376
        ;
3972
4377
 
3973
4378
/*
3975
4380
*/
3976
4381
 
3977
4382
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;
 
4383
          DROP opt_temporary table_or_tables if_exists table_list
 
4384
          {
 
4385
            LEX *lex=Lex;
 
4386
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4387
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4388
            lex->statement= statement;
 
4389
            if (lex->statement == NULL)
 
4390
              DRIZZLE_YYABORT;
3986
4391
            statement->drop_temporary= $2;
3987
4392
            statement->drop_if_exists= $4;
3988
4393
          }
3989
4394
        | DROP build_method INDEX_SYM ident ON table_ident {}
3990
4395
          {
3991
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
3992
 
            Lex->statement= statement;
 
4396
            LEX *lex=Lex;
 
4397
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4398
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4399
            lex->statement= statement;
 
4400
            if (lex->statement == NULL)
 
4401
              DRIZZLE_YYABORT;
3993
4402
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
3994
4403
            statement->alter_info.build_method= $2;
3995
4404
            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))
 
4405
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4406
                                                        TL_OPTION_UPDATING))
3998
4407
              DRIZZLE_YYABORT;
3999
4408
          }
4000
 
        | DROP DATABASE if_exists schema_name
 
4409
        | DROP DATABASE if_exists ident
4001
4410
          {
4002
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4003
 
            Lex->statement= statement;
 
4411
            LEX *lex=Lex;
 
4412
            lex->sql_command= SQLCOM_DROP_DB;
 
4413
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4414
            lex->statement= statement;
 
4415
            if (lex->statement == NULL)
 
4416
              DRIZZLE_YYABORT;
4004
4417
            statement->drop_if_exists=$3;
4005
 
            Lex->name= $4;
 
4418
            lex->name= $4;
4006
4419
          }
4007
 
        ;
4008
 
 
4009
4420
table_list:
4010
4421
          table_name
4011
4422
        | table_list ',' table_name
4020
4431
        ;
4021
4432
 
4022
4433
if_exists:
4023
 
          /* empty */ { $$= false; }
4024
 
        | IF EXISTS { $$= true; }
 
4434
          /* empty */ { $$= 0; }
 
4435
        | IF EXISTS { $$= 1; }
4025
4436
        ;
4026
4437
 
4027
4438
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
 
 
 
4439
          /* empty */ { $$= 0; }
 
4440
        | TEMPORARY_SYM { $$= 1; }
 
4441
        ;
4068
4442
/*
4069
4443
** Insert : add new data to table
4070
4444
*/
4072
4446
insert:
4073
4447
          INSERT
4074
4448
          {
4075
 
            Lex->statement= new statement::Insert(YYSession);
4076
 
            Lex->duplicates= DUP_ERROR;
4077
 
            init_select(Lex);
 
4449
            LEX *lex= Lex;
 
4450
            lex->sql_command= SQLCOM_INSERT;
 
4451
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4452
            if (lex->statement == NULL)
 
4453
              DRIZZLE_YYABORT;
 
4454
            lex->duplicates= DUP_ERROR;
 
4455
            mysql_init_select(lex);
4078
4456
            /* for subselects */
4079
 
            Lex->lock_option= TL_READ;
 
4457
            lex->lock_option= TL_READ;
4080
4458
          }
4081
4459
          opt_ignore insert2
4082
4460
          {
4090
4468
replace:
4091
4469
          REPLACE
4092
4470
          {
4093
 
            Lex->statement= new statement::Replace(YYSession);
4094
 
            Lex->duplicates= DUP_REPLACE;
4095
 
            init_select(Lex);
 
4471
            LEX *lex= Lex;
 
4472
            lex->sql_command= SQLCOM_REPLACE;
 
4473
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4474
            if (lex->statement == NULL)
 
4475
              DRIZZLE_YYABORT;
 
4476
            lex->duplicates= DUP_REPLACE;
 
4477
            mysql_init_select(lex);
4096
4478
          }
4097
4479
          insert2
4098
4480
          {
4111
4493
insert_table:
4112
4494
          table_name
4113
4495
          {
4114
 
            Lex->field_list.clear();
4115
 
            Lex->many_values.clear();
4116
 
            Lex->insert_list=0;
 
4496
            LEX *lex=Lex;
 
4497
            lex->field_list.empty();
 
4498
            lex->many_values.empty();
 
4499
            lex->insert_list=0;
4117
4500
          };
4118
4501
 
4119
4502
insert_field_spec:
4120
4503
          insert_values {}
4121
4504
        | '(' ')' insert_values {}
4122
4505
        | '(' fields ')' insert_values {}
4123
 
        | SET_SYM
 
4506
        | SET
4124
4507
          {
4125
 
            if (not (Lex->insert_list = new List_item) ||
4126
 
                Lex->many_values.push_back(Lex->insert_list))
 
4508
            LEX *lex=Lex;
 
4509
            if (!(lex->insert_list = new List_item) ||
 
4510
                lex->many_values.push_back(lex->insert_list))
4127
4511
              DRIZZLE_YYABORT;
4128
4512
          }
4129
4513
          ident_eq_list
4137
4521
insert_values:
4138
4522
          VALUES values_list {}
4139
4523
        | VALUE_SYM values_list {}
4140
 
        | stored_select
4141
 
          {
4142
 
            Lex->current_select->set_braces(0);
4143
 
          }
 
4524
        | create_select
 
4525
          { Lex->current_select->set_braces(0);}
4144
4526
          union_clause {}
4145
 
        | '(' stored_select ')'
4146
 
          {
4147
 
            Lex->current_select->set_braces(1);
4148
 
          }
 
4527
        | '(' create_select ')'
 
4528
          { Lex->current_select->set_braces(1);}
4149
4529
          union_opt {}
4150
4530
        ;
4151
4531
 
4160
4540
        ;
4161
4541
 
4162
4542
ident_eq_value:
4163
 
          simple_ident equal expr_or_default
 
4543
          simple_ident_nospvar equal expr_or_default
4164
4544
          {
4165
 
            if (Lex->field_list.push_back($1) ||
4166
 
                Lex->insert_list->push_back($3))
 
4545
            LEX *lex=Lex;
 
4546
            if (lex->field_list.push_back($1) ||
 
4547
                lex->insert_list->push_back($3))
4167
4548
              DRIZZLE_YYABORT;
4168
4549
          }
4169
4550
        ;
4170
4551
 
4171
4552
equal:
4172
 
          '=' {}
 
4553
          EQ {}
4173
4554
        | SET_VAR {}
4174
4555
        ;
4175
4556
 
4186
4567
          }
4187
4568
          opt_values ')'
4188
4569
          {
4189
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4570
            LEX *lex=Lex;
 
4571
            if (lex->many_values.push_back(lex->insert_list))
4190
4572
              DRIZZLE_YYABORT;
4191
4573
          }
4192
4574
        ;
4223
4605
/* Update rows in a table */
4224
4606
 
4225
4607
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)
 
4608
          UPDATE_SYM opt_ignore table_ident
 
4609
          {
 
4610
            LEX *lex= Lex;
 
4611
            mysql_init_select(lex);
 
4612
            lex->sql_command= SQLCOM_UPDATE;
 
4613
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4614
            if (lex->statement == NULL)
 
4615
              DRIZZLE_YYABORT;
 
4616
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4617
            lex->duplicates= DUP_ERROR;
 
4618
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4619
              DRIZZLE_YYABORT;
 
4620
          }
 
4621
          SET update_list
 
4622
          {
 
4623
            LEX *lex= Lex;
 
4624
            if (lex->select_lex.get_table_list()->derived)
4236
4625
            {
4237
4626
              /* it is single table update and it is update of derived table */
4238
4627
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4239
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4628
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4240
4629
              DRIZZLE_YYABORT;
4241
4630
            }
4242
4631
            /*
4243
4632
              In case of multi-update setting write lock for all tables may
4244
4633
              be too pessimistic. We will decrease lock level if possible in
4245
 
              multi_update().
 
4634
              mysql_multi_update().
4246
4635
            */
4247
4636
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4248
4637
          }
4255
4644
        ;
4256
4645
 
4257
4646
update_elem:
4258
 
          simple_ident equal expr_or_default
 
4647
          simple_ident_nospvar equal expr_or_default
4259
4648
          {
4260
4649
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4261
4650
              DRIZZLE_YYABORT;
4268
4657
        ;
4269
4658
 
4270
4659
insert_update_elem:
4271
 
          simple_ident equal expr_or_default
 
4660
          simple_ident_nospvar equal expr_or_default
4272
4661
          {
4273
 
          if (Lex->update_list.push_back($1) ||
4274
 
              Lex->value_list.push_back($3))
 
4662
          LEX *lex= Lex;
 
4663
          if (lex->update_list.push_back($1) ||
 
4664
              lex->value_list.push_back($3))
4275
4665
              DRIZZLE_YYABORT;
4276
4666
          }
4277
4667
        ;
4279
4669
/* Delete rows from a table */
4280
4670
 
4281
4671
delete:
4282
 
          DELETE_SYM opt_delete_option FROM table_ident
 
4672
          DELETE_SYM
4283
4673
          {
4284
 
            Lex->statement= new statement::Delete(YYSession);
4285
 
            init_select(Lex);
4286
 
            Lex->lock_option= TL_WRITE_DEFAULT;
4287
 
            Lex->select_lex.init_order();
 
4674
            LEX *lex= Lex;
 
4675
            lex->sql_command= SQLCOM_DELETE;
 
4676
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4677
            if (lex->statement == NULL)
 
4678
              DRIZZLE_YYABORT;
 
4679
            mysql_init_select(lex);
 
4680
            lex->lock_option= TL_WRITE_DEFAULT;
 
4681
            lex->ignore= 0;
 
4682
            lex->select_lex.init_order();
 
4683
          }
 
4684
          opt_delete_options single_multi
 
4685
        ;
4288
4686
 
4289
 
            if (!Lex->current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING,
 
4687
single_multi:
 
4688
          FROM table_ident
 
4689
          {
 
4690
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4290
4691
                                           Lex->lock_option))
4291
4692
              DRIZZLE_YYABORT;
4292
4693
          }
4294
4695
          delete_limit_clause {}
4295
4696
        ;
4296
4697
 
 
4698
opt_delete_options:
 
4699
          /* empty */ {}
 
4700
        | opt_delete_option opt_delete_options {}
 
4701
        ;
 
4702
 
4297
4703
opt_delete_option:
4298
 
           /* empty */ { Lex->ignore= 0; }
4299
 
         | IGNORE_SYM  { Lex->ignore= 1; }
 
4704
         IGNORE_SYM   { Lex->ignore= 1; }
4300
4705
        ;
4301
4706
 
4302
4707
truncate:
4303
4708
          TRUNCATE_SYM opt_table_sym table_name
4304
4709
          {
4305
 
            Lex->statement= new statement::Truncate(YYSession);
4306
 
            Lex->select_lex.options= 0;
4307
 
            Lex->select_lex.init_order();
 
4710
            LEX* lex= Lex;
 
4711
            lex->sql_command= SQLCOM_TRUNCATE;
 
4712
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4713
            if (lex->statement == NULL)
 
4714
              DRIZZLE_YYABORT;
 
4715
            lex->select_lex.options= 0;
 
4716
            lex->select_lex.init_order();
4308
4717
          }
4309
4718
        ;
4310
4719
 
4318
4727
show:
4319
4728
          SHOW
4320
4729
          {
4321
 
            Lex->lock_option= TL_READ;
4322
 
            init_select(Lex);
4323
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4730
            LEX *lex=Lex;
 
4731
            lex->wild=0;
 
4732
            lex->lock_option= TL_READ;
 
4733
            mysql_init_select(lex);
 
4734
            lex->current_select->parsing_place= SELECT_LIST;
4324
4735
          }
4325
4736
          show_param
4326
4737
          {}
4327
4738
        ;
4328
4739
 
4329
 
/* SHOW SCHEMAS */
4330
4740
show_param:
4331
4741
           DATABASES show_wild
4332
4742
           {
4333
 
             if (not show::buildScemas(YYSession))
4334
 
               DRIZZLE_YYABORT;
 
4743
             LEX *lex= Lex;
 
4744
             Session *session= YYSession;
 
4745
 
 
4746
             lex->sql_command= SQLCOM_SELECT;
 
4747
             lex->statement=
 
4748
               new(std::nothrow) statement::Select(session);
 
4749
             if (lex->statement == NULL)
 
4750
               DRIZZLE_YYABORT;
 
4751
 
 
4752
             std::string column_name= "Database";
 
4753
             if (Lex->wild)
 
4754
             {
 
4755
               column_name.append(" (");
 
4756
               column_name.append(Lex->wild->ptr());
 
4757
               column_name.append(")");
 
4758
             }
 
4759
 
 
4760
             if (Lex->current_select->where)
 
4761
             {
 
4762
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
4763
                 DRIZZLE_YYABORT;
 
4764
             }
 
4765
             else
 
4766
             {
 
4767
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
4768
                 DRIZZLE_YYABORT;
 
4769
             }
 
4770
 
 
4771
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4772
             my_field->is_autogenerated_name= false;
 
4773
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4774
 
 
4775
             if (session->add_item_to_list(my_field))
 
4776
               DRIZZLE_YYABORT;
 
4777
 
 
4778
              if (session->add_order_to_list(my_field, true))
 
4779
                DRIZZLE_YYABORT;
4335
4780
           }
4336
 
           /* SHOW TABLES */
4337
4781
         | TABLES opt_db show_wild
4338
4782
           {
4339
 
             if (not show::buildTables(YYSession, $2))
4340
 
               DRIZZLE_YYABORT;
 
4783
             LEX *lex= Lex;
 
4784
             Session *session= YYSession;
 
4785
 
 
4786
             lex->sql_command= SQLCOM_SELECT;
 
4787
 
 
4788
             statement::Select *select=
 
4789
               new(std::nothrow) statement::Select(YYSession);
 
4790
 
 
4791
             lex->statement= select;
 
4792
 
 
4793
             if (lex->statement == NULL)
 
4794
               DRIZZLE_YYABORT;
 
4795
 
 
4796
 
 
4797
              std::string column_name= "Tables_in_";
 
4798
 
 
4799
              if ($2)
 
4800
              {
 
4801
                SchemaIdentifier identifier($2);
 
4802
                column_name.append($2);
 
4803
                lex->select_lex.db= $2;
 
4804
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4805
                {
 
4806
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
4807
                }
 
4808
                select->setShowPredicate($2, "");
 
4809
              }
 
4810
              else if (not session->db.empty())
 
4811
              {
 
4812
                column_name.append(session->db);
 
4813
                select->setShowPredicate(session->db, "");
 
4814
              }
 
4815
              else
 
4816
              {
 
4817
                 my_error(ER_NO_DB_ERROR, MYF(0));
 
4818
              }
 
4819
 
 
4820
 
 
4821
             if (Lex->wild)
 
4822
             {
 
4823
               column_name.append(" (");
 
4824
               column_name.append(Lex->wild->ptr());
 
4825
               column_name.append(")");
 
4826
             }
 
4827
 
 
4828
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
4829
               DRIZZLE_YYABORT;
 
4830
 
 
4831
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4832
             my_field->is_autogenerated_name= false;
 
4833
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4834
 
 
4835
             if (session->add_item_to_list(my_field))
 
4836
               DRIZZLE_YYABORT;
 
4837
 
 
4838
              if (session->add_order_to_list(my_field, true))
 
4839
                DRIZZLE_YYABORT;
4341
4840
           }
4342
 
           /* SHOW TEMPORARY TABLES */
4343
4841
         | TEMPORARY_SYM TABLES show_wild
4344
4842
           {
4345
 
             if (not show::buildTemporaryTables(YYSession))
4346
 
               DRIZZLE_YYABORT;
 
4843
             LEX *lex= Lex;
 
4844
             Session *session= YYSession;
 
4845
 
 
4846
             lex->sql_command= SQLCOM_SELECT;
 
4847
 
 
4848
             statement::Select *select=
 
4849
               new(std::nothrow) statement::Select(YYSession);
 
4850
 
 
4851
             lex->statement= select;
 
4852
 
 
4853
             if (lex->statement == NULL)
 
4854
               DRIZZLE_YYABORT;
 
4855
 
 
4856
 
 
4857
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
 
4858
               DRIZZLE_YYABORT;
 
4859
 
 
4860
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4861
                                                           context,
 
4862
                                                           NULL, NULL, "*")))
 
4863
               DRIZZLE_YYABORT;
 
4864
             (session->lex->current_select->with_wild)++;
 
4865
 
4347
4866
           }
4348
 
           /* SHOW TABLE STATUS */
4349
4867
         | TABLE_SYM STATUS_SYM opt_db show_wild
4350
4868
           {
4351
 
             if (not show::buildTableStatus(YYSession, $3))
4352
 
               DRIZZLE_YYABORT;
 
4869
             LEX *lex= Lex;
 
4870
             lex->sql_command= SQLCOM_SELECT;
 
4871
             statement::Select *select=
 
4872
               new(std::nothrow) statement::Select(YYSession);
 
4873
 
 
4874
             lex->statement= select;
 
4875
 
 
4876
             if (lex->statement == NULL)
 
4877
               DRIZZLE_YYABORT;
 
4878
 
 
4879
             Session *session= YYSession;
 
4880
 
 
4881
             std::string column_name= "Tables_in_";
 
4882
 
 
4883
             if ($3)
 
4884
             {
 
4885
               lex->select_lex.db= $3;
 
4886
 
 
4887
               SchemaIdentifier identifier($3);
 
4888
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
4889
               {
 
4890
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
4891
               }
 
4892
 
 
4893
               select->setShowPredicate($3, "");
 
4894
             }
 
4895
             else
 
4896
             {
 
4897
               select->setShowPredicate(session->db, "");
 
4898
             }
 
4899
 
 
4900
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
4901
               DRIZZLE_YYABORT;
 
4902
 
 
4903
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4904
                                                           context,
 
4905
                                                           NULL, NULL, "*")))
 
4906
               DRIZZLE_YYABORT;
 
4907
             (session->lex->current_select->with_wild)++;
4353
4908
           }
4354
 
           /* SHOW COLUMNS FROM table_name */
4355
4909
        | 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 */
 
4910
          {
 
4911
             LEX *lex= Lex;
 
4912
             Session *session= YYSession;
 
4913
             statement::Select *select;
 
4914
 
 
4915
             lex->sql_command= SQLCOM_SELECT;
 
4916
 
 
4917
             select= new(std::nothrow) statement::Select(session);
 
4918
 
 
4919
             lex->statement= select;
 
4920
 
 
4921
             if (lex->statement == NULL)
 
4922
               DRIZZLE_YYABORT;
 
4923
 
 
4924
             if ($4)
 
4925
              select->setShowPredicate($4, $3->table.str);
 
4926
             else if ($3->db.str)
 
4927
              select->setShowPredicate($3->db.str, $3->table.str);
 
4928
             else
 
4929
              select->setShowPredicate(session->db, $3->table.str);
 
4930
 
 
4931
             {
 
4932
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4933
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4934
               {
 
4935
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
4936
                            select->getShowSchema().c_str(), 
 
4937
                            $3->table.str);
 
4938
               }
 
4939
             }
 
4940
 
 
4941
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
4942
               DRIZZLE_YYABORT;
 
4943
 
 
4944
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4945
                                                           context,
 
4946
                                                           NULL, NULL, "*")))
 
4947
               DRIZZLE_YYABORT;
 
4948
             (session->lex->current_select->with_wild)++;
 
4949
 
 
4950
          }
4361
4951
        | 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
 
           }
 
4952
          {
 
4953
             LEX *lex= Lex;
 
4954
             Session *session= YYSession;
 
4955
             statement::Select *select;
 
4956
 
 
4957
             lex->sql_command= SQLCOM_SELECT;
 
4958
 
 
4959
             select= new(std::nothrow) statement::Select(session);
 
4960
 
 
4961
             lex->statement= select;
 
4962
 
 
4963
             if (lex->statement == NULL)
 
4964
               DRIZZLE_YYABORT;
 
4965
 
 
4966
             if ($4)
 
4967
              select->setShowPredicate($4, $3->table.str);
 
4968
             else if ($3->db.str)
 
4969
              select->setShowPredicate($3->db.str, $3->table.str);
 
4970
             else
 
4971
              select->setShowPredicate(session->db, $3->table.str);
 
4972
 
 
4973
             {
 
4974
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
 
4975
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4976
               {
 
4977
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
4978
                            select->getShowSchema().c_str(), 
 
4979
                            $3->table.str);
 
4980
               }
 
4981
             }
 
4982
 
 
4983
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
4984
               DRIZZLE_YYABORT;
 
4985
 
 
4986
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4987
                                                           context,
 
4988
                                                           NULL, NULL, "*")))
 
4989
               DRIZZLE_YYABORT;
 
4990
             (session->lex->current_select->with_wild)++;
 
4991
          }
4366
4992
        | COUNT_SYM '(' '*' ')' WARNINGS
4367
4993
          {
4368
 
            show::buildSelectWarning(YYSession);
 
4994
            (void) create_select_for_variable("warning_count");
 
4995
            LEX *lex= Lex;
 
4996
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4997
            if (lex->statement == NULL)
 
4998
              DRIZZLE_YYABORT;
4369
4999
          }
4370
5000
        | COUNT_SYM '(' '*' ')' ERRORS
4371
5001
          {
4372
 
            show::buildSelectError(YYSession);
 
5002
            (void) create_select_for_variable("error_count");
 
5003
            LEX *lex= Lex;
 
5004
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5005
            if (lex->statement == NULL)
 
5006
              DRIZZLE_YYABORT;
4373
5007
          }
4374
5008
        | WARNINGS opt_limit_clause_init
4375
5009
          {
4376
 
            show::buildWarnings(YYSession);
 
5010
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
5011
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
5012
            if (Lex->statement == NULL)
 
5013
              DRIZZLE_YYABORT;
4377
5014
          }
4378
5015
        | ERRORS opt_limit_clause_init
4379
5016
          {
4380
 
            show::buildErrors(YYSession);
 
5017
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
5018
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
5019
            if (Lex->statement == NULL)
 
5020
              DRIZZLE_YYABORT;
4381
5021
          }
4382
5022
        | 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
 
          }
 
5023
           {
 
5024
             LEX *lex= Lex;
 
5025
             lex->sql_command= SQLCOM_SELECT;
 
5026
             lex->statement=
 
5027
               new(std::nothrow) statement::Select(YYSession);
 
5028
             if (lex->statement == NULL)
 
5029
               DRIZZLE_YYABORT;
 
5030
 
 
5031
             Session *session= YYSession;
 
5032
 
 
5033
             if ($1 == OPT_GLOBAL)
 
5034
             {
 
5035
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5036
                 DRIZZLE_YYABORT;
 
5037
             }
 
5038
             else
 
5039
             {
 
5040
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5041
                 DRIZZLE_YYABORT;
 
5042
             }
 
5043
 
 
5044
             std::string key("Variable_name");
 
5045
             std::string value("Value");
 
5046
 
 
5047
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5048
             my_field->is_autogenerated_name= false;
 
5049
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5050
 
 
5051
             if (session->add_item_to_list(my_field))
 
5052
               DRIZZLE_YYABORT;
 
5053
 
 
5054
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5055
             my_field->is_autogenerated_name= false;
 
5056
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5057
 
 
5058
             if (session->add_item_to_list(my_field))
 
5059
               DRIZZLE_YYABORT;
 
5060
           }
4397
5061
        | PROCESSLIST_SYM
4398
5062
          {
4399
 
            if (not show::buildProcesslist(YYSession))
4400
 
              DRIZZLE_YYABORT;
 
5063
           {
 
5064
             LEX *lex= Lex;
 
5065
             lex->sql_command= SQLCOM_SELECT;
 
5066
             lex->statement=
 
5067
               new(std::nothrow) statement::Select(YYSession);
 
5068
             if (lex->statement == NULL)
 
5069
               DRIZZLE_YYABORT;
 
5070
 
 
5071
             Session *session= YYSession;
 
5072
 
 
5073
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
 
5074
               DRIZZLE_YYABORT;
 
5075
 
 
5076
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5077
                                                           context,
 
5078
                                                           NULL, NULL, "*")))
 
5079
               DRIZZLE_YYABORT;
 
5080
             (session->lex->current_select->with_wild)++;
 
5081
           }
4401
5082
          }
4402
5083
        | opt_var_type  VARIABLES show_wild
4403
 
          {
4404
 
            if (not show::buildVariables(YYSession, $1))
4405
 
              DRIZZLE_YYABORT;
4406
 
          }
 
5084
           {
 
5085
             LEX *lex= Lex;
 
5086
             lex->sql_command= SQLCOM_SELECT;
 
5087
             lex->statement=
 
5088
               new(std::nothrow) statement::Select(YYSession);
 
5089
             if (lex->statement == NULL)
 
5090
               DRIZZLE_YYABORT;
 
5091
 
 
5092
             Session *session= YYSession;
 
5093
 
 
5094
             if ($1 == OPT_GLOBAL)
 
5095
             {
 
5096
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5097
                 DRIZZLE_YYABORT;
 
5098
             }
 
5099
             else
 
5100
             {
 
5101
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5102
                 DRIZZLE_YYABORT;
 
5103
             }
 
5104
 
 
5105
             std::string key("Variable_name");
 
5106
             std::string value("Value");
 
5107
 
 
5108
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5109
             my_field->is_autogenerated_name= false;
 
5110
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5111
 
 
5112
             if (session->add_item_to_list(my_field))
 
5113
               DRIZZLE_YYABORT;
 
5114
 
 
5115
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5116
             my_field->is_autogenerated_name= false;
 
5117
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5118
 
 
5119
             if (session->add_item_to_list(my_field))
 
5120
               DRIZZLE_YYABORT;
 
5121
           }
4407
5122
        | CREATE DATABASE opt_if_not_exists ident
4408
5123
          {
4409
 
            if (not show::buildCreateSchema(YYSession, $4))
 
5124
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
 
5125
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
 
5126
            Lex->statement= statement;
 
5127
            if (Lex->statement == NULL)
 
5128
              DRIZZLE_YYABORT;
 
5129
            statement->is_if_not_exists= $3;
 
5130
            Lex->name= $4;
 
5131
          }
 
5132
        | CREATE TABLE_SYM table_ident
 
5133
          {
 
5134
            LEX *lex= Lex;
 
5135
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
5136
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
 
5137
            if (lex->statement == NULL)
 
5138
              DRIZZLE_YYABORT;
 
5139
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4410
5140
              DRIZZLE_YYABORT;
4411
5141
          }
4412
5142
 
4441
5171
describe:
4442
5172
          describe_command table_ident
4443
5173
          {
4444
 
            if (not show::buildDescribe(YYSession, $2))
4445
 
            {
 
5174
            Session *session= YYSession;
 
5175
            statement::Select *select;
 
5176
            LEX *lex= Lex;
 
5177
            lex->lock_option= TL_READ;
 
5178
            mysql_init_select(lex);
 
5179
            lex->current_select->parsing_place= SELECT_LIST;
 
5180
            lex->sql_command= SQLCOM_SELECT;
 
5181
            select= new(std::nothrow) statement::Select(session);
 
5182
            lex->statement= select;
 
5183
            if (lex->statement == NULL)
4446
5184
              DRIZZLE_YYABORT;
4447
 
            }
 
5185
            lex->select_lex.db= 0;
 
5186
 
 
5187
             if ($2->db.str)
 
5188
              select->setShowPredicate($2->db.str, $2->table.str);
 
5189
             else
 
5190
              select->setShowPredicate(session->db, $2->table.str);
 
5191
 
 
5192
             {
 
5193
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
 
5194
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5195
               {
 
5196
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
 
5197
                            select->getShowSchema().c_str(), 
 
5198
                            $2->table.str);
 
5199
               }
 
5200
             }
 
5201
 
 
5202
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5203
               DRIZZLE_YYABORT;
 
5204
 
 
5205
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5206
                                                           context,
 
5207
                                                           NULL, NULL, "*")))
 
5208
               DRIZZLE_YYABORT;
 
5209
             (session->lex->current_select->with_wild)++;
 
5210
 
4448
5211
          }
4449
5212
          opt_describe_column {}
4450
5213
        | describe_command opt_extended_describe
4451
5214
          { Lex->describe|= DESCRIBE_NORMAL; }
4452
5215
          select
4453
5216
          {
4454
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5217
            LEX *lex=Lex;
 
5218
            lex->select_lex.options|= SELECT_DESCRIBE;
4455
5219
          }
4456
5220
        ;
4457
5221
 
4482
5246
flush:
4483
5247
          FLUSH_SYM
4484
5248
          {
4485
 
            Lex->statement= new statement::Flush(YYSession);
 
5249
            LEX *lex=Lex;
 
5250
            lex->sql_command= SQLCOM_FLUSH;
 
5251
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
5252
            if (lex->statement == NULL)
 
5253
              DRIZZLE_YYABORT;
 
5254
            lex->type= 0;
4486
5255
          }
4487
5256
          flush_options
4488
5257
          {}
4515
5284
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4516
5285
            statement->setFlushStatus(true);
4517
5286
          }
4518
 
        | GLOBAL_SYM STATUS_SYM
4519
 
          {
4520
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4521
 
            statement->setFlushGlobalStatus(true);
4522
 
          }
4523
5287
        ;
4524
5288
 
4525
5289
opt_table_list:
4532
5296
kill:
4533
5297
          KILL_SYM kill_option expr
4534
5298
          {
4535
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5299
            LEX *lex=Lex;
 
5300
            lex->value_list.empty();
 
5301
            lex->value_list.push_front($3);
 
5302
            lex->sql_command= SQLCOM_KILL;
 
5303
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5304
            if (lex->statement == NULL)
 
5305
              DRIZZLE_YYABORT;
4536
5306
          }
4537
5307
        ;
4538
5308
 
4539
5309
kill_option:
4540
 
          /* empty */ { $$= false; }
4541
 
        | CONNECTION_SYM { $$= false; }
4542
 
        | QUERY_SYM      { $$= true; }
 
5310
          /* empty */ { Lex->type= 0; }
 
5311
        | CONNECTION_SYM { Lex->type= 0; }
 
5312
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
4543
5313
        ;
4544
5314
 
4545
5315
/* change database */
4546
5316
 
4547
5317
use:
4548
 
          USE_SYM schema_name
 
5318
          USE_SYM ident
4549
5319
          {
4550
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4551
 
            Lex->select_lex.db= $2.str;
 
5320
            LEX *lex=Lex;
 
5321
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5322
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5323
            if (lex->statement == NULL)
 
5324
              DRIZZLE_YYABORT;
 
5325
            lex->select_lex.db= $2.str;
4552
5326
          }
4553
5327
        ;
4554
5328
 
4557
5331
load:
4558
5332
          LOAD data_file
4559
5333
          {
4560
 
            statement::Load *statement= new statement::Load(YYSession);
4561
 
            Lex->statement= statement;
4562
 
 
4563
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5334
            Session *session= YYSession;
 
5335
            LEX *lex= session->lex;
 
5336
 
 
5337
            lex->sql_command= SQLCOM_LOAD;
 
5338
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5339
            lex->statement= statement;
 
5340
            if (lex->statement == NULL)
 
5341
              DRIZZLE_YYABORT;
 
5342
 
 
5343
            Lex_input_stream *lip= session->m_lip;
4564
5344
            statement->fname_start= lip->get_ptr();
4565
5345
          }
4566
5346
          load_data_lock INFILE TEXT_STRING_filesystem
4567
5347
          {
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)))
 
5348
            LEX *lex=Lex;
 
5349
            lex->lock_option= $4;
 
5350
            lex->duplicates= DUP_ERROR;
 
5351
            lex->ignore= 0;
 
5352
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4572
5353
              DRIZZLE_YYABORT;
4573
5354
          }
4574
5355
          opt_duplicate INTO
4575
5356
          {
4576
 
            Lex_input_stream *lip= YYSession->m_lip;
 
5357
            Session *session= YYSession;
 
5358
            Lex_input_stream *lip= session->m_lip;
4577
5359
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
4578
5360
          }
4579
5361
          TABLE_SYM table_ident
4580
5362
          {
 
5363
            LEX *lex=Lex;
4581
5364
            if (!Lex->current_select->add_table_to_list(YYSession,
4582
5365
                    $12, NULL, TL_OPTION_UPDATING,
4583
 
                    Lex->lock_option))
 
5366
                    lex->lock_option))
4584
5367
              DRIZZLE_YYABORT;
4585
 
            Lex->field_list.clear();
4586
 
            Lex->update_list.clear();
4587
 
            Lex->value_list.clear();
 
5368
            lex->field_list.empty();
 
5369
            lex->update_list.empty();
 
5370
            lex->value_list.empty();
4588
5371
          }
4589
5372
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4590
5373
          opt_load_data_set_spec
4608
5391
        | IGNORE_SYM { Lex->ignore= 1; }
4609
5392
        ;
4610
5393
 
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
5394
opt_field_term:
4621
5395
          /* empty */
4622
5396
        | COLUMNS field_term_list
4635
5409
          }
4636
5410
        | OPTIONALLY ENCLOSED BY text_string
4637
5411
          {
4638
 
            assert(Lex->exchange != 0);
4639
 
            Lex->exchange->enclosed= $4;
4640
 
            Lex->exchange->opt_enclosed= 1;
 
5412
            LEX *lex= Lex;
 
5413
            assert(lex->exchange != 0);
 
5414
            lex->exchange->enclosed= $4;
 
5415
            lex->exchange->opt_enclosed= 1;
4641
5416
          }
4642
5417
        | ENCLOSED BY text_string
4643
5418
          {
4702
5477
        ;
4703
5478
 
4704
5479
field_or_var:
4705
 
          simple_ident {$$= $1;}
4706
 
        | '@' user_variable_ident
 
5480
          simple_ident_nospvar {$$= $1;}
 
5481
        | '@' ident_or_text
4707
5482
          { $$= new Item_user_var_as_out_param($2); }
4708
5483
        ;
4709
5484
 
4710
5485
opt_load_data_set_spec:
4711
5486
          /* empty */ {}
4712
 
        | SET_SYM insert_update_list {}
 
5487
        | SET insert_update_list {}
4713
5488
        ;
4714
5489
 
4715
5490
/* Common definitions */
4717
5492
text_literal:
4718
5493
        TEXT_STRING_literal
4719
5494
        {
4720
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5495
          Session *session= YYSession;
 
5496
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4721
5497
        }
4722
5498
        | text_literal TEXT_STRING_literal
4723
5499
          {
4773
5549
            $$ = new Item_null();
4774
5550
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4775
5551
          }
4776
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4777
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5552
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5553
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4778
5554
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4779
5555
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4780
5556
        | DATE_SYM text_literal { $$ = $2; }
4817
5593
**********************************************************************/
4818
5594
 
4819
5595
insert_ident:
4820
 
          simple_ident { $$=$1; }
 
5596
          simple_ident_nospvar { $$=$1; }
4821
5597
        | table_wild { $$=$1; }
4822
5598
        ;
4823
5599
 
4824
5600
table_wild:
4825
5601
          ident '.' '*'
4826
5602
          {
4827
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5603
            Select_Lex *sel= Lex->current_select;
 
5604
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5605
            sel->with_wild++;
4828
5606
          }
4829
5607
        | ident '.' ident '.' '*'
4830
5608
          {
4831
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5609
            Select_Lex *sel= Lex->current_select;
 
5610
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
 
5611
            sel->with_wild++;
4832
5612
          }
4833
5613
        ;
4834
5614
 
4839
5619
simple_ident:
4840
5620
          ident
4841
5621
          {
4842
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5622
            {
 
5623
              Select_Lex *sel=Lex->current_select;
 
5624
              $$= (sel->parsing_place != IN_HAVING ||
 
5625
                  sel->get_in_sum_expr() > 0) ?
 
5626
                  (Item*) new Item_field(Lex->current_context(),
 
5627
                                         (const char *)NULL, NULL, $1.str) :
 
5628
                  (Item*) new Item_ref(Lex->current_context(),
 
5629
                                       (const char *)NULL, NULL, $1.str);
 
5630
            }
 
5631
          }
 
5632
        | simple_ident_q { $$= $1; }
 
5633
        ;
 
5634
 
 
5635
simple_ident_nospvar:
 
5636
          ident
 
5637
          {
 
5638
            Select_Lex *sel=Lex->current_select;
 
5639
            $$= (sel->parsing_place != IN_HAVING ||
 
5640
                sel->get_in_sum_expr() > 0) ?
 
5641
                (Item*) new Item_field(Lex->current_context(),
 
5642
                                       (const char *)NULL, NULL, $1.str) :
 
5643
                (Item*) new Item_ref(Lex->current_context(),
 
5644
                                     (const char *)NULL, NULL, $1.str);
4843
5645
          }
4844
5646
        | simple_ident_q { $$= $1; }
4845
5647
        ;
4847
5649
simple_ident_q:
4848
5650
          ident '.' ident
4849
5651
          {
4850
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5652
            Session *session= YYSession;
 
5653
            LEX *lex= session->lex;
 
5654
 
 
5655
            {
 
5656
              Select_Lex *sel= lex->current_select;
 
5657
              if (sel->no_table_names_allowed)
 
5658
              {
 
5659
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5660
                         MYF(0), $1.str, session->where);
 
5661
              }
 
5662
              $$= (sel->parsing_place != IN_HAVING ||
 
5663
                  sel->get_in_sum_expr() > 0) ?
 
5664
                  (Item*) new Item_field(Lex->current_context(),
 
5665
                                         (const char *)NULL, $1.str, $3.str) :
 
5666
                  (Item*) new Item_ref(Lex->current_context(),
 
5667
                                       (const char *)NULL, $1.str, $3.str);
 
5668
            }
4851
5669
          }
4852
5670
        | '.' ident '.' ident
4853
5671
          {
4854
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5672
            Session *session= YYSession;
 
5673
            LEX *lex= session->lex;
 
5674
            Select_Lex *sel= lex->current_select;
 
5675
            if (sel->no_table_names_allowed)
 
5676
            {
 
5677
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5678
                       MYF(0), $2.str, session->where);
 
5679
            }
 
5680
            $$= (sel->parsing_place != IN_HAVING ||
 
5681
                sel->get_in_sum_expr() > 0) ?
 
5682
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5683
                (Item*) new Item_ref(Lex->current_context(),
 
5684
                                     (const char *)NULL, $2.str, $4.str);
4855
5685
          }
4856
5686
        | ident '.' ident '.' ident
4857
5687
          {
4858
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5688
            Session *session= YYSession;
 
5689
            LEX *lex= session->lex;
 
5690
            Select_Lex *sel= lex->current_select;
 
5691
            if (sel->no_table_names_allowed)
 
5692
            {
 
5693
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5694
                       MYF(0), $3.str, session->where);
 
5695
            }
 
5696
            $$= (sel->parsing_place != IN_HAVING ||
 
5697
                sel->get_in_sum_expr() > 0) ?
 
5698
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5699
                                       $5.str) :
 
5700
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5701
                                     $5.str);
4859
5702
          }
4860
5703
        ;
4861
5704
 
4862
5705
field_ident:
4863
 
          ident 
4864
 
          {
4865
 
            $$=$1;
4866
 
          }
 
5706
          ident { $$=$1;}
4867
5707
        | ident '.' ident '.' ident
4868
5708
          {
4869
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4870
 
              DRIZZLE_YYABORT;
4871
 
 
 
5709
            TableList *table=
 
5710
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5711
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5712
            {
 
5713
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5714
              DRIZZLE_YYABORT;
 
5715
            }
 
5716
            if (my_strcasecmp(table_alias_charset, $3.str,
 
5717
                              table->table_name))
 
5718
            {
 
5719
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
5720
              DRIZZLE_YYABORT;
 
5721
            }
4872
5722
            $$=$5;
4873
5723
          }
4874
5724
        | ident '.' ident
4875
5725
          {
4876
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5726
            TableList *table=
 
5727
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5728
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
5729
            {
 
5730
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4877
5731
              DRIZZLE_YYABORT;
4878
 
 
 
5732
            }
4879
5733
            $$=$3;
4880
5734
          }
4881
 
        | '.' ident 
4882
 
          { /* For Delphi */
4883
 
            $$=$2;
4884
 
          }
 
5735
        | '.' ident { $$=$2;} /* For Delphi */
4885
5736
        ;
4886
5737
 
4887
5738
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
 
5739
          ident { $$=new Table_ident($1); }
 
5740
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
5741
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4908
5742
        ;
4909
5743
 
4910
5744
IDENT_sys:
4911
 
          IDENT 
4912
 
          {
4913
 
            $$= $1;
4914
 
          }
 
5745
          IDENT { $$= $1; }
4915
5746
        | IDENT_QUOTED
4916
5747
          {
4917
5748
            const CHARSET_INFO * const cs= system_charset_info;
4954
5785
          IDENT_sys    { $$=$1; }
4955
5786
        | keyword
4956
5787
          {
4957
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
5788
            Session *session= YYSession;
 
5789
            $$.str= session->strmake($1.str, $1.length);
4958
5790
            $$.length= $1.length;
4959
5791
          }
4960
5792
        ;
4961
5793
 
4962
5794
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          {}
 
5795
          ident           { $$=$1;}
 
5796
        | TEXT_STRING_sys { $$=$1;}
 
5797
        | LEX_HOSTNAME { $$=$1;}
4976
5798
        ;
4977
5799
 
4978
5800
/* Keyword that we allow for identifiers (except SP labels) */
4979
5801
keyword:
4980
5802
          keyword_sp            {}
4981
5803
        | BEGIN_SYM             {}
 
5804
        | BYTE_SYM              {}
4982
5805
        | CHECKSUM_SYM          {}
4983
5806
        | CLOSE_SYM             {}
4984
5807
        | COMMENT_SYM           {}
4985
5808
        | COMMIT_SYM            {}
4986
5809
        | CONTAINS_SYM          {}
4987
5810
        | DEALLOCATE_SYM        {}
4988
 
        | DO_SYM                {}
4989
5811
        | END                   {}
4990
5812
        | FLUSH_SYM             {}
4991
5813
        | NO_SYM                {}
4994
5816
        | SAVEPOINT_SYM         {}
4995
5817
        | SECURITY_SYM          {}
4996
5818
        | SERVER_SYM            {}
4997
 
        | SIGNED_SYM            {}
4998
5819
        | START_SYM             {}
4999
5820
        | STOP_SYM              {}
5000
5821
        | TRUNCATE_SYM          {}
5014
5835
        | ANY_SYM                  {}
5015
5836
        | AT_SYM                   {}
5016
5837
        | AUTO_INC                 {}
 
5838
        | AVG_ROW_LENGTH           {}
5017
5839
        | AVG_SYM                  {}
5018
5840
        | BIT_SYM                  {}
5019
5841
        | BOOL_SYM                 {}
5023
5845
        | CHAIN_SYM                {}
5024
5846
        | COALESCE                 {}
5025
5847
        | COLLATION_SYM            {}
 
5848
        | COLUMN_FORMAT_SYM        {}
5026
5849
        | COLUMNS                  {}
5027
5850
        | COMMITTED_SYM            {}
5028
5851
        | COMPACT_SYM              {}
5029
5852
        | COMPRESSED_SYM           {}
5030
5853
        | CONCURRENT               {}
5031
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
5854
        | CONNECTION_SYM           {}
5032
5855
        | CONSISTENT_SYM           {}
5033
5856
        | CUBE_SYM                 {}
5034
5857
        | DATA_SYM                 {}
5035
5858
        | DATABASES                {}
 
5859
        | DATAFILE_SYM             {}
5036
5860
        | DATETIME_SYM             {}
5037
 
        | DATE_SYM                 {} /* Create conflict */
 
5861
        | DATE_SYM                 {}
5038
5862
        | DAY_SYM                  {}
5039
5863
        | DISABLE_SYM              {}
5040
5864
        | DISCARD                  {}
5065
5889
        | KEY_BLOCK_SIZE           {}
5066
5890
        | LAST_SYM                 {}
5067
5891
        | LEVEL_SYM                {}
 
5892
        | LIST_SYM                 {}
5068
5893
        | LOCAL_SYM                {}
5069
5894
        | LOCKS_SYM                {}
5070
5895
        | LOGS_SYM                 {}
 
5896
        | MAX_ROWS                 {}
 
5897
        | MAX_SIZE_SYM             {}
5071
5898
        | MAX_VALUE_SYM            {}
5072
5899
        | MEDIUM_SYM               {}
5073
5900
        | MERGE_SYM                {}
5074
5901
        | MICROSECOND_SYM          {}
5075
5902
        | MINUTE_SYM               {}
 
5903
        | MIN_ROWS                 {}
5076
5904
        | MODIFY_SYM               {}
5077
5905
        | MODE_SYM                 {}
5078
5906
        | MONTH_SYM                {}
5087
5915
        | ONE_SHOT_SYM             {}
5088
5916
        | ONE_SYM                  {}
5089
5917
        | ONLINE_SYM               {}
 
5918
        | PAGE_SYM                 {}
5090
5919
        | PARTIAL                  {}
 
5920
        | PHASE_SYM                {}
5091
5921
        | PREV_SYM                 {}
5092
5922
        | PROCESS                  {}
5093
5923
        | PROCESSLIST_SYM          {}
5094
5924
        | QUARTER_SYM              {}
5095
 
        | QUERY_SYM                {} // Causes conflict
 
5925
        | QUERY_SYM                {}
 
5926
        | READ_ONLY_SYM            {}
5096
5927
        | REDUNDANT_SYM            {}
5097
5928
        | REPEATABLE_SYM           {}
5098
5929
        | RETURNS_SYM              {}
 
5930
        | REVERSE_SYM              {}
5099
5931
        | ROLLUP_SYM               {}
5100
5932
        | ROUTINE_SYM              {}
5101
5933
        | ROWS_SYM                 {}
5107
5939
        | SESSION_SYM              {}
5108
5940
        | SIMPLE_SYM               {}
5109
5941
        | SHARE_SYM                {}
 
5942
        | SHUTDOWN                 {}
5110
5943
        | SNAPSHOT_SYM             {}
 
5944
        | SQL_BUFFER_RESULT        {}
5111
5945
        | STATUS_SYM               {}
 
5946
        | STORAGE_SYM              {}
5112
5947
        | STRING_SYM               {}
5113
5948
        | SUBDATE_SYM              {}
5114
5949
        | SUBJECT_SYM              {}
5115
5950
        | SUSPEND_SYM              {}
 
5951
        | SWAPS_SYM                {}
 
5952
        | SWITCHES_SYM             {}
5116
5953
        | TABLES                   {}
5117
5954
        | TABLESPACE               {}
5118
5955
        | TEMPORARY_SYM            {}
5119
5956
        | TEXT_SYM                 {}
5120
5957
        | TRANSACTION_SYM          {}
5121
 
        | TIME_SYM                 {}
 
5958
        | TIMESTAMP_SYM            {}
5122
5959
        | TIMESTAMP_ADD            {}
5123
5960
        | TIMESTAMP_DIFF           {}
 
5961
        | TYPES_SYM                {}
5124
5962
        | TYPE_SYM                 {}
5125
5963
        | UNCOMMITTED_SYM          {}
5126
5964
        | UNDOFILE_SYM             {}
5127
5965
        | UNKNOWN_SYM              {}
5128
 
        | UUID_SYM                 {}
5129
5966
        | USER                     {}
5130
5967
        | VARIABLES                {}
5131
5968
        | VALUE_SYM                {}
5138
5975
/* Option functions */
5139
5976
 
5140
5977
set:
5141
 
          SET_SYM opt_option
 
5978
          SET opt_option
5142
5979
          {
5143
 
            Lex->statement= new statement::SetOption(YYSession);
 
5980
            LEX *lex=Lex;
 
5981
            lex->sql_command= SQLCOM_SET_OPTION;
 
5982
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
5983
            lex->statement= statement;
 
5984
            if (lex->statement == NULL)
 
5985
              DRIZZLE_YYABORT;
 
5986
            mysql_init_select(lex);
 
5987
            lex->option_type=OPT_SESSION;
 
5988
            lex->var_list.empty();
5144
5989
          }
5145
5990
          option_value_list
5146
5991
          {}
5157
6002
        ;
5158
6003
 
5159
6004
option_type_value:
5160
 
          { }
 
6005
          {
 
6006
          }
5161
6007
          ext_option_value
5162
 
          { }
 
6008
          {
 
6009
          }
5163
6010
        ;
5164
6011
 
5165
6012
option_type:
5196
6043
sys_option_value:
5197
6044
          option_type internal_variable_name equal set_expr_or_default
5198
6045
          {
 
6046
            LEX *lex=Lex;
 
6047
 
5199
6048
            if ($2.var)
5200
6049
            { /* System variable */
5201
6050
              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)));
 
6051
                lex->option_type= $1;
 
6052
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6053
                                      &$2.base_name, $4));
5206
6054
            }
5207
6055
          }
5208
6056
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5209
6057
          {
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))));
 
6058
            LEX *lex=Lex;
 
6059
            lex->option_type= $1;
 
6060
            lex->var_list.push_back(new set_var(lex->option_type,
 
6061
                                                find_sys_var(YYSession, "tx_isolation"),
 
6062
                                                &null_lex_str,
 
6063
                                                new Item_int((int32_t) $5)));
5216
6064
          }
5217
6065
        ;
5218
6066
 
5219
6067
option_value:
5220
 
          '@' user_variable_ident equal expr
 
6068
          '@' ident_or_text equal expr
5221
6069
          {
5222
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6070
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5223
6071
          }
5224
6072
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5225
6073
          {
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; }
 
6074
            LEX *lex=Lex;
 
6075
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6076
          }
5243
6077
        ;
5244
6078
 
5245
6079
internal_variable_name:
5246
 
          internal_variable_ident
 
6080
          ident
5247
6081
          {
 
6082
            Session *session= YYSession;
 
6083
 
5248
6084
            /* We have to lookup here since local vars can shadow sysvars */
5249
6085
            {
5250
6086
              /* Not an SP local variable */
5251
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6087
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
5252
6088
              if (!tmp)
5253
6089
                DRIZZLE_YYABORT;
5254
6090
              $$.var= tmp;
5280
6116
unlock:
5281
6117
          UNLOCK_SYM
5282
6118
          {
5283
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6119
            LEX *lex= Lex;
 
6120
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6121
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
6122
            if (lex->statement == NULL)
 
6123
              DRIZZLE_YYABORT;
5284
6124
          }
5285
6125
          table_or_tables
5286
6126
          {}
5289
6129
begin:
5290
6130
          BEGIN_SYM
5291
6131
          {
5292
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6132
            LEX *lex=Lex;
 
6133
            lex->sql_command = SQLCOM_BEGIN;
 
6134
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
6135
            if (lex->statement == NULL)
 
6136
              DRIZZLE_YYABORT;
5293
6137
          }
5294
6138
          opt_work {}
5295
6139
        ;
5321
6165
commit:
5322
6166
          COMMIT_SYM opt_work opt_chain opt_release
5323
6167
          {
5324
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6168
            LEX *lex=Lex;
 
6169
            lex->sql_command= SQLCOM_COMMIT;
 
6170
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
6171
            lex->statement= statement;
 
6172
            if (lex->statement == NULL)
 
6173
              DRIZZLE_YYABORT;
 
6174
            statement->tx_chain= $3;
 
6175
            statement->tx_release= $4;
5325
6176
          }
5326
6177
        ;
5327
6178
 
5328
6179
rollback:
5329
6180
          ROLLBACK_SYM opt_work opt_chain opt_release
5330
6181
          {
5331
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6182
            LEX *lex=Lex;
 
6183
            lex->sql_command= SQLCOM_ROLLBACK;
 
6184
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
6185
            lex->statement= statement;
 
6186
            if (lex->statement == NULL)
 
6187
              DRIZZLE_YYABORT;
 
6188
            statement->tx_chain= $3;
 
6189
            statement->tx_release= $4;
5332
6190
          }
5333
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6191
        | ROLLBACK_SYM opt_work
 
6192
          TO_SYM opt_savepoint ident
5334
6193
          {
5335
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6194
            LEX *lex=Lex;
 
6195
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6196
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
6197
            if (lex->statement == NULL)
 
6198
              DRIZZLE_YYABORT;
 
6199
            lex->ident= $5;
5336
6200
          }
5337
6201
        ;
5338
6202
 
5339
6203
savepoint:
5340
 
          SAVEPOINT_SYM savepoint_ident
 
6204
          SAVEPOINT_SYM ident
5341
6205
          {
5342
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6206
            LEX *lex=Lex;
 
6207
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6208
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
6209
            if (lex->statement == NULL)
 
6210
              DRIZZLE_YYABORT;
 
6211
            lex->ident= $2;
5343
6212
          }
5344
6213
        ;
5345
6214
 
5346
6215
release:
5347
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6216
          RELEASE_SYM SAVEPOINT_SYM ident
5348
6217
          {
5349
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6218
            LEX *lex=Lex;
 
6219
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6220
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
6221
            if (lex->statement == NULL)
 
6222
              DRIZZLE_YYABORT;
 
6223
            lex->ident= $3;
5350
6224
          }
5351
6225
        ;
5352
6226
 
5353
 
savepoint_ident:
5354
 
               IDENT_sys
5355
 
               ;
5356
 
 
5357
6227
/*
5358
6228
   UNIONS : glue selects together
5359
6229
*/
5367
6237
union_list:
5368
6238
          UNION_SYM union_option
5369
6239
          {
5370
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6240
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
5371
6241
              DRIZZLE_YYABORT;
5372
6242
          }
5373
6243
          select_init
5388
6258
 
5389
6259
union_order_or_limit:
5390
6260
          {
5391
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5392
 
            Select_Lex *sel= Lex->current_select;
 
6261
            Session *session= YYSession;
 
6262
            LEX *lex= session->lex;
 
6263
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6264
            Select_Lex *sel= lex->current_select;
5393
6265
            Select_Lex_Unit *unit= sel->master_unit();
5394
6266
            Select_Lex *fake= unit->fake_select_lex;
5395
6267
            if (fake)
5396
6268
            {
5397
6269
              unit->global_parameters= fake;
5398
6270
              fake->no_table_names_allowed= 1;
5399
 
              Lex->current_select= fake;
 
6271
              lex->current_select= fake;
5400
6272
            }
5401
 
            YYSession->setWhere("global ORDER clause");
 
6273
            session->where= "global ORDER clause";
5402
6274
          }
5403
6275
          order_or_limit
5404
6276
          {
5405
 
            YYSession->getLex()->current_select->no_table_names_allowed= 0;
5406
 
            YYSession->setWhere("");
 
6277
            Session *session= YYSession;
 
6278
            session->lex->current_select->no_table_names_allowed= 0;
 
6279
            session->where= "";
5407
6280
          }
5408
6281
        ;
5409
6282
 
5434
6307
        | query_expression_body
5435
6308
          UNION_SYM union_option
5436
6309
          {
5437
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6310
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
5438
6311
              DRIZZLE_YYABORT;
5439
6312
          }
5440
6313
          query_specification
5454
6327
 
5455
6328
subselect_start:
5456
6329
          {
5457
 
            if (not Lex->expr_allows_subselect)
 
6330
            LEX *lex=Lex;
 
6331
            if (!lex->expr_allows_subselect)
5458
6332
            {
5459
 
              parser::my_parse_error(YYSession->m_lip);
 
6333
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6334
              my_parse_error(&pass);
5460
6335
              DRIZZLE_YYABORT;
5461
6336
            }
5462
6337
            /*
5466
6341
              (SELECT .. ) UNION ...  becomes
5467
6342
              SELECT * FROM ((SELECT ...) UNION ...)
5468
6343
            */
5469
 
            if (new_select(Lex, 1))
 
6344
            if (mysql_new_select(Lex, 1))
5470
6345
              DRIZZLE_YYABORT;
5471
6346
          }
5472
6347
        ;
5473
6348
 
5474
6349
subselect_end:
5475
6350
          {
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;
 
6351
            LEX *lex=Lex;
 
6352
            lex->pop_context();
 
6353
            Select_Lex *child= lex->current_select;
 
6354
            lex->current_select = lex->current_select->return_after_parsing();
 
6355
            lex->nest_level--;
 
6356
            lex->current_select->n_child_sum_items += child->n_sum_items;
5481
6357
            /*
5482
6358
              A subselect can add fields to an outer select. Reserve space for
5483
6359
              them.
5484
6360
            */
5485
 
            Lex->current_select->select_n_where_fields+=
 
6361
            lex->current_select->select_n_where_fields+=
5486
6362
            child->select_n_where_fields;
5487
6363
          }
5488
6364
        ;