~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_yacc.yy

  • Committer: Stewart Smith
  • Date: 2008-07-23 21:34:38 UTC
  • mto: (207.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 209.
  • Revision ID: stewart@flamingspork.com-20080723213438-4xpwuzu949mmzl0d
cut 'make test' time in half.

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