~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Lee
  • Date: 2009-01-07 22:45:50 UTC
  • mfrom: (772 drizzle)
  • mto: This revision was merged to the branch mainline in revision 777.
  • Revision ID: lbieber@lbieber-desktop-20090107224550-tzjtc8klmv84ppyg
finish enabling tests, remove timezone2, timezone3

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
 
27
27
*/
28
28
#define YYPARSE_PARAM yysession
29
29
#define YYLEX_PARAM yysession
30
 
#define YYSession (static_cast<Session *>(yysession))
 
30
#define YYSession ((Session *)yysession)
31
31
 
32
32
#define YYENABLE_NLS 0
33
33
#define YYLTYPE_IS_TRIVIAL 0
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
#define Select Lex->current_select
 
40
#include <drizzled/server_includes.h>
 
41
#include <drizzled/lex_symbol.h>
 
42
#include <drizzled/function/locate.h>
 
43
#include <drizzled/function/str/char.h>
 
44
#include <drizzled/function/str/collation.h>
 
45
#include <drizzled/function/str/database.h>
 
46
#include <drizzled/function/str/insert.h>
 
47
#include <drizzled/function/str/left.h>
 
48
#include <drizzled/function/str/repeat.h>
 
49
#include <drizzled/function/str/replace.h>
 
50
#include <drizzled/function/str/reverse.h>
 
51
#include <drizzled/function/str/right.h>
 
52
#include <drizzled/function/str/set_collation.h>
 
53
#include <drizzled/function/str/substr.h>
 
54
#include <drizzled/function/str/trim.h>
 
55
#include <drizzled/function/str/user.h>
 
56
#include <drizzled/function/str/weight_string.h>
 
57
 
 
58
#include <drizzled/function/time/add_time.h>
 
59
#include <drizzled/function/time/curdate.h>
 
60
#include <drizzled/function/time/curtime.h>
 
61
#include <drizzled/function/time/date_add_interval.h>
 
62
#include <drizzled/function/time/dayofmonth.h>
 
63
#include <drizzled/function/time/extract.h>
 
64
#include <drizzled/function/time/get_format.h>
 
65
#include <drizzled/function/time/hour.h>
 
66
#include <drizzled/function/time/microsecond.h>
 
67
#include <drizzled/function/time/minute.h>
 
68
#include <drizzled/function/time/month.h>
 
69
#include <drizzled/function/time/now.h>
 
70
#include <drizzled/function/time/quarter.h>
 
71
#include <drizzled/function/time/second.h>
 
72
#include <drizzled/function/time/sysdate_local.h>
 
73
#include <drizzled/function/time/timestamp_diff.h>
 
74
#include <drizzled/function/time/typecast.h>
 
75
#include <drizzled/function/time/week.h>
 
76
#include <drizzled/function/time/year.h>
 
77
 
 
78
#include <drizzled/error.h>
 
79
#include <drizzled/nested_join.h>
 
80
#include <drizzled/sql_parse.h>
 
81
#include <drizzled/item/copy_string.h>
 
82
#include <drizzled/item/cmpfunc.h>
 
83
#include <drizzled/item/uint.h>
 
84
#include <drizzled/item/null.h>
 
85
#include <drizzled/virtual_column_info.h>
 
86
#include <drizzled/session.h>
 
87
#include <drizzled/item/func.h>
 
88
#include <drizzled/sql_base.h>
 
89
#include <drizzled/item/create.h>
 
90
#include <drizzled/item/insert_value.h>
 
91
#include <drizzled/lex_string.h>
 
92
#include <drizzled/function/get_system_var.h>
 
93
 
 
94
class Table_ident;
 
95
class Item;
 
96
class Item_num;
43
97
 
44
98
int yylex(void *yylval, void *yysession);
45
99
 
46
100
#define yyoverflow(A,B,C,D,E,F)               \
47
101
  {                                           \
48
 
    unsigned long val= *(F);                          \
49
 
    if (drizzled::my_yyoverflow((B), (D), &val)) \
 
102
    ulong val= *(F);                          \
 
103
    if (my_yyoverflow((B), (D), &val))        \
50
104
    {                                         \
51
105
      yyerror((char*) (A));                   \
52
106
      return 2;                               \
60
114
#define DRIZZLE_YYABORT                         \
61
115
  do                                          \
62
116
  {                                           \
 
117
    LEX::cleanup_lex_after_parse_error(YYSession);\
63
118
    YYABORT;                                  \
64
119
  } while (0)
65
120
 
66
121
#define DRIZZLE_YYABORT_UNLESS(A)         \
67
122
  if (!(A))                             \
68
123
  {                                     \
69
 
    parser::my_parse_error(YYSession->m_lip);\
 
124
    my_parse_error(ER(ER_SYNTAX_ERROR));\
70
125
    DRIZZLE_YYABORT;                      \
71
126
  }
72
127
 
 
128
/*
 
129
  Work around for broken code generated by bison 1.875.
 
130
 
 
131
  The code generated by bison 1.875a and later, bison 2.1 and bison 2.2 is ok.
 
132
  With bison 1.875 however, the generated code contains:
 
133
<pre>
 
134
  yyerrlab1:
 
135
  #if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
 
136
    __attribute__ ((__unused__))
 
137
  #endif
 
138
</pre>
 
139
  This usage of __attribute__ is illegal, so we remove it.
 
140
  See the following references for details:
 
141
  http://lists.gnu.org/archive/html/bug-bison/2004-02/msg00014.html
 
142
  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14273
 
143
*/
 
144
 
 
145
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
 
146
#undef __attribute__
 
147
#define __attribute__(X)
 
148
#endif
73
149
 
74
150
#define YYDEBUG 0
75
151
 
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;
 
152
/**
 
153
  @brief Push an error message into MySQL error stack with line
 
154
  and position information.
 
155
 
 
156
  This function provides semantic action implementers with a way
 
157
  to push the famous "You have a syntax error near..." error
 
158
  message into the error stack, which is normally produced only if
 
159
  a parse error is discovered internally by the Bison generated
 
160
  parser.
 
161
*/
 
162
 
 
163
void my_parse_error(const char *s)
 
164
{
 
165
  Session *session= current_session;
 
166
  Lex_input_stream *lip= session->m_lip;
 
167
 
 
168
  const char *yytext= lip->get_tok_start();
 
169
  /* Push an error into the error stack */
 
170
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
171
                  (yytext ? yytext : ""),
 
172
                  lip->yylineno);
88
173
}
89
174
 
90
 
 
91
175
/**
92
176
  @brief Bison callback to report a syntax/OOM error
93
177
 
102
186
  The parser will abort immediately after invoking this callback.
103
187
 
104
188
  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
 
189
  the parser, as it performs some pre-return cleanup. 
 
190
  In semantic actions, please use my_parse_error or my_error to
107
191
  push an error into the error stack and DRIZZLE_YYABORT
108
192
  to abort from the parser.
109
193
*/
110
194
 
111
 
static void DRIZZLEerror(const char *s)
112
 
{
113
 
  parser::errorOn(s);
114
 
}
115
 
 
116
 
} /* namespace drizzled; */
117
 
 
118
 
using namespace drizzled;
 
195
void DRIZZLEerror(const char *s)
 
196
{
 
197
  Session *session= current_session;
 
198
 
 
199
  /*
 
200
    Restore the original LEX if it was replaced when parsing
 
201
    a stored procedure. We must ensure that a parsing error
 
202
    does not leave any side effects in the Session.
 
203
  */
 
204
  LEX::cleanup_lex_after_parse_error(session);
 
205
 
 
206
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
207
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
208
    s= ER(ER_SYNTAX_ERROR);
 
209
  my_parse_error(s);
 
210
}
 
211
 
 
212
/**
 
213
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
214
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
215
  This function returns the proper item for the SQL expression
 
216
  <code>left [NOT] IN ( expr )</code>
 
217
  @param session the current thread
 
218
  @param left the in predicand
 
219
  @param equal true for IN predicates, false for NOT IN predicates
 
220
  @param expr first and only expression of the in value list
 
221
  @return an expression representing the IN predicate.
 
222
*/
 
223
Item* handle_sql2003_note184_exception(Session *session, Item* left, bool equal,
 
224
                                       Item *expr)
 
225
{
 
226
  /*
 
227
    Relevant references for this issue:
 
228
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
229
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
230
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
231
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
232
    - SQL:2003 Feature F561, "Full value expressions".
 
233
 
 
234
    The exception in SQL:2003 Note 184 means:
 
235
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
236
    should be re-interpreted as an Item_in_subselect, which corresponds
 
237
    to a <table subquery> when used inside an <in predicate>.
 
238
 
 
239
    Our reading of Note 184 is reccursive, so that all:
 
240
    - IN (( <subquery> ))
 
241
    - IN ((( <subquery> )))
 
242
    - IN '('^N <subquery> ')'^N
 
243
    - etc
 
244
    should be interpreted as a <table subquery>, no matter how deep in the
 
245
    expression the <subquery> is.
 
246
  */
 
247
 
 
248
  Item *result;
 
249
 
 
250
  if (expr->type() == Item::SUBSELECT_ITEM)
 
251
  {
 
252
    Item_subselect *expr2 = (Item_subselect*) expr;
 
253
 
 
254
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
255
    {
 
256
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
257
      st_select_lex *subselect;
 
258
 
 
259
      /*
 
260
        Implement the mandated change, by altering the semantic tree:
 
261
          left IN Item_singlerow_subselect(subselect)
 
262
        is modified to
 
263
          left IN (subselect)
 
264
        which is represented as
 
265
          Item_in_subselect(left, subselect)
 
266
      */
 
267
      subselect= expr3->invalidate_and_restore_select_lex();
 
268
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
269
 
 
270
      if (! equal)
 
271
        result = negate_expression(session, result);
 
272
 
 
273
      return(result);
 
274
    }
 
275
  }
 
276
 
 
277
  if (equal)
 
278
    result= new (session->mem_root) Item_func_eq(left, expr);
 
279
  else
 
280
    result= new (session->mem_root) Item_func_ne(left, expr);
 
281
 
 
282
  return(result);
 
283
}
 
284
 
 
285
/**
 
286
   @brief Creates a new SELECT_LEX for a UNION branch.
 
287
 
 
288
   Sets up and initializes a SELECT_LEX structure for a query once the parser
 
289
   discovers a UNION token. The current SELECT_LEX is pushed on the stack and
 
290
   the new SELECT_LEX becomes the current one..=
 
291
 
 
292
   @lex The parser state.
 
293
 
 
294
   @is_union_distinct True if the union preceding the new select statement
 
295
   uses UNION DISTINCT.
 
296
 
 
297
   @return <code>false</code> if successful, <code>true</code> if an error was
 
298
   reported. In the latter case parsing should stop.
 
299
 */
 
300
bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
301
{
 
302
  if (lex->result)
 
303
  {
 
304
    /* Only the last SELECT can have  INTO...... */
 
305
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
306
    return true;
 
307
  }
 
308
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
309
  {
 
310
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
311
    return true;
 
312
  }
 
313
  /* This counter shouldn't be incremented for UNION parts */
 
314
  lex->nest_level--;
 
315
  if (mysql_new_select(lex, 0))
 
316
    return true;
 
317
  mysql_init_select(lex);
 
318
  lex->current_select->linkage=UNION_TYPE;
 
319
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
320
    lex->current_select->master_unit()->union_distinct=
 
321
      lex->current_select;
 
322
  return false;
 
323
}
 
324
 
 
325
/**
 
326
   @brief Initializes a SELECT_LEX for a query within parentheses (aka
 
327
   braces).
 
328
 
 
329
   @return false if successful, true if an error was reported. In the latter
 
330
   case parsing should stop.
 
331
 */
 
332
bool setup_select_in_parentheses(LEX *lex) 
 
333
{
 
334
  SELECT_LEX * sel= lex->current_select;
 
335
  if (sel->set_braces(1))
 
336
  {
 
337
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
338
    return true;
 
339
  }
 
340
  if (sel->linkage == UNION_TYPE &&
 
341
      !sel->master_unit()->first_select()->braces &&
 
342
      sel->master_unit()->first_select()->linkage ==
 
343
      UNION_TYPE)
 
344
  {
 
345
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
346
    return true;
 
347
  }
 
348
  if (sel->linkage == UNION_TYPE &&
 
349
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
350
      sel->master_unit()->fake_select_lex)
 
351
  {
 
352
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
353
    return true;
 
354
  }
 
355
  /* select in braces, can't contain global parameters */
 
356
  if (sel->master_unit()->fake_select_lex)
 
357
    sel->master_unit()->global_parameters=
 
358
      sel->master_unit()->fake_select_lex;
 
359
  return false;
 
360
}
 
361
 
119
362
%}
120
363
%union {
121
 
  bool boolean;
122
364
  int  num;
123
 
  unsigned long ulong_num;
 
365
  ulong ulong_num;
124
366
  uint64_t ulonglong_number;
125
367
  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;
 
368
  LEX_STRING lex_str;
 
369
  LEX_STRING *lex_str_ptr;
 
370
  LEX_SYMBOL symbol;
 
371
  Table_ident *table;
130
372
  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;
 
373
  Item *item;
 
374
  Item_num *item_num;
 
375
  List<Item> *item_list;
 
376
  List<String> *string_list;
 
377
  String *string;
 
378
  Key_part_spec *key_part;
 
379
  TableList *table_list;
 
380
  udf_func *udf;
 
381
  LEX_USER *lex_user;
 
382
  struct sys_var_with_base variable;
 
383
  enum enum_var_type var_type;
 
384
  Key::Keytype key_type;
 
385
  enum ha_key_alg key_alg;
 
386
  handlerton *db_type;
 
387
  enum row_type row_type;
 
388
  enum column_format_type column_format_type;
 
389
  enum ha_rkey_function ha_rkey_mode;
 
390
  enum enum_tx_isolation tx_isolation;
 
391
  enum Cast_target cast_type;
 
392
  enum ha_choice choice;
 
393
  const CHARSET_INFO *charset;
 
394
  thr_lock_type lock_type;
 
395
  struct st_table_lock_info table_lock_info;
 
396
  interval_type interval, interval_time_st;
 
397
  enum enum_drizzle_timestamp_type date_time_type;
 
398
  st_select_lex *select_lex;
 
399
  chooser_compare_func_creator boolfunc2creator;
 
400
  struct sp_cond_type *spcondtype;
 
401
  struct { int vars, conds, hndlrs, curs; } spblock;
 
402
  struct st_lex *lex;
 
403
  struct p_elem_val *p_elem_value;
 
404
  enum index_hint_type index_hint;
 
405
  enum enum_filetype filetype;
 
406
  enum ha_build_method build_method;
 
407
  enum Foreign_key::fk_option m_fk_option;
159
408
}
160
409
 
161
410
%{
162
 
namespace drizzled
163
 
{
164
 
bool my_yyoverflow(short **a, YYSTYPE **b, unsigned long *yystacksize);
165
 
}
 
411
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
166
412
%}
167
413
 
168
 
%debug
169
414
%pure_parser                                    /* We have threads */
170
 
 
171
415
/*
172
 
  Currently there are 70 shift/reduce conflicts.
 
416
  Currently there are 92 shift/reduce conflicts.
173
417
  We should not introduce new conflicts any more.
174
418
*/
175
 
%expect 70
 
419
%expect 92
176
420
 
177
421
/*
178
422
   Comments for TOKENS.
192
436
*/
193
437
 
194
438
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
 
439
%token  ACCESSIBLE_SYM
195
440
%token  ACTION                        /* SQL-2003-N */
196
 
%token  ADD_SYM                           /* SQL-2003-R */
 
441
%token  ADD                           /* SQL-2003-R */
197
442
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
198
443
%token  AFTER_SYM                     /* SQL-2003-N */
199
444
%token  AGGREGATE_SYM
 
445
%token  ALGORITHM_SYM
200
446
%token  ALL                           /* SQL-2003-R */
201
 
%token  ALTER_SYM                         /* SQL-2003-R */
 
447
%token  ALTER                         /* SQL-2003-R */
202
448
%token  ANALYZE_SYM
203
449
%token  AND_SYM                       /* SQL-2003-R */
204
450
%token  ANY_SYM                       /* SQL-2003-R */
205
451
%token  AS                            /* SQL-2003-R */
206
452
%token  ASC                           /* SQL-2003-N */
 
453
%token  ASCII_SYM                     /* MYSQL-FUNC */
207
454
%token  ASENSITIVE_SYM                /* FUTURE-USE */
208
455
%token  AT_SYM                        /* SQL-2003-R */
 
456
%token  AUTOEXTEND_SIZE_SYM
209
457
%token  AUTO_INC
 
458
%token  AVG_ROW_LENGTH
210
459
%token  AVG_SYM                       /* SQL-2003-N */
211
460
%token  BEFORE_SYM                    /* SQL-2003-N */
212
461
%token  BEGIN_SYM                     /* SQL-2003-R */
213
462
%token  BETWEEN_SYM                   /* SQL-2003-R */
214
 
%token  BIGINT_SYM                    /* SQL-2003-R */
 
463
%token  BIGINT                        /* SQL-2003-R */
215
464
%token  BINARY                        /* SQL-2003-R */
 
465
%token  BINLOG_SYM
216
466
%token  BIN_NUM
217
467
%token  BIT_SYM                       /* MYSQL-FUNC */
218
468
%token  BLOB_SYM                      /* SQL-2003-R */
 
469
%token  BLOCK_SIZE_SYM
 
470
%token  BLOCK_SYM
219
471
%token  BOOLEAN_SYM                   /* SQL-2003-R */
220
472
%token  BOOL_SYM
221
473
%token  BOTH                          /* SQL-2003-R */
222
474
%token  BTREE_SYM
223
475
%token  BY                            /* SQL-2003-R */
 
476
%token  BYTE_SYM
 
477
%token  CACHE_SYM
224
478
%token  CALL_SYM                      /* SQL-2003-R */
225
479
%token  CASCADE                       /* SQL-2003-N */
226
480
%token  CASCADED                      /* SQL-2003-R */
227
481
%token  CASE_SYM                      /* SQL-2003-R */
228
482
%token  CAST_SYM                      /* SQL-2003-R */
229
 
%token  CATALOG_SYM
230
483
%token  CHAIN_SYM                     /* SQL-2003-N */
231
 
%token  CHANGE_SYM
 
484
%token  CHANGE
 
485
%token  CHANGED
 
486
%token  CHARSET
232
487
%token  CHAR_SYM                      /* SQL-2003-R */
233
488
%token  CHECKSUM_SYM
234
489
%token  CHECK_SYM                     /* SQL-2003-R */
242
497
%token  COMMITTED_SYM                 /* SQL-2003-N */
243
498
%token  COMMIT_SYM                    /* SQL-2003-R */
244
499
%token  COMPACT_SYM
 
500
%token  COMPLETION_SYM
245
501
%token  COMPRESSED_SYM
246
502
%token  CONCURRENT
247
503
%token  CONDITION_SYM                 /* SQL-2003-N */
249
505
%token  CONSISTENT_SYM
250
506
%token  CONSTRAINT                    /* SQL-2003-R */
251
507
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
508
%token  CONTEXT_SYM
 
509
%token  CONTINUE_SYM                  /* SQL-2003-R */
252
510
%token  CONVERT_SYM                   /* SQL-2003-N */
253
511
%token  COUNT_SYM                     /* SQL-2003-N */
254
512
%token  CREATE                        /* SQL-2003-R */
257
515
%token  CURDATE                       /* MYSQL-FUNC */
258
516
%token  CURRENT_USER                  /* SQL-2003-R */
259
517
%token  CURSOR_SYM                    /* SQL-2003-R */
 
518
%token  CURTIME                       /* MYSQL-FUNC */
260
519
%token  DATABASE
261
520
%token  DATABASES
 
521
%token  DATAFILE_SYM
262
522
%token  DATA_SYM                      /* SQL-2003-N */
263
 
%token  DATETIME_SYM
 
523
%token  DATETIME
264
524
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
265
525
%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
266
526
%token  DATE_SYM                      /* SQL-2003-R */
274
534
%token  DECIMAL_SYM                   /* SQL-2003-R */
275
535
%token  DECLARE_SYM                   /* SQL-2003-R */
276
536
%token  DEFAULT                       /* SQL-2003-R */
 
537
%token  DELAYED_SYM
 
538
%token  DELAY_KEY_WRITE_SYM
277
539
%token  DELETE_SYM                    /* SQL-2003-R */
278
540
%token  DESC                          /* SQL-2003-N */
279
541
%token  DESCRIBE                      /* SQL-2003-R */
280
542
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
 
543
%token  DIRECTORY_SYM
281
544
%token  DISABLE_SYM
282
545
%token  DISCARD
283
546
%token  DISTINCT                      /* SQL-2003-R */
284
547
%token  DIV_SYM
285
 
%token  DO_SYM
286
548
%token  DOUBLE_SYM                    /* SQL-2003-R */
287
549
%token  DROP                          /* SQL-2003-R */
288
550
%token  DUMPFILE
290
552
%token  DYNAMIC_SYM                   /* SQL-2003-R */
291
553
%token  EACH_SYM                      /* SQL-2003-R */
292
554
%token  ELSE                          /* SQL-2003-R */
 
555
%token  ELSEIF_SYM
293
556
%token  ENABLE_SYM
294
557
%token  ENCLOSED
295
558
%token  END                           /* SQL-2003-R */
296
559
%token  ENDS_SYM
297
560
%token  END_OF_INPUT                  /* INTERNAL */
298
561
%token  ENGINE_SYM
299
 
%token  ENUM_SYM
 
562
%token  ENUM
300
563
%token  EQ                            /* OPERATOR */
301
564
%token  EQUAL_SYM                     /* OPERATOR */
302
565
%token  ERRORS
303
566
%token  ESCAPED
304
567
%token  ESCAPE_SYM                    /* SQL-2003-R */
305
568
%token  EXCLUSIVE_SYM
306
 
%token  EXECUTE_SYM                   /* SQL-2003-R */
307
569
%token  EXISTS                        /* SQL-2003-R */
 
570
%token  EXIT_SYM
308
571
%token  EXTENDED_SYM
 
572
%token  EXTENT_SIZE_SYM
309
573
%token  EXTRACT_SYM                   /* SQL-2003-N */
310
574
%token  FALSE_SYM                     /* SQL-2003-R */
 
575
%token  FAST_SYM
 
576
%token  FAULTS_SYM
 
577
%token  FETCH_SYM                     /* SQL-2003-R */
 
578
%token  COLUMN_FORMAT_SYM
311
579
%token  FILE_SYM
312
580
%token  FIRST_SYM                     /* SQL-2003-N */
313
581
%token  FIXED_SYM
321
589
%token  FROM
322
590
%token  FULL                          /* SQL-2003-R */
323
591
%token  GE
 
592
%token  GET_FORMAT                    /* MYSQL-FUNC */
324
593
%token  GLOBAL_SYM                    /* SQL-2003-R */
325
594
%token  GROUP_SYM                     /* SQL-2003-R */
326
595
%token  GROUP_CONCAT_SYM
327
596
%token  GT_SYM                        /* OPERATOR */
 
597
%token  HANDLER_SYM
328
598
%token  HASH_SYM
329
599
%token  HAVING                        /* SQL-2003-R */
330
600
%token  HEX_NUM
 
601
%token  HIGH_PRIORITY
 
602
%token  HOST_SYM
 
603
%token  HOSTS_SYM
331
604
%token  HOUR_MICROSECOND_SYM
332
605
%token  HOUR_MINUTE_SYM
333
606
%token  HOUR_SECOND_SYM
334
607
%token  HOUR_SYM                      /* SQL-2003-R */
335
608
%token  IDENT
336
609
%token  IDENTIFIED_SYM
337
 
%token  IDENTITY_SYM                  /* SQL-2003-R */
338
610
%token  IDENT_QUOTED
339
611
%token  IF
340
612
%token  IGNORE_SYM
342
614
%token  INDEXES
343
615
%token  INDEX_SYM
344
616
%token  INFILE
 
617
%token  INITIAL_SIZE_SYM
345
618
%token  INNER_SYM                     /* SQL-2003-R */
346
619
%token  INOUT_SYM                     /* SQL-2003-R */
347
620
%token  INSENSITIVE_SYM               /* SQL-2003-R */
348
621
%token  INSERT                        /* SQL-2003-R */
 
622
%token  INSERT_METHOD
 
623
%token  INSTALL_SYM
349
624
%token  INTERVAL_SYM                  /* SQL-2003-R */
350
625
%token  INTO                          /* SQL-2003-R */
351
626
%token  INT_SYM                       /* SQL-2003-R */
361
636
%token  LAST_SYM                      /* SQL-2003-N */
362
637
%token  LE                            /* OPERATOR */
363
638
%token  LEADING                       /* SQL-2003-R */
 
639
%token  LEAVES
364
640
%token  LEFT                          /* SQL-2003-R */
365
641
%token  LEVEL_SYM
366
642
%token  LEX_HOSTNAME
367
643
%token  LIKE                          /* SQL-2003-R */
368
644
%token  LIMIT
 
645
%token  LINEAR_SYM
369
646
%token  LINES
 
647
%token  LINESTRING
 
648
%token  LIST_SYM
370
649
%token  LOAD
371
650
%token  LOCAL_SYM                     /* SQL-2003-R */
 
651
%token  LOCATOR_SYM                   /* SQL-2003-N */
372
652
%token  LOCKS_SYM
373
653
%token  LOCK_SYM
 
654
%token  LOGFILE_SYM
374
655
%token  LOGS_SYM
375
656
%token  LONG_NUM
376
657
%token  LONG_SYM
 
658
%token  LOOP_SYM
 
659
%token  LOW_PRIORITY
377
660
%token  LT                            /* OPERATOR */
 
661
%token  MASTER_CONNECT_RETRY_SYM
 
662
%token  MASTER_HOST_SYM
 
663
%token  MASTER_LOG_FILE_SYM
 
664
%token  MASTER_LOG_POS_SYM
 
665
%token  MASTER_PASSWORD_SYM
 
666
%token  MASTER_PORT_SYM
 
667
%token  MASTER_SERVER_ID_SYM
 
668
%token  MASTER_SYM
 
669
%token  MASTER_USER_SYM
 
670
%token  MASTER_HEARTBEAT_PERIOD_SYM
378
671
%token  MATCH                         /* SQL-2003-R */
 
672
%token  MAX_CONNECTIONS_PER_HOUR
 
673
%token  MAX_QUERIES_PER_HOUR
 
674
%token  MAX_ROWS
 
675
%token  MAX_SIZE_SYM
379
676
%token  MAX_SYM                       /* SQL-2003-N */
 
677
%token  MAX_UPDATES_PER_HOUR
 
678
%token  MAX_USER_CONNECTIONS_SYM
380
679
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
381
680
%token  MEDIUM_SYM
382
681
%token  MERGE_SYM                     /* SQL-2003-R */
383
682
%token  MICROSECOND_SYM               /* MYSQL-FUNC */
 
683
%token  MIGRATE_SYM
384
684
%token  MINUTE_MICROSECOND_SYM
385
685
%token  MINUTE_SECOND_SYM
386
686
%token  MINUTE_SYM                    /* SQL-2003-R */
 
687
%token  MIN_ROWS
387
688
%token  MIN_SYM                       /* SQL-2003-N */
388
689
%token  MODE_SYM
389
690
%token  MODIFIES_SYM                  /* SQL-2003-R */
398
699
%token  NEG
399
700
%token  NEW_SYM                       /* SQL-2003-R */
400
701
%token  NEXT_SYM                      /* SQL-2003-N */
 
702
%token  NODEGROUP_SYM
401
703
%token  NONE_SYM                      /* SQL-2003-R */
402
704
%token  NOT_SYM                       /* SQL-2003-R */
403
705
%token  NOW_SYM
 
706
%token  NOWAIT_SYM
404
707
%token  NO_SYM                        /* SQL-2003-R */
 
708
%token  NO_WAIT_SYM
 
709
%token  NO_WRITE_TO_BINLOG
405
710
%token  NULL_SYM                      /* SQL-2003-R */
406
711
%token  NUM
407
712
%token  NUMERIC_SYM                   /* SQL-2003-R */
412
717
%token  ONE_SYM
413
718
%token  ONLINE_SYM
414
719
%token  OPEN_SYM                      /* SQL-2003-R */
415
 
%token  OPTIMIZE                      /* Leave assuming we might add it back */
 
720
%token  OPTIMIZE
 
721
%token  OPTIONS_SYM
416
722
%token  OPTION                        /* SQL-2003-N */
417
723
%token  OPTIONALLY
418
724
%token  ORDER_SYM                     /* SQL-2003-R */
420
726
%token  OUTER
421
727
%token  OUTFILE
422
728
%token  OUT_SYM                       /* SQL-2003-R */
 
729
%token  PACK_KEYS_SYM
 
730
%token  PAGE_SYM
 
731
%token  PAGE_CHECKSUM_SYM
 
732
%token  PARAM_MARKER
 
733
%token  PARSE_VCOL_EXPR_SYM
423
734
%token  PARTIAL                       /* SQL-2003-N */
 
735
%token  PHASE_SYM
 
736
%token  PLUGINS_SYM
 
737
%token  PLUGIN_SYM
 
738
%token  POINT_SYM
 
739
%token  PORT_SYM
424
740
%token  POSITION_SYM                  /* SQL-2003-N */
425
741
%token  PRECISION                     /* SQL-2003-R */
426
742
%token  PREV_SYM
427
743
%token  PRIMARY_SYM                   /* SQL-2003-R */
428
744
%token  PROCESS
429
745
%token  PROCESSLIST_SYM
 
746
%token  PURGE
430
747
%token  QUARTER_SYM
431
748
%token  QUERY_SYM
 
749
%token  QUICK
432
750
%token  RANGE_SYM                     /* SQL-2003-R */
433
751
%token  READS_SYM                     /* SQL-2003-R */
 
752
%token  READ_ONLY_SYM
434
753
%token  READ_SYM                      /* SQL-2003-N */
435
754
%token  READ_WRITE_SYM
436
755
%token  REAL                          /* SQL-2003-R */
 
756
%token  REBUILD_SYM
 
757
%token  RECOVER_SYM
 
758
%token  REDOFILE_SYM
 
759
%token  REDO_BUFFER_SIZE_SYM
437
760
%token  REDUNDANT_SYM
438
 
%token  REGEXP_SYM
439
761
%token  REFERENCES                    /* SQL-2003-R */
 
762
%token  RELAY_LOG_FILE_SYM
 
763
%token  RELAY_LOG_POS_SYM
 
764
%token  RELAY_THREAD
440
765
%token  RELEASE_SYM                   /* SQL-2003-R */
 
766
%token  RELOAD
 
767
%token  REMOVE_SYM
441
768
%token  RENAME
 
769
%token  REORGANIZE_SYM
 
770
%token  REPAIR
442
771
%token  REPEATABLE_SYM                /* SQL-2003-N */
443
772
%token  REPEAT_SYM                    /* MYSQL-FUNC */
444
773
%token  REPLACE                       /* MYSQL-FUNC */
 
774
%token  REPLICATION
 
775
%token  REQUIRE_SYM
 
776
%token  RESET_SYM
 
777
%token  RESOURCES
445
778
%token  RESTRICT
 
779
%token  RESUME_SYM
446
780
%token  RETURNS_SYM                   /* SQL-2003-R */
447
781
%token  RETURN_SYM                    /* SQL-2003-R */
 
782
%token  REVERSE_SYM
448
783
%token  REVOKE                        /* SQL-2003-R */
449
784
%token  RIGHT                         /* SQL-2003-R */
450
785
%token  ROLLBACK_SYM                  /* SQL-2003-R */
464
799
%token  SERIAL_SYM
465
800
%token  SESSION_SYM                   /* SQL-2003-N */
466
801
%token  SERVER_SYM
467
 
%token  SET_SYM                           /* SQL-2003-R */
 
802
%token  SERVER_OPTIONS
 
803
%token  SET                           /* SQL-2003-R */
468
804
%token  SET_VAR
469
805
%token  SHARE_SYM
470
806
%token  SHOW
471
 
%token  SIGNED_SYM
 
807
%token  SHUTDOWN
472
808
%token  SIMPLE_SYM                    /* SQL-2003-N */
 
809
%token  SLAVE
473
810
%token  SNAPSHOT_SYM
 
811
%token  SOCKET_SYM
 
812
%token  SONAME_SYM
 
813
%token  SOURCE_SYM
474
814
%token  SPECIFIC_SYM                  /* SQL-2003-R */
475
815
%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
476
816
%token  SQLSTATE_SYM                  /* SQL-2003-R */
480
820
%token  SQL_CALC_FOUND_ROWS
481
821
%token  SQL_SMALL_RESULT
482
822
%token  SQL_SYM                       /* SQL-2003-R */
 
823
%token  SQL_THREAD
483
824
%token  STARTING
 
825
%token  STARTS_SYM
484
826
%token  START_SYM                     /* SQL-2003-R */
485
827
%token  STATUS_SYM
486
828
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
487
829
%token  STD_SYM
488
830
%token  STOP_SYM
 
831
%token  STORAGE_SYM
489
832
%token  STORED_SYM
490
833
%token  STRAIGHT_JOIN
491
834
%token  STRING_SYM
493
836
%token  SUBJECT_SYM
494
837
%token  SUBSTRING                     /* SQL-2003-N */
495
838
%token  SUM_SYM                       /* SQL-2003-N */
 
839
%token  SUPER_SYM
496
840
%token  SUSPEND_SYM
 
841
%token  SWAPS_SYM
 
842
%token  SWITCHES_SYM
497
843
%token  SYSDATE
498
844
%token  TABLES
499
845
%token  TABLESPACE
500
846
%token  TABLE_REF_PRIORITY
501
847
%token  TABLE_SYM                     /* SQL-2003-R */
502
 
%token  TEMPORARY_SYM                 /* SQL-2003-N */
 
848
%token  TABLE_CHECKSUM_SYM
 
849
%token  TEMPORARY                     /* SQL-2003-N */
 
850
%token  TEMPTABLE_SYM
503
851
%token  TERMINATED
504
852
%token  TEXT_STRING
505
853
%token  TEXT_SYM
 
854
%token  THAN_SYM
506
855
%token  THEN_SYM                      /* SQL-2003-R */
507
 
%token  TIME_SYM                 /* SQL-2003-R */
508
 
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
 
856
%token  TIMESTAMP                     /* SQL-2003-R */
509
857
%token  TIMESTAMP_ADD
510
858
%token  TIMESTAMP_DIFF
 
859
%token  TIME_SYM                      /* SQL-2003-R */
511
860
%token  TO_SYM                        /* SQL-2003-R */
512
861
%token  TRAILING                      /* SQL-2003-R */
513
862
%token  TRANSACTION_SYM
 
863
%token  TRANSACTIONAL_SYM
514
864
%token  TRIM                          /* SQL-2003-N */
515
865
%token  TRUE_SYM                      /* SQL-2003-R */
516
866
%token  TRUNCATE_SYM
 
867
%token  TYPES_SYM
517
868
%token  TYPE_SYM                      /* SQL-2003-N */
518
869
%token  ULONGLONG_NUM
519
870
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
 
871
%token  UNDEFINED_SYM
 
872
%token  UNDERSCORE_CHARSET
520
873
%token  UNDOFILE_SYM
521
874
%token  UNDO_SYM                      /* FUTURE-USE */
522
875
%token  UNION_SYM                     /* SQL-2003-R */
523
876
%token  UNIQUE_SYM
524
877
%token  UNKNOWN_SYM                   /* SQL-2003-R */
525
878
%token  UNLOCK_SYM
526
 
%token  UNSIGNED_SYM
 
879
%token  UNTIL_SYM
527
880
%token  UPDATE_SYM                    /* SQL-2003-R */
 
881
%token  UPGRADE_SYM
528
882
%token  USAGE                         /* SQL-2003-N */
529
883
%token  USER                          /* SQL-2003-R */
 
884
%token  USE_FRM
530
885
%token  USE_SYM
531
886
%token  USING                         /* SQL-2003-R */
532
887
%token  UTC_DATE_SYM
533
888
%token  UTC_TIMESTAMP_SYM
534
 
%token  UUID_SYM
 
889
%token  UTC_TIME_SYM
535
890
%token  VALUES                        /* SQL-2003-R */
536
891
%token  VALUE_SYM                     /* SQL-2003-R */
537
892
%token  VARBINARY
538
 
%token  VARCHAR_SYM                   /* SQL-2003-R */
 
893
%token  VARCHAR                       /* SQL-2003-R */
539
894
%token  VARIABLES
540
895
%token  VARIANCE_SYM
541
896
%token  VARYING                       /* SQL-2003-R */
542
897
%token  VAR_SAMP_SYM
 
898
%token  VIRTUAL_SYM
543
899
%token  WAIT_SYM
544
900
%token  WARNINGS
545
901
%token  WEEK_SYM
 
902
%token  WEIGHT_STRING_SYM
546
903
%token  WHEN_SYM                      /* SQL-2003-R */
547
904
%token  WHERE                         /* SQL-2003-R */
548
905
%token  WITH                          /* SQL-2003-R */
552
909
%token  XOR
553
910
%token  YEAR_MONTH_SYM
554
911
%token  YEAR_SYM                      /* SQL-2003-R */
555
 
%token  ZEROFILL_SYM
556
912
 
557
913
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
558
914
/* A dummy token to force the priority of table_ref production in a join. */
562
918
%left   XOR
563
919
%left   AND_SYM
564
920
%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
 
921
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
566
922
%left   '-' '+'
567
923
%left   '*' '/' '%' DIV_SYM MOD_SYM
568
924
%left   NEG
572
928
 
573
929
%type <lex_str>
574
930
        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
 
931
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
581
932
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
582
 
        schema_name
583
 
        catalog_name
584
 
        opt_component
585
 
        engine_option_value
586
 
        savepoint_ident
587
 
        BIN_NUM TEXT_STRING_filesystem
 
933
        opt_component key_cache_name
 
934
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
588
935
        opt_constraint constraint opt_ident
589
936
 
590
 
%type <execute_string>
591
 
        execute_var_or_string
592
 
 
593
937
%type <lex_str_ptr>
594
938
        opt_table_alias
595
939
 
602
946
%type <string>
603
947
        text_string opt_gconcat_separator
604
948
 
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
949
%type <num>
621
 
        order_dir
622
 
        field_def
623
 
        opt_table_options
624
 
        all_or_any opt_distinct
 
950
        type int_type real_type order_dir field_def
 
951
        if_exists opt_local opt_table_options table_options
 
952
        table_option opt_if_not_exists
 
953
        opt_temporary all_or_any opt_distinct
625
954
        union_option
626
955
        start_transaction_opts opt_chain opt_release
627
956
        union_opt select_derived_init option_type2
628
 
        kill_option
 
957
        /* opt_lock_timeout_value */
629
958
 
630
959
%type <m_fk_option>
631
960
        delete_option
632
961
 
633
962
%type <ulong_num>
634
 
        ulong_num
 
963
        ulong_num real_ulong_num
 
964
        ws_nweights
 
965
        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
 
966
        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
 
967
        ws_level_range ws_level_list_or_range  
635
968
 
636
969
%type <ulonglong_number>
637
970
        ulonglong_num
638
971
 
 
972
%type <choice> choice
 
973
 
639
974
%type <lock_type>
640
 
        load_data_lock
 
975
        replace_lock_option opt_low_priority insert_lock_option load_data_lock
 
976
 
 
977
%type <table_lock_info>
 
978
        table_lock_info
641
979
 
642
980
%type <item>
643
981
        literal text_literal insert_ident order_ident
647
985
        table_wild simple_expr udf_expr
648
986
        expr_or_default set_expr_or_default
649
987
        signed_literal now_or_signed_literal opt_escape
650
 
        simple_ident_q
 
988
        simple_ident_nospvar simple_ident_q
651
989
        field_or_var limit_option
652
990
        function_call_keyword
653
991
        function_call_nonkeyword
681
1019
        select_derived derived_table_list
682
1020
        select_derived_union
683
1021
 
 
1022
%type <date_time_type> date_time_type;
684
1023
%type <interval> interval
685
1024
 
686
1025
%type <interval_time_st> interval_time_st
687
1026
 
688
1027
%type <interval_time_st> interval_time_stamp
689
1028
 
 
1029
%type <db_type> storage_engines known_storage_engines
 
1030
 
 
1031
%type <row_type> row_types
 
1032
 
 
1033
%type <column_format_type> column_format_types
 
1034
 
690
1035
%type <tx_isolation> isolation_types
691
1036
 
692
1037
%type <cast_type> cast_type
693
1038
 
694
 
%type <symbol>
695
 
        keyword
696
 
        keyword_sp
697
 
        keyword_exception_for_variable
698
 
        row_format
 
1039
%type <symbol> keyword keyword_sp
699
1040
 
700
1041
%type <charset>
701
1042
        collation_name
702
1043
        collation_name_or_default
 
1044
        UNDERSCORE_CHARSET
703
1045
 
704
1046
%type <variable> internal_variable_name
705
1047
 
706
1048
%type <select_lex> subselect
707
 
        get_select_lex query_specification
 
1049
        get_select_lex query_specification 
708
1050
        query_expression_body
709
1051
 
710
1052
%type <boolfunc2creator> comp_op
712
1054
%type <build_method> build_method
713
1055
 
714
1056
%type <NONE>
715
 
        query verb_clause create select drop insert replace insert2
 
1057
        query verb_clause create change select drop insert replace insert2
716
1058
        insert_values update delete truncate rename
717
 
        show describe load alter flush
718
 
        begin commit rollback savepoint release
719
 
        analyze check start
 
1059
        show describe load alter optimize keycache flush
 
1060
        reset purge begin commit rollback savepoint release
 
1061
        slave master_def master_defs master_file_def slave_until_opts
 
1062
        repair analyze check start checksum
720
1063
        field_list field_list_item field_spec kill column_def key_def
 
1064
        keycache_list assign_to_keycache
721
1065
        select_item_list select_item values_list no_braces
722
1066
        opt_limit_clause delete_limit_clause fields opt_values values
723
1067
        opt_precision opt_ignore opt_column
724
 
        set unlock string_list
 
1068
        set lock unlock string_list
 
1069
        opt_binary table_lock_list table_lock
725
1070
        ref_list opt_match_clause opt_on_update_delete use
726
1071
        opt_delete_options opt_delete_option varchar
727
 
        opt_outer table_list table_name
 
1072
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
728
1073
        opt_option opt_place
729
1074
        opt_attribute opt_attribute_list attribute
730
1075
        flush_options flush_option
731
1076
        equal optional_braces
732
 
        normal_join
733
 
        table_to_table_list table_to_table opt_table_list
734
 
        single_multi
 
1077
        opt_mi_check_type opt_to mi_check_types normal_join
 
1078
        table_to_table_list table_to_table opt_table_list opt_as
 
1079
        single_multi table_wild_list table_wild_one opt_wild
735
1080
        union_clause union_list
736
1081
        precision subselect_start
737
1082
        subselect_end select_var_list select_var_list_init opt_len
738
1083
        opt_extended_describe
739
1084
        statement
740
 
        execute
741
1085
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
 
1086
        binlog_base64_event
742
1087
        init_key_options key_options key_opts key_opt key_using_alg
 
1088
        parse_vcol_expr vcol_opt_attribute vcol_opt_attribute_list
 
1089
        vcol_attribute
743
1090
END_OF_INPUT
744
1091
 
745
1092
%type <index_hint> index_hint_type
784
1131
            }
785
1132
            else
786
1133
            {
787
 
              session->lex->statement= new statement::EmptyQuery(YYSession);
 
1134
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
788
1135
            }
789
1136
          }
790
1137
        | verb_clause END_OF_INPUT {}
799
1146
statement:
800
1147
          alter
801
1148
        | analyze
 
1149
        | binlog_base64_event
 
1150
        | change
802
1151
        | check
 
1152
        | checksum
803
1153
        | commit
804
1154
        | create
805
1155
        | delete
806
1156
        | describe
807
1157
        | drop
808
 
        | execute
809
1158
        | flush
810
1159
        | insert
811
1160
        | kill
812
1161
        | load
 
1162
        | lock
 
1163
        | optimize
 
1164
        | keycache
 
1165
        | parse_vcol_expr
 
1166
        | purge
813
1167
        | release
814
1168
        | rename
 
1169
        | repair
815
1170
        | replace
 
1171
        | reset
816
1172
        | rollback
817
1173
        | savepoint
818
1174
        | select
819
1175
        | set
820
1176
        | show
 
1177
        | slave
821
1178
        | start
822
1179
        | truncate
823
1180
        | unlock
825
1182
        | use
826
1183
        ;
827
1184
 
 
1185
 
 
1186
/* change master */
 
1187
 
 
1188
change:
 
1189
          CHANGE MASTER_SYM TO_SYM
 
1190
          {
 
1191
            LEX *lex = Lex;
 
1192
            lex->sql_command = SQLCOM_CHANGE_MASTER;
 
1193
            memset(&lex->mi, 0, sizeof(lex->mi));
 
1194
          }
 
1195
          master_defs
 
1196
          {}
 
1197
        ;
 
1198
 
 
1199
master_defs:
 
1200
          master_def
 
1201
        | master_defs ',' master_def
 
1202
        ;
 
1203
 
 
1204
master_def:
 
1205
          MASTER_HOST_SYM EQ TEXT_STRING_sys
 
1206
          {
 
1207
            Lex->mi.host = $3.str;
 
1208
          }
 
1209
        | MASTER_USER_SYM EQ TEXT_STRING_sys
 
1210
          {
 
1211
            Lex->mi.user = $3.str;
 
1212
          }
 
1213
        | MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
 
1214
          {
 
1215
            Lex->mi.password = $3.str;
 
1216
          }
 
1217
        | MASTER_PORT_SYM EQ ulong_num
 
1218
          {
 
1219
            Lex->mi.port = $3;
 
1220
          }
 
1221
        | MASTER_CONNECT_RETRY_SYM EQ ulong_num
 
1222
          {
 
1223
            Lex->mi.connect_retry = $3;
 
1224
          }
 
1225
        | MASTER_HEARTBEAT_PERIOD_SYM EQ NUM_literal
 
1226
          {
 
1227
            Lex->mi.heartbeat_period= (float) $3->val_real();
 
1228
            if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD ||
 
1229
                Lex->mi.heartbeat_period < 0.0)
 
1230
            {
 
1231
              char buf[sizeof(SLAVE_MAX_HEARTBEAT_PERIOD*4)];
 
1232
              sprintf(buf, "%d seconds", SLAVE_MAX_HEARTBEAT_PERIOD);
 
1233
              my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
 
1234
                       MYF(0),
 
1235
                       " is negative or exceeds the maximum ",
 
1236
                       buf); 
 
1237
              DRIZZLE_YYABORT;
 
1238
            }
 
1239
            if (Lex->mi.heartbeat_period > slave_net_timeout)
 
1240
            {
 
1241
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1242
                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
 
1243
                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
 
1244
                                  " exceeds the value of `slave_net_timeout' sec.",
 
1245
                                  " A sensible value for the period should be"
 
1246
                                  " less than the timeout.");
 
1247
            }
 
1248
            if (Lex->mi.heartbeat_period < 0.001)
 
1249
            {
 
1250
              if (Lex->mi.heartbeat_period != 0.0)
 
1251
              {
 
1252
                push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1253
                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
 
1254
                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
 
1255
                                    " is less than 1 msec.",
 
1256
                                    " The period is reset to zero which means"
 
1257
                                    " no heartbeats will be sending");
 
1258
                Lex->mi.heartbeat_period= 0.0;
 
1259
              }
 
1260
              Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_DISABLE;
 
1261
            }
 
1262
            Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_ENABLE;
 
1263
          }
 
1264
        |
 
1265
        master_file_def
 
1266
        ;
 
1267
 
 
1268
master_file_def:
 
1269
          MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
 
1270
          {
 
1271
            Lex->mi.log_file_name = $3.str;
 
1272
          }
 
1273
        | MASTER_LOG_POS_SYM EQ ulonglong_num
 
1274
          {
 
1275
            Lex->mi.pos = $3;
 
1276
            /* 
 
1277
               If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
 
1278
               instead of causing subsequent errors. 
 
1279
               We need to do it in this file, because only there we know that 
 
1280
               MASTER_LOG_POS has been explicitely specified. On the contrary
 
1281
               in change_master() (sql_repl.cc) we cannot distinguish between 0
 
1282
               (MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
 
1283
               whereas we want to distinguish (specified 0 means "read the binlog
 
1284
               from 0" (4 in fact), unspecified means "don't change the position
 
1285
               (keep the preceding value)").
 
1286
            */
 
1287
            Lex->mi.pos = cmax((uint64_t)BIN_LOG_HEADER_SIZE, Lex->mi.pos);
 
1288
          }
 
1289
        | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
 
1290
          {
 
1291
            Lex->mi.relay_log_name = $3.str;
 
1292
          }
 
1293
        | RELAY_LOG_POS_SYM EQ ulong_num
 
1294
          {
 
1295
            Lex->mi.relay_log_pos = $3;
 
1296
            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
 
1297
            Lex->mi.relay_log_pos = cmax((uint32_t)BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
 
1298
          }
 
1299
        ;
 
1300
 
828
1301
/* create a table */
829
1302
 
830
1303
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);
 
1304
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1305
          {
 
1306
            Session *session= YYSession;
 
1307
            LEX *lex= session->lex;
 
1308
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1309
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
1310
                                                   TL_OPTION_UPDATING,
 
1311
                                                   TL_WRITE))
 
1312
              DRIZZLE_YYABORT;
 
1313
            lex->alter_info.reset();
 
1314
            lex->col_list.empty();
 
1315
            lex->change=NULL;
 
1316
            memset(&lex->create_info, 0, sizeof(lex->create_info));
 
1317
            lex->create_info.options=$2 | $4;
 
1318
            lex->create_info.db_type= ha_default_handlerton(session);
 
1319
            lex->create_info.default_table_charset= NULL;
 
1320
            lex->name.str= 0;
 
1321
            lex->name.length= 0;
 
1322
          }
 
1323
          create2
 
1324
          {
 
1325
            LEX *lex= YYSession->lex;
 
1326
            lex->current_select= &lex->select_lex; 
 
1327
            if (!lex->create_info.db_type)
 
1328
            {
 
1329
              lex->create_info.db_type= ha_default_handlerton(YYSession);
 
1330
              push_warning_printf(YYSession, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1331
                                  ER_WARN_USING_OTHER_HANDLER,
 
1332
                                  ER(ER_WARN_USING_OTHER_HANDLER),
 
1333
                                  ha_resolve_storage_engine_name(lex->create_info.db_type),
 
1334
                                  $5->table.str);
 
1335
            }
 
1336
          }
 
1337
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
 
1338
          ON table_ident
 
1339
          {
 
1340
            LEX *lex=Lex;
 
1341
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1342
            if (!lex->current_select->add_table_to_list(lex->session, $8,
 
1343
                                                        NULL,
 
1344
                                                        TL_OPTION_UPDATING))
 
1345
              DRIZZLE_YYABORT;
 
1346
            lex->alter_info.reset();
 
1347
            lex->alter_info.flags= ALTER_ADD_INDEX;
 
1348
            lex->alter_info.build_method= $2;
 
1349
            lex->col_list.empty();
 
1350
            lex->change=NULL;
 
1351
          }
 
1352
          '(' key_list ')' key_options
 
1353
          {
 
1354
            LEX *lex=Lex;
 
1355
            Key *key;
 
1356
            key= new Key($3, $5, &lex->key_create_info, 0,
 
1357
                         lex->col_list);
 
1358
            lex->alter_info.key_list.push_back(key);
 
1359
            lex->col_list.empty();
 
1360
          }
 
1361
        | CREATE DATABASE opt_if_not_exists ident
 
1362
          {
 
1363
            Lex->create_info.default_table_charset= NULL;
 
1364
            Lex->create_info.used_fields= 0;
865
1365
          }
866
1366
          opt_create_database_options
867
1367
          {
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
 
           }
 
1368
            LEX *lex=Lex;
 
1369
            lex->sql_command=SQLCOM_CREATE_DB;
 
1370
            lex->name= $4;
 
1371
            lex->create_info.options=$3;
 
1372
          }
 
1373
        ;
 
1374
 
 
1375
create2:
 
1376
          '(' create2a {}
 
1377
        | opt_create_table_options
 
1378
          create3 {}
 
1379
        | LIKE table_ident
 
1380
          {
 
1381
            Session *session= YYSession;
 
1382
            LEX *lex= session->lex;
 
1383
 
 
1384
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1385
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
 
1386
              DRIZZLE_YYABORT;
 
1387
          }
 
1388
        | '(' LIKE table_ident ')'
 
1389
          {
 
1390
            Session *session= YYSession;
 
1391
            LEX *lex= session->lex;
 
1392
 
 
1393
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1394
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
 
1395
              DRIZZLE_YYABORT;
 
1396
          }
 
1397
        ;
 
1398
 
 
1399
create2a:
 
1400
          field_list ')' opt_create_table_options
 
1401
          create3 {}
 
1402
        |  create_select ')'
 
1403
           { Select->set_braces(1);}
879
1404
           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
1405
        ;
887
1406
 
888
 
create_select_as:
 
1407
create3:
889
1408
          /* empty */ {}
890
 
        | opt_duplicate_as create_select
891
 
          {
892
 
            Lex->current_select->set_braces(0);
893
 
          }
 
1409
        | opt_duplicate opt_as create_select
 
1410
          { Select->set_braces(0);}
894
1411
          union_clause {}
895
 
        | opt_duplicate_as '(' create_select ')'
896
 
          {
897
 
            Lex->current_select->set_braces(1);
898
 
          }
 
1412
        | opt_duplicate opt_as '(' create_select ')'
 
1413
          { Select->set_braces(1);}
899
1414
          union_opt {}
900
1415
        ;
901
1416
 
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
1417
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
1418
          SELECT_SYM
923
1419
          {
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
 
            }
 
1420
            LEX *lex=Lex;
 
1421
            lex->lock_option= TL_READ;
 
1422
            if (lex->sql_command == SQLCOM_INSERT)
 
1423
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1424
            else if (lex->sql_command == SQLCOM_REPLACE)
 
1425
              lex->sql_command= SQLCOM_REPLACE_SELECT;
935
1426
            /*
936
1427
              The following work only with the local list, the global list
937
1428
              is created correctly in this case
938
1429
            */
939
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
 
            init_select(Lex);
941
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
1430
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1431
            mysql_init_select(lex);
 
1432
            lex->current_select->parsing_place= SELECT_LIST;
942
1433
          }
943
1434
          select_options select_item_list
944
1435
          {
945
 
            Lex->current_select->parsing_place= NO_MATTER;
 
1436
            Select->parsing_place= NO_MATTER;
946
1437
          }
947
1438
          opt_select_from
948
1439
          {
954
1445
          }
955
1446
        ;
956
1447
 
 
1448
opt_as:
 
1449
          /* empty */ {}
 
1450
        | AS {}
 
1451
        ;
 
1452
 
957
1453
opt_create_database_options:
958
1454
          /* 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
 
          }
 
1455
        | create_database_options {}
 
1456
        ;
 
1457
 
 
1458
create_database_options:
 
1459
          create_database_option {}
 
1460
        | create_database_options create_database_option {}
 
1461
        ;
 
1462
 
 
1463
create_database_option:
 
1464
          default_collation {}
982
1465
        ;
983
1466
 
984
1467
opt_table_options:
985
 
          /* empty */ { $$= false; }
986
 
        | TEMPORARY_SYM { $$= true; }
 
1468
          /* empty */ { $$= 0; }
 
1469
        | table_options  { $$= $1;}
 
1470
        ;
 
1471
 
 
1472
table_options:
 
1473
          table_option { $$=$1; }
 
1474
        | table_option table_options { $$= $1 | $2; }
 
1475
        ;
 
1476
 
 
1477
table_option:
 
1478
          TEMPORARY { $$=HA_LEX_CREATE_TMP_TABLE; }
987
1479
        ;
988
1480
 
989
1481
opt_if_not_exists:
990
 
          /* empty */ { $$= false; }
991
 
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1482
          /* empty */ { $$= 0; }
 
1483
        | IF not EXISTS { $$=HA_LEX_CREATE_IF_NOT_EXISTS; }
992
1484
        ;
993
1485
 
994
1486
opt_create_table_options:
1005
1497
          create_table_option
1006
1498
        | create_table_option     create_table_options
1007
1499
        | create_table_option ',' create_table_options
 
1500
        ;
1008
1501
 
1009
1502
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);
 
1503
          ENGINE_SYM opt_equal storage_engines
 
1504
          {
 
1505
            Lex->create_info.db_type= $3;
 
1506
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1507
          }
 
1508
        | MAX_ROWS opt_equal ulonglong_num
 
1509
          {
 
1510
            Lex->create_info.max_rows= $3;
 
1511
            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
 
1512
          }
 
1513
        | MIN_ROWS opt_equal ulonglong_num
 
1514
          {
 
1515
            Lex->create_info.min_rows= $3;
 
1516
            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
 
1517
          }
 
1518
        | AVG_ROW_LENGTH opt_equal ulong_num
 
1519
          {
 
1520
            Lex->create_info.avg_row_length=$3;
 
1521
            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
 
1522
          }
 
1523
        | BLOCK_SIZE_SYM opt_equal ulong_num    
 
1524
          { 
 
1525
            Lex->create_info.block_size= $3; 
 
1526
            Lex->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
1016
1527
          }
1017
1528
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1018
1529
          {
1019
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1530
            Lex->create_info.comment=$3;
 
1531
            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
1020
1532
          }
1021
1533
        | AUTO_INC opt_equal ulonglong_num
1022
1534
          {
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);
 
1535
            Lex->create_info.auto_increment_value=$3;
 
1536
            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1537
          }
 
1538
        | PACK_KEYS_SYM opt_equal ulong_num
 
1539
          {
 
1540
            switch($3) {
 
1541
            case 0:
 
1542
                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
 
1543
                break;
 
1544
            case 1:
 
1545
                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
 
1546
                break;
 
1547
            default:
 
1548
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
1549
                DRIZZLE_YYABORT;
 
1550
            }
 
1551
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
 
1552
          }
 
1553
        | PACK_KEYS_SYM opt_equal DEFAULT
 
1554
          {
 
1555
            Lex->create_info.table_options&=
 
1556
              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
 
1557
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
 
1558
          }
 
1559
        | CHECKSUM_SYM opt_equal ulong_num
 
1560
          {
 
1561
            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
 
1562
            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
 
1563
          }
 
1564
        | TABLE_CHECKSUM_SYM opt_equal ulong_num
 
1565
          {
 
1566
             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
 
1567
             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
 
1568
          }
 
1569
        | PAGE_CHECKSUM_SYM opt_equal choice
 
1570
          {
 
1571
            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
 
1572
            Lex->create_info.page_checksum= $3;
 
1573
          }
 
1574
        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
 
1575
          {
 
1576
            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
 
1577
            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
 
1578
          }
 
1579
        | ROW_FORMAT_SYM opt_equal row_types
 
1580
          {
 
1581
            Lex->create_info.row_type= $3;
 
1582
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1583
            Lex->alter_info.flags|= ALTER_ROW_FORMAT;
1040
1584
          }
1041
1585
        | default_collation
 
1586
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
 
1587
          {
 
1588
            Lex->create_info.data_file_name= $4.str;
 
1589
            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
 
1590
          }
 
1591
        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
 
1592
          {
 
1593
            Lex->create_info.index_file_name= $4.str;
 
1594
            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
 
1595
          }
 
1596
        | CONNECTION_SYM opt_equal TEXT_STRING_sys
 
1597
          {
 
1598
            Lex->create_info.connect_string.str= $3.str;
 
1599
            Lex->create_info.connect_string.length= $3.length;
 
1600
            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
 
1601
          }
 
1602
        | KEY_BLOCK_SIZE opt_equal ulong_num
 
1603
          {
 
1604
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1605
            Lex->create_info.key_block_size= $3;
 
1606
          }
1042
1607
        ;
1043
1608
 
1044
1609
default_collation:
1045
1610
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1046
1611
          {
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
 
          }
 
1612
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1613
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1614
                 cinfo->default_table_charset && $4 &&
 
1615
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1616
              {
 
1617
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1618
                         $4->name, cinfo->default_table_charset->csname);
 
1619
                DRIZZLE_YYABORT;
 
1620
              }
 
1621
              Lex->create_info.default_table_charset= $4;
 
1622
              Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1623
          }
 
1624
        ;
 
1625
 
 
1626
storage_engines:
 
1627
          ident_or_text
 
1628
          {
 
1629
            plugin_ref plugin= ha_resolve_by_name(YYSession, &$1);
 
1630
 
 
1631
            if (plugin)
 
1632
              $$= plugin_data(plugin, handlerton*);
 
1633
            else
 
1634
            {
 
1635
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1636
              DRIZZLE_YYABORT;
 
1637
            }
 
1638
          }
 
1639
        ;
 
1640
 
 
1641
known_storage_engines:
 
1642
          ident_or_text
 
1643
          {
 
1644
            plugin_ref plugin;
 
1645
            if ((plugin= ha_resolve_by_name(YYSession, &$1)))
 
1646
              $$= plugin_data(plugin, handlerton*);
 
1647
            else
 
1648
            {
 
1649
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1650
              DRIZZLE_YYABORT;
 
1651
            }
 
1652
          }
 
1653
        ;
 
1654
 
 
1655
column_format_types:
 
1656
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1657
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1658
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1659
 
 
1660
row_types:
 
1661
          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
 
1662
        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
 
1663
        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
 
1664
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
 
1665
        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
 
1666
        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
 
1667
        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
1076
1668
        ;
1077
1669
 
1078
1670
opt_select_from:
1094
1686
          field_spec opt_check_constraint
1095
1687
        | field_spec references
1096
1688
          {
1097
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1689
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1098
1690
          }
1099
1691
        ;
1100
1692
 
1101
1693
key_def:
1102
1694
          key_type opt_ident key_alg '(' key_list ')' key_options
1103
1695
          {
1104
 
            parser::buildKey(Lex, $1, $2);
 
1696
            LEX *lex=Lex;
 
1697
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
 
1698
                              lex->col_list);
 
1699
            lex->alter_info.key_list.push_back(key);
 
1700
            lex->col_list.empty(); /* Alloced by sql_alloc */
1105
1701
          }
1106
1702
        | opt_constraint constraint_key_type opt_ident key_alg
1107
1703
          '(' key_list ')' key_options
1108
1704
          {
1109
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1705
            LEX *lex=Lex;
 
1706
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
 
1707
                              lex->col_list);
 
1708
            lex->alter_info.key_list.push_back(key);
 
1709
            lex->col_list.empty(); /* Alloced by sql_alloc */
1110
1710
          }
1111
1711
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1112
1712
          {
1113
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1713
            LEX *lex=Lex;
 
1714
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
 
1715
                                      $8,
 
1716
                                      lex->ref_list,
 
1717
                                      lex->fk_delete_opt,
 
1718
                                      lex->fk_update_opt,
 
1719
                                      lex->fk_match_option);
 
1720
            lex->alter_info.key_list.push_back(key);
 
1721
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1722
                         &default_key_create_info, 1,
 
1723
                         lex->col_list);
 
1724
            lex->alter_info.key_list.push_back(key);
 
1725
            lex->col_list.empty(); /* Alloced by sql_alloc */
 
1726
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1727
            lex->alter_info.flags|= ALTER_FOREIGN_KEY;
1114
1728
          }
1115
1729
        | constraint opt_check_constraint
1116
1730
          {
1117
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1731
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1118
1732
          }
1119
1733
        | opt_constraint check_constraint
1120
1734
          {
1121
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1735
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1122
1736
          }
1123
1737
        ;
1124
1738
 
1143
1757
field_spec:
1144
1758
          field_ident
1145
1759
          {
1146
 
            parser::buildCreateFieldIdent(Lex);
 
1760
            LEX *lex=Lex;
 
1761
            lex->length=lex->dec=0;
 
1762
            lex->type=0;
 
1763
            lex->default_value= lex->on_update_value= 0;
 
1764
            lex->comment=null_lex_str;
 
1765
            lex->charset=NULL;
 
1766
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1767
            lex->vcol_info= NULL;
1147
1768
          }
1148
1769
          field_def
1149
1770
          {
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))
 
1771
            LEX *lex=Lex;
 
1772
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
 
1773
                                  lex->length,lex->dec,lex->type,
 
1774
                                  lex->column_format,
 
1775
                                  lex->default_value, lex->on_update_value, 
 
1776
                                  &lex->comment,
 
1777
                                  lex->change,&lex->interval_list,lex->charset,
 
1778
                                  lex->vcol_info))
1163
1779
              DRIZZLE_YYABORT;
1164
 
 
1165
 
            Lex->setField(NULL);
1166
1780
          }
1167
1781
        ;
1168
 
 
1169
1782
field_def:
1170
 
          field_definition opt_attribute {}
1171
 
        ;
1172
 
 
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);
 
1783
          type opt_attribute {}
 
1784
        | VIRTUAL_SYM type AS '(' virtual_column_func ')' vcol_opt_attribute
 
1785
          {
 
1786
            $$=DRIZZLE_TYPE_VIRTUAL;
 
1787
            Lex->vcol_info->set_field_type((enum enum_field_types) $2);
 
1788
          }
 
1789
        ;
 
1790
 
 
1791
vcol_opt_attribute:
 
1792
          /* empty */ {}
 
1793
        | vcol_opt_attribute_list {}
 
1794
        ;
 
1795
 
 
1796
vcol_opt_attribute_list:
 
1797
          vcol_opt_attribute_list vcol_attribute {}
 
1798
        | vcol_attribute
 
1799
        ;
 
1800
 
 
1801
vcol_attribute:
 
1802
          UNIQUE_SYM
 
1803
          {
 
1804
            LEX *lex=Lex;
 
1805
            lex->type|= UNIQUE_FLAG; 
 
1806
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1807
          }
 
1808
        | UNIQUE_SYM KEY_SYM
 
1809
          {
 
1810
            LEX *lex=Lex;
 
1811
            lex->type|= UNIQUE_KEY_FLAG; 
 
1812
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
1813
          }
 
1814
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
 
1815
        | STORED_SYM
 
1816
          {
 
1817
            Lex->vcol_info->set_field_stored(true);
 
1818
          }
 
1819
        ;
 
1820
 
 
1821
parse_vcol_expr:
 
1822
          PARSE_VCOL_EXPR_SYM '(' virtual_column_func ')'
 
1823
          {
 
1824
            /* 
 
1825
              "PARSE_VCOL_EXPR" can only be used by the SQL server
 
1826
              when reading a '*.frm' file.
 
1827
              Prevent the end user from invoking this command.
 
1828
            */
 
1829
            if (not Lex->parse_vcol_expr)
 
1830
            {
 
1831
              my_message(ER_SYNTAX_ERROR, ER(ER_SYNTAX_ERROR), MYF(0));
 
1832
              DRIZZLE_YYABORT;
 
1833
            }
 
1834
          }
 
1835
        ;
 
1836
 
 
1837
virtual_column_func:
 
1838
          remember_name expr remember_end
 
1839
          {
 
1840
            Lex->vcol_info= new virtual_column_info();
 
1841
            if (not Lex->vcol_info)
 
1842
            {
 
1843
              my_error(ER_OUTOFMEMORY, MYF(0), sizeof(virtual_column_info));
 
1844
              DRIZZLE_YYABORT;
 
1845
            }
 
1846
            uint expr_len= (uint)($3 - $1) - 1;
 
1847
            Lex->vcol_info->expr_str.str= (char* ) sql_memdup($1 + 1, expr_len);
 
1848
            Lex->vcol_info->expr_str.length= expr_len;
 
1849
            Lex->vcol_info->expr_item= $2;
 
1850
          }
 
1851
        ;
 
1852
 
 
1853
type:
 
1854
        int_type
 
1855
        { 
 
1856
          $$=$1; 
 
1857
          Lex->length=(char*) 0; /* use default length */
 
1858
        }
 
1859
        | real_type opt_precision { $$=$1; }
 
1860
        | char '(' NUM ')' opt_binary
 
1861
          {
 
1862
            Lex->length=$3.str;
 
1863
            $$=DRIZZLE_TYPE_VARCHAR;
 
1864
          }
 
1865
        | char opt_binary
 
1866
          {
 
1867
            Lex->length=(char*) "1";
 
1868
            $$=DRIZZLE_TYPE_VARCHAR;
 
1869
          }
 
1870
        | varchar '(' NUM ')' opt_binary
 
1871
          {
 
1872
            Lex->length=$3.str;
 
1873
            $$= DRIZZLE_TYPE_VARCHAR;
1194
1874
          }
1195
1875
        | VARBINARY '(' NUM ')'
1196
1876
          {
1197
 
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
 
1877
            Lex->length=$3.str;
 
1878
            Lex->charset=&my_charset_bin;
 
1879
            $$= DRIZZLE_TYPE_VARCHAR;
1198
1880
          }
1199
1881
        | DATE_SYM
1200
 
          {
1201
 
            $$=DRIZZLE_TYPE_DATE;
1202
 
 
1203
 
            if (Lex->field())
1204
 
              Lex->field()->set_type(message::Table::Field::DATE);
1205
 
          }
 
1882
          { $$=DRIZZLE_TYPE_DATE; }
1206
1883
        | TIME_SYM
1207
 
          {
1208
 
            $$=DRIZZLE_TYPE_TIME;
1209
 
 
1210
 
            if (Lex->field())
1211
 
              Lex->field()->set_type(message::Table::Field::TIME);
1212
 
          }
1213
 
        | TIMESTAMP_SYM
1214
 
          {
1215
 
            $$=parser::buildTimestampColumn(Lex, NULL);
1216
 
          }
1217
 
        | TIMESTAMP_SYM '(' NUM ')'
1218
 
          {
1219
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1220
 
          }
1221
 
        | DATETIME_SYM
1222
 
          {
1223
 
            $$=DRIZZLE_TYPE_DATETIME;
1224
 
 
1225
 
            if (Lex->field())
1226
 
              Lex->field()->set_type(message::Table::Field::DATETIME);
1227
 
          }
 
1884
          { $$=DRIZZLE_TYPE_TIME; }
 
1885
        | TIMESTAMP
 
1886
          {
 
1887
            /* Unlike other types TIMESTAMP fields are NOT NULL by default */
 
1888
            Lex->type|= NOT_NULL_FLAG;
 
1889
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1890
          }
 
1891
        | DATETIME
 
1892
          { $$=DRIZZLE_TYPE_DATETIME; }
1228
1893
        | BLOB_SYM
1229
1894
          {
1230
 
            $$= parser::buildBlobColumn(Lex);
1231
 
          }
1232
 
        | TEXT_SYM
1233
 
          {
 
1895
            Lex->charset=&my_charset_bin;
1234
1896
            $$=DRIZZLE_TYPE_BLOB;
1235
1897
            Lex->length=(char*) 0; /* use default length */
1236
 
 
1237
 
          if (Lex->field())
1238
 
            Lex->field()->set_type(message::Table::Field::BLOB);
 
1898
          }
 
1899
        | TEXT_SYM opt_binary
 
1900
          { 
 
1901
            $$=DRIZZLE_TYPE_BLOB; 
 
1902
            Lex->length=(char*) 0; /* use default length */
1239
1903
          }
1240
1904
        | DECIMAL_SYM float_options
1241
 
          {
1242
 
            $$= parser::buildDecimalColumn(Lex);
1243
 
          }
 
1905
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1244
1906
        | NUMERIC_SYM float_options
1245
 
          {
1246
 
            $$= parser::buildDecimalColumn(Lex);
1247
 
          }
 
1907
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1248
1908
        | FIXED_SYM float_options
1249
 
          {
1250
 
            $$= parser::buildDecimalColumn(Lex);
1251
 
          }
1252
 
        | 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
 
          }
 
1909
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1910
        | ENUM
 
1911
          {Lex->interval_list.empty();}
 
1912
          '(' string_list ')' opt_binary
 
1913
          { $$=DRIZZLE_TYPE_ENUM; }
1271
1914
        | SERIAL_SYM
1272
1915
          {
1273
 
            $$= parser::buildSerialColumn(Lex);
 
1916
            $$=DRIZZLE_TYPE_LONGLONG;
 
1917
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1274
1918
          }
1275
1919
        ;
1276
1920
 
1280
1924
 
1281
1925
varchar:
1282
1926
          char VARYING {}
1283
 
        | VARCHAR_SYM {}
 
1927
        | VARCHAR {}
1284
1928
        ;
1285
1929
 
1286
1930
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
 
          }
 
1931
          INT_SYM   { $$=DRIZZLE_TYPE_LONG; }
 
1932
        | BIGINT    { $$=DRIZZLE_TYPE_LONGLONG; }
1299
1933
        ;
1300
1934
 
1301
1935
real_type:
1304
1938
            $$= DRIZZLE_TYPE_DOUBLE;
1305
1939
          }
1306
1940
        | DOUBLE_SYM
1307
 
          {
1308
 
            $$= DRIZZLE_TYPE_DOUBLE;
1309
 
          }
 
1941
          { $$=DRIZZLE_TYPE_DOUBLE; }
1310
1942
        | DOUBLE_SYM PRECISION
1311
 
          {
1312
 
            $$= DRIZZLE_TYPE_DOUBLE;
1313
 
          }
 
1943
          { $$=DRIZZLE_TYPE_DOUBLE; }
1314
1944
        ;
1315
1945
 
1316
1946
float_options:
1325
1955
precision:
1326
1956
          '(' NUM ',' NUM ')'
1327
1957
          {
1328
 
            Lex->length= $2.str;
1329
 
            Lex->dec= $4.str;
 
1958
            LEX *lex=Lex;
 
1959
            lex->length=$2.str;
 
1960
            lex->dec=$4.str;
1330
1961
          }
1331
1962
        ;
1332
1963
 
1335
1966
        | '(' NUM ')' { Lex->length= $2.str; }
1336
1967
        ;
1337
1968
 
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
1969
opt_precision:
1355
 
          /* empty */
1356
 
          { Lex->dec=Lex->length= (char*)0; }
1357
 
        | '(' NUM ')'
1358
 
          { Lex->length=Lex->dec= (char*)0; }
1359
 
        | precision
1360
 
          {}
 
1970
          /* empty */ {}
 
1971
        | precision {}
1361
1972
        ;
1362
1973
 
1363
1974
opt_attribute:
1371
1982
        ;
1372
1983
 
1373
1984
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
 
          }
 
1985
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
 
1986
        | COLUMN_FORMAT_SYM column_format_types
 
1987
          {
 
1988
            Lex->column_format= $2;
 
1989
            Lex->alter_info.flags|= ALTER_COLUMN_FORMAT;
 
1990
          }
 
1991
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
 
1992
        | DEFAULT now_or_signed_literal 
 
1993
          { 
 
1994
            Lex->default_value=$2; 
 
1995
            Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
1996
          }
 
1997
        | ON UPDATE_SYM NOW_SYM optional_braces 
 
1998
          { Lex->on_update_value= new Item_func_now_local(); }
 
1999
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1402
2000
        | SERIAL_SYM DEFAULT VALUE_SYM
1403
 
          {
1404
 
            (void)parser::buildSerialColumn(Lex);
 
2001
          { 
 
2002
            LEX *lex=Lex;
 
2003
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
2004
            lex->alter_info.flags|= ALTER_ADD_INDEX;
1405
2005
          }
1406
2006
        | opt_primary KEY_SYM
1407
2007
          {
1408
 
            parser::buildPrimaryOnColumn(Lex);
 
2008
            LEX *lex=Lex;
 
2009
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
2010
            lex->alter_info.flags|= ALTER_ADD_INDEX;
1409
2011
          }
1410
2012
        | UNIQUE_SYM
1411
2013
          {
1412
 
            parser::buildKeyOnColumn(Lex);
 
2014
            LEX *lex=Lex;
 
2015
            lex->type|= UNIQUE_FLAG; 
 
2016
            lex->alter_info.flags|= ALTER_ADD_INDEX;
1413
2017
          }
1414
2018
        | UNIQUE_SYM KEY_SYM
1415
2019
          {
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
 
          }
 
2020
            LEX *lex=Lex;
 
2021
            lex->type|= UNIQUE_KEY_FLAG; 
 
2022
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
2023
          }
 
2024
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
1426
2025
        | COLLATE_SYM collation_name
1427
2026
          {
1428
2027
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
1448
2047
collation_name:
1449
2048
          ident_or_text
1450
2049
          {
1451
 
            if (!($$=get_charset_by_name($1.str)))
 
2050
            if (!($$=get_charset_by_name($1.str,MYF(0))))
1452
2051
            {
1453
2052
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
1454
2053
              DRIZZLE_YYABORT;
1466
2065
        | DEFAULT {}
1467
2066
        ;
1468
2067
 
 
2068
opt_binary:
 
2069
          /* empty */ { Lex->charset=NULL; }
 
2070
        | BYTE_SYM { Lex->charset=&my_charset_bin; }
 
2071
        | BINARY { Lex->type|= BINCMP_FLAG; }
 
2072
        ;
 
2073
 
 
2074
ws_nweights:
 
2075
        '(' real_ulong_num
 
2076
        {
 
2077
          if ($2 == 0)
 
2078
          {
 
2079
            my_parse_error(ER(ER_SYNTAX_ERROR));
 
2080
            DRIZZLE_YYABORT;
 
2081
          }
 
2082
        }
 
2083
        ')'
 
2084
        { $$= $2; }
 
2085
        ;
 
2086
 
 
2087
ws_level_flag_desc:
 
2088
        ASC { $$= 0; }
 
2089
        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
 
2090
        ;
 
2091
 
 
2092
ws_level_flag_reverse:
 
2093
        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
 
2094
 
 
2095
ws_level_flags:
 
2096
        /* empty */ { $$= 0; }
 
2097
        | ws_level_flag_desc { $$= $1; }
 
2098
        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
 
2099
        | ws_level_flag_reverse { $$= $1 ; }
 
2100
        ;
 
2101
 
 
2102
ws_level_number:
 
2103
        real_ulong_num
 
2104
        {
 
2105
          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
 
2106
          $$--;
 
2107
        }
 
2108
        ;
 
2109
 
 
2110
ws_level_list_item:
 
2111
        ws_level_number ws_level_flags
 
2112
        {
 
2113
          $$= (1 | $2) << $1;
 
2114
        }
 
2115
        ;
 
2116
 
 
2117
ws_level_list:
 
2118
        ws_level_list_item { $$= $1; }
 
2119
        | ws_level_list ',' ws_level_list_item { $$|= $3; }
 
2120
        ;
 
2121
 
 
2122
ws_level_range:
 
2123
        ws_level_number '-' ws_level_number
 
2124
        {
 
2125
          uint32_t start= $1;
 
2126
          uint32_t end= $3;
 
2127
          for ($$= 0; start <= end; start++)
 
2128
            $$|= (1 << start);
 
2129
        }
 
2130
        ;
 
2131
 
 
2132
ws_level_list_or_range:
 
2133
        ws_level_list { $$= $1; }
 
2134
        | ws_level_range { $$= $1; }
 
2135
        ;
 
2136
 
 
2137
opt_ws_levels:
 
2138
        /* empty*/ { $$= 0; }
 
2139
        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
 
2140
        ;
 
2141
 
1469
2142
opt_primary:
1470
2143
          /* empty */
1471
2144
        | PRIMARY_SYM
1493
2166
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
1494
2167
        | ident
1495
2168
          {
1496
 
            Lex->ref_list.empty();
1497
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
2169
            LEX *lex= Lex;
 
2170
            lex->ref_list.empty();
 
2171
            lex->ref_list.push_back(new Key_part_spec($1, 0));
1498
2172
          }
1499
2173
        ;
1500
2174
 
1501
2175
opt_match_clause:
1502
2176
          /* empty */
1503
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
 
2177
          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
1504
2178
        | MATCH FULL
1505
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
 
2179
          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
1506
2180
        | MATCH PARTIAL
1507
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
 
2181
          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
1508
2182
        | MATCH SIMPLE_SYM
1509
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
 
2183
          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
1510
2184
        ;
1511
2185
 
1512
2186
opt_on_update_delete:
1513
2187
          /* empty */
1514
2188
          {
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;
 
2189
            LEX *lex= Lex;
 
2190
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
2191
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1517
2192
          }
1518
2193
        | ON UPDATE_SYM delete_option
1519
2194
          {
1520
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1521
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
2195
            LEX *lex= Lex;
 
2196
            lex->fk_update_opt= $3;
 
2197
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1522
2198
          }
1523
2199
        | ON DELETE_SYM delete_option
1524
2200
          {
1525
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1526
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
2201
            LEX *lex= Lex;
 
2202
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
2203
            lex->fk_delete_opt= $3;
1527
2204
          }
1528
2205
        | ON UPDATE_SYM delete_option
1529
2206
          ON DELETE_SYM delete_option
1530
2207
          {
1531
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1532
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
 
2208
            LEX *lex= Lex;
 
2209
            lex->fk_update_opt= $3;
 
2210
            lex->fk_delete_opt= $6;
1533
2211
          }
1534
2212
        | ON DELETE_SYM delete_option
1535
2213
          ON UPDATE_SYM delete_option
1536
2214
          {
1537
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
1538
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
2215
            LEX *lex= Lex;
 
2216
            lex->fk_update_opt= $6;
 
2217
            lex->fk_delete_opt= $3;
1539
2218
          }
1540
2219
        ;
1541
2220
 
1542
2221
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;  }
 
2222
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
 
2223
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
 
2224
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
 
2225
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
 
2226
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
1548
2227
        ;
1549
2228
 
1550
2229
key_type:
1579
2258
 
1580
2259
init_key_options:
1581
2260
          {
1582
 
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
 
2261
            Lex->key_create_info= default_key_create_info;
1583
2262
          }
1584
2263
        ;
1585
2264
 
1586
2265
/*
1587
 
  For now, key_alg initializies Lex->key_create_info.
 
2266
  For now, key_alg initializies lex->key_create_info.
1588
2267
  In the future, when all key options are after key definition,
1589
2268
  we can remove key_alg and move init_key_options to key_options
1590
2269
*/
1605
2284
        ;
1606
2285
 
1607
2286
key_using_alg:
1608
 
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2287
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
 
2288
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
1609
2289
        ;
1610
2290
 
1611
2291
key_opt:
1612
2292
          key_using_alg
1613
2293
        | KEY_BLOCK_SIZE opt_equal ulong_num
1614
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
 
2294
          { Lex->key_create_info.block_size= $3; }
1615
2295
        | COMMENT_SYM TEXT_STRING_sys
1616
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
 
2296
          { Lex->key_create_info.comment= $2; }
1617
2297
        ;
1618
2298
 
1619
2299
btree_or_rtree:
1658
2338
*/
1659
2339
 
1660
2340
alter:
1661
 
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
 
2341
          ALTER build_method opt_ignore TABLE_SYM table_ident
1662
2342
          {
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
 
            {
 
2343
            Session *session= YYSession;
 
2344
            LEX *lex= session->lex;
 
2345
            lex->name.str= 0;
 
2346
            lex->name.length= 0;
 
2347
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2348
            lex->duplicates= DUP_ERROR; 
 
2349
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
 
2350
                                                   TL_OPTION_UPDATING))
1668
2351
              DRIZZLE_YYABORT;
1669
 
            }
1670
 
 
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());
 
2352
            lex->alter_info.reset();
 
2353
            lex->col_list.empty();
 
2354
            lex->select_lex.init_order();
 
2355
            lex->select_lex.db=
 
2356
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2357
            memset(&lex->create_info, 0, sizeof(lex->create_info));
 
2358
            lex->create_info.db_type= 0;
 
2359
            lex->create_info.default_table_charset= NULL;
 
2360
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
 
2361
            lex->alter_info.reset();
 
2362
            lex->alter_info.build_method= $2;
1674
2363
          }
1675
2364
          alter_commands
1676
2365
          {}
1677
 
        | ALTER_SYM DATABASE schema_name
 
2366
        | ALTER DATABASE ident_or_empty
1678
2367
          {
1679
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
2368
            Lex->create_info.default_table_charset= NULL;
 
2369
            Lex->create_info.used_fields= 0;
1680
2370
          }
1681
 
          default_collation_schema
 
2371
          create_database_options
1682
2372
          {
1683
 
            Lex->name= $3;
1684
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
 
2373
            LEX *lex=Lex;
 
2374
            lex->sql_command=SQLCOM_ALTER_DB;
 
2375
            lex->name= $3;
 
2376
            if (lex->name.str == NULL &&
 
2377
                lex->copy_db_to(&lex->name.str, &lex->name.length))
1685
2378
              DRIZZLE_YYABORT;
1686
2379
          }
1687
2380
        ;
1688
2381
 
 
2382
ident_or_empty:
 
2383
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2384
        | ident { $$= $1; }
 
2385
        ;
 
2386
 
1689
2387
alter_commands:
1690
2388
          /* 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
 
          }
 
2389
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
 
2390
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
1701
2391
        | alter_list
1702
2392
        ;
1703
2393
 
1722
2412
        ;
1723
2413
 
1724
2414
add_column:
1725
 
          ADD_SYM opt_column
 
2415
          ADD opt_column
1726
2416
          {
1727
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1728
 
 
1729
 
            statement->change=0;
1730
 
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2417
            LEX *lex=Lex;
 
2418
            lex->change=0;
 
2419
            lex->alter_info.flags|= ALTER_ADD_COLUMN;
1731
2420
          }
1732
2421
        ;
1733
2422
 
1734
2423
alter_list_item:
1735
2424
          add_column column_def opt_place { }
1736
 
        | ADD_SYM key_def
 
2425
        | ADD key_def
1737
2426
          {
1738
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1739
 
 
1740
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
2427
            Lex->alter_info.flags|= ALTER_ADD_INDEX;
1741
2428
          }
1742
2429
        | add_column '(' field_list ')'
1743
2430
          {
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);
 
2431
            Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX;
1748
2432
          }
1749
 
        | CHANGE_SYM opt_column field_ident
 
2433
        | CHANGE opt_column field_ident
1750
2434
          {
1751
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1752
 
            statement->change= $3.str;
1753
 
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2435
            LEX *lex=Lex;
 
2436
            lex->change= $3.str;
 
2437
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
1754
2438
          }
1755
2439
          field_spec opt_place
1756
2440
        | MODIFY_SYM opt_column field_ident
1757
2441
          {
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);
 
2442
            LEX *lex=Lex;
 
2443
            lex->length=lex->dec=0; lex->type=0;
 
2444
            lex->default_value= lex->on_update_value= 0;
 
2445
            lex->comment=null_lex_str;
 
2446
            lex->charset= NULL;
 
2447
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2448
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
2449
            lex->vcol_info= NULL;
1768
2450
          }
1769
2451
          field_def
1770
2452
          {
1771
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1772
 
 
1773
 
            if (add_field_to_list(Lex->session,&$3,
 
2453
            LEX *lex=Lex;
 
2454
            if (add_field_to_list(lex->session,&$3,
1774
2455
                                  (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))
 
2456
                                  lex->length,lex->dec,lex->type,
 
2457
                                  lex->column_format,
 
2458
                                  lex->default_value, lex->on_update_value,
 
2459
                                  &lex->comment,
 
2460
                                  $3.str, &lex->interval_list, lex->charset,
 
2461
                                  lex->vcol_info))
1781
2462
              DRIZZLE_YYABORT;
1782
2463
          }
1783
2464
          opt_place
1784
2465
        | DROP opt_column field_ident
1785
2466
          {
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);
 
2467
            LEX *lex=Lex;
 
2468
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
 
2469
                                                               $3.str));
 
2470
            lex->alter_info.flags|= ALTER_DROP_COLUMN;
1790
2471
          }
1791
2472
        | DROP FOREIGN KEY_SYM opt_ident
1792
2473
          {
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);
 
2474
            Lex->alter_info.flags|= ALTER_DROP_INDEX | ALTER_FOREIGN_KEY;
1798
2475
          }
1799
2476
        | DROP PRIMARY_SYM KEY_SYM
1800
2477
          {
1801
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1802
 
 
1803
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2478
            LEX *lex=Lex;
 
2479
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
1804
2480
                                                               "PRIMARY"));
1805
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2481
            lex->alter_info.flags|= ALTER_DROP_INDEX;
1806
2482
          }
1807
2483
        | DROP key_or_index field_ident
1808
2484
          {
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);
 
2485
            LEX *lex=Lex;
 
2486
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
2487
                                                               $3.str));
 
2488
            lex->alter_info.flags|= ALTER_DROP_INDEX;
1814
2489
          }
1815
2490
        | DISABLE_SYM KEYS
1816
2491
          {
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);
 
2492
            LEX *lex=Lex;
 
2493
            lex->alter_info.keys_onoff= DISABLE;
 
2494
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
1821
2495
          }
1822
2496
        | ENABLE_SYM KEYS
1823
2497
          {
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);
 
2498
            LEX *lex=Lex;
 
2499
            lex->alter_info.keys_onoff= ENABLE;
 
2500
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2501
          }
 
2502
        | ALTER opt_column field_ident SET DEFAULT signed_literal
 
2503
          {
 
2504
            LEX *lex=Lex;
 
2505
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
 
2506
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2507
          }
 
2508
        | ALTER opt_column field_ident DROP DEFAULT
 
2509
          {
 
2510
            LEX *lex=Lex;
 
2511
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
 
2512
                                                                  (Item*) 0));
 
2513
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
1842
2514
          }
1843
2515
        | RENAME opt_to table_ident
1844
2516
          {
1845
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2517
            LEX *lex=Lex;
1846
2518
            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))
 
2519
            lex->select_lex.db=$3->db.str;
 
2520
            if (lex->select_lex.db == NULL &&
 
2521
                lex->copy_db_to(&lex->select_lex.db, &dummy))
1851
2522
            {
1852
2523
              DRIZZLE_YYABORT;
1853
2524
            }
1854
 
 
1855
 
            if (check_table_name($3->table.str,$3->table.length))
 
2525
            if (check_table_name($3->table.str,$3->table.length) || ($3->db.str && check_db_name(&$3->db)))
1856
2526
            {
1857
2527
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
1858
2528
              DRIZZLE_YYABORT;
1859
2529
            }
1860
 
 
1861
 
            Lex->name= $3->table;
1862
 
            statement->alter_info.flags.set(ALTER_RENAME);
 
2530
            lex->name= $3->table;
 
2531
            lex->alter_info.flags|= ALTER_RENAME;
1863
2532
          }
1864
2533
        | CONVERT_SYM TO_SYM collation_name_or_default
1865
2534
          {
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 |
 
2535
            if (!$3)
 
2536
            {
 
2537
              Session *session= YYSession;
 
2538
              $3= session->variables.collation_database;
 
2539
            }
 
2540
            LEX *lex= Lex;
 
2541
            lex->create_info.table_charset=
 
2542
            lex->create_info.default_table_charset= $3;
 
2543
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
1871
2544
              HA_CREATE_USED_DEFAULT_CHARSET);
1872
 
            statement->alter_info.flags.set(ALTER_CONVERT);
 
2545
            lex->alter_info.flags|= ALTER_CONVERT;
1873
2546
          }
1874
2547
        | create_table_options_space_separated
1875
2548
          {
1876
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1877
 
 
1878
 
            statement->alter_info.flags.set(ALTER_OPTIONS);
 
2549
            LEX *lex=Lex;
 
2550
            lex->alter_info.flags|= ALTER_OPTIONS;
1879
2551
          }
1880
2552
        | FORCE_SYM
1881
2553
          {
1882
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1883
 
 
1884
 
            statement->alter_info.flags.set(ALTER_FORCE);
 
2554
            Lex->alter_info.flags|= ALTER_FORCE;
1885
2555
          }
1886
2556
        | alter_order_clause
1887
2557
          {
1888
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1889
 
 
1890
 
            statement->alter_info.flags.set(ALTER_ORDER);
 
2558
            LEX *lex=Lex;
 
2559
            lex->alter_info.flags|= ALTER_ORDER;
1891
2560
          }
1892
2561
        ;
1893
2562
 
1905
2574
          /* empty */ {}
1906
2575
        | AFTER_SYM ident
1907
2576
          {
1908
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2577
            store_position_for_column($2.str);
 
2578
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
1909
2579
          }
1910
2580
        | FIRST_SYM
1911
2581
          {
1912
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2582
            store_position_for_column(first_keyword);
 
2583
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
1913
2584
          }
1914
2585
        ;
1915
2586
 
1920
2591
        | AS {}
1921
2592
        ;
1922
2593
 
 
2594
/*
 
2595
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
 
2596
*/
 
2597
 
 
2598
slave:
 
2599
          START_SYM SLAVE slave_thread_opts
 
2600
          {
 
2601
            LEX *lex=Lex;
 
2602
            lex->sql_command = SQLCOM_SLAVE_START;
 
2603
            lex->type = 0;
 
2604
            /* We'll use mi structure for UNTIL options */
 
2605
            memset(&lex->mi, 0, sizeof(lex->mi));
 
2606
            /* If you change this code don't forget to update SLAVE START too */
 
2607
          }
 
2608
          slave_until
 
2609
          {}
 
2610
        | STOP_SYM SLAVE slave_thread_opts
 
2611
          {
 
2612
            LEX *lex=Lex;
 
2613
            lex->sql_command = SQLCOM_SLAVE_STOP;
 
2614
            lex->type = 0;
 
2615
            /* If you change this code don't forget to update SLAVE STOP too */
 
2616
          }
 
2617
        | SLAVE START_SYM slave_thread_opts
 
2618
          {
 
2619
            LEX *lex=Lex;
 
2620
            lex->sql_command = SQLCOM_SLAVE_START;
 
2621
            lex->type = 0;
 
2622
            /* We'll use mi structure for UNTIL options */
 
2623
            memset(&lex->mi, 0, sizeof(lex->mi));
 
2624
          }
 
2625
          slave_until
 
2626
          {}
 
2627
        | SLAVE STOP_SYM slave_thread_opts
 
2628
          {
 
2629
            LEX *lex=Lex;
 
2630
            lex->sql_command = SQLCOM_SLAVE_STOP;
 
2631
            lex->type = 0;
 
2632
          }
 
2633
        ;
 
2634
 
1923
2635
start:
1924
2636
          START_SYM TRANSACTION_SYM start_transaction_opts
1925
2637
          {
1926
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2638
            LEX *lex= Lex;
 
2639
            lex->sql_command= SQLCOM_BEGIN;
 
2640
            lex->start_transaction_opt= $3;
1927
2641
          }
1928
2642
        ;
1929
2643
 
1930
2644
start_transaction_opts:
1931
 
          /*empty*/ { $$ = START_TRANS_NO_OPTIONS; }
 
2645
          /*empty*/ { $$ = 0; }
1932
2646
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
1933
2647
          {
1934
 
            $$= START_TRANS_OPT_WITH_CONS_SNAPSHOT;
1935
 
          }
 
2648
            $$= DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
 
2649
          }
 
2650
        ;
 
2651
 
 
2652
slave_thread_opts:
 
2653
          { Lex->slave_session_opt= 0; }
 
2654
          slave_thread_opt_list
 
2655
          {}
 
2656
        ;
 
2657
 
 
2658
slave_thread_opt_list:
 
2659
          slave_thread_opt
 
2660
        | slave_thread_opt_list ',' slave_thread_opt
 
2661
        ;
 
2662
 
 
2663
slave_thread_opt:
 
2664
          /*empty*/ {}
 
2665
        | SQL_THREAD   { Lex->slave_session_opt|=SLAVE_SQL; }
 
2666
        | RELAY_THREAD { Lex->slave_session_opt|=SLAVE_IO; }
 
2667
        ;
 
2668
 
 
2669
slave_until:
 
2670
          /*empty*/ {}
 
2671
        | UNTIL_SYM slave_until_opts
 
2672
          {
 
2673
            LEX *lex=Lex;
 
2674
            if (((lex->mi.log_file_name || lex->mi.pos) && (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
 
2675
                !((lex->mi.log_file_name && lex->mi.pos) ||
 
2676
                  (lex->mi.relay_log_name && lex->mi.relay_log_pos)))
 
2677
            {
 
2678
               my_message(ER_BAD_SLAVE_UNTIL_COND,
 
2679
                          ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0));
 
2680
               DRIZZLE_YYABORT;
 
2681
            }
 
2682
          }
 
2683
        ;
 
2684
 
 
2685
slave_until_opts:
 
2686
          master_file_def
 
2687
        | slave_until_opts ',' master_file_def
 
2688
        ;
 
2689
 
 
2690
checksum:
 
2691
          CHECKSUM_SYM table_or_tables
 
2692
          {
 
2693
            LEX *lex=Lex;
 
2694
            lex->sql_command = SQLCOM_CHECKSUM;
 
2695
          }
 
2696
          table_list opt_checksum_type
 
2697
          {}
 
2698
        ;
 
2699
 
 
2700
opt_checksum_type:
 
2701
          /* nothing */ { Lex->check_opt.flags= 0; }
 
2702
        | QUICK         { Lex->check_opt.flags= T_QUICK; }
 
2703
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
 
2704
        ;
 
2705
 
 
2706
repair:
 
2707
          REPAIR table_or_tables
 
2708
          {
 
2709
            LEX *lex=Lex;
 
2710
            lex->sql_command = SQLCOM_REPAIR;
 
2711
            lex->check_opt.init();
 
2712
          }
 
2713
          table_list opt_mi_repair_type
 
2714
          {}
 
2715
        ;
 
2716
 
 
2717
opt_mi_repair_type:
 
2718
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2719
        | mi_repair_types {}
 
2720
        ;
 
2721
 
 
2722
mi_repair_types:
 
2723
          mi_repair_type {}
 
2724
        | mi_repair_type mi_repair_types {}
 
2725
        ;
 
2726
 
 
2727
mi_repair_type:
 
2728
          QUICK        { Lex->check_opt.flags|= T_QUICK; }
 
2729
        | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
 
2730
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; }
1936
2731
        ;
1937
2732
 
1938
2733
analyze:
1939
2734
          ANALYZE_SYM table_or_tables
1940
2735
          {
1941
 
            Lex->statement= new statement::Analyze(YYSession);
 
2736
            LEX *lex=Lex;
 
2737
            lex->sql_command = SQLCOM_ANALYZE;
 
2738
            lex->check_opt.init();
1942
2739
          }
1943
2740
          table_list
1944
2741
          {}
1945
2742
        ;
1946
2743
 
 
2744
binlog_base64_event:
 
2745
          BINLOG_SYM TEXT_STRING_sys
 
2746
          {
 
2747
            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
 
2748
            Lex->comment= $2;
 
2749
          }
 
2750
        ;
 
2751
 
1947
2752
check:
1948
2753
          CHECK_SYM table_or_tables
1949
2754
          {
1950
 
            Lex->statement= new statement::Check(YYSession);
 
2755
            LEX *lex=Lex;
 
2756
 
 
2757
            lex->sql_command = SQLCOM_CHECK;
 
2758
            lex->check_opt.init();
 
2759
          }
 
2760
          table_list opt_mi_check_type
 
2761
          {}
 
2762
        ;
 
2763
 
 
2764
opt_mi_check_type:
 
2765
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2766
        | mi_check_types {}
 
2767
        ;
 
2768
 
 
2769
mi_check_types:
 
2770
          mi_check_type {}
 
2771
        | mi_check_type mi_check_types {}
 
2772
        ;
 
2773
 
 
2774
mi_check_type:
 
2775
          QUICK               { Lex->check_opt.flags|= T_QUICK; }
 
2776
        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
 
2777
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
 
2778
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
 
2779
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
 
2780
        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
 
2781
        ;
 
2782
 
 
2783
optimize:
 
2784
          OPTIMIZE table_or_tables
 
2785
          {
 
2786
            LEX *lex=Lex;
 
2787
            lex->sql_command = SQLCOM_OPTIMIZE;
 
2788
            lex->check_opt.init();
1951
2789
          }
1952
2790
          table_list
1953
2791
          {}
1956
2794
rename:
1957
2795
          RENAME table_or_tables
1958
2796
          {
1959
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2797
            Lex->sql_command= SQLCOM_RENAME_TABLE;
1960
2798
          }
1961
2799
          table_to_table_list
1962
2800
          {}
1970
2808
table_to_table:
1971
2809
          table_ident TO_SYM table_ident
1972
2810
          {
1973
 
            Select_Lex *sl= Lex->current_select;
1974
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2811
            LEX *lex=Lex;
 
2812
            SELECT_LEX *sl= lex->current_select;
 
2813
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
1975
2814
                                       TL_IGNORE) ||
1976
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2815
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
1977
2816
                                       TL_IGNORE))
1978
2817
              DRIZZLE_YYABORT;
1979
2818
          }
1980
2819
        ;
1981
2820
 
 
2821
keycache:
 
2822
          CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
 
2823
          {
 
2824
            LEX *lex=Lex;
 
2825
            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
 
2826
            lex->ident= $5;
 
2827
          }
 
2828
        ;
 
2829
 
 
2830
keycache_list:
 
2831
          assign_to_keycache
 
2832
        | keycache_list ',' assign_to_keycache
 
2833
        ;
 
2834
 
 
2835
assign_to_keycache:
 
2836
          table_ident cache_keys_spec
 
2837
          {
 
2838
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
 
2839
                                           Select->pop_index_hints()))
 
2840
              DRIZZLE_YYABORT;
 
2841
          }
 
2842
        ;
 
2843
 
 
2844
key_cache_name:
 
2845
          ident    { $$= $1; }
 
2846
        | DEFAULT  { $$ = default_key_cache_base; }
 
2847
        ;
 
2848
 
 
2849
cache_keys_spec:
 
2850
          {
 
2851
            Lex->select_lex.alloc_index_hints(YYSession);
 
2852
            Select->set_index_hint_type(INDEX_HINT_USE, 
 
2853
                                        global_system_variables.old_mode ? 
 
2854
                                        INDEX_HINT_MASK_JOIN : 
 
2855
                                        INDEX_HINT_MASK_ALL);
 
2856
          }
 
2857
          cache_key_list_or_empty
 
2858
        ;
 
2859
 
 
2860
cache_key_list_or_empty:
 
2861
          /* empty */ { }
 
2862
        | key_or_index '(' opt_key_usage_list ')'
 
2863
        ;
 
2864
 
1982
2865
/*
1983
2866
  Select : retrieve data from table
1984
2867
*/
1987
2870
select:
1988
2871
          select_init
1989
2872
          {
1990
 
            Lex->statement= new statement::Select(YYSession);
 
2873
            LEX *lex= Lex;
 
2874
            lex->sql_command= SQLCOM_SELECT;
1991
2875
          }
1992
2876
        ;
1993
2877
 
2000
2884
select_paren:
2001
2885
          SELECT_SYM select_part2
2002
2886
          {
2003
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2887
            if (setup_select_in_parentheses(Lex))
2004
2888
              DRIZZLE_YYABORT;
2005
2889
          }
2006
2890
        | '(' select_paren ')'
2010
2894
select_paren_derived:
2011
2895
          SELECT_SYM select_part2_derived
2012
2896
          {
2013
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2897
            if (setup_select_in_parentheses(Lex))
2014
2898
              DRIZZLE_YYABORT;
2015
2899
          }
2016
2900
        | '(' select_paren_derived ')'
2019
2903
select_init2:
2020
2904
          select_part2
2021
2905
          {
2022
 
            Select_Lex * sel= Lex->current_select;
2023
 
            if (Lex->current_select->set_braces(0))
 
2906
            LEX *lex= Lex;
 
2907
            SELECT_LEX * sel= lex->current_select;
 
2908
            if (lex->current_select->set_braces(0))
2024
2909
            {
2025
 
              parser::my_parse_error(YYSession->m_lip);
 
2910
              my_parse_error(ER(ER_SYNTAX_ERROR));
2026
2911
              DRIZZLE_YYABORT;
2027
2912
            }
2028
2913
            if (sel->linkage == UNION_TYPE &&
2029
2914
                sel->master_unit()->first_select()->braces)
2030
2915
            {
2031
 
              parser::my_parse_error(YYSession->m_lip);
 
2916
              my_parse_error(ER(ER_SYNTAX_ERROR));
2032
2917
              DRIZZLE_YYABORT;
2033
2918
            }
2034
2919
          }
2037
2922
 
2038
2923
select_part2:
2039
2924
          {
2040
 
            Select_Lex *sel= Lex->current_select;
 
2925
            LEX *lex= Lex;
 
2926
            SELECT_LEX *sel= lex->current_select;
2041
2927
            if (sel->linkage != UNION_TYPE)
2042
 
              init_select(Lex);
2043
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2928
              mysql_init_select(lex);
 
2929
            lex->current_select->parsing_place= SELECT_LIST;
2044
2930
          }
2045
2931
          select_options select_item_list
2046
2932
          {
2047
 
            Lex->current_select->parsing_place= NO_MATTER;
 
2933
            Select->parsing_place= NO_MATTER;
2048
2934
          }
2049
2935
          select_into select_lock_type
2050
2936
        ;
2061
2947
          FROM join_table_list where_clause group_clause having_clause
2062
2948
          opt_order_clause opt_limit_clause
2063
2949
          {
2064
 
            Lex->current_select->context.table_list=
2065
 
              Lex->current_select->context.first_name_resolution_table=
2066
 
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
 
2950
            Select->context.table_list=
 
2951
              Select->context.first_name_resolution_table= 
 
2952
                (TableList *) Select->table_list.first;
2067
2953
          }
2068
2954
        ;
2069
2955
 
2070
2956
select_options:
2071
2957
          /* empty*/
2072
2958
        | select_option_list
2073
 
          { }
 
2959
          {
 
2960
            if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
 
2961
            {
 
2962
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
2963
              DRIZZLE_YYABORT;
 
2964
            }
 
2965
          }
2074
2966
        ;
2075
2967
 
2076
2968
select_option_list:
2078
2970
        | select_option
2079
2971
        ;
2080
2972
 
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
2973
select_option:
2129
 
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2974
          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
 
2975
        | HIGH_PRIORITY
 
2976
          {
 
2977
            if (check_simple_select())
 
2978
              DRIZZLE_YYABORT;
 
2979
            Lex->lock_option= TL_READ_HIGH_PRIORITY;
 
2980
          }
 
2981
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
 
2982
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
 
2983
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
2130
2984
        | SQL_BUFFER_RESULT
2131
2985
          {
2132
 
            if (check_simple_select(YYSession))
 
2986
            if (check_simple_select())
2133
2987
              DRIZZLE_YYABORT;
2134
 
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
 
2988
            Select->options|= OPTION_BUFFER_RESULT;
2135
2989
          }
2136
 
        | select_option_small_or_big
2137
 
          { }
2138
 
        | select_option_distinct_or_all
2139
 
          { }
2140
2990
        | SQL_CALC_FOUND_ROWS
2141
2991
          {
2142
 
            if (check_simple_select(YYSession))
 
2992
            if (check_simple_select())
2143
2993
              DRIZZLE_YYABORT;
2144
 
            Lex->current_select->options|= OPTION_FOUND_ROWS;
 
2994
            Select->options|= OPTION_FOUND_ROWS;
2145
2995
          }
 
2996
        | ALL { Select->options|= SELECT_ALL; }
2146
2997
        ;
2147
2998
 
2148
2999
select_lock_type:
2149
3000
          /* empty */
2150
3001
        | FOR_SYM UPDATE_SYM
2151
3002
          {
2152
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
3003
            LEX *lex=Lex;
 
3004
            lex->current_select->set_lock_for_tables(TL_WRITE);
2153
3005
          }
2154
3006
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2155
3007
          {
2156
 
            Lex->current_select->
 
3008
            LEX *lex=Lex;
 
3009
            lex->current_select->
2157
3010
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2158
3011
          }
2159
3012
        ;
2163
3016
        | select_item
2164
3017
        | '*'
2165
3018
          {
2166
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
2167
 
                                                          context,
2168
 
                                                          NULL, NULL, "*")))
 
3019
            Session *session= YYSession;
 
3020
            if (add_item_to_list(session,
 
3021
                                 new Item_field(&session->lex->current_select->
 
3022
                                                context,
 
3023
                                                NULL, NULL, "*")))
2169
3024
              DRIZZLE_YYABORT;
2170
 
            (YYSession->lex->current_select->with_wild)++;
 
3025
            (session->lex->current_select->with_wild)++;
2171
3026
          }
2172
3027
        ;
2173
3028
 
2174
3029
select_item:
2175
3030
          remember_name table_wild remember_end
2176
3031
          {
2177
 
            if (YYSession->add_item_to_list($2))
 
3032
            Session *session= YYSession;
 
3033
 
 
3034
            if (add_item_to_list(session, $2))
2178
3035
              DRIZZLE_YYABORT;
2179
3036
          }
2180
3037
        | remember_name expr remember_end select_alias
2181
3038
          {
 
3039
            Session *session= YYSession;
2182
3040
            assert($1 < $3);
2183
3041
 
2184
 
            if (YYSession->add_item_to_list($2))
 
3042
            if (add_item_to_list(session, $2))
2185
3043
              DRIZZLE_YYABORT;
2186
 
 
2187
3044
            if ($4.str)
2188
3045
            {
2189
3046
              $2->is_autogenerated_name= false;
2191
3048
            }
2192
3049
            else if (!$2->name)
2193
3050
            {
2194
 
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
 
3051
              $2->set_name($1, (uint) ($3 - $1), session->charset());
2195
3052
            }
2196
3053
          }
2197
3054
        ;
2198
3055
 
2199
3056
remember_name:
2200
3057
          {
2201
 
            Lex_input_stream *lip= YYSession->m_lip;
 
3058
            Session *session= YYSession;
 
3059
            Lex_input_stream *lip= session->m_lip;
2202
3060
            $$= (char*) lip->get_cpp_tok_start();
2203
3061
          }
2204
3062
        ;
2205
3063
 
2206
3064
remember_end:
2207
3065
          {
2208
 
            Lex_input_stream *lip= YYSession->m_lip;
 
3066
            Session *session= YYSession;
 
3067
            Lex_input_stream *lip= session->m_lip;
2209
3068
            $$= (char*) lip->get_cpp_tok_end();
2210
3069
          }
2211
3070
        ;
2358
3217
          }
2359
3218
        | bit_expr not IN_SYM '(' subselect ')'
2360
3219
          {
2361
 
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
2362
 
            $$= negate_expression(YYSession, item);
 
3220
            Session *session= YYSession;
 
3221
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
3222
            $$= negate_expression(session, item);
2363
3223
          }
2364
3224
        | bit_expr IN_SYM '(' expr ')'
2365
3225
          {
2366
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
3226
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2367
3227
          }
2368
3228
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2369
 
          {
 
3229
          { 
2370
3230
            $6->push_front($4);
2371
3231
            $6->push_front($1);
2372
3232
            $$= new (YYSession->mem_root) Item_func_in(*$6);
2373
3233
          }
2374
3234
        | bit_expr not IN_SYM '(' expr ')'
2375
3235
          {
2376
 
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
3236
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
2377
3237
          }
2378
3238
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2379
3239
          {
2384
3244
            $$= item;
2385
3245
          }
2386
3246
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
2387
 
          {
2388
 
            $$= new Item_func_between($1,$3,$5);
2389
 
          }
 
3247
          { $$= new Item_func_between($1,$3,$5); }
2390
3248
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
2391
3249
          {
2392
3250
            Item_func_between *item= new Item_func_between($1,$4,$6);
2394
3252
            $$= item;
2395
3253
          }
2396
3254
        | bit_expr LIKE simple_expr opt_escape
2397
 
          { 
2398
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
2399
 
          }
 
3255
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
2400
3256
        | 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
 
          }
 
3257
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
2425
3258
        | bit_expr
2426
3259
        ;
2427
3260
 
2437
3270
        | bit_expr '*' bit_expr %prec '*'
2438
3271
          { $$= new Item_func_mul($1,$3); }
2439
3272
        | bit_expr '/' bit_expr %prec '/'
2440
 
          { $$= new Item_func_div(YYSession,$1,$3); }
 
3273
          { $$= new Item_func_div($1,$3); }
2441
3274
        | bit_expr '%' bit_expr %prec '%'
2442
3275
          { $$= new Item_func_mod($1,$3); }
2443
3276
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2481
3314
        | function_call_conflict
2482
3315
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
2483
3316
          {
2484
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
 
3317
            Session *session= YYSession;
 
3318
            Item *i1= new (session->mem_root) Item_string($3.str,
2485
3319
                                                      $3.length,
2486
 
                                                      YYSession->charset());
2487
 
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
 
3320
                                                      session->charset());
 
3321
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
2488
3322
          }
2489
3323
        | literal
2490
3324
        | variable
2491
3325
        | sum_expr
2492
 
          {
2493
 
            Lex->setSumExprUsed();
2494
 
          }
2495
3326
        | '+' simple_expr %prec NEG { $$= $2; }
2496
3327
        | '-' simple_expr %prec NEG
2497
3328
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2498
3329
        | '(' subselect ')'
2499
 
          {
 
3330
          { 
2500
3331
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
2501
3332
          }
2502
3333
        | '(' expr ')' { $$= $2; }
2522
3353
          }
2523
3354
        | CAST_SYM '(' expr AS cast_type ')'
2524
3355
          {
2525
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2526
 
                                 Lex->charset);
 
3356
            LEX *lex= Lex;
 
3357
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
 
3358
                                 lex->charset);
2527
3359
            if (!$$)
2528
3360
              DRIZZLE_YYABORT;
2529
3361
          }
2541
3373
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
2542
3374
                                                         $3);
2543
3375
          }
2544
 
        | VALUES '(' simple_ident ')'
 
3376
        | VALUES '(' simple_ident_nospvar ')'
2545
3377
          {
2546
3378
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
2547
3379
                                                        $3);
2562
3394
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
2563
3395
        | CURRENT_USER optional_braces
2564
3396
          {
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);
 
3397
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
2571
3398
          }
2572
3399
        | DATE_SYM '(' expr ')'
2573
3400
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
2576
3403
        | HOUR_SYM '(' expr ')'
2577
3404
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
2578
3405
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
2579
 
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
 
3406
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
2580
3407
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
2581
3408
          {
2582
 
            List<Item> *list= new (YYSession->mem_root) List<Item>;
 
3409
            Session *session= YYSession;
 
3410
            List<Item> *list= new (session->mem_root) List<Item>;
2583
3411
            list->push_front($5);
2584
3412
            list->push_front($3);
2585
 
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
2586
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3413
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3414
            $$= new (session->mem_root) Item_func_interval(item);
2587
3415
          }
2588
3416
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
2589
3417
          {
 
3418
            Session *session= YYSession;
2590
3419
            $7->push_front($5);
2591
3420
            $7->push_front($3);
2592
 
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
2593
 
            $$= new (YYSession->mem_root) Item_func_interval(item);
 
3421
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3422
            $$= new (session->mem_root) Item_func_interval(item);
2594
3423
          }
2595
3424
        | LEFT '(' expr ',' expr ')'
2596
3425
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
2602
3431
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
2603
3432
        | SECOND_SYM '(' expr ')'
2604
3433
          { $$= new (YYSession->mem_root) Item_func_second($3); }
2605
 
        | TIMESTAMP_SYM '(' expr ')'
 
3434
        | TIME_SYM '(' expr ')'
 
3435
          { $$= new (YYSession->mem_root) Item_time_typecast($3); }
 
3436
        | TIMESTAMP '(' expr ')'
2606
3437
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
 
3438
        | TIMESTAMP '(' expr ',' expr ')'
 
3439
          { $$= new (YYSession->mem_root) Item_func_add_time($3, $5, 1, 0); }
2607
3440
        | TRIM '(' expr ')'
2608
3441
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
2609
3442
        | TRIM '(' LEADING expr FROM expr ')'
2622
3455
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
2623
3456
        | USER '(' ')'
2624
3457
          {
2625
 
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
2626
 
            {
2627
 
              DRIZZLE_YYABORT;
2628
 
            }
2629
 
            Lex->setCacheable(false);
 
3458
            $$= new (YYSession->mem_root) Item_func_user();
2630
3459
          }
2631
3460
        | YEAR_SYM '(' expr ')'
2632
3461
          { $$= new (YYSession->mem_root) Item_func_year($3); }
2640
3469
  MAINTAINER:
2641
3470
  The only reasons a function should be added here are:
2642
3471
  - for compatibility reasons with another SQL syntax (CURDATE),
 
3472
  - for typing reasons (GET_FORMAT)
2643
3473
  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
2644
3474
  discouraged.
2645
3475
*/
2654
3484
        | CURDATE optional_braces
2655
3485
          {
2656
3486
            $$= new (YYSession->mem_root) Item_func_curdate_local();
2657
 
            Lex->setCacheable(false);
 
3487
          }
 
3488
        | CURTIME optional_braces
 
3489
          {
 
3490
            $$= new (YYSession->mem_root) Item_func_curtime_local();
 
3491
          }
 
3492
        | CURTIME '(' expr ')'
 
3493
          {
 
3494
            $$= new (YYSession->mem_root) Item_func_curtime_local($3);
2658
3495
          }
2659
3496
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
2660
3497
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
2662
3499
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
2663
3500
        | EXTRACT_SYM '(' interval FROM expr ')'
2664
3501
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
 
3502
        | GET_FORMAT '(' date_time_type  ',' expr ')'
 
3503
          { $$= new (YYSession->mem_root) Item_func_get_format($3, $5); }
2665
3504
        | NOW_SYM optional_braces
2666
3505
          {
2667
3506
            $$= new (YYSession->mem_root) Item_func_now_local();
2668
 
            Lex->setCacheable(false);
2669
3507
          }
2670
3508
        | NOW_SYM '(' expr ')'
2671
3509
          {
2672
3510
            $$= new (YYSession->mem_root) Item_func_now_local($3);
2673
 
            Lex->setCacheable(false);
2674
3511
          }
2675
3512
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
2676
3513
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
2682
3519
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
2683
3520
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2684
3521
        | 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
 
          }
 
3522
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
2696
3523
        | 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
 
          }
 
3524
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
2707
3525
        | 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
 
          }
 
3526
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
2719
3527
        | 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
 
          }
 
3528
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
2730
3529
        | SYSDATE optional_braces
2731
 
          { 
2732
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
2733
 
            Lex->setCacheable(false);
 
3530
          {
 
3531
            if (global_system_variables.sysdate_is_now == 0)
 
3532
              $$= new (YYSession->mem_root) Item_func_sysdate_local();
 
3533
            else
 
3534
              $$= new (YYSession->mem_root) Item_func_now_local();
2734
3535
          }
2735
3536
        | SYSDATE '(' expr ')'
2736
 
          { 
2737
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
2738
 
            Lex->setCacheable(false);
 
3537
          {
 
3538
            if (global_system_variables.sysdate_is_now == 0)
 
3539
              $$= new (YYSession->mem_root) Item_func_sysdate_local($3);
 
3540
            else
 
3541
              $$= new (YYSession->mem_root) Item_func_now_local($3);
2739
3542
          }
2740
3543
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
2741
3544
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
2744
3547
        | UTC_DATE_SYM optional_braces
2745
3548
          {
2746
3549
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
2747
 
            Lex->setCacheable(false);
 
3550
          }
 
3551
        | UTC_TIME_SYM optional_braces
 
3552
          {
 
3553
            $$= new (YYSession->mem_root) Item_func_curtime_utc();
2748
3554
          }
2749
3555
        | UTC_TIMESTAMP_SYM optional_braces
2750
3556
          {
2751
3557
            $$= new (YYSession->mem_root) Item_func_now_utc();
2752
 
            Lex->setCacheable(false);
2753
3558
          }
2754
3559
        ;
2755
3560
 
2759
3564
  a dedicated rule is needed here.
2760
3565
*/
2761
3566
function_call_conflict:
2762
 
        COALESCE '(' expr_list ')'
 
3567
          ASCII_SYM '(' expr ')'
 
3568
          { $$= new (YYSession->mem_root) Item_func_ascii($3); }
 
3569
        | COALESCE '(' expr_list ')'
2763
3570
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
2764
3571
        | COLLATION_SYM '(' expr ')'
2765
3572
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
2766
3573
        | DATABASE '(' ')'
2767
3574
          {
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
 
            }
 
3575
            $$= new (YYSession->mem_root) Item_func_database();
2796
3576
          }
2797
3577
        | IF '(' expr ',' expr ',' expr ')'
2798
3578
          { $$= 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
3579
        | MICROSECOND_SYM '(' expr ')'
2816
3580
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
2817
3581
        | MOD_SYM '(' expr ',' expr ')'
2819
3583
        | QUARTER_SYM '(' expr ')'
2820
3584
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
2821
3585
        | REPEAT_SYM '(' expr ',' expr ')'
2822
 
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
 
3586
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
2823
3587
        | REPLACE '(' expr ',' expr ',' expr ')'
2824
 
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
 
3588
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
 
3589
        | REVERSE_SYM '(' expr ')'
 
3590
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
2825
3591
        | TRUNCATE_SYM '(' expr ',' expr ')'
2826
3592
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
2827
 
        | WAIT_SYM '(' expr ')'
2828
 
          {
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
 
            }
2836
 
          }
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
 
            }
 
3593
        | WEEK_SYM '(' expr ')'
 
3594
          {
 
3595
            Session *session= YYSession;
 
3596
            Item *i1= new (session->mem_root) Item_int((char*) "0",
 
3597
                                           session->variables.default_week_format,
 
3598
                                                   1);
 
3599
 
 
3600
            $$= new (session->mem_root) Item_func_week($3, i1);
 
3601
          }
 
3602
        | WEEK_SYM '(' expr ',' expr ')'
 
3603
          { $$= new (YYSession->mem_root) Item_func_week($3,$5); }
 
3604
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
 
3605
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
 
3606
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
 
3607
          {
 
3608
            $$= new (YYSession->mem_root)
 
3609
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
 
3610
          }
 
3611
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
 
3612
          {
 
3613
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3614
            $$= new (YYSession->mem_root)
 
3615
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
2855
3616
          }
2856
3617
        ;
2857
3618
 
2861
3622
  introduce side effects to the language in general.
2862
3623
  MAINTAINER:
2863
3624
  All the new functions implemented for new features should fit into
2864
 
  this category.
 
3625
  this category. The place to implement the function itself is
 
3626
  in sql/item_create.cc
2865
3627
*/
2866
3628
function_call_generic:
2867
3629
          IDENT_sys '('
2868
3630
          {
2869
 
            const plugin::Function *udf= plugin::Function::get($1.str, $1.length);
 
3631
            udf_func *udf= 0;
 
3632
            udf= find_udf($1.str, $1.length);
2870
3633
 
2871
 
            /* Temporary placing the result of getFunction in $3 */
 
3634
            /* Temporary placing the result of find_udf in $3 */
2872
3635
            $<udf>$= udf;
2873
3636
          }
2874
3637
          opt_udf_expr_list ')'
2875
3638
          {
 
3639
            Session *session= YYSession;
2876
3640
            Create_func *builder;
2877
3641
            Item *item= NULL;
2878
3642
 
2885
3649
 
2886
3650
              This will be revised with WL#2128 (SQL PATH)
2887
3651
            */
2888
 
            builder= find_native_function_builder($1);
 
3652
            builder= find_native_function_builder(session, $1);
2889
3653
            if (builder)
2890
3654
            {
2891
 
              item= builder->create(YYSession, $1, $4);
 
3655
              item= builder->create(session, $1, $4);
2892
3656
            }
2893
3657
            else
2894
3658
            {
2895
 
              /* Retrieving the result of service::Function::get */
2896
 
              const plugin::Function *udf= $<udf>3;
 
3659
              /* Retrieving the result of find_udf */
 
3660
              udf_func *udf= $<udf>3;
2897
3661
              if (udf)
2898
3662
              {
2899
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
2900
 
              } else {
 
3663
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
3664
              } else {
2901
3665
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
2902
3666
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
2903
3667
              }
2907
3671
            {
2908
3672
              DRIZZLE_YYABORT;
2909
3673
            }
2910
 
            Lex->setCacheable(false);
2911
3674
          }
2912
3675
        ;
2913
3676
 
2959
3722
        | COUNT_SYM '(' in_sum_expr ')'
2960
3723
          { $$=new Item_sum_count($3); }
2961
3724
        | COUNT_SYM '(' DISTINCT
2962
 
          { Lex->current_select->in_sum_expr++; }
 
3725
          { Select->in_sum_expr++; }
2963
3726
          expr_list
2964
 
          { Lex->current_select->in_sum_expr--; }
 
3727
          { Select->in_sum_expr--; }
2965
3728
          ')'
2966
3729
          { $$=new Item_sum_count_distinct(* $5); }
2967
3730
        | MIN_SYM '(' in_sum_expr ')'
2990
3753
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
2991
3754
          { $$=new Item_sum_sum_distinct($4); }
2992
3755
        | GROUP_CONCAT_SYM '(' opt_distinct
2993
 
          { Lex->current_select->in_sum_expr++; }
 
3756
          { Select->in_sum_expr++; }
2994
3757
          expr_list opt_gorder_clause
2995
3758
          opt_gconcat_separator
2996
3759
          ')'
2997
3760
          {
2998
 
            Select_Lex *sel= Lex->current_select;
 
3761
            SELECT_LEX *sel= Select;
2999
3762
            sel->in_sum_expr--;
3000
3763
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3001
3764
                                          sel->gorder_list, $7);
3013
3776
        ;
3014
3777
 
3015
3778
variable_aux:
3016
 
          user_variable_ident SET_VAR expr
 
3779
          ident_or_text SET_VAR expr
3017
3780
          {
3018
3781
            $$= new Item_func_set_user_var($1, $3);
3019
 
            Lex->setCacheable(false);
3020
3782
          }
3021
 
        | user_variable_ident
 
3783
        | ident_or_text
3022
3784
          {
3023
 
            $$= new Item_func_get_user_var(*YYSession, $1);
3024
 
            Lex->setCacheable(false);
 
3785
            $$= new Item_func_get_user_var($1);
3025
3786
          }
3026
 
        | '@' opt_var_ident_type user_variable_ident opt_component
 
3787
        | '@' opt_var_ident_type ident_or_text opt_component
3027
3788
          {
3028
3789
            /* disallow "SELECT @@global.global.variable" */
3029
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3790
            if ($3.str && $4.str && check_reserved_words(&$3))
3030
3791
            {
3031
 
              parser::my_parse_error(YYSession->m_lip);
 
3792
              my_parse_error(ER(ER_SYNTAX_ERROR));
3032
3793
              DRIZZLE_YYABORT;
3033
3794
            }
3034
3795
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3037
3798
        ;
3038
3799
 
3039
3800
opt_distinct:
3040
 
          /* empty */ { $$ = false; }
3041
 
        | DISTINCT    { $$ = true; }
 
3801
          /* empty */ { $$ = 0; }
 
3802
        | DISTINCT    { $$ = 1; }
3042
3803
        ;
3043
3804
 
3044
3805
opt_gconcat_separator:
3052
3813
opt_gorder_clause:
3053
3814
          /* empty */
3054
3815
          {
3055
 
            Lex->current_select->gorder_list = NULL;
 
3816
            Select->gorder_list = NULL;
3056
3817
          }
3057
3818
        | order_clause
3058
3819
          {
3059
 
            Select_Lex *select= Lex->current_select;
 
3820
            SELECT_LEX *select= Select;
3060
3821
            select->gorder_list=
3061
 
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
 
3822
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3062
3823
                                     sizeof(st_sql_list));
3063
3824
            select->order_list.empty();
3064
3825
          }
3067
3828
in_sum_expr:
3068
3829
          opt_all
3069
3830
          {
3070
 
            if (Lex->current_select->inc_in_sum_expr())
 
3831
            LEX *lex= Lex;
 
3832
            if (lex->current_select->inc_in_sum_expr())
3071
3833
            {
3072
 
              parser::my_parse_error(YYSession->m_lip);
 
3834
              my_parse_error(ER(ER_SYNTAX_ERROR));
3073
3835
              DRIZZLE_YYABORT;
3074
3836
            }
3075
3837
          }
3076
3838
          expr
3077
3839
          {
3078
 
            Lex->current_select->in_sum_expr--;
 
3840
            Select->in_sum_expr--;
3079
3841
            $$= $3;
3080
3842
          }
3081
3843
        ;
3083
3845
cast_type:
3084
3846
          BINARY opt_len
3085
3847
          { $$=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
 
3848
        | CHAR_SYM opt_len opt_binary
3099
3849
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3100
3850
        | DATE_SYM
3101
3851
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3102
3852
        | TIME_SYM
3103
3853
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3104
 
        | DATETIME_SYM
 
3854
        | DATETIME
3105
3855
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3106
3856
        | DECIMAL_SYM float_options
3107
3857
          { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
3151
3901
          table_factor { $$=$1; }
3152
3902
        | join_table
3153
3903
          {
3154
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3904
            LEX *lex= Lex;
 
3905
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3155
3906
              DRIZZLE_YYABORT;
3156
3907
          }
3157
3908
        ;
3197
3948
            left-associative joins.
3198
3949
          */
3199
3950
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
3200
 
          { 
3201
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
3202
 
            Lex->is_cross= false;
3203
 
          }
 
3951
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); }
3204
3952
        | table_ref STRAIGHT_JOIN table_factor
3205
 
          { 
3206
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
3207
 
          }
 
3953
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
3208
3954
        | table_ref normal_join table_ref
3209
3955
          ON
3210
3956
          {
3211
3957
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3212
 
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
3213
3958
            /* Change the current name resolution context to a local context. */
3214
3959
            if (push_new_name_resolution_context(YYSession, $1, $3))
3215
3960
              DRIZZLE_YYABORT;
3216
 
            Lex->current_select->parsing_place= IN_ON;
 
3961
            Select->parsing_place= IN_ON;
3217
3962
          }
3218
3963
          expr
3219
3964
          {
3220
3965
            add_join_on($3,$6);
3221
3966
            Lex->pop_context();
3222
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3967
            Select->parsing_place= NO_MATTER;
3223
3968
          }
3224
3969
        | table_ref STRAIGHT_JOIN table_factor
3225
3970
          ON
3228
3973
            /* Change the current name resolution context to a local context. */
3229
3974
            if (push_new_name_resolution_context(YYSession, $1, $3))
3230
3975
              DRIZZLE_YYABORT;
3231
 
            Lex->current_select->parsing_place= IN_ON;
 
3976
            Select->parsing_place= IN_ON;
3232
3977
          }
3233
3978
          expr
3234
3979
          {
3235
3980
            $3->straight=1;
3236
3981
            add_join_on($3,$6);
3237
3982
            Lex->pop_context();
3238
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3983
            Select->parsing_place= NO_MATTER;
3239
3984
          }
3240
3985
        | table_ref normal_join table_ref
3241
3986
          USING
3243
3988
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3244
3989
          }
3245
3990
          '(' using_list ')'
3246
 
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
 
3991
          { add_join_natural($1,$3,$7,Select); $$=$3; }
3247
3992
        | table_ref NATURAL JOIN_SYM table_factor
3248
3993
          {
3249
3994
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
3250
 
            add_join_natural($1,$4,NULL,Lex->current_select);
 
3995
            add_join_natural($1,$4,NULL,Select);
3251
3996
          }
3252
3997
 
3253
3998
          /* LEFT JOIN variants */
3258
4003
            /* Change the current name resolution context to a local context. */
3259
4004
            if (push_new_name_resolution_context(YYSession, $1, $5))
3260
4005
              DRIZZLE_YYABORT;
3261
 
            Lex->current_select->parsing_place= IN_ON;
 
4006
            Select->parsing_place= IN_ON;
3262
4007
          }
3263
4008
          expr
3264
4009
          {
3266
4011
            Lex->pop_context();
3267
4012
            $5->outer_join|=JOIN_TYPE_LEFT;
3268
4013
            $$=$5;
3269
 
            Lex->current_select->parsing_place= NO_MATTER;
 
4014
            Select->parsing_place= NO_MATTER;
3270
4015
          }
3271
4016
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3272
4017
          {
3273
4018
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3274
4019
          }
3275
4020
          USING '(' using_list ')'
3276
 
          {
3277
 
            add_join_natural($1,$5,$9,Lex->current_select);
3278
 
            $5->outer_join|=JOIN_TYPE_LEFT;
3279
 
            $$=$5;
 
4021
          { 
 
4022
            add_join_natural($1,$5,$9,Select); 
 
4023
            $5->outer_join|=JOIN_TYPE_LEFT; 
 
4024
            $$=$5; 
3280
4025
          }
3281
4026
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3282
4027
          {
3283
4028
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3284
 
            add_join_natural($1,$6,NULL,Lex->current_select);
 
4029
            add_join_natural($1,$6,NULL,Select);
3285
4030
            $6->outer_join|=JOIN_TYPE_LEFT;
3286
4031
            $$=$6;
3287
4032
          }
3294
4039
            /* Change the current name resolution context to a local context. */
3295
4040
            if (push_new_name_resolution_context(YYSession, $1, $5))
3296
4041
              DRIZZLE_YYABORT;
3297
 
            Lex->current_select->parsing_place= IN_ON;
 
4042
            Select->parsing_place= IN_ON;
3298
4043
          }
3299
4044
          expr
3300
4045
          {
3301
 
            if (!($$= Lex->current_select->convert_right_join()))
 
4046
            LEX *lex= Lex;
 
4047
            if (!($$= lex->current_select->convert_right_join()))
3302
4048
              DRIZZLE_YYABORT;
3303
4049
            add_join_on($$, $8);
3304
4050
            Lex->pop_context();
3305
 
            Lex->current_select->parsing_place= NO_MATTER;
 
4051
            Select->parsing_place= NO_MATTER;
3306
4052
          }
3307
4053
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3308
4054
          {
3310
4056
          }
3311
4057
          USING '(' using_list ')'
3312
4058
          {
3313
 
            if (!($$= Lex->current_select->convert_right_join()))
 
4059
            LEX *lex= Lex;
 
4060
            if (!($$= lex->current_select->convert_right_join()))
3314
4061
              DRIZZLE_YYABORT;
3315
 
            add_join_natural($$,$5,$9,Lex->current_select);
 
4062
            add_join_natural($$,$5,$9,Select);
3316
4063
          }
3317
4064
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3318
4065
          {
3319
4066
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3320
 
            add_join_natural($6,$1,NULL,Lex->current_select);
3321
 
            if (!($$= Lex->current_select->convert_right_join()))
 
4067
            add_join_natural($6,$1,NULL,Select);
 
4068
            LEX *lex= Lex;
 
4069
            if (!($$= lex->current_select->convert_right_join()))
3322
4070
              DRIZZLE_YYABORT;
3323
4071
          }
3324
4072
        ;
3326
4074
normal_join:
3327
4075
          JOIN_SYM {}
3328
4076
        | INNER_SYM JOIN_SYM {}
3329
 
        | CROSS JOIN_SYM
3330
 
          {
3331
 
            Lex->is_cross= true;
3332
 
            Lex->current_select->is_cross= true;
3333
 
          }
 
4077
        | CROSS JOIN_SYM {}
3334
4078
        ;
3335
4079
 
3336
 
/*
 
4080
/* 
3337
4081
   This is a flattening of the rules <table factor> and <table primary>
3338
4082
   in the SQL:2003 standard, since we don't have <sample clause>
3339
4083
 
3340
4084
   I.e.
3341
4085
   <table factor> ::= <table primary> [ <sample clause> ]
3342
 
*/  
 
4086
*/   
3343
4087
/* Warning - may return NULL in case of incomplete SELECT */
3344
4088
table_factor:
3345
4089
          {
 
4090
            SELECT_LEX *sel= Select;
 
4091
            sel->table_join_options= 0;
3346
4092
          }
3347
4093
          table_ident opt_table_alias opt_key_definition
3348
4094
          {
3349
 
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3350
 
                             0,
3351
 
                             Lex->lock_option,
3352
 
                             Lex->current_select->pop_index_hints())))
 
4095
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
 
4096
                                                Select->get_table_join_options(),
 
4097
                                                Lex->lock_option,
 
4098
                                                Select->pop_index_hints())))
3353
4099
              DRIZZLE_YYABORT;
3354
 
            Lex->current_select->add_joined_table($$);
 
4100
            Select->add_joined_table($$);
3355
4101
          }
3356
4102
        | select_derived_init get_select_lex select_derived2
3357
4103
          {
3358
 
            Select_Lex *sel= Lex->current_select;
 
4104
            LEX *lex= Lex;
 
4105
            SELECT_LEX *sel= lex->current_select;
3359
4106
            if ($1)
3360
4107
            {
3361
4108
              if (sel->set_braces(1))
3362
4109
              {
3363
 
                parser::my_parse_error(YYSession->m_lip);
 
4110
                my_parse_error(ER(ER_SYNTAX_ERROR));
3364
4111
                DRIZZLE_YYABORT;
3365
4112
              }
3366
4113
              /* select in braces, can't contain global parameters */
3368
4115
                sel->master_unit()->global_parameters=
3369
4116
                   sel->master_unit()->fake_select_lex;
3370
4117
            }
3371
 
            if ($2->init_nested_join(Lex->session))
 
4118
            if ($2->init_nested_join(lex->session))
3372
4119
              DRIZZLE_YYABORT;
3373
4120
            $$= 0;
3374
4121
            /* incomplete derived tables return NULL, we must be
3378
4125
            Represents a flattening of the following rules from the SQL:2003
3379
4126
            standard. This sub-rule corresponds to the sub-rule
3380
4127
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
3381
 
           
 
4128
            
3382
4129
            The following rules have been flattened into query_expression_body
3383
4130
            (since we have no <with clause>).
3384
4131
 
3397
4144
            /* Use $2 instead of Lex->current_select as derived table will
3398
4145
               alter value of Lex->current_select. */
3399
4146
            if (!($3 || $5) && $2->embedding &&
3400
 
                !$2->embedding->getNestedJoin()->join_list.elements)
 
4147
                !$2->embedding->nested_join->join_list.elements)
3401
4148
            {
3402
4149
              /* we have a derived table ($3 == NULL) but no alias,
3403
4150
                 Since we are nested in further parentheses so we
3410
4157
              /* Handle case of derived table, alias may be NULL if there
3411
4158
                 are no outer parentheses, add_table_to_list() will throw
3412
4159
                 error in this case */
3413
 
              Select_Lex *sel= Lex->current_select;
3414
 
              Select_Lex_Unit *unit= sel->master_unit();
3415
 
              Lex->current_select= sel= unit->outer_select();
3416
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
4160
              LEX *lex=Lex;
 
4161
              SELECT_LEX *sel= lex->current_select;
 
4162
              SELECT_LEX_UNIT *unit= sel->master_unit();
 
4163
              lex->current_select= sel= unit->outer_select();
 
4164
              if (!($$= sel->add_table_to_list(lex->session,
3417
4165
                                               new Table_ident(unit), $5, 0,
3418
4166
                                               TL_READ)))
3419
4167
 
3420
4168
                DRIZZLE_YYABORT;
3421
4169
              sel->add_joined_table($$);
3422
 
              Lex->pop_context();
 
4170
              lex->pop_context();
3423
4171
            }
3424
4172
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3425
4173
            {
3426
4174
              /* simple nested joins cannot have aliases or unions */
3427
 
              parser::my_parse_error(YYSession->m_lip);
 
4175
              my_parse_error(ER(ER_SYNTAX_ERROR));
3428
4176
              DRIZZLE_YYABORT;
3429
4177
            }
3430
4178
            else
3438
4186
          UNION_SYM
3439
4187
          union_option
3440
4188
          {
3441
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
4189
            if (add_select_to_union_list(Lex, (bool)$3))
3442
4190
              DRIZZLE_YYABORT;
3443
4191
          }
3444
4192
          query_specification
3456
4204
select_init2_derived:
3457
4205
          select_part2_derived
3458
4206
          {
3459
 
            Select_Lex * sel= Lex->current_select;
3460
 
            if (Lex->current_select->set_braces(0))
 
4207
            LEX *lex= Lex;
 
4208
            SELECT_LEX * sel= lex->current_select;
 
4209
            if (lex->current_select->set_braces(0))
3461
4210
            {
3462
 
              parser::my_parse_error(YYSession->m_lip);
 
4211
              my_parse_error(ER(ER_SYNTAX_ERROR));
3463
4212
              DRIZZLE_YYABORT;
3464
4213
            }
3465
4214
            if (sel->linkage == UNION_TYPE &&
3466
4215
                sel->master_unit()->first_select()->braces)
3467
4216
            {
3468
 
              parser::my_parse_error(YYSession->m_lip);
 
4217
              my_parse_error(ER(ER_SYNTAX_ERROR));
3469
4218
              DRIZZLE_YYABORT;
3470
4219
            }
3471
4220
          }
3474
4223
/* The equivalent of select_part2 for nested queries. */
3475
4224
select_part2_derived:
3476
4225
          {
3477
 
            Select_Lex *sel= Lex->current_select;
 
4226
            LEX *lex= Lex;
 
4227
            SELECT_LEX *sel= lex->current_select;
3478
4228
            if (sel->linkage != UNION_TYPE)
3479
 
              init_select(Lex);
3480
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4229
              mysql_init_select(lex);
 
4230
            lex->current_select->parsing_place= SELECT_LIST;
3481
4231
          }
3482
4232
          select_options select_item_list
3483
4233
          {
3484
 
            Lex->current_select->parsing_place= NO_MATTER;
 
4234
            Select->parsing_place= NO_MATTER;
3485
4235
          }
3486
4236
          opt_select_from select_lock_type
3487
4237
        ;
3490
4240
select_derived:
3491
4241
          get_select_lex
3492
4242
          {
3493
 
            if ($1->init_nested_join(Lex->session))
 
4243
            LEX *lex= Lex;
 
4244
            if ($1->init_nested_join(lex->session))
3494
4245
              DRIZZLE_YYABORT;
3495
4246
          }
3496
4247
          derived_table_list
3497
4248
          {
 
4249
            LEX *lex= Lex;
3498
4250
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3499
4251
               for derived tables, both must equal NULL */
3500
4252
 
3501
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
4253
            if (!($$= $1->end_nested_join(lex->session)) && $3)
3502
4254
              DRIZZLE_YYABORT;
3503
 
 
3504
4255
            if (!$3 && $$)
3505
4256
            {
3506
 
              parser::my_parse_error(YYSession->m_lip);
 
4257
              my_parse_error(ER(ER_SYNTAX_ERROR));
3507
4258
              DRIZZLE_YYABORT;
3508
4259
            }
3509
4260
          }
3511
4262
 
3512
4263
select_derived2:
3513
4264
          {
3514
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3515
 
            if (not Lex->expr_allows_subselect)
 
4265
            LEX *lex= Lex;
 
4266
            lex->derived_tables|= DERIVED_SUBQUERY;
 
4267
            if (!lex->expr_allows_subselect ||
 
4268
                lex->sql_command == (int)SQLCOM_PURGE)
3516
4269
            {
3517
 
              parser::my_parse_error(YYSession->m_lip);
 
4270
              my_parse_error(ER(ER_SYNTAX_ERROR));
3518
4271
              DRIZZLE_YYABORT;
3519
4272
            }
3520
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
4273
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
4274
                mysql_new_select(lex, 1))
3521
4275
              DRIZZLE_YYABORT;
3522
 
            init_select(Lex);
3523
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3524
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4276
            mysql_init_select(lex);
 
4277
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
4278
            lex->current_select->parsing_place= SELECT_LIST;
3525
4279
          }
3526
4280
          select_options select_item_list
3527
4281
          {
3528
 
            Lex->current_select->parsing_place= NO_MATTER;
 
4282
            Select->parsing_place= NO_MATTER;
3529
4283
          }
3530
4284
          opt_select_from
3531
4285
        ;
3532
4286
 
3533
4287
get_select_lex:
3534
 
          /* Empty */ { $$= Lex->current_select; }
 
4288
          /* Empty */ { $$= Select; }
3535
4289
        ;
3536
4290
 
3537
4291
select_derived_init:
3538
4292
          SELECT_SYM
3539
4293
          {
3540
 
            Select_Lex *sel= Lex->current_select;
 
4294
            LEX *lex= Lex;
 
4295
 
 
4296
            SELECT_LEX *sel= lex->current_select;
3541
4297
            TableList *embedding;
3542
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
4298
            if (!sel->embedding || sel->end_nested_join(lex->session))
3543
4299
            {
3544
4300
              /* we are not in parentheses */
3545
 
              parser::my_parse_error(YYSession->m_lip);
 
4301
              my_parse_error(ER(ER_SYNTAX_ERROR));
3546
4302
              DRIZZLE_YYABORT;
3547
4303
            }
3548
 
            embedding= Lex->current_select->embedding;
 
4304
            embedding= Select->embedding;
3549
4305
            $$= embedding &&
3550
 
                !embedding->getNestedJoin()->join_list.elements;
 
4306
                !embedding->nested_join->join_list.elements;
3551
4307
            /* return true if we are deeply nested */
3552
4308
          }
3553
4309
        ;
3560
4316
index_hint_clause:
3561
4317
          /* empty */
3562
4318
          {
3563
 
            $$= INDEX_HINT_MASK_ALL;
 
4319
            $$= global_system_variables.old_mode ? 
 
4320
                  INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL; 
3564
4321
          }
3565
4322
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
3566
4323
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
3569
4326
 
3570
4327
index_hint_type:
3571
4328
          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
3572
 
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
 
4329
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; } 
3573
4330
        ;
3574
4331
 
3575
4332
index_hint_definition:
3576
4333
          index_hint_type key_or_index index_hint_clause
3577
4334
          {
3578
 
            Lex->current_select->set_index_hint_type($1, $3);
 
4335
            Select->set_index_hint_type($1, $3);
3579
4336
          }
3580
4337
          '(' key_usage_list ')'
3581
4338
        | USE_SYM key_or_index index_hint_clause
3582
4339
          {
3583
 
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
 
4340
            Select->set_index_hint_type(INDEX_HINT_USE, $3);
3584
4341
          }
3585
4342
          '(' opt_key_usage_list ')'
3586
4343
       ;
3592
4349
 
3593
4350
opt_index_hints_list:
3594
4351
          /* empty */
3595
 
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
 
4352
        | { Select->alloc_index_hints(YYSession); } index_hints_list
3596
4353
        ;
3597
4354
 
3598
4355
opt_key_definition:
3599
 
          {  Lex->current_select->clear_index_hints(); }
 
4356
          {  Select->clear_index_hints(); }
3600
4357
          opt_index_hints_list
3601
4358
        ;
3602
4359
 
3603
4360
opt_key_usage_list:
3604
 
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
 
4361
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
3605
4362
        | key_usage_list {}
3606
4363
        ;
3607
4364
 
3608
4365
key_usage_element:
3609
4366
          ident
3610
 
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
 
4367
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
3611
4368
        | PRIMARY_SYM
3612
 
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
 
4369
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
3613
4370
        ;
3614
4371
 
3615
4372
key_usage_list:
3652
4409
 
3653
4410
interval_time_stamp:
3654
4411
        interval_time_st        {}
3655
 
        | FRAC_SECOND_SYM       {
3656
 
                                  $$=INTERVAL_MICROSECOND;
 
4412
        | FRAC_SECOND_SYM       { 
 
4413
                                  $$=INTERVAL_MICROSECOND; 
3657
4414
                                  /*
3658
4415
                                    FRAC_SECOND was mistakenly implemented with
3659
4416
                                    a wrong resolution. According to the ODBC
3681
4438
        | YEAR_SYM        { $$=INTERVAL_YEAR; }
3682
4439
        ;
3683
4440
 
 
4441
date_time_type:
 
4442
          DATE_SYM  {$$=DRIZZLE_TIMESTAMP_DATE;}
 
4443
        | TIME_SYM  {$$=DRIZZLE_TIMESTAMP_TIME;}
 
4444
        | DATETIME  {$$=DRIZZLE_TIMESTAMP_DATETIME;}
 
4445
        | TIMESTAMP {$$=DRIZZLE_TIMESTAMP_DATETIME;}
 
4446
        ;
 
4447
 
3684
4448
table_alias:
3685
4449
          /* empty */
3686
4450
        | AS
3690
4454
opt_table_alias:
3691
4455
          /* empty */ { $$=0; }
3692
4456
        | table_alias ident
3693
 
          {
3694
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
3695
 
          }
 
4457
          { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
3696
4458
        ;
3697
4459
 
3698
4460
opt_all:
3701
4463
        ;
3702
4464
 
3703
4465
where_clause:
3704
 
          /* empty */  { Lex->current_select->where= 0; }
 
4466
          /* empty */  { Select->where= 0; }
3705
4467
        | WHERE
3706
4468
          {
3707
 
            Lex->current_select->parsing_place= IN_WHERE;
 
4469
            Select->parsing_place= IN_WHERE;
3708
4470
          }
3709
4471
          expr
3710
4472
          {
3711
 
            Select_Lex *select= Lex->current_select;
 
4473
            SELECT_LEX *select= Select;
3712
4474
            select->where= $3;
3713
4475
            select->parsing_place= NO_MATTER;
3714
4476
            if ($3)
3720
4482
          /* empty */
3721
4483
        | HAVING
3722
4484
          {
3723
 
            Lex->current_select->parsing_place= IN_HAVING;
 
4485
            Select->parsing_place= IN_HAVING;
3724
4486
          }
3725
4487
          expr
3726
4488
          {
3727
 
            Select_Lex *sel= Lex->current_select;
 
4489
            SELECT_LEX *sel= Select;
3728
4490
            sel->having= $3;
3729
4491
            sel->parsing_place= NO_MATTER;
3730
4492
            if ($3)
3733
4495
        ;
3734
4496
 
3735
4497
opt_escape:
3736
 
          ESCAPE_SYM simple_expr
 
4498
          ESCAPE_SYM simple_expr 
3737
4499
          {
3738
4500
            Lex->escape_used= true;
3739
4501
            $$= $2;
3756
4518
 
3757
4519
group_list:
3758
4520
          group_list ',' order_ident order_dir
3759
 
          { if (YYSession->add_group_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
 
4521
          { if (add_group_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
3760
4522
        | order_ident order_dir
3761
 
          { if (YYSession->add_group_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
 
4523
          { if (add_group_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
3762
4524
        ;
3763
4525
 
3764
4526
olap_opt:
3772
4534
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3773
4535
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3774
4536
            */
3775
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4537
            LEX *lex= Lex;
 
4538
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
3776
4539
            {
3777
4540
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3778
4541
                       "global union parameters");
3779
4542
              DRIZZLE_YYABORT;
3780
4543
            }
3781
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
4544
            lex->current_select->olap= ROLLUP_TYPE;
3782
4545
          }
3783
4546
        ;
3784
4547
 
3796
4559
        ;
3797
4560
 
3798
4561
alter_order_item:
3799
 
          simple_ident order_dir
 
4562
          simple_ident_nospvar order_dir
3800
4563
          {
 
4564
            Session *session= YYSession;
3801
4565
            bool ascending= ($2 == 1) ? true : false;
3802
 
            if (YYSession->add_order_to_list($1, ascending))
 
4566
            if (add_order_to_list(session, $1, ascending))
3803
4567
              DRIZZLE_YYABORT;
3804
4568
          }
3805
4569
        ;
3816
4580
order_clause:
3817
4581
          ORDER_SYM BY
3818
4582
          {
3819
 
            if (not parser::buildOrderBy(Lex))
 
4583
            LEX *lex=Lex;
 
4584
            SELECT_LEX *sel= lex->current_select;
 
4585
            SELECT_LEX_UNIT *unit= sel-> master_unit();
 
4586
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4587
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4588
                (sel->linkage != UNION_TYPE || sel->braces))
 
4589
            {
 
4590
              my_error(ER_WRONG_USAGE, MYF(0),
 
4591
                       "CUBE/ROLLUP", "ORDER BY");
3820
4592
              DRIZZLE_YYABORT;
 
4593
            }
 
4594
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4595
            {
 
4596
              /*
 
4597
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4598
                executed in the same way as the query
 
4599
                SELECT ... ORDER BY order_list
 
4600
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4601
                Otherwise we create a fake SELECT_LEX if it has not been created
 
4602
                yet.
 
4603
              */
 
4604
              SELECT_LEX *first_sl= unit->first_select();
 
4605
              if (!unit->is_union() &&
 
4606
                  (first_sl->order_list.elements || 
 
4607
                   first_sl->select_limit) &&            
 
4608
                  unit->add_fake_select_lex(lex->session))
 
4609
                DRIZZLE_YYABORT;
 
4610
            }
3821
4611
          }
3822
4612
          order_list
3823
4613
        ;
3824
4614
 
3825
4615
order_list:
3826
4616
          order_list ',' order_ident order_dir
3827
 
          {
3828
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3829
 
              DRIZZLE_YYABORT;
3830
 
          }
 
4617
          { if (add_order_to_list(YYSession, $3,(bool) $4)) DRIZZLE_YYABORT; }
3831
4618
        | order_ident order_dir
3832
 
          {
3833
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3834
 
              DRIZZLE_YYABORT;
3835
 
          }
 
4619
          { if (add_order_to_list(YYSession, $1,(bool) $2)) DRIZZLE_YYABORT; }
3836
4620
        ;
3837
4621
 
3838
4622
order_dir:
3844
4628
opt_limit_clause_init:
3845
4629
          /* empty */
3846
4630
          {
3847
 
            Select_Lex *sel= Lex->current_select;
 
4631
            LEX *lex= Lex;
 
4632
            SELECT_LEX *sel= lex->current_select;
3848
4633
            sel->offset_limit= 0;
3849
4634
            sel->select_limit= 0;
3850
4635
          }
3863
4648
limit_options:
3864
4649
          limit_option
3865
4650
          {
3866
 
            Select_Lex *sel= Lex->current_select;
 
4651
            SELECT_LEX *sel= Select;
3867
4652
            sel->select_limit= $1;
3868
4653
            sel->offset_limit= 0;
3869
4654
            sel->explicit_limit= 1;
3870
4655
          }
3871
4656
        | limit_option ',' limit_option
3872
4657
          {
3873
 
            Select_Lex *sel= Lex->current_select;
 
4658
            SELECT_LEX *sel= Select;
3874
4659
            sel->select_limit= $3;
3875
4660
            sel->offset_limit= $1;
3876
4661
            sel->explicit_limit= 1;
3877
4662
          }
3878
4663
        | limit_option OFFSET_SYM limit_option
3879
4664
          {
3880
 
            Select_Lex *sel= Lex->current_select;
 
4665
            SELECT_LEX *sel= Select;
3881
4666
            sel->select_limit= $1;
3882
4667
            sel->offset_limit= $3;
3883
4668
            sel->explicit_limit= 1;
3893
4678
delete_limit_clause:
3894
4679
          /* empty */
3895
4680
          {
3896
 
            Lex->current_select->select_limit= 0;
 
4681
            LEX *lex=Lex;
 
4682
            lex->current_select->select_limit= 0;
3897
4683
          }
3898
4684
        | LIMIT limit_option
3899
4685
          {
3900
 
            Select_Lex *sel= Lex->current_select;
 
4686
            SELECT_LEX *sel= Select;
3901
4687
            sel->select_limit= $2;
3902
4688
            sel->explicit_limit= 1;
3903
4689
          }
3904
4690
        ;
3905
4691
 
3906
4692
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); }
 
4693
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4694
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4695
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4696
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4697
        | DECIMAL_NUM   { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4698
        | FLOAT_NUM     { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4699
        ;
 
4700
 
 
4701
real_ulong_num:
 
4702
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4703
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4704
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4705
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4706
        | dec_num_error { DRIZZLE_YYABORT; }
3913
4707
        ;
3914
4708
 
3915
4709
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
 
        ;
 
4710
          NUM           { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4711
        | ULONGLONG_NUM { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4712
        | LONG_NUM      { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4713
        | DECIMAL_NUM   { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4714
        | FLOAT_NUM     { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4715
        ;
 
4716
 
 
4717
dec_num_error:
 
4718
          dec_num
 
4719
          { my_parse_error(ER(ER_ONLY_INTEGERS_ALLOWED)); }
 
4720
        ;
 
4721
 
 
4722
dec_num:
 
4723
          DECIMAL_NUM
 
4724
        | FLOAT_NUM
 
4725
        ;
 
4726
 
 
4727
choice:
 
4728
        ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
 
4729
        | DEFAULT { $$= HA_CHOICE_UNDEF; }
 
4730
        ;
3922
4731
 
3923
4732
select_var_list_init:
3924
4733
          {
3925
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
 
4734
            LEX *lex=Lex;
 
4735
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
3926
4736
              DRIZZLE_YYABORT;
3927
4737
          }
3928
4738
          select_var_list
3934
4744
        | select_var_ident {}
3935
4745
        ;
3936
4746
 
3937
 
select_var_ident: 
3938
 
          '@' user_variable_ident
 
4747
select_var_ident:  
 
4748
          '@' ident_or_text
3939
4749
          {
3940
 
            if (Lex->result)
3941
 
            {
3942
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
3943
 
            }
 
4750
            LEX *lex=Lex;
 
4751
            if (lex->result) 
 
4752
              ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
3944
4753
            else
3945
 
            {
3946
4754
              /*
3947
4755
                The parser won't create select_result instance only
3948
4756
                if it's an EXPLAIN.
3949
4757
              */
3950
 
              assert(Lex->describe);
3951
 
            }
 
4758
              assert(lex->describe);
3952
4759
          }
3953
4760
        ;
3954
4761
 
3961
4768
into_destination:
3962
4769
          OUTFILE TEXT_STRING_filesystem
3963
4770
          {
3964
 
            Lex->setCacheable(false);
3965
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
3966
 
                !(Lex->result= new select_export(Lex->exchange)))
 
4771
            LEX *lex= Lex;
 
4772
            if (!(lex->exchange= new sql_exchange($2.str, 0)) ||
 
4773
                !(lex->result= new select_export(lex->exchange)))
3967
4774
              DRIZZLE_YYABORT;
3968
4775
          }
3969
4776
          opt_field_term opt_line_term
3970
4777
        | DUMPFILE TEXT_STRING_filesystem
3971
4778
          {
3972
 
            if (not Lex->describe)
 
4779
            LEX *lex=Lex;
 
4780
            if (!lex->describe)
3973
4781
            {
3974
 
              Lex->setCacheable(false);
3975
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
 
4782
              if (!(lex->exchange= new sql_exchange($2.str,1)))
3976
4783
                DRIZZLE_YYABORT;
3977
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
 
4784
              if (!(lex->result= new select_dump(lex->exchange)))
3978
4785
                DRIZZLE_YYABORT;
3979
4786
            }
3980
4787
          }
3981
4788
        | select_var_list_init
3982
 
          {Lex->setCacheable(false);}
 
4789
          { }
3983
4790
        ;
3984
4791
 
3985
4792
/*
3987
4794
*/
3988
4795
 
3989
4796
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;
 
4797
          DROP opt_temporary table_or_tables if_exists table_list
 
4798
          {
 
4799
            LEX *lex=Lex;
 
4800
            lex->sql_command = SQLCOM_DROP_TABLE;
 
4801
            lex->drop_temporary= $2;
 
4802
            lex->drop_if_exists= $4;
4000
4803
          }
4001
4804
        | DROP build_method INDEX_SYM ident ON table_ident {}
4002
4805
          {
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))
 
4806
            LEX *lex=Lex;
 
4807
            lex->sql_command= SQLCOM_DROP_INDEX;
 
4808
            lex->alter_info.reset();
 
4809
            lex->alter_info.flags= ALTER_DROP_INDEX;
 
4810
            lex->alter_info.build_method= $2;
 
4811
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
4812
                                                               $4.str));
 
4813
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
 
4814
                                                        TL_OPTION_UPDATING))
4010
4815
              DRIZZLE_YYABORT;
4011
4816
          }
4012
 
        | DROP DATABASE if_exists schema_name
 
4817
        | DROP DATABASE if_exists ident
4013
4818
          {
4014
 
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4015
 
            Lex->statement= statement;
4016
 
            statement->drop_if_exists=$3;
4017
 
            Lex->name= $4;
 
4819
            LEX *lex=Lex;
 
4820
            lex->sql_command= SQLCOM_DROP_DB;
 
4821
            lex->drop_if_exists=$3;
 
4822
            lex->name= $4;
4018
4823
          }
4019
 
        ;
4020
 
 
4021
4824
table_list:
4022
4825
          table_name
4023
4826
        | table_list ',' table_name
4026
4829
table_name:
4027
4830
          table_ident
4028
4831
          {
4029
 
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
 
4832
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
 
4833
              DRIZZLE_YYABORT;
 
4834
          }
 
4835
        ;
 
4836
 
 
4837
table_alias_ref_list:
 
4838
          table_alias_ref
 
4839
        | table_alias_ref_list ',' table_alias_ref
 
4840
        ;
 
4841
 
 
4842
table_alias_ref:
 
4843
          table_ident
 
4844
          {
 
4845
            if (!Select->add_table_to_list(YYSession, $1, NULL,
 
4846
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4847
                                           Lex->lock_option ))
4030
4848
              DRIZZLE_YYABORT;
4031
4849
          }
4032
4850
        ;
4033
4851
 
4034
4852
if_exists:
4035
 
          /* empty */ { $$= false; }
4036
 
        | IF EXISTS { $$= true; }
 
4853
          /* empty */ { $$= 0; }
 
4854
        | IF EXISTS { $$= 1; }
4037
4855
        ;
4038
4856
 
4039
4857
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
 
 
 
4858
          /* empty */ { $$= 0; }
 
4859
        | TEMPORARY { $$= 1; }
 
4860
        ;
4080
4861
/*
4081
4862
** Insert : add new data to table
4082
4863
*/
4084
4865
insert:
4085
4866
          INSERT
4086
4867
          {
4087
 
            Lex->statement= new statement::Insert(YYSession);
4088
 
            Lex->duplicates= DUP_ERROR;
4089
 
            init_select(Lex);
 
4868
            LEX *lex= Lex;
 
4869
            lex->sql_command= SQLCOM_INSERT;
 
4870
            lex->duplicates= DUP_ERROR; 
 
4871
            mysql_init_select(lex);
4090
4872
            /* for subselects */
4091
 
            Lex->lock_option= TL_READ;
 
4873
            lex->lock_option= TL_READ;
4092
4874
          }
 
4875
          insert_lock_option
4093
4876
          opt_ignore insert2
4094
4877
          {
4095
 
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
 
4878
            Select->set_lock_for_tables($3);
4096
4879
            Lex->current_select= &Lex->select_lex;
4097
4880
          }
4098
4881
          insert_field_spec opt_insert_update
4102
4885
replace:
4103
4886
          REPLACE
4104
4887
          {
4105
 
            Lex->statement= new statement::Replace(YYSession);
4106
 
            Lex->duplicates= DUP_REPLACE;
4107
 
            init_select(Lex);
 
4888
            LEX *lex=Lex;
 
4889
            lex->sql_command = SQLCOM_REPLACE;
 
4890
            lex->duplicates= DUP_REPLACE;
 
4891
            mysql_init_select(lex);
4108
4892
          }
4109
 
          insert2
 
4893
          replace_lock_option insert2
4110
4894
          {
4111
 
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4895
            Select->set_lock_for_tables($3);
4112
4896
            Lex->current_select= &Lex->select_lex;
4113
4897
          }
4114
4898
          insert_field_spec
4115
4899
          {}
4116
4900
        ;
4117
4901
 
 
4902
insert_lock_option:
 
4903
          /* empty */
 
4904
          {
 
4905
            $$= TL_WRITE_CONCURRENT_INSERT;
 
4906
          }
 
4907
        | LOW_PRIORITY  { $$= TL_WRITE_DEFAULT; }
 
4908
        | DELAYED_SYM   { $$= TL_WRITE_DEFAULT; }
 
4909
        | HIGH_PRIORITY { $$= TL_WRITE; }
 
4910
        ;
 
4911
 
 
4912
replace_lock_option:
 
4913
          opt_low_priority { $$= $1; }
 
4914
        | DELAYED_SYM { $$= TL_WRITE_DEFAULT; }
 
4915
        ;
 
4916
 
4118
4917
insert2:
4119
4918
          INTO insert_table {}
4120
4919
        | insert_table {}
4123
4922
insert_table:
4124
4923
          table_name
4125
4924
          {
4126
 
            Lex->field_list.empty();
4127
 
            Lex->many_values.empty();
4128
 
            Lex->insert_list=0;
 
4925
            LEX *lex=Lex;
 
4926
            lex->field_list.empty();
 
4927
            lex->many_values.empty();
 
4928
            lex->insert_list=0;
4129
4929
          };
4130
4930
 
4131
4931
insert_field_spec:
4132
4932
          insert_values {}
4133
4933
        | '(' ')' insert_values {}
4134
4934
        | '(' fields ')' insert_values {}
4135
 
        | SET_SYM
 
4935
        | SET
4136
4936
          {
4137
 
            if (not (Lex->insert_list = new List_item) ||
4138
 
                Lex->many_values.push_back(Lex->insert_list))
 
4937
            LEX *lex=Lex;
 
4938
            if (!(lex->insert_list = new List_item) ||
 
4939
                lex->many_values.push_back(lex->insert_list))
4139
4940
              DRIZZLE_YYABORT;
4140
4941
          }
4141
4942
          ident_eq_list
4149
4950
insert_values:
4150
4951
          VALUES values_list {}
4151
4952
        | VALUE_SYM values_list {}
4152
 
        | stored_select
4153
 
          {
4154
 
            Lex->current_select->set_braces(0);
4155
 
          }
 
4953
        | create_select
 
4954
          { Select->set_braces(0);}
4156
4955
          union_clause {}
4157
 
        | '(' stored_select ')'
4158
 
          {
4159
 
            Lex->current_select->set_braces(1);
4160
 
          }
 
4956
        | '(' create_select ')'
 
4957
          { Select->set_braces(1);}
4161
4958
          union_opt {}
4162
4959
        ;
4163
4960
 
4172
4969
        ;
4173
4970
 
4174
4971
ident_eq_value:
4175
 
          simple_ident equal expr_or_default
 
4972
          simple_ident_nospvar equal expr_or_default
4176
4973
          {
4177
 
            if (Lex->field_list.push_back($1) ||
4178
 
                Lex->insert_list->push_back($3))
 
4974
            LEX *lex=Lex;
 
4975
            if (lex->field_list.push_back($1) ||
 
4976
                lex->insert_list->push_back($3))
4179
4977
              DRIZZLE_YYABORT;
4180
4978
          }
4181
4979
        ;
4198
4996
          }
4199
4997
          opt_values ')'
4200
4998
          {
4201
 
            if (Lex->many_values.push_back(Lex->insert_list))
 
4999
            LEX *lex=Lex;
 
5000
            if (lex->many_values.push_back(lex->insert_list))
4202
5001
              DRIZZLE_YYABORT;
4203
5002
          }
4204
5003
        ;
4235
5034
/* Update rows in a table */
4236
5035
 
4237
5036
update:
4238
 
          UPDATE_SYM opt_ignore table_ident
 
5037
          UPDATE_SYM
4239
5038
          {
4240
 
            init_select(Lex);
4241
 
            Lex->statement= new statement::Update(YYSession);
4242
 
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
4243
 
            Lex->duplicates= DUP_ERROR;
4244
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4245
 
              DRIZZLE_YYABORT;
 
5039
            LEX *lex= Lex;
 
5040
            mysql_init_select(lex);
 
5041
            lex->sql_command= SQLCOM_UPDATE;
 
5042
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
5043
            lex->duplicates= DUP_ERROR; 
4246
5044
          }
4247
 
          SET_SYM update_list
 
5045
          opt_low_priority opt_ignore join_table_list
 
5046
          SET update_list
4248
5047
          {
4249
 
            if (Lex->select_lex.get_table_list()->derived)
 
5048
            LEX *lex= Lex;
 
5049
            if (lex->select_lex.table_list.elements > 1)
 
5050
              lex->sql_command= SQLCOM_UPDATE_MULTI;
 
5051
            else if (lex->select_lex.get_table_list()->derived)
4250
5052
            {
4251
5053
              /* it is single table update and it is update of derived table */
4252
5054
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4253
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
5055
                       lex->select_lex.get_table_list()->alias, "UPDATE");
4254
5056
              DRIZZLE_YYABORT;
4255
5057
            }
4256
5058
            /*
4257
5059
              In case of multi-update setting write lock for all tables may
4258
5060
              be too pessimistic. We will decrease lock level if possible in
4259
 
              multi_update().
 
5061
              mysql_multi_update().
4260
5062
            */
4261
 
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
5063
            Select->set_lock_for_tables($3);
4262
5064
          }
4263
5065
          where_clause opt_order_clause delete_limit_clause {}
4264
5066
        ;
4269
5071
        ;
4270
5072
 
4271
5073
update_elem:
4272
 
          simple_ident equal expr_or_default
 
5074
          simple_ident_nospvar equal expr_or_default
4273
5075
          {
4274
 
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
 
5076
            if (add_item_to_list(YYSession, $1) || add_value_to_list(YYSession, $3))
4275
5077
              DRIZZLE_YYABORT;
4276
5078
          }
4277
5079
        ;
4282
5084
        ;
4283
5085
 
4284
5086
insert_update_elem:
4285
 
          simple_ident equal expr_or_default
 
5087
          simple_ident_nospvar equal expr_or_default
4286
5088
          {
4287
 
          if (Lex->update_list.push_back($1) ||
4288
 
              Lex->value_list.push_back($3))
 
5089
          LEX *lex= Lex;
 
5090
          if (lex->update_list.push_back($1) || 
 
5091
              lex->value_list.push_back($3))
4289
5092
              DRIZZLE_YYABORT;
4290
5093
          }
4291
5094
        ;
4292
5095
 
 
5096
opt_low_priority:
 
5097
          /* empty */ { $$= TL_WRITE_DEFAULT; }
 
5098
        | LOW_PRIORITY { $$= TL_WRITE_DEFAULT; }
 
5099
        ;
 
5100
 
4293
5101
/* Delete rows from a table */
4294
5102
 
4295
5103
delete:
4296
5104
          DELETE_SYM
4297
5105
          {
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();
 
5106
            LEX *lex= Lex;
 
5107
            lex->sql_command= SQLCOM_DELETE;
 
5108
            mysql_init_select(lex);
 
5109
            lex->lock_option= TL_WRITE_DEFAULT;
 
5110
            lex->ignore= 0;
 
5111
            lex->select_lex.init_order();
4303
5112
          }
4304
5113
          opt_delete_options single_multi
4305
5114
        ;
4307
5116
single_multi:
4308
5117
          FROM table_ident
4309
5118
          {
4310
 
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
 
5119
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4311
5120
                                           Lex->lock_option))
4312
5121
              DRIZZLE_YYABORT;
4313
5122
          }
4314
5123
          where_clause opt_order_clause
4315
5124
          delete_limit_clause {}
 
5125
        | table_wild_list
 
5126
          { mysql_init_multi_delete(Lex); }
 
5127
          FROM join_table_list where_clause
 
5128
          {
 
5129
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
 
5130
              DRIZZLE_YYABORT;
 
5131
          }
 
5132
        | FROM table_alias_ref_list
 
5133
          { mysql_init_multi_delete(Lex); }
 
5134
          USING join_table_list where_clause
 
5135
          {
 
5136
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
 
5137
              DRIZZLE_YYABORT;
 
5138
          }
 
5139
        ;
 
5140
 
 
5141
table_wild_list:
 
5142
          table_wild_one
 
5143
        | table_wild_list ',' table_wild_one
 
5144
        ;
 
5145
 
 
5146
table_wild_one:
 
5147
          ident opt_wild
 
5148
          {
 
5149
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
 
5150
                                           NULL,
 
5151
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
5152
                                           Lex->lock_option))
 
5153
              DRIZZLE_YYABORT;
 
5154
          }
 
5155
        | ident '.' ident opt_wild
 
5156
          {
 
5157
            if (!Select->add_table_to_list(YYSession,
 
5158
                                           new Table_ident(YYSession, $1, $3, 0),
 
5159
                                           NULL,
 
5160
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
5161
                                           Lex->lock_option))
 
5162
              DRIZZLE_YYABORT;
 
5163
          }
 
5164
        ;
 
5165
 
 
5166
opt_wild:
 
5167
          /* empty */ {}
 
5168
        | '.' '*' {}
4316
5169
        ;
4317
5170
 
4318
5171
opt_delete_options:
4321
5174
        ;
4322
5175
 
4323
5176
opt_delete_option:
4324
 
         IGNORE_SYM   { Lex->ignore= 1; }
 
5177
          QUICK        { Select->options|= OPTION_QUICK; }
 
5178
        | LOW_PRIORITY { Lex->lock_option= TL_WRITE_DEFAULT; }
 
5179
        | IGNORE_SYM   { Lex->ignore= 1; }
4325
5180
        ;
4326
5181
 
4327
5182
truncate:
4328
5183
          TRUNCATE_SYM opt_table_sym table_name
4329
5184
          {
4330
 
            Lex->statement= new statement::Truncate(YYSession);
4331
 
            Lex->select_lex.options= 0;
4332
 
            Lex->select_lex.init_order();
 
5185
            LEX* lex= Lex;
 
5186
            lex->sql_command= SQLCOM_TRUNCATE;
 
5187
            lex->select_lex.options= 0;
 
5188
            lex->select_lex.init_order();
4333
5189
          }
4334
5190
        ;
4335
5191
 
4343
5199
show:
4344
5200
          SHOW
4345
5201
          {
4346
 
            Lex->lock_option= TL_READ;
4347
 
            init_select(Lex);
4348
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
5202
            LEX *lex=Lex;
 
5203
            lex->wild=0;
 
5204
            lex->lock_option= TL_READ;
 
5205
            mysql_init_select(lex);
 
5206
            lex->current_select->parsing_place= SELECT_LIST;
 
5207
            memset(&lex->create_info, 0, sizeof(lex->create_info));
4349
5208
          }
4350
5209
          show_param
4351
5210
          {}
4352
5211
        ;
4353
5212
 
4354
 
/* SHOW SCHEMAS */
4355
5213
show_param:
4356
5214
           DATABASES show_wild
4357
5215
           {
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 */
 
5216
             LEX *lex= Lex;
 
5217
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
5218
             if (prepare_schema_table(YYSession, lex, 0, SCH_SCHEMATA))
 
5219
               DRIZZLE_YYABORT;
 
5220
           }
 
5221
         | opt_full TABLES opt_db show_wild
 
5222
           {
 
5223
             LEX *lex= Lex;
 
5224
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
5225
             lex->select_lex.db= $3;
 
5226
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLE_NAMES))
 
5227
               DRIZZLE_YYABORT;
 
5228
           }
4374
5229
         | TABLE_SYM STATUS_SYM opt_db show_wild
4375
5230
           {
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 */
 
5231
             LEX *lex= Lex;
 
5232
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
5233
             lex->select_lex.db= $3;
 
5234
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLES))
 
5235
               DRIZZLE_YYABORT;
 
5236
           }
 
5237
        | OPEN_SYM TABLES opt_db show_wild
 
5238
          {
 
5239
            LEX *lex= Lex;
 
5240
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
5241
            lex->select_lex.db= $3;
 
5242
            if (prepare_schema_table(YYSession, lex, 0, SCH_OPEN_TABLES))
 
5243
              DRIZZLE_YYABORT;
 
5244
          }
 
5245
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
 
5246
          { 
 
5247
            Lex->create_info.db_type= $2; 
 
5248
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
 
5249
          }
 
5250
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
 
5251
          {
 
5252
            LEX *lex= Lex;
 
5253
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
5254
            if ($5)
 
5255
              $4->change_db($5);
 
5256
            if (prepare_schema_table(YYSession, lex, $4, SCH_COLUMNS))
 
5257
              DRIZZLE_YYABORT;
 
5258
          }
 
5259
        | master_or_binary LOGS_SYM
 
5260
          {
 
5261
            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
 
5262
          }
4386
5263
        | 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
 
           }
 
5264
          {
 
5265
            LEX *lex= Lex;
 
5266
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
5267
            if ($4)
 
5268
              $3->change_db($4);
 
5269
            if (prepare_schema_table(YYSession, lex, $3, SCH_STATISTICS))
 
5270
              DRIZZLE_YYABORT;
 
5271
          }
4391
5272
        | COUNT_SYM '(' '*' ')' WARNINGS
4392
 
          {
4393
 
            show::buildSelectWarning(YYSession);
4394
 
          }
 
5273
          { (void) create_select_for_variable("warning_count"); }
4395
5274
        | COUNT_SYM '(' '*' ')' ERRORS
4396
 
          {
4397
 
            show::buildSelectError(YYSession);
4398
 
          }
 
5275
          { (void) create_select_for_variable("error_count"); }
4399
5276
        | WARNINGS opt_limit_clause_init
4400
 
          {
4401
 
            show::buildWarnings(YYSession);
4402
 
          }
 
5277
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4403
5278
        | ERRORS opt_limit_clause_init
4404
 
          {
4405
 
            show::buildErrors(YYSession);
4406
 
          }
 
5279
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
4407
5280
        | opt_var_type STATUS_SYM show_wild
4408
5281
          {
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;
 
5282
            LEX *lex= Lex;
 
5283
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
5284
            lex->option_type= $1;
 
5285
            if (prepare_schema_table(YYSession, lex, 0, SCH_STATUS))
 
5286
              DRIZZLE_YYABORT;
 
5287
          }
 
5288
        | opt_full PROCESSLIST_SYM
 
5289
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
 
5290
        | opt_var_type  VARIABLES show_wild
 
5291
          {
 
5292
            LEX *lex= Lex;
 
5293
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
5294
            lex->option_type= $1;
 
5295
            if (prepare_schema_table(YYSession, lex, 0, SCH_VARIABLES))
 
5296
              DRIZZLE_YYABORT;
 
5297
          }
 
5298
        | CREATE DATABASE opt_if_not_exists ident
 
5299
          {
 
5300
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
 
5301
            Lex->create_info.options=$3;
 
5302
            Lex->name= $4;
4416
5303
          }
4417
5304
        | CREATE TABLE_SYM table_ident
4418
5305
          {
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))
4435
 
              DRIZZLE_YYABORT;
4436
 
          }
 
5306
            LEX *lex= Lex;
 
5307
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
5308
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
5309
              DRIZZLE_YYABORT;
 
5310
          }
 
5311
        | MASTER_SYM STATUS_SYM
 
5312
          {
 
5313
            Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
 
5314
          }
 
5315
        | SLAVE STATUS_SYM
 
5316
          {
 
5317
            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
 
5318
          }
 
5319
 
 
5320
master_or_binary:
 
5321
          MASTER_SYM
 
5322
        | BINARY
 
5323
        ;
4437
5324
 
4438
5325
opt_db:
4439
5326
          /* empty */  { $$= 0; }
4440
5327
        | from_or_in ident { $$= $2.str; }
4441
5328
        ;
4442
5329
 
 
5330
opt_full:
 
5331
          /* empty */ { Lex->verbose=0; }
 
5332
        | FULL        { Lex->verbose=1; }
 
5333
        ;
 
5334
 
4443
5335
from_or_in:
4444
5336
          FROM
4445
5337
        | IN_SYM
4451
5343
          {
4452
5344
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
4453
5345
                                                    system_charset_info);
4454
 
            if (Lex->wild == NULL)
4455
 
              DRIZZLE_YYABORT;
4456
 
          }
4457
 
        | WHERE expr
4458
 
          {
4459
 
            Lex->current_select->where= $2;
4460
 
            if ($2)
4461
 
              $2->top_level_item();
4462
5346
          }
4463
5347
        ;
4464
5348
 
4466
5350
describe:
4467
5351
          describe_command table_ident
4468
5352
          {
4469
 
            if (not show::buildDescribe(YYSession, $2))
4470
 
            {
 
5353
            LEX *lex= Lex;
 
5354
            lex->lock_option= TL_READ;
 
5355
            mysql_init_select(lex);
 
5356
            lex->current_select->parsing_place= SELECT_LIST;
 
5357
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
5358
            lex->select_lex.db= 0;
 
5359
            lex->verbose= 0;
 
5360
            if (prepare_schema_table(YYSession, lex, $2, SCH_COLUMNS))
4471
5361
              DRIZZLE_YYABORT;
4472
 
            }
4473
5362
          }
4474
5363
          opt_describe_column {}
4475
5364
        | describe_command opt_extended_describe
4476
5365
          { Lex->describe|= DESCRIBE_NORMAL; }
4477
5366
          select
4478
5367
          {
4479
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
5368
            LEX *lex=Lex;
 
5369
            lex->select_lex.options|= SELECT_DESCRIBE;
4480
5370
          }
4481
5371
        ;
4482
5372
 
4507
5397
flush:
4508
5398
          FLUSH_SYM
4509
5399
          {
4510
 
            Lex->statement= new statement::Flush(YYSession);
 
5400
            LEX *lex=Lex;
 
5401
            lex->sql_command= SQLCOM_FLUSH;
 
5402
            lex->type= 0;
4511
5403
          }
4512
5404
          flush_options
4513
5405
          {}
4520
5412
 
4521
5413
flush_option:
4522
5414
          table_or_tables
4523
 
          {
4524
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4525
 
            statement->setFlushTables(true);
4526
 
          }
 
5415
          { Lex->type|= REFRESH_TABLES; }
4527
5416
          opt_table_list {}
4528
5417
        | TABLES WITH READ_SYM LOCK_SYM
4529
 
          {
4530
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4531
 
            statement->setFlushTablesWithReadLock(true);
4532
 
          }
 
5418
          { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
 
5419
        | QUERY_SYM CACHE_SYM
 
5420
          { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
 
5421
        | HOSTS_SYM
 
5422
          { Lex->type|= REFRESH_HOSTS; }
4533
5423
        | LOGS_SYM
4534
 
          {
4535
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
4536
 
            statement->setFlushLog(true);
4537
 
          }
 
5424
          { Lex->type|= REFRESH_LOG; }
4538
5425
        | 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
 
          }
 
5426
          { Lex->type|= REFRESH_STATUS; }
 
5427
        | SLAVE
 
5428
          { Lex->type|= REFRESH_SLAVE; }
 
5429
        | MASTER_SYM
 
5430
          { Lex->type|= REFRESH_MASTER; }
 
5431
        | RESOURCES
 
5432
          { Lex->type|= REFRESH_USER_RESOURCES; }
4548
5433
        ;
4549
5434
 
4550
5435
opt_table_list:
4552
5437
        | table_list {}
4553
5438
        ;
4554
5439
 
 
5440
reset:
 
5441
          RESET_SYM
 
5442
          {
 
5443
            LEX *lex=Lex;
 
5444
            lex->sql_command= SQLCOM_RESET; lex->type=0;
 
5445
          }
 
5446
          reset_options
 
5447
          {}
 
5448
        ;
 
5449
 
 
5450
reset_options:
 
5451
          reset_options ',' reset_option
 
5452
        | reset_option
 
5453
        ;
 
5454
 
 
5455
reset_option:
 
5456
          SLAVE               { Lex->type|= REFRESH_SLAVE; }
 
5457
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
 
5458
        | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;}
 
5459
        ;
 
5460
 
 
5461
purge:
 
5462
          PURGE
 
5463
          {
 
5464
            LEX *lex=Lex;
 
5465
            lex->type=0;
 
5466
            lex->sql_command = SQLCOM_PURGE;
 
5467
          }
 
5468
          purge_options
 
5469
          {}
 
5470
        ;
 
5471
 
 
5472
purge_options:
 
5473
          master_or_binary LOGS_SYM purge_option
 
5474
        ;
 
5475
 
 
5476
purge_option:
 
5477
          TO_SYM TEXT_STRING_sys
 
5478
          {
 
5479
            Lex->to_log = $2.str;
 
5480
          }
 
5481
        | BEFORE_SYM expr
 
5482
          {
 
5483
            LEX *lex= Lex;
 
5484
            lex->value_list.empty();
 
5485
            lex->value_list.push_front($2);
 
5486
            lex->sql_command= SQLCOM_PURGE_BEFORE;
 
5487
          }
 
5488
        ;
 
5489
 
4555
5490
/* kill threads */
4556
5491
 
4557
5492
kill:
4558
5493
          KILL_SYM kill_option expr
4559
5494
          {
4560
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
5495
            LEX *lex=Lex;
 
5496
            lex->value_list.empty();
 
5497
            lex->value_list.push_front($3);
 
5498
            lex->sql_command= SQLCOM_KILL;
4561
5499
          }
4562
5500
        ;
4563
5501
 
4564
5502
kill_option:
4565
 
          /* empty */ { $$= false; }
4566
 
        | CONNECTION_SYM { $$= false; }
4567
 
        | QUERY_SYM      { $$= true; }
 
5503
          /* empty */ { Lex->type= 0; }
 
5504
        | CONNECTION_SYM { Lex->type= 0; }
 
5505
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
4568
5506
        ;
4569
5507
 
4570
5508
/* change database */
4571
5509
 
4572
5510
use:
4573
 
          USE_SYM schema_name
 
5511
          USE_SYM ident
4574
5512
          {
4575
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4576
 
            Lex->select_lex.db= $2.str;
 
5513
            LEX *lex=Lex;
 
5514
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5515
            lex->select_lex.db= $2.str;
4577
5516
          }
4578
5517
        ;
4579
5518
 
4582
5521
load:
4583
5522
          LOAD data_file
4584
5523
          {
4585
 
            statement::Load *statement= new statement::Load(YYSession);
4586
 
            Lex->statement= statement;
 
5524
            Session *session= YYSession;
 
5525
            LEX *lex= session->lex;
 
5526
            Lex_input_stream *lip= session->m_lip;
4587
5527
 
4588
 
            Lex_input_stream *lip= YYSession->m_lip;
4589
 
            statement->fname_start= lip->get_ptr();
 
5528
            lex->fname_start= lip->get_ptr();
4590
5529
          }
4591
 
          load_data_lock INFILE TEXT_STRING_filesystem
 
5530
          load_data_lock opt_local INFILE TEXT_STRING_filesystem
4592
5531
          {
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)))
 
5532
            LEX *lex=Lex;
 
5533
            lex->sql_command= SQLCOM_LOAD;
 
5534
            lex->lock_option= $4;
 
5535
            lex->local_file=  $5;
 
5536
            lex->duplicates= DUP_ERROR;
 
5537
            lex->ignore= 0;
 
5538
            if (!(lex->exchange= new sql_exchange($7.str, 0, $2)))
4597
5539
              DRIZZLE_YYABORT;
4598
5540
          }
4599
5541
          opt_duplicate INTO
4600
5542
          {
4601
 
            Lex_input_stream *lip= YYSession->m_lip;
4602
 
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
 
5543
            Session *session= YYSession;
 
5544
            LEX *lex= session->lex;
 
5545
            Lex_input_stream *lip= session->m_lip;
 
5546
            lex->fname_end= lip->get_ptr();
4603
5547
          }
4604
5548
          TABLE_SYM table_ident
4605
5549
          {
4606
 
            if (!Lex->current_select->add_table_to_list(YYSession,
4607
 
                    $12, NULL, TL_OPTION_UPDATING,
4608
 
                    Lex->lock_option))
 
5550
            LEX *lex=Lex;
 
5551
            if (!Select->add_table_to_list(YYSession, $13, NULL, TL_OPTION_UPDATING,
 
5552
                                           lex->lock_option))
4609
5553
              DRIZZLE_YYABORT;
4610
 
            Lex->field_list.empty();
4611
 
            Lex->update_list.empty();
4612
 
            Lex->value_list.empty();
 
5554
            lex->field_list.empty();
 
5555
            lex->update_list.empty();
 
5556
            lex->value_list.empty();
4613
5557
          }
4614
5558
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4615
5559
          opt_load_data_set_spec
4619
5563
data_file:
4620
5564
        DATA_SYM  { $$= FILETYPE_CSV; };
4621
5565
 
 
5566
opt_local:
 
5567
          /* empty */ { $$=0;}
 
5568
        | LOCAL_SYM { $$=1;}
 
5569
        ;
 
5570
 
4622
5571
load_data_lock:
4623
5572
          /* empty */ { $$= TL_WRITE_DEFAULT; }
4624
5573
        | CONCURRENT
4625
5574
          {
4626
5575
              $$= TL_WRITE_CONCURRENT_INSERT;
4627
5576
          }
 
5577
        | LOW_PRIORITY { $$= TL_WRITE_DEFAULT; }
4628
5578
        ;
4629
5579
 
4630
5580
opt_duplicate:
4633
5583
        | IGNORE_SYM { Lex->ignore= 1; }
4634
5584
        ;
4635
5585
 
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
5586
opt_field_term:
4646
5587
          /* empty */
4647
5588
        | COLUMNS field_term_list
4653
5594
        ;
4654
5595
 
4655
5596
field_term:
4656
 
          TERMINATED BY text_string
 
5597
          TERMINATED BY text_string 
4657
5598
          {
4658
5599
            assert(Lex->exchange != 0);
4659
5600
            Lex->exchange->field_term= $3;
4660
5601
          }
4661
5602
        | OPTIONALLY ENCLOSED BY text_string
4662
5603
          {
4663
 
            assert(Lex->exchange != 0);
4664
 
            Lex->exchange->enclosed= $4;
4665
 
            Lex->exchange->opt_enclosed= 1;
 
5604
            LEX *lex= Lex;
 
5605
            assert(lex->exchange != 0);
 
5606
            lex->exchange->enclosed= $4;
 
5607
            lex->exchange->opt_enclosed= 1;
4666
5608
          }
4667
5609
        | ENCLOSED BY text_string
4668
5610
          {
4727
5669
        ;
4728
5670
 
4729
5671
field_or_var:
4730
 
          simple_ident {$$= $1;}
4731
 
        | '@' user_variable_ident
 
5672
          simple_ident_nospvar {$$= $1;}
 
5673
        | '@' ident_or_text
4732
5674
          { $$= new Item_user_var_as_out_param($2); }
4733
5675
        ;
4734
5676
 
4735
5677
opt_load_data_set_spec:
4736
5678
          /* empty */ {}
4737
 
        | SET_SYM insert_update_list {}
 
5679
        | SET insert_update_list {}
4738
5680
        ;
4739
5681
 
4740
5682
/* Common definitions */
4741
5683
 
4742
5684
text_literal:
4743
 
        TEXT_STRING_literal
4744
 
        {
4745
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
4746
 
        }
 
5685
          TEXT_STRING
 
5686
          {
 
5687
            LEX_STRING tmp;
 
5688
            Session *session= YYSession;
 
5689
            const CHARSET_INFO * const cs_con= session->variables.getCollation();
 
5690
            const CHARSET_INFO * const cs_cli= default_charset_info;
 
5691
            uint32_t repertoire= session->lex->text_string_is_7bit &&
 
5692
                             my_charset_is_ascii_based(cs_cli) ?
 
5693
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
 
5694
            if (session->charset_is_collation_connection ||
 
5695
                (repertoire == MY_REPERTOIRE_ASCII &&
 
5696
                 my_charset_is_ascii_based(cs_con)))
 
5697
              tmp= $1;
 
5698
            else
 
5699
              session->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
 
5700
            $$= new Item_string(tmp.str, tmp.length, cs_con,
 
5701
                                DERIVATION_COERCIBLE, repertoire);
 
5702
          }
 
5703
        | UNDERSCORE_CHARSET TEXT_STRING
 
5704
          {
 
5705
            Item_string *str= new Item_string($2.str, $2.length, $1);
 
5706
            str->set_repertoire_from_value();
 
5707
            str->set_cs_specified(true);
 
5708
 
 
5709
            $$= str;
 
5710
          }
4747
5711
        | text_literal TEXT_STRING_literal
4748
5712
          {
4749
 
            ((Item_string*) $1)->append($2.str, $2.length);
 
5713
            Item_string* item= (Item_string*) $1;
 
5714
            item->append($2.str, $2.length);
 
5715
            if (!(item->collation.repertoire & MY_REPERTOIRE_EXTENDED))
 
5716
            {
 
5717
              /*
 
5718
                 If the string has been pure ASCII so far,
 
5719
                 check the new part.
 
5720
              */
 
5721
              const CHARSET_INFO * const cs= YYSession->variables.getCollation();
 
5722
              item->collation.repertoire|= my_string_repertoire(cs,
 
5723
                                                                $2.str,
 
5724
                                                                $2.length);
 
5725
            }
4750
5726
          }
4751
5727
        ;
4752
5728
 
4798
5774
            $$ = new Item_null();
4799
5775
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
4800
5776
          }
4801
 
        | FALSE_SYM { $$= new drizzled::item::False(); }
4802
 
        | TRUE_SYM { $$= new drizzled::item::True(); }
 
5777
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
5778
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
4803
5779
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4804
5780
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
 
5781
        | UNDERSCORE_CHARSET HEX_NUM
 
5782
          {
 
5783
            Item *tmp= new Item_hex_string($2.str, $2.length);
 
5784
            /*
 
5785
              it is OK only emulate fix_fieds, because we need only
 
5786
              value of constant
 
5787
            */
 
5788
            String *str= tmp ?
 
5789
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
 
5790
              (String*) 0;
 
5791
 
 
5792
            Item_string *item_str=
 
5793
              new Item_string(NULL, /* name will be set in select_item */
 
5794
                              str ? str->ptr() : "",
 
5795
                              str ? str->length() : 0,
 
5796
                              $1);
 
5797
            if (!item_str ||
 
5798
                !item_str->check_well_formed_result(&item_str->str_value, true))
 
5799
            {
 
5800
              DRIZZLE_YYABORT;
 
5801
            }
 
5802
 
 
5803
            item_str->set_repertoire_from_value();
 
5804
            item_str->set_cs_specified(true);
 
5805
 
 
5806
            $$= item_str;
 
5807
          }
 
5808
        | UNDERSCORE_CHARSET BIN_NUM
 
5809
          {
 
5810
            Item *tmp= new Item_bin_string($2.str, $2.length);
 
5811
            /*
 
5812
              it is OK only emulate fix_fieds, because we need only
 
5813
              value of constant
 
5814
            */
 
5815
            String *str= tmp ?
 
5816
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
 
5817
              (String*) 0;
 
5818
 
 
5819
            Item_string *item_str=
 
5820
              new Item_string(NULL, /* name will be set in select_item */
 
5821
                              str ? str->ptr() : "",
 
5822
                              str ? str->length() : 0,
 
5823
                              $1);
 
5824
            if (!item_str ||
 
5825
                !item_str->check_well_formed_result(&item_str->str_value, true))
 
5826
            {
 
5827
              DRIZZLE_YYABORT;
 
5828
            }
 
5829
 
 
5830
            item_str->set_cs_specified(true);
 
5831
 
 
5832
            $$= item_str;
 
5833
          }
4805
5834
        | DATE_SYM text_literal { $$ = $2; }
4806
 
        | TIMESTAMP_SYM text_literal { $$ = $2; }
 
5835
        | TIME_SYM text_literal { $$ = $2; }
 
5836
        | TIMESTAMP text_literal { $$ = $2; }
4807
5837
        ;
4808
5838
 
4809
5839
NUM_literal:
4810
5840
          NUM
4811
5841
          {
4812
5842
            int error;
4813
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5843
            $$ = new Item_int($1.str, (int64_t) my_strtoll10($1.str, NULL, &error), $1.length);
4814
5844
          }
4815
5845
        | LONG_NUM
4816
5846
          {
4817
5847
            int error;
4818
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5848
            $$ = new Item_int($1.str, (int64_t) my_strtoll10($1.str, NULL, &error), $1.length);
4819
5849
          }
4820
5850
        | ULONGLONG_NUM
4821
5851
          { $$ = new Item_uint($1.str, $1.length); }
4842
5872
**********************************************************************/
4843
5873
 
4844
5874
insert_ident:
4845
 
          simple_ident { $$=$1; }
 
5875
          simple_ident_nospvar { $$=$1; }
4846
5876
        | table_wild { $$=$1; }
4847
5877
        ;
4848
5878
 
4849
5879
table_wild:
4850
5880
          ident '.' '*'
4851
5881
          {
4852
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5882
            SELECT_LEX *sel= Select;
 
5883
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
 
5884
            sel->with_wild++;
4853
5885
          }
4854
5886
        | ident '.' ident '.' '*'
4855
5887
          {
4856
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5888
            SELECT_LEX *sel= Select;
 
5889
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
 
5890
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
 
5891
                                $3.str,"*");
 
5892
            sel->with_wild++;
4857
5893
          }
4858
5894
        ;
4859
5895
 
4864
5900
simple_ident:
4865
5901
          ident
4866
5902
          {
4867
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5903
            {
 
5904
              SELECT_LEX *sel=Select;
 
5905
              $$= (sel->parsing_place != IN_HAVING ||
 
5906
                  sel->get_in_sum_expr() > 0) ?
 
5907
                  (Item*) new Item_field(Lex->current_context(),
 
5908
                                         (const char *)NULL, NULL, $1.str) :
 
5909
                  (Item*) new Item_ref(Lex->current_context(),
 
5910
                                       (const char *)NULL, NULL, $1.str);
 
5911
            }
 
5912
          }
 
5913
        | simple_ident_q { $$= $1; }
 
5914
        ;
 
5915
 
 
5916
simple_ident_nospvar:
 
5917
          ident
 
5918
          {
 
5919
            SELECT_LEX *sel=Select;
 
5920
            $$= (sel->parsing_place != IN_HAVING ||
 
5921
                sel->get_in_sum_expr() > 0) ?
 
5922
                (Item*) new Item_field(Lex->current_context(),
 
5923
                                       (const char *)NULL, NULL, $1.str) :
 
5924
                (Item*) new Item_ref(Lex->current_context(),
 
5925
                                     (const char *)NULL, NULL, $1.str);
4868
5926
          }
4869
5927
        | simple_ident_q { $$= $1; }
4870
5928
        ;
4872
5930
simple_ident_q:
4873
5931
          ident '.' ident
4874
5932
          {
4875
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5933
            Session *session= YYSession;
 
5934
            LEX *lex= session->lex;
 
5935
 
 
5936
            {
 
5937
              SELECT_LEX *sel= lex->current_select;
 
5938
              if (sel->no_table_names_allowed)
 
5939
              {
 
5940
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5941
                         MYF(0), $1.str, session->where);
 
5942
              }
 
5943
              $$= (sel->parsing_place != IN_HAVING ||
 
5944
                  sel->get_in_sum_expr() > 0) ?
 
5945
                  (Item*) new Item_field(Lex->current_context(),
 
5946
                                         (const char *)NULL, $1.str, $3.str) :
 
5947
                  (Item*) new Item_ref(Lex->current_context(),
 
5948
                                       (const char *)NULL, $1.str, $3.str);
 
5949
            }
4876
5950
          }
4877
5951
        | '.' ident '.' ident
4878
5952
          {
4879
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5953
            Session *session= YYSession;
 
5954
            LEX *lex= session->lex;
 
5955
            SELECT_LEX *sel= lex->current_select;
 
5956
            if (sel->no_table_names_allowed)
 
5957
            {
 
5958
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5959
                       MYF(0), $2.str, session->where);
 
5960
            }
 
5961
            $$= (sel->parsing_place != IN_HAVING ||
 
5962
                sel->get_in_sum_expr() > 0) ?
 
5963
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5964
                (Item*) new Item_ref(Lex->current_context(),
 
5965
                                     (const char *)NULL, $2.str, $4.str);
4880
5966
          }
4881
5967
        | ident '.' ident '.' ident
4882
5968
          {
4883
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5969
            Session *session= YYSession;
 
5970
            LEX *lex= session->lex;
 
5971
            SELECT_LEX *sel= lex->current_select;
 
5972
            if (sel->no_table_names_allowed)
 
5973
            {
 
5974
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
5975
                       MYF(0), $3.str, session->where);
 
5976
            }
 
5977
            $$= (sel->parsing_place != IN_HAVING ||
 
5978
                sel->get_in_sum_expr() > 0) ?
 
5979
                (Item*) new Item_field(Lex->current_context(),
 
5980
                                       (YYSession->client_capabilities &
 
5981
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
 
5982
                                       $3.str, $5.str) :
 
5983
                (Item*) new Item_ref(Lex->current_context(),
 
5984
                                     (YYSession->client_capabilities &
 
5985
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
 
5986
                                     $3.str, $5.str);
4884
5987
          }
4885
5988
        ;
4886
5989
 
4887
5990
field_ident:
4888
 
          ident 
4889
 
          {
4890
 
            $$=$1;
4891
 
          }
 
5991
          ident { $$=$1;}
4892
5992
        | ident '.' ident '.' ident
4893
5993
          {
4894
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
4895
 
              DRIZZLE_YYABORT;
4896
 
 
 
5994
            TableList *table= (TableList*) Select->table_list.first;
 
5995
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5996
            {
 
5997
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
5998
              DRIZZLE_YYABORT;
 
5999
            }
 
6000
            if (my_strcasecmp(table_alias_charset, $3.str,
 
6001
                              table->table_name))
 
6002
            {
 
6003
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
6004
              DRIZZLE_YYABORT;
 
6005
            }
4897
6006
            $$=$5;
4898
6007
          }
4899
6008
        | ident '.' ident
4900
6009
          {
4901
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
6010
            TableList *table= (TableList*) Select->table_list.first;
 
6011
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
6012
            {
 
6013
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6014
              DRIZZLE_YYABORT;
4903
 
 
 
6015
            }
4904
6016
            $$=$3;
4905
6017
          }
4906
 
        | '.' ident 
4907
 
          { /* For Delphi */
4908
 
            $$=$2;
4909
 
          }
 
6018
        | '.' ident { $$=$2;} /* For Delphi */
4910
6019
        ;
4911
6020
 
4912
6021
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
 
6022
          ident { $$=new Table_ident($1); }
 
6023
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
 
6024
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
4933
6025
        ;
4934
6026
 
4935
6027
IDENT_sys:
4936
 
          IDENT 
4937
 
          {
4938
 
            $$= $1;
4939
 
          }
 
6028
          IDENT { $$= $1; }
4940
6029
        | IDENT_QUOTED
4941
6030
          {
4942
 
            const CHARSET_INFO * const cs= system_charset_info;
4943
 
            int dummy_error;
4944
 
            uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
4945
 
                                                 $1.str+$1.length,
4946
 
                                                 $1.length, &dummy_error);
4947
 
            if (wlen < $1.length)
 
6031
            Session *session= YYSession;
 
6032
 
 
6033
            if (session->charset_is_system_charset)
4948
6034
            {
4949
 
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
4950
 
                       cs->csname, $1.str + wlen);
4951
 
              DRIZZLE_YYABORT;
 
6035
              const CHARSET_INFO * const cs= system_charset_info;
 
6036
              int dummy_error;
 
6037
              uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
 
6038
                                                   $1.str+$1.length,
 
6039
                                                   $1.length, &dummy_error);
 
6040
              if (wlen < $1.length)
 
6041
              {
 
6042
                my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
 
6043
                         cs->csname, $1.str + wlen);
 
6044
                DRIZZLE_YYABORT;
 
6045
              }
 
6046
              $$= $1;
4952
6047
            }
4953
 
            $$= $1;
 
6048
            else
 
6049
              session->convert_string(&$$, system_charset_info,
 
6050
                                  $1.str, $1.length, session->charset());
4954
6051
          }
4955
6052
        ;
4956
6053
 
4957
6054
TEXT_STRING_sys:
4958
6055
          TEXT_STRING
4959
6056
          {
4960
 
            $$= $1;
 
6057
            Session *session= YYSession;
 
6058
 
 
6059
            if (session->charset_is_system_charset)
 
6060
              $$= $1;
 
6061
            else
 
6062
              session->convert_string(&$$, system_charset_info,
 
6063
                                  $1.str, $1.length, session->charset());
4961
6064
          }
4962
6065
        ;
4963
6066
 
4964
6067
TEXT_STRING_literal:
4965
6068
          TEXT_STRING
4966
6069
          {
4967
 
            $$= $1;
 
6070
            Session *session= YYSession;
 
6071
 
 
6072
            if (session->charset_is_collation_connection)
 
6073
              $$= $1;
 
6074
            else
 
6075
              session->convert_string(&$$, session->variables.getCollation(),
 
6076
                                  $1.str, $1.length, session->charset());
4968
6077
          }
4969
6078
        ;
4970
6079
 
4971
6080
TEXT_STRING_filesystem:
4972
6081
          TEXT_STRING
4973
6082
          {
4974
 
            $$= $1;
 
6083
            Session *session= YYSession;
 
6084
 
 
6085
            if (session->charset_is_character_set_filesystem)
 
6086
              $$= $1;
 
6087
            else
 
6088
              session->convert_string(&$$, session->variables.character_set_filesystem,
 
6089
                                  $1.str, $1.length, session->charset());
4975
6090
          }
4976
6091
        ;
4977
6092
 
4979
6094
          IDENT_sys    { $$=$1; }
4980
6095
        | keyword
4981
6096
          {
4982
 
            $$.str= YYSession->strmake($1.str, $1.length);
 
6097
            Session *session= YYSession;
 
6098
            $$.str= session->strmake($1.str, $1.length);
4983
6099
            $$.length= $1.length;
4984
6100
          }
4985
6101
        ;
4986
6102
 
4987
6103
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          {}
 
6104
          ident           { $$=$1;}
 
6105
        | TEXT_STRING_sys { $$=$1;}
 
6106
        | LEX_HOSTNAME { $$=$1;}
5001
6107
        ;
5002
6108
 
5003
6109
/* Keyword that we allow for identifiers (except SP labels) */
5004
6110
keyword:
5005
6111
          keyword_sp            {}
 
6112
        | ASCII_SYM             {}
5006
6113
        | BEGIN_SYM             {}
 
6114
        | BYTE_SYM              {}
 
6115
        | CACHE_SYM             {}
 
6116
        | CHARSET               {}
5007
6117
        | CHECKSUM_SYM          {}
5008
6118
        | CLOSE_SYM             {}
5009
6119
        | COMMENT_SYM           {}
5010
6120
        | COMMIT_SYM            {}
5011
6121
        | CONTAINS_SYM          {}
5012
6122
        | DEALLOCATE_SYM        {}
5013
 
        | DO_SYM                {}
5014
6123
        | END                   {}
5015
6124
        | FLUSH_SYM             {}
 
6125
        | HANDLER_SYM           {}
 
6126
        | HOST_SYM              {}
 
6127
        | INSTALL_SYM           {}
5016
6128
        | NO_SYM                {}
5017
6129
        | OPEN_SYM              {}
 
6130
        | OPTIONS_SYM           {}
 
6131
        | PORT_SYM              {}
 
6132
        | REMOVE_SYM            {}
 
6133
        | REPAIR                {}
 
6134
        | RESET_SYM             {}
5018
6135
        | ROLLBACK_SYM          {}
5019
6136
        | SAVEPOINT_SYM         {}
5020
6137
        | SECURITY_SYM          {}
5021
6138
        | SERVER_SYM            {}
5022
 
        | SIGNED_SYM            {}
 
6139
        | SOCKET_SYM            {}
 
6140
        | SLAVE                 {}
 
6141
        | SONAME_SYM            {}
5023
6142
        | START_SYM             {}
5024
6143
        | STOP_SYM              {}
5025
6144
        | TRUNCATE_SYM          {}
 
6145
        | UPGRADE_SYM           {}
5026
6146
        ;
5027
6147
 
5028
6148
/*
5036
6156
        | ADDDATE_SYM              {}
5037
6157
        | AFTER_SYM                {}
5038
6158
        | AGGREGATE_SYM            {}
 
6159
        | ALGORITHM_SYM            {}
5039
6160
        | ANY_SYM                  {}
5040
6161
        | AT_SYM                   {}
5041
6162
        | AUTO_INC                 {}
 
6163
        | AUTOEXTEND_SIZE_SYM      {}
 
6164
        | AVG_ROW_LENGTH           {}
5042
6165
        | AVG_SYM                  {}
 
6166
        | BINLOG_SYM               {}
5043
6167
        | BIT_SYM                  {}
 
6168
        | BLOCK_SIZE_SYM           {}
 
6169
        | BLOCK_SYM                {}
5044
6170
        | BOOL_SYM                 {}
5045
6171
        | BOOLEAN_SYM              {}
5046
6172
        | BTREE_SYM                {}
5047
6173
        | CASCADED                 {}
5048
6174
        | CHAIN_SYM                {}
 
6175
        | CHANGED                  {}
5049
6176
        | COALESCE                 {}
5050
6177
        | COLLATION_SYM            {}
 
6178
        | COLUMN_FORMAT_SYM        {}
5051
6179
        | COLUMNS                  {}
5052
6180
        | COMMITTED_SYM            {}
5053
6181
        | COMPACT_SYM              {}
 
6182
        | COMPLETION_SYM           {}
5054
6183
        | COMPRESSED_SYM           {}
5055
6184
        | CONCURRENT               {}
5056
 
        | CONNECTION_SYM           {} /* Causes conflict because of kill */
 
6185
        | CONNECTION_SYM           {}
5057
6186
        | CONSISTENT_SYM           {}
 
6187
        | CONTEXT_SYM              {}
5058
6188
        | CUBE_SYM                 {}
5059
6189
        | DATA_SYM                 {}
5060
 
        | DATABASES                {}
5061
 
        | DATETIME_SYM             {}
5062
 
        | DATE_SYM                 {} /* Create conflict */
 
6190
        | DATAFILE_SYM             {}
 
6191
        | DATETIME                 {}
 
6192
        | DATE_SYM                 {}
5063
6193
        | DAY_SYM                  {}
 
6194
        | DELAY_KEY_WRITE_SYM      {}
 
6195
        | DIRECTORY_SYM            {}
5064
6196
        | DISABLE_SYM              {}
5065
6197
        | DISCARD                  {}
5066
6198
        | DUMPFILE                 {}
5067
6199
        | DUPLICATE_SYM            {}
5068
6200
        | DYNAMIC_SYM              {}
5069
6201
        | ENDS_SYM                 {}
5070
 
        | ENUM_SYM                 {}
 
6202
        | ENUM                     {}
5071
6203
        | ENGINE_SYM               {}
5072
6204
        | ERRORS                   {}
5073
6205
        | ESCAPE_SYM               {}
5074
6206
        | EXCLUSIVE_SYM            {}
5075
6207
        | EXTENDED_SYM             {}
 
6208
        | EXTENT_SIZE_SYM          {}
 
6209
        | FAULTS_SYM               {}
 
6210
        | FAST_SYM                 {}
5076
6211
        | FOUND_SYM                {}
5077
6212
        | ENABLE_SYM               {}
5078
6213
        | FULL                     {}
5080
6215
        | FIRST_SYM                {}
5081
6216
        | FIXED_SYM                {}
5082
6217
        | FRAC_SECOND_SYM          {}
 
6218
        | GET_FORMAT               {}
5083
6219
        | GLOBAL_SYM               {}
5084
6220
        | HASH_SYM                 {}
 
6221
        | HOSTS_SYM                {}
5085
6222
        | HOUR_SYM                 {}
5086
6223
        | IDENTIFIED_SYM           {}
5087
6224
        | IMPORT                   {}
5088
6225
        | INDEXES                  {}
 
6226
        | INITIAL_SIZE_SYM         {}
5089
6227
        | ISOLATION                {}
 
6228
        | INSERT_METHOD            {}
5090
6229
        | KEY_BLOCK_SIZE           {}
5091
6230
        | LAST_SYM                 {}
 
6231
        | LEAVES                   {}
5092
6232
        | LEVEL_SYM                {}
 
6233
        | LINESTRING               {}
 
6234
        | LIST_SYM                 {}
5093
6235
        | LOCAL_SYM                {}
5094
6236
        | LOCKS_SYM                {}
 
6237
        | LOGFILE_SYM              {}
5095
6238
        | LOGS_SYM                 {}
 
6239
        | MAX_ROWS                 {}
 
6240
        | MASTER_SYM               {}
 
6241
        | MASTER_HOST_SYM          {}
 
6242
        | MASTER_PORT_SYM          {}
 
6243
        | MASTER_LOG_FILE_SYM      {}
 
6244
        | MASTER_LOG_POS_SYM       {}
 
6245
        | MASTER_USER_SYM          {}
 
6246
        | MASTER_PASSWORD_SYM      {}
 
6247
        | MASTER_SERVER_ID_SYM     {}
 
6248
        | MASTER_CONNECT_RETRY_SYM {}
 
6249
        | MAX_CONNECTIONS_PER_HOUR {}
 
6250
        | MAX_QUERIES_PER_HOUR     {}
 
6251
        | MAX_SIZE_SYM             {}
 
6252
        | MAX_UPDATES_PER_HOUR     {}
 
6253
        | MAX_USER_CONNECTIONS_SYM {}
5096
6254
        | MAX_VALUE_SYM            {}
5097
6255
        | MEDIUM_SYM               {}
5098
6256
        | MERGE_SYM                {}
5099
6257
        | MICROSECOND_SYM          {}
 
6258
        | MIGRATE_SYM              {}
5100
6259
        | MINUTE_SYM               {}
 
6260
        | MIN_ROWS                 {}
5101
6261
        | MODIFY_SYM               {}
5102
6262
        | MODE_SYM                 {}
5103
6263
        | MONTH_SYM                {}
5106
6266
        | NATIONAL_SYM             {}
5107
6267
        | NEXT_SYM                 {}
5108
6268
        | NEW_SYM                  {}
 
6269
        | NO_WAIT_SYM              {}
 
6270
        | NODEGROUP_SYM            {}
5109
6271
        | NONE_SYM                 {}
 
6272
        | NOWAIT_SYM               {}
5110
6273
        | OFFLINE_SYM              {}
5111
6274
        | OFFSET_SYM               {}
5112
6275
        | ONE_SHOT_SYM             {}
5113
6276
        | ONE_SYM                  {}
5114
6277
        | ONLINE_SYM               {}
 
6278
        | PACK_KEYS_SYM            {}
 
6279
        | PAGE_SYM                 {}
 
6280
        | PAGE_CHECKSUM_SYM        {}
5115
6281
        | PARTIAL                  {}
 
6282
        | PHASE_SYM                {}
 
6283
        | PLUGIN_SYM               {}
 
6284
        | PLUGINS_SYM              {}
 
6285
        | POINT_SYM                {}
5116
6286
        | PREV_SYM                 {}
5117
6287
        | PROCESS                  {}
5118
6288
        | PROCESSLIST_SYM          {}
5119
6289
        | QUARTER_SYM              {}
5120
 
        | QUERY_SYM                {} // Causes conflict
 
6290
        | QUERY_SYM                {}
 
6291
        | QUICK                    {}
 
6292
        | READ_ONLY_SYM            {}
 
6293
        | REBUILD_SYM              {}
 
6294
        | RECOVER_SYM              {}
 
6295
        | REDO_BUFFER_SIZE_SYM     {}
 
6296
        | REDOFILE_SYM             {}
5121
6297
        | REDUNDANT_SYM            {}
 
6298
        | RELAY_LOG_FILE_SYM       {}
 
6299
        | RELAY_LOG_POS_SYM        {}
 
6300
        | RELAY_THREAD             {}
 
6301
        | RELOAD                   {}
 
6302
        | REORGANIZE_SYM           {}
5122
6303
        | REPEATABLE_SYM           {}
 
6304
        | REPLICATION              {}
 
6305
        | RESOURCES                {}
 
6306
        | RESUME_SYM               {}
5123
6307
        | RETURNS_SYM              {}
 
6308
        | REVERSE_SYM              {}
5124
6309
        | ROLLUP_SYM               {}
5125
6310
        | ROUTINE_SYM              {}
5126
6311
        | ROWS_SYM                 {}
5132
6317
        | SESSION_SYM              {}
5133
6318
        | SIMPLE_SYM               {}
5134
6319
        | SHARE_SYM                {}
 
6320
        | SHUTDOWN                 {}
5135
6321
        | SNAPSHOT_SYM             {}
 
6322
        | SOURCE_SYM               {}
 
6323
        | SQL_BUFFER_RESULT        {}
 
6324
        | SQL_THREAD               {}
 
6325
        | STARTS_SYM               {}
5136
6326
        | STATUS_SYM               {}
 
6327
        | STORAGE_SYM              {}
5137
6328
        | STRING_SYM               {}
5138
6329
        | SUBDATE_SYM              {}
5139
6330
        | SUBJECT_SYM              {}
 
6331
        | SUPER_SYM                {}
5140
6332
        | SUSPEND_SYM              {}
 
6333
        | SWAPS_SYM                {}
 
6334
        | SWITCHES_SYM             {}
5141
6335
        | TABLES                   {}
 
6336
        | TABLE_CHECKSUM_SYM       {}
5142
6337
        | TABLESPACE               {}
5143
 
        | TEMPORARY_SYM            {}
 
6338
        | TEMPORARY                {}
 
6339
        | TEMPTABLE_SYM            {}
5144
6340
        | TEXT_SYM                 {}
 
6341
        | THAN_SYM                 {}
5145
6342
        | TRANSACTION_SYM          {}
5146
 
        | TIME_SYM                 {}
 
6343
        | TRANSACTIONAL_SYM        {}
 
6344
        | TIMESTAMP                {}
5147
6345
        | TIMESTAMP_ADD            {}
5148
6346
        | TIMESTAMP_DIFF           {}
 
6347
        | TIME_SYM                 {}
 
6348
        | TYPES_SYM                {}
5149
6349
        | TYPE_SYM                 {}
5150
6350
        | UNCOMMITTED_SYM          {}
 
6351
        | UNDEFINED_SYM            {}
5151
6352
        | UNDOFILE_SYM             {}
5152
6353
        | UNKNOWN_SYM              {}
5153
 
        | UUID_SYM                 {}
 
6354
        | UNTIL_SYM                {}
5154
6355
        | USER                     {}
 
6356
        | USE_FRM                  {}
5155
6357
        | VARIABLES                {}
5156
6358
        | VALUE_SYM                {}
5157
6359
        | WARNINGS                 {}
 
6360
        | WAIT_SYM                 {}
5158
6361
        | WEEK_SYM                 {}
 
6362
        | WEIGHT_STRING_SYM        {}
5159
6363
        | WORK_SYM                 {}
5160
6364
        | YEAR_SYM                 {}
5161
6365
        ;
5163
6367
/* Option functions */
5164
6368
 
5165
6369
set:
5166
 
          SET_SYM opt_option
 
6370
          SET opt_option
5167
6371
          {
5168
 
            Lex->statement= new statement::SetOption(YYSession);
 
6372
            LEX *lex=Lex;
 
6373
            lex->sql_command= SQLCOM_SET_OPTION;
 
6374
            mysql_init_select(lex);
 
6375
            lex->option_type=OPT_SESSION;
 
6376
            lex->var_list.empty();
 
6377
            lex->one_shot_set= 0;
 
6378
            lex->autocommit= 0;
5169
6379
          }
5170
6380
          option_value_list
5171
6381
          {}
5182
6392
        ;
5183
6393
 
5184
6394
option_type_value:
5185
 
          { }
 
6395
          {
 
6396
          }
5186
6397
          ext_option_value
5187
 
          { }
 
6398
          {
 
6399
          }
5188
6400
        ;
5189
6401
 
5190
6402
option_type:
5196
6408
 
5197
6409
option_type2:
5198
6410
          /* empty */ { $$= OPT_DEFAULT; }
5199
 
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
 
6411
        | ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
5200
6412
        ;
5201
6413
 
5202
6414
opt_var_type:
5221
6433
sys_option_value:
5222
6434
          option_type internal_variable_name equal set_expr_or_default
5223
6435
          {
 
6436
            LEX *lex=Lex;
 
6437
 
5224
6438
            if ($2.var)
5225
6439
            { /* System variable */
5226
6440
              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)));
 
6441
                lex->option_type= $1;
 
6442
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6443
                                      &$2.base_name, $4));
5231
6444
            }
5232
6445
          }
5233
6446
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5234
6447
          {
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))));
 
6448
            LEX *lex=Lex;
 
6449
            lex->option_type= $1;
 
6450
            lex->var_list.push_back(new set_var(lex->option_type,
 
6451
                                                find_sys_var(YYSession, "tx_isolation"),
 
6452
                                                &null_lex_str,
 
6453
                                                new Item_int((int32_t) $5)));
5241
6454
          }
5242
6455
        ;
5243
6456
 
5244
6457
option_value:
5245
 
          '@' user_variable_ident equal expr
 
6458
          '@' ident_or_text equal expr
5246
6459
          {
5247
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
6460
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
5248
6461
          }
5249
6462
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5250
6463
          {
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; }
 
6464
            LEX *lex=Lex;
 
6465
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6466
          }
5268
6467
        ;
5269
6468
 
5270
6469
internal_variable_name:
5271
 
          internal_variable_ident
 
6470
          ident
5272
6471
          {
 
6472
            Session *session= YYSession;
 
6473
 
5273
6474
            /* We have to lookup here since local vars can shadow sysvars */
5274
6475
            {
5275
6476
              /* Not an SP local variable */
5276
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
 
6477
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
5277
6478
              if (!tmp)
5278
6479
                DRIZZLE_YYABORT;
5279
6480
              $$.var= tmp;
5280
6481
              $$.base_name= null_lex_str;
5281
6482
            }
5282
6483
          }
 
6484
        | ident '.' ident
 
6485
          {
 
6486
            if (check_reserved_words(&$1))
 
6487
            {
 
6488
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
6489
              DRIZZLE_YYABORT;
 
6490
            }
 
6491
            {
 
6492
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
 
6493
              if (!tmp)
 
6494
                DRIZZLE_YYABORT;
 
6495
              if (!tmp->is_struct())
 
6496
                my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 
6497
              $$.var= tmp;
 
6498
              $$.base_name= $1;
 
6499
            }
 
6500
          }
 
6501
        | DEFAULT '.' ident
 
6502
          {
 
6503
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
 
6504
            if (!tmp)
 
6505
              DRIZZLE_YYABORT;
 
6506
            if (!tmp->is_struct())
 
6507
              my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 
6508
            $$.var= tmp;
 
6509
            $$.base_name.str=    (char*) "default";
 
6510
            $$.base_name.length= 7;
 
6511
          }
5283
6512
        ;
5284
6513
 
5285
6514
isolation_types:
5297
6526
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
5298
6527
        ;
5299
6528
 
 
6529
/* Lock function */
 
6530
 
 
6531
lock:
 
6532
          LOCK_SYM
 
6533
          {
 
6534
            /*
 
6535
              Transactional locks can be taken only if all requested locks
 
6536
              are transactional. Initialize lex->lock_transactional as
 
6537
              TRUE. Any non-transactional lock request turns this to FALSE.
 
6538
              Table specific variables keep track of the locking method
 
6539
              requested for the table. This is used to warn about a
 
6540
              changed locking method later.
 
6541
            */
 
6542
            Lex->lock_transactional= true;
 
6543
          }
 
6544
          table_or_tables
 
6545
          {
 
6546
            LEX *lex= Lex;
 
6547
            lex->sql_command= SQLCOM_LOCK_TABLES;
 
6548
          }
 
6549
          table_lock_list
 
6550
          {}
 
6551
        ;
 
6552
 
5300
6553
table_or_tables:
5301
6554
          TABLE_SYM
5302
6555
        | TABLES
5303
6556
        ;
5304
6557
 
 
6558
table_lock_list:
 
6559
          table_lock
 
6560
        | table_lock_list ',' table_lock
 
6561
        ;
 
6562
 
 
6563
table_lock:
 
6564
        table_ident opt_table_alias table_lock_info
 
6565
        {
 
6566
          TableList *tlist;
 
6567
          if (!(tlist= Select->add_table_to_list(YYSession, $1, $2, 0,
 
6568
                                                 $3.lock_type)))
 
6569
            DRIZZLE_YYABORT; /* purecov: inspected */
 
6570
          tlist->lock_timeout= $3.lock_timeout;
 
6571
          /* Store the requested lock method for later warning. */
 
6572
          tlist->lock_transactional= $3.lock_transactional;
 
6573
          /* Compute the resulting lock method for all tables. */
 
6574
          if (!$3.lock_transactional)
 
6575
            Lex->lock_transactional= false;
 
6576
        }
 
6577
        ;
 
6578
 
 
6579
table_lock_info:
 
6580
        READ_SYM
 
6581
        {
 
6582
          $$.lock_type=          TL_READ_NO_INSERT;
 
6583
          $$.lock_timeout=       -1;
 
6584
          $$.lock_transactional= false;
 
6585
        }
 
6586
        | WRITE_SYM
 
6587
        {
 
6588
          $$.lock_type=          TL_WRITE_DEFAULT;
 
6589
          $$.lock_timeout=       -1;
 
6590
          $$.lock_transactional= false;
 
6591
        }
 
6592
        | LOW_PRIORITY WRITE_SYM
 
6593
        {
 
6594
          $$.lock_type=          TL_WRITE_DEFAULT;
 
6595
          $$.lock_timeout=       -1;
 
6596
          $$.lock_transactional= false;
 
6597
        }
 
6598
        | READ_SYM LOCAL_SYM
 
6599
        {
 
6600
          $$.lock_type=          TL_READ;
 
6601
          $$.lock_timeout=       -1;
 
6602
          $$.lock_transactional= false;
 
6603
        }
 
6604
        ;
 
6605
 
 
6606
/*
 
6607
  We have a timeout resolution of milliseconds. The WAIT argument is in
 
6608
  seconds with decimal fragments for sub-second resolution. E.g. 22.5, 0.015
 
6609
*/
 
6610
/* opt_lock_timeout_value: */
 
6611
        /* empty { $$= -1; } */
 
6612
        /* | NUM       { $$= (int) (atof($1.str) * 1000.0 + 0.5); } */
 
6613
 
5305
6614
unlock:
5306
6615
          UNLOCK_SYM
5307
6616
          {
5308
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
6617
            LEX *lex= Lex;
 
6618
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
5309
6619
          }
5310
6620
          table_or_tables
5311
6621
          {}
5314
6624
begin:
5315
6625
          BEGIN_SYM
5316
6626
          {
5317
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
6627
            LEX *lex=Lex;
 
6628
            lex->sql_command = SQLCOM_BEGIN;
 
6629
            lex->start_transaction_opt= 0;
5318
6630
          }
5319
6631
          opt_work {}
5320
6632
        ;
5346
6658
commit:
5347
6659
          COMMIT_SYM opt_work opt_chain opt_release
5348
6660
          {
5349
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
6661
            LEX *lex=Lex;
 
6662
            lex->sql_command= SQLCOM_COMMIT;
 
6663
            lex->tx_chain= $3; 
 
6664
            lex->tx_release= $4;
5350
6665
          }
5351
6666
        ;
5352
6667
 
5353
6668
rollback:
5354
6669
          ROLLBACK_SYM opt_work opt_chain opt_release
5355
6670
          {
5356
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
6671
            LEX *lex=Lex;
 
6672
            lex->sql_command= SQLCOM_ROLLBACK;
 
6673
            lex->tx_chain= $3; 
 
6674
            lex->tx_release= $4;
5357
6675
          }
5358
 
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
 
6676
        | ROLLBACK_SYM opt_work
 
6677
          TO_SYM opt_savepoint ident
5359
6678
          {
5360
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
6679
            LEX *lex=Lex;
 
6680
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6681
            lex->ident= $5;
5361
6682
          }
5362
6683
        ;
5363
6684
 
5364
6685
savepoint:
5365
 
          SAVEPOINT_SYM savepoint_ident
 
6686
          SAVEPOINT_SYM ident
5366
6687
          {
5367
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
6688
            LEX *lex=Lex;
 
6689
            lex->sql_command= SQLCOM_SAVEPOINT;
 
6690
            lex->ident= $2;
5368
6691
          }
5369
6692
        ;
5370
6693
 
5371
6694
release:
5372
 
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
 
6695
          RELEASE_SYM SAVEPOINT_SYM ident
5373
6696
          {
5374
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
6697
            LEX *lex=Lex;
 
6698
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6699
            lex->ident= $3;
5375
6700
          }
5376
6701
        ;
5377
6702
 
5378
 
savepoint_ident:
5379
 
               IDENT_sys
5380
 
               ;
5381
 
 
5382
6703
/*
5383
6704
   UNIONS : glue selects together
5384
6705
*/
5392
6713
union_list:
5393
6714
          UNION_SYM union_option
5394
6715
          {
5395
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
6716
            if (add_select_to_union_list(Lex, (bool)$2))
5396
6717
              DRIZZLE_YYABORT;
5397
6718
          }
5398
6719
          select_init
5413
6734
 
5414
6735
union_order_or_limit:
5415
6736
          {
5416
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5417
 
            Select_Lex *sel= Lex->current_select;
5418
 
            Select_Lex_Unit *unit= sel->master_unit();
5419
 
            Select_Lex *fake= unit->fake_select_lex;
 
6737
            Session *session= YYSession;
 
6738
            LEX *lex= session->lex;
 
6739
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6740
            SELECT_LEX *sel= lex->current_select;
 
6741
            SELECT_LEX_UNIT *unit= sel->master_unit();
 
6742
            SELECT_LEX *fake= unit->fake_select_lex;
5420
6743
            if (fake)
5421
6744
            {
5422
6745
              unit->global_parameters= fake;
5423
6746
              fake->no_table_names_allowed= 1;
5424
 
              Lex->current_select= fake;
 
6747
              lex->current_select= fake;
5425
6748
            }
5426
 
            YYSession->setWhere("global ORDER clause");
 
6749
            session->where= "global ORDER clause";
5427
6750
          }
5428
6751
          order_or_limit
5429
6752
          {
5430
 
            YYSession->lex->current_select->no_table_names_allowed= 0;
5431
 
            YYSession->setWhere("");
 
6753
            Session *session= YYSession;
 
6754
            session->lex->current_select->no_table_names_allowed= 0;
 
6755
            session->where= "";
5432
6756
          }
5433
6757
        ;
5434
6758
 
5445
6769
 
5446
6770
query_specification:
5447
6771
          SELECT_SYM select_init2_derived
5448
 
          {
 
6772
          { 
5449
6773
            $$= Lex->current_select->master_unit()->first_select();
5450
6774
          }
5451
6775
        | '(' select_paren_derived ')'
5457
6781
query_expression_body:
5458
6782
          query_specification
5459
6783
        | query_expression_body
5460
 
          UNION_SYM union_option
 
6784
          UNION_SYM union_option 
5461
6785
          {
5462
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
6786
            if (add_select_to_union_list(Lex, (bool)$3))
5463
6787
              DRIZZLE_YYABORT;
5464
6788
          }
5465
6789
          query_specification
5472
6796
/* Corresponds to <query expression> in the SQL:2003 standard. */
5473
6797
subselect:
5474
6798
          subselect_start query_expression_body subselect_end
5475
 
          {
 
6799
          { 
5476
6800
            $$= $2;
5477
6801
          }
5478
6802
        ;
5479
6803
 
5480
6804
subselect_start:
5481
6805
          {
5482
 
            if (not Lex->expr_allows_subselect)
 
6806
            LEX *lex=Lex;
 
6807
            if (!lex->expr_allows_subselect ||
 
6808
               lex->sql_command == (int)SQLCOM_PURGE)
5483
6809
            {
5484
 
              parser::my_parse_error(YYSession->m_lip);
 
6810
              my_parse_error(ER(ER_SYNTAX_ERROR));
5485
6811
              DRIZZLE_YYABORT;
5486
6812
            }
5487
 
            /*
 
6813
            /* 
5488
6814
              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
 
6815
              as we need to have a lex level to fit the union 
 
6816
              after the parenthesis, e.g. 
 
6817
              (SELECT .. ) UNION ...  becomes 
5492
6818
              SELECT * FROM ((SELECT ...) UNION ...)
5493
6819
            */
5494
 
            if (new_select(Lex, 1))
 
6820
            if (mysql_new_select(Lex, 1))
5495
6821
              DRIZZLE_YYABORT;
5496
6822
          }
5497
6823
        ;
5498
6824
 
5499
6825
subselect_end:
5500
6826
          {
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;
 
6827
            LEX *lex=Lex;
 
6828
            lex->pop_context();
 
6829
            SELECT_LEX *child= lex->current_select;
 
6830
            lex->current_select = lex->current_select->return_after_parsing();
 
6831
            lex->nest_level--;
 
6832
            lex->current_select->n_child_sum_items += child->n_sum_items;
5506
6833
            /*
5507
6834
              A subselect can add fields to an outer select. Reserve space for
5508
6835
              them.
5509
6836
            */
5510
 
            Lex->current_select->select_n_where_fields+=
 
6837
            lex->current_select->select_n_where_fields+=
5511
6838
            child->select_n_where_fields;
5512
6839
          }
5513
6840
        ;