~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-08-04 06:21:17 UTC
  • mfrom: (1108.2.2 merge)
  • Revision ID: brian@gaz-20090804062117-fef8x6y3ydzrvab3
Merge Brian

Show diffs side-by-side

added added

removed removed

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