~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

Reverted 1103

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
 
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
38
#define Lex (YYSession->lex)
39
 
 
40
 
#include "config.h"
41
 
#include <cstdio>
42
 
#include "drizzled/parser.h"
 
39
#include <drizzled/server_includes.h>
 
40
#include <drizzled/lex_symbol.h>
 
41
#include <drizzled/function/locate.h>
 
42
#include <drizzled/function/str/char.h>
 
43
#include <drizzled/function/str/collation.h>
 
44
#include <drizzled/function/str/database.h>
 
45
#include <drizzled/function/str/insert.h>
 
46
#include <drizzled/function/str/left.h>
 
47
#include <drizzled/function/str/repeat.h>
 
48
#include <drizzled/function/str/replace.h>
 
49
#include <drizzled/function/str/reverse.h>
 
50
#include <drizzled/function/str/right.h>
 
51
#include <drizzled/function/str/set_collation.h>
 
52
#include <drizzled/function/str/substr.h>
 
53
#include <drizzled/function/str/trim.h>
 
54
#include <drizzled/function/str/user.h>
 
55
#include <drizzled/function/str/weight_string.h>
 
56
 
 
57
#include <drizzled/function/time/curdate.h>
 
58
#include <drizzled/function/time/date_add_interval.h>
 
59
#include <drizzled/function/time/dayofmonth.h>
 
60
#include <drizzled/function/time/extract.h>
 
61
#include <drizzled/function/time/hour.h>
 
62
#include <drizzled/function/time/microsecond.h>
 
63
#include <drizzled/function/time/minute.h>
 
64
#include <drizzled/function/time/month.h>
 
65
#include <drizzled/function/time/now.h>
 
66
#include <drizzled/function/time/quarter.h>
 
67
#include <drizzled/function/time/second.h>
 
68
#include <drizzled/function/time/sysdate_local.h>
 
69
#include <drizzled/function/time/timestamp_diff.h>
 
70
#include <drizzled/function/time/typecast.h>
 
71
#include <drizzled/function/time/year.h>
 
72
 
 
73
#include <drizzled/error.h>
 
74
#include <drizzled/nested_join.h>
 
75
#include <drizzled/sql_parse.h>
 
76
#include <drizzled/item/copy_string.h>
 
77
#include <drizzled/item/cmpfunc.h>
 
78
#include <drizzled/item/uint.h>
 
79
#include <drizzled/item/null.h>
 
80
#include <drizzled/session.h>
 
81
#include <drizzled/item/func.h>
 
82
#include <drizzled/sql_base.h>
 
83
#include <drizzled/item/create.h>
 
84
#include <drizzled/item/default_value.h>
 
85
#include <drizzled/item/insert_value.h>
 
86
#include <drizzled/lex_string.h>
 
87
#include <drizzled/function/get_system_var.h>
 
88
#include <mysys/thr_lock.h>
 
89
#include <drizzled/message/table.pb.h>
 
90
#include <drizzled/command.h>
 
91
#include <drizzled/command/show_status.h>
 
92
#include <drizzled/command/select.h>
 
93
 
 
94
using namespace drizzled;
 
95
 
 
96
class Table_ident;
 
97
class Item;
 
98
class Item_num;
43
99
 
44
100
int yylex(void *yylval, void *yysession);
45
101
 
46
102
#define yyoverflow(A,B,C,D,E,F)               \
47
103
  {                                           \
48
 
    unsigned long val= *(F);                          \
49
 
    if (drizzled::my_yyoverflow((B), (D), &val)) \
 
104
    ulong val= *(F);                          \
 
105
    if (my_yyoverflow((B), (D), &val))        \
50
106
    {                                         \
51
107
      yyerror((char*) (A));                   \
52
108
      return 2;                               \
60
116
#define DRIZZLE_YYABORT                         \
61
117
  do                                          \
62
118
  {                                           \
 
119
    LEX::cleanup_lex_after_parse_error(YYSession);\
63
120
    YYABORT;                                  \
64
121
  } while (0)
65
122
 
66
123
#define DRIZZLE_YYABORT_UNLESS(A)         \
67
124
  if (!(A))                             \
68
125
  {                                     \
69
 
    parser::my_parse_error(YYSession->m_lip);\
 
126
    my_parse_error(ER(ER_SYNTAX_ERROR));\
70
127
    DRIZZLE_YYABORT;                      \
71
128
  }
72
129
 
73
130
 
74
131
#define YYDEBUG 0
75
132
 
76
 
namespace drizzled
77
 
{
78
 
 
79
 
class Table_ident;
80
 
class Item;
81
 
class Item_num;
82
 
 
83
 
namespace item
84
 
{
85
 
class Boolean;
86
 
class True;
87
 
class False;
 
133
/**
 
134
  @brief Push an error message into MySQL error stack with line
 
135
  and position information.
 
136
 
 
137
  This function provides semantic action implementers with a way
 
138
  to push the famous "You have a syntax error near..." error
 
139
  message into the error stack, which is normally produced only if
 
140
  a parse error is discovered internally by the Bison generated
 
141
  parser.
 
142
*/
 
143
 
 
144
static void my_parse_error(const char *s)
 
145
{
 
146
  Session *session= current_session;
 
147
  Lex_input_stream *lip= session->m_lip;
 
148
 
 
149
  const char *yytext= lip->get_tok_start();
 
150
  /* Push an error into the error stack */
 
151
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
152
                  (yytext ? yytext : ""),
 
153
                  lip->yylineno);
88
154
}
89
155
 
90
 
 
91
156
/**
92
157
  @brief Bison callback to report a syntax/OOM error
93
158
 
102
167
  The parser will abort immediately after invoking this callback.
103
168
 
104
169
  This function is not for use in semantic actions and is internal to
105
 
  the parser, as it performs some pre-return cleanup.
106
 
  In semantic actions, please use parser::my_parse_error or my_error to
 
170
  the parser, as it performs some pre-return cleanup. 
 
171
  In semantic actions, please use my_parse_error or my_error to
107
172
  push an error into the error stack and DRIZZLE_YYABORT
108
173
  to abort from the parser.
109
174
*/
110
175
 
111
176
static void DRIZZLEerror(const char *s)
112
177
{
113
 
  parser::errorOn(s);
114
 
}
115
 
 
116
 
} /* namespace drizzled; */
117
 
 
118
 
using namespace drizzled;
 
178
  Session *session= current_session;
 
179
 
 
180
  /*
 
181
    Restore the original LEX if it was replaced when parsing
 
182
    a stored procedure. We must ensure that a parsing error
 
183
    does not leave any side effects in the Session.
 
184
  */
 
185
  LEX::cleanup_lex_after_parse_error(session);
 
186
 
 
187
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
188
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
189
    s= ER(ER_SYNTAX_ERROR);
 
190
  my_parse_error(s);
 
191
}
 
192
 
 
193
/**
 
194
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
195
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
196
  This function returns the proper item for the SQL expression
 
197
  <code>left [NOT] IN ( expr )</code>
 
198
  @param session the current thread
 
199
  @param left the in predicand
 
200
  @param equal true for IN predicates, false for NOT IN predicates
 
201
  @param expr first and only expression of the in value list
 
202
  @return an expression representing the IN predicate.
 
203
*/
 
204
static Item* handle_sql2003_note184_exception(Session *session,
 
205
                                              Item* left, bool equal,
 
206
                                              Item *expr)
 
207
{
 
208
  /*
 
209
    Relevant references for this issue:
 
210
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
211
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
212
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
213
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
214
    - SQL:2003 Feature F561, "Full value expressions".
 
215
 
 
216
    The exception in SQL:2003 Note 184 means:
 
217
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
218
    should be re-interpreted as an Item_in_subselect, which corresponds
 
219
    to a <table subquery> when used inside an <in predicate>.
 
220
 
 
221
    Our reading of Note 184 is reccursive, so that all:
 
222
    - IN (( <subquery> ))
 
223
    - IN ((( <subquery> )))
 
224
    - IN '('^N <subquery> ')'^N
 
225
    - etc
 
226
    should be interpreted as a <table subquery>, no matter how deep in the
 
227
    expression the <subquery> is.
 
228
  */
 
229
 
 
230
  Item *result;
 
231
 
 
232
  if (expr->type() == Item::SUBSELECT_ITEM)
 
233
  {
 
234
    Item_subselect *expr2 = (Item_subselect*) expr;
 
235
 
 
236
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
237
    {
 
238
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
239
      Select_Lex *subselect;
 
240
 
 
241
      /*
 
242
        Implement the mandated change, by altering the semantic tree:
 
243
          left IN Item_singlerow_subselect(subselect)
 
244
        is modified to
 
245
          left IN (subselect)
 
246
        which is represented as
 
247
          Item_in_subselect(left, subselect)
 
248
      */
 
249
      subselect= expr3->invalidate_and_restore_select_lex();
 
250
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
251
 
 
252
      if (! equal)
 
253
        result = negate_expression(session, result);
 
254
 
 
255
      return(result);
 
256
    }
 
257
  }
 
258
 
 
259
  if (equal)
 
260
    result= new (session->mem_root) Item_func_eq(left, expr);
 
261
  else
 
262
    result= new (session->mem_root) Item_func_ne(left, expr);
 
263
 
 
264
  return(result);
 
265
}
 
266
 
 
267
/**
 
268
   @brief Creates a new Select_Lex for a UNION branch.
 
269
 
 
270
   Sets up and initializes a Select_Lex structure for a query once the parser
 
271
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
272
   the new Select_Lex becomes the current one..=
 
273
 
 
274
   @lex The parser state.
 
275
 
 
276
   @is_union_distinct True if the union preceding the new select statement
 
277
   uses UNION DISTINCT.
 
278
 
 
279
   @return <code>false</code> if successful, <code>true</code> if an error was
 
280
   reported. In the latter case parsing should stop.
 
281
 */
 
282
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
283
{
 
284
  if (lex->result)
 
285
  {
 
286
    /* Only the last SELECT can have  INTO...... */
 
287
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
288
    return true;
 
289
  }
 
290
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
291
  {
 
292
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
293
    return true;
 
294
  }
 
295
  /* This counter shouldn't be incremented for UNION parts */
 
296
  lex->nest_level--;
 
297
  if (mysql_new_select(lex, 0))
 
298
    return true;
 
299
  mysql_init_select(lex);
 
300
  lex->current_select->linkage=UNION_TYPE;
 
301
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
302
    lex->current_select->master_unit()->union_distinct=
 
303
      lex->current_select;
 
304
  return false;
 
305
}
 
306
 
 
307
/**
 
308
   @brief Initializes a Select_Lex for a query within parentheses (aka
 
309
   braces).
 
310
 
 
311
   @return false if successful, true if an error was reported. In the latter
 
312
   case parsing should stop.
 
313
 */
 
314
static bool setup_select_in_parentheses(LEX *lex) 
 
315
{
 
316
  Select_Lex * sel= lex->current_select;
 
317
  if (sel->set_braces(1))
 
318
  {
 
319
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
320
    return true;
 
321
  }
 
322
  if (sel->linkage == UNION_TYPE &&
 
323
      !sel->master_unit()->first_select()->braces &&
 
324
      sel->master_unit()->first_select()->linkage ==
 
325
      UNION_TYPE)
 
326
  {
 
327
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
328
    return true;
 
329
  }
 
330
  if (sel->linkage == UNION_TYPE &&
 
331
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
332
      sel->master_unit()->fake_select_lex)
 
333
  {
 
334
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
335
    return true;
 
336
  }
 
337
  /* select in braces, can't contain global parameters */
 
338
  if (sel->master_unit()->fake_select_lex)
 
339
    sel->master_unit()->global_parameters=
 
340
      sel->master_unit()->fake_select_lex;
 
341
  return false;
 
342
}
 
343
 
119
344
%}
120
345
%union {
121
 
  bool boolean;
122
346
  int  num;
123
 
  unsigned long ulong_num;
 
347
  ulong ulong_num;
124
348
  uint64_t ulonglong_number;
125
349
  int64_t longlong_number;
126
 
  drizzled::LEX_STRING lex_str;
127
 
  drizzled::LEX_STRING *lex_str_ptr;
128
 
  drizzled::LEX_SYMBOL symbol;
129
 
  drizzled::Table_ident *table;
 
350
  LEX_STRING lex_str;
 
351
  LEX_STRING *lex_str_ptr;
 
352
  LEX_SYMBOL symbol;
 
353
  Table_ident *table;
130
354
  char *simple_string;
131
 
  drizzled::Item *item;
132
 
  drizzled::Item_num *item_num;
133
 
  drizzled::List<drizzled::Item> *item_list;
134
 
  drizzled::List<drizzled::String> *string_list;
135
 
  drizzled::String *string;
136
 
  drizzled::Key_part_spec *key_part;
137
 
  const drizzled::plugin::Function *udf;
138
 
  drizzled::TableList *table_list;
139
 
  drizzled::enum_field_types field_val;
140
 
  drizzled::sys_var_with_base variable;
141
 
  drizzled::sql_var_t var_type;
142
 
  drizzled::Key::Keytype key_type;
143
 
  drizzled::ha_key_alg key_alg;
144
 
  drizzled::ha_rkey_function ha_rkey_mode;
145
 
  drizzled::enum_tx_isolation tx_isolation;
146
 
  drizzled::Cast_target cast_type;
147
 
  const drizzled::CHARSET_INFO *charset;
148
 
  drizzled::thr_lock_type lock_type;
149
 
  drizzled::interval_type interval, interval_time_st;
150
 
  drizzled::type::timestamp_t date_time_type;
151
 
  drizzled::Select_Lex *select_lex;
152
 
  drizzled::chooser_compare_func_creator boolfunc2creator;
153
 
  drizzled::st_lex *lex;
154
 
  drizzled::index_hint_type index_hint;
155
 
  drizzled::enum_filetype filetype;
156
 
  drizzled::ha_build_method build_method;
157
 
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
158
 
  drizzled::execute_string_t execute_string;
 
355
  Item *item;
 
356
  Item_num *item_num;
 
357
  List<Item> *item_list;
 
358
  List<String> *string_list;
 
359
  String *string;
 
360
  Key_part_spec *key_part;
 
361
  Function_builder *udf;
 
362
  TableList *table_list;
 
363
  struct sys_var_with_base variable;
 
364
  enum enum_var_type var_type;
 
365
  Key::Keytype key_type;
 
366
  enum ha_key_alg key_alg;
 
367
  StorageEngine *db_type;
 
368
  enum row_type row_type;
 
369
  enum column_format_type column_format_type;
 
370
  enum ha_rkey_function ha_rkey_mode;
 
371
  enum enum_tx_isolation tx_isolation;
 
372
  enum Cast_target cast_type;
 
373
  enum ha_choice choice;
 
374
  const CHARSET_INFO *charset;
 
375
  thr_lock_type lock_type;
 
376
  interval_type interval, interval_time_st;
 
377
  enum enum_drizzle_timestamp_type date_time_type;
 
378
  Select_Lex *select_lex;
 
379
  chooser_compare_func_creator boolfunc2creator;
 
380
  struct st_lex *lex;
 
381
  struct p_elem_val *p_elem_value;
 
382
  enum index_hint_type index_hint;
 
383
  enum enum_filetype filetype;
 
384
  enum ha_build_method build_method;
 
385
  enum Foreign_key::fk_option m_fk_option;
159
386
}
160
387
 
161
388
%{
162
 
namespace drizzled
163
 
{
164
 
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
165
 
}
 
389
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
166
390
%}
167
391
 
168
 
%debug
169
392
%pure_parser                                    /* We have threads */
170
 
 
171
393
/*
172
 
  Currently there are 70 shift/reduce conflicts.
 
394
  Currently there are 90 shift/reduce conflicts.
173
395
  We should not introduce new conflicts any more.
174
396
*/
175
 
%expect 70
 
397
%expect 90
176
398
 
177
399
/*
178
400
   Comments for TOKENS.
192
414
*/
193
415
 
194
416
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
 
417
%token  ACCESSIBLE_SYM
195
418
%token  ACTION                        /* SQL-2003-N */
196
 
%token  ADD_SYM                           /* SQL-2003-R */
 
419
%token  ADD                           /* SQL-2003-R */
197
420
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
198
421
%token  AFTER_SYM                     /* SQL-2003-N */
199
422
%token  AGGREGATE_SYM
 
423
%token  ALGORITHM_SYM
200
424
%token  ALL                           /* SQL-2003-R */
201
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
425
%token  ALTER                         /* SQL-2003-R */
202
426
%token  ANALYZE_SYM
203
427
%token  AND_SYM                       /* SQL-2003-R */
204
428
%token  ANY_SYM                       /* SQL-2003-R */
206
430
%token  ASC                           /* SQL-2003-N */
207
431
%token  ASENSITIVE_SYM                /* FUTURE-USE */
208
432
%token  AT_SYM                        /* SQL-2003-R */
 
433
%token  AUTOEXTEND_SIZE_SYM
209
434
%token  AUTO_INC
 
435
%token  AVG_ROW_LENGTH
210
436
%token  AVG_SYM                       /* SQL-2003-N */
211
437
%token  BEFORE_SYM                    /* SQL-2003-N */
212
438
%token  BEGIN_SYM                     /* SQL-2003-R */
213
439
%token  BETWEEN_SYM                   /* SQL-2003-R */
214
440
%token  BIGINT_SYM                    /* SQL-2003-R */
215
441
%token  BINARY                        /* SQL-2003-R */
 
442
%token  BINLOG_SYM
216
443
%token  BIN_NUM
217
444
%token  BIT_SYM                       /* MYSQL-FUNC */
218
445
%token  BLOB_SYM                      /* SQL-2003-R */
 
446
%token  BLOCK_SIZE_SYM
 
447
%token  BLOCK_SYM
219
448
%token  BOOLEAN_SYM                   /* SQL-2003-R */
220
449
%token  BOOL_SYM
221
450
%token  BOTH                          /* SQL-2003-R */
222
451
%token  BTREE_SYM
223
452
%token  BY                            /* SQL-2003-R */
 
453
%token  BYTE_SYM
 
454
%token  CACHE_SYM
224
455
%token  CALL_SYM                      /* SQL-2003-R */
225
456
%token  CASCADE                       /* SQL-2003-N */
226
457
%token  CASCADED                      /* SQL-2003-R */
227
458
%token  CASE_SYM                      /* SQL-2003-R */
228
459
%token  CAST_SYM                      /* SQL-2003-R */
229
 
%token  CATALOG_SYM
230
460
%token  CHAIN_SYM                     /* SQL-2003-N */
231
 
%token  CHANGE_SYM
 
461
%token  CHANGE
 
462
%token  CHANGED
 
463
%token  CHARSET
232
464
%token  CHAR_SYM                      /* SQL-2003-R */
233
465
%token  CHECKSUM_SYM
234
466
%token  CHECK_SYM                     /* SQL-2003-R */
242
474
%token  COMMITTED_SYM                 /* SQL-2003-N */
243
475
%token  COMMIT_SYM                    /* SQL-2003-R */
244
476
%token  COMPACT_SYM
 
477
%token  COMPLETION_SYM
245
478
%token  COMPRESSED_SYM
246
479
%token  CONCURRENT
247
480
%token  CONDITION_SYM                 /* SQL-2003-N */
249
482
%token  CONSISTENT_SYM
250
483
%token  CONSTRAINT                    /* SQL-2003-R */
251
484
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
485
%token  CONTEXT_SYM
 
486
%token  CONTINUE_SYM                  /* SQL-2003-R */
252
487
%token  CONVERT_SYM                   /* SQL-2003-N */
253
488
%token  COUNT_SYM                     /* SQL-2003-N */
254
489
%token  CREATE                        /* SQL-2003-R */
259
494
%token  CURSOR_SYM                    /* SQL-2003-R */
260
495
%token  DATABASE
261
496
%token  DATABASES
 
497
%token  DATAFILE_SYM
262
498
%token  DATA_SYM                      /* SQL-2003-N */
263
499
%token  DATETIME_SYM
264
500
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
274
510
%token  DECIMAL_SYM                   /* SQL-2003-R */
275
511
%token  DECLARE_SYM                   /* SQL-2003-R */
276
512
%token  DEFAULT                       /* SQL-2003-R */
 
513
%token  DELAY_KEY_WRITE_SYM
277
514
%token  DELETE_SYM                    /* SQL-2003-R */
278
515
%token  DESC                          /* SQL-2003-N */
279
516
%token  DESCRIBE                      /* SQL-2003-R */
280
517
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
 
518
%token  DIRECTORY_SYM
281
519
%token  DISABLE_SYM
282
520
%token  DISCARD
283
521
%token  DISTINCT                      /* SQL-2003-R */
284
522
%token  DIV_SYM
285
 
%token  DO_SYM
286
523
%token  DOUBLE_SYM                    /* SQL-2003-R */
287
524
%token  DROP                          /* SQL-2003-R */
288
525
%token  DUMPFILE
290
527
%token  DYNAMIC_SYM                   /* SQL-2003-R */
291
528
%token  EACH_SYM                      /* SQL-2003-R */
292
529
%token  ELSE                          /* SQL-2003-R */
 
530
%token  ELSEIF_SYM
293
531
%token  ENABLE_SYM
294
532
%token  ENCLOSED
295
533
%token  END                           /* SQL-2003-R */
303
541
%token  ESCAPED
304
542
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
543
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
307
544
%token  EXISTS                        /* SQL-2003-R */
 
545
%token  EXIT_SYM
308
546
%token  EXTENDED_SYM
 
547
%token  EXTENT_SIZE_SYM
309
548
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
549
%token  FALSE_SYM                     /* SQL-2003-R */
 
550
%token  FAST_SYM
 
551
%token  FAULTS_SYM
 
552
%token  FETCH_SYM                     /* SQL-2003-R */
 
553
%token  COLUMN_FORMAT_SYM
311
554
%token  FILE_SYM
312
555
%token  FIRST_SYM                     /* SQL-2003-N */
313
556
%token  FIXED_SYM
325
568
%token  GROUP_SYM                     /* SQL-2003-R */
326
569
%token  GROUP_CONCAT_SYM
327
570
%token  GT_SYM                        /* OPERATOR */
 
571
%token  HANDLER_SYM
328
572
%token  HASH_SYM
329
573
%token  HAVING                        /* SQL-2003-R */
330
574
%token  HEX_NUM
 
575
%token  HOST_SYM
 
576
%token  HOSTS_SYM
331
577
%token  HOUR_MICROSECOND_SYM
332
578
%token  HOUR_MINUTE_SYM
333
579
%token  HOUR_SECOND_SYM
334
580
%token  HOUR_SYM                      /* SQL-2003-R */
335
581
%token  IDENT
336
582
%token  IDENTIFIED_SYM
337
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
338
583
%token  IDENT_QUOTED
339
584
%token  IF
340
585
%token  IGNORE_SYM
342
587
%token  INDEXES
343
588
%token  INDEX_SYM
344
589
%token  INFILE
 
590
%token  INITIAL_SIZE_SYM
345
591
%token  INNER_SYM                     /* SQL-2003-R */
346
592
%token  INOUT_SYM                     /* SQL-2003-R */
347
593
%token  INSENSITIVE_SYM               /* SQL-2003-R */
348
594
%token  INSERT                        /* SQL-2003-R */
 
595
%token  INSERT_METHOD
 
596
%token  INSTALL_SYM
349
597
%token  INTERVAL_SYM                  /* SQL-2003-R */
350
598
%token  INTO                          /* SQL-2003-R */
351
599
%token  INT_SYM                       /* SQL-2003-R */
361
609
%token  LAST_SYM                      /* SQL-2003-N */
362
610
%token  LE                            /* OPERATOR */
363
611
%token  LEADING                       /* SQL-2003-R */
 
612
%token  LEAVES
364
613
%token  LEFT                          /* SQL-2003-R */
365
614
%token  LEVEL_SYM
366
615
%token  LEX_HOSTNAME
367
616
%token  LIKE                          /* SQL-2003-R */
368
617
%token  LIMIT
 
618
%token  LINEAR_SYM
369
619
%token  LINES
 
620
%token  LINESTRING
 
621
%token  LIST_SYM
370
622
%token  LOAD
371
623
%token  LOCAL_SYM                     /* SQL-2003-R */
 
624
%token  LOCATOR_SYM                   /* SQL-2003-N */
372
625
%token  LOCKS_SYM
373
626
%token  LOCK_SYM
 
627
%token  LOGFILE_SYM
374
628
%token  LOGS_SYM
375
629
%token  LONG_NUM
376
630
%token  LONG_SYM
 
631
%token  LOOP_SYM
377
632
%token  LT                            /* OPERATOR */
378
633
%token  MATCH                         /* SQL-2003-R */
 
634
%token  MAX_ROWS
 
635
%token  MAX_SIZE_SYM
379
636
%token  MAX_SYM                       /* SQL-2003-N */
380
637
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
381
638
%token  MEDIUM_SYM
382
639
%token  MERGE_SYM                     /* SQL-2003-R */
383
640
%token  MICROSECOND_SYM               /* MYSQL-FUNC */
 
641
%token  MIGRATE_SYM
384
642
%token  MINUTE_MICROSECOND_SYM
385
643
%token  MINUTE_SECOND_SYM
386
644
%token  MINUTE_SYM                    /* SQL-2003-R */
 
645
%token  MIN_ROWS
387
646
%token  MIN_SYM                       /* SQL-2003-N */
388
647
%token  MODE_SYM
389
648
%token  MODIFIES_SYM                  /* SQL-2003-R */
398
657
%token  NEG
399
658
%token  NEW_SYM                       /* SQL-2003-R */
400
659
%token  NEXT_SYM                      /* SQL-2003-N */
 
660
%token  NODEGROUP_SYM
401
661
%token  NONE_SYM                      /* SQL-2003-R */
402
662
%token  NOT_SYM                       /* SQL-2003-R */
403
663
%token  NOW_SYM
 
664
%token  NOWAIT_SYM
404
665
%token  NO_SYM                        /* SQL-2003-R */
 
666
%token  NO_WAIT_SYM
 
667
%token  NO_WRITE_TO_BINLOG
405
668
%token  NULL_SYM                      /* SQL-2003-R */
406
669
%token  NUM
407
670
%token  NUMERIC_SYM                   /* SQL-2003-R */
412
675
%token  ONE_SYM
413
676
%token  ONLINE_SYM
414
677
%token  OPEN_SYM                      /* SQL-2003-R */
415
 
%token  OPTIMIZE                      /* Leave assuming we might add it back */
 
678
%token  OPTIMIZE
 
679
%token  OPTIONS_SYM
416
680
%token  OPTION                        /* SQL-2003-N */
417
681
%token  OPTIONALLY
418
682
%token  ORDER_SYM                     /* SQL-2003-R */
420
684
%token  OUTER
421
685
%token  OUTFILE
422
686
%token  OUT_SYM                       /* SQL-2003-R */
 
687
%token  PACK_KEYS_SYM
 
688
%token  PAGE_SYM
 
689
%token  PAGE_CHECKSUM_SYM
 
690
%token  PARAM_MARKER
423
691
%token  PARTIAL                       /* SQL-2003-N */
 
692
%token  PHASE_SYM
 
693
%token  POINT_SYM
 
694
%token  PORT_SYM
424
695
%token  POSITION_SYM                  /* SQL-2003-N */
425
696
%token  PRECISION                     /* SQL-2003-R */
426
697
%token  PREV_SYM
427
698
%token  PRIMARY_SYM                   /* SQL-2003-R */
428
699
%token  PROCESS
429
700
%token  PROCESSLIST_SYM
 
701
%token  PURGE
430
702
%token  QUARTER_SYM
431
703
%token  QUERY_SYM
 
704
%token  QUICK
432
705
%token  RANGE_SYM                     /* SQL-2003-R */
433
706
%token  READS_SYM                     /* SQL-2003-R */
 
707
%token  READ_ONLY_SYM
434
708
%token  READ_SYM                      /* SQL-2003-N */
435
709
%token  READ_WRITE_SYM
436
710
%token  REAL                          /* SQL-2003-R */
 
711
%token  REBUILD_SYM
 
712
%token  RECOVER_SYM
 
713
%token  REDOFILE_SYM
 
714
%token  REDO_BUFFER_SIZE_SYM
437
715
%token  REDUNDANT_SYM
438
 
%token  REGEXP_SYM
439
716
%token  REFERENCES                    /* SQL-2003-R */
440
717
%token  RELEASE_SYM                   /* SQL-2003-R */
 
718
%token  RELOAD
 
719
%token  REMOVE_SYM
441
720
%token  RENAME
 
721
%token  REORGANIZE_SYM
442
722
%token  REPEATABLE_SYM                /* SQL-2003-N */
443
723
%token  REPEAT_SYM                    /* MYSQL-FUNC */
444
724
%token  REPLACE                       /* MYSQL-FUNC */
 
725
%token  REPLICATION
 
726
%token  REQUIRE_SYM
 
727
%token  RESET_SYM
 
728
%token  RESOURCES
445
729
%token  RESTRICT
 
730
%token  RESUME_SYM
446
731
%token  RETURNS_SYM                   /* SQL-2003-R */
447
732
%token  RETURN_SYM                    /* SQL-2003-R */
 
733
%token  REVERSE_SYM
448
734
%token  REVOKE                        /* SQL-2003-R */
449
735
%token  RIGHT                         /* SQL-2003-R */
450
736
%token  ROLLBACK_SYM                  /* SQL-2003-R */
464
750
%token  SERIAL_SYM
465
751
%token  SESSION_SYM                   /* SQL-2003-N */
466
752
%token  SERVER_SYM
467
 
%token  SET_SYM                           /* SQL-2003-R */
 
753
%token  SERVER_OPTIONS
 
754
%token  SET                           /* SQL-2003-R */
468
755
%token  SET_VAR
469
756
%token  SHARE_SYM
470
757
%token  SHOW
471
 
%token  SIGNED_SYM
 
758
%token  SHUTDOWN
472
759
%token  SIMPLE_SYM                    /* SQL-2003-N */
473
760
%token  SNAPSHOT_SYM
 
761
%token  SOCKET_SYM
 
762
%token  SONAME_SYM
 
763
%token  SOURCE_SYM
474
764
%token  SPECIFIC_SYM                  /* SQL-2003-R */
475
765
%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
476
766
%token  SQLSTATE_SYM                  /* SQL-2003-R */
481
771
%token  SQL_SMALL_RESULT
482
772
%token  SQL_SYM                       /* SQL-2003-R */
483
773
%token  STARTING
 
774
%token  STARTS_SYM
484
775
%token  START_SYM                     /* SQL-2003-R */
485
776
%token  STATUS_SYM
486
777
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
487
778
%token  STD_SYM
488
779
%token  STOP_SYM
 
780
%token  STORAGE_SYM
489
781
%token  STORED_SYM
490
782
%token  STRAIGHT_JOIN
491
783
%token  STRING_SYM
493
785
%token  SUBJECT_SYM
494
786
%token  SUBSTRING                     /* SQL-2003-N */
495
787
%token  SUM_SYM                       /* SQL-2003-N */
 
788
%token  SUPER_SYM
496
789
%token  SUSPEND_SYM
 
790
%token  SWAPS_SYM
 
791
%token  SWITCHES_SYM
497
792
%token  SYSDATE
498
793
%token  TABLES
499
794
%token  TABLESPACE
500
795
%token  TABLE_REF_PRIORITY
501
796
%token  TABLE_SYM                     /* SQL-2003-R */
 
797
%token  TABLE_CHECKSUM_SYM
502
798
%token  TEMPORARY_SYM                 /* SQL-2003-N */
 
799
%token  TEMPTABLE_SYM
503
800
%token  TERMINATED
504
801
%token  TEXT_STRING
505
802
%token  TEXT_SYM
 
803
%token  THAN_SYM
506
804
%token  THEN_SYM                      /* SQL-2003-R */
507
 
%token  TIME_SYM                 /* SQL-2003-R */
508
805
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
509
806
%token  TIMESTAMP_ADD
510
807
%token  TIMESTAMP_DIFF
514
811
%token  TRIM                          /* SQL-2003-N */
515
812
%token  TRUE_SYM                      /* SQL-2003-R */
516
813
%token  TRUNCATE_SYM
 
814
%token  TYPES_SYM
517
815
%token  TYPE_SYM                      /* SQL-2003-N */
518
816
%token  ULONGLONG_NUM
519
817
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
 
818
%token  UNDEFINED_SYM
520
819
%token  UNDOFILE_SYM
521
820
%token  UNDO_SYM                      /* FUTURE-USE */
522
821
%token  UNION_SYM                     /* SQL-2003-R */
523
822
%token  UNIQUE_SYM
524
823
%token  UNKNOWN_SYM                   /* SQL-2003-R */
525
824
%token  UNLOCK_SYM
526
 
%token  UNSIGNED_SYM
 
825
%token  UNTIL_SYM
527
826
%token  UPDATE_SYM                    /* SQL-2003-R */
528
827
%token  USAGE                         /* SQL-2003-N */
529
828
%token  USER                          /* SQL-2003-R */
 
829
%token  USE_FRM
530
830
%token  USE_SYM
531
831
%token  USING                         /* SQL-2003-R */
532
832
%token  UTC_DATE_SYM
533
833
%token  UTC_TIMESTAMP_SYM
534
 
%token  UUID_SYM
535
834
%token  VALUES                        /* SQL-2003-R */
536
835
%token  VALUE_SYM                     /* SQL-2003-R */
537
836
%token  VARBINARY
540
839
%token  VARIANCE_SYM
541
840
%token  VARYING                       /* SQL-2003-R */
542
841
%token  VAR_SAMP_SYM
 
842
%token  VIRTUAL_SYM
543
843
%token  WAIT_SYM
544
844
%token  WARNINGS
545
845
%token  WEEK_SYM
 
846
%token  WEIGHT_STRING_SYM
546
847
%token  WHEN_SYM                      /* SQL-2003-R */
547
848
%token  WHERE                         /* SQL-2003-R */
548
849
%token  WITH                          /* SQL-2003-R */
552
853
%token  XOR
553
854
%token  YEAR_MONTH_SYM
554
855
%token  YEAR_SYM                      /* SQL-2003-R */
555
 
%token  ZEROFILL_SYM
556
856
 
557
857
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
558
858
/* A dummy token to force the priority of table_ref production in a join. */
562
862
%left   XOR
563
863
%left   AND_SYM
564
864
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
565
 
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP_SYM IN_SYM
 
865
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
566
866
%left   '-' '+'
567
867
%left   '*' '/' '%' DIV_SYM MOD_SYM
568
868
%left   NEG
572
872
 
573
873
%type <lex_str>
574
874
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
575
 
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
576
 
        ident
577
 
        ident_or_text
578
 
        internal_variable_ident
579
 
        user_variable_ident
580
 
        row_format_or_text
 
875
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
581
876
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
582
 
        schema_name
583
 
        catalog_name
584
 
        opt_component
585
 
        engine_option_value
586
 
        savepoint_ident
587
 
        BIN_NUM TEXT_STRING_filesystem
 
877
        opt_component key_cache_name
 
878
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
588
879
        opt_constraint constraint opt_ident
589
880
 
590
 
%type <execute_string>
591
 
        execute_var_or_string
592
 
 
593
881
%type <lex_str_ptr>
594
882
        opt_table_alias
595
883
 
602
890
%type <string>
603
891
        text_string opt_gconcat_separator
604
892
 
605
 
%type <field_val>
606
 
      field_definition
607
 
      int_type
608
 
      real_type
609
 
 
610
 
%type <boolean>
611
 
        opt_wait
612
 
        opt_concurrent
613
 
        opt_status
614
 
        opt_zerofill
615
 
        opt_if_not_exists
616
 
        if_exists 
617
 
        opt_temporary 
618
 
        opt_field_number_signed
619
 
 
620
893
%type <num>
621
 
        order_dir
622
 
        field_def
623
 
        opt_table_options
624
 
        all_or_any opt_distinct
 
894
        type int_type real_type order_dir field_def
 
895
        if_exists opt_table_options table_options
 
896
        table_option opt_if_not_exists
 
897
        opt_temporary all_or_any opt_distinct
625
898
        union_option
626
899
        start_transaction_opts opt_chain opt_release
627
900
        union_opt select_derived_init option_type2
628
 
        kill_option
629
901
 
630
902
%type <m_fk_option>
631
903
        delete_option
632
904
 
633
905
%type <ulong_num>
634
 
        ulong_num
 
906
        ulong_num real_ulong_num
 
907
        ws_nweights
 
908
        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
 
909
        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
 
910
        ws_level_range ws_level_list_or_range  
635
911
 
636
912
%type <ulonglong_number>
637
913
        ulonglong_num
638
914
 
 
915
%type <choice> choice
 
916
 
639
917
%type <lock_type>
640
918
        load_data_lock
641
919
 
647
925
        table_wild simple_expr udf_expr
648
926
        expr_or_default set_expr_or_default
649
927
        signed_literal now_or_signed_literal opt_escape
650
 
        simple_ident_q
 
928
        simple_ident_nospvar simple_ident_q
651
929
        field_or_var limit_option
652
930
        function_call_keyword
653
931
        function_call_nonkeyword
687
965
 
688
966
%type <interval_time_st> interval_time_stamp
689
967
 
 
968
%type <db_type> storage_engines known_storage_engines
 
969
 
 
970
%type <row_type> row_types
 
971
 
 
972
%type <column_format_type> column_format_types
 
973
 
690
974
%type <tx_isolation> isolation_types
691
975
 
692
976
%type <cast_type> cast_type
693
977
 
694
 
%type <symbol>
695
 
        keyword
696
 
        keyword_sp
697
 
        keyword_exception_for_variable
698
 
        row_format
 
978
%type <symbol> keyword keyword_sp
699
979
 
700
980
%type <charset>
701
981
        collation_name
704
984
%type <variable> internal_variable_name
705
985
 
706
986
%type <select_lex> subselect
707
 
        get_select_lex query_specification
 
987
        get_select_lex query_specification 
708
988
        query_expression_body
709
989
 
710
990
%type <boolfunc2creator> comp_op
714
994
%type <NONE>
715
995
        query verb_clause create select drop insert replace insert2
716
996
        insert_values update delete truncate rename
717
 
        show describe load alter flush
 
997
        show describe load alter optimize keycache flush
718
998
        begin commit rollback savepoint release
719
 
        analyze check start
 
999
        analyze check start checksum
720
1000
        field_list field_list_item field_spec kill column_def key_def
 
1001
        keycache_list assign_to_keycache
721
1002
        select_item_list select_item values_list no_braces
722
1003
        opt_limit_clause delete_limit_clause fields opt_values values
723
1004
        opt_precision opt_ignore opt_column
724
1005
        set unlock string_list
 
1006
        opt_binary
725
1007
        ref_list opt_match_clause opt_on_update_delete use
726
1008
        opt_delete_options opt_delete_option varchar
727
 
        opt_outer table_list table_name
 
1009
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
728
1010
        opt_option opt_place
729
1011
        opt_attribute opt_attribute_list attribute
730
1012
        flush_options flush_option
731
1013
        equal optional_braces
732
 
        normal_join
733
 
        table_to_table_list table_to_table opt_table_list
734
 
        single_multi
 
1014
        opt_mi_check_type opt_to mi_check_types normal_join
 
1015
        table_to_table_list table_to_table opt_table_list opt_as
 
1016
        single_multi table_wild_list table_wild_one opt_wild
735
1017
        union_clause union_list
736
1018
        precision subselect_start
737
1019
        subselect_end select_var_list select_var_list_init opt_len
738
1020
        opt_extended_describe
739
1021
        statement
740
 
        execute
741
1022
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
742
1023
        init_key_options key_options key_opts key_opt key_using_alg
743
1024
END_OF_INPUT
784
1065
            }
785
1066
            else
786
1067
            {
787
 
              session->lex->statement= new statement::EmptyQuery(YYSession);
 
1068
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
788
1069
            }
789
1070
          }
790
1071
        | verb_clause END_OF_INPUT {}
800
1081
          alter
801
1082
        | analyze
802
1083
        | check
 
1084
        | checksum
803
1085
        | commit
804
1086
        | create
805
1087
        | delete
806
1088
        | describe
807
1089
        | drop
808
 
        | execute
809
1090
        | flush
810
1091
        | insert
811
1092
        | kill
812
1093
        | load
 
1094
        | optimize
 
1095
        | keycache
813
1096
        | release
814
1097
        | rename
815
1098
        | replace
828
1111
/* create a table */
829
1112
 
830
1113
create:
831
 
          CREATE CATALOG_SYM catalog_name
832
 
          {
833
 
            Lex->statement= new statement::catalog::Create(YYSession, $3);
834
 
          }
835
 
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
836
 
          {
837
 
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
838
 
 
839
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
840
 
                                                     TL_OPTION_UPDATING,
841
 
                                                     TL_WRITE))
842
 
              DRIZZLE_YYABORT;
843
 
            Lex->col_list.empty();
844
 
          }
845
 
          create_table_definition
846
 
          {
847
 
            Lex->current_select= &Lex->select_lex;
848
 
          }
849
 
        | CREATE build_method
850
 
          {
851
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
852
 
          }
853
 
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
 
          {
855
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
856
 
                                                            NULL,
857
 
                                                            TL_OPTION_UPDATING))
858
 
              DRIZZLE_YYABORT;
859
 
 
860
 
            parser::buildKey(Lex, $4, $6);
861
 
          }
862
 
        | CREATE DATABASE opt_if_not_exists schema_name
863
 
          {
864
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
1114
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1115
          {
 
1116
            Session *session= YYSession;
 
1117
            LEX *lex= session->lex;
 
1118
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1119
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1120
                                                   TL_OPTION_UPDATING,
 
1121
                                                   TL_WRITE))
 
1122
              DRIZZLE_YYABORT;
 
1123
            lex->alter_info.reset();
 
1124
            lex->col_list.empty();
 
1125
            lex->change=NULL;
 
1126
            memset(&lex->create_info, 0, sizeof(lex->create_info));
 
1127
            lex->create_info.options=$2 | $4;
 
1128
            lex->create_info.db_type= ha_default_storage_engine(session);
 
1129
            lex->create_info.default_table_charset= NULL;
 
1130
            lex->name.str= 0;
 
1131
 
 
1132
            drizzled::message::Table *proto=
 
1133
              lex->create_table_proto= new drizzled::message::Table();
 
1134
            
 
1135
            proto->set_name($5->table.str);
 
1136
            if($2 & HA_LEX_CREATE_TMP_TABLE)
 
1137
              proto->set_type(drizzled::message::Table::TEMPORARY);
 
1138
            else
 
1139
              proto->set_type(drizzled::message::Table::STANDARD);
 
1140
 
 
1141
            {
 
1142
              drizzled::message::Table::StorageEngine *protoengine;
 
1143
              protoengine= proto->mutable_engine();
 
1144
              StorageEngine *engine= ha_default_storage_engine(session);
 
1145
 
 
1146
              protoengine->set_name(engine->getName());
 
1147
            }
 
1148
          }
 
1149
          create2
 
1150
          {
 
1151
            LEX *lex= YYSession->lex;
 
1152
            lex->current_select= &lex->select_lex; 
 
1153
            assert(lex->create_info.db_type);
 
1154
          }
 
1155
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
 
1156
          ON table_ident
 
1157
          {
 
1158
            LEX *lex=Lex;
 
1159
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1160
            if (!lex->current_select->add_table_to_list(lex->session, $8,
 
1161
                                                        NULL,
 
1162
                                                        TL_OPTION_UPDATING))
 
1163
              DRIZZLE_YYABORT;
 
1164
            lex->alter_info.reset();
 
1165
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1166
            lex->alter_info.build_method= $2;
 
1167
            lex->col_list.empty();
 
1168
            lex->change=NULL;
 
1169
          }
 
1170
          '(' key_list ')' key_options
 
1171
          {
 
1172
            LEX *lex=Lex;
 
1173
            Key *key;
 
1174
            key= new Key($3, $5, &lex->key_create_info, 0,
 
1175
                         lex->col_list);
 
1176
            lex->alter_info.key_list.push_back(key);
 
1177
            lex->col_list.empty();
 
1178
          }
 
1179
        | CREATE DATABASE opt_if_not_exists ident
 
1180
          {
 
1181
            Lex->create_info.default_table_charset= NULL;
 
1182
            Lex->create_info.used_fields= 0;
865
1183
          }
866
1184
          opt_create_database_options
867
1185
          {
868
 
            Lex->name= $4;
869
 
          }
870
 
        ;
871
 
 
872
 
create_table_definition:
873
 
          '(' field_list ')' opt_create_table_options  create_select_as
874
 
          { }
875
 
        | '(' create_select ')'
876
 
           {
877
 
             Lex->current_select->set_braces(1);
878
 
           }
 
1186
            LEX *lex=Lex;
 
1187
            lex->sql_command=SQLCOM_CREATE_DB;
 
1188
            lex->name= $4;
 
1189
            lex->create_info.options=$3;
 
1190
          }
 
1191
        ;
 
1192
 
 
1193
create2:
 
1194
          '(' create2a {}
 
1195
        | opt_create_table_options
 
1196
          create3 {}
 
1197
        | LIKE table_ident
 
1198
          {
 
1199
            Session *session= YYSession;
 
1200
            LEX *lex= session->lex;
 
1201
 
 
1202
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1203
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1204
              DRIZZLE_YYABORT;
 
1205
          }
 
1206
        | '(' LIKE table_ident ')'
 
1207
          {
 
1208
            Session *session= YYSession;
 
1209
            LEX *lex= session->lex;
 
1210
 
 
1211
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1212
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1213
              DRIZZLE_YYABORT;
 
1214
          }
 
1215
        ;
 
1216
 
 
1217
create2a:
 
1218
          field_list ')' opt_create_table_options
 
1219
          create3 {}
 
1220
        |  create_select ')'
 
1221
           { Lex->current_select->set_braces(1);}
879
1222
           union_opt {}
880
 
        |  '(' create_like ')' opt_create_table_options
881
 
          { }
882
 
        | create_like opt_create_table_options
883
 
          { }
884
 
        | opt_create_table_options create_select_as 
885
 
          { }
886
1223
        ;
887
1224
 
888
 
create_select_as:
 
1225
create3:
889
1226
          /* empty */ {}
890
 
        | opt_duplicate_as create_select
891
 
          {
892
 
            Lex->current_select->set_braces(0);
893
 
          }
 
1227
        | opt_duplicate opt_as create_select
 
1228
          { Lex->current_select->set_braces(0);}
894
1229
          union_clause {}
895
 
        | opt_duplicate_as '(' create_select ')'
896
 
          {
897
 
            Lex->current_select->set_braces(1);
898
 
          }
 
1230
        | opt_duplicate opt_as '(' create_select ')'
 
1231
          { Lex->current_select->set_braces(1);}
899
1232
          union_opt {}
900
1233
        ;
901
1234
 
902
 
create_like:
903
 
          LIKE table_ident
904
 
          {
905
 
            ((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
906
 
 
907
 
            if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
908
 
              DRIZZLE_YYABORT;
909
 
          }
910
 
        ;
911
 
 
912
1235
create_select:
913
 
          stored_select
914
 
          {
915
 
          }
916
 
        ;
917
 
 
918
 
/*
919
 
  This rule is used for both CREATE TABLE .. SELECT,  AND INSERT ... SELECT
920
 
*/
921
 
stored_select:
922
1236
          SELECT_SYM
923
1237
          {
924
 
            Lex->lock_option= TL_READ;
925
 
            if (Lex->sql_command == SQLCOM_INSERT)
926
 
            {
927
 
              delete Lex->statement;
928
 
              Lex->statement= new statement::InsertSelect(YYSession);
929
 
            }
930
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
931
 
            {
932
 
              delete Lex->statement;
933
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
934
 
            }
 
1238
            LEX *lex=Lex;
 
1239
            lex->lock_option= TL_READ;
 
1240
            if (lex->sql_command == SQLCOM_INSERT)
 
1241
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1242
            else if (lex->sql_command == SQLCOM_REPLACE)
 
1243
              lex->sql_command= SQLCOM_REPLACE_SELECT;
935
1244
            /*
936
1245
              The following work only with the local list, the global list
937
1246
              is created correctly in this case
938
1247
            */
939
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
 
            init_select(Lex);
941
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1248
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1249
            mysql_init_select(lex);
 
1250
            lex->current_select->parsing_place= SELECT_LIST;
942
1251
          }
943
1252
          select_options select_item_list
944
1253
          {
954
1263
          }
955
1264
        ;
956
1265
 
 
1266
opt_as:
 
1267
          /* empty */ {}
 
1268
        | AS {}
 
1269
        ;
 
1270
 
957
1271
opt_create_database_options:
958
1272
          /* empty */ {}
959
 
        | default_collation_schema {}
960
 
        | opt_database_custom_options {}
961
 
        ;
962
 
 
963
 
opt_database_custom_options:
964
 
        custom_database_option
965
 
        | custom_database_option ',' opt_database_custom_options
966
 
        ;
967
 
 
968
 
custom_database_option:
969
 
          ident_or_text
970
 
          {
971
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
972
 
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
973
 
          }
974
 
        | ident_or_text equal ident_or_text
975
 
          {
976
 
            parser::buildSchemaOption(Lex, $1.str, $3);
977
 
          }
978
 
        | ident_or_text equal ulonglong_num
979
 
          {
980
 
            parser::buildSchemaOption(Lex, $1.str, $3);
981
 
          }
 
1273
        | create_database_options {}
 
1274
        ;
 
1275
 
 
1276
create_database_options:
 
1277
          create_database_option {}
 
1278
        | create_database_options create_database_option {}
 
1279
        ;
 
1280
 
 
1281
create_database_option:
 
1282
          default_collation {}
982
1283
        ;
983
1284
 
984
1285
opt_table_options:
985
 
          /* empty */ { $$= false; }
986
 
        | TEMPORARY_SYM { $$= true; }
 
1286
          /* empty */ { $$= 0; }
 
1287
        | table_options  { $$= $1;}
 
1288
        ;
 
1289
 
 
1290
table_options:
 
1291
          table_option { $$=$1; }
 
1292
        | table_option table_options { $$= $1 | $2; }
 
1293
        ;
 
1294
 
 
1295
table_option:
 
1296
          TEMPORARY_SYM { $$=HA_LEX_CREATE_TMP_TABLE; }
987
1297
        ;
988
1298
 
989
1299
opt_if_not_exists:
990
 
          /* empty */ { $$= false; }
991
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1300
          /* empty */ { $$= 0; }
 
1301
        | IF not EXISTS { $$=HA_LEX_CREATE_IF_NOT_EXISTS; }
992
1302
        ;
993
1303
 
994
1304
opt_create_table_options:
1005
1315
          create_table_option
1006
1316
        | create_table_option     create_table_options
1007
1317
        | create_table_option ',' create_table_options
 
1318
        ;
1008
1319
 
1009
1320
create_table_option:
1010
 
          custom_engine_option;
1011
 
 
1012
 
custom_engine_option:
1013
 
        ENGINE_SYM equal ident_or_text
1014
 
          {
1015
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1321
          ENGINE_SYM opt_equal storage_engines
 
1322
          {
 
1323
            Lex->create_info.db_type= $3;
 
1324
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1325
 
 
1326
            {
 
1327
              drizzled::message::Table::StorageEngine *protoengine;
 
1328
              protoengine= Lex->create_table_proto->mutable_engine();
 
1329
 
 
1330
              protoengine->set_name($3->getName());
 
1331
            }
 
1332
          }
 
1333
        | MAX_ROWS opt_equal ulonglong_num
 
1334
          {
 
1335
            Lex->create_info.max_rows= $3;
 
1336
            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
 
1337
          }
 
1338
        | MIN_ROWS opt_equal ulonglong_num
 
1339
          {
 
1340
            Lex->create_info.min_rows= $3;
 
1341
            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
 
1342
          }
 
1343
        | AVG_ROW_LENGTH opt_equal ulong_num
 
1344
          {
 
1345
            Lex->create_info.avg_row_length=$3;
 
1346
            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
 
1347
          }
 
1348
        | BLOCK_SIZE_SYM opt_equal ulong_num    
 
1349
          { 
 
1350
            Lex->create_info.block_size= $3; 
 
1351
            Lex->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
1016
1352
          }
1017
1353
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1018
1354
          {
1019
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1355
            Lex->create_info.comment=$3;
 
1356
            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
1020
1357
          }
1021
1358
        | AUTO_INC opt_equal ulonglong_num
1022
1359
          {
1023
 
            Lex->table()->mutable_options()->set_auto_increment_value($3);
1024
 
          }
1025
 
        |  ROW_FORMAT_SYM equal row_format_or_text
1026
 
          {
1027
 
            parser::buildEngineOption(Lex, "ROW_FORMAT", $3);
1028
 
          }
1029
 
        |  FILE_SYM equal TEXT_STRING_sys
1030
 
          {
1031
 
            parser::buildEngineOption(Lex, "FILE", $3);
1032
 
          }
1033
 
        |  ident_or_text equal engine_option_value
1034
 
          {
1035
 
            parser::buildEngineOption(Lex, $1.str, $3);
1036
 
          }
1037
 
        | ident_or_text equal ulonglong_num
1038
 
          {
1039
 
            parser::buildEngineOption(Lex, $1.str, $3);
 
1360
            Lex->create_info.auto_increment_value=$3;
 
1361
            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1362
          }
 
1363
        | PACK_KEYS_SYM opt_equal ulong_num
 
1364
          {
 
1365
            switch($3) {
 
1366
            case 0:
 
1367
                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
 
1368
                break;
 
1369
            case 1:
 
1370
                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
 
1371
                break;
 
1372
            default:
 
1373
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
1374
                DRIZZLE_YYABORT;
 
1375
            }
 
1376
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
 
1377
          }
 
1378
        | PACK_KEYS_SYM opt_equal DEFAULT
 
1379
          {
 
1380
            Lex->create_info.table_options&=
 
1381
              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
 
1382
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
 
1383
          }
 
1384
        | CHECKSUM_SYM opt_equal ulong_num
 
1385
          {
 
1386
            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
 
1387
            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
 
1388
          }
 
1389
        | TABLE_CHECKSUM_SYM opt_equal ulong_num
 
1390
          {
 
1391
             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
 
1392
             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
 
1393
          }
 
1394
        | PAGE_CHECKSUM_SYM opt_equal choice
 
1395
          {
 
1396
            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
 
1397
            Lex->create_info.page_checksum= $3;
 
1398
          }
 
1399
        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
 
1400
          {
 
1401
            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
 
1402
            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
 
1403
          }
 
1404
        | ROW_FORMAT_SYM opt_equal row_types
 
1405
          {
 
1406
            Lex->create_info.row_type= $3;
 
1407
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1408
            Lex->alter_info.flags.set(ALTER_ROW_FORMAT);
1040
1409
          }
1041
1410
        | default_collation
 
1411
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
 
1412
          {
 
1413
            Lex->create_info.data_file_name= $4.str;
 
1414
            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
 
1415
          }
 
1416
        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
 
1417
          {
 
1418
            Lex->create_info.index_file_name= $4.str;
 
1419
            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
 
1420
          }
 
1421
        | CONNECTION_SYM opt_equal TEXT_STRING_sys
 
1422
          {
 
1423
            Lex->create_info.connect_string.str= $3.str;
 
1424
            Lex->create_info.connect_string.length= $3.length;
 
1425
            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
 
1426
          }
 
1427
        | KEY_BLOCK_SIZE opt_equal ulong_num
 
1428
          {
 
1429
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1430
            Lex->create_info.key_block_size= $3;
 
1431
          }
1042
1432
        ;
1043
1433
 
1044
1434
default_collation:
1045
1435
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1046
1436
          {
1047
 
            if (not parser::buildCollation(Lex, $4))
1048
 
            {
1049
 
              DRIZZLE_YYABORT;
1050
 
            }
1051
 
          }
1052
 
        ;
1053
 
 
1054
 
default_collation_schema:
1055
 
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1056
 
          {
1057
 
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
1058
 
          }
1059
 
        ;
1060
 
 
1061
 
row_format:
1062
 
          COMPACT_SYM  {}
1063
 
        | COMPRESSED_SYM  {}
1064
 
        | DEFAULT  {}
1065
 
        | DYNAMIC_SYM  {}
1066
 
        | FIXED_SYM  {}
1067
 
        | REDUNDANT_SYM  {}
1068
 
        ;
1069
 
 
1070
 
row_format_or_text:
1071
 
          row_format
1072
 
          {
1073
 
            $$.str= YYSession->strmake($1.str, $1.length);
1074
 
            $$.length= $1.length;
1075
 
          }
 
1437
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1438
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1439
                 cinfo->default_table_charset && $4 &&
 
1440
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1441
              {
 
1442
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1443
                         $4->name, cinfo->default_table_charset->csname);
 
1444
                DRIZZLE_YYABORT;
 
1445
              }
 
1446
              Lex->create_info.default_table_charset= $4;
 
1447
              Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1448
          }
 
1449
        ;
 
1450
 
 
1451
storage_engines:
 
1452
          ident_or_text
 
1453
          {
 
1454
            const std::string engine_name($1.str);
 
1455
            StorageEngine *engine= ha_resolve_by_name(YYSession, engine_name);
 
1456
 
 
1457
            if (engine)
 
1458
              $$= engine;
 
1459
            else
 
1460
            {
 
1461
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1462
              DRIZZLE_YYABORT;
 
1463
            }
 
1464
          }
 
1465
        ;
 
1466
 
 
1467
known_storage_engines:
 
1468
          ident_or_text
 
1469
          {
 
1470
            const std::string engine_name($1.str);
 
1471
            StorageEngine *engine;
 
1472
            if ((engine= ha_resolve_by_name(YYSession, engine_name)))
 
1473
              $$= engine;
 
1474
            else
 
1475
            {
 
1476
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1477
              DRIZZLE_YYABORT;
 
1478
            }
 
1479
          }
 
1480
        ;
 
1481
 
 
1482
column_format_types:
 
1483
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1484
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1485
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1486
 
 
1487
row_types:
 
1488
          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
 
1489
        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
 
1490
        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
 
1491
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
 
1492
        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
 
1493
        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
 
1494
        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
1076
1495
        ;
1077
1496
 
1078
1497
opt_select_from:
1094
1513
          field_spec opt_check_constraint
1095
1514
        | field_spec references
1096
1515
          {
1097
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1516
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1098
1517
          }
1099
1518
        ;
1100
1519
 
1101
1520
key_def:
1102
1521
          key_type opt_ident key_alg '(' key_list ')' key_options
1103
1522
          {
1104
 
            parser::buildKey(Lex, $1, $2);
 
1523
            LEX *lex=Lex;
 
1524
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
 
1525
                              lex->col_list);
 
1526
            lex->alter_info.key_list.push_back(key);
 
1527
            lex->col_list.empty(); /* Alloced by sql_alloc */
1105
1528
          }
1106
1529
        | opt_constraint constraint_key_type opt_ident key_alg
1107
1530
          '(' key_list ')' key_options
1108
1531
          {
1109
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1532
            LEX *lex=Lex;
 
1533
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
 
1534
                              lex->col_list);
 
1535
            lex->alter_info.key_list.push_back(key);
 
1536
            lex->col_list.empty(); /* Alloced by sql_alloc */
1110
1537
          }
1111
1538
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1112
1539
          {
1113
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1540
            LEX *lex=Lex;
 
1541
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
 
1542
                                      $8,
 
1543
                                      lex->ref_list,
 
1544
                                      lex->fk_delete_opt,
 
1545
                                      lex->fk_update_opt,
 
1546
                                      lex->fk_match_option);
 
1547
            lex->alter_info.key_list.push_back(key);
 
1548
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1549
                         &default_key_create_info, 1,
 
1550
                         lex->col_list);
 
1551
            lex->alter_info.key_list.push_back(key);
 
1552
            lex->col_list.empty(); /* Alloced by sql_alloc */
 
1553
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1554
            lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
1114
1555
          }
1115
1556
        | constraint opt_check_constraint
1116
1557
          {
1117
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1558
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1118
1559
          }
1119
1560
        | opt_constraint check_constraint
1120
1561
          {
1121
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1562
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1122
1563
          }
1123
1564
        ;
1124
1565
 
1143
1584
field_spec:
1144
1585
          field_ident
1145
1586
          {
1146
 
            parser::buildCreateFieldIdent(Lex);
 
1587
            LEX *lex=Lex;
 
1588
            lex->length=lex->dec=0;
 
1589
            lex->type=0;
 
1590
            lex->default_value= lex->on_update_value= 0;
 
1591
            lex->comment=null_lex_str;
 
1592
            lex->charset=NULL;
 
1593
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1147
1594
          }
1148
1595
          field_def
1149
1596
          {
1150
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1151
 
 
1152
 
            if (Lex->field())
1153
 
            {
1154
 
              Lex->field()->set_name($1.str);
1155
 
            }
1156
 
 
1157
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
 
                                  Lex->length, Lex->dec, Lex->type,
1159
 
                                  statement->column_format,
1160
 
                                  statement->default_value, statement->on_update_value,
1161
 
                                  &statement->comment,
1162
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1597
            LEX *lex=Lex;
 
1598
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1599
                                  lex->length,lex->dec,lex->type,
 
1600
                                  lex->column_format,
 
1601
                                  lex->default_value, lex->on_update_value, 
 
1602
                                  &lex->comment,
 
1603
                                  lex->change,&lex->interval_list,lex->charset))
1163
1604
              DRIZZLE_YYABORT;
1164
 
 
1165
 
            Lex->setField(NULL);
1166
1605
          }
1167
1606
        ;
1168
 
 
1169
1607
field_def:
1170
 
          field_definition opt_attribute {}
 
1608
          type opt_attribute {}
1171
1609
        ;
1172
1610
 
1173
 
field_definition:
1174
 
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1175
 
          { 
1176
 
            $$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1177
 
          }
1178
 
        | real_type opt_precision
1179
 
          {
1180
 
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
1181
 
            $$= parser::buildDoubleColumn(Lex);
1182
 
          }
1183
 
        | char '(' NUM ')'
1184
 
          {
1185
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
1186
 
          }
1187
 
        | char
1188
 
          {
1189
 
            $$= parser::buildVarcharColumn(Lex, "1");
1190
 
          }
1191
 
        | varchar '(' NUM ')'
1192
 
          {
1193
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
 
1611
type:
 
1612
        int_type
 
1613
        { 
 
1614
          $$=$1; 
 
1615
          Lex->length=(char*) 0; /* use default length */
 
1616
        }
 
1617
        | real_type opt_precision { $$=$1; }
 
1618
        | char '(' NUM ')' opt_binary
 
1619
          {
 
1620
            Lex->length=$3.str;
 
1621
            $$=DRIZZLE_TYPE_VARCHAR;
 
1622
          }
 
1623
        | char opt_binary
 
1624
          {
 
1625
            Lex->length=(char*) "1";
 
1626
            $$=DRIZZLE_TYPE_VARCHAR;
 
1627
          }
 
1628
        | varchar '(' NUM ')' opt_binary
 
1629
          {
 
1630
            Lex->length=$3.str;
 
1631
            $$= DRIZZLE_TYPE_VARCHAR;
1194
1632
          }
1195
1633
        | VARBINARY '(' NUM ')'
1196
1634
          {
1197
 
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
 
1635
            Lex->length=$3.str;
 
1636
            Lex->charset=&my_charset_bin;
 
1637
            $$= DRIZZLE_TYPE_VARCHAR;
1198
1638
          }
1199
1639
        | DATE_SYM
1200
 
          {
1201
 
            $$=DRIZZLE_TYPE_DATE;
1202
 
 
1203
 
            if (Lex->field())
1204
 
              Lex->field()->set_type(message::Table::Field::DATE);
1205
 
          }
1206
 
        | TIME_SYM
1207
 
          {
1208
 
            $$=DRIZZLE_TYPE_TIME;
1209
 
 
1210
 
            if (Lex->field())
1211
 
              Lex->field()->set_type(message::Table::Field::TIME);
1212
 
          }
 
1640
          { $$=DRIZZLE_TYPE_DATE; }
1213
1641
        | TIMESTAMP_SYM
1214
 
          {
1215
 
            $$=parser::buildTimestampColumn(Lex, NULL);
1216
 
          }
1217
 
        | TIMESTAMP_SYM '(' NUM ')'
1218
 
          {
1219
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1220
 
          }
 
1642
          { $$=DRIZZLE_TYPE_TIMESTAMP; }
1221
1643
        | DATETIME_SYM
1222
 
          {
1223
 
            $$=DRIZZLE_TYPE_DATETIME;
1224
 
 
1225
 
            if (Lex->field())
1226
 
              Lex->field()->set_type(message::Table::Field::DATETIME);
1227
 
          }
 
1644
          { $$=DRIZZLE_TYPE_DATETIME; }
1228
1645
        | BLOB_SYM
1229
1646
          {
1230
 
            $$= parser::buildBlobColumn(Lex);
1231
 
          }
1232
 
        | TEXT_SYM
1233
 
          {
 
1647
            Lex->charset=&my_charset_bin;
1234
1648
            $$=DRIZZLE_TYPE_BLOB;
1235
1649
            Lex->length=(char*) 0; /* use default length */
1236
 
 
1237
 
          if (Lex->field())
1238
 
            Lex->field()->set_type(message::Table::Field::BLOB);
 
1650
          }
 
1651
        | TEXT_SYM opt_binary
 
1652
          { 
 
1653
            $$=DRIZZLE_TYPE_BLOB; 
 
1654
            Lex->length=(char*) 0; /* use default length */
1239
1655
          }
1240
1656
        | DECIMAL_SYM float_options
1241
 
          {
1242
 
            $$= parser::buildDecimalColumn(Lex);
1243
 
          }
 
1657
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1244
1658
        | NUMERIC_SYM float_options
1245
 
          {
1246
 
            $$= parser::buildDecimalColumn(Lex);
1247
 
          }
 
1659
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1248
1660
        | FIXED_SYM float_options
1249
 
          {
1250
 
            $$= parser::buildDecimalColumn(Lex);
1251
 
          }
 
1661
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1252
1662
        | ENUM_SYM
1253
 
          {
1254
 
            Lex->interval_list.empty();
1255
 
          }
1256
 
          '(' string_list ')'
1257
 
          {
1258
 
            $$=DRIZZLE_TYPE_ENUM;
1259
 
 
1260
 
            if (Lex->field())
1261
 
              Lex->field()->set_type(message::Table::Field::ENUM);
1262
 
          }
1263
 
        | UUID_SYM
1264
 
          {
1265
 
            $$= parser::buildUuidColumn(Lex);
1266
 
          }
1267
 
        | BOOLEAN_SYM
1268
 
          {
1269
 
            $$= parser::buildBooleanColumn(Lex);
1270
 
          }
 
1663
          {Lex->interval_list.empty();}
 
1664
          '(' string_list ')' opt_binary
 
1665
          { $$=DRIZZLE_TYPE_ENUM; }
1271
1666
        | SERIAL_SYM
1272
1667
          {
1273
 
            $$= parser::buildSerialColumn(Lex);
 
1668
            $$=DRIZZLE_TYPE_LONGLONG;
 
1669
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1274
1670
          }
1275
1671
        ;
1276
1672
 
1284
1680
        ;
1285
1681
 
1286
1682
int_type:
1287
 
          INT_SYM 
1288
 
          {
1289
 
            $$= DRIZZLE_TYPE_LONG;
1290
 
          }
1291
 
        | BOOL_SYM
1292
 
          {
1293
 
            $$= DRIZZLE_TYPE_LONG;
1294
 
          }
1295
 
        | BIGINT_SYM
1296
 
          {
1297
 
            $$= DRIZZLE_TYPE_LONGLONG;
1298
 
          }
 
1683
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1684
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1299
1685
        ;
1300
1686
 
1301
1687
real_type:
1304
1690
            $$= DRIZZLE_TYPE_DOUBLE;
1305
1691
          }
1306
1692
        | DOUBLE_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_DOUBLE;
1309
 
          }
 
1693
          { $$=DRIZZLE_TYPE_DOUBLE; }
1310
1694
        | DOUBLE_SYM PRECISION
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_DOUBLE;
1313
 
          }
 
1695
          { $$=DRIZZLE_TYPE_DOUBLE; }
1314
1696
        ;
1315
1697
 
1316
1698
float_options:
1325
1707
precision:
1326
1708
          '(' NUM ',' NUM ')'
1327
1709
          {
1328
 
            Lex->length= $2.str;
1329
 
            Lex->dec= $4.str;
 
1710
            LEX *lex=Lex;
 
1711
            lex->length=$2.str;
 
1712
            lex->dec=$4.str;
1330
1713
          }
1331
1714
        ;
1332
1715
 
1335
1718
        | '(' NUM ')' { Lex->length= $2.str; }
1336
1719
        ;
1337
1720
 
1338
 
opt_field_number_signed:
1339
 
          /* empty */ { $$= false; }
1340
 
        | SIGNED_SYM { $$= false; }
1341
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1342
 
        ;
1343
 
 
1344
 
ignored_field_number_length:
1345
 
          /* empty */ { }
1346
 
        | '(' NUM ')' { }
1347
 
        ;
1348
 
 
1349
 
opt_zerofill:
1350
 
          /* empty */ { $$= false; }
1351
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1352
 
        ;
1353
 
 
1354
1721
opt_precision:
1355
 
          /* empty */
1356
 
          { Lex->dec=Lex->length= (char*)0; }
1357
 
        | '(' NUM ')'
1358
 
          { Lex->length=Lex->dec= (char*)0; }
1359
 
        | precision
1360
 
          {}
 
1722
          /* empty */ {}
 
1723
        | precision {}
1361
1724
        ;
1362
1725
 
1363
1726
opt_attribute:
1371
1734
        ;
1372
1735
 
1373
1736
attribute:
1374
 
          NULL_SYM
1375
 
          {
1376
 
            Lex->type&= ~ NOT_NULL_FLAG;
1377
 
          }
1378
 
        | not NULL_SYM
1379
 
          {
1380
 
            Lex->type|= NOT_NULL_FLAG;
1381
 
 
1382
 
            if (Lex->field())
1383
 
            {
1384
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1385
 
            }
1386
 
          }
1387
 
        | DEFAULT now_or_signed_literal
1388
 
          {
1389
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1390
 
 
1391
 
            statement->default_value=$2;
1392
 
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1393
 
          }
1394
 
        | ON UPDATE_SYM NOW_SYM optional_braces
1395
 
          {
1396
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
1397
 
          }
1398
 
        | AUTO_INC
1399
 
          {
1400
 
            parser::buildAutoOnColumn(Lex);
1401
 
          }
 
1737
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
 
1738
        | COLUMN_FORMAT_SYM column_format_types
 
1739
          {
 
1740
            Lex->column_format= $2;
 
1741
            Lex->alter_info.flags.set(ALTER_COLUMN_FORMAT);
 
1742
          }
 
1743
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
 
1744
        | DEFAULT now_or_signed_literal 
 
1745
          { 
 
1746
            Lex->default_value=$2; 
 
1747
            Lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
1748
          }
 
1749
        | ON UPDATE_SYM NOW_SYM optional_braces 
 
1750
          { Lex->on_update_value= new Item_func_now_local(); }
 
1751
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1402
1752
        | SERIAL_SYM DEFAULT VALUE_SYM
1403
 
          {
1404
 
            (void)parser::buildSerialColumn(Lex);
 
1753
          { 
 
1754
            LEX *lex=Lex;
 
1755
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1756
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1405
1757
          }
1406
1758
        | opt_primary KEY_SYM
1407
1759
          {
1408
 
            parser::buildPrimaryOnColumn(Lex);
 
1760
            LEX *lex=Lex;
 
1761
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1762
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1409
1763
          }
1410
1764
        | UNIQUE_SYM
1411
1765
          {
1412
 
            parser::buildKeyOnColumn(Lex);
 
1766
            LEX *lex=Lex;
 
1767
            lex->type|= UNIQUE_FLAG; 
 
1768
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1413
1769
          }
1414
1770
        | UNIQUE_SYM KEY_SYM
1415
1771
          {
1416
 
            parser::buildKeyOnColumn(Lex);
1417
 
          }
1418
 
        | COMMENT_SYM TEXT_STRING_sys
1419
 
          {
1420
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1421
 
            statement->comment= $2;
1422
 
 
1423
 
            if (Lex->field())
1424
 
              Lex->field()->set_comment($2.str);
1425
 
          }
 
1772
            LEX *lex=Lex;
 
1773
            lex->type|= UNIQUE_KEY_FLAG; 
 
1774
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1775
          }
 
1776
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
1426
1777
        | COLLATE_SYM collation_name
1427
1778
          {
1428
1779
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
1466
1817
        | DEFAULT {}
1467
1818
        ;
1468
1819
 
 
1820
opt_binary:
 
1821
          /* empty */ { Lex->charset=NULL; }
 
1822
        | BYTE_SYM { Lex->charset=&my_charset_bin; }
 
1823
        | BINARY { Lex->type|= BINCMP_FLAG; }
 
1824
        ;
 
1825
 
 
1826
ws_nweights:
 
1827
        '(' real_ulong_num
 
1828
        {
 
1829
          if ($2 == 0)
 
1830
          {
 
1831
            my_parse_error(ER(ER_SYNTAX_ERROR));
 
1832
            DRIZZLE_YYABORT;
 
1833
          }
 
1834
        }
 
1835
        ')'
 
1836
        { $$= $2; }
 
1837
        ;
 
1838
 
 
1839
ws_level_flag_desc:
 
1840
        ASC { $$= 0; }
 
1841
        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
 
1842
        ;
 
1843
 
 
1844
ws_level_flag_reverse:
 
1845
        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
 
1846
 
 
1847
ws_level_flags:
 
1848
        /* empty */ { $$= 0; }
 
1849
        | ws_level_flag_desc { $$= $1; }
 
1850
        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
 
1851
        | ws_level_flag_reverse { $$= $1 ; }
 
1852
        ;
 
1853
 
 
1854
ws_level_number:
 
1855
        real_ulong_num
 
1856
        {
 
1857
          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
 
1858
          $$--;
 
1859
        }
 
1860
        ;
 
1861
 
 
1862
ws_level_list_item:
 
1863
        ws_level_number ws_level_flags
 
1864
        {
 
1865
          $$= (1 | $2) << $1;
 
1866
        }
 
1867
        ;
 
1868
 
 
1869
ws_level_list:
 
1870
        ws_level_list_item { $$= $1; }
 
1871
        | ws_level_list ',' ws_level_list_item { $$|= $3; }
 
1872
        ;
 
1873
 
 
1874
ws_level_range:
 
1875
        ws_level_number '-' ws_level_number
 
1876
        {
 
1877
          uint32_t start= $1;
 
1878
          uint32_t end= $3;
 
1879
          for ($$= 0; start <= end; start++)
 
1880
            $$|= (1 << start);
 
1881
        }
 
1882
        ;
 
1883
 
 
1884
ws_level_list_or_range:
 
1885
        ws_level_list { $$= $1; }
 
1886
        | ws_level_range { $$= $1; }
 
1887
        ;
 
1888
 
 
1889
opt_ws_levels:
 
1890
        /* empty*/ { $$= 0; }
 
1891
        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
 
1892
        ;
 
1893
 
1469
1894
opt_primary:
1470
1895
          /* empty */
1471
1896
        | PRIMARY_SYM
1493
1918
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1494
1919
        | ident
1495
1920
          {
1496
 
            Lex->ref_list.empty();
1497
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1921
            LEX *lex= Lex;
 
1922
            lex->ref_list.empty();
 
1923
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1498
1924
          }
1499
1925
        ;
1500
1926
 
1501
1927
opt_match_clause:
1502
1928
          /* empty */
1503
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
 
1929
          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
1504
1930
        | MATCH FULL
1505
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
 
1931
          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
1506
1932
        | MATCH PARTIAL
1507
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
 
1933
          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
1508
1934
        | MATCH SIMPLE_SYM
1509
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
 
1935
          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
1510
1936
        ;
1511
1937
 
1512
1938
opt_on_update_delete:
1513
1939
          /* empty */
1514
1940
          {
1515
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1516
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1941
            LEX *lex= Lex;
 
1942
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1943
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1517
1944
          }
1518
1945
        | ON UPDATE_SYM delete_option
1519
1946
          {
1520
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1521
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1947
            LEX *lex= Lex;
 
1948
            lex->fk_update_opt= $3;
 
1949
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1522
1950
          }
1523
1951
        | ON DELETE_SYM delete_option
1524
1952
          {
1525
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1526
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
1953
            LEX *lex= Lex;
 
1954
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1955
            lex->fk_delete_opt= $3;
1527
1956
          }
1528
1957
        | ON UPDATE_SYM delete_option
1529
1958
          ON DELETE_SYM delete_option
1530
1959
          {
1531
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1532
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
 
1960
            LEX *lex= Lex;
 
1961
            lex->fk_update_opt= $3;
 
1962
            lex->fk_delete_opt= $6;
1533
1963
          }
1534
1964
        | ON DELETE_SYM delete_option
1535
1965
          ON UPDATE_SYM delete_option
1536
1966
          {
1537
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
1538
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
1967
            LEX *lex= Lex;
 
1968
            lex->fk_update_opt= $6;
 
1969
            lex->fk_delete_opt= $3;
1539
1970
          }
1540
1971
        ;
1541
1972
 
1542
1973
delete_option:
1543
 
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
1544
 
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1545
 
        | SET_SYM NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1546
 
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1547
 
        | SET_SYM DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
 
1974
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
 
1975
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
 
1976
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
 
1977
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
 
1978
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
1548
1979
        ;
1549
1980
 
1550
1981
key_type:
1579
2010
 
1580
2011
init_key_options:
1581
2012
          {
1582
 
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
 
2013
            Lex->key_create_info= default_key_create_info;
1583
2014
          }
1584
2015
        ;
1585
2016
 
1586
2017
/*
1587
 
  For now, key_alg initializies Lex->key_create_info.
 
2018
  For now, key_alg initializies lex->key_create_info.
1588
2019
  In the future, when all key options are after key definition,
1589
2020
  we can remove key_alg and move init_key_options to key_options
1590
2021
*/
1605
2036
        ;
1606
2037
 
1607
2038
key_using_alg:
1608
 
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2039
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
 
2040
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
1609
2041
        ;
1610
2042
 
1611
2043
key_opt:
1612
2044
          key_using_alg
1613
2045
        | KEY_BLOCK_SIZE opt_equal ulong_num
1614
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
 
2046
          { Lex->key_create_info.block_size= $3; }
1615
2047
        | COMMENT_SYM TEXT_STRING_sys
1616
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
 
2048
          { Lex->key_create_info.comment= $2; }
1617
2049
        ;
1618
2050
 
1619
2051
btree_or_rtree:
1658
2090
*/
1659
2091
 
1660
2092
alter:
1661
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2093
          ALTER build_method opt_ignore TABLE_SYM table_ident
1662
2094
          {
1663
 
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5, $2);
1664
 
            Lex->statement= statement;
1665
 
            Lex->duplicates= DUP_ERROR;
1666
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
1667
 
            {
 
2095
            Session *session= YYSession;
 
2096
            LEX *lex= session->lex;
 
2097
            lex->name.str= 0;
 
2098
            lex->name.length= 0;
 
2099
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2100
            lex->duplicates= DUP_ERROR; 
 
2101
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2102
                                                   TL_OPTION_UPDATING))
1668
2103
              DRIZZLE_YYABORT;
1669
 
            }
 
2104
            lex->alter_info.reset();
 
2105
            lex->col_list.empty();
 
2106
            lex->select_lex.init_order();
 
2107
            lex->select_lex.db=
 
2108
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2109
            memset(&lex->create_info, 0, sizeof(lex->create_info));
 
2110
            lex->create_info.db_type= 0;
 
2111
            lex->create_info.default_table_charset= NULL;
 
2112
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
 
2113
            lex->alter_info.reset();
 
2114
            lex->alter_info.build_method= $2;
1670
2115
 
1671
 
            Lex->col_list.empty();
1672
 
            Lex->select_lex.init_order();
1673
 
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
 
2116
            lex->create_table_proto= new drizzled::message::Table();
1674
2117
          }
1675
2118
          alter_commands
1676
2119
          {}
1677
 
        | ALTER_SYM DATABASE schema_name
 
2120
        | ALTER DATABASE ident_or_empty
1678
2121
          {
1679
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2122
            Lex->create_info.default_table_charset= NULL;
 
2123
            Lex->create_info.used_fields= 0;
1680
2124
          }
1681
 
          default_collation_schema
 
2125
          create_database_options
1682
2126
          {
1683
 
            Lex->name= $3;
1684
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2127
            LEX *lex=Lex;
 
2128
            lex->sql_command=SQLCOM_ALTER_DB;
 
2129
            lex->name= $3;
 
2130
            if (lex->name.str == NULL &&
 
2131
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1685
2132
              DRIZZLE_YYABORT;
1686
2133
          }
1687
2134
        ;
1688
2135
 
 
2136
ident_or_empty:
 
2137
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2138
        | ident { $$= $1; }
 
2139
        ;
 
2140
 
1689
2141
alter_commands:
1690
2142
          /* empty */
1691
 
        | DISCARD TABLESPACE
1692
 
          {
1693
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1694
 
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE;
1695
 
          }
1696
 
        | IMPORT TABLESPACE
1697
 
          {
1698
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1699
 
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE;
1700
 
          }
 
2143
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
 
2144
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
1701
2145
        | alter_list
1702
2146
        ;
1703
2147
 
1722
2166
        ;
1723
2167
 
1724
2168
add_column:
1725
 
          ADD_SYM opt_column
 
2169
          ADD opt_column
1726
2170
          {
1727
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1728
 
 
1729
 
            statement->change=0;
1730
 
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2171
            LEX *lex=Lex;
 
2172
            lex->change=0;
 
2173
            lex->alter_info.flags.set(ALTER_ADD_COLUMN);
1731
2174
          }
1732
2175
        ;
1733
2176
 
1734
2177
alter_list_item:
1735
2178
          add_column column_def opt_place { }
1736
 
        | ADD_SYM key_def
 
2179
        | ADD key_def
1737
2180
          {
1738
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
 
 
1740
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
2181
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
1741
2182
          }
1742
2183
        | add_column '(' field_list ')'
1743
2184
          {
1744
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1745
 
 
1746
 
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1747
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
2185
            Lex->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2186
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
1748
2187
          }
1749
 
        | CHANGE_SYM opt_column field_ident
 
2188
        | CHANGE opt_column field_ident
1750
2189
          {
1751
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1752
 
            statement->change= $3.str;
1753
 
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2190
            LEX *lex=Lex;
 
2191
            lex->change= $3.str;
 
2192
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1754
2193
          }
1755
2194
          field_spec opt_place
1756
2195
        | MODIFY_SYM opt_column field_ident
1757
2196
          {
1758
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1759
 
            Lex->length= Lex->dec=0;
1760
 
            Lex->type= 0;
1761
 
            statement->default_value= statement->on_update_value= 0;
1762
 
            statement->comment= null_lex_str;
1763
 
            Lex->charset= NULL;
1764
 
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1765
 
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1766
 
 
1767
 
            Lex->setField(NULL);
 
2197
            LEX *lex=Lex;
 
2198
            lex->length=lex->dec=0; lex->type=0;
 
2199
            lex->default_value= lex->on_update_value= 0;
 
2200
            lex->comment=null_lex_str;
 
2201
            lex->charset= NULL;
 
2202
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2203
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1768
2204
          }
1769
2205
          field_def
1770
2206
          {
1771
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1772
 
 
1773
 
            if (add_field_to_list(Lex->session,&$3,
 
2207
            LEX *lex=Lex;
 
2208
            if (add_field_to_list(lex->session,&$3,
1774
2209
                                  (enum enum_field_types) $5,
1775
 
                                  Lex->length, Lex->dec, Lex->type,
1776
 
                                  statement->column_format,
1777
 
                                  statement->default_value,
1778
 
                                  statement->on_update_value,
1779
 
                                  &statement->comment,
1780
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
2210
                                  lex->length,lex->dec,lex->type,
 
2211
                                  lex->column_format,
 
2212
                                  lex->default_value, lex->on_update_value,
 
2213
                                  &lex->comment,
 
2214
                                  $3.str, &lex->interval_list, lex->charset))
1781
2215
              DRIZZLE_YYABORT;
1782
2216
          }
1783
2217
          opt_place
1784
2218
        | DROP opt_column field_ident
1785
2219
          {
1786
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1787
 
 
1788
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN, $3.str));
1789
 
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
 
2220
            LEX *lex=Lex;
 
2221
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
 
2222
                                                               $3.str));
 
2223
            lex->alter_info.flags.set(ALTER_DROP_COLUMN);
1790
2224
          }
1791
2225
        | DROP FOREIGN KEY_SYM opt_ident
1792
2226
          {
1793
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1794
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY,
1795
 
                                                                    $4.str));
1796
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
1797
 
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
2227
            Lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
2228
            Lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
1798
2229
          }
1799
2230
        | DROP PRIMARY_SYM KEY_SYM
1800
2231
          {
1801
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1802
 
 
1803
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2232
            LEX *lex=Lex;
 
2233
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
1804
2234
                                                               "PRIMARY"));
1805
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2235
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
1806
2236
          }
1807
2237
        | DROP key_or_index field_ident
1808
2238
          {
1809
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1810
 
 
1811
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
1812
 
                                                                    $3.str));
1813
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2239
            LEX *lex=Lex;
 
2240
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
2241
                                                               $3.str));
 
2242
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
1814
2243
          }
1815
2244
        | DISABLE_SYM KEYS
1816
2245
          {
1817
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1818
 
 
1819
 
            statement->alter_info.keys_onoff= DISABLE;
1820
 
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
2246
            LEX *lex=Lex;
 
2247
            lex->alter_info.keys_onoff= DISABLE;
 
2248
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
1821
2249
          }
1822
2250
        | ENABLE_SYM KEYS
1823
2251
          {
1824
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1825
 
 
1826
 
            statement->alter_info.keys_onoff= ENABLE;
1827
 
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
1828
 
          }
1829
 
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
1830
 
          {
1831
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1832
 
 
1833
 
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
1834
 
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1835
 
          }
1836
 
        | ALTER_SYM opt_column field_ident DROP DEFAULT
1837
 
          {
1838
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1839
 
 
1840
 
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str, (Item*) 0));
1841
 
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
2252
            LEX *lex=Lex;
 
2253
            lex->alter_info.keys_onoff= ENABLE;
 
2254
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
2255
          }
 
2256
        | ALTER opt_column field_ident SET DEFAULT signed_literal
 
2257
          {
 
2258
            LEX *lex=Lex;
 
2259
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
 
2260
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
2261
          }
 
2262
        | ALTER opt_column field_ident DROP DEFAULT
 
2263
          {
 
2264
            LEX *lex=Lex;
 
2265
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
 
2266
                                                                  (Item*) 0));
 
2267
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1842
2268
          }
1843
2269
        | RENAME opt_to table_ident
1844
2270
          {
1845
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2271
            LEX *lex=Lex;
1846
2272
            size_t dummy;
1847
 
 
1848
 
            Lex->select_lex.db=$3->db.str;
1849
 
            if (Lex->select_lex.db == NULL &&
1850
 
                Lex->copy_db_to(&Lex->select_lex.db, &dummy))
 
2273
            lex->select_lex.db=$3->db.str;
 
2274
            if (lex->select_lex.db == NULL &&
 
2275
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1851
2276
            {
1852
2277
              DRIZZLE_YYABORT;
1853
2278
            }
1854
 
 
1855
 
            if (check_table_name($3->table.str,$3->table.length))
 
2279
            if (check_table_name($3->table.str,$3->table.length) || ($3->db.str && check_db_name(&$3->db)))
1856
2280
            {
1857
2281
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
1858
2282
              DRIZZLE_YYABORT;
1859
2283
            }
1860
 
 
1861
 
            Lex->name= $3->table;
1862
 
            statement->alter_info.flags.set(ALTER_RENAME);
 
2284
            lex->name= $3->table;
 
2285
            lex->alter_info.flags.set(ALTER_RENAME);
1863
2286
          }
1864
2287
        | CONVERT_SYM TO_SYM collation_name_or_default
1865
2288
          {
1866
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
 
 
1868
 
            statement->create_info().table_charset=
1869
 
            statement->create_info().default_table_charset= $3;
1870
 
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
 
2289
            LEX *lex= Lex;
 
2290
            lex->create_info.table_charset=
 
2291
            lex->create_info.default_table_charset= $3;
 
2292
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1871
2293
              HA_CREATE_USED_DEFAULT_CHARSET);
1872
 
            statement->alter_info.flags.set(ALTER_CONVERT);
 
2294
            lex->alter_info.flags.set(ALTER_CONVERT);
1873
2295
          }
1874
2296
        | create_table_options_space_separated
1875
2297
          {
1876
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1877
 
 
1878
 
            statement->alter_info.flags.set(ALTER_OPTIONS);
 
2298
            LEX *lex=Lex;
 
2299
            lex->alter_info.flags.set(ALTER_OPTIONS);
1879
2300
          }
1880
2301
        | FORCE_SYM
1881
2302
          {
1882
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1883
 
 
1884
 
            statement->alter_info.flags.set(ALTER_FORCE);
 
2303
            Lex->alter_info.flags.set(ALTER_FORCE);
1885
2304
          }
1886
2305
        | alter_order_clause
1887
2306
          {
1888
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1889
 
 
1890
 
            statement->alter_info.flags.set(ALTER_ORDER);
 
2307
            LEX *lex=Lex;
 
2308
            lex->alter_info.flags.set(ALTER_ORDER);
1891
2309
          }
1892
2310
        ;
1893
2311
 
1905
2323
          /* empty */ {}
1906
2324
        | AFTER_SYM ident
1907
2325
          {
1908
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2326
            store_position_for_column($2.str);
 
2327
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
1909
2328
          }
1910
2329
        | FIRST_SYM
1911
2330
          {
1912
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2331
            store_position_for_column(first_keyword);
 
2332
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
1913
2333
          }
1914
2334
        ;
1915
2335
 
1923
2343
start:
1924
2344
          START_SYM TRANSACTION_SYM start_transaction_opts
1925
2345
          {
1926
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2346
            LEX *lex= Lex;
 
2347
            lex->sql_command= SQLCOM_BEGIN;
 
2348
            lex->start_transaction_opt= $3;
1927
2349
          }
1928
2350
        ;
1929
2351
 
1930
2352
start_transaction_opts:
1931
 
          /*empty*/ { $$ = START_TRANS_NO_OPTIONS; }
 
2353
          /*empty*/ { $$ = 0; }
1932
2354
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
1933
2355
          {
1934
 
            $$= START_TRANS_OPT_WITH_CONS_SNAPSHOT;
1935
 
          }
1936
 
        ;
 
2356
            $$= DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
 
2357
          }
 
2358
        ;
 
2359
 
 
2360
 
 
2361
checksum:
 
2362
          CHECKSUM_SYM table_or_tables
 
2363
          {
 
2364
            LEX *lex=Lex;
 
2365
            lex->sql_command = SQLCOM_CHECKSUM;
 
2366
          }
 
2367
          table_list opt_checksum_type
 
2368
          {}
 
2369
        ;
 
2370
 
 
2371
opt_checksum_type:
 
2372
          /* nothing */ { Lex->check_opt.flags= 0; }
 
2373
        | QUICK         { Lex->check_opt.flags= T_QUICK; }
 
2374
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
 
2375
        ;
 
2376
 
1937
2377
 
1938
2378
analyze:
1939
2379
          ANALYZE_SYM table_or_tables
1940
2380
          {
1941
 
            Lex->statement= new statement::Analyze(YYSession);
 
2381
            LEX *lex=Lex;
 
2382
            lex->sql_command = SQLCOM_ANALYZE;
 
2383
            lex->check_opt.init();
1942
2384
          }
1943
2385
          table_list
1944
2386
          {}
1947
2389
check:
1948
2390
          CHECK_SYM table_or_tables
1949
2391
          {
1950
 
            Lex->statement= new statement::Check(YYSession);
 
2392
            LEX *lex=Lex;
 
2393
 
 
2394
            lex->sql_command = SQLCOM_CHECK;
 
2395
            lex->check_opt.init();
 
2396
          }
 
2397
          table_list opt_mi_check_type
 
2398
          {}
 
2399
        ;
 
2400
 
 
2401
opt_mi_check_type:
 
2402
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2403
        | mi_check_types {}
 
2404
        ;
 
2405
 
 
2406
mi_check_types:
 
2407
          mi_check_type {}
 
2408
        | mi_check_type mi_check_types {}
 
2409
        ;
 
2410
 
 
2411
mi_check_type:
 
2412
          QUICK               { Lex->check_opt.flags|= T_QUICK; }
 
2413
        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
 
2414
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
 
2415
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
 
2416
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
 
2417
        ;
 
2418
 
 
2419
optimize:
 
2420
          OPTIMIZE table_or_tables
 
2421
          {
 
2422
            LEX *lex=Lex;
 
2423
            lex->sql_command = SQLCOM_OPTIMIZE;
 
2424
            lex->check_opt.init();
1951
2425
          }
1952
2426
          table_list
1953
2427
          {}
1956
2430
rename:
1957
2431
          RENAME table_or_tables
1958
2432
          {
1959
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2433
            Lex->sql_command= SQLCOM_RENAME_TABLE;
1960
2434
          }
1961
2435
          table_to_table_list
1962
2436
          {}
1970
2444
table_to_table:
1971
2445
          table_ident TO_SYM table_ident
1972
2446
          {
1973
 
            Select_Lex *sl= Lex->current_select;
1974
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2447
            LEX *lex=Lex;
 
2448
            Select_Lex *sl= lex->current_select;
 
2449
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1975
2450
                                       TL_IGNORE) ||
1976
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2451
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1977
2452
                                       TL_IGNORE))
1978
2453
              DRIZZLE_YYABORT;
1979
2454
          }
1980
2455
        ;
1981
2456
 
 
2457
keycache:
 
2458
          CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
 
2459
          {
 
2460
            LEX *lex=Lex;
 
2461
            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
 
2462
            lex->ident= $5;
 
2463
          }
 
2464
        ;
 
2465
 
 
2466
keycache_list:
 
2467
          assign_to_keycache
 
2468
        | keycache_list ',' assign_to_keycache
 
2469
        ;
 
2470
 
 
2471
assign_to_keycache:
 
2472
          table_ident cache_keys_spec
 
2473
          {
 
2474
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL,
 
2475
                   0, TL_READ, Lex->current_select->pop_index_hints()))
 
2476
              DRIZZLE_YYABORT;
 
2477
          }
 
2478
        ;
 
2479
 
 
2480
key_cache_name:
 
2481
          ident    { $$= $1; }
 
2482
        | DEFAULT  { $$ = default_key_cache_base; }
 
2483
        ;
 
2484
 
 
2485
cache_keys_spec:
 
2486
          {
 
2487
            Lex->select_lex.alloc_index_hints(YYSession);
 
2488
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE,
 
2489
                                                     INDEX_HINT_MASK_ALL);
 
2490
          }
 
2491
          cache_key_list_or_empty
 
2492
        ;
 
2493
 
 
2494
cache_key_list_or_empty:
 
2495
          /* empty */ { }
 
2496
        | key_or_index '(' opt_key_usage_list ')'
 
2497
        ;
 
2498
 
1982
2499
/*
1983
2500
  Select : retrieve data from table
1984
2501
*/
1987
2504
select:
1988
2505
          select_init
1989
2506
          {
1990
 
            Lex->statement= new statement::Select(YYSession);
 
2507
            LEX *lex= Lex;
 
2508
            lex->sql_command= SQLCOM_SELECT;
 
2509
            lex->command= new(YYSession->mem_root) command::Select(SQLCOM_SELECT,
 
2510
                                                            YYSession);
 
2511
            if (lex->command == NULL)
 
2512
              DRIZZLE_YYABORT;
1991
2513
          }
1992
2514
        ;
1993
2515
 
2000
2522
select_paren:
2001
2523
          SELECT_SYM select_part2
2002
2524
          {
2003
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2525
            if (setup_select_in_parentheses(Lex))
2004
2526
              DRIZZLE_YYABORT;
2005
2527
          }
2006
2528
        | '(' select_paren ')'
2010
2532
select_paren_derived:
2011
2533
          SELECT_SYM select_part2_derived
2012
2534
          {
2013
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2535
            if (setup_select_in_parentheses(Lex))
2014
2536
              DRIZZLE_YYABORT;
2015
2537
          }
2016
2538
        | '(' select_paren_derived ')'
2019
2541
select_init2:
2020
2542
          select_part2
2021
2543
          {
2022
 
            Select_Lex * sel= Lex->current_select;
2023
 
            if (Lex->current_select->set_braces(0))
 
2544
            LEX *lex= Lex;
 
2545
            Select_Lex * sel= lex->current_select;
 
2546
            if (lex->current_select->set_braces(0))
2024
2547
            {
2025
 
              parser::my_parse_error(YYSession->m_lip);
 
2548
              my_parse_error(ER(ER_SYNTAX_ERROR));
2026
2549
              DRIZZLE_YYABORT;
2027
2550
            }
2028
2551
            if (sel->linkage == UNION_TYPE &&
2029
2552
                sel->master_unit()->first_select()->braces)
2030
2553
            {
2031
 
              parser::my_parse_error(YYSession->m_lip);
 
2554
              my_parse_error(ER(ER_SYNTAX_ERROR));
2032
2555
              DRIZZLE_YYABORT;
2033
2556
            }
2034
2557
          }
2037
2560
 
2038
2561
select_part2:
2039
2562
          {
2040
 
            Select_Lex *sel= Lex->current_select;
 
2563
            LEX *lex= Lex;
 
2564
            Select_Lex *sel= lex->current_select;
2041
2565
            if (sel->linkage != UNION_TYPE)
2042
 
              init_select(Lex);
2043
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2566
              mysql_init_select(lex);
 
2567
            lex->current_select->parsing_place= SELECT_LIST;
2044
2568
          }
2045
2569
          select_options select_item_list
2046
2570
          {
2062
2586
          opt_order_clause opt_limit_clause
2063
2587
          {
2064
2588
            Lex->current_select->context.table_list=
2065
 
              Lex->current_select->context.first_name_resolution_table=
 
2589
              Lex->current_select->context.first_name_resolution_table= 
2066
2590
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
2067
2591
          }
2068
2592
        ;
2070
2594
select_options:
2071
2595
          /* empty*/
2072
2596
        | select_option_list
2073
 
          { }
 
2597
          {
 
2598
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2599
                Lex->current_select->options & SELECT_ALL)
 
2600
            {
 
2601
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2602
              DRIZZLE_YYABORT;
 
2603
            }
 
2604
          }
2074
2605
        ;
2075
2606
 
2076
2607
select_option_list:
2078
2609
        | select_option
2079
2610
        ;
2080
2611
 
2081
 
select_option_distinct_or_all:
2082
 
          DISTINCT
2083
 
          {
2084
 
            Lex->current_select->options|= SELECT_DISTINCT; 
2085
 
 
2086
 
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
2087
 
            {
2088
 
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2089
 
              DRIZZLE_YYABORT;
2090
 
            }
2091
 
          }
2092
 
        | ALL
2093
 
          {
2094
 
            Lex->current_select->options|= SELECT_ALL; 
2095
 
 
2096
 
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
2097
 
            {
2098
 
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2099
 
              DRIZZLE_YYABORT;
2100
 
            }
2101
 
          }
2102
 
        ;
2103
 
 
2104
 
select_option_small_or_big:
2105
 
          SQL_SMALL_RESULT
2106
 
          {
2107
 
            Lex->current_select->options|= SELECT_SMALL_RESULT;
2108
 
 
2109
 
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
2110
 
            {
2111
 
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2112
 
              DRIZZLE_YYABORT;
2113
 
            }
2114
 
          }
2115
 
        | SQL_BIG_RESULT
2116
 
          {
2117
 
            Lex->current_select->options|= SELECT_BIG_RESULT;
2118
 
 
2119
 
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
2120
 
            {
2121
 
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2122
 
              DRIZZLE_YYABORT;
2123
 
            }
2124
 
          }
2125
 
        ;
2126
 
 
2127
 
 
2128
2612
select_option:
2129
2613
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2614
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2615
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2616
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2130
2617
        | SQL_BUFFER_RESULT
2131
2618
          {
2132
 
            if (check_simple_select(YYSession))
 
2619
            if (check_simple_select())
2133
2620
              DRIZZLE_YYABORT;
2134
2621
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2135
2622
          }
2136
 
        | select_option_small_or_big
2137
 
          { }
2138
 
        | select_option_distinct_or_all
2139
 
          { }
2140
2623
        | SQL_CALC_FOUND_ROWS
2141
2624
          {
2142
 
            if (check_simple_select(YYSession))
 
2625
            if (check_simple_select())
2143
2626
              DRIZZLE_YYABORT;
2144
2627
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2145
2628
          }
 
2629
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2146
2630
        ;
2147
2631
 
2148
2632
select_lock_type:
2149
2633
          /* empty */
2150
2634
        | FOR_SYM UPDATE_SYM
2151
2635
          {
2152
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2636
            LEX *lex=Lex;
 
2637
            lex->current_select->set_lock_for_tables(TL_WRITE);
2153
2638
          }
2154
2639
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2155
2640
          {
2156
 
            Lex->current_select->
 
2641
            LEX *lex=Lex;
 
2642
            lex->current_select->
2157
2643
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2158
2644
          }
2159
2645
        ;
2163
2649
        | select_item
2164
2650
        | '*'
2165
2651
          {
2166
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
 
2652
            Session *session= YYSession;
 
2653
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
2167
2654
                                                          context,
2168
2655
                                                          NULL, NULL, "*")))
2169
2656
              DRIZZLE_YYABORT;
2170
 
            (YYSession->lex->current_select->with_wild)++;
 
2657
            (session->lex->current_select->with_wild)++;
2171
2658
          }
2172
2659
        ;
2173
2660
 
2174
2661
select_item:
2175
2662
          remember_name table_wild remember_end
2176
2663
          {
2177
 
            if (YYSession->add_item_to_list($2))
 
2664
            Session *session= YYSession;
 
2665
 
 
2666
            if (session->add_item_to_list($2))
2178
2667
              DRIZZLE_YYABORT;
2179
2668
          }
2180
2669
        | remember_name expr remember_end select_alias
2181
2670
          {
 
2671
            Session *session= YYSession;
2182
2672
            assert($1 < $3);
2183
2673
 
2184
 
            if (YYSession->add_item_to_list($2))
 
2674
            if (session->add_item_to_list($2))
2185
2675
              DRIZZLE_YYABORT;
2186
 
 
2187
2676
            if ($4.str)
2188
2677
            {
2189
2678
              $2->is_autogenerated_name= false;
2191
2680
            }
2192
2681
            else if (!$2->name)
2193
2682
            {
2194
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
2683
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2195
2684
            }
2196
2685
          }
2197
2686
        ;
2198
2687
 
2199
2688
remember_name:
2200
2689
          {
2201
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2690
            Session *session= YYSession;
 
2691
            Lex_input_stream *lip= session->m_lip;
2202
2692
            $$= (char*) lip->get_cpp_tok_start();
2203
2693
          }
2204
2694
        ;
2205
2695
 
2206
2696
remember_end:
2207
2697
          {
2208
 
            Lex_input_stream *lip= YYSession->m_lip;
 
2698
            Session *session= YYSession;
 
2699
            Lex_input_stream *lip= session->m_lip;
2209
2700
            $$= (char*) lip->get_cpp_tok_end();
2210
2701
          }
2211
2702
        ;
2358
2849
          }
2359
2850
        | bit_expr not IN_SYM '(' subselect ')'
2360
2851
          {
2361
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2362
 
            $$= negate_expression(YYSession, item);
 
2852
            Session *session= YYSession;
 
2853
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2854
            $$= negate_expression(session, item);
2363
2855
          }
2364
2856
        | bit_expr IN_SYM '(' expr ')'
2365
2857
          {
2366
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2858
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2367
2859
          }
2368
2860
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2369
 
          {
 
2861
          { 
2370
2862
            $6->push_front($4);
2371
2863
            $6->push_front($1);
2372
2864
            $$= new (YYSession->mem_root) Item_func_in(*$6);
2373
2865
          }
2374
2866
        | bit_expr not IN_SYM '(' expr ')'
2375
2867
          {
2376
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2868
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2377
2869
          }
2378
2870
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2379
2871
          {
2384
2876
            $$= item;
2385
2877
          }
2386
2878
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2387
 
          {
2388
 
            $$= new Item_func_between($1,$3,$5);
2389
 
          }
 
2879
          { $$= new Item_func_between($1,$3,$5); }
2390
2880
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2391
2881
          {
2392
2882
            Item_func_between *item= new Item_func_between($1,$4,$6);
2394
2884
            $$= item;
2395
2885
          }
2396
2886
        | bit_expr LIKE simple_expr opt_escape
2397
 
          { 
2398
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
2399
 
          }
 
2887
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2400
2888
        | bit_expr not LIKE simple_expr opt_escape
2401
 
          { 
2402
 
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used));
2403
 
          }
2404
 
        | bit_expr REGEXP_SYM bit_expr
2405
 
          { 
2406
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2407
 
            args->push_back($1);
2408
 
            args->push_back($3);
2409
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2410
 
            {
2411
 
              DRIZZLE_YYABORT;
2412
 
            }
2413
 
          }
2414
 
        | bit_expr not REGEXP_SYM bit_expr
2415
 
          { 
2416
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2417
 
            args->push_back($1);
2418
 
            args->push_back($4);
2419
 
            args->push_back(new (YYSession->mem_root) Item_int(1));
2420
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2421
 
            {
2422
 
              DRIZZLE_YYABORT;
2423
 
            }
2424
 
          }
 
2889
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2425
2890
        | bit_expr
2426
2891
        ;
2427
2892
 
2437
2902
        | bit_expr '*' bit_expr %prec '*'
2438
2903
          { $$= new Item_func_mul($1,$3); }
2439
2904
        | bit_expr '/' bit_expr %prec '/'
2440
 
          { $$= new Item_func_div(YYSession,$1,$3); }
 
2905
          { $$= new Item_func_div($1,$3); }
2441
2906
        | bit_expr '%' bit_expr %prec '%'
2442
2907
          { $$= new Item_func_mod($1,$3); }
2443
2908
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2481
2946
        | function_call_conflict
2482
2947
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2483
2948
          {
2484
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
2949
            Session *session= YYSession;
 
2950
            Item *i1= new (session->mem_root) Item_string($3.str,
2485
2951
                                                      $3.length,
2486
 
                                                      YYSession->charset());
2487
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
2952
                                                      session->charset());
 
2953
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2488
2954
          }
2489
2955
        | literal
2490
2956
        | variable
2491
2957
        | sum_expr
2492
 
          {
2493
 
            Lex->setSumExprUsed();
2494
 
          }
2495
2958
        | '+' simple_expr %prec NEG { $$= $2; }
2496
2959
        | '-' simple_expr %prec NEG
2497
2960
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2498
2961
        | '(' subselect ')'
2499
 
          {
 
2962
          { 
2500
2963
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
2501
2964
          }
2502
2965
        | '(' expr ')' { $$= $2; }
2522
2985
          }
2523
2986
        | CAST_SYM '(' expr AS cast_type ')'
2524
2987
          {
2525
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2526
 
                                 Lex->charset);
 
2988
            LEX *lex= Lex;
 
2989
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
2990
                                 lex->charset);
2527
2991
            if (!$$)
2528
2992
              DRIZZLE_YYABORT;
2529
2993
          }
2541
3005
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2542
3006
                                                         $3);
2543
3007
          }
2544
 
        | VALUES '(' simple_ident ')'
 
3008
        | VALUES '(' simple_ident_nospvar ')'
2545
3009
          {
2546
3010
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2547
3011
                                                        $3);
2562
3026
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
2563
3027
        | CURRENT_USER optional_braces
2564
3028
          {
2565
 
            std::string user_str("user");
2566
 
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
2567
 
            {
2568
 
              DRIZZLE_YYABORT;
2569
 
            }
2570
 
            Lex->setCacheable(false);
 
3029
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
2571
3030
          }
2572
3031
        | DATE_SYM '(' expr ')'
2573
3032
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
2576
3035
        | HOUR_SYM '(' expr ')'
2577
3036
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
2578
3037
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
2579
 
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
 
3038
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
2580
3039
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2581
3040
          {
2582
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3041
            Session *session= YYSession;
 
3042
            List<Item> *list= new (session->mem_root) List<Item>;
2583
3043
            list->push_front($5);
2584
3044
            list->push_front($3);
2585
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2586
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3045
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3046
            $$= new (session->mem_root) Item_func_interval(item);
2587
3047
          }
2588
3048
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2589
3049
          {
 
3050
            Session *session= YYSession;
2590
3051
            $7->push_front($5);
2591
3052
            $7->push_front($3);
2592
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2593
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3053
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3054
            $$= new (session->mem_root) Item_func_interval(item);
2594
3055
          }
2595
3056
        | LEFT '(' expr ',' expr ')'
2596
3057
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2622
3083
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2623
3084
        | USER '(' ')'
2624
3085
          {
2625
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
2626
 
            {
2627
 
              DRIZZLE_YYABORT;
2628
 
            }
2629
 
            Lex->setCacheable(false);
 
3086
            $$= new (YYSession->mem_root) Item_func_user();
2630
3087
          }
2631
3088
        | YEAR_SYM '(' expr ')'
2632
3089
          { $$= new (YYSession->mem_root) Item_func_year($3); }
2654
3111
        | CURDATE optional_braces
2655
3112
          {
2656
3113
            $$= new (YYSession->mem_root) Item_func_curdate_local();
2657
 
            Lex->setCacheable(false);
2658
3114
          }
2659
3115
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
2660
3116
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
2665
3121
        | NOW_SYM optional_braces
2666
3122
          {
2667
3123
            $$= new (YYSession->mem_root) Item_func_now_local();
2668
 
            Lex->setCacheable(false);
2669
3124
          }
2670
3125
        | NOW_SYM '(' expr ')'
2671
3126
          {
2672
3127
            $$= new (YYSession->mem_root) Item_func_now_local($3);
2673
 
            Lex->setCacheable(false);
2674
3128
          }
2675
3129
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
2676
3130
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
2682
3136
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
2683
3137
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2684
3138
        | SUBSTRING '(' expr ',' expr ',' expr ')'
2685
 
          {
2686
 
            std::string reverse_str("substr");
2687
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2688
 
            args->push_back($3);
2689
 
            args->push_back($5);
2690
 
            args->push_back($7);
2691
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
2692
 
            {
2693
 
              DRIZZLE_YYABORT;
2694
 
            }
2695
 
          }
 
3139
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
2696
3140
        | SUBSTRING '(' expr ',' expr ')'
2697
 
          {
2698
 
            std::string reverse_str("substr");
2699
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2700
 
            args->push_back($3);
2701
 
            args->push_back($5);
2702
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
2703
 
            {
2704
 
              DRIZZLE_YYABORT;
2705
 
            }
2706
 
          }
 
3141
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
2707
3142
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
2708
 
          {
2709
 
            std::string reverse_str("substr");
2710
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2711
 
            args->push_back($3);
2712
 
            args->push_back($5);
2713
 
            args->push_back($7);
2714
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
2715
 
            {
2716
 
              DRIZZLE_YYABORT;
2717
 
            }
2718
 
          }
 
3143
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
2719
3144
        | SUBSTRING '(' expr FROM expr ')'
2720
 
          {
2721
 
            std::string reverse_str("substr");
2722
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2723
 
            args->push_back($3);
2724
 
            args->push_back($5);
2725
 
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
2726
 
            {
2727
 
              DRIZZLE_YYABORT;
2728
 
            }
2729
 
          }
 
3145
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
2730
3146
        | SYSDATE optional_braces
2731
 
          { 
2732
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
2733
 
            Lex->setCacheable(false);
2734
 
          }
 
3147
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
2735
3148
        | SYSDATE '(' expr ')'
2736
 
          { 
2737
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
2738
 
            Lex->setCacheable(false);
2739
 
          }
 
3149
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
2740
3150
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
2741
3151
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
2742
3152
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
2744
3154
        | UTC_DATE_SYM optional_braces
2745
3155
          {
2746
3156
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
2747
 
            Lex->setCacheable(false);
2748
3157
          }
2749
3158
        | UTC_TIMESTAMP_SYM optional_braces
2750
3159
          {
2751
3160
            $$= new (YYSession->mem_root) Item_func_now_utc();
2752
 
            Lex->setCacheable(false);
2753
3161
          }
2754
3162
        ;
2755
3163
 
2765
3173
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2766
3174
        | DATABASE '(' ')'
2767
3175
          {
2768
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
2769
 
            {
2770
 
              DRIZZLE_YYABORT;
2771
 
            }
2772
 
            Lex->setCacheable(false);
2773
 
          }
2774
 
        | CATALOG_SYM '(' ')'
2775
 
          {
2776
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
2777
 
            {
2778
 
              DRIZZLE_YYABORT;
2779
 
            }
2780
 
            Lex->setCacheable(false);
2781
 
          }
2782
 
        | EXECUTE_SYM '(' expr ')' opt_wait
2783
 
          {
2784
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2785
 
            args->push_back($3);
2786
 
 
2787
 
            if ($5)
2788
 
            {
2789
 
              args->push_back(new (YYSession->mem_root) Item_int(1));
2790
 
            }
2791
 
 
2792
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
2793
 
            {
2794
 
              DRIZZLE_YYABORT;
2795
 
            }
 
3176
            $$= new (YYSession->mem_root) Item_func_database();
2796
3177
          }
2797
3178
        | IF '(' expr ',' expr ',' expr ')'
2798
3179
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
2799
 
        | KILL_SYM kill_option '(' expr ')'
2800
 
          {
2801
 
            std::string kill_str("kill");
2802
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2803
 
            args->push_back($4);
2804
 
 
2805
 
            if ($2)
2806
 
            {
2807
 
              args->push_back(new (YYSession->mem_root) Item_uint(1));
2808
 
            }
2809
 
 
2810
 
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
2811
 
            {
2812
 
              DRIZZLE_YYABORT;
2813
 
            }
2814
 
          }
2815
3180
        | MICROSECOND_SYM '(' expr ')'
2816
3181
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
2817
3182
        | MOD_SYM '(' expr ',' expr ')'
2819
3184
        | QUARTER_SYM '(' expr ')'
2820
3185
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
2821
3186
        | REPEAT_SYM '(' expr ',' expr ')'
2822
 
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
 
3187
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
2823
3188
        | REPLACE '(' expr ',' expr ',' expr ')'
2824
 
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3189
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
 
3190
        | REVERSE_SYM '(' expr ')'
 
3191
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
2825
3192
        | TRUNCATE_SYM '(' expr ',' expr ')'
2826
3193
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2827
 
        | WAIT_SYM '(' expr ')'
 
3194
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
 
3195
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
 
3196
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
2828
3197
          {
2829
 
            std::string wait_str("wait");
2830
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2831
 
            args->push_back($3);
2832
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
2833
 
            {
2834
 
              DRIZZLE_YYABORT;
2835
 
            }
 
3198
            $$= new (YYSession->mem_root)
 
3199
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
2836
3200
          }
2837
 
        | UUID_SYM '(' ')'
2838
 
          {
2839
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
2840
 
            {
2841
 
              DRIZZLE_YYABORT;
2842
 
            }
2843
 
            Lex->setCacheable(false);
2844
 
          }
2845
 
        | WAIT_SYM '(' expr ',' expr ')'
2846
 
          {
2847
 
            std::string wait_str("wait");
2848
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2849
 
            args->push_back($3);
2850
 
            args->push_back($5);
2851
 
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
2852
 
            {
2853
 
              DRIZZLE_YYABORT;
2854
 
            }
 
3201
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
 
3202
          {
 
3203
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3204
            $$= new (YYSession->mem_root)
 
3205
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
2855
3206
          }
2856
3207
        ;
2857
3208
 
2866
3217
function_call_generic:
2867
3218
          IDENT_sys '('
2868
3219
          {
2869
 
            const plugin::Function *udf= plugin::Function::get($1.str, $1.length);
 
3220
            Function_builder *udf= 0;
 
3221
            udf= find_udf($1.str, $1.length);
2870
3222
 
2871
 
            /* Temporary placing the result of getFunction in $3 */
 
3223
            /* Temporary placing the result of find_udf in $3 */
2872
3224
            $<udf>$= udf;
2873
3225
          }
2874
3226
          opt_udf_expr_list ')'
2875
3227
          {
 
3228
            Session *session= YYSession;
2876
3229
            Create_func *builder;
2877
3230
            Item *item= NULL;
2878
3231
 
2888
3241
            builder= find_native_function_builder($1);
2889
3242
            if (builder)
2890
3243
            {
2891
 
              item= builder->create(YYSession, $1, $4);
 
3244
              item= builder->create(session, $1, $4);
2892
3245
            }
2893
3246
            else
2894
3247
            {
2895
 
              /* Retrieving the result of service::Function::get */
2896
 
              const plugin::Function *udf= $<udf>3;
 
3248
              /* Retrieving the result of find_udf */
 
3249
              Function_builder *udf= $<udf>3;
2897
3250
              if (udf)
2898
3251
              {
2899
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3252
                item= Create_udf_func::s_singleton.create(session, udf, $4);
2900
3253
              } else {
2901
3254
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2902
3255
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
2907
3260
            {
2908
3261
              DRIZZLE_YYABORT;
2909
3262
            }
2910
 
            Lex->setCacheable(false);
2911
3263
          }
2912
3264
        ;
2913
3265
 
3013
3365
        ;
3014
3366
 
3015
3367
variable_aux:
3016
 
          user_variable_ident SET_VAR expr
 
3368
          ident_or_text SET_VAR expr
3017
3369
          {
3018
3370
            $$= new Item_func_set_user_var($1, $3);
3019
 
            Lex->setCacheable(false);
3020
3371
          }
3021
 
        | user_variable_ident
 
3372
        | ident_or_text
3022
3373
          {
3023
 
            $$= new Item_func_get_user_var(*YYSession, $1);
3024
 
            Lex->setCacheable(false);
 
3374
            $$= new Item_func_get_user_var($1);
3025
3375
          }
3026
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3376
        | '@' opt_var_ident_type ident_or_text opt_component
3027
3377
          {
3028
3378
            /* disallow "SELECT @@global.global.variable" */
3029
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3379
            if ($3.str && $4.str && check_reserved_words(&$3))
3030
3380
            {
3031
 
              parser::my_parse_error(YYSession->m_lip);
 
3381
              my_parse_error(ER(ER_SYNTAX_ERROR));
3032
3382
              DRIZZLE_YYABORT;
3033
3383
            }
3034
3384
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3037
3387
        ;
3038
3388
 
3039
3389
opt_distinct:
3040
 
          /* empty */ { $$ = false; }
3041
 
        | DISTINCT    { $$ = true; }
 
3390
          /* empty */ { $$ = 0; }
 
3391
        | DISTINCT    { $$ = 1; }
3042
3392
        ;
3043
3393
 
3044
3394
opt_gconcat_separator:
3058
3408
          {
3059
3409
            Select_Lex *select= Lex->current_select;
3060
3410
            select->gorder_list=
3061
 
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
 
3411
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3062
3412
                                     sizeof(st_sql_list));
3063
3413
            select->order_list.empty();
3064
3414
          }
3067
3417
in_sum_expr:
3068
3418
          opt_all
3069
3419
          {
3070
 
            if (Lex->current_select->inc_in_sum_expr())
 
3420
            LEX *lex= Lex;
 
3421
            if (lex->current_select->inc_in_sum_expr())
3071
3422
            {
3072
 
              parser::my_parse_error(YYSession->m_lip);
 
3423
              my_parse_error(ER(ER_SYNTAX_ERROR));
3073
3424
              DRIZZLE_YYABORT;
3074
3425
            }
3075
3426
          }
3083
3434
cast_type:
3084
3435
          BINARY opt_len
3085
3436
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3086
 
        | BOOLEAN_SYM
3087
 
          { $$=ITEM_CAST_BOOLEAN; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3088
 
        | SIGNED_SYM
3089
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3090
 
        | SIGNED_SYM INT_SYM
3091
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3092
 
        | INT_SYM
3093
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3094
 
        | UNSIGNED_SYM
3095
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3096
 
        | UNSIGNED_SYM INT_SYM
3097
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3098
 
        | CHAR_SYM opt_len
 
3437
        | CHAR_SYM opt_len opt_binary
3099
3438
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3100
3439
        | DATE_SYM
3101
3440
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3102
 
        | TIME_SYM
3103
 
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3104
3441
        | DATETIME_SYM
3105
3442
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3106
3443
        | DECIMAL_SYM float_options
3151
3488
          table_factor { $$=$1; }
3152
3489
        | join_table
3153
3490
          {
3154
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3491
            LEX *lex= Lex;
 
3492
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3155
3493
              DRIZZLE_YYABORT;
3156
3494
          }
3157
3495
        ;
3197
3535
            left-associative joins.
3198
3536
          */
3199
3537
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
3200
 
          { 
3201
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
3202
 
            Lex->is_cross= false;
3203
 
          }
 
3538
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); }
3204
3539
        | table_ref STRAIGHT_JOIN table_factor
3205
 
          { 
3206
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
3207
 
          }
 
3540
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
3208
3541
        | table_ref normal_join table_ref
3209
3542
          ON
3210
3543
          {
3211
3544
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3212
 
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
3213
3545
            /* Change the current name resolution context to a local context. */
3214
3546
            if (push_new_name_resolution_context(YYSession, $1, $3))
3215
3547
              DRIZZLE_YYABORT;
3273
3605
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3274
3606
          }
3275
3607
          USING '(' using_list ')'
3276
 
          {
3277
 
            add_join_natural($1,$5,$9,Lex->current_select);
3278
 
            $5->outer_join|=JOIN_TYPE_LEFT;
3279
 
            $$=$5;
 
3608
          { 
 
3609
            add_join_natural($1,$5,$9,Lex->current_select); 
 
3610
            $5->outer_join|=JOIN_TYPE_LEFT; 
 
3611
            $$=$5; 
3280
3612
          }
3281
3613
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3282
3614
          {
3298
3630
          }
3299
3631
          expr
3300
3632
          {
3301
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3633
            LEX *lex= Lex;
 
3634
            if (!($$= lex->current_select->convert_right_join()))
3302
3635
              DRIZZLE_YYABORT;
3303
3636
            add_join_on($$, $8);
3304
3637
            Lex->pop_context();
3310
3643
          }
3311
3644
          USING '(' using_list ')'
3312
3645
          {
3313
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3646
            LEX *lex= Lex;
 
3647
            if (!($$= lex->current_select->convert_right_join()))
3314
3648
              DRIZZLE_YYABORT;
3315
3649
            add_join_natural($$,$5,$9,Lex->current_select);
3316
3650
          }
3318
3652
          {
3319
3653
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3320
3654
            add_join_natural($6,$1,NULL,Lex->current_select);
3321
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3655
            LEX *lex= Lex;
 
3656
            if (!($$= lex->current_select->convert_right_join()))
3322
3657
              DRIZZLE_YYABORT;
3323
3658
          }
3324
3659
        ;
3326
3661
normal_join:
3327
3662
          JOIN_SYM {}
3328
3663
        | INNER_SYM JOIN_SYM {}
3329
 
        | CROSS JOIN_SYM
3330
 
          {
3331
 
            Lex->is_cross= true;
3332
 
            Lex->current_select->is_cross= true;
3333
 
          }
 
3664
        | CROSS JOIN_SYM {}
3334
3665
        ;
3335
3666
 
3336
 
/*
 
3667
/* 
3337
3668
   This is a flattening of the rules <table factor> and <table primary>
3338
3669
   in the SQL:2003 standard, since we don't have <sample clause>
3339
3670
 
3340
3671
   I.e.
3341
3672
   <table factor> ::= <table primary> [ <sample clause> ]
3342
 
*/  
 
3673
*/   
3343
3674
/* Warning - may return NULL in case of incomplete SELECT */
3344
3675
table_factor:
3345
3676
          {
 
3677
            Select_Lex *sel= Lex->current_select;
 
3678
            sel->table_join_options= 0;
3346
3679
          }
3347
3680
          table_ident opt_table_alias opt_key_definition
3348
3681
          {
3349
3682
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3350
 
                             0,
 
3683
                             Lex->current_select->get_table_join_options(),
3351
3684
                             Lex->lock_option,
3352
3685
                             Lex->current_select->pop_index_hints())))
3353
3686
              DRIZZLE_YYABORT;
3355
3688
          }
3356
3689
        | select_derived_init get_select_lex select_derived2
3357
3690
          {
3358
 
            Select_Lex *sel= Lex->current_select;
 
3691
            LEX *lex= Lex;
 
3692
            Select_Lex *sel= lex->current_select;
3359
3693
            if ($1)
3360
3694
            {
3361
3695
              if (sel->set_braces(1))
3362
3696
              {
3363
 
                parser::my_parse_error(YYSession->m_lip);
 
3697
                my_parse_error(ER(ER_SYNTAX_ERROR));
3364
3698
                DRIZZLE_YYABORT;
3365
3699
              }
3366
3700
              /* select in braces, can't contain global parameters */
3368
3702
                sel->master_unit()->global_parameters=
3369
3703
                   sel->master_unit()->fake_select_lex;
3370
3704
            }
3371
 
            if ($2->init_nested_join(Lex->session))
 
3705
            if ($2->init_nested_join(lex->session))
3372
3706
              DRIZZLE_YYABORT;
3373
3707
            $$= 0;
3374
3708
            /* incomplete derived tables return NULL, we must be
3378
3712
            Represents a flattening of the following rules from the SQL:2003
3379
3713
            standard. This sub-rule corresponds to the sub-rule
3380
3714
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
3381
 
           
 
3715
            
3382
3716
            The following rules have been flattened into query_expression_body
3383
3717
            (since we have no <with clause>).
3384
3718
 
3397
3731
            /* Use $2 instead of Lex->current_select as derived table will
3398
3732
               alter value of Lex->current_select. */
3399
3733
            if (!($3 || $5) && $2->embedding &&
3400
 
                !$2->embedding->getNestedJoin()->join_list.elements)
 
3734
                !$2->embedding->nested_join->join_list.elements)
3401
3735
            {
3402
3736
              /* we have a derived table ($3 == NULL) but no alias,
3403
3737
                 Since we are nested in further parentheses so we
3410
3744
              /* Handle case of derived table, alias may be NULL if there
3411
3745
                 are no outer parentheses, add_table_to_list() will throw
3412
3746
                 error in this case */
3413
 
              Select_Lex *sel= Lex->current_select;
 
3747
              LEX *lex=Lex;
 
3748
              Select_Lex *sel= lex->current_select;
3414
3749
              Select_Lex_Unit *unit= sel->master_unit();
3415
 
              Lex->current_select= sel= unit->outer_select();
3416
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3750
              lex->current_select= sel= unit->outer_select();
 
3751
              if (!($$= sel->add_table_to_list(lex->session,
3417
3752
                                               new Table_ident(unit), $5, 0,
3418
3753
                                               TL_READ)))
3419
3754
 
3420
3755
                DRIZZLE_YYABORT;
3421
3756
              sel->add_joined_table($$);
3422
 
              Lex->pop_context();
 
3757
              lex->pop_context();
3423
3758
            }
3424
3759
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3425
3760
            {
3426
3761
              /* simple nested joins cannot have aliases or unions */
3427
 
              parser::my_parse_error(YYSession->m_lip);
 
3762
              my_parse_error(ER(ER_SYNTAX_ERROR));
3428
3763
              DRIZZLE_YYABORT;
3429
3764
            }
3430
3765
            else
3438
3773
          UNION_SYM
3439
3774
          union_option
3440
3775
          {
3441
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3776
            if (add_select_to_union_list(Lex, (bool)$3))
3442
3777
              DRIZZLE_YYABORT;
3443
3778
          }
3444
3779
          query_specification
3456
3791
select_init2_derived:
3457
3792
          select_part2_derived
3458
3793
          {
3459
 
            Select_Lex * sel= Lex->current_select;
3460
 
            if (Lex->current_select->set_braces(0))
 
3794
            LEX *lex= Lex;
 
3795
            Select_Lex * sel= lex->current_select;
 
3796
            if (lex->current_select->set_braces(0))
3461
3797
            {
3462
 
              parser::my_parse_error(YYSession->m_lip);
 
3798
              my_parse_error(ER(ER_SYNTAX_ERROR));
3463
3799
              DRIZZLE_YYABORT;
3464
3800
            }
3465
3801
            if (sel->linkage == UNION_TYPE &&
3466
3802
                sel->master_unit()->first_select()->braces)
3467
3803
            {
3468
 
              parser::my_parse_error(YYSession->m_lip);
 
3804
              my_parse_error(ER(ER_SYNTAX_ERROR));
3469
3805
              DRIZZLE_YYABORT;
3470
3806
            }
3471
3807
          }
3474
3810
/* The equivalent of select_part2 for nested queries. */
3475
3811
select_part2_derived:
3476
3812
          {
3477
 
            Select_Lex *sel= Lex->current_select;
 
3813
            LEX *lex= Lex;
 
3814
            Select_Lex *sel= lex->current_select;
3478
3815
            if (sel->linkage != UNION_TYPE)
3479
 
              init_select(Lex);
3480
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3816
              mysql_init_select(lex);
 
3817
            lex->current_select->parsing_place= SELECT_LIST;
3481
3818
          }
3482
3819
          select_options select_item_list
3483
3820
          {
3490
3827
select_derived:
3491
3828
          get_select_lex
3492
3829
          {
3493
 
            if ($1->init_nested_join(Lex->session))
 
3830
            LEX *lex= Lex;
 
3831
            if ($1->init_nested_join(lex->session))
3494
3832
              DRIZZLE_YYABORT;
3495
3833
          }
3496
3834
          derived_table_list
3497
3835
          {
 
3836
            LEX *lex= Lex;
3498
3837
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3499
3838
               for derived tables, both must equal NULL */
3500
3839
 
3501
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
3840
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3502
3841
              DRIZZLE_YYABORT;
3503
 
 
3504
3842
            if (!$3 && $$)
3505
3843
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
3844
              my_parse_error(ER(ER_SYNTAX_ERROR));
3507
3845
              DRIZZLE_YYABORT;
3508
3846
            }
3509
3847
          }
3511
3849
 
3512
3850
select_derived2:
3513
3851
          {
3514
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3515
 
            if (not Lex->expr_allows_subselect)
 
3852
            LEX *lex= Lex;
 
3853
            lex->derived_tables|= DERIVED_SUBQUERY;
 
3854
            if (!lex->expr_allows_subselect)
3516
3855
            {
3517
 
              parser::my_parse_error(YYSession->m_lip);
 
3856
              my_parse_error(ER(ER_SYNTAX_ERROR));
3518
3857
              DRIZZLE_YYABORT;
3519
3858
            }
3520
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
3859
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
3860
                mysql_new_select(lex, 1))
3521
3861
              DRIZZLE_YYABORT;
3522
 
            init_select(Lex);
3523
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3524
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3862
            mysql_init_select(lex);
 
3863
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3864
            lex->current_select->parsing_place= SELECT_LIST;
3525
3865
          }
3526
3866
          select_options select_item_list
3527
3867
          {
3537
3877
select_derived_init:
3538
3878
          SELECT_SYM
3539
3879
          {
3540
 
            Select_Lex *sel= Lex->current_select;
 
3880
            LEX *lex= Lex;
 
3881
 
 
3882
            Select_Lex *sel= lex->current_select;
3541
3883
            TableList *embedding;
3542
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
3884
            if (!sel->embedding || sel->end_nested_join(lex->session))
3543
3885
            {
3544
3886
              /* we are not in parentheses */
3545
 
              parser::my_parse_error(YYSession->m_lip);
 
3887
              my_parse_error(ER(ER_SYNTAX_ERROR));
3546
3888
              DRIZZLE_YYABORT;
3547
3889
            }
3548
3890
            embedding= Lex->current_select->embedding;
3549
3891
            $$= embedding &&
3550
 
                !embedding->getNestedJoin()->join_list.elements;
 
3892
                !embedding->nested_join->join_list.elements;
3551
3893
            /* return true if we are deeply nested */
3552
3894
          }
3553
3895
        ;
3560
3902
index_hint_clause:
3561
3903
          /* empty */
3562
3904
          {
3563
 
            $$= INDEX_HINT_MASK_ALL;
 
3905
            $$= INDEX_HINT_MASK_ALL; 
3564
3906
          }
3565
3907
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
3566
3908
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
3569
3911
 
3570
3912
index_hint_type:
3571
3913
          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
3572
 
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
 
3914
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; } 
3573
3915
        ;
3574
3916
 
3575
3917
index_hint_definition:
3652
3994
 
3653
3995
interval_time_stamp:
3654
3996
        interval_time_st        {}
3655
 
        | FRAC_SECOND_SYM       {
3656
 
                                  $$=INTERVAL_MICROSECOND;
 
3997
        | FRAC_SECOND_SYM       { 
 
3998
                                  $$=INTERVAL_MICROSECOND; 
3657
3999
                                  /*
3658
4000
                                    FRAC_SECOND was mistakenly implemented with
3659
4001
                                    a wrong resolution. According to the ODBC
3690
4032
opt_table_alias:
3691
4033
          /* empty */ { $$=0; }
3692
4034
        | table_alias ident
3693
 
          {
3694
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3695
 
          }
 
4035
          { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
3696
4036
        ;
3697
4037
 
3698
4038
opt_all:
3733
4073
        ;
3734
4074
 
3735
4075
opt_escape:
3736
 
          ESCAPE_SYM simple_expr
 
4076
          ESCAPE_SYM simple_expr 
3737
4077
          {
3738
4078
            Lex->escape_used= true;
3739
4079
            $$= $2;
3772
4112
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3773
4113
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3774
4114
            */
3775
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4115
            LEX *lex= Lex;
 
4116
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3776
4117
            {
3777
4118
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3778
4119
                       "global union parameters");
3779
4120
              DRIZZLE_YYABORT;
3780
4121
            }
3781
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4122
            lex->current_select->olap= ROLLUP_TYPE;
3782
4123
          }
3783
4124
        ;
3784
4125
 
3796
4137
        ;
3797
4138
 
3798
4139
alter_order_item:
3799
 
          simple_ident order_dir
 
4140
          simple_ident_nospvar order_dir
3800
4141
          {
 
4142
            Session *session= YYSession;
3801
4143
            bool ascending= ($2 == 1) ? true : false;
3802
 
            if (YYSession->add_order_to_list($1, ascending))
 
4144
            if (session->add_order_to_list($1, ascending))
3803
4145
              DRIZZLE_YYABORT;
3804
4146
          }
3805
4147
        ;
3816
4158
order_clause:
3817
4159
          ORDER_SYM BY
3818
4160
          {
3819
 
            if (not parser::buildOrderBy(Lex))
 
4161
            LEX *lex=Lex;
 
4162
            Select_Lex *sel= lex->current_select;
 
4163
            Select_Lex_Unit *unit= sel-> master_unit();
 
4164
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4165
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4166
                (sel->linkage != UNION_TYPE || sel->braces))
 
4167
            {
 
4168
              my_error(ER_WRONG_USAGE, MYF(0),
 
4169
                       "CUBE/ROLLUP", "ORDER BY");
3820
4170
              DRIZZLE_YYABORT;
 
4171
            }
 
4172
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4173
            {
 
4174
              /*
 
4175
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4176
                executed in the same way as the query
 
4177
                SELECT ... ORDER BY order_list
 
4178
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4179
                Otherwise we create a fake Select_Lex if it has not been created
 
4180
                yet.
 
4181
              */
 
4182
              Select_Lex *first_sl= unit->first_select();
 
4183
              if (!unit->is_union() &&
 
4184
                  (first_sl->order_list.elements || 
 
4185
                   first_sl->select_limit) &&            
 
4186
                  unit->add_fake_select_lex(lex->session))
 
4187
                DRIZZLE_YYABORT;
 
4188
            }
3821
4189
          }
3822
4190
          order_list
3823
4191
        ;
3824
4192
 
3825
4193
order_list:
3826
4194
          order_list ',' order_ident order_dir
3827
 
          {
3828
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3829
 
              DRIZZLE_YYABORT;
3830
 
          }
 
4195
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
3831
4196
        | order_ident order_dir
3832
 
          {
3833
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3834
 
              DRIZZLE_YYABORT;
3835
 
          }
 
4197
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
3836
4198
        ;
3837
4199
 
3838
4200
order_dir:
3844
4206
opt_limit_clause_init:
3845
4207
          /* empty */
3846
4208
          {
3847
 
            Select_Lex *sel= Lex->current_select;
 
4209
            LEX *lex= Lex;
 
4210
            Select_Lex *sel= lex->current_select;
3848
4211
            sel->offset_limit= 0;
3849
4212
            sel->select_limit= 0;
3850
4213
          }
3893
4256
delete_limit_clause:
3894
4257
          /* empty */
3895
4258
          {
3896
 
            Lex->current_select->select_limit= 0;
 
4259
            LEX *lex=Lex;
 
4260
            lex->current_select->select_limit= 0;
3897
4261
          }
3898
4262
        | LIMIT limit_option
3899
4263
          {
3904
4268
        ;
3905
4269
 
3906
4270
ulong_num:
3907
 
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3908
 
        | HEX_NUM       { $$= (unsigned long) strtol($1.str, (char**) 0, 16); }
3909
 
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3910
 
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3911
 
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
3912
 
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4271
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4272
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4273
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4274
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4275
        | DECIMAL_NUM   { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4276
        | FLOAT_NUM     { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
3913
4277
        ;
3914
4278
 
 
4279
real_ulong_num:
 
4280
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4281
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4282
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4283
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4284
        | dec_num_error { }
 
4285
        ;
 
4286
 
3915
4287
ulonglong_num:
3916
 
          NUM           { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
3917
 
        | ULONGLONG_NUM { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
3918
 
        | LONG_NUM      { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
3919
 
        | DECIMAL_NUM   { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
3920
 
        | FLOAT_NUM     { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
3921
 
        ;
 
4288
          NUM           { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4289
        | ULONGLONG_NUM { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4290
        | LONG_NUM      { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4291
        | DECIMAL_NUM   { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4292
        | FLOAT_NUM     { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4293
        ;
 
4294
 
 
4295
dec_num_error:
 
4296
          dec_num
 
4297
          { my_parse_error(ER(ER_ONLY_INTEGERS_ALLOWED)); }
 
4298
        ;
 
4299
 
 
4300
dec_num:
 
4301
          DECIMAL_NUM
 
4302
        | FLOAT_NUM
 
4303
        ;
 
4304
 
 
4305
choice:
 
4306
        ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
 
4307
        | DEFAULT { $$= HA_CHOICE_UNDEF; }
 
4308
        ;
3922
4309
 
3923
4310
select_var_list_init:
3924
4311
          {
3925
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4312
            LEX *lex=Lex;
 
4313
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3926
4314
              DRIZZLE_YYABORT;
3927
4315
          }
3928
4316
          select_var_list
3934
4322
        | select_var_ident {}
3935
4323
        ;
3936
4324
 
3937
 
select_var_ident: 
3938
 
          '@' user_variable_ident
 
4325
select_var_ident:  
 
4326
          '@' ident_or_text
3939
4327
          {
3940
 
            if (Lex->result)
3941
 
            {
3942
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3943
 
            }
 
4328
            LEX *lex=Lex;
 
4329
            if (lex->result) 
 
4330
              ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
3944
4331
            else
3945
 
            {
3946
4332
              /*
3947
4333
                The parser won't create select_result instance only
3948
4334
                if it's an EXPLAIN.
3949
4335
              */
3950
 
              assert(Lex->describe);
3951
 
            }
 
4336
              assert(lex->describe);
3952
4337
          }
3953
4338
        ;
3954
4339
 
3961
4346
into_destination:
3962
4347
          OUTFILE TEXT_STRING_filesystem
3963
4348
          {
3964
 
            Lex->setCacheable(false);
3965
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3966
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4349
            LEX *lex= Lex;
 
4350
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
 
4351
                !(lex->result= new select_export(lex->exchange)))
3967
4352
              DRIZZLE_YYABORT;
3968
4353
          }
3969
4354
          opt_field_term opt_line_term
3970
4355
        | DUMPFILE TEXT_STRING_filesystem
3971
4356
          {
3972
 
            if (not Lex->describe)
 
4357
            LEX *lex=Lex;
 
4358
            if (!lex->describe)
3973
4359
            {
3974
 
              Lex->setCacheable(false);
3975
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4360
              if (!(lex->exchange= new file_exchange($2.str,1)))
3976
4361
                DRIZZLE_YYABORT;
3977
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4362
              if (!(lex->result= new select_dump(lex->exchange)))
3978
4363
                DRIZZLE_YYABORT;
3979
4364
            }
3980
4365
          }
3981
4366
        | select_var_list_init
3982
 
          {Lex->setCacheable(false);}
 
4367
          { }
3983
4368
        ;
3984
4369
 
3985
4370
/*
3987
4372
*/
3988
4373
 
3989
4374
drop:
3990
 
          DROP CATALOG_SYM catalog_name
3991
 
          {
3992
 
            Lex->statement= new statement::catalog::Drop(YYSession, $3);
3993
 
          }
3994
 
        | DROP opt_temporary table_or_tables if_exists table_list
3995
 
          {
3996
 
            statement::DropTable *statement= new statement::DropTable(YYSession);
3997
 
            Lex->statement= statement;
3998
 
            statement->drop_temporary= $2;
3999
 
            statement->drop_if_exists= $4;
 
4375
          DROP opt_temporary table_or_tables if_exists table_list
 
4376
          {
 
4377
            LEX *lex=Lex;
 
4378
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4379
            lex->drop_temporary= $2;
 
4380
            lex->drop_if_exists= $4;
4000
4381
          }
4001
4382
        | DROP build_method INDEX_SYM ident ON table_ident {}
4002
4383
          {
4003
 
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
4004
 
            Lex->statement= statement;
4005
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4006
 
            statement->alter_info.build_method= $2;
4007
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4008
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
4009
 
                                                          TL_OPTION_UPDATING))
 
4384
            LEX *lex=Lex;
 
4385
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4386
            lex->alter_info.reset();
 
4387
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
4388
            lex->alter_info.build_method= $2;
 
4389
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
4390
                                                               $4.str));
 
4391
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4392
                                                        TL_OPTION_UPDATING))
4010
4393
              DRIZZLE_YYABORT;
4011
4394
          }
4012
 
        | DROP DATABASE if_exists schema_name
 
4395
        | DROP DATABASE if_exists ident
4013
4396
          {
4014
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4015
 
            Lex->statement= statement;
4016
 
            statement->drop_if_exists=$3;
4017
 
            Lex->name= $4;
 
4397
            LEX *lex=Lex;
 
4398
            lex->sql_command= SQLCOM_DROP_DB;
 
4399
            lex->drop_if_exists=$3;
 
4400
            lex->name= $4;
4018
4401
          }
4019
 
        ;
4020
 
 
4021
4402
table_list:
4022
4403
          table_name
4023
4404
        | table_list ',' table_name
4031
4412
          }
4032
4413
        ;
4033
4414
 
 
4415
table_alias_ref_list:
 
4416
          table_alias_ref
 
4417
        | table_alias_ref_list ',' table_alias_ref
 
4418
        ;
 
4419
 
 
4420
table_alias_ref:
 
4421
          table_ident
 
4422
          {
 
4423
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL,
 
4424
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4425
                                           Lex->lock_option ))
 
4426
              DRIZZLE_YYABORT;
 
4427
          }
 
4428
        ;
 
4429
 
4034
4430
if_exists:
4035
 
          /* empty */ { $$= false; }
4036
 
        | IF EXISTS { $$= true; }
 
4431
          /* empty */ { $$= 0; }
 
4432
        | IF EXISTS { $$= 1; }
4037
4433
        ;
4038
4434
 
4039
4435
opt_temporary:
4040
 
          /* empty */ { $$= false; }
4041
 
        | TEMPORARY_SYM { $$= true; }
4042
 
        ;
4043
 
 
4044
 
/*
4045
 
  Execute a string as dynamic SQL.
4046
 
*/
4047
 
 
4048
 
execute:
4049
 
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
4050
 
        {
4051
 
          Lex->statement= new statement::Execute(YYSession, $2, $3, $4, $5);
4052
 
        }
4053
 
 
4054
 
 
4055
 
execute_var_or_string:
4056
 
         user_variable_ident
4057
 
         {
4058
 
            $$.set($1);
4059
 
         }
4060
 
        | '@' user_variable_ident
4061
 
        {
4062
 
            $$.set($2, true);
4063
 
        }
4064
 
 
4065
 
opt_status:
4066
 
          /* empty */ { $$= false; }
4067
 
        | WITH NO_SYM RETURN_SYM { $$= true; }
4068
 
        ;
4069
 
 
4070
 
opt_concurrent:
4071
 
          /* empty */ { $$= false; }
4072
 
        | CONCURRENT { $$= true; }
4073
 
        ;
4074
 
 
4075
 
opt_wait:
4076
 
          /* empty */ { $$= false; }
4077
 
        | WAIT_SYM { $$= true; }
4078
 
        ;
4079
 
 
 
4436
          /* empty */ { $$= 0; }
 
4437
        | TEMPORARY_SYM { $$= 1; }
 
4438
        ;
4080
4439
/*
4081
4440
** Insert : add new data to table
4082
4441
*/
4084
4443
insert:
4085
4444
          INSERT
4086
4445
          {
4087
 
            Lex->statement= new statement::Insert(YYSession);
4088
 
            Lex->duplicates= DUP_ERROR;
4089
 
            init_select(Lex);
 
4446
            LEX *lex= Lex;
 
4447
            lex->sql_command= SQLCOM_INSERT;
 
4448
            lex->duplicates= DUP_ERROR; 
 
4449
            mysql_init_select(lex);
4090
4450
            /* for subselects */
4091
 
            Lex->lock_option= TL_READ;
 
4451
            lex->lock_option= TL_READ;
4092
4452
          }
4093
4453
          opt_ignore insert2
4094
4454
          {
4102
4462
replace:
4103
4463
          REPLACE
4104
4464
          {
4105
 
            Lex->statement= new statement::Replace(YYSession);
4106
 
            Lex->duplicates= DUP_REPLACE;
4107
 
            init_select(Lex);
 
4465
            LEX *lex=Lex;
 
4466
            lex->sql_command = SQLCOM_REPLACE;
 
4467
            lex->duplicates= DUP_REPLACE;
 
4468
            mysql_init_select(lex);
4108
4469
          }
4109
4470
          insert2
4110
4471
          {
4123
4484
insert_table:
4124
4485
          table_name
4125
4486
          {
4126
 
            Lex->field_list.empty();
4127
 
            Lex->many_values.empty();
4128
 
            Lex->insert_list=0;
 
4487
            LEX *lex=Lex;
 
4488
            lex->field_list.empty();
 
4489
            lex->many_values.empty();
 
4490
            lex->insert_list=0;
4129
4491
          };
4130
4492
 
4131
4493
insert_field_spec:
4132
4494
          insert_values {}
4133
4495
        | '(' ')' insert_values {}
4134
4496
        | '(' fields ')' insert_values {}
4135
 
        | SET_SYM
 
4497
        | SET
4136
4498
          {
4137
 
            if (not (Lex->insert_list = new List_item) ||
4138
 
                Lex->many_values.push_back(Lex->insert_list))
 
4499
            LEX *lex=Lex;
 
4500
            if (!(lex->insert_list = new List_item) ||
 
4501
                lex->many_values.push_back(lex->insert_list))
4139
4502
              DRIZZLE_YYABORT;
4140
4503
          }
4141
4504
          ident_eq_list
4149
4512
insert_values:
4150
4513
          VALUES values_list {}
4151
4514
        | VALUE_SYM values_list {}
4152
 
        | stored_select
4153
 
          {
4154
 
            Lex->current_select->set_braces(0);
4155
 
          }
 
4515
        | create_select
 
4516
          { Lex->current_select->set_braces(0);}
4156
4517
          union_clause {}
4157
 
        | '(' stored_select ')'
4158
 
          {
4159
 
            Lex->current_select->set_braces(1);
4160
 
          }
 
4518
        | '(' create_select ')'
 
4519
          { Lex->current_select->set_braces(1);}
4161
4520
          union_opt {}
4162
4521
        ;
4163
4522
 
4172
4531
        ;
4173
4532
 
4174
4533
ident_eq_value:
4175
 
          simple_ident equal expr_or_default
 
4534
          simple_ident_nospvar equal expr_or_default
4176
4535
          {
4177
 
            if (Lex->field_list.push_back($1) ||
4178
 
                Lex->insert_list->push_back($3))
 
4536
            LEX *lex=Lex;
 
4537
            if (lex->field_list.push_back($1) ||
 
4538
                lex->insert_list->push_back($3))
4179
4539
              DRIZZLE_YYABORT;
4180
4540
          }
4181
4541
        ;
4198
4558
          }
4199
4559
          opt_values ')'
4200
4560
          {
4201
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4561
            LEX *lex=Lex;
 
4562
            if (lex->many_values.push_back(lex->insert_list))
4202
4563
              DRIZZLE_YYABORT;
4203
4564
          }
4204
4565
        ;
4235
4596
/* Update rows in a table */
4236
4597
 
4237
4598
update:
4238
 
          UPDATE_SYM opt_ignore table_ident
 
4599
          UPDATE_SYM
4239
4600
          {
4240
 
            init_select(Lex);
4241
 
            Lex->statement= new statement::Update(YYSession);
4242
 
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
4243
 
            Lex->duplicates= DUP_ERROR;
4244
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4245
 
              DRIZZLE_YYABORT;
 
4601
            LEX *lex= Lex;
 
4602
            mysql_init_select(lex);
 
4603
            lex->sql_command= SQLCOM_UPDATE;
 
4604
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4605
            lex->duplicates= DUP_ERROR; 
4246
4606
          }
4247
 
          SET_SYM update_list
 
4607
          opt_ignore join_table_list
 
4608
          SET update_list
4248
4609
          {
4249
 
            if (Lex->select_lex.get_table_list()->derived)
 
4610
            LEX *lex= Lex;
 
4611
            if (lex->select_lex.table_list.elements > 1)
 
4612
              lex->sql_command= SQLCOM_UPDATE_MULTI;
 
4613
            else if (lex->select_lex.get_table_list()->derived)
4250
4614
            {
4251
4615
              /* it is single table update and it is update of derived table */
4252
4616
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4253
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4617
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4254
4618
              DRIZZLE_YYABORT;
4255
4619
            }
4256
4620
            /*
4257
4621
              In case of multi-update setting write lock for all tables may
4258
4622
              be too pessimistic. We will decrease lock level if possible in
4259
 
              multi_update().
 
4623
              mysql_multi_update().
4260
4624
            */
4261
4625
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4262
4626
          }
4269
4633
        ;
4270
4634
 
4271
4635
update_elem:
4272
 
          simple_ident equal expr_or_default
 
4636
          simple_ident_nospvar equal expr_or_default
4273
4637
          {
4274
4638
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4275
4639
              DRIZZLE_YYABORT;
4282
4646
        ;
4283
4647
 
4284
4648
insert_update_elem:
4285
 
          simple_ident equal expr_or_default
 
4649
          simple_ident_nospvar equal expr_or_default
4286
4650
          {
4287
 
          if (Lex->update_list.push_back($1) ||
4288
 
              Lex->value_list.push_back($3))
 
4651
          LEX *lex= Lex;
 
4652
          if (lex->update_list.push_back($1) || 
 
4653
              lex->value_list.push_back($3))
4289
4654
              DRIZZLE_YYABORT;
4290
4655
          }
4291
4656
        ;
4295
4660
delete:
4296
4661
          DELETE_SYM
4297
4662
          {
4298
 
            Lex->statement= new statement::Delete(YYSession);
4299
 
            init_select(Lex);
4300
 
            Lex->lock_option= TL_WRITE_DEFAULT;
4301
 
            Lex->ignore= 0;
4302
 
            Lex->select_lex.init_order();
 
4663
            LEX *lex= Lex;
 
4664
            lex->sql_command= SQLCOM_DELETE;
 
4665
            mysql_init_select(lex);
 
4666
            lex->lock_option= TL_WRITE_DEFAULT;
 
4667
            lex->ignore= 0;
 
4668
            lex->select_lex.init_order();
4303
4669
          }
4304
4670
          opt_delete_options single_multi
4305
4671
        ;
4313
4679
          }
4314
4680
          where_clause opt_order_clause
4315
4681
          delete_limit_clause {}
 
4682
        | table_wild_list
 
4683
          { mysql_init_multi_delete(Lex); }
 
4684
          FROM join_table_list where_clause
 
4685
          {
 
4686
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
 
4687
              DRIZZLE_YYABORT;
 
4688
          }
 
4689
        | FROM table_alias_ref_list
 
4690
          { mysql_init_multi_delete(Lex); }
 
4691
          USING join_table_list where_clause
 
4692
          {
 
4693
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
 
4694
              DRIZZLE_YYABORT;
 
4695
          }
 
4696
        ;
 
4697
 
 
4698
table_wild_list:
 
4699
          table_wild_one
 
4700
        | table_wild_list ',' table_wild_one
 
4701
        ;
 
4702
 
 
4703
table_wild_one:
 
4704
          ident opt_wild
 
4705
          {
 
4706
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4707
                    new Table_ident($1), NULL,
 
4708
                    TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4709
                    Lex->lock_option))
 
4710
              DRIZZLE_YYABORT;
 
4711
          }
 
4712
        | ident '.' ident opt_wild
 
4713
          {
 
4714
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4715
                    new Table_ident(YYSession, $1, $3, 0), NULL,
 
4716
                    TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4717
                    Lex->lock_option))
 
4718
              DRIZZLE_YYABORT;
 
4719
          }
 
4720
        ;
 
4721
 
 
4722
opt_wild:
 
4723
          /* empty */ {}
 
4724
        | '.' '*' {}
4316
4725
        ;
4317
4726
 
4318
4727
opt_delete_options:
4321
4730
        ;
4322
4731
 
4323
4732
opt_delete_option:
4324
 
         IGNORE_SYM   { Lex->ignore= 1; }
 
4733
          QUICK        { Lex->current_select->options|= OPTION_QUICK; }
 
4734
        | IGNORE_SYM   { Lex->ignore= 1; }
4325
4735
        ;
4326
4736
 
4327
4737
truncate:
4328
4738
          TRUNCATE_SYM opt_table_sym table_name
4329
4739
          {
4330
 
            Lex->statement= new statement::Truncate(YYSession);
4331
 
            Lex->select_lex.options= 0;
4332
 
            Lex->select_lex.init_order();
 
4740
            LEX* lex= Lex;
 
4741
            lex->sql_command= SQLCOM_TRUNCATE;
 
4742
            lex->select_lex.options= 0;
 
4743
            lex->select_lex.init_order();
4333
4744
          }
4334
4745
        ;
4335
4746
 
4343
4754
show:
4344
4755
          SHOW
4345
4756
          {
4346
 
            Lex->lock_option= TL_READ;
4347
 
            init_select(Lex);
4348
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4757
            LEX *lex=Lex;
 
4758
            lex->wild=0;
 
4759
            lex->lock_option= TL_READ;
 
4760
            mysql_init_select(lex);
 
4761
            lex->current_select->parsing_place= SELECT_LIST;
 
4762
            memset(&lex->create_info, 0, sizeof(lex->create_info));
4349
4763
          }
4350
4764
          show_param
4351
4765
          {}
4352
4766
        ;
4353
4767
 
4354
 
/* SHOW SCHEMAS */
4355
4768
show_param:
4356
4769
           DATABASES show_wild
4357
4770
           {
4358
 
             if (not show::buildScemas(YYSession))
4359
 
               DRIZZLE_YYABORT;
4360
 
           }
4361
 
           /* SHOW TABLES */
4362
 
         | TABLES opt_db show_wild
4363
 
           {
4364
 
             if (not show::buildTables(YYSession, $2))
4365
 
               DRIZZLE_YYABORT;
4366
 
           }
4367
 
           /* SHOW TEMPORARY TABLES */
4368
 
         | TEMPORARY_SYM TABLES show_wild
4369
 
           {
4370
 
             if (not show::buildTemporaryTables(YYSession))
4371
 
               DRIZZLE_YYABORT;
4372
 
           }
4373
 
           /* SHOW TABLE STATUS */
 
4771
             LEX *lex= Lex;
 
4772
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
4773
             lex->command=
 
4774
               new(YYSession->mem_root) command::Select(SQLCOM_SHOW_DATABASES, 
 
4775
                                                 YYSession);
 
4776
             if (lex->command == NULL)
 
4777
               DRIZZLE_YYABORT;
 
4778
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
 
4779
               DRIZZLE_YYABORT;
 
4780
           }
 
4781
         | opt_full TABLES opt_db show_wild
 
4782
           {
 
4783
             LEX *lex= Lex;
 
4784
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4785
             lex->command=
 
4786
               new(YYSession->mem_root) command::Select(SQLCOM_SHOW_TABLES,
 
4787
                                                 YYSession);
 
4788
             if (lex->command == NULL)
 
4789
               DRIZZLE_YYABORT;
 
4790
             lex->select_lex.db= $3;
 
4791
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
 
4792
               DRIZZLE_YYABORT;
 
4793
           }
4374
4794
         | TABLE_SYM STATUS_SYM opt_db show_wild
4375
4795
           {
4376
 
             if (not show::buildTableStatus(YYSession, $3))
4377
 
               DRIZZLE_YYABORT;
4378
 
           }
4379
 
           /* SHOW COLUMNS FROM table_name */
4380
 
        | COLUMNS from_or_in table_ident opt_db show_wild
4381
 
           {
4382
 
             if (not show::buildColumns(YYSession, $4, $3))
4383
 
               DRIZZLE_YYABORT;
4384
 
           }
4385
 
          /* SHOW INDEXES from table */
 
4796
             LEX *lex= Lex;
 
4797
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4798
             lex->command=
 
4799
               new(YYSession->mem_root) command::Select(SQLCOM_SHOW_TABLE_STATUS,
 
4800
                                                        YYSession);
 
4801
             if (lex->command == NULL)
 
4802
               DRIZZLE_YYABORT;
 
4803
             lex->select_lex.db= $3;
 
4804
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
 
4805
               DRIZZLE_YYABORT;
 
4806
           }
 
4807
        | OPEN_SYM TABLES opt_db show_wild
 
4808
          {
 
4809
            LEX *lex= Lex;
 
4810
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
4811
            lex->command=
 
4812
              new(YYSession->mem_root) command::Select(SQLCOM_SHOW_OPEN_TABLES,
 
4813
                                                YYSession);
 
4814
            if (lex->command == NULL)
 
4815
              DRIZZLE_YYABORT;
 
4816
            lex->select_lex.db= $3;
 
4817
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
 
4818
              DRIZZLE_YYABORT;
 
4819
          }
 
4820
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
 
4821
          { 
 
4822
            Lex->show_engine= $2; 
 
4823
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
 
4824
          }
 
4825
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
 
4826
          {
 
4827
            LEX *lex= Lex;
 
4828
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4829
            lex->command=
 
4830
              new(YYSession->mem_root) command::Select(SQLCOM_SHOW_FIELDS, YYSession);
 
4831
            if (lex->command == NULL)
 
4832
              DRIZZLE_YYABORT;
 
4833
            if ($5)
 
4834
              $4->change_db($5);
 
4835
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
 
4836
              DRIZZLE_YYABORT;
 
4837
          }
4386
4838
        | keys_or_index from_or_in table_ident opt_db where_clause
4387
 
           {
4388
 
             if (not show::buildIndex(YYSession, $4, $3))
4389
 
               DRIZZLE_YYABORT;
4390
 
           }
 
4839
          {
 
4840
            LEX *lex= Lex;
 
4841
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
4842
            lex->command= new(YYSession->mem_root) command::Select(SQLCOM_SHOW_KEYS,
 
4843
                                                            YYSession);
 
4844
            if (lex->command == NULL)
 
4845
              DRIZZLE_YYABORT;
 
4846
            if ($4)
 
4847
              $3->change_db($4);
 
4848
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
 
4849
              DRIZZLE_YYABORT;
 
4850
          }
4391
4851
        | COUNT_SYM '(' '*' ')' WARNINGS
4392
 
          {
4393
 
            show::buildSelectWarning(YYSession);
 
4852
          { 
 
4853
            (void) create_select_for_variable("warning_count"); 
 
4854
            LEX *lex= Lex;
 
4855
            lex->command= new(YYSession->mem_root) command::Select(SQLCOM_SELECT,
 
4856
                                                            YYSession);
 
4857
            if (lex->command == NULL)
 
4858
              DRIZZLE_YYABORT;
4394
4859
          }
4395
4860
        | COUNT_SYM '(' '*' ')' ERRORS
4396
 
          {
4397
 
            show::buildSelectError(YYSession);
 
4861
          { 
 
4862
            (void) create_select_for_variable("error_count"); 
 
4863
            LEX *lex= Lex;
 
4864
            lex->command= new(YYSession->mem_root) command::Select(SQLCOM_SELECT,
 
4865
                                                            YYSession);
 
4866
            if (lex->command == NULL)
 
4867
              DRIZZLE_YYABORT;
4398
4868
          }
4399
4869
        | WARNINGS opt_limit_clause_init
4400
 
          {
4401
 
            show::buildWarnings(YYSession);
4402
 
          }
 
4870
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4403
4871
        | ERRORS opt_limit_clause_init
4404
 
          {
4405
 
            show::buildErrors(YYSession);
4406
 
          }
 
4872
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
4407
4873
        | opt_var_type STATUS_SYM show_wild
4408
4874
          {
4409
 
            if (not show::buildStatus(YYSession, $1))
4410
 
              DRIZZLE_YYABORT;
4411
 
          }
4412
 
        | engine_option_value STATUS_SYM
4413
 
          {
4414
 
            if (not show::buildEngineStatus(YYSession, $1))
4415
 
              DRIZZLE_YYABORT;
 
4875
            LEX *lex= Lex;
 
4876
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
4877
            lex->command=
 
4878
              new(YYSession->mem_root) command::ShowStatus(SQLCOM_SHOW_STATUS,
 
4879
                                                    YYSession,
 
4880
                                                    &LOCK_status);
 
4881
            if (lex->command == NULL)
 
4882
              DRIZZLE_YYABORT;
 
4883
            lex->option_type= $1;
 
4884
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
 
4885
              DRIZZLE_YYABORT;
 
4886
          }
 
4887
        | opt_full PROCESSLIST_SYM
 
4888
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
 
4889
        | opt_var_type  VARIABLES show_wild
 
4890
          {
 
4891
            LEX *lex= Lex;
 
4892
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
4893
            lex->command=
 
4894
              new(YYSession->mem_root) command::Select(SQLCOM_SHOW_VARIABLES, 
 
4895
                                                YYSession);
 
4896
            if (lex->command == NULL)
 
4897
              DRIZZLE_YYABORT;
 
4898
            lex->option_type= $1;
 
4899
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
 
4900
              DRIZZLE_YYABORT;
 
4901
          }
 
4902
        | CREATE DATABASE opt_if_not_exists ident
 
4903
          {
 
4904
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
 
4905
            Lex->create_info.options=$3;
 
4906
            Lex->name= $4;
4416
4907
          }
4417
4908
        | CREATE TABLE_SYM table_ident
4418
4909
          {
4419
 
            if (not show::buildCreateTable(YYSession, $3))
4420
 
              DRIZZLE_YYABORT;
4421
 
          }
4422
 
        | PROCESSLIST_SYM
4423
 
          {
4424
 
            if (not show::buildProcesslist(YYSession))
4425
 
              DRIZZLE_YYABORT;
4426
 
          }
4427
 
        | opt_var_type  VARIABLES show_wild
4428
 
          {
4429
 
            if (not show::buildVariables(YYSession, $1))
4430
 
              DRIZZLE_YYABORT;
4431
 
          }
4432
 
        | CREATE DATABASE opt_if_not_exists ident
4433
 
          {
4434
 
            if (not show::buildCreateSchema(YYSession, $4))
 
4910
            LEX *lex= Lex;
 
4911
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
4912
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4435
4913
              DRIZZLE_YYABORT;
4436
4914
          }
4437
4915
 
4440
4918
        | from_or_in ident { $$= $2.str; }
4441
4919
        ;
4442
4920
 
 
4921
opt_full:
 
4922
          /* empty */ { Lex->verbose=0; }
 
4923
        | FULL        { Lex->verbose=1; }
 
4924
        ;
 
4925
 
4443
4926
from_or_in:
4444
4927
          FROM
4445
4928
        | IN_SYM
4466
4949
describe:
4467
4950
          describe_command table_ident
4468
4951
          {
4469
 
            if (not show::buildDescribe(YYSession, $2))
4470
 
            {
 
4952
            LEX *lex= Lex;
 
4953
            lex->lock_option= TL_READ;
 
4954
            mysql_init_select(lex);
 
4955
            lex->current_select->parsing_place= SELECT_LIST;
 
4956
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4957
            lex->select_lex.db= 0;
 
4958
            lex->verbose= 0;
 
4959
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
4471
4960
              DRIZZLE_YYABORT;
4472
 
            }
4473
4961
          }
4474
4962
          opt_describe_column {}
4475
4963
        | describe_command opt_extended_describe
4476
4964
          { Lex->describe|= DESCRIBE_NORMAL; }
4477
4965
          select
4478
4966
          {
4479
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
4967
            LEX *lex=Lex;
 
4968
            lex->select_lex.options|= SELECT_DESCRIBE;
4480
4969
          }
4481
4970
        ;
4482
4971
 
4507
4996
flush:
4508
4997
          FLUSH_SYM
4509
4998
          {
4510
 
            Lex->statement= new statement::Flush(YYSession);
 
4999
            LEX *lex=Lex;
 
5000
            lex->sql_command= SQLCOM_FLUSH;
 
5001
            lex->type= 0;
4511
5002
          }
4512
5003
          flush_options
4513
5004
          {}
4520
5011
 
4521
5012
flush_option:
4522
5013
          table_or_tables
4523
 
          {
4524
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4525
 
            statement->setFlushTables(true);
4526
 
          }
 
5014
          { Lex->type|= REFRESH_TABLES; }
4527
5015
          opt_table_list {}
4528
5016
        | TABLES WITH READ_SYM LOCK_SYM
4529
 
          {
4530
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4531
 
            statement->setFlushTablesWithReadLock(true);
4532
 
          }
 
5017
          { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
4533
5018
        | LOGS_SYM
4534
 
          {
4535
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4536
 
            statement->setFlushLog(true);
4537
 
          }
 
5019
          { Lex->type|= REFRESH_LOG; }
4538
5020
        | STATUS_SYM
4539
 
          {
4540
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4541
 
            statement->setFlushStatus(true);
4542
 
          }
4543
 
        | GLOBAL_SYM STATUS_SYM
4544
 
          {
4545
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4546
 
            statement->setFlushGlobalStatus(true);
4547
 
          }
 
5021
          { Lex->type|= REFRESH_STATUS; }
4548
5022
        ;
4549
5023
 
4550
5024
opt_table_list:
4557
5031
kill:
4558
5032
          KILL_SYM kill_option expr
4559
5033
          {
4560
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5034
            LEX *lex=Lex;
 
5035
            lex->value_list.empty();
 
5036
            lex->value_list.push_front($3);
 
5037
            lex->sql_command= SQLCOM_KILL;
4561
5038
          }
4562
5039
        ;
4563
5040
 
4564
5041
kill_option:
4565
 
          /* empty */ { $$= false; }
4566
 
        | CONNECTION_SYM { $$= false; }
4567
 
        | QUERY_SYM      { $$= true; }
 
5042
          /* empty */ { Lex->type= 0; }
 
5043
        | CONNECTION_SYM { Lex->type= 0; }
 
5044
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
4568
5045
        ;
4569
5046
 
4570
5047
/* change database */
4571
5048
 
4572
5049
use:
4573
 
          USE_SYM schema_name
 
5050
          USE_SYM ident
4574
5051
          {
4575
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4576
 
            Lex->select_lex.db= $2.str;
 
5052
            LEX *lex=Lex;
 
5053
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5054
            lex->select_lex.db= $2.str;
4577
5055
          }
4578
5056
        ;
4579
5057
 
4582
5060
load:
4583
5061
          LOAD data_file
4584
5062
          {
4585
 
            statement::Load *statement= new statement::Load(YYSession);
4586
 
            Lex->statement= statement;
 
5063
            Session *session= YYSession;
 
5064
            LEX *lex= session->lex;
 
5065
            Lex_input_stream *lip= session->m_lip;
4587
5066
 
4588
 
            Lex_input_stream *lip= YYSession->m_lip;
4589
 
            statement->fname_start= lip->get_ptr();
 
5067
            lex->fname_start= lip->get_ptr();
4590
5068
          }
4591
5069
          load_data_lock INFILE TEXT_STRING_filesystem
4592
5070
          {
4593
 
            Lex->lock_option= $4;
4594
 
            Lex->duplicates= DUP_ERROR;
4595
 
            Lex->ignore= 0;
4596
 
            if (not (Lex->exchange= new file_exchange($6.str, 0, $2)))
 
5071
            LEX *lex=Lex;
 
5072
            lex->sql_command= SQLCOM_LOAD;
 
5073
            lex->lock_option= $4;
 
5074
            lex->duplicates= DUP_ERROR;
 
5075
            lex->ignore= 0;
 
5076
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
4597
5077
              DRIZZLE_YYABORT;
4598
5078
          }
4599
5079
          opt_duplicate INTO
4600
5080
          {
4601
 
            Lex_input_stream *lip= YYSession->m_lip;
4602
 
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
 
5081
            Session *session= YYSession;
 
5082
            LEX *lex= session->lex;
 
5083
            Lex_input_stream *lip= session->m_lip;
 
5084
            lex->fname_end= lip->get_ptr();
4603
5085
          }
4604
5086
          TABLE_SYM table_ident
4605
5087
          {
 
5088
            LEX *lex=Lex;
4606
5089
            if (!Lex->current_select->add_table_to_list(YYSession,
4607
5090
                    $12, NULL, TL_OPTION_UPDATING,
4608
 
                    Lex->lock_option))
 
5091
                    lex->lock_option))
4609
5092
              DRIZZLE_YYABORT;
4610
 
            Lex->field_list.empty();
4611
 
            Lex->update_list.empty();
4612
 
            Lex->value_list.empty();
 
5093
            lex->field_list.empty();
 
5094
            lex->update_list.empty();
 
5095
            lex->value_list.empty();
4613
5096
          }
4614
5097
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4615
5098
          opt_load_data_set_spec
4633
5116
        | IGNORE_SYM { Lex->ignore= 1; }
4634
5117
        ;
4635
5118
 
4636
 
opt_duplicate_as:
4637
 
          /* empty */ { Lex->duplicates=DUP_ERROR; }
4638
 
        | AS { Lex->duplicates=DUP_ERROR; }
4639
 
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
4640
 
        | IGNORE_SYM { Lex->ignore= true; }
4641
 
        | REPLACE AS { Lex->duplicates=DUP_REPLACE; }
4642
 
        | IGNORE_SYM AS { Lex->ignore= true; }
4643
 
        ;
4644
 
 
4645
5119
opt_field_term:
4646
5120
          /* empty */
4647
5121
        | COLUMNS field_term_list
4653
5127
        ;
4654
5128
 
4655
5129
field_term:
4656
 
          TERMINATED BY text_string
 
5130
          TERMINATED BY text_string 
4657
5131
          {
4658
5132
            assert(Lex->exchange != 0);
4659
5133
            Lex->exchange->field_term= $3;
4660
5134
          }
4661
5135
        | OPTIONALLY ENCLOSED BY text_string
4662
5136
          {
4663
 
            assert(Lex->exchange != 0);
4664
 
            Lex->exchange->enclosed= $4;
4665
 
            Lex->exchange->opt_enclosed= 1;
 
5137
            LEX *lex= Lex;
 
5138
            assert(lex->exchange != 0);
 
5139
            lex->exchange->enclosed= $4;
 
5140
            lex->exchange->opt_enclosed= 1;
4666
5141
          }
4667
5142
        | ENCLOSED BY text_string
4668
5143
          {
4727
5202
        ;
4728
5203
 
4729
5204
field_or_var:
4730
 
          simple_ident {$$= $1;}
4731
 
        | '@' user_variable_ident
 
5205
          simple_ident_nospvar {$$= $1;}
 
5206
        | '@' ident_or_text
4732
5207
          { $$= new Item_user_var_as_out_param($2); }
4733
5208
        ;
4734
5209
 
4735
5210
opt_load_data_set_spec:
4736
5211
          /* empty */ {}
4737
 
        | SET_SYM insert_update_list {}
 
5212
        | SET insert_update_list {}
4738
5213
        ;
4739
5214
 
4740
5215
/* Common definitions */
4742
5217
text_literal:
4743
5218
        TEXT_STRING_literal
4744
5219
        {
4745
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
5220
          Session *session= YYSession;
 
5221
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
4746
5222
        }
4747
5223
        | text_literal TEXT_STRING_literal
4748
 
          {
4749
 
            ((Item_string*) $1)->append($2.str, $2.length);
 
5224
          { 
 
5225
            ((Item_string*) $1)->append($2.str, $2.length); 
4750
5226
          }
4751
5227
        ;
4752
5228
 
4798
5274
            $$ = new Item_null();
4799
5275
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4800
5276
          }
4801
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4802
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5277
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5278
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4803
5279
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4804
5280
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
4805
5281
        | DATE_SYM text_literal { $$ = $2; }
4810
5286
          NUM
4811
5287
          {
4812
5288
            int error;
4813
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5289
            $$ = new Item_int($1.str, (int64_t) my_strtoll10($1.str, NULL, &error), $1.length);
4814
5290
          }
4815
5291
        | LONG_NUM
4816
5292
          {
4817
5293
            int error;
4818
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5294
            $$ = new Item_int($1.str, (int64_t) my_strtoll10($1.str, NULL, &error), $1.length);
4819
5295
          }
4820
5296
        | ULONGLONG_NUM
4821
5297
          { $$ = new Item_uint($1.str, $1.length); }
4842
5318
**********************************************************************/
4843
5319
 
4844
5320
insert_ident:
4845
 
          simple_ident { $$=$1; }
 
5321
          simple_ident_nospvar { $$=$1; }
4846
5322
        | table_wild { $$=$1; }
4847
5323
        ;
4848
5324
 
4849
5325
table_wild:
4850
5326
          ident '.' '*'
4851
5327
          {
4852
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5328
            Select_Lex *sel= Lex->current_select;
 
5329
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5330
            sel->with_wild++;
4853
5331
          }
4854
5332
        | ident '.' ident '.' '*'
4855
5333
          {
4856
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5334
            Select_Lex *sel= Lex->current_select;
 
5335
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
 
5336
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
 
5337
                                $3.str,"*");
 
5338
            sel->with_wild++;
4857
5339
          }
4858
5340
        ;
4859
5341
 
4864
5346
simple_ident:
4865
5347
          ident
4866
5348
          {
4867
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5349
            {
 
5350
              Select_Lex *sel=Lex->current_select;
 
5351
              $$= (sel->parsing_place != IN_HAVING ||
 
5352
                  sel->get_in_sum_expr() > 0) ?
 
5353
                  (Item*) new Item_field(Lex->current_context(),
 
5354
                                         (const char *)NULL, NULL, $1.str) :
 
5355
                  (Item*) new Item_ref(Lex->current_context(),
 
5356
                                       (const char *)NULL, NULL, $1.str);
 
5357
            }
 
5358
          }
 
5359
        | simple_ident_q { $$= $1; }
 
5360
        ;
 
5361
 
 
5362
simple_ident_nospvar:
 
5363
          ident
 
5364
          {
 
5365
            Select_Lex *sel=Lex->current_select;
 
5366
            $$= (sel->parsing_place != IN_HAVING ||
 
5367
                sel->get_in_sum_expr() > 0) ?
 
5368
                (Item*) new Item_field(Lex->current_context(),
 
5369
                                       (const char *)NULL, NULL, $1.str) :
 
5370
                (Item*) new Item_ref(Lex->current_context(),
 
5371
                                     (const char *)NULL, NULL, $1.str);
4868
5372
          }
4869
5373
        | simple_ident_q { $$= $1; }
4870
5374
        ;
4872
5376
simple_ident_q:
4873
5377
          ident '.' ident
4874
5378
          {
4875
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5379
            Session *session= YYSession;
 
5380
            LEX *lex= session->lex;
 
5381
 
 
5382
            {
 
5383
              Select_Lex *sel= lex->current_select;
 
5384
              if (sel->no_table_names_allowed)
 
5385
              {
 
5386
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5387
                         MYF(0), $1.str, session->where);
 
5388
              }
 
5389
              $$= (sel->parsing_place != IN_HAVING ||
 
5390
                  sel->get_in_sum_expr() > 0) ?
 
5391
                  (Item*) new Item_field(Lex->current_context(),
 
5392
                                         (const char *)NULL, $1.str, $3.str) :
 
5393
                  (Item*) new Item_ref(Lex->current_context(),
 
5394
                                       (const char *)NULL, $1.str, $3.str);
 
5395
            }
4876
5396
          }
4877
5397
        | '.' ident '.' ident
4878
5398
          {
4879
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5399
            Session *session= YYSession;
 
5400
            LEX *lex= session->lex;
 
5401
            Select_Lex *sel= lex->current_select;
 
5402
            if (sel->no_table_names_allowed)
 
5403
            {
 
5404
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5405
                       MYF(0), $2.str, session->where);
 
5406
            }
 
5407
            $$= (sel->parsing_place != IN_HAVING ||
 
5408
                sel->get_in_sum_expr() > 0) ?
 
5409
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5410
                (Item*) new Item_ref(Lex->current_context(),
 
5411
                                     (const char *)NULL, $2.str, $4.str);
4880
5412
          }
4881
5413
        | ident '.' ident '.' ident
4882
5414
          {
4883
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5415
            Session *session= YYSession;
 
5416
            LEX *lex= session->lex;
 
5417
            Select_Lex *sel= lex->current_select;
 
5418
            if (sel->no_table_names_allowed)
 
5419
            {
 
5420
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5421
                       MYF(0), $3.str, session->where);
 
5422
            }
 
5423
            $$= (sel->parsing_place != IN_HAVING ||
 
5424
                sel->get_in_sum_expr() > 0) ?
 
5425
                (Item*) new Item_field(Lex->current_context(),
 
5426
                                       (YYSession->client_capabilities &
 
5427
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
 
5428
                                       $3.str, $5.str) :
 
5429
                (Item*) new Item_ref(Lex->current_context(),
 
5430
                                     (YYSession->client_capabilities &
 
5431
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
 
5432
                                     $3.str, $5.str);
4884
5433
          }
4885
5434
        ;
4886
5435
 
4887
5436
field_ident:
4888
 
          ident 
4889
 
          {
4890
 
            $$=$1;
4891
 
          }
 
5437
          ident { $$=$1;}
4892
5438
        | ident '.' ident '.' ident
4893
5439
          {
4894
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4895
 
              DRIZZLE_YYABORT;
4896
 
 
 
5440
            TableList *table=
 
5441
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5442
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5443
            {
 
5444
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5445
              DRIZZLE_YYABORT;
 
5446
            }
 
5447
            if (my_strcasecmp(table_alias_charset, $3.str,
 
5448
                              table->table_name))
 
5449
            {
 
5450
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
5451
              DRIZZLE_YYABORT;
 
5452
            }
4897
5453
            $$=$5;
4898
5454
          }
4899
5455
        | ident '.' ident
4900
5456
          {
4901
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5457
            TableList *table=
 
5458
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
 
5459
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
5460
            {
 
5461
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
5462
              DRIZZLE_YYABORT;
4903
 
 
 
5463
            }
4904
5464
            $$=$3;
4905
5465
          }
4906
 
        | '.' ident 
4907
 
          { /* For Delphi */
4908
 
            $$=$2;
4909
 
          }
 
5466
        | '.' ident { $$=$2;} /* For Delphi */
4910
5467
        ;
4911
5468
 
4912
5469
table_ident:
4913
 
          ident
4914
 
          {
4915
 
            $$= new Table_ident($1);
4916
 
          }
4917
 
        | schema_name '.' ident
4918
 
          {
4919
 
            $$=new Table_ident($1,$3);
4920
 
          }
4921
 
        | '.' ident
4922
 
        { /* For Delphi */
4923
 
          $$= new Table_ident($2);
4924
 
        }
4925
 
        ;
4926
 
 
4927
 
schema_name:
4928
 
          ident
4929
 
        ;
4930
 
 
4931
 
catalog_name:
4932
 
          ident
 
5470
          ident { $$=new Table_ident($1); }
 
5471
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
 
5472
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4933
5473
        ;
4934
5474
 
4935
5475
IDENT_sys:
4936
 
          IDENT 
4937
 
          {
4938
 
            $$= $1;
4939
 
          }
 
5476
          IDENT { $$= $1; }
4940
5477
        | IDENT_QUOTED
4941
5478
          {
4942
5479
            const CHARSET_INFO * const cs= system_charset_info;
4979
5516
          IDENT_sys    { $$=$1; }
4980
5517
        | keyword
4981
5518
          {
4982
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
5519
            Session *session= YYSession;
 
5520
            $$.str= session->strmake($1.str, $1.length);
4983
5521
            $$.length= $1.length;
4984
5522
          }
4985
5523
        ;
4986
5524
 
4987
5525
ident_or_text:
4988
 
          IDENT_sys           { $$=$1;}
4989
 
        | TEXT_STRING_sys { $$=$1;}
4990
 
        ;
4991
 
 
4992
 
engine_option_value:
4993
 
          IDENT_sys           { $$=$1;}
4994
 
        | TEXT_STRING_sys { $$=$1;}
4995
 
        ;
4996
 
 
4997
 
keyword_exception_for_variable:
4998
 
          TIMESTAMP_SYM         {}
4999
 
        | SQL_BUFFER_RESULT     {}
5000
 
        | IDENTITY_SYM          {}
 
5526
          ident           { $$=$1;}
 
5527
        | TEXT_STRING_sys { $$=$1;}
 
5528
        | LEX_HOSTNAME { $$=$1;}
5001
5529
        ;
5002
5530
 
5003
5531
/* Keyword that we allow for identifiers (except SP labels) */
5004
5532
keyword:
5005
5533
          keyword_sp            {}
5006
5534
        | BEGIN_SYM             {}
 
5535
        | BYTE_SYM              {}
 
5536
        | CACHE_SYM             {}
 
5537
        | CHARSET               {}
5007
5538
        | CHECKSUM_SYM          {}
5008
5539
        | CLOSE_SYM             {}
5009
5540
        | COMMENT_SYM           {}
5010
5541
        | COMMIT_SYM            {}
5011
5542
        | CONTAINS_SYM          {}
5012
5543
        | DEALLOCATE_SYM        {}
5013
 
        | DO_SYM                {}
5014
5544
        | END                   {}
5015
5545
        | FLUSH_SYM             {}
 
5546
        | HANDLER_SYM           {}
 
5547
        | HOST_SYM              {}
 
5548
        | INSTALL_SYM           {}
5016
5549
        | NO_SYM                {}
5017
5550
        | OPEN_SYM              {}
 
5551
        | OPTIONS_SYM           {}
 
5552
        | PORT_SYM              {}
 
5553
        | REMOVE_SYM            {}
 
5554
        | RESET_SYM             {}
5018
5555
        | ROLLBACK_SYM          {}
5019
5556
        | SAVEPOINT_SYM         {}
5020
5557
        | SECURITY_SYM          {}
5021
5558
        | SERVER_SYM            {}
5022
 
        | SIGNED_SYM            {}
 
5559
        | SOCKET_SYM            {}
 
5560
        | SONAME_SYM            {}
5023
5561
        | START_SYM             {}
5024
5562
        | STOP_SYM              {}
5025
5563
        | TRUNCATE_SYM          {}
5036
5574
        | ADDDATE_SYM              {}
5037
5575
        | AFTER_SYM                {}
5038
5576
        | AGGREGATE_SYM            {}
 
5577
        | ALGORITHM_SYM            {}
5039
5578
        | ANY_SYM                  {}
5040
5579
        | AT_SYM                   {}
5041
5580
        | AUTO_INC                 {}
 
5581
        | AUTOEXTEND_SIZE_SYM      {}
 
5582
        | AVG_ROW_LENGTH           {}
5042
5583
        | AVG_SYM                  {}
 
5584
        | BINLOG_SYM               {}
5043
5585
        | BIT_SYM                  {}
 
5586
        | BLOCK_SIZE_SYM           {}
 
5587
        | BLOCK_SYM                {}
5044
5588
        | BOOL_SYM                 {}
5045
5589
        | BOOLEAN_SYM              {}
5046
5590
        | BTREE_SYM                {}
5047
5591
        | CASCADED                 {}
5048
5592
        | CHAIN_SYM                {}
 
5593
        | CHANGED                  {}
5049
5594
        | COALESCE                 {}
5050
5595
        | COLLATION_SYM            {}
 
5596
        | COLUMN_FORMAT_SYM        {}
5051
5597
        | COLUMNS                  {}
5052
5598
        | COMMITTED_SYM            {}
5053
5599
        | COMPACT_SYM              {}
 
5600
        | COMPLETION_SYM           {}
5054
5601
        | COMPRESSED_SYM           {}
5055
5602
        | CONCURRENT               {}
5056
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
5603
        | CONNECTION_SYM           {}
5057
5604
        | CONSISTENT_SYM           {}
 
5605
        | CONTEXT_SYM              {}
5058
5606
        | CUBE_SYM                 {}
5059
5607
        | DATA_SYM                 {}
5060
 
        | DATABASES                {}
 
5608
        | DATAFILE_SYM             {}
5061
5609
        | DATETIME_SYM             {}
5062
 
        | DATE_SYM                 {} /* Create conflict */
 
5610
        | DATE_SYM                 {}
5063
5611
        | DAY_SYM                  {}
 
5612
        | DELAY_KEY_WRITE_SYM      {}
 
5613
        | DIRECTORY_SYM            {}
5064
5614
        | DISABLE_SYM              {}
5065
5615
        | DISCARD                  {}
5066
5616
        | DUMPFILE                 {}
5073
5623
        | ESCAPE_SYM               {}
5074
5624
        | EXCLUSIVE_SYM            {}
5075
5625
        | EXTENDED_SYM             {}
 
5626
        | EXTENT_SIZE_SYM          {}
 
5627
        | FAULTS_SYM               {}
 
5628
        | FAST_SYM                 {}
5076
5629
        | FOUND_SYM                {}
5077
5630
        | ENABLE_SYM               {}
5078
5631
        | FULL                     {}
5082
5635
        | FRAC_SECOND_SYM          {}
5083
5636
        | GLOBAL_SYM               {}
5084
5637
        | HASH_SYM                 {}
 
5638
        | HOSTS_SYM                {}
5085
5639
        | HOUR_SYM                 {}
5086
5640
        | IDENTIFIED_SYM           {}
5087
5641
        | IMPORT                   {}
5088
5642
        | INDEXES                  {}
 
5643
        | INITIAL_SIZE_SYM         {}
5089
5644
        | ISOLATION                {}
 
5645
        | INSERT_METHOD            {}
5090
5646
        | KEY_BLOCK_SIZE           {}
5091
5647
        | LAST_SYM                 {}
 
5648
        | LEAVES                   {}
5092
5649
        | LEVEL_SYM                {}
 
5650
        | LINESTRING               {}
 
5651
        | LIST_SYM                 {}
5093
5652
        | LOCAL_SYM                {}
5094
5653
        | LOCKS_SYM                {}
 
5654
        | LOGFILE_SYM              {}
5095
5655
        | LOGS_SYM                 {}
 
5656
        | MAX_ROWS                 {}
 
5657
        | MAX_SIZE_SYM             {}
5096
5658
        | MAX_VALUE_SYM            {}
5097
5659
        | MEDIUM_SYM               {}
5098
5660
        | MERGE_SYM                {}
5099
5661
        | MICROSECOND_SYM          {}
 
5662
        | MIGRATE_SYM              {}
5100
5663
        | MINUTE_SYM               {}
 
5664
        | MIN_ROWS                 {}
5101
5665
        | MODIFY_SYM               {}
5102
5666
        | MODE_SYM                 {}
5103
5667
        | MONTH_SYM                {}
5106
5670
        | NATIONAL_SYM             {}
5107
5671
        | NEXT_SYM                 {}
5108
5672
        | NEW_SYM                  {}
 
5673
        | NO_WAIT_SYM              {}
 
5674
        | NODEGROUP_SYM            {}
5109
5675
        | NONE_SYM                 {}
 
5676
        | NOWAIT_SYM               {}
5110
5677
        | OFFLINE_SYM              {}
5111
5678
        | OFFSET_SYM               {}
5112
5679
        | ONE_SHOT_SYM             {}
5113
5680
        | ONE_SYM                  {}
5114
5681
        | ONLINE_SYM               {}
 
5682
        | PACK_KEYS_SYM            {}
 
5683
        | PAGE_SYM                 {}
 
5684
        | PAGE_CHECKSUM_SYM        {}
5115
5685
        | PARTIAL                  {}
 
5686
        | PHASE_SYM                {}
 
5687
        | POINT_SYM                {}
5116
5688
        | PREV_SYM                 {}
5117
5689
        | PROCESS                  {}
5118
5690
        | PROCESSLIST_SYM          {}
5119
5691
        | QUARTER_SYM              {}
5120
 
        | QUERY_SYM                {} // Causes conflict
 
5692
        | QUERY_SYM                {}
 
5693
        | QUICK                    {}
 
5694
        | READ_ONLY_SYM            {}
 
5695
        | REBUILD_SYM              {}
 
5696
        | RECOVER_SYM              {}
 
5697
        | REDO_BUFFER_SIZE_SYM     {}
 
5698
        | REDOFILE_SYM             {}
5121
5699
        | REDUNDANT_SYM            {}
 
5700
        | RELOAD                   {}
 
5701
        | REORGANIZE_SYM           {}
5122
5702
        | REPEATABLE_SYM           {}
 
5703
        | REPLICATION              {}
 
5704
        | RESOURCES                {}
 
5705
        | RESUME_SYM               {}
5123
5706
        | RETURNS_SYM              {}
 
5707
        | REVERSE_SYM              {}
5124
5708
        | ROLLUP_SYM               {}
5125
5709
        | ROUTINE_SYM              {}
5126
5710
        | ROWS_SYM                 {}
5132
5716
        | SESSION_SYM              {}
5133
5717
        | SIMPLE_SYM               {}
5134
5718
        | SHARE_SYM                {}
 
5719
        | SHUTDOWN                 {}
5135
5720
        | SNAPSHOT_SYM             {}
 
5721
        | SOURCE_SYM               {}
 
5722
        | SQL_BUFFER_RESULT        {}
 
5723
        | STARTS_SYM               {}
5136
5724
        | STATUS_SYM               {}
 
5725
        | STORAGE_SYM              {}
5137
5726
        | STRING_SYM               {}
5138
5727
        | SUBDATE_SYM              {}
5139
5728
        | SUBJECT_SYM              {}
 
5729
        | SUPER_SYM                {}
5140
5730
        | SUSPEND_SYM              {}
 
5731
        | SWAPS_SYM                {}
 
5732
        | SWITCHES_SYM             {}
5141
5733
        | TABLES                   {}
 
5734
        | TABLE_CHECKSUM_SYM       {}
5142
5735
        | TABLESPACE               {}
5143
5736
        | TEMPORARY_SYM            {}
 
5737
        | TEMPTABLE_SYM            {}
5144
5738
        | TEXT_SYM                 {}
 
5739
        | THAN_SYM                 {}
5145
5740
        | TRANSACTION_SYM          {}
5146
 
        | TIME_SYM                 {}
 
5741
        | TIMESTAMP_SYM            {}
5147
5742
        | TIMESTAMP_ADD            {}
5148
5743
        | TIMESTAMP_DIFF           {}
 
5744
        | TYPES_SYM                {}
5149
5745
        | TYPE_SYM                 {}
5150
5746
        | UNCOMMITTED_SYM          {}
 
5747
        | UNDEFINED_SYM            {}
5151
5748
        | UNDOFILE_SYM             {}
5152
5749
        | UNKNOWN_SYM              {}
5153
 
        | UUID_SYM                 {}
 
5750
        | UNTIL_SYM                {}
5154
5751
        | USER                     {}
 
5752
        | USE_FRM                  {}
5155
5753
        | VARIABLES                {}
5156
5754
        | VALUE_SYM                {}
5157
5755
        | WARNINGS                 {}
 
5756
        | WAIT_SYM                 {}
5158
5757
        | WEEK_SYM                 {}
 
5758
        | WEIGHT_STRING_SYM        {}
5159
5759
        | WORK_SYM                 {}
5160
5760
        | YEAR_SYM                 {}
5161
5761
        ;
5163
5763
/* Option functions */
5164
5764
 
5165
5765
set:
5166
 
          SET_SYM opt_option
 
5766
          SET opt_option
5167
5767
          {
5168
 
            Lex->statement= new statement::SetOption(YYSession);
 
5768
            LEX *lex=Lex;
 
5769
            lex->sql_command= SQLCOM_SET_OPTION;
 
5770
            mysql_init_select(lex);
 
5771
            lex->option_type=OPT_SESSION;
 
5772
            lex->var_list.empty();
 
5773
            lex->one_shot_set= 0;
5169
5774
          }
5170
5775
          option_value_list
5171
5776
          {}
5182
5787
        ;
5183
5788
 
5184
5789
option_type_value:
5185
 
          { }
 
5790
          {
 
5791
          }
5186
5792
          ext_option_value
5187
 
          { }
 
5793
          {
 
5794
          }
5188
5795
        ;
5189
5796
 
5190
5797
option_type:
5196
5803
 
5197
5804
option_type2:
5198
5805
          /* empty */ { $$= OPT_DEFAULT; }
5199
 
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
 
5806
        | ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
5200
5807
        ;
5201
5808
 
5202
5809
opt_var_type:
5221
5828
sys_option_value:
5222
5829
          option_type internal_variable_name equal set_expr_or_default
5223
5830
          {
 
5831
            LEX *lex=Lex;
 
5832
 
5224
5833
            if ($2.var)
5225
5834
            { /* System variable */
5226
5835
              if ($1)
5227
 
              {
5228
 
                Lex->option_type= $1;
5229
 
              }
5230
 
              Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type, $2.var, &$2.base_name, $4)));
 
5836
                lex->option_type= $1;
 
5837
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
5838
                                      &$2.base_name, $4));
5231
5839
            }
5232
5840
          }
5233
5841
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5234
5842
          {
5235
 
            Lex->option_type= $1;
5236
 
            Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type,
5237
 
                                              find_sys_var("tx_isolation"),
5238
 
                                              &null_lex_str,
5239
 
                                              new Item_int((int32_t)
5240
 
                                              $5))));
 
5843
            LEX *lex=Lex;
 
5844
            lex->option_type= $1;
 
5845
            lex->var_list.push_back(new set_var(lex->option_type,
 
5846
                                                find_sys_var(YYSession, "tx_isolation"),
 
5847
                                                &null_lex_str,
 
5848
                                                new Item_int((int32_t) $5)));
5241
5849
          }
5242
5850
        ;
5243
5851
 
5244
5852
option_value:
5245
 
          '@' user_variable_ident equal expr
 
5853
          '@' ident_or_text equal expr
5246
5854
          {
5247
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
5855
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5248
5856
          }
5249
5857
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5250
5858
          {
5251
 
            Lex->var_list.push_back(SetVarPtr(new set_var($3, $4.var, &$4.base_name, $6)));
5252
 
          }
5253
 
        ;
5254
 
 
5255
 
user_variable_ident:
5256
 
          internal_variable_ident { $$=$1;}
5257
 
        | TEXT_STRING_sys { $$=$1;}
5258
 
        | LEX_HOSTNAME { $$=$1;}
5259
 
        ;
5260
 
 
5261
 
internal_variable_ident:
5262
 
          keyword_exception_for_variable
5263
 
          {
5264
 
            $$.str= YYSession->strmake($1.str, $1.length);
5265
 
            $$.length= $1.length;
5266
 
          }
5267
 
        | IDENT_sys    { $$=$1; }
 
5859
            LEX *lex=Lex;
 
5860
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
5861
          }
5268
5862
        ;
5269
5863
 
5270
5864
internal_variable_name:
5271
 
          internal_variable_ident
 
5865
          ident
5272
5866
          {
 
5867
            Session *session= YYSession;
 
5868
 
5273
5869
            /* We have to lookup here since local vars can shadow sysvars */
5274
5870
            {
5275
5871
              /* Not an SP local variable */
5276
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
5872
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
5277
5873
              if (!tmp)
5278
5874
                DRIZZLE_YYABORT;
5279
5875
              $$.var= tmp;
5280
5876
              $$.base_name= null_lex_str;
5281
5877
            }
5282
5878
          }
 
5879
        | ident '.' ident
 
5880
          {
 
5881
            if (check_reserved_words(&$1))
 
5882
            {
 
5883
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
5884
              DRIZZLE_YYABORT;
 
5885
            }
 
5886
            {
 
5887
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
 
5888
              if (!tmp)
 
5889
                DRIZZLE_YYABORT;
 
5890
              if (!tmp->is_struct())
 
5891
                my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 
5892
              $$.var= tmp;
 
5893
              $$.base_name= $1;
 
5894
            }
 
5895
          }
 
5896
        | DEFAULT '.' ident
 
5897
          {
 
5898
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
 
5899
            if (!tmp)
 
5900
              DRIZZLE_YYABORT;
 
5901
            if (!tmp->is_struct())
 
5902
              my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 
5903
            $$.var= tmp;
 
5904
            $$.base_name.str=    (char*) "default";
 
5905
            $$.base_name.length= 7;
 
5906
          }
5283
5907
        ;
5284
5908
 
5285
5909
isolation_types:
5305
5929
unlock:
5306
5930
          UNLOCK_SYM
5307
5931
          {
5308
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
5932
            LEX *lex= Lex;
 
5933
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
5309
5934
          }
5310
5935
          table_or_tables
5311
5936
          {}
5314
5939
begin:
5315
5940
          BEGIN_SYM
5316
5941
          {
5317
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
5942
            LEX *lex=Lex;
 
5943
            lex->sql_command = SQLCOM_BEGIN;
 
5944
            lex->start_transaction_opt= 0;
5318
5945
          }
5319
5946
          opt_work {}
5320
5947
        ;
5346
5973
commit:
5347
5974
          COMMIT_SYM opt_work opt_chain opt_release
5348
5975
          {
5349
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
5976
            LEX *lex=Lex;
 
5977
            lex->sql_command= SQLCOM_COMMIT;
 
5978
            lex->tx_chain= $3; 
 
5979
            lex->tx_release= $4;
5350
5980
          }
5351
5981
        ;
5352
5982
 
5353
5983
rollback:
5354
5984
          ROLLBACK_SYM opt_work opt_chain opt_release
5355
5985
          {
5356
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
5986
            LEX *lex=Lex;
 
5987
            lex->sql_command= SQLCOM_ROLLBACK;
 
5988
            lex->tx_chain= $3; 
 
5989
            lex->tx_release= $4;
5357
5990
          }
5358
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
5991
        | ROLLBACK_SYM opt_work
 
5992
          TO_SYM opt_savepoint ident
5359
5993
          {
5360
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
5994
            LEX *lex=Lex;
 
5995
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
5996
            lex->ident= $5;
5361
5997
          }
5362
5998
        ;
5363
5999
 
5364
6000
savepoint:
5365
 
          SAVEPOINT_SYM savepoint_ident
 
6001
          SAVEPOINT_SYM ident
5366
6002
          {
5367
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6003
            LEX *lex=Lex;
 
6004
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6005
            lex->ident= $2;
5368
6006
          }
5369
6007
        ;
5370
6008
 
5371
6009
release:
5372
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6010
          RELEASE_SYM SAVEPOINT_SYM ident
5373
6011
          {
5374
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6012
            LEX *lex=Lex;
 
6013
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6014
            lex->ident= $3;
5375
6015
          }
5376
6016
        ;
5377
6017
 
5378
 
savepoint_ident:
5379
 
               IDENT_sys
5380
 
               ;
5381
 
 
5382
6018
/*
5383
6019
   UNIONS : glue selects together
5384
6020
*/
5392
6028
union_list:
5393
6029
          UNION_SYM union_option
5394
6030
          {
5395
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6031
            if (add_select_to_union_list(Lex, (bool)$2))
5396
6032
              DRIZZLE_YYABORT;
5397
6033
          }
5398
6034
          select_init
5413
6049
 
5414
6050
union_order_or_limit:
5415
6051
          {
5416
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5417
 
            Select_Lex *sel= Lex->current_select;
 
6052
            Session *session= YYSession;
 
6053
            LEX *lex= session->lex;
 
6054
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6055
            Select_Lex *sel= lex->current_select;
5418
6056
            Select_Lex_Unit *unit= sel->master_unit();
5419
6057
            Select_Lex *fake= unit->fake_select_lex;
5420
6058
            if (fake)
5421
6059
            {
5422
6060
              unit->global_parameters= fake;
5423
6061
              fake->no_table_names_allowed= 1;
5424
 
              Lex->current_select= fake;
 
6062
              lex->current_select= fake;
5425
6063
            }
5426
 
            YYSession->setWhere("global ORDER clause");
 
6064
            session->where= "global ORDER clause";
5427
6065
          }
5428
6066
          order_or_limit
5429
6067
          {
5430
 
            YYSession->lex->current_select->no_table_names_allowed= 0;
5431
 
            YYSession->setWhere("");
 
6068
            Session *session= YYSession;
 
6069
            session->lex->current_select->no_table_names_allowed= 0;
 
6070
            session->where= "";
5432
6071
          }
5433
6072
        ;
5434
6073
 
5445
6084
 
5446
6085
query_specification:
5447
6086
          SELECT_SYM select_init2_derived
5448
 
          {
 
6087
          { 
5449
6088
            $$= Lex->current_select->master_unit()->first_select();
5450
6089
          }
5451
6090
        | '(' select_paren_derived ')'
5457
6096
query_expression_body:
5458
6097
          query_specification
5459
6098
        | query_expression_body
5460
 
          UNION_SYM union_option
 
6099
          UNION_SYM union_option 
5461
6100
          {
5462
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6101
            if (add_select_to_union_list(Lex, (bool)$3))
5463
6102
              DRIZZLE_YYABORT;
5464
6103
          }
5465
6104
          query_specification
5472
6111
/* Corresponds to <query expression> in the SQL:2003 standard. */
5473
6112
subselect:
5474
6113
          subselect_start query_expression_body subselect_end
5475
 
          {
 
6114
          { 
5476
6115
            $$= $2;
5477
6116
          }
5478
6117
        ;
5479
6118
 
5480
6119
subselect_start:
5481
6120
          {
5482
 
            if (not Lex->expr_allows_subselect)
 
6121
            LEX *lex=Lex;
 
6122
            if (!lex->expr_allows_subselect)
5483
6123
            {
5484
 
              parser::my_parse_error(YYSession->m_lip);
 
6124
              my_parse_error(ER(ER_SYNTAX_ERROR));
5485
6125
              DRIZZLE_YYABORT;
5486
6126
            }
5487
 
            /*
 
6127
            /* 
5488
6128
              we are making a "derived table" for the parenthesis
5489
 
              as we need to have a lex level to fit the union
5490
 
              after the parenthesis, e.g.
5491
 
              (SELECT .. ) UNION ...  becomes
 
6129
              as we need to have a lex level to fit the union 
 
6130
              after the parenthesis, e.g. 
 
6131
              (SELECT .. ) UNION ...  becomes 
5492
6132
              SELECT * FROM ((SELECT ...) UNION ...)
5493
6133
            */
5494
 
            if (new_select(Lex, 1))
 
6134
            if (mysql_new_select(Lex, 1))
5495
6135
              DRIZZLE_YYABORT;
5496
6136
          }
5497
6137
        ;
5498
6138
 
5499
6139
subselect_end:
5500
6140
          {
5501
 
            Lex->pop_context();
5502
 
            Select_Lex *child= Lex->current_select;
5503
 
            Lex->current_select= Lex->current_select->return_after_parsing();
5504
 
            Lex->nest_level--;
5505
 
            Lex->current_select->n_child_sum_items += child->n_sum_items;
 
6141
            LEX *lex=Lex;
 
6142
            lex->pop_context();
 
6143
            Select_Lex *child= lex->current_select;
 
6144
            lex->current_select = lex->current_select->return_after_parsing();
 
6145
            lex->nest_level--;
 
6146
            lex->current_select->n_child_sum_items += child->n_sum_items;
5506
6147
            /*
5507
6148
              A subselect can add fields to an outer select. Reserve space for
5508
6149
              them.
5509
6150
            */
5510
 
            Lex->current_select->select_n_where_fields+=
 
6151
            lex->current_select->select_n_where_fields+=
5511
6152
            child->select_n_where_fields;
5512
6153
          }
5513
6154
        ;