~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-08-17 01:44:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1118.
  • Revision ID: brian@gaz-20090817014423-jxi2qonsumm8mndf
Remove SQL level reference for DELAY (just now done correctly by default in
engine).

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