~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-10-01 22:56:26 UTC
  • mto: (1154.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: brian@gaz-20091001225626-sb1pdykpxlnkheaj
Remove Factory/make scheduler work like everything else.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
%{
24
 
/* thd is passed as an argument to yyparse(), and subsequently to yylex().
25
 
** The type will be void*, so it must be  cast to (THD*) when used.
26
 
** Use the YYTHD macro for this.
 
24
/* session is passed as an argument to yyparse(), and subsequently to yylex().
 
25
** The type will be void*, so it must be  cast to (Session*) when used.
 
26
** Use the YYSession macro for this.
27
27
*/
28
 
#define YYPARSE_PARAM yythd
29
 
#define YYLEX_PARAM yythd
30
 
#define YYTHD ((THD *)yythd)
 
28
#define YYPARSE_PARAM yysession
 
29
#define YYLEX_PARAM yysession
 
30
#define YYSession (static_cast<Session *>(yysession))
31
31
 
32
32
#define YYENABLE_NLS 0
33
33
#define YYLTYPE_IS_TRIVIAL 0
35
35
#define DRIZZLE_YACC
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
 
#define Lex (YYTHD->lex)
39
 
#define Select Lex->current_select
 
38
#define Lex (YYSession->lex)
40
39
#include <drizzled/server_includes.h>
41
 
#include "lex_symbol.h"
42
 
#include <storage/myisam/myisam.h>
43
 
#include <drizzled/drizzled_error_messages.h>
44
 
 
45
 
int yylex(void *yylval, void *yythd);
 
40
#include <drizzled/lex_symbol.h>
 
41
#include <drizzled/function/locate.h>
 
42
#include <drizzled/function/str/char.h>
 
43
#include <drizzled/function/str/collation.h>
 
44
#include <drizzled/function/str/database.h>
 
45
#include <drizzled/function/str/insert.h>
 
46
#include <drizzled/function/str/left.h>
 
47
#include <drizzled/function/str/repeat.h>
 
48
#include <drizzled/function/str/replace.h>
 
49
#include <drizzled/function/str/reverse.h>
 
50
#include <drizzled/function/str/right.h>
 
51
#include <drizzled/function/str/set_collation.h>
 
52
#include <drizzled/function/str/substr.h>
 
53
#include <drizzled/function/str/trim.h>
 
54
#include <drizzled/function/str/user.h>
 
55
#include <drizzled/function/str/weight_string.h>
 
56
 
 
57
#include <drizzled/function/time/curdate.h>
 
58
#include <drizzled/function/time/date_add_interval.h>
 
59
#include <drizzled/function/time/dayofmonth.h>
 
60
#include <drizzled/function/time/extract.h>
 
61
#include <drizzled/function/time/hour.h>
 
62
#include <drizzled/function/time/microsecond.h>
 
63
#include <drizzled/function/time/minute.h>
 
64
#include <drizzled/function/time/month.h>
 
65
#include <drizzled/function/time/now.h>
 
66
#include <drizzled/function/time/quarter.h>
 
67
#include <drizzled/function/time/second.h>
 
68
#include <drizzled/function/time/sysdate_local.h>
 
69
#include <drizzled/function/time/timestamp_diff.h>
 
70
#include <drizzled/function/time/typecast.h>
 
71
#include <drizzled/function/time/year.h>
 
72
 
 
73
#include <drizzled/error.h>
 
74
#include <drizzled/nested_join.h>
 
75
#include <drizzled/sql_parse.h>
 
76
#include <drizzled/item/copy_string.h>
 
77
#include <drizzled/item/cmpfunc.h>
 
78
#include <drizzled/item/uint.h>
 
79
#include <drizzled/item/null.h>
 
80
#include <drizzled/session.h>
 
81
#include <drizzled/item/func.h>
 
82
#include <drizzled/sql_base.h>
 
83
#include <drizzled/item/create.h>
 
84
#include <drizzled/item/default_value.h>
 
85
#include <drizzled/item/insert_value.h>
 
86
#include <drizzled/lex_string.h>
 
87
#include <drizzled/function/get_system_var.h>
 
88
#include <mysys/thr_lock.h>
 
89
#include <drizzled/message/table.pb.h>
 
90
#include <drizzled/statement.h>
 
91
#include <drizzled/statement/alter_schema.h>
 
92
#include <drizzled/statement/alter_table.h>
 
93
#include <drizzled/statement/analyze.h>
 
94
#include <drizzled/statement/change_schema.h>
 
95
#include <drizzled/statement/check.h>
 
96
#include <drizzled/statement/checksum.h>
 
97
#include <drizzled/statement/commit.h>
 
98
#include <drizzled/statement/create_index.h>
 
99
#include <drizzled/statement/create_schema.h>
 
100
#include <drizzled/statement/create_table.h>
 
101
#include <drizzled/statement/delete.h>
 
102
#include <drizzled/statement/drop_index.h>
 
103
#include <drizzled/statement/drop_schema.h>
 
104
#include <drizzled/statement/drop_table.h>
 
105
#include <drizzled/statement/empty_query.h>
 
106
#include <drizzled/statement/flush.h>
 
107
#include <drizzled/statement/insert.h>
 
108
#include <drizzled/statement/insert_select.h>
 
109
#include <drizzled/statement/kill.h>
 
110
#include <drizzled/statement/load.h>
 
111
#include <drizzled/statement/optimize.h>
 
112
#include <drizzled/statement/release_savepoint.h>
 
113
#include <drizzled/statement/rename_table.h>
 
114
#include <drizzled/statement/replace.h>
 
115
#include <drizzled/statement/replace_select.h>
 
116
#include <drizzled/statement/rollback.h>
 
117
#include <drizzled/statement/rollback_to_savepoint.h>
 
118
#include <drizzled/statement/savepoint.h>
 
119
#include <drizzled/statement/select.h>
 
120
#include <drizzled/statement/set_option.h>
 
121
#include <drizzled/statement/show_create.h>
 
122
#include <drizzled/statement/show_create_schema.h>
 
123
#include <drizzled/statement/show_engine_status.h>
 
124
#include <drizzled/statement/show_errors.h>
 
125
#include <drizzled/statement/show_processlist.h>
 
126
#include <drizzled/statement/show_status.h>
 
127
#include <drizzled/statement/show_warnings.h>
 
128
#include <drizzled/statement/start_transaction.h>
 
129
#include <drizzled/statement/truncate.h>
 
130
#include <drizzled/statement/unlock_tables.h>
 
131
#include <drizzled/statement/update.h>
 
132
 
 
133
using namespace drizzled;
 
134
 
 
135
class Table_ident;
 
136
class Item;
 
137
class Item_num;
 
138
 
 
139
int yylex(void *yylval, void *yysession);
46
140
 
47
141
#define yyoverflow(A,B,C,D,E,F)               \
48
142
  {                                           \
61
155
#define DRIZZLE_YYABORT                         \
62
156
  do                                          \
63
157
  {                                           \
64
 
    LEX::cleanup_lex_after_parse_error(YYTHD);\
 
158
    LEX::cleanup_lex_after_parse_error(YYSession);\
65
159
    YYABORT;                                  \
66
160
  } while (0)
67
161
 
72
166
    DRIZZLE_YYABORT;                      \
73
167
  }
74
168
 
75
 
/*
76
 
  Work around for broken code generated by bison 1.875.
77
 
 
78
 
  The code generated by bison 1.875a and later, bison 2.1 and bison 2.2 is ok.
79
 
  With bison 1.875 however, the generated code contains:
80
 
<pre>
81
 
  yyerrlab1:
82
 
  #if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
83
 
    __attribute__ ((__unused__))
84
 
  #endif
85
 
</pre>
86
 
  This usage of __attribute__ is illegal, so we remove it.
87
 
  See the following references for details:
88
 
  http://lists.gnu.org/archive/html/bug-bison/2004-02/msg00014.html
89
 
  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14273
90
 
*/
91
 
 
92
 
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
93
 
#undef __attribute__
94
 
#define __attribute__(X)
95
 
#endif
96
169
 
97
170
#define YYDEBUG 0
98
171
 
107
180
  parser.
108
181
*/
109
182
 
110
 
void my_parse_error(const char *s)
 
183
static void my_parse_error(const char *s)
111
184
{
112
 
  THD *thd= current_thd;
113
 
  Lex_input_stream *lip= thd->m_lip;
 
185
  Session *session= current_session;
 
186
  Lex_input_stream *lip= session->m_lip;
114
187
 
115
188
  const char *yytext= lip->get_tok_start();
116
189
  /* Push an error into the error stack */
139
212
  to abort from the parser.
140
213
*/
141
214
 
142
 
void MYSQLerror(const char *s)
 
215
static void DRIZZLEerror(const char *s)
143
216
{
144
 
  THD *thd= current_thd;
 
217
  Session *session= current_session;
145
218
 
146
219
  /*
147
220
    Restore the original LEX if it was replaced when parsing
148
221
    a stored procedure. We must ensure that a parsing error
149
 
    does not leave any side effects in the THD.
 
222
    does not leave any side effects in the Session.
150
223
  */
151
 
  LEX::cleanup_lex_after_parse_error(thd);
 
224
  LEX::cleanup_lex_after_parse_error(session);
152
225
 
153
226
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
154
227
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
161
234
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
162
235
  This function returns the proper item for the SQL expression
163
236
  <code>left [NOT] IN ( expr )</code>
164
 
  @param thd the current thread
 
237
  @param session the current thread
165
238
  @param left the in predicand
166
239
  @param equal true for IN predicates, false for NOT IN predicates
167
240
  @param expr first and only expression of the in value list
168
241
  @return an expression representing the IN predicate.
169
242
*/
170
 
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
171
 
                                       Item *expr)
 
243
static Item* handle_sql2003_note184_exception(Session *session,
 
244
                                              Item* left, bool equal,
 
245
                                              Item *expr)
172
246
{
173
247
  /*
174
248
    Relevant references for this issue:
201
275
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
202
276
    {
203
277
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
204
 
      st_select_lex *subselect;
 
278
      Select_Lex *subselect;
205
279
 
206
280
      /*
207
281
        Implement the mandated change, by altering the semantic tree:
212
286
          Item_in_subselect(left, subselect)
213
287
      */
214
288
      subselect= expr3->invalidate_and_restore_select_lex();
215
 
      result= new (thd->mem_root) Item_in_subselect(left, subselect);
 
289
      result= new (session->mem_root) Item_in_subselect(left, subselect);
216
290
 
217
291
      if (! equal)
218
 
        result = negate_expression(thd, result);
 
292
        result = negate_expression(session, result);
219
293
 
220
294
      return(result);
221
295
    }
222
296
  }
223
297
 
224
298
  if (equal)
225
 
    result= new (thd->mem_root) Item_func_eq(left, expr);
 
299
    result= new (session->mem_root) Item_func_eq(left, expr);
226
300
  else
227
 
    result= new (thd->mem_root) Item_func_ne(left, expr);
 
301
    result= new (session->mem_root) Item_func_ne(left, expr);
228
302
 
229
303
  return(result);
230
304
}
231
305
 
232
306
/**
233
 
   @brief Creates a new SELECT_LEX for a UNION branch.
 
307
   @brief Creates a new Select_Lex for a UNION branch.
234
308
 
235
 
   Sets up and initializes a SELECT_LEX structure for a query once the parser
236
 
   discovers a UNION token. The current SELECT_LEX is pushed on the stack and
237
 
   the new SELECT_LEX becomes the current one..=
 
309
   Sets up and initializes a Select_Lex structure for a query once the parser
 
310
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
311
   the new Select_Lex becomes the current one..=
238
312
 
239
313
   @lex The parser state.
240
314
 
244
318
   @return <code>false</code> if successful, <code>true</code> if an error was
245
319
   reported. In the latter case parsing should stop.
246
320
 */
247
 
bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
321
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
248
322
{
249
323
  if (lex->result)
250
324
  {
270
344
}
271
345
 
272
346
/**
273
 
   @brief Initializes a SELECT_LEX for a query within parentheses (aka
 
347
   @brief Initializes a Select_Lex for a query within parentheses (aka
274
348
   braces).
275
349
 
276
350
   @return false if successful, true if an error was reported. In the latter
277
351
   case parsing should stop.
278
352
 */
279
 
bool setup_select_in_parentheses(LEX *lex) 
 
353
static bool setup_select_in_parentheses(LEX *lex) 
280
354
{
281
 
  SELECT_LEX * sel= lex->current_select;
 
355
  Select_Lex * sel= lex->current_select;
282
356
  if (sel->set_braces(1))
283
357
  {
284
358
    my_parse_error(ER(ER_SYNTAX_ERROR));
323
397
  List<String> *string_list;
324
398
  String *string;
325
399
  Key_part_spec *key_part;
326
 
  TABLE_LIST *table_list;
327
 
  udf_func *udf;
328
 
  LEX_USER *lex_user;
 
400
  const ::drizzled::plugin::Function *udf;
 
401
  TableList *table_list;
329
402
  struct sys_var_with_base variable;
330
403
  enum enum_var_type var_type;
331
404
  Key::Keytype key_type;
332
405
  enum ha_key_alg key_alg;
333
 
  handlerton *db_type;
 
406
  ::drizzled::plugin::StorageEngine *db_type;
334
407
  enum row_type row_type;
335
408
  enum column_format_type column_format_type;
336
409
  enum ha_rkey_function ha_rkey_mode;
337
410
  enum enum_tx_isolation tx_isolation;
338
411
  enum Cast_target cast_type;
339
 
  enum ha_choice choice;
340
412
  const CHARSET_INFO *charset;
341
413
  thr_lock_type lock_type;
342
 
  struct st_table_lock_info table_lock_info;
343
414
  interval_type interval, interval_time_st;
344
 
  timestamp_type date_time_type;
345
 
  st_select_lex *select_lex;
 
415
  enum enum_drizzle_timestamp_type date_time_type;
 
416
  Select_Lex *select_lex;
346
417
  chooser_compare_func_creator boolfunc2creator;
347
 
  struct sp_cond_type *spcondtype;
348
 
  struct { int vars, conds, hndlrs, curs; } spblock;
349
418
  struct st_lex *lex;
350
419
  struct p_elem_val *p_elem_value;
351
420
  enum index_hint_type index_hint;
360
429
 
361
430
%pure_parser                                    /* We have threads */
362
431
/*
363
 
  Currently there are 100 shift/reduce conflicts.
 
432
  Currently there are 88 shift/reduce conflicts.
364
433
  We should not introduce new conflicts any more.
365
434
*/
366
 
%expect 95
 
435
%expect 88
367
436
 
368
437
/*
369
438
   Comments for TOKENS.
383
452
*/
384
453
 
385
454
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
386
 
%token  ACCESSIBLE_SYM
387
455
%token  ACTION                        /* SQL-2003-N */
388
456
%token  ADD                           /* SQL-2003-R */
389
457
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
390
458
%token  AFTER_SYM                     /* SQL-2003-N */
391
459
%token  AGGREGATE_SYM
392
 
%token  ALGORITHM_SYM
393
460
%token  ALL                           /* SQL-2003-R */
394
461
%token  ALTER                         /* SQL-2003-R */
395
462
%token  ANALYZE_SYM
397
464
%token  ANY_SYM                       /* SQL-2003-R */
398
465
%token  AS                            /* SQL-2003-R */
399
466
%token  ASC                           /* SQL-2003-N */
400
 
%token  ASCII_SYM                     /* MYSQL-FUNC */
401
467
%token  ASENSITIVE_SYM                /* FUTURE-USE */
402
468
%token  AT_SYM                        /* SQL-2003-R */
403
 
%token  AUTHORS_SYM
404
 
%token  AUTOEXTEND_SIZE_SYM
405
469
%token  AUTO_INC
406
470
%token  AVG_ROW_LENGTH
407
471
%token  AVG_SYM                       /* SQL-2003-N */
408
472
%token  BEFORE_SYM                    /* SQL-2003-N */
409
473
%token  BEGIN_SYM                     /* SQL-2003-R */
410
474
%token  BETWEEN_SYM                   /* SQL-2003-R */
411
 
%token  BIGINT                        /* SQL-2003-R */
 
475
%token  BIGINT_SYM                    /* SQL-2003-R */
412
476
%token  BINARY                        /* SQL-2003-R */
413
477
%token  BINLOG_SYM
414
478
%token  BIN_NUM
463
527
%token  CURDATE                       /* MYSQL-FUNC */
464
528
%token  CURRENT_USER                  /* SQL-2003-R */
465
529
%token  CURSOR_SYM                    /* SQL-2003-R */
466
 
%token  CURTIME                       /* MYSQL-FUNC */
467
530
%token  DATABASE
468
531
%token  DATABASES
469
532
%token  DATAFILE_SYM
470
533
%token  DATA_SYM                      /* SQL-2003-N */
471
 
%token  DATETIME
 
534
%token  DATETIME_SYM
472
535
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
473
536
%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
474
537
%token  DATE_SYM                      /* SQL-2003-R */
482
545
%token  DECIMAL_SYM                   /* SQL-2003-R */
483
546
%token  DECLARE_SYM                   /* SQL-2003-R */
484
547
%token  DEFAULT                       /* SQL-2003-R */
485
 
%token  DELAYED_SYM
486
 
%token  DELAY_KEY_WRITE_SYM
487
548
%token  DELETE_SYM                    /* SQL-2003-R */
488
549
%token  DESC                          /* SQL-2003-N */
489
550
%token  DESCRIBE                      /* SQL-2003-R */
490
551
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
491
 
%token  DIRECTORY_SYM
492
552
%token  DISABLE_SYM
493
553
%token  DISCARD
494
554
%token  DISTINCT                      /* SQL-2003-R */
507
567
%token  ENDS_SYM
508
568
%token  END_OF_INPUT                  /* INTERNAL */
509
569
%token  ENGINE_SYM
510
 
%token  ENUM
 
570
%token  ENUM_SYM
511
571
%token  EQ                            /* OPERATOR */
512
572
%token  EQUAL_SYM                     /* OPERATOR */
513
573
%token  ERRORS
514
574
%token  ESCAPED
515
575
%token  ESCAPE_SYM                    /* SQL-2003-R */
516
 
%token  EVENTS_SYM
517
576
%token  EXCLUSIVE_SYM
518
577
%token  EXISTS                        /* SQL-2003-R */
519
578
%token  EXIT_SYM
522
581
%token  EXTRACT_SYM                   /* SQL-2003-N */
523
582
%token  FALSE_SYM                     /* SQL-2003-R */
524
583
%token  FAST_SYM
525
 
%token  FAULTS_SYM
526
584
%token  FETCH_SYM                     /* SQL-2003-R */
527
585
%token  COLUMN_FORMAT_SYM
528
586
%token  FILE_SYM
538
596
%token  FROM
539
597
%token  FULL                          /* SQL-2003-R */
540
598
%token  GE
541
 
%token  GET_FORMAT                    /* MYSQL-FUNC */
542
599
%token  GLOBAL_SYM                    /* SQL-2003-R */
543
600
%token  GROUP_SYM                     /* SQL-2003-R */
544
601
%token  GROUP_CONCAT_SYM
545
602
%token  GT_SYM                        /* OPERATOR */
546
 
%token  HANDLER_SYM
547
603
%token  HASH_SYM
548
604
%token  HAVING                        /* SQL-2003-R */
549
605
%token  HEX_NUM
550
 
%token  HIGH_PRIORITY
551
606
%token  HOST_SYM
552
607
%token  HOSTS_SYM
553
608
%token  HOUR_MICROSECOND_SYM
563
618
%token  INDEXES
564
619
%token  INDEX_SYM
565
620
%token  INFILE
566
 
%token  INITIAL_SIZE_SYM
567
621
%token  INNER_SYM                     /* SQL-2003-R */
568
622
%token  INOUT_SYM                     /* SQL-2003-R */
569
623
%token  INSENSITIVE_SYM               /* SQL-2003-R */
585
639
%token  LAST_SYM                      /* SQL-2003-N */
586
640
%token  LE                            /* OPERATOR */
587
641
%token  LEADING                       /* SQL-2003-R */
588
 
%token  LEAVES
589
642
%token  LEFT                          /* SQL-2003-R */
590
643
%token  LEVEL_SYM
591
644
%token  LEX_HOSTNAME
592
645
%token  LIKE                          /* SQL-2003-R */
593
646
%token  LIMIT
594
 
%token  LINEAR_SYM
595
647
%token  LINES
596
 
%token  LINESTRING
597
648
%token  LIST_SYM
598
649
%token  LOAD
599
650
%token  LOCAL_SYM                     /* SQL-2003-R */
600
651
%token  LOCATOR_SYM                   /* SQL-2003-N */
601
652
%token  LOCKS_SYM
602
653
%token  LOCK_SYM
603
 
%token  LOGFILE_SYM
604
654
%token  LOGS_SYM
605
655
%token  LONG_NUM
606
656
%token  LONG_SYM
607
657
%token  LOOP_SYM
608
 
%token  LOW_PRIORITY
609
658
%token  LT                            /* OPERATOR */
610
 
%token  MASTER_CONNECT_RETRY_SYM
611
 
%token  MASTER_HOST_SYM
612
 
%token  MASTER_LOG_FILE_SYM
613
 
%token  MASTER_LOG_POS_SYM
614
 
%token  MASTER_PASSWORD_SYM
615
 
%token  MASTER_PORT_SYM
616
 
%token  MASTER_SERVER_ID_SYM
617
 
%token  MASTER_SYM
618
 
%token  MASTER_USER_SYM
619
 
%token  MASTER_HEARTBEAT_PERIOD_SYM
620
659
%token  MATCH                         /* SQL-2003-R */
621
 
%token  MAX_CONNECTIONS_PER_HOUR
622
 
%token  MAX_QUERIES_PER_HOUR
623
660
%token  MAX_ROWS
624
661
%token  MAX_SIZE_SYM
625
662
%token  MAX_SYM                       /* SQL-2003-N */
626
 
%token  MAX_UPDATES_PER_HOUR
627
 
%token  MAX_USER_CONNECTIONS_SYM
628
663
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
629
664
%token  MEDIUM_SYM
630
665
%token  MERGE_SYM                     /* SQL-2003-R */
675
710
%token  OUTER
676
711
%token  OUTFILE
677
712
%token  OUT_SYM                       /* SQL-2003-R */
678
 
%token  PACK_KEYS_SYM
679
713
%token  PAGE_SYM
680
 
%token  PAGE_CHECKSUM_SYM
681
714
%token  PARAM_MARKER
682
715
%token  PARTIAL                       /* SQL-2003-N */
683
716
%token  PHASE_SYM
684
 
%token  PLUGINS_SYM
685
 
%token  PLUGIN_SYM
686
717
%token  POINT_SYM
687
718
%token  PORT_SYM
688
719
%token  POSITION_SYM                  /* SQL-2003-N */
707
738
%token  REDO_BUFFER_SIZE_SYM
708
739
%token  REDUNDANT_SYM
709
740
%token  REFERENCES                    /* SQL-2003-R */
710
 
%token  RELAY_LOG_FILE_SYM
711
 
%token  RELAY_LOG_POS_SYM
712
 
%token  RELAY_THREAD
713
741
%token  RELEASE_SYM                   /* SQL-2003-R */
714
742
%token  RELOAD
715
743
%token  REMOVE_SYM
716
744
%token  RENAME
717
745
%token  REORGANIZE_SYM
718
 
%token  REPAIR
719
746
%token  REPEATABLE_SYM                /* SQL-2003-N */
720
747
%token  REPEAT_SYM                    /* MYSQL-FUNC */
721
748
%token  REPLACE                       /* MYSQL-FUNC */
753
780
%token  SHARE_SYM
754
781
%token  SHOW
755
782
%token  SHUTDOWN
756
 
%token  SIGNED_SYM
757
783
%token  SIMPLE_SYM                    /* SQL-2003-N */
758
 
%token  SLAVE
759
 
%token  SMALLINT                      /* SQL-2003-R */
760
784
%token  SNAPSHOT_SYM
761
785
%token  SOCKET_SYM
762
786
%token  SONAME_SYM
770
794
%token  SQL_CALC_FOUND_ROWS
771
795
%token  SQL_SMALL_RESULT
772
796
%token  SQL_SYM                       /* SQL-2003-R */
773
 
%token  SQL_THREAD
774
797
%token  STARTING
775
798
%token  STARTS_SYM
776
799
%token  START_SYM                     /* SQL-2003-R */
779
802
%token  STD_SYM
780
803
%token  STOP_SYM
781
804
%token  STORAGE_SYM
 
805
%token  STORED_SYM
782
806
%token  STRAIGHT_JOIN
783
807
%token  STRING_SYM
784
808
%token  SUBDATE_SYM
785
809
%token  SUBJECT_SYM
786
810
%token  SUBSTRING                     /* SQL-2003-N */
787
811
%token  SUM_SYM                       /* SQL-2003-N */
788
 
%token  SUPER_SYM
789
812
%token  SUSPEND_SYM
790
813
%token  SWAPS_SYM
791
814
%token  SWITCHES_SYM
794
817
%token  TABLESPACE
795
818
%token  TABLE_REF_PRIORITY
796
819
%token  TABLE_SYM                     /* SQL-2003-R */
797
 
%token  TABLE_CHECKSUM_SYM
798
 
%token  TEMPORARY                     /* SQL-2003-N */
 
820
%token  TEMPORARY_SYM                 /* SQL-2003-N */
799
821
%token  TEMPTABLE_SYM
800
822
%token  TERMINATED
801
823
%token  TEXT_STRING
802
824
%token  TEXT_SYM
803
825
%token  THAN_SYM
804
826
%token  THEN_SYM                      /* SQL-2003-R */
805
 
%token  TIMESTAMP                     /* SQL-2003-R */
 
827
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
806
828
%token  TIMESTAMP_ADD
807
829
%token  TIMESTAMP_DIFF
808
 
%token  TIME_SYM                      /* SQL-2003-R */
809
 
%token  TINYINT
810
830
%token  TO_SYM                        /* SQL-2003-R */
811
831
%token  TRAILING                      /* SQL-2003-R */
812
832
%token  TRANSACTION_SYM
813
 
%token  TRANSACTIONAL_SYM
814
833
%token  TRIM                          /* SQL-2003-N */
815
834
%token  TRUE_SYM                      /* SQL-2003-R */
816
835
%token  TRUNCATE_SYM
819
838
%token  ULONGLONG_NUM
820
839
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
821
840
%token  UNDEFINED_SYM
822
 
%token  UNDERSCORE_CHARSET
823
841
%token  UNDOFILE_SYM
824
842
%token  UNDO_SYM                      /* FUTURE-USE */
825
 
%token  UNICODE_SYM
826
 
%token  UNINSTALL_SYM
827
843
%token  UNION_SYM                     /* SQL-2003-R */
828
844
%token  UNIQUE_SYM
829
845
%token  UNKNOWN_SYM                   /* SQL-2003-R */
830
846
%token  UNLOCK_SYM
831
 
%token  UNSIGNED
832
847
%token  UNTIL_SYM
833
848
%token  UPDATE_SYM                    /* SQL-2003-R */
834
 
%token  UPGRADE_SYM
835
849
%token  USAGE                         /* SQL-2003-N */
836
850
%token  USER                          /* SQL-2003-R */
837
 
%token  USE_FRM
838
851
%token  USE_SYM
839
852
%token  USING                         /* SQL-2003-R */
840
853
%token  UTC_DATE_SYM
841
854
%token  UTC_TIMESTAMP_SYM
842
 
%token  UTC_TIME_SYM
843
855
%token  VALUES                        /* SQL-2003-R */
844
856
%token  VALUE_SYM                     /* SQL-2003-R */
845
857
%token  VARBINARY
846
 
%token  VARCHAR                       /* SQL-2003-R */
 
858
%token  VARCHAR_SYM                   /* SQL-2003-R */
847
859
%token  VARIABLES
848
860
%token  VARIANCE_SYM
849
861
%token  VARYING                       /* SQL-2003-R */
855
867
%token  WHEN_SYM                      /* SQL-2003-R */
856
868
%token  WHERE                         /* SQL-2003-R */
857
869
%token  WITH                          /* SQL-2003-R */
858
 
%token  WITH_CUBE_SYM                 /* INTERNAL */
859
870
%token  WITH_ROLLUP_SYM               /* INTERNAL */
860
871
%token  WORK_SYM                      /* SQL-2003-N */
861
 
%token  WRAPPER_SYM
862
872
%token  WRITE_SYM                     /* SQL-2003-N */
863
873
%token  XOR
864
874
%token  YEAR_MONTH_SYM
884
894
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
885
895
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
886
896
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
887
 
        opt_component key_cache_name
 
897
        opt_component
888
898
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
889
899
        opt_constraint constraint opt_ident
890
900
 
901
911
        text_string opt_gconcat_separator
902
912
 
903
913
%type <num>
904
 
        type int_type real_type order_dir
905
 
        if_exists opt_local opt_table_options table_options
906
 
        table_option opt_if_not_exists opt_no_write_to_binlog
 
914
        type int_type real_type order_dir field_def
 
915
        if_exists opt_table_options table_options
 
916
        table_option opt_if_not_exists
907
917
        opt_temporary all_or_any opt_distinct
908
918
        union_option
909
919
        start_transaction_opts opt_chain opt_release
910
920
        union_opt select_derived_init option_type2
911
 
        opt_transactional_lock_timeout
912
 
        /* opt_lock_timeout_value */
913
921
 
914
922
%type <m_fk_option>
915
923
        delete_option
924
932
%type <ulonglong_number>
925
933
        ulonglong_num
926
934
 
927
 
%type <choice> choice
928
 
 
929
935
%type <lock_type>
930
 
        replace_lock_option opt_low_priority insert_lock_option load_data_lock
931
 
        transactional_lock_mode
932
 
 
933
 
%type <table_lock_info>
934
 
        table_lock_info
 
936
        load_data_lock
935
937
 
936
938
%type <item>
937
939
        literal text_literal insert_ident order_ident
975
977
        select_derived derived_table_list
976
978
        select_derived_union
977
979
 
978
 
%type <date_time_type> date_time_type;
979
980
%type <interval> interval
980
981
 
981
982
%type <interval_time_st> interval_time_st
995
996
%type <symbol> keyword keyword_sp
996
997
 
997
998
%type <charset>
998
 
        opt_collate
999
 
        charset_name
1000
 
        charset_name_or_default
1001
 
        old_or_new_charset_name
1002
 
        old_or_new_charset_name_or_default
1003
999
        collation_name
1004
1000
        collation_name_or_default
1005
 
        opt_load_data_charset
1006
 
        UNDERSCORE_CHARSET
1007
1001
 
1008
1002
%type <variable> internal_variable_name
1009
1003
 
1016
1010
%type <build_method> build_method
1017
1011
 
1018
1012
%type <NONE>
1019
 
        query verb_clause create change select drop insert replace insert2
 
1013
        query verb_clause create select drop insert replace insert2
1020
1014
        insert_values update delete truncate rename
1021
 
        show describe load alter optimize keycache flush
1022
 
        reset purge begin commit rollback savepoint release
1023
 
        slave master_def master_defs master_file_def slave_until_opts
1024
 
        repair analyze check start checksum
 
1015
        show describe load alter optimize flush
 
1016
        begin commit rollback savepoint release
 
1017
        analyze check start checksum
1025
1018
        field_list field_list_item field_spec kill column_def key_def
1026
 
        keycache_list assign_to_keycache
1027
1019
        select_item_list select_item values_list no_braces
1028
1020
        opt_limit_clause delete_limit_clause fields opt_values values
1029
1021
        opt_precision opt_ignore opt_column
1030
 
        set lock unlock string_list field_options field_option
1031
 
        field_opt_list opt_binary table_lock_list table_lock
 
1022
        set unlock string_list
 
1023
        opt_binary
1032
1024
        ref_list opt_match_clause opt_on_update_delete use
1033
1025
        opt_delete_options opt_delete_option varchar
1034
 
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
 
1026
        opt_outer table_list table_name
1035
1027
        opt_option opt_place
1036
1028
        opt_attribute opt_attribute_list attribute
1037
1029
        flush_options flush_option
1038
1030
        equal optional_braces
1039
1031
        opt_mi_check_type opt_to mi_check_types normal_join
1040
1032
        table_to_table_list table_to_table opt_table_list opt_as
1041
 
        single_multi table_wild_list table_wild_one opt_wild
 
1033
        single_multi
1042
1034
        union_clause union_list
1043
 
        precision subselect_start charset
 
1035
        precision subselect_start
1044
1036
        subselect_end select_var_list select_var_list_init opt_len
1045
1037
        opt_extended_describe
1046
1038
        statement
1047
1039
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1048
 
        binlog_base64_event
1049
1040
        init_key_options key_options key_opts key_opt key_using_alg
1050
1041
END_OF_INPUT
1051
1042
 
1083
1074
query:
1084
1075
          END_OF_INPUT
1085
1076
          {
1086
 
            THD *thd= YYTHD;
1087
 
            if (!thd->bootstrap &&
1088
 
              (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
 
1077
            Session *session= YYSession;
 
1078
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
1089
1079
            {
1090
1080
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
1091
1081
              DRIZZLE_YYABORT;
1092
1082
            }
1093
1083
            else
1094
1084
            {
1095
 
              thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1085
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1086
              session->lex->statement= 
 
1087
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
1088
              if (session->lex->statement == NULL)
 
1089
                DRIZZLE_YYABORT;
1096
1090
            }
1097
1091
          }
1098
1092
        | verb_clause END_OF_INPUT {}
1107
1101
statement:
1108
1102
          alter
1109
1103
        | analyze
1110
 
        | binlog_base64_event
1111
 
        | change
1112
1104
        | check
1113
1105
        | checksum
1114
1106
        | commit
1120
1112
        | insert
1121
1113
        | kill
1122
1114
        | load
1123
 
        | lock
1124
1115
        | optimize
1125
 
        | keycache
1126
 
        | purge
1127
1116
        | release
1128
1117
        | rename
1129
 
        | repair
1130
1118
        | replace
1131
 
        | reset
1132
1119
        | rollback
1133
1120
        | savepoint
1134
1121
        | select
1135
1122
        | set
1136
1123
        | show
1137
 
        | slave
1138
1124
        | start
1139
1125
        | truncate
1140
1126
        | unlock
1142
1128
        | use
1143
1129
        ;
1144
1130
 
1145
 
 
1146
 
/* change master */
1147
 
 
1148
 
change:
1149
 
          CHANGE MASTER_SYM TO_SYM
1150
 
          {
1151
 
            LEX *lex = Lex;
1152
 
            lex->sql_command = SQLCOM_CHANGE_MASTER;
1153
 
            memset(&lex->mi, 0, sizeof(lex->mi));
1154
 
          }
1155
 
          master_defs
1156
 
          {}
1157
 
        ;
1158
 
 
1159
 
master_defs:
1160
 
          master_def
1161
 
        | master_defs ',' master_def
1162
 
        ;
1163
 
 
1164
 
master_def:
1165
 
          MASTER_HOST_SYM EQ TEXT_STRING_sys
1166
 
          {
1167
 
            Lex->mi.host = $3.str;
1168
 
          }
1169
 
        | MASTER_USER_SYM EQ TEXT_STRING_sys
1170
 
          {
1171
 
            Lex->mi.user = $3.str;
1172
 
          }
1173
 
        | MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
1174
 
          {
1175
 
            Lex->mi.password = $3.str;
1176
 
          }
1177
 
        | MASTER_PORT_SYM EQ ulong_num
1178
 
          {
1179
 
            Lex->mi.port = $3;
1180
 
          }
1181
 
        | MASTER_CONNECT_RETRY_SYM EQ ulong_num
1182
 
          {
1183
 
            Lex->mi.connect_retry = $3;
1184
 
          }
1185
 
        | MASTER_HEARTBEAT_PERIOD_SYM EQ NUM_literal
1186
 
          {
1187
 
            Lex->mi.heartbeat_period= (float) $3->val_real();
1188
 
            if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD ||
1189
 
                Lex->mi.heartbeat_period < 0.0)
1190
 
            {
1191
 
              char buf[sizeof(SLAVE_MAX_HEARTBEAT_PERIOD*4)];
1192
 
              sprintf(buf, "%d seconds", SLAVE_MAX_HEARTBEAT_PERIOD);
1193
 
              my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1194
 
                       MYF(0),
1195
 
                       " is negative or exceeds the maximum ",
1196
 
                       buf); 
1197
 
              DRIZZLE_YYABORT;
1198
 
            }
1199
 
            if (Lex->mi.heartbeat_period > slave_net_timeout)
1200
 
            {
1201
 
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1202
 
                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1203
 
                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1204
 
                                  " exceeds the value of `slave_net_timeout' sec.",
1205
 
                                  " A sensible value for the period should be"
1206
 
                                  " less than the timeout.");
1207
 
            }
1208
 
            if (Lex->mi.heartbeat_period < 0.001)
1209
 
            {
1210
 
              if (Lex->mi.heartbeat_period != 0.0)
1211
 
              {
1212
 
                push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1213
 
                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1214
 
                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1215
 
                                    " is less than 1 msec.",
1216
 
                                    " The period is reset to zero which means"
1217
 
                                    " no heartbeats will be sending");
1218
 
                Lex->mi.heartbeat_period= 0.0;
1219
 
              }
1220
 
              Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_DISABLE;
1221
 
            }
1222
 
            Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_ENABLE;
1223
 
          }
1224
 
        |
1225
 
        master_file_def
1226
 
        ;
1227
 
 
1228
 
master_file_def:
1229
 
          MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
1230
 
          {
1231
 
            Lex->mi.log_file_name = $3.str;
1232
 
          }
1233
 
        | MASTER_LOG_POS_SYM EQ ulonglong_num
1234
 
          {
1235
 
            Lex->mi.pos = $3;
1236
 
            /* 
1237
 
               If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
1238
 
               instead of causing subsequent errors. 
1239
 
               We need to do it in this file, because only there we know that 
1240
 
               MASTER_LOG_POS has been explicitely specified. On the contrary
1241
 
               in change_master() (sql_repl.cc) we cannot distinguish between 0
1242
 
               (MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
1243
 
               whereas we want to distinguish (specified 0 means "read the binlog
1244
 
               from 0" (4 in fact), unspecified means "don't change the position
1245
 
               (keep the preceding value)").
1246
 
            */
1247
 
            Lex->mi.pos = max((uint64_t)BIN_LOG_HEADER_SIZE, Lex->mi.pos);
1248
 
          }
1249
 
        | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
1250
 
          {
1251
 
            Lex->mi.relay_log_name = $3.str;
1252
 
          }
1253
 
        | RELAY_LOG_POS_SYM EQ ulong_num
1254
 
          {
1255
 
            Lex->mi.relay_log_pos = $3;
1256
 
            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
1257
 
            Lex->mi.relay_log_pos = max((uint32_t)BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
1258
 
          }
1259
 
        ;
1260
 
 
1261
1131
/* create a table */
1262
1132
 
1263
1133
create:
1264
1134
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1265
1135
          {
1266
 
            THD *thd= YYTHD;
1267
 
            LEX *lex= thd->lex;
 
1136
            Session *session= YYSession;
 
1137
            LEX *lex= session->lex;
1268
1138
            lex->sql_command= SQLCOM_CREATE_TABLE;
1269
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
1139
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1140
            lex->statement= statement;
 
1141
            if (lex->statement == NULL)
 
1142
              DRIZZLE_YYABORT;
 
1143
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1270
1144
                                                   TL_OPTION_UPDATING,
1271
1145
                                                   TL_WRITE))
1272
1146
              DRIZZLE_YYABORT;
1273
 
            lex->alter_info.reset();
1274
1147
            lex->col_list.empty();
1275
 
            lex->change=NullS;
1276
 
            memset(&lex->create_info, 0, sizeof(lex->create_info));
1277
 
            lex->create_info.options=$2 | $4;
1278
 
            lex->create_info.db_type= ha_default_handlerton(thd);
1279
 
            lex->create_info.default_table_charset= NULL;
 
1148
            statement->change=NULL;
 
1149
            statement->create_info.options=$2 | $4;
 
1150
            statement->create_info.db_type= ha_default_storage_engine(session);
 
1151
            statement->create_info.default_table_charset= NULL;
1280
1152
            lex->name.str= 0;
1281
 
            lex->name.length= 0;
 
1153
 
 
1154
            message::Table *proto= &statement->create_table_proto;
 
1155
            
 
1156
            proto->set_name($5->table.str);
 
1157
            if($2 & HA_LEX_CREATE_TMP_TABLE)
 
1158
              proto->set_type(message::Table::TEMPORARY);
 
1159
            else
 
1160
              proto->set_type(message::Table::STANDARD);
 
1161
 
 
1162
            {
 
1163
              message::Table::StorageEngine *protoengine;
 
1164
              protoengine= proto->mutable_engine();
 
1165
              drizzled::plugin::StorageEngine *engine= ha_default_storage_engine(session);
 
1166
 
 
1167
              protoengine->set_name(engine->getName());
 
1168
            }
1282
1169
          }
1283
1170
          create2
1284
1171
          {
1285
 
            LEX *lex= YYTHD->lex;
 
1172
            LEX *lex= YYSession->lex;
 
1173
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1286
1174
            lex->current_select= &lex->select_lex; 
1287
 
            if (!lex->create_info.db_type)
1288
 
            {
1289
 
              lex->create_info.db_type= ha_default_handlerton(YYTHD);
1290
 
              push_warning_printf(YYTHD, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1291
 
                                  ER_WARN_USING_OTHER_HANDLER,
1292
 
                                  ER(ER_WARN_USING_OTHER_HANDLER),
1293
 
                                  ha_resolve_storage_engine_name(lex->create_info.db_type),
1294
 
                                  $5->table.str);
1295
 
            }
 
1175
            assert(statement->create_info.db_type);
1296
1176
          }
1297
 
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
1298
 
          ON table_ident
 
1177
        | CREATE build_method
1299
1178
          {
1300
1179
            LEX *lex=Lex;
1301
1180
            lex->sql_command= SQLCOM_CREATE_INDEX;
1302
 
            if (!lex->current_select->add_table_to_list(lex->thd, $8,
 
1181
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1182
            lex->statement= statement;
 
1183
            if (lex->statement == NULL)
 
1184
              DRIZZLE_YYABORT;
 
1185
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1186
            statement->alter_info.build_method= $2;
 
1187
            lex->col_list.empty();
 
1188
            statement->change=NULL;
 
1189
          }
 
1190
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
 
1191
          {
 
1192
            LEX *lex=Lex;
 
1193
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1194
 
 
1195
            if (!lex->current_select->add_table_to_list(lex->session, $9,
1303
1196
                                                        NULL,
1304
1197
                                                        TL_OPTION_UPDATING))
1305
1198
              DRIZZLE_YYABORT;
1306
 
            lex->alter_info.reset();
1307
 
            lex->alter_info.flags= ALTER_ADD_INDEX;
1308
 
            lex->alter_info.build_method= $2;
1309
 
            lex->col_list.empty();
1310
 
            lex->change=NullS;
1311
 
          }
1312
 
          '(' key_list ')' key_options
1313
 
          {
1314
 
            LEX *lex=Lex;
1315
1199
            Key *key;
1316
 
            key= new Key($3, $5, &lex->key_create_info, 0,
1317
 
                         lex->col_list);
1318
 
            lex->alter_info.key_list.push_back(key);
 
1200
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1201
            statement->alter_info.key_list.push_back(key);
1319
1202
            lex->col_list.empty();
1320
1203
          }
1321
1204
        | CREATE DATABASE opt_if_not_exists ident
1322
1205
          {
1323
 
            Lex->create_info.default_table_charset= NULL;
1324
 
            Lex->create_info.used_fields= 0;
 
1206
            LEX *lex=Lex;
 
1207
 
 
1208
            lex->sql_command=SQLCOM_CREATE_DB;
 
1209
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1210
            lex->statement= statement;
 
1211
            if (lex->statement == NULL)
 
1212
              DRIZZLE_YYABORT;
 
1213
            statement->create_info.options=$3;
1325
1214
          }
1326
1215
          opt_create_database_options
1327
1216
          {
1328
 
            LEX *lex=Lex;
1329
 
            lex->sql_command=SQLCOM_CREATE_DB;
1330
 
            lex->name= $4;
1331
 
            lex->create_info.options=$3;
 
1217
            Lex->name= $4;
1332
1218
          }
1333
1219
        ;
1334
1220
 
1338
1224
          create3 {}
1339
1225
        | LIKE table_ident
1340
1226
          {
1341
 
            THD *thd= YYTHD;
1342
 
            LEX *lex= thd->lex;
 
1227
            Session *session= YYSession;
 
1228
            LEX *lex= session->lex;
 
1229
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1343
1230
 
1344
 
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1345
 
            if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
 
1231
            statement->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1232
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1346
1233
              DRIZZLE_YYABORT;
1347
1234
          }
1348
1235
        | '(' LIKE table_ident ')'
1349
1236
          {
1350
 
            THD *thd= YYTHD;
1351
 
            LEX *lex= thd->lex;
 
1237
            Session *session= YYSession;
 
1238
            LEX *lex= session->lex;
 
1239
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1352
1240
 
1353
 
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1354
 
            if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
 
1241
            statement->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1242
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1355
1243
              DRIZZLE_YYABORT;
1356
1244
          }
1357
1245
        ;
1360
1248
          field_list ')' opt_create_table_options
1361
1249
          create3 {}
1362
1250
        |  create_select ')'
1363
 
           { Select->set_braces(1);}
 
1251
           { Lex->current_select->set_braces(1);}
1364
1252
           union_opt {}
1365
1253
        ;
1366
1254
 
1367
1255
create3:
1368
1256
          /* empty */ {}
1369
1257
        | opt_duplicate opt_as create_select
1370
 
          { Select->set_braces(0);}
 
1258
          { Lex->current_select->set_braces(0);}
1371
1259
          union_clause {}
1372
1260
        | opt_duplicate opt_as '(' create_select ')'
1373
 
          { Select->set_braces(1);}
 
1261
          { Lex->current_select->set_braces(1);}
1374
1262
          union_opt {}
1375
1263
        ;
1376
1264
 
1378
1266
          SELECT_SYM
1379
1267
          {
1380
1268
            LEX *lex=Lex;
1381
 
            lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
 
1269
            lex->lock_option= TL_READ;
1382
1270
            if (lex->sql_command == SQLCOM_INSERT)
 
1271
            {
1383
1272
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1273
              lex->statement= 
 
1274
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1275
              if (lex->statement == NULL)
 
1276
                DRIZZLE_YYABORT;
 
1277
            }
1384
1278
            else if (lex->sql_command == SQLCOM_REPLACE)
 
1279
            {
1385
1280
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1281
              lex->statement= 
 
1282
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1283
              if (lex->statement == NULL)
 
1284
                DRIZZLE_YYABORT;
 
1285
            }
1386
1286
            /*
1387
1287
              The following work only with the local list, the global list
1388
1288
              is created correctly in this case
1393
1293
          }
1394
1294
          select_options select_item_list
1395
1295
          {
1396
 
            Select->parsing_place= NO_MATTER;
 
1296
            Lex->current_select->parsing_place= NO_MATTER;
1397
1297
          }
1398
1298
          opt_select_from
1399
1299
          {
1412
1312
 
1413
1313
opt_create_database_options:
1414
1314
          /* empty */ {}
1415
 
        | create_database_options {}
1416
 
        ;
1417
 
 
1418
 
create_database_options:
1419
 
          create_database_option {}
1420
 
        | create_database_options create_database_option {}
1421
 
        ;
1422
 
 
1423
 
create_database_option:
1424
 
          default_collation {}
1425
 
        | default_charset {}
 
1315
        | default_collation_schema {}
1426
1316
        ;
1427
1317
 
1428
1318
opt_table_options:
1436
1326
        ;
1437
1327
 
1438
1328
table_option:
1439
 
          TEMPORARY { $$=HA_LEX_CREATE_TMP_TABLE; }
 
1329
          TEMPORARY_SYM { $$=HA_LEX_CREATE_TMP_TABLE; }
1440
1330
        ;
1441
1331
 
1442
1332
opt_if_not_exists:
1463
1353
create_table_option:
1464
1354
          ENGINE_SYM opt_equal storage_engines
1465
1355
          {
1466
 
            Lex->create_info.db_type= $3;
1467
 
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
1468
 
          }
1469
 
        | MAX_ROWS opt_equal ulonglong_num
1470
 
          {
1471
 
            Lex->create_info.max_rows= $3;
1472
 
            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
1473
 
          }
1474
 
        | MIN_ROWS opt_equal ulonglong_num
1475
 
          {
1476
 
            Lex->create_info.min_rows= $3;
1477
 
            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
1478
 
          }
1479
 
        | AVG_ROW_LENGTH opt_equal ulong_num
1480
 
          {
1481
 
            Lex->create_info.avg_row_length=$3;
1482
 
            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
 
1356
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1357
 
 
1358
            statement->create_info.db_type= $3;
 
1359
            statement->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1360
 
 
1361
            {
 
1362
              message::Table::StorageEngine *protoengine;
 
1363
              protoengine= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_engine();
 
1364
 
 
1365
              protoengine->set_name($3->getName());
 
1366
            }
1483
1367
          }
1484
1368
        | BLOCK_SIZE_SYM opt_equal ulong_num    
1485
1369
          { 
1486
 
            Lex->create_info.block_size= $3; 
1487
 
            Lex->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
 
1370
            message::Table::TableOptions *tableopts;
 
1371
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1372
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1373
 
 
1374
            tableopts->set_block_size($3);
 
1375
            statement->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
1488
1376
          }
1489
1377
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1490
1378
          {
1491
 
            Lex->create_info.comment=$3;
1492
 
            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
 
1379
            message::Table::TableOptions *tableopts;
 
1380
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1381
 
 
1382
            tableopts->set_comment($3.str);
1493
1383
          }
1494
1384
        | AUTO_INC opt_equal ulonglong_num
1495
1385
          {
1496
 
            Lex->create_info.auto_increment_value=$3;
1497
 
            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
1498
 
          }
1499
 
        | PACK_KEYS_SYM opt_equal ulong_num
1500
 
          {
1501
 
            switch($3) {
1502
 
            case 0:
1503
 
                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
1504
 
                break;
1505
 
            case 1:
1506
 
                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
1507
 
                break;
1508
 
            default:
1509
 
                my_parse_error(ER(ER_SYNTAX_ERROR));
1510
 
                DRIZZLE_YYABORT;
1511
 
            }
1512
 
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
1513
 
          }
1514
 
        | PACK_KEYS_SYM opt_equal DEFAULT
1515
 
          {
1516
 
            Lex->create_info.table_options&=
1517
 
              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
1518
 
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
1519
 
          }
1520
 
        | CHECKSUM_SYM opt_equal ulong_num
1521
 
          {
1522
 
            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
1523
 
            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
1524
 
          }
1525
 
        | TABLE_CHECKSUM_SYM opt_equal ulong_num
1526
 
          {
1527
 
             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
1528
 
             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
1529
 
          }
1530
 
        | PAGE_CHECKSUM_SYM opt_equal choice
1531
 
          {
1532
 
            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
1533
 
            Lex->create_info.page_checksum= $3;
1534
 
          }
1535
 
        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
1536
 
          {
1537
 
            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
1538
 
            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
 
1386
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1387
 
 
1388
            statement->create_info.auto_increment_value=$3;
 
1389
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1539
1390
          }
1540
1391
        | ROW_FORMAT_SYM opt_equal row_types
1541
1392
          {
1542
 
            Lex->create_info.row_type= $3;
1543
 
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1544
 
            Lex->alter_info.flags|= ALTER_ROW_FORMAT;
 
1393
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1394
 
 
1395
            statement->create_info.row_type= $3;
 
1396
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1397
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1545
1398
          }
1546
 
        | default_charset
1547
1399
        | default_collation
1548
 
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1549
 
          {
1550
 
            Lex->create_info.data_file_name= $4.str;
1551
 
            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
1552
 
          }
1553
 
        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1554
 
          {
1555
 
            Lex->create_info.index_file_name= $4.str;
1556
 
            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
1557
 
          }
1558
 
        | CONNECTION_SYM opt_equal TEXT_STRING_sys
1559
 
          {
1560
 
            Lex->create_info.connect_string.str= $3.str;
1561
 
            Lex->create_info.connect_string.length= $3.length;
1562
 
            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
1563
 
          }
1564
1400
        | KEY_BLOCK_SIZE opt_equal ulong_num
1565
1401
          {
1566
 
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1567
 
            Lex->create_info.key_block_size= $3;
1568
 
          }
1569
 
        | TRANSACTIONAL_SYM opt_equal choice
1570
 
          {
1571
 
            Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
1572
 
            Lex->create_info.transactional= $3;
1573
 
          }
1574
 
        ;
 
1402
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1575
1403
 
1576
 
default_charset:
1577
 
          opt_default charset opt_equal charset_name_or_default
1578
 
          {
1579
 
            HA_CREATE_INFO *cinfo= &Lex->create_info;
1580
 
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1581
 
                 cinfo->default_table_charset && $4 &&
1582
 
                 !my_charset_same(cinfo->default_table_charset,$4))
1583
 
            {
1584
 
              my_error(ER_CONFLICTING_DECLARATIONS, MYF(0),
1585
 
                       "CHARACTER SET ", cinfo->default_table_charset->csname,
1586
 
                       "CHARACTER SET ", $4->csname);
1587
 
              DRIZZLE_YYABORT;
1588
 
            }
1589
 
            Lex->create_info.default_table_charset= $4;
1590
 
            Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1404
            statement->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1405
            statement->create_info.key_block_size= $3;
1591
1406
          }
1592
1407
        ;
1593
1408
 
1594
1409
default_collation:
1595
1410
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1596
1411
          {
1597
 
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1412
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1413
 
 
1414
            HA_CREATE_INFO *cinfo= &statement->create_info;
1598
1415
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1599
1416
                 cinfo->default_table_charset && $4 &&
1600
1417
                 !my_charset_same(cinfo->default_table_charset,$4))
1603
1420
                         $4->name, cinfo->default_table_charset->csname);
1604
1421
                DRIZZLE_YYABORT;
1605
1422
              }
1606
 
              Lex->create_info.default_table_charset= $4;
1607
 
              Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1423
              statement->create_info.default_table_charset= $4;
 
1424
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1425
          }
 
1426
        ;
 
1427
 
 
1428
default_collation_schema:
 
1429
          opt_default COLLATE_SYM opt_equal collation_name_or_default
 
1430
          {
 
1431
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1432
 
 
1433
            statement->create_info.default_table_charset= $4;
 
1434
            statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1608
1435
          }
1609
1436
        ;
1610
1437
 
1611
1438
storage_engines:
1612
1439
          ident_or_text
1613
1440
          {
1614
 
            plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
 
1441
            const std::string engine_name($1.str);
 
1442
            drizzled::plugin::StorageEngine *engine= plugin::StorageEngine::findByName(YYSession, engine_name);
1615
1443
 
1616
 
            if (plugin)
1617
 
              $$= plugin_data(plugin, handlerton*);
 
1444
            if (engine)
 
1445
              $$= engine;
1618
1446
            else
1619
1447
            {
1620
1448
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1626
1454
known_storage_engines:
1627
1455
          ident_or_text
1628
1456
          {
1629
 
            plugin_ref plugin;
1630
 
            if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
1631
 
              $$= plugin_data(plugin, handlerton*);
 
1457
            const std::string engine_name($1.str);
 
1458
            drizzled::plugin::StorageEngine *engine;
 
1459
            if ((engine= plugin::StorageEngine::findByName(YYSession, engine_name)))
 
1460
              $$= engine;
1632
1461
            else
1633
1462
            {
1634
1463
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1679
1508
          key_type opt_ident key_alg '(' key_list ')' key_options
1680
1509
          {
1681
1510
            LEX *lex=Lex;
1682
 
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
 
1511
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1512
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1683
1513
                              lex->col_list);
1684
 
            lex->alter_info.key_list.push_back(key);
 
1514
            statement->alter_info.key_list.push_back(key);
1685
1515
            lex->col_list.empty(); /* Alloced by sql_alloc */
1686
1516
          }
1687
1517
        | opt_constraint constraint_key_type opt_ident key_alg
1688
1518
          '(' key_list ')' key_options
1689
1519
          {
1690
1520
            LEX *lex=Lex;
1691
 
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
 
1521
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1522
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1692
1523
                              lex->col_list);
1693
 
            lex->alter_info.key_list.push_back(key);
 
1524
            statement->alter_info.key_list.push_back(key);
1694
1525
            lex->col_list.empty(); /* Alloced by sql_alloc */
1695
1526
          }
1696
1527
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1697
1528
          {
1698
1529
            LEX *lex=Lex;
 
1530
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1699
1531
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1700
1532
                                      $8,
1701
1533
                                      lex->ref_list,
1702
 
                                      lex->fk_delete_opt,
1703
 
                                      lex->fk_update_opt,
1704
 
                                      lex->fk_match_option);
1705
 
            lex->alter_info.key_list.push_back(key);
 
1534
                                      statement->fk_delete_opt,
 
1535
                                      statement->fk_update_opt,
 
1536
                                      statement->fk_match_option);
 
1537
            statement->alter_info.key_list.push_back(key);
1706
1538
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1707
1539
                         &default_key_create_info, 1,
1708
1540
                         lex->col_list);
1709
 
            lex->alter_info.key_list.push_back(key);
 
1541
            statement->alter_info.key_list.push_back(key);
1710
1542
            lex->col_list.empty(); /* Alloced by sql_alloc */
1711
1543
            /* Only used for ALTER TABLE. Ignored otherwise. */
1712
 
            lex->alter_info.flags|= ALTER_FOREIGN_KEY;
 
1544
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1713
1545
          }
1714
1546
        | constraint opt_check_constraint
1715
1547
          {
1743
1575
          field_ident
1744
1576
          {
1745
1577
            LEX *lex=Lex;
 
1578
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1746
1579
            lex->length=lex->dec=0;
1747
1580
            lex->type=0;
1748
 
            lex->default_value= lex->on_update_value= 0;
1749
 
            lex->comment=null_lex_str;
 
1581
            statement->default_value= statement->on_update_value= 0;
 
1582
            statement->comment= null_lex_str;
1750
1583
            lex->charset=NULL;
1751
 
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1584
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1752
1585
          }
1753
 
          type opt_attribute
 
1586
          field_def
1754
1587
          {
1755
1588
            LEX *lex=Lex;
1756
 
            if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
 
1589
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1590
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1757
1591
                                  lex->length,lex->dec,lex->type,
1758
 
                                  lex->column_format,
1759
 
                                  lex->default_value, lex->on_update_value, 
1760
 
                                  &lex->comment,
1761
 
                                  lex->change,&lex->interval_list,lex->charset))
 
1592
                                  statement->column_format,
 
1593
                                  statement->default_value, statement->on_update_value, 
 
1594
                                  &statement->comment,
 
1595
                                  statement->change, &lex->interval_list, lex->charset))
1762
1596
              DRIZZLE_YYABORT;
1763
1597
          }
1764
1598
        ;
 
1599
field_def:
 
1600
          type opt_attribute {}
 
1601
        ;
1765
1602
 
1766
1603
type:
1767
 
        int_type field_options 
 
1604
        int_type
1768
1605
        { 
1769
1606
          $$=$1; 
1770
1607
          Lex->length=(char*) 0; /* use default length */
1771
1608
        }
1772
 
        | real_type opt_precision field_options { $$=$1; }
1773
 
        | BIT_SYM
1774
 
          {
1775
 
            Lex->length= (char*) "1";
1776
 
            $$=DRIZZLE_TYPE_TINY;
1777
 
          }
1778
 
        | BOOL_SYM
1779
 
          {
1780
 
            Lex->length=(char*) "1";
1781
 
            $$=DRIZZLE_TYPE_TINY;
1782
 
          }
1783
 
        | BOOLEAN_SYM
1784
 
          {
1785
 
            Lex->length=(char*) "1";
1786
 
            $$=DRIZZLE_TYPE_TINY;
1787
 
          }
 
1609
        | real_type opt_precision { $$=$1; }
1788
1610
        | char '(' NUM ')' opt_binary
1789
1611
          {
1790
1612
            Lex->length=$3.str;
1807
1629
            $$= DRIZZLE_TYPE_VARCHAR;
1808
1630
          }
1809
1631
        | DATE_SYM
1810
 
          { $$=DRIZZLE_TYPE_NEWDATE; }
1811
 
        | TIME_SYM
1812
 
          { $$=DRIZZLE_TYPE_TIME; }
1813
 
        | TIMESTAMP
1814
 
          {
1815
 
            /* Unlike other types TIMESTAMP fields are NOT NULL by default */
1816
 
            Lex->type|= NOT_NULL_FLAG;
1817
 
            $$=DRIZZLE_TYPE_TIMESTAMP;
1818
 
          }
1819
 
        | DATETIME
 
1632
          { $$=DRIZZLE_TYPE_DATE; }
 
1633
        | TIMESTAMP_SYM
 
1634
          { $$=DRIZZLE_TYPE_TIMESTAMP; }
 
1635
        | DATETIME_SYM
1820
1636
          { $$=DRIZZLE_TYPE_DATETIME; }
1821
1637
        | BLOB_SYM
1822
1638
          {
1829
1645
            $$=DRIZZLE_TYPE_BLOB; 
1830
1646
            Lex->length=(char*) 0; /* use default length */
1831
1647
          }
1832
 
        | DECIMAL_SYM float_options field_options
1833
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1834
 
        | NUMERIC_SYM float_options field_options
1835
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1836
 
        | FIXED_SYM float_options field_options
1837
 
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
1838
 
        | ENUM
 
1648
        | DECIMAL_SYM float_options
 
1649
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1650
        | NUMERIC_SYM float_options
 
1651
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1652
        | FIXED_SYM float_options
 
1653
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1654
        | ENUM_SYM
1839
1655
          {Lex->interval_list.empty();}
1840
1656
          '(' string_list ')' opt_binary
1841
1657
          { $$=DRIZZLE_TYPE_ENUM; }
1842
1658
        | SERIAL_SYM
1843
1659
          {
1844
1660
            $$=DRIZZLE_TYPE_LONGLONG;
1845
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
1846
 
              UNIQUE_FLAG);
 
1661
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1847
1662
          }
1848
1663
        ;
1849
1664
 
1853
1668
 
1854
1669
varchar:
1855
1670
          char VARYING {}
1856
 
        | VARCHAR {}
 
1671
        | VARCHAR_SYM {}
1857
1672
        ;
1858
1673
 
1859
1674
int_type:
1860
 
          INT_SYM   { $$=DRIZZLE_TYPE_LONG; }
1861
 
        | TINYINT   { $$=DRIZZLE_TYPE_TINY; }
1862
 
        | SMALLINT  { $$=DRIZZLE_TYPE_SHORT; }
1863
 
        | BIGINT    { $$=DRIZZLE_TYPE_LONGLONG; }
 
1675
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1676
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1864
1677
        ;
1865
1678
 
1866
1679
real_type:
1892
1705
          }
1893
1706
        ;
1894
1707
 
1895
 
field_options:
1896
 
          /* empty */ {}
1897
 
        | field_opt_list {}
1898
 
        ;
1899
 
 
1900
 
field_opt_list:
1901
 
          field_opt_list field_option {}
1902
 
        | field_option {}
1903
 
        ;
1904
 
 
1905
 
field_option:
1906
 
          SIGNED_SYM {}
1907
 
        | UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
1908
 
        ;
1909
 
 
1910
1708
opt_len:
1911
1709
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
1912
1710
        | '(' NUM ')' { Lex->length= $2.str; }
1931
1729
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
1932
1730
        | COLUMN_FORMAT_SYM column_format_types
1933
1731
          {
1934
 
            Lex->column_format= $2;
1935
 
            Lex->alter_info.flags|= ALTER_COLUMN_FORMAT;
 
1732
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1733
 
 
1734
            statement->column_format= $2;
 
1735
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1936
1736
          }
1937
1737
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
1938
1738
        | DEFAULT now_or_signed_literal 
1939
1739
          { 
1940
 
            Lex->default_value=$2; 
1941
 
            Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
1740
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1741
 
 
1742
            statement->default_value=$2; 
 
1743
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1942
1744
          }
1943
1745
        | ON UPDATE_SYM NOW_SYM optional_braces 
1944
 
          { Lex->on_update_value= new Item_func_now_local(); }
 
1746
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1945
1747
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1946
1748
        | SERIAL_SYM DEFAULT VALUE_SYM
1947
1749
          { 
1948
1750
            LEX *lex=Lex;
 
1751
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1752
 
1949
1753
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1950
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1754
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1951
1755
          }
1952
1756
        | opt_primary KEY_SYM
1953
1757
          {
1954
1758
            LEX *lex=Lex;
 
1759
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1760
 
1955
1761
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1956
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1762
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1957
1763
          }
1958
1764
        | UNIQUE_SYM
1959
1765
          {
1960
1766
            LEX *lex=Lex;
 
1767
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1768
 
1961
1769
            lex->type|= UNIQUE_FLAG; 
1962
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1770
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1963
1771
          }
1964
1772
        | UNIQUE_SYM KEY_SYM
1965
1773
          {
1966
1774
            LEX *lex=Lex;
 
1775
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1776
 
1967
1777
            lex->type|= UNIQUE_KEY_FLAG; 
1968
 
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
1778
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1969
1779
          }
1970
 
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
 
1780
        | COMMENT_SYM TEXT_STRING_sys { ((statement::AlterTable *)Lex->statement)->comment= $2; }
1971
1781
        | COLLATE_SYM collation_name
1972
1782
          {
1973
1783
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
1990
1800
          { $$=$1; }
1991
1801
        ;
1992
1802
 
1993
 
charset:
1994
 
          CHAR_SYM SET {}
1995
 
        | CHARSET {}
1996
 
        ;
1997
 
 
1998
 
charset_name:
1999
 
          ident_or_text
2000
 
          {
2001
 
            if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
2002
 
            {
2003
 
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
2004
 
              DRIZZLE_YYABORT;
2005
 
            }
2006
 
          }
2007
 
        | BINARY { $$= &my_charset_bin; }
2008
 
        ;
2009
 
 
2010
 
charset_name_or_default:
2011
 
          charset_name { $$=$1;   }
2012
 
        | DEFAULT    { $$=NULL; }
2013
 
        ;
2014
 
 
2015
 
opt_load_data_charset:
2016
 
          /* Empty */ { $$= NULL; }
2017
 
        | charset charset_name_or_default { $$= $2; }
2018
 
        ;
2019
 
 
2020
 
old_or_new_charset_name:
2021
 
          ident_or_text
2022
 
          {
2023
 
            if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
2024
 
                !($$=get_old_charset_by_name($1.str)))
2025
 
            {
2026
 
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
2027
 
              DRIZZLE_YYABORT;
2028
 
            }
2029
 
          }
2030
 
        | BINARY { $$= &my_charset_bin; }
2031
 
        ;
2032
 
 
2033
 
old_or_new_charset_name_or_default:
2034
 
          old_or_new_charset_name { $$=$1;   }
2035
 
        | DEFAULT    { $$=NULL; }
2036
 
        ;
2037
 
 
2038
1803
collation_name:
2039
1804
          ident_or_text
2040
1805
          {
2041
 
            if (!($$=get_charset_by_name($1.str,MYF(0))))
 
1806
            if (!($$=get_charset_by_name($1.str)))
2042
1807
            {
2043
1808
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
2044
1809
              DRIZZLE_YYABORT;
2046
1811
          }
2047
1812
        ;
2048
1813
 
2049
 
opt_collate:
2050
 
          /* empty */ { $$=NULL; }
2051
 
        | COLLATE_SYM collation_name_or_default { $$=$2; }
2052
 
        ;
2053
 
 
2054
1814
collation_name_or_default:
2055
1815
          collation_name { $$=$1; }
2056
1816
        | DEFAULT    { $$=NULL; }
2063
1823
 
2064
1824
opt_binary:
2065
1825
          /* empty */ { Lex->charset=NULL; }
2066
 
        | ASCII_SYM opt_bin_mod { Lex->charset=&my_charset_latin1; }
2067
1826
        | BYTE_SYM { Lex->charset=&my_charset_bin; }
2068
 
        | UNICODE_SYM opt_bin_mod
2069
 
          {
2070
 
            if (!(Lex->charset=get_charset_by_csname("ucs2",
2071
 
                                                     MY_CS_PRIMARY,MYF(0))))
2072
 
            {
2073
 
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
2074
 
              DRIZZLE_YYABORT;
2075
 
            }
2076
 
          }
2077
 
        | charset charset_name opt_bin_mod { Lex->charset=$2; }
2078
 
        | BINARY opt_bin_charset { Lex->type|= BINCMP_FLAG; }
2079
 
        ;
2080
 
 
2081
 
opt_bin_mod:
2082
 
          /* empty */ { }
2083
1827
        | BINARY { Lex->type|= BINCMP_FLAG; }
2084
1828
        ;
2085
1829
 
2086
 
opt_bin_charset:
2087
 
          /* empty */ { Lex->charset= NULL; }
2088
 
        | ASCII_SYM { Lex->charset=&my_charset_latin1; }
2089
 
        | UNICODE_SYM
2090
 
          {
2091
 
            if (!(Lex->charset=get_charset_by_csname("ucs2",
2092
 
                                                     MY_CS_PRIMARY,MYF(0))))
2093
 
            {
2094
 
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
2095
 
              DRIZZLE_YYABORT;
2096
 
            }
2097
 
          }
2098
 
        | charset charset_name { Lex->charset=$2; }
2099
 
        ;
2100
 
 
2101
1830
ws_nweights:
2102
1831
        '(' real_ulong_num
2103
1832
        {
2149
1878
ws_level_range:
2150
1879
        ws_level_number '-' ws_level_number
2151
1880
        {
2152
 
          uint start= $1;
2153
 
          uint end= $3;
 
1881
          uint32_t start= $1;
 
1882
          uint32_t end= $3;
2154
1883
          for ($$= 0; start <= end; start++)
2155
1884
            $$|= (1 << start);
2156
1885
        }
2201
1930
 
2202
1931
opt_match_clause:
2203
1932
          /* empty */
2204
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
 
1933
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
2205
1934
        | MATCH FULL
2206
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
 
1935
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
2207
1936
        | MATCH PARTIAL
2208
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
 
1937
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
2209
1938
        | MATCH SIMPLE_SYM
2210
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
 
1939
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
2211
1940
        ;
2212
1941
 
2213
1942
opt_on_update_delete:
2214
1943
          /* empty */
2215
1944
          {
2216
 
            LEX *lex= Lex;
2217
 
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
2218
 
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1945
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1946
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
2219
1947
          }
2220
1948
        | ON UPDATE_SYM delete_option
2221
1949
          {
2222
 
            LEX *lex= Lex;
2223
 
            lex->fk_update_opt= $3;
2224
 
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1950
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
 
1951
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
2225
1952
          }
2226
1953
        | ON DELETE_SYM delete_option
2227
1954
          {
2228
 
            LEX *lex= Lex;
2229
 
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
2230
 
            lex->fk_delete_opt= $3;
 
1955
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1956
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
2231
1957
          }
2232
1958
        | ON UPDATE_SYM delete_option
2233
1959
          ON DELETE_SYM delete_option
2234
1960
          {
2235
 
            LEX *lex= Lex;
2236
 
            lex->fk_update_opt= $3;
2237
 
            lex->fk_delete_opt= $6;
 
1961
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
 
1962
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
2238
1963
          }
2239
1964
        | ON DELETE_SYM delete_option
2240
1965
          ON UPDATE_SYM delete_option
2241
1966
          {
2242
 
            LEX *lex= Lex;
2243
 
            lex->fk_update_opt= $6;
2244
 
            lex->fk_delete_opt= $3;
 
1967
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
 
1968
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
2245
1969
          }
2246
1970
        ;
2247
1971
 
2285
2009
 
2286
2010
init_key_options:
2287
2011
          {
2288
 
            Lex->key_create_info= default_key_create_info;
 
2012
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
2289
2013
          }
2290
2014
        ;
2291
2015
 
2311
2035
        ;
2312
2036
 
2313
2037
key_using_alg:
2314
 
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
2315
 
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
 
2038
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2039
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2316
2040
        ;
2317
2041
 
2318
2042
key_opt:
2319
2043
          key_using_alg
2320
2044
        | KEY_BLOCK_SIZE opt_equal ulong_num
2321
 
          { Lex->key_create_info.block_size= $3; }
 
2045
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
2322
2046
        | COMMENT_SYM TEXT_STRING_sys
2323
 
          { Lex->key_create_info.comment= $2; }
 
2047
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
2324
2048
        ;
2325
2049
 
2326
2050
btree_or_rtree:
2367
2091
alter:
2368
2092
          ALTER build_method opt_ignore TABLE_SYM table_ident
2369
2093
          {
2370
 
            THD *thd= YYTHD;
2371
 
            LEX *lex= thd->lex;
 
2094
            Session *session= YYSession;
 
2095
            LEX *lex= session->lex;
2372
2096
            lex->name.str= 0;
2373
2097
            lex->name.length= 0;
2374
2098
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2099
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2100
            lex->statement= statement;
 
2101
            if (lex->statement == NULL)
 
2102
              DRIZZLE_YYABORT;
2375
2103
            lex->duplicates= DUP_ERROR; 
2376
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
2104
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2377
2105
                                                   TL_OPTION_UPDATING))
2378
2106
              DRIZZLE_YYABORT;
2379
 
            lex->alter_info.reset();
2380
2107
            lex->col_list.empty();
2381
2108
            lex->select_lex.init_order();
2382
2109
            lex->select_lex.db=
2383
 
              ((TABLE_LIST*) lex->select_lex.table_list.first)->db;
2384
 
            memset(&lex->create_info, 0, sizeof(lex->create_info));
2385
 
            lex->create_info.db_type= 0;
2386
 
            lex->create_info.default_table_charset= NULL;
2387
 
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
2388
 
            lex->alter_info.reset();
2389
 
            lex->no_write_to_binlog= 0;
2390
 
            lex->alter_info.build_method= $2;
 
2110
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2111
            statement->create_info.db_type= 0;
 
2112
            statement->create_info.default_table_charset= NULL;
 
2113
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
 
2114
            statement->alter_info.build_method= $2;
2391
2115
          }
2392
2116
          alter_commands
2393
2117
          {}
2394
2118
        | ALTER DATABASE ident_or_empty
2395
 
          {
2396
 
            Lex->create_info.default_table_charset= NULL;
2397
 
            Lex->create_info.used_fields= 0;
2398
 
          }
2399
 
          create_database_options
2400
 
          {
 
2119
          { 
2401
2120
            LEX *lex=Lex;
2402
2121
            lex->sql_command=SQLCOM_ALTER_DB;
 
2122
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2123
            if (lex->statement == NULL)
 
2124
              DRIZZLE_YYABORT;
 
2125
          }
 
2126
          default_collation_schema
 
2127
          {
 
2128
            LEX *lex=Lex;
2403
2129
            lex->name= $3;
2404
2130
            if (lex->name.str == NULL &&
2405
2131
                lex->copy_db_to(&lex->name.str, &lex->name.length))
2414
2140
 
2415
2141
alter_commands:
2416
2142
          /* empty */
2417
 
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
2418
 
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
 
2143
        | DISCARD TABLESPACE 
 
2144
          { 
 
2145
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2146
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE; 
 
2147
          }
 
2148
        | IMPORT TABLESPACE 
 
2149
          { 
 
2150
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2151
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE; 
 
2152
          }
2419
2153
        | alter_list
2420
2154
        ;
2421
2155
 
2442
2176
add_column:
2443
2177
          ADD opt_column
2444
2178
          {
2445
 
            LEX *lex=Lex;
2446
 
            lex->change=0;
2447
 
            lex->alter_info.flags|= ALTER_ADD_COLUMN;
 
2179
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2180
 
 
2181
            statement->change=0;
 
2182
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2448
2183
          }
2449
2184
        ;
2450
2185
 
2452
2187
          add_column column_def opt_place { }
2453
2188
        | ADD key_def
2454
2189
          {
2455
 
            Lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2190
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2191
 
 
2192
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2456
2193
          }
2457
2194
        | add_column '(' field_list ')'
2458
2195
          {
2459
 
            Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX;
 
2196
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2197
 
 
2198
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2199
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2460
2200
          }
2461
2201
        | CHANGE opt_column field_ident
2462
2202
          {
2463
 
            LEX *lex=Lex;
2464
 
            lex->change= $3.str;
2465
 
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2203
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2204
            statement->change= $3.str;
 
2205
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2466
2206
          }
2467
2207
          field_spec opt_place
2468
2208
        | MODIFY_SYM opt_column field_ident
2469
2209
          {
2470
2210
            LEX *lex=Lex;
 
2211
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2471
2212
            lex->length=lex->dec=0; lex->type=0;
2472
 
            lex->default_value= lex->on_update_value= 0;
2473
 
            lex->comment=null_lex_str;
 
2213
            statement->default_value= statement->on_update_value= 0;
 
2214
            statement->comment= null_lex_str;
2474
2215
            lex->charset= NULL;
2475
 
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
2476
 
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
2216
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2217
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2477
2218
          }
2478
 
          type opt_attribute
 
2219
          field_def
2479
2220
          {
2480
2221
            LEX *lex=Lex;
2481
 
            if (add_field_to_list(lex->thd,&$3,
 
2222
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2223
 
 
2224
            if (add_field_to_list(lex->session,&$3,
2482
2225
                                  (enum enum_field_types) $5,
2483
 
                                  lex->length,lex->dec,lex->type,
2484
 
                                  lex->column_format,
2485
 
                                  lex->default_value, lex->on_update_value,
2486
 
                                  &lex->comment,
 
2226
                                  lex->length, lex->dec, lex->type,
 
2227
                                  statement->column_format,
 
2228
                                  statement->default_value, 
 
2229
                                  statement->on_update_value,
 
2230
                                  &statement->comment,
2487
2231
                                  $3.str, &lex->interval_list, lex->charset))
2488
2232
              DRIZZLE_YYABORT;
2489
2233
          }
2490
2234
          opt_place
2491
2235
        | DROP opt_column field_ident
2492
2236
          {
2493
 
            LEX *lex=Lex;
2494
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
2495
 
                                                               $3.str));
2496
 
            lex->alter_info.flags|= ALTER_DROP_COLUMN;
 
2237
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2238
 
 
2239
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN, $3.str));
 
2240
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
2497
2241
          }
2498
2242
        | DROP FOREIGN KEY_SYM opt_ident
2499
2243
          {
2500
 
            Lex->alter_info.flags|= ALTER_DROP_INDEX | ALTER_FOREIGN_KEY;
 
2244
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2245
 
 
2246
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2247
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
2501
2248
          }
2502
2249
        | DROP PRIMARY_SYM KEY_SYM
2503
2250
          {
2504
 
            LEX *lex=Lex;
2505
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2506
 
                                                               primary_key_name));
2507
 
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2251
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2252
 
 
2253
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2254
                                                               "PRIMARY"));
 
2255
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2508
2256
          }
2509
2257
        | DROP key_or_index field_ident
2510
2258
          {
2511
 
            LEX *lex=Lex;
2512
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2513
 
                                                               $3.str));
2514
 
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2259
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2260
 
 
2261
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2262
                                                                    $3.str));
 
2263
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2515
2264
          }
2516
2265
        | DISABLE_SYM KEYS
2517
2266
          {
2518
 
            LEX *lex=Lex;
2519
 
            lex->alter_info.keys_onoff= DISABLE;
2520
 
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2267
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2268
 
 
2269
            statement->alter_info.keys_onoff= DISABLE;
 
2270
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2521
2271
          }
2522
2272
        | ENABLE_SYM KEYS
2523
2273
          {
2524
 
            LEX *lex=Lex;
2525
 
            lex->alter_info.keys_onoff= ENABLE;
2526
 
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2274
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2275
 
 
2276
            statement->alter_info.keys_onoff= ENABLE;
 
2277
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2527
2278
          }
2528
2279
        | ALTER opt_column field_ident SET DEFAULT signed_literal
2529
2280
          {
2530
 
            LEX *lex=Lex;
2531
 
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
2532
 
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2281
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2282
 
 
2283
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
 
2284
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2533
2285
          }
2534
2286
        | ALTER opt_column field_ident DROP DEFAULT
2535
2287
          {
2536
 
            LEX *lex=Lex;
2537
 
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
2538
 
                                                                  (Item*) 0));
2539
 
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2288
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2289
 
 
2290
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str, (Item*) 0));
 
2291
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2540
2292
          }
2541
2293
        | RENAME opt_to table_ident
2542
2294
          {
2543
2295
            LEX *lex=Lex;
 
2296
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2544
2297
            size_t dummy;
 
2298
 
2545
2299
            lex->select_lex.db=$3->db.str;
2546
2300
            if (lex->select_lex.db == NULL &&
2547
2301
                lex->copy_db_to(&lex->select_lex.db, &dummy))
2554
2308
              DRIZZLE_YYABORT;
2555
2309
            }
2556
2310
            lex->name= $3->table;
2557
 
            lex->alter_info.flags|= ALTER_RENAME;
 
2311
            statement->alter_info.flags.set(ALTER_RENAME);
2558
2312
          }
2559
 
        | CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
 
2313
        | CONVERT_SYM TO_SYM collation_name_or_default
2560
2314
          {
2561
 
            if (!$4)
2562
 
            {
2563
 
              THD *thd= YYTHD;
2564
 
              $4= thd->variables.collation_database;
2565
 
            }
2566
 
            $5= $5 ? $5 : $4;
2567
 
            if (!my_charset_same($4,$5))
2568
 
            {
2569
 
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
2570
 
                       $5->name, $4->csname);
2571
 
              DRIZZLE_YYABORT;
2572
 
            }
2573
 
            LEX *lex= Lex;
2574
 
            lex->create_info.table_charset=
2575
 
            lex->create_info.default_table_charset= $5;
2576
 
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
 
2315
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2316
 
 
2317
            statement->create_info.table_charset=
 
2318
            statement->create_info.default_table_charset= $3;
 
2319
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2577
2320
              HA_CREATE_USED_DEFAULT_CHARSET);
2578
 
            lex->alter_info.flags|= ALTER_CONVERT;
 
2321
            statement->alter_info.flags.set(ALTER_CONVERT);
2579
2322
          }
2580
2323
        | create_table_options_space_separated
2581
2324
          {
2582
 
            LEX *lex=Lex;
2583
 
            lex->alter_info.flags|= ALTER_OPTIONS;
 
2325
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2326
 
 
2327
            statement->alter_info.flags.set(ALTER_OPTIONS);
2584
2328
          }
2585
2329
        | FORCE_SYM
2586
2330
          {
2587
 
            Lex->alter_info.flags|= ALTER_FORCE;
 
2331
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2332
 
 
2333
            statement->alter_info.flags.set(ALTER_FORCE);
2588
2334
          }
2589
2335
        | alter_order_clause
2590
2336
          {
2591
 
            LEX *lex=Lex;
2592
 
            lex->alter_info.flags|= ALTER_ORDER;
 
2337
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2338
 
 
2339
            statement->alter_info.flags.set(ALTER_ORDER);
2593
2340
          }
2594
2341
        ;
2595
2342
 
2607
2354
          /* empty */ {}
2608
2355
        | AFTER_SYM ident
2609
2356
          {
 
2357
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2358
 
2610
2359
            store_position_for_column($2.str);
2611
 
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2360
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
2612
2361
          }
2613
2362
        | FIRST_SYM
2614
2363
          {
 
2364
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2365
 
2615
2366
            store_position_for_column(first_keyword);
2616
 
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2367
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
2617
2368
          }
2618
2369
        ;
2619
2370
 
2624
2375
        | AS {}
2625
2376
        ;
2626
2377
 
2627
 
/*
2628
 
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
2629
 
*/
2630
 
 
2631
 
slave:
2632
 
          START_SYM SLAVE slave_thread_opts
2633
 
          {
2634
 
            LEX *lex=Lex;
2635
 
            lex->sql_command = SQLCOM_SLAVE_START;
2636
 
            lex->type = 0;
2637
 
            /* We'll use mi structure for UNTIL options */
2638
 
            memset(&lex->mi, 0, sizeof(lex->mi));
2639
 
            /* If you change this code don't forget to update SLAVE START too */
2640
 
          }
2641
 
          slave_until
2642
 
          {}
2643
 
        | STOP_SYM SLAVE slave_thread_opts
2644
 
          {
2645
 
            LEX *lex=Lex;
2646
 
            lex->sql_command = SQLCOM_SLAVE_STOP;
2647
 
            lex->type = 0;
2648
 
            /* If you change this code don't forget to update SLAVE STOP too */
2649
 
          }
2650
 
        | SLAVE START_SYM slave_thread_opts
2651
 
          {
2652
 
            LEX *lex=Lex;
2653
 
            lex->sql_command = SQLCOM_SLAVE_START;
2654
 
            lex->type = 0;
2655
 
            /* We'll use mi structure for UNTIL options */
2656
 
            memset(&lex->mi, 0, sizeof(lex->mi));
2657
 
          }
2658
 
          slave_until
2659
 
          {}
2660
 
        | SLAVE STOP_SYM slave_thread_opts
2661
 
          {
2662
 
            LEX *lex=Lex;
2663
 
            lex->sql_command = SQLCOM_SLAVE_STOP;
2664
 
            lex->type = 0;
2665
 
          }
2666
 
        ;
2667
 
 
2668
2378
start:
2669
2379
          START_SYM TRANSACTION_SYM start_transaction_opts
2670
2380
          {
2671
2381
            LEX *lex= Lex;
2672
2382
            lex->sql_command= SQLCOM_BEGIN;
 
2383
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
2384
            if (lex->statement == NULL)
 
2385
              DRIZZLE_YYABORT;
2673
2386
            lex->start_transaction_opt= $3;
2674
2387
          }
2675
2388
        ;
2682
2395
          }
2683
2396
        ;
2684
2397
 
2685
 
slave_thread_opts:
2686
 
          { Lex->slave_thd_opt= 0; }
2687
 
          slave_thread_opt_list
2688
 
          {}
2689
 
        ;
2690
 
 
2691
 
slave_thread_opt_list:
2692
 
          slave_thread_opt
2693
 
        | slave_thread_opt_list ',' slave_thread_opt
2694
 
        ;
2695
 
 
2696
 
slave_thread_opt:
2697
 
          /*empty*/ {}
2698
 
        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
2699
 
        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
2700
 
        ;
2701
 
 
2702
 
slave_until:
2703
 
          /*empty*/ {}
2704
 
        | UNTIL_SYM slave_until_opts
2705
 
          {
2706
 
            LEX *lex=Lex;
2707
 
            if (((lex->mi.log_file_name || lex->mi.pos) && (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
2708
 
                !((lex->mi.log_file_name && lex->mi.pos) ||
2709
 
                  (lex->mi.relay_log_name && lex->mi.relay_log_pos)))
2710
 
            {
2711
 
               my_message(ER_BAD_SLAVE_UNTIL_COND,
2712
 
                          ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0));
2713
 
               DRIZZLE_YYABORT;
2714
 
            }
2715
 
          }
2716
 
        ;
2717
 
 
2718
 
slave_until_opts:
2719
 
          master_file_def
2720
 
        | slave_until_opts ',' master_file_def
2721
 
        ;
2722
2398
 
2723
2399
checksum:
2724
2400
          CHECKSUM_SYM table_or_tables
2725
2401
          {
2726
2402
            LEX *lex=Lex;
2727
2403
            lex->sql_command = SQLCOM_CHECKSUM;
 
2404
            lex->statement= new(std::nothrow) statement::Checksum(YYSession);
 
2405
            if (lex->statement == NULL)
 
2406
              DRIZZLE_YYABORT;
2728
2407
          }
2729
2408
          table_list opt_checksum_type
2730
2409
          {}
2731
2410
        ;
2732
2411
 
2733
2412
opt_checksum_type:
2734
 
          /* nothing */ { Lex->check_opt.flags= 0; }
2735
 
        | QUICK         { Lex->check_opt.flags= T_QUICK; }
2736
 
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
2737
 
        ;
2738
 
 
2739
 
repair:
2740
 
          REPAIR opt_no_write_to_binlog table_or_tables
2741
 
          {
2742
 
            LEX *lex=Lex;
2743
 
            lex->sql_command = SQLCOM_REPAIR;
2744
 
            lex->no_write_to_binlog= $2;
2745
 
            lex->check_opt.init();
2746
 
          }
2747
 
          table_list opt_mi_repair_type
2748
 
          {}
2749
 
        ;
2750
 
 
2751
 
opt_mi_repair_type:
2752
 
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
2753
 
        | mi_repair_types {}
2754
 
        ;
2755
 
 
2756
 
mi_repair_types:
2757
 
          mi_repair_type {}
2758
 
        | mi_repair_type mi_repair_types {}
2759
 
        ;
2760
 
 
2761
 
mi_repair_type:
2762
 
          QUICK        { Lex->check_opt.flags|= T_QUICK; }
2763
 
        | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
2764
 
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; }
2765
 
        ;
 
2413
          /* nothing */ { ((statement::Checksum *)Lex->statement)->check_opt.flags= 0; }
 
2414
        | QUICK         { ((statement::Checksum *)Lex->statement)->check_opt.flags= T_QUICK; }
 
2415
        | EXTENDED_SYM  { ((statement::Checksum *)Lex->statement)->check_opt.flags= T_EXTEND; }
 
2416
        ;
 
2417
 
2766
2418
 
2767
2419
analyze:
2768
 
          ANALYZE_SYM opt_no_write_to_binlog table_or_tables
 
2420
          ANALYZE_SYM table_or_tables
2769
2421
          {
2770
2422
            LEX *lex=Lex;
2771
2423
            lex->sql_command = SQLCOM_ANALYZE;
2772
 
            lex->no_write_to_binlog= $2;
2773
 
            lex->check_opt.init();
 
2424
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2425
            if (lex->statement == NULL)
 
2426
              DRIZZLE_YYABORT;
2774
2427
          }
2775
2428
          table_list
2776
2429
          {}
2777
2430
        ;
2778
2431
 
2779
 
binlog_base64_event:
2780
 
          BINLOG_SYM TEXT_STRING_sys
2781
 
          {
2782
 
            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
2783
 
            Lex->comment= $2;
2784
 
          }
2785
 
        ;
2786
 
 
2787
2432
check:
2788
2433
          CHECK_SYM table_or_tables
2789
2434
          {
2790
2435
            LEX *lex=Lex;
2791
2436
 
2792
2437
            lex->sql_command = SQLCOM_CHECK;
2793
 
            lex->check_opt.init();
 
2438
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2439
            if (lex->statement == NULL)
 
2440
              DRIZZLE_YYABORT;
2794
2441
          }
2795
2442
          table_list opt_mi_check_type
2796
2443
          {}
2797
2444
        ;
2798
2445
 
2799
2446
opt_mi_check_type:
2800
 
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2447
          /* empty */ { ((statement::Check *)Lex->statement)->check_opt.flags = T_MEDIUM; }
2801
2448
        | mi_check_types {}
2802
2449
        ;
2803
2450
 
2807
2454
        ;
2808
2455
 
2809
2456
mi_check_type:
2810
 
          QUICK               { Lex->check_opt.flags|= T_QUICK; }
2811
 
        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
2812
 
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
2813
 
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
2814
 
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
2815
 
        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
 
2457
          QUICK               { ((statement::Check *)Lex->statement)->check_opt.flags|= T_QUICK; }
 
2458
        | FAST_SYM            { ((statement::Check *)Lex->statement)->check_opt.flags|= T_FAST; }
 
2459
        | MEDIUM_SYM          { ((statement::Check *)Lex->statement)->check_opt.flags|= T_MEDIUM; }
 
2460
        | EXTENDED_SYM        { ((statement::Check *)Lex->statement)->check_opt.flags|= T_EXTEND; }
 
2461
        | CHANGED             { ((statement::Check *)Lex->statement)->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
2816
2462
        ;
2817
2463
 
2818
2464
optimize:
2819
 
          OPTIMIZE opt_no_write_to_binlog table_or_tables
 
2465
          OPTIMIZE table_or_tables
2820
2466
          {
2821
2467
            LEX *lex=Lex;
2822
2468
            lex->sql_command = SQLCOM_OPTIMIZE;
2823
 
            lex->no_write_to_binlog= $2;
2824
 
            lex->check_opt.init();
 
2469
            statement::Optimize *statement= new(std::nothrow) statement::Optimize(YYSession);
 
2470
            lex->statement= statement;
 
2471
            if (lex->statement == NULL)
 
2472
              DRIZZLE_YYABORT;
2825
2473
          }
2826
2474
          table_list
2827
2475
          {}
2828
2476
        ;
2829
2477
 
2830
 
opt_no_write_to_binlog:
2831
 
          /* empty */ { $$= 0; }
2832
 
        | NO_WRITE_TO_BINLOG { $$= 1; }
2833
 
        | LOCAL_SYM { $$= 1; }
2834
 
        ;
2835
 
 
2836
2478
rename:
2837
2479
          RENAME table_or_tables
2838
2480
          {
2839
2481
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2482
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2483
            if (Lex->statement == NULL)
 
2484
              DRIZZLE_YYABORT;
2840
2485
          }
2841
2486
          table_to_table_list
2842
2487
          {}
2851
2496
          table_ident TO_SYM table_ident
2852
2497
          {
2853
2498
            LEX *lex=Lex;
2854
 
            SELECT_LEX *sl= lex->current_select;
2855
 
            if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
 
2499
            Select_Lex *sl= lex->current_select;
 
2500
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
2856
2501
                                       TL_IGNORE) ||
2857
 
                !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
 
2502
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
2858
2503
                                       TL_IGNORE))
2859
2504
              DRIZZLE_YYABORT;
2860
2505
          }
2861
2506
        ;
2862
2507
 
2863
 
keycache:
2864
 
          CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
2865
 
          {
2866
 
            LEX *lex=Lex;
2867
 
            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
2868
 
            lex->ident= $5;
2869
 
          }
2870
 
        ;
2871
 
 
2872
 
keycache_list:
2873
 
          assign_to_keycache
2874
 
        | keycache_list ',' assign_to_keycache
2875
 
        ;
2876
 
 
2877
 
assign_to_keycache:
2878
 
          table_ident cache_keys_spec
2879
 
          {
2880
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ, 
2881
 
                                           Select->pop_index_hints()))
2882
 
              DRIZZLE_YYABORT;
2883
 
          }
2884
 
        ;
2885
 
 
2886
 
key_cache_name:
2887
 
          ident    { $$= $1; }
2888
 
        | DEFAULT  { $$ = default_key_cache_base; }
2889
 
        ;
2890
 
 
2891
 
cache_keys_spec:
2892
 
          {
2893
 
            Lex->select_lex.alloc_index_hints(YYTHD);
2894
 
            Select->set_index_hint_type(INDEX_HINT_USE, 
2895
 
                                        global_system_variables.old_mode ? 
2896
 
                                        INDEX_HINT_MASK_JOIN : 
2897
 
                                        INDEX_HINT_MASK_ALL);
2898
 
          }
2899
 
          cache_key_list_or_empty
2900
 
        ;
2901
 
 
2902
 
cache_key_list_or_empty:
2903
 
          /* empty */ { }
2904
 
        | key_or_index '(' opt_key_usage_list ')'
2905
 
        ;
2906
 
 
2907
2508
/*
2908
2509
  Select : retrieve data from table
2909
2510
*/
2914
2515
          {
2915
2516
            LEX *lex= Lex;
2916
2517
            lex->sql_command= SQLCOM_SELECT;
 
2518
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2519
            if (lex->statement == NULL)
 
2520
              DRIZZLE_YYABORT;
2917
2521
          }
2918
2522
        ;
2919
2523
 
2946
2550
          select_part2
2947
2551
          {
2948
2552
            LEX *lex= Lex;
2949
 
            SELECT_LEX * sel= lex->current_select;
 
2553
            Select_Lex * sel= lex->current_select;
2950
2554
            if (lex->current_select->set_braces(0))
2951
2555
            {
2952
2556
              my_parse_error(ER(ER_SYNTAX_ERROR));
2965
2569
select_part2:
2966
2570
          {
2967
2571
            LEX *lex= Lex;
2968
 
            SELECT_LEX *sel= lex->current_select;
 
2572
            Select_Lex *sel= lex->current_select;
2969
2573
            if (sel->linkage != UNION_TYPE)
2970
2574
              mysql_init_select(lex);
2971
2575
            lex->current_select->parsing_place= SELECT_LIST;
2972
2576
          }
2973
2577
          select_options select_item_list
2974
2578
          {
2975
 
            Select->parsing_place= NO_MATTER;
 
2579
            Lex->current_select->parsing_place= NO_MATTER;
2976
2580
          }
2977
2581
          select_into select_lock_type
2978
2582
        ;
2989
2593
          FROM join_table_list where_clause group_clause having_clause
2990
2594
          opt_order_clause opt_limit_clause
2991
2595
          {
2992
 
            Select->context.table_list=
2993
 
              Select->context.first_name_resolution_table= 
2994
 
                (TABLE_LIST *) Select->table_list.first;
 
2596
            Lex->current_select->context.table_list=
 
2597
              Lex->current_select->context.first_name_resolution_table= 
 
2598
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
2995
2599
          }
2996
2600
        ;
2997
2601
 
2999
2603
          /* empty*/
3000
2604
        | select_option_list
3001
2605
          {
3002
 
            if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
 
2606
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2607
                Lex->current_select->options & SELECT_ALL)
3003
2608
            {
3004
2609
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
3005
2610
              DRIZZLE_YYABORT;
3013
2618
        ;
3014
2619
 
3015
2620
select_option:
3016
 
          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
3017
 
        | HIGH_PRIORITY
3018
 
          {
3019
 
            if (check_simple_select())
3020
 
              DRIZZLE_YYABORT;
3021
 
            Lex->lock_option= TL_READ_HIGH_PRIORITY;
3022
 
          }
3023
 
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
3024
 
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
3025
 
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
 
2621
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2622
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2623
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2624
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
3026
2625
        | SQL_BUFFER_RESULT
3027
2626
          {
3028
2627
            if (check_simple_select())
3029
2628
              DRIZZLE_YYABORT;
3030
 
            Select->options|= OPTION_BUFFER_RESULT;
 
2629
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
3031
2630
          }
3032
2631
        | SQL_CALC_FOUND_ROWS
3033
2632
          {
3034
2633
            if (check_simple_select())
3035
2634
              DRIZZLE_YYABORT;
3036
 
            Select->options|= OPTION_FOUND_ROWS;
 
2635
            Lex->current_select->options|= OPTION_FOUND_ROWS;
3037
2636
          }
3038
 
        | ALL { Select->options|= SELECT_ALL; }
 
2637
        | ALL { Lex->current_select->options|= SELECT_ALL; }
3039
2638
        ;
3040
2639
 
3041
2640
select_lock_type:
3058
2657
        | select_item
3059
2658
        | '*'
3060
2659
          {
3061
 
            THD *thd= YYTHD;
3062
 
            if (add_item_to_list(thd,
3063
 
                                 new Item_field(&thd->lex->current_select->
3064
 
                                                context,
3065
 
                                                NULL, NULL, "*")))
 
2660
            Session *session= YYSession;
 
2661
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2662
                                                          context,
 
2663
                                                          NULL, NULL, "*")))
3066
2664
              DRIZZLE_YYABORT;
3067
 
            (thd->lex->current_select->with_wild)++;
 
2665
            (session->lex->current_select->with_wild)++;
3068
2666
          }
3069
2667
        ;
3070
2668
 
3071
2669
select_item:
3072
2670
          remember_name table_wild remember_end
3073
2671
          {
3074
 
            THD *thd= YYTHD;
 
2672
            Session *session= YYSession;
3075
2673
 
3076
 
            if (add_item_to_list(thd, $2))
 
2674
            if (session->add_item_to_list($2))
3077
2675
              DRIZZLE_YYABORT;
3078
2676
          }
3079
2677
        | remember_name expr remember_end select_alias
3080
2678
          {
3081
 
            THD *thd= YYTHD;
 
2679
            Session *session= YYSession;
3082
2680
            assert($1 < $3);
3083
2681
 
3084
 
            if (add_item_to_list(thd, $2))
 
2682
            if (session->add_item_to_list($2))
3085
2683
              DRIZZLE_YYABORT;
3086
2684
            if ($4.str)
3087
2685
            {
3090
2688
            }
3091
2689
            else if (!$2->name)
3092
2690
            {
3093
 
              $2->set_name($1, (uint) ($3 - $1), thd->charset());
 
2691
              $2->set_name($1, (uint) ($3 - $1), session->charset());
3094
2692
            }
3095
2693
          }
3096
2694
        ;
3097
2695
 
3098
2696
remember_name:
3099
2697
          {
3100
 
            THD *thd= YYTHD;
3101
 
            Lex_input_stream *lip= thd->m_lip;
 
2698
            Session *session= YYSession;
 
2699
            Lex_input_stream *lip= session->m_lip;
3102
2700
            $$= (char*) lip->get_cpp_tok_start();
3103
2701
          }
3104
2702
        ;
3105
2703
 
3106
2704
remember_end:
3107
2705
          {
3108
 
            THD *thd= YYTHD;
3109
 
            Lex_input_stream *lip= thd->m_lip;
 
2706
            Session *session= YYSession;
 
2707
            Lex_input_stream *lip= session->m_lip;
3110
2708
            $$= (char*) lip->get_cpp_tok_end();
3111
2709
          }
3112
2710
        ;
3130
2728
          {
3131
2729
            /*
3132
2730
              Design notes:
3133
 
              Do not use a manually maintained stack like thd->lex->xxx_list,
 
2731
              Do not use a manually maintained stack like session->lex->xxx_list,
3134
2732
              but use the internal bison stack ($$, $1 and $3) instead.
3135
2733
              Using the bison stack is:
3136
2734
              - more robust to changes in the grammar,
3172
2770
            else
3173
2771
            {
3174
2772
              /* X OR Y */
3175
 
              $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
 
2773
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
3176
2774
            }
3177
2775
          }
3178
2776
        | expr XOR expr %prec XOR
3179
2777
          {
3180
2778
            /* XOR is a proprietary extension */
3181
 
            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
 
2779
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
3182
2780
          }
3183
2781
        | expr and expr %prec AND_SYM
3184
2782
          {
3218
2816
            else
3219
2817
            {
3220
2818
              /* X AND Y */
3221
 
              $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
 
2819
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
3222
2820
            }
3223
2821
          }
3224
2822
        | NOT_SYM expr %prec NOT_SYM
3225
 
          { $$= negate_expression(YYTHD, $2); }
 
2823
          { $$= negate_expression(YYSession, $2); }
3226
2824
        | bool_pri IS TRUE_SYM %prec IS
3227
 
          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
 
2825
          { $$= new (YYSession->mem_root) Item_func_istrue($1); }
3228
2826
        | bool_pri IS not TRUE_SYM %prec IS
3229
 
          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
 
2827
          { $$= new (YYSession->mem_root) Item_func_isnottrue($1); }
3230
2828
        | bool_pri IS FALSE_SYM %prec IS
3231
 
          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
 
2829
          { $$= new (YYSession->mem_root) Item_func_isfalse($1); }
3232
2830
        | bool_pri IS not FALSE_SYM %prec IS
3233
 
          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
 
2831
          { $$= new (YYSession->mem_root) Item_func_isnotfalse($1); }
3234
2832
        | bool_pri IS UNKNOWN_SYM %prec IS
3235
2833
          { $$= new Item_func_isnull($1); }
3236
2834
        | bool_pri IS not UNKNOWN_SYM %prec IS
3255
2853
predicate:
3256
2854
          bit_expr IN_SYM '(' subselect ')'
3257
2855
          {
3258
 
            $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
 
2856
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
3259
2857
          }
3260
2858
        | bit_expr not IN_SYM '(' subselect ')'
3261
2859
          {
3262
 
            THD *thd= YYTHD;
3263
 
            Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
3264
 
            $$= negate_expression(thd, item);
 
2860
            Session *session= YYSession;
 
2861
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2862
            $$= negate_expression(session, item);
3265
2863
          }
3266
2864
        | bit_expr IN_SYM '(' expr ')'
3267
2865
          {
3268
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
 
2866
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
3269
2867
          }
3270
2868
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
3271
2869
          { 
3272
2870
            $6->push_front($4);
3273
2871
            $6->push_front($1);
3274
 
            $$= new (YYTHD->mem_root) Item_func_in(*$6);
 
2872
            $$= new (YYSession->mem_root) Item_func_in(*$6);
3275
2873
          }
3276
2874
        | bit_expr not IN_SYM '(' expr ')'
3277
2875
          {
3278
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
 
2876
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
3279
2877
          }
3280
2878
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
3281
2879
          {
3282
2880
            $7->push_front($5);
3283
2881
            $7->push_front($1);
3284
 
            Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
 
2882
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
3285
2883
            item->negate();
3286
2884
            $$= item;
3287
2885
          }
3356
2954
        | function_call_conflict
3357
2955
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
3358
2956
          {
3359
 
            THD *thd= YYTHD;
3360
 
            Item *i1= new (thd->mem_root) Item_string($3.str,
 
2957
            Session *session= YYSession;
 
2958
            Item *i1= new (session->mem_root) Item_string($3.str,
3361
2959
                                                      $3.length,
3362
 
                                                      thd->charset());
3363
 
            $$= new (thd->mem_root) Item_func_set_collation($1, i1);
 
2960
                                                      session->charset());
 
2961
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
3364
2962
          }
3365
2963
        | literal
3366
2964
        | variable
3367
2965
        | sum_expr
3368
2966
        | '+' simple_expr %prec NEG { $$= $2; }
3369
2967
        | '-' simple_expr %prec NEG
3370
 
          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
 
2968
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
3371
2969
        | '(' subselect ')'
3372
2970
          { 
3373
 
            $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
 
2971
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
3374
2972
          }
3375
2973
        | '(' expr ')' { $$= $2; }
3376
2974
        | '(' expr ',' expr_list ')'
3377
2975
          {
3378
2976
            $4->push_front($2);
3379
 
            $$= new (YYTHD->mem_root) Item_row(*$4);
 
2977
            $$= new (YYSession->mem_root) Item_row(*$4);
3380
2978
          }
3381
2979
        | ROW_SYM '(' expr ',' expr_list ')'
3382
2980
          {
3383
2981
            $5->push_front($3);
3384
 
            $$= new (YYTHD->mem_root) Item_row(*$5);
 
2982
            $$= new (YYSession->mem_root) Item_row(*$5);
3385
2983
          }
3386
2984
        | EXISTS '(' subselect ')'
3387
2985
          {
3388
 
            $$= new (YYTHD->mem_root) Item_exists_subselect($3);
 
2986
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
3389
2987
          }
3390
2988
        | '{' ident expr '}' { $$= $3; }
3391
2989
        | BINARY simple_expr %prec NEG
3392
2990
          {
3393
 
            $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
 
2991
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
3394
2992
                                 &my_charset_bin);
3395
2993
          }
3396
2994
        | CAST_SYM '(' expr AS cast_type ')'
3397
2995
          {
3398
2996
            LEX *lex= Lex;
3399
 
            $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
 
2997
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
3400
2998
                                 lex->charset);
3401
2999
            if (!$$)
3402
3000
              DRIZZLE_YYABORT;
3403
3001
          }
3404
3002
        | CASE_SYM opt_expr when_list opt_else END
3405
 
          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
 
3003
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
3406
3004
        | CONVERT_SYM '(' expr ',' cast_type ')'
3407
3005
          {
3408
 
            $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
 
3006
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
3409
3007
                                 Lex->charset);
3410
3008
            if (!$$)
3411
3009
              DRIZZLE_YYABORT;
3412
3010
          }
3413
 
        | CONVERT_SYM '(' expr USING charset_name ')'
3414
 
          { $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5); }
3415
3011
        | DEFAULT '(' simple_ident ')'
3416
3012
          {
3417
 
            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
 
3013
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
3418
3014
                                                         $3);
3419
3015
          }
3420
3016
        | VALUES '(' simple_ident_nospvar ')'
3421
3017
          {
3422
 
            $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
 
3018
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
3423
3019
                                                        $3);
3424
3020
          }
3425
3021
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
3426
3022
          /* we cannot put interval before - */
3427
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
 
3023
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
3428
3024
        ;
3429
3025
 
3430
3026
/*
3435
3031
*/
3436
3032
function_call_keyword:
3437
3033
          CHAR_SYM '(' expr_list ')'
3438
 
          { $$= new (YYTHD->mem_root) Item_func_char(*$3); }
3439
 
        | CHAR_SYM '(' expr_list USING charset_name ')'
3440
 
          { $$= new (YYTHD->mem_root) Item_func_char(*$3, $5); }
 
3034
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
3441
3035
        | CURRENT_USER optional_braces
3442
3036
          {
3443
 
            $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
3444
 
            Lex->set_stmt_unsafe();
 
3037
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
3445
3038
          }
3446
3039
        | DATE_SYM '(' expr ')'
3447
 
          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
 
3040
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3448
3041
        | DAY_SYM '(' expr ')'
3449
 
          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
 
3042
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
3450
3043
        | HOUR_SYM '(' expr ')'
3451
 
          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
 
3044
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
3452
3045
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3453
 
          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3046
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
3454
3047
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3455
3048
          {
3456
 
            THD *thd= YYTHD;
3457
 
            List<Item> *list= new (thd->mem_root) List<Item>;
 
3049
            Session *session= YYSession;
 
3050
            List<Item> *list= new (session->mem_root) List<Item>;
3458
3051
            list->push_front($5);
3459
3052
            list->push_front($3);
3460
 
            Item_row *item= new (thd->mem_root) Item_row(*list);
3461
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3053
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3054
            $$= new (session->mem_root) Item_func_interval(item);
3462
3055
          }
3463
3056
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3464
3057
          {
3465
 
            THD *thd= YYTHD;
 
3058
            Session *session= YYSession;
3466
3059
            $7->push_front($5);
3467
3060
            $7->push_front($3);
3468
 
            Item_row *item= new (thd->mem_root) Item_row(*$7);
3469
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3061
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3062
            $$= new (session->mem_root) Item_func_interval(item);
3470
3063
          }
3471
3064
        | LEFT '(' expr ',' expr ')'
3472
 
          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
 
3065
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3473
3066
        | MINUTE_SYM '(' expr ')'
3474
 
          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
 
3067
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
3475
3068
        | MONTH_SYM '(' expr ')'
3476
 
          { $$= new (YYTHD->mem_root) Item_func_month($3); }
 
3069
          { $$= new (YYSession->mem_root) Item_func_month($3); }
3477
3070
        | RIGHT '(' expr ',' expr ')'
3478
 
          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
 
3071
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
3479
3072
        | SECOND_SYM '(' expr ')'
3480
 
          { $$= new (YYTHD->mem_root) Item_func_second($3); }
3481
 
        | TIME_SYM '(' expr ')'
3482
 
          { $$= new (YYTHD->mem_root) Item_time_typecast($3); }
3483
 
        | TIMESTAMP '(' expr ')'
3484
 
          { $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
3485
 
        | TIMESTAMP '(' expr ',' expr ')'
3486
 
          { $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
 
3073
          { $$= new (YYSession->mem_root) Item_func_second($3); }
 
3074
        | TIMESTAMP_SYM '(' expr ')'
 
3075
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
3487
3076
        | TRIM '(' expr ')'
3488
 
          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
 
3077
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
3489
3078
        | TRIM '(' LEADING expr FROM expr ')'
3490
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
 
3079
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
3491
3080
        | TRIM '(' TRAILING expr FROM expr ')'
3492
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
 
3081
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
3493
3082
        | TRIM '(' BOTH expr FROM expr ')'
3494
 
          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
 
3083
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
3495
3084
        | TRIM '(' LEADING FROM expr ')'
3496
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
 
3085
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
3497
3086
        | TRIM '(' TRAILING FROM expr ')'
3498
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
 
3087
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
3499
3088
        | TRIM '(' BOTH FROM expr ')'
3500
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
 
3089
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
3501
3090
        | TRIM '(' expr FROM expr ')'
3502
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
 
3091
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3503
3092
        | USER '(' ')'
3504
3093
          {
3505
 
            $$= new (YYTHD->mem_root) Item_func_user();
3506
 
            Lex->set_stmt_unsafe();
 
3094
            $$= new (YYSession->mem_root) Item_func_user();
3507
3095
          }
3508
3096
        | YEAR_SYM '(' expr ')'
3509
 
          { $$= new (YYTHD->mem_root) Item_func_year($3); }
 
3097
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3510
3098
        ;
3511
3099
 
3512
3100
/*
3517
3105
  MAINTAINER:
3518
3106
  The only reasons a function should be added here are:
3519
3107
  - for compatibility reasons with another SQL syntax (CURDATE),
3520
 
  - for typing reasons (GET_FORMAT)
3521
3108
  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
3522
3109
  discouraged.
3523
3110
*/
3524
3111
function_call_nonkeyword:
3525
3112
          ADDDATE_SYM '(' expr ',' expr ')'
3526
3113
          {
3527
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3114
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3528
3115
                                                             INTERVAL_DAY, 0);
3529
3116
          }
3530
3117
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3531
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
3118
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
3532
3119
        | CURDATE optional_braces
3533
3120
          {
3534
 
            $$= new (YYTHD->mem_root) Item_func_curdate_local();
3535
 
          }
3536
 
        | CURTIME optional_braces
3537
 
          {
3538
 
            $$= new (YYTHD->mem_root) Item_func_curtime_local();
3539
 
          }
3540
 
        | CURTIME '(' expr ')'
3541
 
          {
3542
 
            $$= new (YYTHD->mem_root) Item_func_curtime_local($3);
 
3121
            $$= new (YYSession->mem_root) Item_func_curdate_local();
3543
3122
          }
3544
3123
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3545
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
 
3124
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
3546
3125
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3547
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
 
3126
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
3548
3127
        | EXTRACT_SYM '(' interval FROM expr ')'
3549
 
          { $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
3550
 
        | GET_FORMAT '(' date_time_type  ',' expr ')'
3551
 
          { $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
 
3128
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
3552
3129
        | NOW_SYM optional_braces
3553
3130
          {
3554
 
            $$= new (YYTHD->mem_root) Item_func_now_local();
 
3131
            $$= new (YYSession->mem_root) Item_func_now_local();
3555
3132
          }
3556
3133
        | NOW_SYM '(' expr ')'
3557
3134
          {
3558
 
            $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3135
            $$= new (YYSession->mem_root) Item_func_now_local($3);
3559
3136
          }
3560
3137
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3561
 
          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
 
3138
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
3562
3139
        | SUBDATE_SYM '(' expr ',' expr ')'
3563
3140
          {
3564
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3141
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3565
3142
                                                             INTERVAL_DAY, 1);
3566
3143
          }
3567
3144
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3568
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
 
3145
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
3569
3146
        | SUBSTRING '(' expr ',' expr ',' expr ')'
3570
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3147
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3571
3148
        | SUBSTRING '(' expr ',' expr ')'
3572
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3149
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3573
3150
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3574
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3151
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3575
3152
        | SUBSTRING '(' expr FROM expr ')'
3576
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3153
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3577
3154
        | SYSDATE optional_braces
3578
 
          {
3579
 
            if (global_system_variables.sysdate_is_now == 0)
3580
 
              $$= new (YYTHD->mem_root) Item_func_sysdate_local();
3581
 
            else
3582
 
              $$= new (YYTHD->mem_root) Item_func_now_local();
3583
 
          }
 
3155
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
3584
3156
        | SYSDATE '(' expr ')'
3585
 
          {
3586
 
            if (global_system_variables.sysdate_is_now == 0)
3587
 
              $$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
3588
 
            else
3589
 
              $$= new (YYTHD->mem_root) Item_func_now_local($3);
3590
 
          }
 
3157
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
3591
3158
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3592
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
 
3159
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
3593
3160
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3594
 
          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
3161
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
3595
3162
        | UTC_DATE_SYM optional_braces
3596
3163
          {
3597
 
            $$= new (YYTHD->mem_root) Item_func_curdate_utc();
3598
 
          }
3599
 
        | UTC_TIME_SYM optional_braces
3600
 
          {
3601
 
            $$= new (YYTHD->mem_root) Item_func_curtime_utc();
 
3164
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
3602
3165
          }
3603
3166
        | UTC_TIMESTAMP_SYM optional_braces
3604
3167
          {
3605
 
            $$= new (YYTHD->mem_root) Item_func_now_utc();
 
3168
            $$= new (YYSession->mem_root) Item_func_now_utc();
3606
3169
          }
3607
3170
        ;
3608
3171
 
3612
3175
  a dedicated rule is needed here.
3613
3176
*/
3614
3177
function_call_conflict:
3615
 
          ASCII_SYM '(' expr ')'
3616
 
          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
3617
 
        | CHARSET '(' expr ')'
3618
 
          { $$= new (YYTHD->mem_root) Item_func_charset($3); }
3619
 
        | COALESCE '(' expr_list ')'
3620
 
          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
 
3178
        COALESCE '(' expr_list ')'
 
3179
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
3621
3180
        | COLLATION_SYM '(' expr ')'
3622
 
          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
 
3181
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3623
3182
        | DATABASE '(' ')'
3624
3183
          {
3625
 
            $$= new (YYTHD->mem_root) Item_func_database();
 
3184
            $$= new (YYSession->mem_root) Item_func_database();
3626
3185
          }
3627
3186
        | IF '(' expr ',' expr ',' expr ')'
3628
 
          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
 
3187
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3629
3188
        | MICROSECOND_SYM '(' expr ')'
3630
 
          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
 
3189
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
3631
3190
        | MOD_SYM '(' expr ',' expr ')'
3632
 
          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
 
3191
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
3633
3192
        | QUARTER_SYM '(' expr ')'
3634
 
          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
 
3193
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
3635
3194
        | REPEAT_SYM '(' expr ',' expr ')'
3636
 
          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
 
3195
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
3637
3196
        | REPLACE '(' expr ',' expr ',' expr ')'
3638
 
          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
 
3197
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3639
3198
        | REVERSE_SYM '(' expr ')'
3640
 
          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
 
3199
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
3641
3200
        | TRUNCATE_SYM '(' expr ',' expr ')'
3642
 
          { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
3643
 
        | WEEK_SYM '(' expr ')'
3644
 
          {
3645
 
            THD *thd= YYTHD;
3646
 
            Item *i1= new (thd->mem_root) Item_int((char*) "0",
3647
 
                                           thd->variables.default_week_format,
3648
 
                                                   1);
3649
 
 
3650
 
            $$= new (thd->mem_root) Item_func_week($3, i1);
3651
 
          }
3652
 
        | WEEK_SYM '(' expr ',' expr ')'
3653
 
          { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
 
3201
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
3654
3202
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
3655
 
          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
 
3203
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
3656
3204
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
3657
3205
          {
3658
 
            $$= new (YYTHD->mem_root)
 
3206
            $$= new (YYSession->mem_root)
3659
3207
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
3660
3208
          }
3661
3209
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
3662
3210
          {
3663
 
            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
3664
 
            $$= new (YYTHD->mem_root)
 
3211
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3212
            $$= new (YYSession->mem_root)
3665
3213
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
3666
3214
          }
3667
3215
        ;
3672
3220
  introduce side effects to the language in general.
3673
3221
  MAINTAINER:
3674
3222
  All the new functions implemented for new features should fit into
3675
 
  this category. The place to implement the function itself is
3676
 
  in sql/item_create.cc
 
3223
  this category.
3677
3224
*/
3678
3225
function_call_generic:
3679
3226
          IDENT_sys '('
3680
3227
          {
3681
 
            udf_func *udf= 0;
3682
 
            LEX *lex= Lex;
3683
 
            if (using_udf_functions &&
3684
 
                (udf= find_udf($1.str, $1.length)) &&
3685
 
                udf->type == UDFTYPE_AGGREGATE)
3686
 
            {
3687
 
              if (lex->current_select->inc_in_sum_expr())
3688
 
              {
3689
 
                my_parse_error(ER(ER_SYNTAX_ERROR));
3690
 
                DRIZZLE_YYABORT;
3691
 
              }
3692
 
            }
3693
 
            /* Temporary placing the result of find_udf in $3 */
 
3228
            const plugin::Function *udf= plugin::Function::get($1.str, $1.length);
 
3229
 
 
3230
            /* Temporary placing the result of getFunction in $3 */
3694
3231
            $<udf>$= udf;
3695
3232
          }
3696
3233
          opt_udf_expr_list ')'
3697
3234
          {
3698
 
            THD *thd= YYTHD;
 
3235
            Session *session= YYSession;
3699
3236
            Create_func *builder;
3700
3237
            Item *item= NULL;
3701
3238
 
3708
3245
 
3709
3246
              This will be revised with WL#2128 (SQL PATH)
3710
3247
            */
3711
 
            builder= find_native_function_builder(thd, $1);
 
3248
            builder= find_native_function_builder($1);
3712
3249
            if (builder)
3713
3250
            {
3714
 
              item= builder->create(thd, $1, $4);
 
3251
              item= builder->create(session, $1, $4);
3715
3252
            }
3716
3253
            else
3717
3254
            {
3718
 
              /* Retrieving the result of find_udf */
3719
 
              udf_func *udf= $<udf>3;
 
3255
              /* Retrieving the result of service::Function::get */
 
3256
              const plugin::Function *udf= $<udf>3;
3720
3257
              if (udf)
3721
3258
              {
3722
 
                if (udf->type == UDFTYPE_AGGREGATE)
3723
 
                {
3724
 
                  Select->in_sum_expr--;
3725
 
                }
3726
 
 
3727
 
                item= Create_udf_func::s_singleton.create(thd, udf, $4);
3728
 
              } else {
 
3259
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
3260
              } else {
3729
3261
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3730
3262
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3731
3263
              }
3746
3278
udf_expr_list:
3747
3279
          udf_expr
3748
3280
          {
3749
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3281
            $$= new (YYSession->mem_root) List<Item>;
3750
3282
            $$->push_back($1);
3751
3283
          }
3752
3284
        | udf_expr_list ',' udf_expr
3771
3303
              $2->set_name($4.str, $4.length, system_charset_info);
3772
3304
            }
3773
3305
            else
3774
 
              $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
 
3306
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
3775
3307
            $$= $2;
3776
3308
          }
3777
3309
        ;
3786
3318
        | COUNT_SYM '(' in_sum_expr ')'
3787
3319
          { $$=new Item_sum_count($3); }
3788
3320
        | COUNT_SYM '(' DISTINCT
3789
 
          { Select->in_sum_expr++; }
 
3321
          { Lex->current_select->in_sum_expr++; }
3790
3322
          expr_list
3791
 
          { Select->in_sum_expr--; }
 
3323
          { Lex->current_select->in_sum_expr--; }
3792
3324
          ')'
3793
3325
          { $$=new Item_sum_count_distinct(* $5); }
3794
3326
        | MIN_SYM '(' in_sum_expr ')'
3817
3349
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3818
3350
          { $$=new Item_sum_sum_distinct($4); }
3819
3351
        | GROUP_CONCAT_SYM '(' opt_distinct
3820
 
          { Select->in_sum_expr++; }
 
3352
          { Lex->current_select->in_sum_expr++; }
3821
3353
          expr_list opt_gorder_clause
3822
3354
          opt_gconcat_separator
3823
3355
          ')'
3824
3356
          {
3825
 
            SELECT_LEX *sel= Select;
 
3357
            Select_Lex *sel= Lex->current_select;
3826
3358
            sel->in_sum_expr--;
3827
3359
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3828
3360
                                          sel->gorder_list, $7);
3832
3364
 
3833
3365
variable:
3834
3366
          '@'
3835
 
          {
3836
 
            if (! Lex->parsing_options.allows_variable)
3837
 
            {
3838
 
              my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
3839
 
              DRIZZLE_YYABORT;
3840
 
            }
3841
 
          }
 
3367
          { }
3842
3368
          variable_aux
3843
3369
          {
3844
3370
            $$= $3;
3862
3388
              my_parse_error(ER(ER_SYNTAX_ERROR));
3863
3389
              DRIZZLE_YYABORT;
3864
3390
            }
3865
 
            if (!($$= get_system_var(YYTHD, $2, $3, $4)))
 
3391
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3866
3392
              DRIZZLE_YYABORT;
3867
 
            if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
3868
 
              Lex->set_stmt_unsafe();
3869
3393
          }
3870
3394
        ;
3871
3395
 
3877
3401
opt_gconcat_separator:
3878
3402
          /* empty */
3879
3403
            {
3880
 
              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
 
3404
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
3881
3405
            }
3882
3406
        | SEPARATOR_SYM text_string { $$ = $2; }
3883
3407
        ;
3885
3409
opt_gorder_clause:
3886
3410
          /* empty */
3887
3411
          {
3888
 
            Select->gorder_list = NULL;
 
3412
            Lex->current_select->gorder_list = NULL;
3889
3413
          }
3890
3414
        | order_clause
3891
3415
          {
3892
 
            SELECT_LEX *select= Select;
 
3416
            Select_Lex *select= Lex->current_select;
3893
3417
            select->gorder_list=
3894
3418
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3895
3419
                                     sizeof(st_sql_list));
3909
3433
          }
3910
3434
          expr
3911
3435
          {
3912
 
            Select->in_sum_expr--;
 
3436
            Lex->current_select->in_sum_expr--;
3913
3437
            $$= $3;
3914
3438
          }
3915
3439
        ;
3919
3443
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3920
3444
        | CHAR_SYM opt_len opt_binary
3921
3445
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3922
 
        | SIGNED_SYM
3923
 
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3924
 
        | SIGNED_SYM INT_SYM
3925
 
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3926
 
        | UNSIGNED
3927
 
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3928
 
        | UNSIGNED INT_SYM
3929
 
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3930
3446
        | DATE_SYM
3931
3447
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3932
 
        | TIME_SYM
3933
 
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3934
 
        | DATETIME
 
3448
        | DATETIME_SYM
3935
3449
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3936
3450
        | DECIMAL_SYM float_options
3937
3451
          { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
3940
3454
expr_list:
3941
3455
          expr
3942
3456
          {
3943
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3457
            $$= new (YYSession->mem_root) List<Item>;
3944
3458
            $$->push_back($1);
3945
3459
          }
3946
3460
        | expr_list ',' expr
3982
3496
        | join_table
3983
3497
          {
3984
3498
            LEX *lex= Lex;
3985
 
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
 
3499
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3986
3500
              DRIZZLE_YYABORT;
3987
3501
          }
3988
3502
        ;
4036
3550
          {
4037
3551
            DRIZZLE_YYABORT_UNLESS($1 && $3);
4038
3552
            /* Change the current name resolution context to a local context. */
4039
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3553
            if (push_new_name_resolution_context(YYSession, $1, $3))
4040
3554
              DRIZZLE_YYABORT;
4041
 
            Select->parsing_place= IN_ON;
 
3555
            Lex->current_select->parsing_place= IN_ON;
4042
3556
          }
4043
3557
          expr
4044
3558
          {
4045
3559
            add_join_on($3,$6);
4046
3560
            Lex->pop_context();
4047
 
            Select->parsing_place= NO_MATTER;
 
3561
            Lex->current_select->parsing_place= NO_MATTER;
4048
3562
          }
4049
3563
        | table_ref STRAIGHT_JOIN table_factor
4050
3564
          ON
4051
3565
          {
4052
3566
            DRIZZLE_YYABORT_UNLESS($1 && $3);
4053
3567
            /* Change the current name resolution context to a local context. */
4054
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3568
            if (push_new_name_resolution_context(YYSession, $1, $3))
4055
3569
              DRIZZLE_YYABORT;
4056
 
            Select->parsing_place= IN_ON;
 
3570
            Lex->current_select->parsing_place= IN_ON;
4057
3571
          }
4058
3572
          expr
4059
3573
          {
4060
3574
            $3->straight=1;
4061
3575
            add_join_on($3,$6);
4062
3576
            Lex->pop_context();
4063
 
            Select->parsing_place= NO_MATTER;
 
3577
            Lex->current_select->parsing_place= NO_MATTER;
4064
3578
          }
4065
3579
        | table_ref normal_join table_ref
4066
3580
          USING
4068
3582
            DRIZZLE_YYABORT_UNLESS($1 && $3);
4069
3583
          }
4070
3584
          '(' using_list ')'
4071
 
          { add_join_natural($1,$3,$7,Select); $$=$3; }
 
3585
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
4072
3586
        | table_ref NATURAL JOIN_SYM table_factor
4073
3587
          {
4074
3588
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
4075
 
            add_join_natural($1,$4,NULL,Select);
 
3589
            add_join_natural($1,$4,NULL,Lex->current_select);
4076
3590
          }
4077
3591
 
4078
3592
          /* LEFT JOIN variants */
4081
3595
          {
4082
3596
            DRIZZLE_YYABORT_UNLESS($1 && $5);
4083
3597
            /* Change the current name resolution context to a local context. */
4084
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
3598
            if (push_new_name_resolution_context(YYSession, $1, $5))
4085
3599
              DRIZZLE_YYABORT;
4086
 
            Select->parsing_place= IN_ON;
 
3600
            Lex->current_select->parsing_place= IN_ON;
4087
3601
          }
4088
3602
          expr
4089
3603
          {
4091
3605
            Lex->pop_context();
4092
3606
            $5->outer_join|=JOIN_TYPE_LEFT;
4093
3607
            $$=$5;
4094
 
            Select->parsing_place= NO_MATTER;
 
3608
            Lex->current_select->parsing_place= NO_MATTER;
4095
3609
          }
4096
3610
        | table_ref LEFT opt_outer JOIN_SYM table_factor
4097
3611
          {
4099
3613
          }
4100
3614
          USING '(' using_list ')'
4101
3615
          { 
4102
 
            add_join_natural($1,$5,$9,Select); 
 
3616
            add_join_natural($1,$5,$9,Lex->current_select); 
4103
3617
            $5->outer_join|=JOIN_TYPE_LEFT; 
4104
3618
            $$=$5; 
4105
3619
          }
4106
3620
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
4107
3621
          {
4108
3622
            DRIZZLE_YYABORT_UNLESS($1 && $6);
4109
 
            add_join_natural($1,$6,NULL,Select);
 
3623
            add_join_natural($1,$6,NULL,Lex->current_select);
4110
3624
            $6->outer_join|=JOIN_TYPE_LEFT;
4111
3625
            $$=$6;
4112
3626
          }
4117
3631
          {
4118
3632
            DRIZZLE_YYABORT_UNLESS($1 && $5);
4119
3633
            /* Change the current name resolution context to a local context. */
4120
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
3634
            if (push_new_name_resolution_context(YYSession, $1, $5))
4121
3635
              DRIZZLE_YYABORT;
4122
 
            Select->parsing_place= IN_ON;
 
3636
            Lex->current_select->parsing_place= IN_ON;
4123
3637
          }
4124
3638
          expr
4125
3639
          {
4128
3642
              DRIZZLE_YYABORT;
4129
3643
            add_join_on($$, $8);
4130
3644
            Lex->pop_context();
4131
 
            Select->parsing_place= NO_MATTER;
 
3645
            Lex->current_select->parsing_place= NO_MATTER;
4132
3646
          }
4133
3647
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
4134
3648
          {
4139
3653
            LEX *lex= Lex;
4140
3654
            if (!($$= lex->current_select->convert_right_join()))
4141
3655
              DRIZZLE_YYABORT;
4142
 
            add_join_natural($$,$5,$9,Select);
 
3656
            add_join_natural($$,$5,$9,Lex->current_select);
4143
3657
          }
4144
3658
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
4145
3659
          {
4146
3660
            DRIZZLE_YYABORT_UNLESS($1 && $6);
4147
 
            add_join_natural($6,$1,NULL,Select);
 
3661
            add_join_natural($6,$1,NULL,Lex->current_select);
4148
3662
            LEX *lex= Lex;
4149
3663
            if (!($$= lex->current_select->convert_right_join()))
4150
3664
              DRIZZLE_YYABORT;
4167
3681
/* Warning - may return NULL in case of incomplete SELECT */
4168
3682
table_factor:
4169
3683
          {
4170
 
            SELECT_LEX *sel= Select;
 
3684
            Select_Lex *sel= Lex->current_select;
4171
3685
            sel->table_join_options= 0;
4172
3686
          }
4173
3687
          table_ident opt_table_alias opt_key_definition
4174
3688
          {
4175
 
            if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
4176
 
                                                Select->get_table_join_options(),
4177
 
                                                Lex->lock_option,
4178
 
                                                Select->pop_index_hints())))
 
3689
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
 
3690
                             Lex->current_select->get_table_join_options(),
 
3691
                             Lex->lock_option,
 
3692
                             Lex->current_select->pop_index_hints())))
4179
3693
              DRIZZLE_YYABORT;
4180
 
            Select->add_joined_table($$);
 
3694
            Lex->current_select->add_joined_table($$);
4181
3695
          }
4182
3696
        | select_derived_init get_select_lex select_derived2
4183
3697
          {
4184
3698
            LEX *lex= Lex;
4185
 
            SELECT_LEX *sel= lex->current_select;
 
3699
            Select_Lex *sel= lex->current_select;
4186
3700
            if ($1)
4187
3701
            {
4188
3702
              if (sel->set_braces(1))
4195
3709
                sel->master_unit()->global_parameters=
4196
3710
                   sel->master_unit()->fake_select_lex;
4197
3711
            }
4198
 
            if ($2->init_nested_join(lex->thd))
 
3712
            if ($2->init_nested_join(lex->session))
4199
3713
              DRIZZLE_YYABORT;
4200
3714
            $$= 0;
4201
3715
            /* incomplete derived tables return NULL, we must be
4238
3752
                 are no outer parentheses, add_table_to_list() will throw
4239
3753
                 error in this case */
4240
3754
              LEX *lex=Lex;
4241
 
              SELECT_LEX *sel= lex->current_select;
4242
 
              SELECT_LEX_UNIT *unit= sel->master_unit();
 
3755
              Select_Lex *sel= lex->current_select;
 
3756
              Select_Lex_Unit *unit= sel->master_unit();
4243
3757
              lex->current_select= sel= unit->outer_select();
4244
 
              if (!($$= sel->add_table_to_list(lex->thd,
 
3758
              if (!($$= sel->add_table_to_list(lex->session,
4245
3759
                                               new Table_ident(unit), $5, 0,
4246
3760
                                               TL_READ)))
4247
3761
 
4285
3799
          select_part2_derived
4286
3800
          {
4287
3801
            LEX *lex= Lex;
4288
 
            SELECT_LEX * sel= lex->current_select;
 
3802
            Select_Lex * sel= lex->current_select;
4289
3803
            if (lex->current_select->set_braces(0))
4290
3804
            {
4291
3805
              my_parse_error(ER(ER_SYNTAX_ERROR));
4304
3818
select_part2_derived:
4305
3819
          {
4306
3820
            LEX *lex= Lex;
4307
 
            SELECT_LEX *sel= lex->current_select;
 
3821
            Select_Lex *sel= lex->current_select;
4308
3822
            if (sel->linkage != UNION_TYPE)
4309
3823
              mysql_init_select(lex);
4310
3824
            lex->current_select->parsing_place= SELECT_LIST;
4311
3825
          }
4312
3826
          select_options select_item_list
4313
3827
          {
4314
 
            Select->parsing_place= NO_MATTER;
 
3828
            Lex->current_select->parsing_place= NO_MATTER;
4315
3829
          }
4316
3830
          opt_select_from select_lock_type
4317
3831
        ;
4321
3835
          get_select_lex
4322
3836
          {
4323
3837
            LEX *lex= Lex;
4324
 
            if ($1->init_nested_join(lex->thd))
 
3838
            if ($1->init_nested_join(lex->session))
4325
3839
              DRIZZLE_YYABORT;
4326
3840
          }
4327
3841
          derived_table_list
4330
3844
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
4331
3845
               for derived tables, both must equal NULL */
4332
3846
 
4333
 
            if (!($$= $1->end_nested_join(lex->thd)) && $3)
 
3847
            if (!($$= $1->end_nested_join(lex->session)) && $3)
4334
3848
              DRIZZLE_YYABORT;
4335
3849
            if (!$3 && $$)
4336
3850
            {
4344
3858
          {
4345
3859
            LEX *lex= Lex;
4346
3860
            lex->derived_tables|= DERIVED_SUBQUERY;
4347
 
            if (!lex->expr_allows_subselect ||
4348
 
                lex->sql_command == (int)SQLCOM_PURGE)
 
3861
            if (!lex->expr_allows_subselect)
4349
3862
            {
4350
3863
              my_parse_error(ER(ER_SYNTAX_ERROR));
4351
3864
              DRIZZLE_YYABORT;
4359
3872
          }
4360
3873
          select_options select_item_list
4361
3874
          {
4362
 
            Select->parsing_place= NO_MATTER;
 
3875
            Lex->current_select->parsing_place= NO_MATTER;
4363
3876
          }
4364
3877
          opt_select_from
4365
3878
        ;
4366
3879
 
4367
3880
get_select_lex:
4368
 
          /* Empty */ { $$= Select; }
 
3881
          /* Empty */ { $$= Lex->current_select; }
4369
3882
        ;
4370
3883
 
4371
3884
select_derived_init:
4373
3886
          {
4374
3887
            LEX *lex= Lex;
4375
3888
 
4376
 
            if (! lex->parsing_options.allows_derived)
4377
 
            {
4378
 
              my_error(ER_VIEW_SELECT_DERIVED, MYF(0));
4379
 
              DRIZZLE_YYABORT;
4380
 
            }
4381
 
 
4382
 
            SELECT_LEX *sel= lex->current_select;
4383
 
            TABLE_LIST *embedding;
4384
 
            if (!sel->embedding || sel->end_nested_join(lex->thd))
 
3889
            Select_Lex *sel= lex->current_select;
 
3890
            TableList *embedding;
 
3891
            if (!sel->embedding || sel->end_nested_join(lex->session))
4385
3892
            {
4386
3893
              /* we are not in parentheses */
4387
3894
              my_parse_error(ER(ER_SYNTAX_ERROR));
4388
3895
              DRIZZLE_YYABORT;
4389
3896
            }
4390
 
            embedding= Select->embedding;
 
3897
            embedding= Lex->current_select->embedding;
4391
3898
            $$= embedding &&
4392
3899
                !embedding->nested_join->join_list.elements;
4393
3900
            /* return true if we are deeply nested */
4402
3909
index_hint_clause:
4403
3910
          /* empty */
4404
3911
          {
4405
 
            $$= global_system_variables.old_mode ? 
4406
 
                  INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL; 
 
3912
            $$= INDEX_HINT_MASK_ALL; 
4407
3913
          }
4408
3914
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
4409
3915
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
4418
3924
index_hint_definition:
4419
3925
          index_hint_type key_or_index index_hint_clause
4420
3926
          {
4421
 
            Select->set_index_hint_type($1, $3);
 
3927
            Lex->current_select->set_index_hint_type($1, $3);
4422
3928
          }
4423
3929
          '(' key_usage_list ')'
4424
3930
        | USE_SYM key_or_index index_hint_clause
4425
3931
          {
4426
 
            Select->set_index_hint_type(INDEX_HINT_USE, $3);
 
3932
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
4427
3933
          }
4428
3934
          '(' opt_key_usage_list ')'
4429
3935
       ;
4435
3941
 
4436
3942
opt_index_hints_list:
4437
3943
          /* empty */
4438
 
        | { Select->alloc_index_hints(YYTHD); } index_hints_list
 
3944
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
4439
3945
        ;
4440
3946
 
4441
3947
opt_key_definition:
4442
 
          {  Select->clear_index_hints(); }
 
3948
          {  Lex->current_select->clear_index_hints(); }
4443
3949
          opt_index_hints_list
4444
3950
        ;
4445
3951
 
4446
3952
opt_key_usage_list:
4447
 
          /* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
 
3953
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
4448
3954
        | key_usage_list {}
4449
3955
        ;
4450
3956
 
4451
3957
key_usage_element:
4452
3958
          ident
4453
 
          { Select->add_index_hint(YYTHD, $1.str, $1.length); }
 
3959
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
4454
3960
        | PRIMARY_SYM
4455
 
          { Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
 
3961
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
4456
3962
        ;
4457
3963
 
4458
3964
key_usage_list:
4465
3971
          {
4466
3972
            if (!($$= new List<String>))
4467
3973
              DRIZZLE_YYABORT;
4468
 
            $$->push_back(new (YYTHD->mem_root)
 
3974
            $$->push_back(new (YYSession->mem_root)
4469
3975
                              String((const char *) $1.str, $1.length,
4470
3976
                                      system_charset_info));
4471
3977
          }
4472
3978
        | using_list ',' ident
4473
3979
          {
4474
 
            $1->push_back(new (YYTHD->mem_root)
 
3980
            $1->push_back(new (YYSession->mem_root)
4475
3981
                              String((const char *) $3.str, $3.length,
4476
3982
                                      system_charset_info));
4477
3983
            $$= $1;
4524
4030
        | YEAR_SYM        { $$=INTERVAL_YEAR; }
4525
4031
        ;
4526
4032
 
4527
 
date_time_type:
4528
 
          DATE_SYM  {$$=DRIZZLE_TIMESTAMP_DATE;}
4529
 
        | TIME_SYM  {$$=DRIZZLE_TIMESTAMP_TIME;}
4530
 
        | DATETIME  {$$=DRIZZLE_TIMESTAMP_DATETIME;}
4531
 
        | TIMESTAMP {$$=DRIZZLE_TIMESTAMP_DATETIME;}
4532
 
        ;
4533
 
 
4534
4033
table_alias:
4535
4034
          /* empty */
4536
4035
        | AS
4549
4048
        ;
4550
4049
 
4551
4050
where_clause:
4552
 
          /* empty */  { Select->where= 0; }
 
4051
          /* empty */  { Lex->current_select->where= 0; }
4553
4052
        | WHERE
4554
4053
          {
4555
 
            Select->parsing_place= IN_WHERE;
 
4054
            Lex->current_select->parsing_place= IN_WHERE;
4556
4055
          }
4557
4056
          expr
4558
4057
          {
4559
 
            SELECT_LEX *select= Select;
 
4058
            Select_Lex *select= Lex->current_select;
4560
4059
            select->where= $3;
4561
4060
            select->parsing_place= NO_MATTER;
4562
4061
            if ($3)
4568
4067
          /* empty */
4569
4068
        | HAVING
4570
4069
          {
4571
 
            Select->parsing_place= IN_HAVING;
 
4070
            Lex->current_select->parsing_place= IN_HAVING;
4572
4071
          }
4573
4072
          expr
4574
4073
          {
4575
 
            SELECT_LEX *sel= Select;
 
4074
            Select_Lex *sel= Lex->current_select;
4576
4075
            sel->having= $3;
4577
4076
            sel->parsing_place= NO_MATTER;
4578
4077
            if ($3)
4589
4088
        | /* empty */
4590
4089
          {
4591
4090
            Lex->escape_used= false;
4592
 
            $$= new Item_string("\\", 1, &my_charset_latin1);
 
4091
            $$= new Item_string("\\", 1, &my_charset_utf8_general_ci);
4593
4092
          }
4594
4093
        ;
4595
4094
 
4604
4103
 
4605
4104
group_list:
4606
4105
          group_list ',' order_ident order_dir
4607
 
          { if (add_group_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4106
          { if (YYSession->add_group_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
4608
4107
        | order_ident order_dir
4609
 
          { if (add_group_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4108
          { if (YYSession->add_group_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
4610
4109
        ;
4611
4110
 
4612
4111
olap_opt:
4613
4112
          /* empty */ {}
4614
 
        | WITH_CUBE_SYM
4615
 
          {
4616
 
            /*
4617
 
              'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
4618
 
              and cause LALR(2) conflicts.
4619
 
              This syntax is not standard.
4620
 
              MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
4621
 
              SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
4622
 
            */
4623
 
            LEX *lex=Lex;
4624
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4625
 
            {
4626
 
              my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
4627
 
                       "global union parameters");
4628
 
              DRIZZLE_YYABORT;
4629
 
            }
4630
 
            lex->current_select->olap= CUBE_TYPE;
4631
 
            my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
4632
 
            DRIZZLE_YYABORT;
4633
 
          }
4634
4113
        | WITH_ROLLUP_SYM
4635
4114
          {
4636
4115
            /*
4667
4146
alter_order_item:
4668
4147
          simple_ident_nospvar order_dir
4669
4148
          {
4670
 
            THD *thd= YYTHD;
 
4149
            Session *session= YYSession;
4671
4150
            bool ascending= ($2 == 1) ? true : false;
4672
 
            if (add_order_to_list(thd, $1, ascending))
 
4151
            if (session->add_order_to_list($1, ascending))
4673
4152
              DRIZZLE_YYABORT;
4674
4153
          }
4675
4154
        ;
4687
4166
          ORDER_SYM BY
4688
4167
          {
4689
4168
            LEX *lex=Lex;
4690
 
            SELECT_LEX *sel= lex->current_select;
4691
 
            SELECT_LEX_UNIT *unit= sel-> master_unit();
 
4169
            Select_Lex *sel= lex->current_select;
 
4170
            Select_Lex_Unit *unit= sel-> master_unit();
4692
4171
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4693
4172
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
4694
4173
                (sel->linkage != UNION_TYPE || sel->braces))
4704
4183
                executed in the same way as the query
4705
4184
                SELECT ... ORDER BY order_list
4706
4185
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
4707
 
                Otherwise we create a fake SELECT_LEX if it has not been created
 
4186
                Otherwise we create a fake Select_Lex if it has not been created
4708
4187
                yet.
4709
4188
              */
4710
 
              SELECT_LEX *first_sl= unit->first_select();
 
4189
              Select_Lex *first_sl= unit->first_select();
4711
4190
              if (!unit->is_union() &&
4712
4191
                  (first_sl->order_list.elements || 
4713
4192
                   first_sl->select_limit) &&            
4714
 
                  unit->add_fake_select_lex(lex->thd))
 
4193
                  unit->add_fake_select_lex(lex->session))
4715
4194
                DRIZZLE_YYABORT;
4716
4195
            }
4717
4196
          }
4720
4199
 
4721
4200
order_list:
4722
4201
          order_list ',' order_ident order_dir
4723
 
          { if (add_order_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4202
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
4724
4203
        | order_ident order_dir
4725
 
          { if (add_order_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4204
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
4726
4205
        ;
4727
4206
 
4728
4207
order_dir:
4735
4214
          /* empty */
4736
4215
          {
4737
4216
            LEX *lex= Lex;
4738
 
            SELECT_LEX *sel= lex->current_select;
 
4217
            Select_Lex *sel= lex->current_select;
4739
4218
            sel->offset_limit= 0;
4740
4219
            sel->select_limit= 0;
4741
4220
          }
4754
4233
limit_options:
4755
4234
          limit_option
4756
4235
          {
4757
 
            SELECT_LEX *sel= Select;
 
4236
            Select_Lex *sel= Lex->current_select;
4758
4237
            sel->select_limit= $1;
4759
4238
            sel->offset_limit= 0;
4760
4239
            sel->explicit_limit= 1;
4761
4240
          }
4762
4241
        | limit_option ',' limit_option
4763
4242
          {
4764
 
            SELECT_LEX *sel= Select;
 
4243
            Select_Lex *sel= Lex->current_select;
4765
4244
            sel->select_limit= $3;
4766
4245
            sel->offset_limit= $1;
4767
4246
            sel->explicit_limit= 1;
4768
4247
          }
4769
4248
        | limit_option OFFSET_SYM limit_option
4770
4249
          {
4771
 
            SELECT_LEX *sel= Select;
 
4250
            Select_Lex *sel= Lex->current_select;
4772
4251
            sel->select_limit= $1;
4773
4252
            sel->offset_limit= $3;
4774
4253
            sel->explicit_limit= 1;
4789
4268
          }
4790
4269
        | LIMIT limit_option
4791
4270
          {
4792
 
            SELECT_LEX *sel= Select;
 
4271
            Select_Lex *sel= Lex->current_select;
4793
4272
            sel->select_limit= $2;
4794
4273
            sel->explicit_limit= 1;
4795
4274
          }
4809
4288
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
4810
4289
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
4811
4290
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
4812
 
        | dec_num_error { DRIZZLE_YYABORT; }
4813
 
        ;
 
4291
        | dec_num_error { }
 
4292
        ;
4814
4293
 
4815
4294
ulonglong_num:
4816
4295
          NUM           { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
4830
4309
        | FLOAT_NUM
4831
4310
        ;
4832
4311
 
4833
 
choice:
4834
 
        ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
4835
 
        | DEFAULT { $$= HA_CHOICE_UNDEF; }
4836
 
        ;
4837
 
 
4838
4312
select_var_list_init:
4839
4313
          {
4840
4314
            LEX *lex=Lex;
4867
4341
 
4868
4342
into:
4869
4343
          INTO
4870
 
          {
4871
 
            if (! Lex->parsing_options.allows_select_into)
4872
 
            {
4873
 
              my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "INTO");
4874
 
              DRIZZLE_YYABORT;
4875
 
            }
4876
 
          }
 
4344
          { }
4877
4345
          into_destination
4878
4346
        ;
4879
4347
 
4881
4349
          OUTFILE TEXT_STRING_filesystem
4882
4350
          {
4883
4351
            LEX *lex= Lex;
4884
 
            if (!(lex->exchange= new sql_exchange($2.str, 0)) ||
 
4352
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
4885
4353
                !(lex->result= new select_export(lex->exchange)))
4886
4354
              DRIZZLE_YYABORT;
4887
4355
          }
4891
4359
            LEX *lex=Lex;
4892
4360
            if (!lex->describe)
4893
4361
            {
4894
 
              if (!(lex->exchange= new sql_exchange($2.str,1)))
 
4362
              if (!(lex->exchange= new file_exchange($2.str,1)))
4895
4363
                DRIZZLE_YYABORT;
4896
4364
              if (!(lex->result= new select_dump(lex->exchange)))
4897
4365
                DRIZZLE_YYABORT;
4910
4378
          {
4911
4379
            LEX *lex=Lex;
4912
4380
            lex->sql_command = SQLCOM_DROP_TABLE;
4913
 
            lex->drop_temporary= $2;
4914
 
            lex->drop_if_exists= $4;
 
4381
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4382
            lex->statement= statement;
 
4383
            if (lex->statement == NULL)
 
4384
              DRIZZLE_YYABORT;
 
4385
            statement->drop_temporary= $2;
 
4386
            statement->drop_if_exists= $4;
4915
4387
          }
4916
4388
        | DROP build_method INDEX_SYM ident ON table_ident {}
4917
4389
          {
4918
4390
            LEX *lex=Lex;
4919
4391
            lex->sql_command= SQLCOM_DROP_INDEX;
4920
 
            lex->alter_info.reset();
4921
 
            lex->alter_info.flags= ALTER_DROP_INDEX;
4922
 
            lex->alter_info.build_method= $2;
4923
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
4924
 
                                                               $4.str));
4925
 
            if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
 
4392
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4393
            lex->statement= statement;
 
4394
            if (lex->statement == NULL)
 
4395
              DRIZZLE_YYABORT;
 
4396
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
4397
            statement->alter_info.build_method= $2;
 
4398
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
 
4399
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4926
4400
                                                        TL_OPTION_UPDATING))
4927
4401
              DRIZZLE_YYABORT;
4928
4402
          }
4930
4404
          {
4931
4405
            LEX *lex=Lex;
4932
4406
            lex->sql_command= SQLCOM_DROP_DB;
4933
 
            lex->drop_if_exists=$3;
 
4407
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4408
            lex->statement= statement;
 
4409
            if (lex->statement == NULL)
 
4410
              DRIZZLE_YYABORT;
 
4411
            statement->drop_if_exists=$3;
4934
4412
            lex->name= $4;
4935
4413
          }
4936
4414
table_list:
4941
4419
table_name:
4942
4420
          table_ident
4943
4421
          {
4944
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
4945
 
              DRIZZLE_YYABORT;
4946
 
          }
4947
 
        ;
4948
 
 
4949
 
table_alias_ref_list:
4950
 
          table_alias_ref
4951
 
        | table_alias_ref_list ',' table_alias_ref
4952
 
        ;
4953
 
 
4954
 
table_alias_ref:
4955
 
          table_ident
4956
 
          {
4957
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL,
4958
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4959
 
                                           Lex->lock_option ))
 
4422
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4960
4423
              DRIZZLE_YYABORT;
4961
4424
          }
4962
4425
        ;
4968
4431
 
4969
4432
opt_temporary:
4970
4433
          /* empty */ { $$= 0; }
4971
 
        | TEMPORARY { $$= 1; }
 
4434
        | TEMPORARY_SYM { $$= 1; }
4972
4435
        ;
4973
4436
/*
4974
4437
** Insert : add new data to table
4979
4442
          {
4980
4443
            LEX *lex= Lex;
4981
4444
            lex->sql_command= SQLCOM_INSERT;
 
4445
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4446
            if (lex->statement == NULL)
 
4447
              DRIZZLE_YYABORT;
4982
4448
            lex->duplicates= DUP_ERROR; 
4983
4449
            mysql_init_select(lex);
4984
4450
            /* for subselects */
4985
 
            lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
 
4451
            lex->lock_option= TL_READ;
4986
4452
          }
4987
 
          insert_lock_option
4988
4453
          opt_ignore insert2
4989
4454
          {
4990
 
            Select->set_lock_for_tables($3);
 
4455
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4991
4456
            Lex->current_select= &Lex->select_lex;
4992
4457
          }
4993
4458
          insert_field_spec opt_insert_update
4997
4462
replace:
4998
4463
          REPLACE
4999
4464
          {
5000
 
            LEX *lex=Lex;
5001
 
            lex->sql_command = SQLCOM_REPLACE;
 
4465
            LEX *lex= Lex;
 
4466
            lex->sql_command= SQLCOM_REPLACE;
 
4467
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4468
            if (lex->statement == NULL)
 
4469
              DRIZZLE_YYABORT;
5002
4470
            lex->duplicates= DUP_REPLACE;
5003
4471
            mysql_init_select(lex);
5004
4472
          }
5005
 
          replace_lock_option insert2
 
4473
          insert2
5006
4474
          {
5007
 
            Select->set_lock_for_tables($3);
 
4475
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
5008
4476
            Lex->current_select= &Lex->select_lex;
5009
4477
          }
5010
4478
          insert_field_spec
5011
4479
          {}
5012
4480
        ;
5013
4481
 
5014
 
insert_lock_option:
5015
 
          /* empty */
5016
 
          {
5017
 
            $$= TL_WRITE_CONCURRENT_INSERT;
5018
 
          }
5019
 
        | LOW_PRIORITY  { $$= TL_WRITE_LOW_PRIORITY; }
5020
 
        | DELAYED_SYM   { $$= TL_WRITE_LOW_PRIORITY; }
5021
 
        | HIGH_PRIORITY { $$= TL_WRITE; }
5022
 
        ;
5023
 
 
5024
 
replace_lock_option:
5025
 
          opt_low_priority { $$= $1; }
5026
 
        | DELAYED_SYM { $$= TL_WRITE_LOW_PRIORITY; }
5027
 
        ;
5028
 
 
5029
4482
insert2:
5030
4483
          INTO insert_table {}
5031
4484
        | insert_table {}
5063
4516
          VALUES values_list {}
5064
4517
        | VALUE_SYM values_list {}
5065
4518
        | create_select
5066
 
          { Select->set_braces(0);}
 
4519
          { Lex->current_select->set_braces(0);}
5067
4520
          union_clause {}
5068
4521
        | '(' create_select ')'
5069
 
          { Select->set_braces(1);}
 
4522
          { Lex->current_select->set_braces(1);}
5070
4523
          union_opt {}
5071
4524
        ;
5072
4525
 
5146
4599
/* Update rows in a table */
5147
4600
 
5148
4601
update:
5149
 
          UPDATE_SYM
 
4602
          UPDATE_SYM opt_ignore table_ident
5150
4603
          {
5151
4604
            LEX *lex= Lex;
5152
4605
            mysql_init_select(lex);
5153
4606
            lex->sql_command= SQLCOM_UPDATE;
 
4607
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4608
            if (lex->statement == NULL)
 
4609
              DRIZZLE_YYABORT;
5154
4610
            lex->lock_option= TL_UNLOCK; /* Will be set later */
5155
4611
            lex->duplicates= DUP_ERROR; 
 
4612
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4613
              DRIZZLE_YYABORT;
5156
4614
          }
5157
 
          opt_low_priority opt_ignore join_table_list
5158
4615
          SET update_list
5159
4616
          {
5160
4617
            LEX *lex= Lex;
5161
 
            if (lex->select_lex.table_list.elements > 1)
5162
 
              lex->sql_command= SQLCOM_UPDATE_MULTI;
5163
 
            else if (lex->select_lex.get_table_list()->derived)
 
4618
            if (lex->select_lex.get_table_list()->derived)
5164
4619
            {
5165
4620
              /* it is single table update and it is update of derived table */
5166
4621
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
5172
4627
              be too pessimistic. We will decrease lock level if possible in
5173
4628
              mysql_multi_update().
5174
4629
            */
5175
 
            Select->set_lock_for_tables($3);
 
4630
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
5176
4631
          }
5177
4632
          where_clause opt_order_clause delete_limit_clause {}
5178
4633
        ;
5185
4640
update_elem:
5186
4641
          simple_ident_nospvar equal expr_or_default
5187
4642
          {
5188
 
            if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
 
4643
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
5189
4644
              DRIZZLE_YYABORT;
5190
4645
          }
5191
4646
        ;
5205
4660
          }
5206
4661
        ;
5207
4662
 
5208
 
opt_low_priority:
5209
 
          /* empty */ { $$= TL_WRITE_DEFAULT; }
5210
 
        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
5211
 
        ;
5212
 
 
5213
4663
/* Delete rows from a table */
5214
4664
 
5215
4665
delete:
5217
4667
          {
5218
4668
            LEX *lex= Lex;
5219
4669
            lex->sql_command= SQLCOM_DELETE;
 
4670
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4671
            if (lex->statement == NULL)
 
4672
              DRIZZLE_YYABORT;
5220
4673
            mysql_init_select(lex);
5221
4674
            lex->lock_option= TL_WRITE_DEFAULT;
5222
4675
            lex->ignore= 0;
5228
4681
single_multi:
5229
4682
          FROM table_ident
5230
4683
          {
5231
 
            if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
 
4684
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
5232
4685
                                           Lex->lock_option))
5233
4686
              DRIZZLE_YYABORT;
5234
4687
          }
5235
4688
          where_clause opt_order_clause
5236
4689
          delete_limit_clause {}
5237
 
        | table_wild_list
5238
 
          { mysql_init_multi_delete(Lex); }
5239
 
          FROM join_table_list where_clause
5240
 
          {
5241
 
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
5242
 
              DRIZZLE_YYABORT;
5243
 
          }
5244
 
        | FROM table_alias_ref_list
5245
 
          { mysql_init_multi_delete(Lex); }
5246
 
          USING join_table_list where_clause
5247
 
          {
5248
 
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
5249
 
              DRIZZLE_YYABORT;
5250
 
          }
5251
 
        ;
5252
 
 
5253
 
table_wild_list:
5254
 
          table_wild_one
5255
 
        | table_wild_list ',' table_wild_one
5256
 
        ;
5257
 
 
5258
 
table_wild_one:
5259
 
          ident opt_wild
5260
 
          {
5261
 
            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
5262
 
                                           NULL,
5263
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5264
 
                                           Lex->lock_option))
5265
 
              DRIZZLE_YYABORT;
5266
 
          }
5267
 
        | ident '.' ident opt_wild
5268
 
          {
5269
 
            if (!Select->add_table_to_list(YYTHD,
5270
 
                                           new Table_ident(YYTHD, $1, $3, 0),
5271
 
                                           NULL,
5272
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5273
 
                                           Lex->lock_option))
5274
 
              DRIZZLE_YYABORT;
5275
 
          }
5276
 
        ;
5277
 
 
5278
 
opt_wild:
5279
 
          /* empty */ {}
5280
 
        | '.' '*' {}
5281
4690
        ;
5282
4691
 
5283
4692
opt_delete_options:
5286
4695
        ;
5287
4696
 
5288
4697
opt_delete_option:
5289
 
          QUICK        { Select->options|= OPTION_QUICK; }
5290
 
        | LOW_PRIORITY { Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
 
4698
          QUICK        { Lex->current_select->options|= OPTION_QUICK; }
5291
4699
        | IGNORE_SYM   { Lex->ignore= 1; }
5292
4700
        ;
5293
4701
 
5296
4704
          {
5297
4705
            LEX* lex= Lex;
5298
4706
            lex->sql_command= SQLCOM_TRUNCATE;
 
4707
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4708
            if (lex->statement == NULL)
 
4709
              DRIZZLE_YYABORT;
5299
4710
            lex->select_lex.options= 0;
5300
4711
            lex->select_lex.init_order();
5301
4712
          }
5316
4727
            lex->lock_option= TL_READ;
5317
4728
            mysql_init_select(lex);
5318
4729
            lex->current_select->parsing_place= SELECT_LIST;
5319
 
            memset(&lex->create_info, 0, sizeof(lex->create_info));
5320
4730
          }
5321
4731
          show_param
5322
4732
          {}
5323
4733
        ;
5324
4734
 
5325
4735
show_param:
5326
 
           DATABASES wild_and_where
 
4736
           DATABASES show_wild
5327
4737
           {
5328
4738
             LEX *lex= Lex;
5329
4739
             lex->sql_command= SQLCOM_SHOW_DATABASES;
5330
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
 
4740
             lex->statement=
 
4741
               new(std::nothrow) statement::Select(YYSession);
 
4742
             if (lex->statement == NULL)
 
4743
               DRIZZLE_YYABORT;
 
4744
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
5331
4745
               DRIZZLE_YYABORT;
5332
4746
           }
5333
 
         | opt_full TABLES opt_db wild_and_where
 
4747
         | opt_full TABLES opt_db show_wild
5334
4748
           {
5335
4749
             LEX *lex= Lex;
5336
4750
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4751
             lex->statement=
 
4752
               new(std::nothrow) statement::Select(YYSession);
 
4753
             if (lex->statement == NULL)
 
4754
               DRIZZLE_YYABORT;
5337
4755
             lex->select_lex.db= $3;
5338
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
 
4756
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
5339
4757
               DRIZZLE_YYABORT;
5340
4758
           }
5341
 
         | TABLE_SYM STATUS_SYM opt_db wild_and_where
 
4759
         | TABLE_SYM STATUS_SYM opt_db show_wild
5342
4760
           {
5343
4761
             LEX *lex= Lex;
5344
4762
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4763
             lex->statement=
 
4764
               new(std::nothrow) statement::Select(YYSession);
 
4765
             if (lex->statement == NULL)
 
4766
               DRIZZLE_YYABORT;
5345
4767
             lex->select_lex.db= $3;
5346
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
 
4768
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
5347
4769
               DRIZZLE_YYABORT;
5348
4770
           }
5349
 
        | OPEN_SYM TABLES opt_db wild_and_where
 
4771
        | OPEN_SYM TABLES opt_db show_wild
5350
4772
          {
5351
4773
            LEX *lex= Lex;
5352
4774
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
4775
            lex->statement=
 
4776
              new(std::nothrow) statement::Select(YYSession);
 
4777
            if (lex->statement == NULL)
 
4778
              DRIZZLE_YYABORT;
5353
4779
            lex->select_lex.db= $3;
5354
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
 
4780
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
5355
4781
              DRIZZLE_YYABORT;
5356
4782
          }
5357
4783
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
5358
4784
          { 
5359
 
            Lex->create_info.db_type= $2; 
5360
4785
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
 
4786
            Lex->statement= 
 
4787
              new(std::nothrow) statement::ShowEngineStatus(YYSession, $2);
 
4788
            if (Lex->statement == NULL)
 
4789
              DRIZZLE_YYABORT;
5361
4790
          }
5362
 
        | opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
 
4791
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
5363
4792
          {
5364
4793
            LEX *lex= Lex;
5365
4794
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4795
            lex->statement=
 
4796
              new(std::nothrow) statement::Select(YYSession);
 
4797
            if (lex->statement == NULL)
 
4798
              DRIZZLE_YYABORT;
5366
4799
            if ($5)
5367
4800
              $4->change_db($5);
5368
 
            if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
 
4801
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
5369
4802
              DRIZZLE_YYABORT;
5370
4803
          }
5371
 
        | master_or_binary LOGS_SYM
5372
 
          {
5373
 
            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
5374
 
          }
5375
 
        | SLAVE HOSTS_SYM
5376
 
          {
5377
 
            Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
5378
 
          }
5379
 
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
5380
 
          {
5381
 
            LEX *lex= Lex;
5382
 
            lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
5383
 
          } opt_limit_clause_init
5384
4804
        | keys_or_index from_or_in table_ident opt_db where_clause
5385
4805
          {
5386
4806
            LEX *lex= Lex;
5387
4807
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
4808
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4809
            if (lex->statement == NULL)
 
4810
              DRIZZLE_YYABORT;
5388
4811
            if ($4)
5389
4812
              $3->change_db($4);
5390
 
            if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
 
4813
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
5391
4814
              DRIZZLE_YYABORT;
5392
4815
          }
5393
4816
        | COUNT_SYM '(' '*' ')' WARNINGS
5394
 
          { (void) create_select_for_variable("warning_count"); }
 
4817
          { 
 
4818
            (void) create_select_for_variable("warning_count"); 
 
4819
            LEX *lex= Lex;
 
4820
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4821
            if (lex->statement == NULL)
 
4822
              DRIZZLE_YYABORT;
 
4823
          }
5395
4824
        | COUNT_SYM '(' '*' ')' ERRORS
5396
 
          { (void) create_select_for_variable("error_count"); }
 
4825
          { 
 
4826
            (void) create_select_for_variable("error_count"); 
 
4827
            LEX *lex= Lex;
 
4828
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4829
            if (lex->statement == NULL)
 
4830
              DRIZZLE_YYABORT;
 
4831
          }
5397
4832
        | WARNINGS opt_limit_clause_init
5398
 
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
 
4833
          { 
 
4834
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
4835
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
4836
            if (Lex->statement == NULL)
 
4837
              DRIZZLE_YYABORT;
 
4838
          }
5399
4839
        | ERRORS opt_limit_clause_init
5400
 
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
5401
 
        | opt_var_type STATUS_SYM wild_and_where
 
4840
          { 
 
4841
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
4842
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
4843
            if (Lex->statement == NULL)
 
4844
              DRIZZLE_YYABORT;
 
4845
          }
 
4846
        | opt_var_type STATUS_SYM show_wild
5402
4847
          {
5403
4848
            LEX *lex= Lex;
5404
4849
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
4850
            lex->statement=
 
4851
              new(std::nothrow) statement::ShowStatus(YYSession,
 
4852
                                                    &LOCK_status);
 
4853
            if (lex->statement == NULL)
 
4854
              DRIZZLE_YYABORT;
5405
4855
            lex->option_type= $1;
5406
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
 
4856
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
5407
4857
              DRIZZLE_YYABORT;
5408
4858
          }
5409
4859
        | opt_full PROCESSLIST_SYM
5410
 
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
5411
 
        | opt_var_type  VARIABLES wild_and_where
 
4860
          { 
 
4861
            Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;
 
4862
            Lex->statement= 
 
4863
              new(std::nothrow) statement::ShowProcesslist(YYSession);
 
4864
            if (Lex->statement == NULL)
 
4865
              DRIZZLE_YYABORT;
 
4866
          }
 
4867
        | opt_var_type  VARIABLES show_wild
5412
4868
          {
5413
4869
            LEX *lex= Lex;
5414
4870
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
4871
            lex->statement=
 
4872
              new(std::nothrow) statement::Select(YYSession);
 
4873
            if (lex->statement == NULL)
 
4874
              DRIZZLE_YYABORT;
5415
4875
            lex->option_type= $1;
5416
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
5417
 
              DRIZZLE_YYABORT;
5418
 
          }
5419
 
        | charset wild_and_where
5420
 
          {
5421
 
            LEX *lex= Lex;
5422
 
            lex->sql_command= SQLCOM_SHOW_CHARSETS;
5423
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
5424
 
              DRIZZLE_YYABORT;
5425
 
          }
5426
 
        | COLLATION_SYM wild_and_where
5427
 
          {
5428
 
            LEX *lex= Lex;
5429
 
            lex->sql_command= SQLCOM_SHOW_COLLATIONS;
5430
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
 
4876
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
5431
4877
              DRIZZLE_YYABORT;
5432
4878
          }
5433
4879
        | CREATE DATABASE opt_if_not_exists ident
5434
4880
          {
5435
4881
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5436
 
            Lex->create_info.options=$3;
 
4882
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
 
4883
            Lex->statement= statement;
 
4884
            if (Lex->statement == NULL)
 
4885
              DRIZZLE_YYABORT;
 
4886
            statement->create_info.options=$3;
5437
4887
            Lex->name= $4;
5438
4888
          }
5439
4889
        | CREATE TABLE_SYM table_ident
5440
4890
          {
5441
4891
            LEX *lex= Lex;
5442
4892
            lex->sql_command = SQLCOM_SHOW_CREATE;
5443
 
            if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
5444
 
              DRIZZLE_YYABORT;
5445
 
          }
5446
 
        | MASTER_SYM STATUS_SYM
5447
 
          {
5448
 
            Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
5449
 
          }
5450
 
        | SLAVE STATUS_SYM
5451
 
          {
5452
 
            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
5453
 
          }
5454
 
 
5455
 
master_or_binary:
5456
 
          MASTER_SYM
5457
 
        | BINARY
5458
 
        ;
 
4893
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
 
4894
            if (lex->statement == NULL)
 
4895
              DRIZZLE_YYABORT;
 
4896
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4897
              DRIZZLE_YYABORT;
 
4898
          }
5459
4899
 
5460
4900
opt_db:
5461
4901
          /* empty */  { $$= 0; }
5463
4903
        ;
5464
4904
 
5465
4905
opt_full:
5466
 
          /* empty */ { Lex->verbose=0; }
5467
 
        | FULL        { Lex->verbose=1; }
 
4906
          /* empty */ { Lex->verbose= false; }
 
4907
        | FULL        { Lex->verbose= true; }
5468
4908
        ;
5469
4909
 
5470
4910
from_or_in:
5472
4912
        | IN_SYM
5473
4913
        ;
5474
4914
 
5475
 
binlog_in:
5476
 
          /* empty */            { Lex->mi.log_file_name = 0; }
5477
 
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
5478
 
        ;
5479
 
 
5480
 
binlog_from:
5481
 
          /* empty */        { Lex->mi.pos = 4; /* skip magic number */ }
5482
 
        | FROM ulonglong_num { Lex->mi.pos = $2; }
5483
 
        ;
5484
 
 
5485
 
wild_and_where:
 
4915
show_wild:
5486
4916
          /* empty */
5487
4917
        | LIKE TEXT_STRING_sys
5488
4918
          {
5489
 
            Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
 
4919
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
5490
4920
                                                    system_charset_info);
 
4921
            if (Lex->wild == NULL)
 
4922
              DRIZZLE_YYABORT;
5491
4923
          }
5492
4924
        | WHERE expr
5493
4925
          {
5494
 
            Select->where= $2;
 
4926
            Lex->current_select->where= $2;
5495
4927
            if ($2)
5496
4928
              $2->top_level_item();
5497
4929
          }
5506
4938
            mysql_init_select(lex);
5507
4939
            lex->current_select->parsing_place= SELECT_LIST;
5508
4940
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4941
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4942
            if (lex->statement == NULL)
 
4943
              DRIZZLE_YYABORT;
5509
4944
            lex->select_lex.db= 0;
5510
4945
            lex->verbose= 0;
5511
 
            if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
 
4946
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
5512
4947
              DRIZZLE_YYABORT;
5513
4948
          }
5514
4949
          opt_describe_column {}
5536
4971
        | text_string { Lex->wild= $1; }
5537
4972
        | ident
5538
4973
          {
5539
 
            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
 
4974
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
5540
4975
                                                    $1.length,
5541
4976
                                                    system_charset_info);
5542
4977
          }
5546
4981
/* flush things */
5547
4982
 
5548
4983
flush:
5549
 
          FLUSH_SYM opt_no_write_to_binlog
 
4984
          FLUSH_SYM
5550
4985
          {
5551
4986
            LEX *lex=Lex;
5552
4987
            lex->sql_command= SQLCOM_FLUSH;
 
4988
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
4989
            if (lex->statement == NULL)
 
4990
              DRIZZLE_YYABORT;
5553
4991
            lex->type= 0;
5554
 
            lex->no_write_to_binlog= $2;
5555
4992
          }
5556
4993
          flush_options
5557
4994
          {}
5568
5005
          opt_table_list {}
5569
5006
        | TABLES WITH READ_SYM LOCK_SYM
5570
5007
          { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
5571
 
        | QUERY_SYM CACHE_SYM
5572
 
          { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
5573
 
        | HOSTS_SYM
5574
 
          { Lex->type|= REFRESH_HOSTS; }
5575
5008
        | LOGS_SYM
5576
5009
          { Lex->type|= REFRESH_LOG; }
5577
5010
        | STATUS_SYM
5578
5011
          { Lex->type|= REFRESH_STATUS; }
5579
 
        | SLAVE
5580
 
          { Lex->type|= REFRESH_SLAVE; }
5581
 
        | MASTER_SYM
5582
 
          { Lex->type|= REFRESH_MASTER; }
5583
 
        | RESOURCES
5584
 
          { Lex->type|= REFRESH_USER_RESOURCES; }
5585
5012
        ;
5586
5013
 
5587
5014
opt_table_list:
5589
5016
        | table_list {}
5590
5017
        ;
5591
5018
 
5592
 
reset:
5593
 
          RESET_SYM
5594
 
          {
5595
 
            LEX *lex=Lex;
5596
 
            lex->sql_command= SQLCOM_RESET; lex->type=0;
5597
 
          }
5598
 
          reset_options
5599
 
          {}
5600
 
        ;
5601
 
 
5602
 
reset_options:
5603
 
          reset_options ',' reset_option
5604
 
        | reset_option
5605
 
        ;
5606
 
 
5607
 
reset_option:
5608
 
          SLAVE               { Lex->type|= REFRESH_SLAVE; }
5609
 
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
5610
 
        | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;}
5611
 
        ;
5612
 
 
5613
 
purge:
5614
 
          PURGE
5615
 
          {
5616
 
            LEX *lex=Lex;
5617
 
            lex->type=0;
5618
 
            lex->sql_command = SQLCOM_PURGE;
5619
 
          }
5620
 
          purge_options
5621
 
          {}
5622
 
        ;
5623
 
 
5624
 
purge_options:
5625
 
          master_or_binary LOGS_SYM purge_option
5626
 
        ;
5627
 
 
5628
 
purge_option:
5629
 
          TO_SYM TEXT_STRING_sys
5630
 
          {
5631
 
            Lex->to_log = $2.str;
5632
 
          }
5633
 
        | BEFORE_SYM expr
5634
 
          {
5635
 
            LEX *lex= Lex;
5636
 
            lex->value_list.empty();
5637
 
            lex->value_list.push_front($2);
5638
 
            lex->sql_command= SQLCOM_PURGE_BEFORE;
5639
 
          }
5640
 
        ;
5641
 
 
5642
5019
/* kill threads */
5643
5020
 
5644
5021
kill:
5648
5025
            lex->value_list.empty();
5649
5026
            lex->value_list.push_front($3);
5650
5027
            lex->sql_command= SQLCOM_KILL;
 
5028
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
5029
            if (lex->statement == NULL)
 
5030
              DRIZZLE_YYABORT;
5651
5031
          }
5652
5032
        ;
5653
5033
 
5664
5044
          {
5665
5045
            LEX *lex=Lex;
5666
5046
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5047
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5048
            if (lex->statement == NULL)
 
5049
              DRIZZLE_YYABORT;
5667
5050
            lex->select_lex.db= $2.str;
5668
5051
          }
5669
5052
        ;
5673
5056
load:
5674
5057
          LOAD data_file
5675
5058
          {
5676
 
            THD *thd= YYTHD;
5677
 
            LEX *lex= thd->lex;
5678
 
            Lex_input_stream *lip= thd->m_lip;
 
5059
            Session *session= YYSession;
 
5060
            LEX *lex= session->lex;
5679
5061
 
5680
 
            lex->fname_start= lip->get_ptr();
5681
 
          }
5682
 
          load_data_lock opt_local INFILE TEXT_STRING_filesystem
5683
 
          {
5684
 
            LEX *lex=Lex;
5685
5062
            lex->sql_command= SQLCOM_LOAD;
 
5063
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5064
            lex->statement= statement;
 
5065
            if (lex->statement == NULL)
 
5066
              DRIZZLE_YYABORT;
 
5067
 
 
5068
            Lex_input_stream *lip= session->m_lip;
 
5069
            statement->fname_start= lip->get_ptr();
 
5070
          }
 
5071
          load_data_lock INFILE TEXT_STRING_filesystem
 
5072
          {
 
5073
            LEX *lex=Lex;
5686
5074
            lex->lock_option= $4;
5687
 
            lex->local_file=  $5;
5688
5075
            lex->duplicates= DUP_ERROR;
5689
5076
            lex->ignore= 0;
5690
 
            if (!(lex->exchange= new sql_exchange($7.str, 0, $2)))
 
5077
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
5691
5078
              DRIZZLE_YYABORT;
5692
5079
          }
5693
5080
          opt_duplicate INTO
5694
5081
          {
5695
 
            THD *thd= YYTHD;
5696
 
            LEX *lex= thd->lex;
5697
 
            Lex_input_stream *lip= thd->m_lip;
5698
 
            lex->fname_end= lip->get_ptr();
 
5082
            Session *session= YYSession;
 
5083
            Lex_input_stream *lip= session->m_lip;
 
5084
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
5699
5085
          }
5700
5086
          TABLE_SYM table_ident
5701
5087
          {
5702
5088
            LEX *lex=Lex;
5703
 
            if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
5704
 
                                           lex->lock_option))
 
5089
            if (!Lex->current_select->add_table_to_list(YYSession,
 
5090
                    $12, NULL, TL_OPTION_UPDATING,
 
5091
                    lex->lock_option))
5705
5092
              DRIZZLE_YYABORT;
5706
5093
            lex->field_list.empty();
5707
5094
            lex->update_list.empty();
5708
5095
            lex->value_list.empty();
5709
5096
          }
5710
 
          opt_load_data_charset
5711
 
          { Lex->exchange->cs= $15; }
5712
5097
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5713
5098
          opt_load_data_set_spec
5714
5099
          {}
5717
5102
data_file:
5718
5103
        DATA_SYM  { $$= FILETYPE_CSV; };
5719
5104
 
5720
 
opt_local:
5721
 
          /* empty */ { $$=0;}
5722
 
        | LOCAL_SYM { $$=1;}
5723
 
        ;
5724
 
 
5725
5105
load_data_lock:
5726
5106
          /* empty */ { $$= TL_WRITE_DEFAULT; }
5727
5107
        | CONCURRENT
5728
5108
          {
5729
5109
              $$= TL_WRITE_CONCURRENT_INSERT;
5730
5110
          }
5731
 
        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
5732
5111
        ;
5733
5112
 
5734
5113
opt_duplicate:
5836
5215
/* Common definitions */
5837
5216
 
5838
5217
text_literal:
5839
 
          TEXT_STRING
5840
 
          {
5841
 
            LEX_STRING tmp;
5842
 
            THD *thd= YYTHD;
5843
 
            const CHARSET_INFO * const cs_con= thd->variables.collation_connection;
5844
 
            const CHARSET_INFO * const cs_cli= thd->variables.character_set_client;
5845
 
            uint repertoire= thd->lex->text_string_is_7bit &&
5846
 
                             my_charset_is_ascii_based(cs_cli) ?
5847
 
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
5848
 
            if (thd->charset_is_collation_connection ||
5849
 
                (repertoire == MY_REPERTOIRE_ASCII &&
5850
 
                 my_charset_is_ascii_based(cs_con)))
5851
 
              tmp= $1;
5852
 
            else
5853
 
              thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
5854
 
            $$= new Item_string(tmp.str, tmp.length, cs_con,
5855
 
                                DERIVATION_COERCIBLE, repertoire);
5856
 
          }
5857
 
        | UNDERSCORE_CHARSET TEXT_STRING
5858
 
          {
5859
 
            Item_string *str= new Item_string($2.str, $2.length, $1);
5860
 
            str->set_repertoire_from_value();
5861
 
            str->set_cs_specified(true);
5862
 
 
5863
 
            $$= str;
5864
 
          }
 
5218
        TEXT_STRING_literal
 
5219
        {
 
5220
          Session *session= YYSession;
 
5221
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
 
5222
        }
5865
5223
        | text_literal TEXT_STRING_literal
5866
 
          {
5867
 
            Item_string* item= (Item_string*) $1;
5868
 
            item->append($2.str, $2.length);
5869
 
            if (!(item->collation.repertoire & MY_REPERTOIRE_EXTENDED))
5870
 
            {
5871
 
              /*
5872
 
                 If the string has been pure ASCII so far,
5873
 
                 check the new part.
5874
 
              */
5875
 
              const CHARSET_INFO * const cs= YYTHD->variables.collation_connection;
5876
 
              item->collation.repertoire|= my_string_repertoire(cs,
5877
 
                                                                $2.str,
5878
 
                                                                $2.length);
5879
 
            }
 
5224
          { 
 
5225
            ((Item_string*) $1)->append($2.str, $2.length); 
5880
5226
          }
5881
5227
        ;
5882
5228
 
5883
5229
text_string:
5884
5230
          TEXT_STRING_literal
5885
5231
          {
5886
 
            $$= new (YYTHD->mem_root) String($1.str,
 
5232
            $$= new (YYSession->mem_root) String($1.str,
5887
5233
                                             $1.length,
5888
 
                                             YYTHD->variables.collation_connection);
 
5234
                                             YYSession->variables.getCollation());
5889
5235
          }
5890
5236
        | HEX_NUM
5891
5237
          {
5926
5272
        | NULL_SYM
5927
5273
          {
5928
5274
            $$ = new Item_null();
5929
 
            YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
 
5275
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5930
5276
          }
5931
5277
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5932
5278
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
5933
5279
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
5934
5280
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
5935
 
        | UNDERSCORE_CHARSET HEX_NUM
5936
 
          {
5937
 
            Item *tmp= new Item_hex_string($2.str, $2.length);
5938
 
            /*
5939
 
              it is OK only emulate fix_fieds, because we need only
5940
 
              value of constant
5941
 
            */
5942
 
            String *str= tmp ?
5943
 
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
5944
 
              (String*) 0;
5945
 
 
5946
 
            Item_string *item_str=
5947
 
              new Item_string(NULL, /* name will be set in select_item */
5948
 
                              str ? str->ptr() : "",
5949
 
                              str ? str->length() : 0,
5950
 
                              $1);
5951
 
            if (!item_str ||
5952
 
                !item_str->check_well_formed_result(&item_str->str_value, true))
5953
 
            {
5954
 
              DRIZZLE_YYABORT;
5955
 
            }
5956
 
 
5957
 
            item_str->set_repertoire_from_value();
5958
 
            item_str->set_cs_specified(true);
5959
 
 
5960
 
            $$= item_str;
5961
 
          }
5962
 
        | UNDERSCORE_CHARSET BIN_NUM
5963
 
          {
5964
 
            Item *tmp= new Item_bin_string($2.str, $2.length);
5965
 
            /*
5966
 
              it is OK only emulate fix_fieds, because we need only
5967
 
              value of constant
5968
 
            */
5969
 
            String *str= tmp ?
5970
 
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
5971
 
              (String*) 0;
5972
 
 
5973
 
            Item_string *item_str=
5974
 
              new Item_string(NULL, /* name will be set in select_item */
5975
 
                              str ? str->ptr() : "",
5976
 
                              str ? str->length() : 0,
5977
 
                              $1);
5978
 
            if (!item_str ||
5979
 
                !item_str->check_well_formed_result(&item_str->str_value, true))
5980
 
            {
5981
 
              DRIZZLE_YYABORT;
5982
 
            }
5983
 
 
5984
 
            item_str->set_cs_specified(true);
5985
 
 
5986
 
            $$= item_str;
5987
 
          }
5988
5281
        | DATE_SYM text_literal { $$ = $2; }
5989
 
        | TIME_SYM text_literal { $$ = $2; }
5990
 
        | TIMESTAMP text_literal { $$ = $2; }
 
5282
        | TIMESTAMP_SYM text_literal { $$ = $2; }
5991
5283
        ;
5992
5284
 
5993
5285
NUM_literal:
6005
5297
          { $$ = new Item_uint($1.str, $1.length); }
6006
5298
        | DECIMAL_NUM
6007
5299
          {
6008
 
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
6009
 
            if (YYTHD->is_error())
 
5300
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
 
5301
            if (YYSession->is_error())
6010
5302
            {
6011
5303
              DRIZZLE_YYABORT;
6012
5304
            }
6014
5306
        | FLOAT_NUM
6015
5307
          {
6016
5308
            $$ = new Item_float($1.str, $1.length);
6017
 
            if (YYTHD->is_error())
 
5309
            if (YYSession->is_error())
6018
5310
            {
6019
5311
              DRIZZLE_YYABORT;
6020
5312
            }
6033
5325
table_wild:
6034
5326
          ident '.' '*'
6035
5327
          {
6036
 
            SELECT_LEX *sel= Select;
6037
 
            $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
 
5328
            Select_Lex *sel= Lex->current_select;
 
5329
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
6038
5330
            sel->with_wild++;
6039
5331
          }
6040
5332
        | ident '.' ident '.' '*'
6041
5333
          {
6042
 
            SELECT_LEX *sel= Select;
6043
 
            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
6044
 
                                CLIENT_NO_SCHEMA ? NullS : $1.str),
6045
 
                                $3.str,"*");
 
5334
            Select_Lex *sel= Lex->current_select;
 
5335
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
6046
5336
            sel->with_wild++;
6047
5337
          }
6048
5338
        ;
6055
5345
          ident
6056
5346
          {
6057
5347
            {
6058
 
              SELECT_LEX *sel=Select;
 
5348
              Select_Lex *sel=Lex->current_select;
6059
5349
              $$= (sel->parsing_place != IN_HAVING ||
6060
5350
                  sel->get_in_sum_expr() > 0) ?
6061
 
                  (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
6062
 
                  (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
 
5351
                  (Item*) new Item_field(Lex->current_context(),
 
5352
                                         (const char *)NULL, NULL, $1.str) :
 
5353
                  (Item*) new Item_ref(Lex->current_context(),
 
5354
                                       (const char *)NULL, NULL, $1.str);
6063
5355
            }
6064
5356
          }
6065
5357
        | simple_ident_q { $$= $1; }
6068
5360
simple_ident_nospvar:
6069
5361
          ident
6070
5362
          {
6071
 
            SELECT_LEX *sel=Select;
 
5363
            Select_Lex *sel=Lex->current_select;
6072
5364
            $$= (sel->parsing_place != IN_HAVING ||
6073
5365
                sel->get_in_sum_expr() > 0) ?
6074
 
                (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
6075
 
                (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
 
5366
                (Item*) new Item_field(Lex->current_context(),
 
5367
                                       (const char *)NULL, NULL, $1.str) :
 
5368
                (Item*) new Item_ref(Lex->current_context(),
 
5369
                                     (const char *)NULL, NULL, $1.str);
6076
5370
          }
6077
5371
        | simple_ident_q { $$= $1; }
6078
5372
        ;
6080
5374
simple_ident_q:
6081
5375
          ident '.' ident
6082
5376
          {
6083
 
            THD *thd= YYTHD;
6084
 
            LEX *lex= thd->lex;
 
5377
            Session *session= YYSession;
 
5378
            LEX *lex= session->lex;
6085
5379
 
6086
5380
            {
6087
 
              SELECT_LEX *sel= lex->current_select;
 
5381
              Select_Lex *sel= lex->current_select;
6088
5382
              if (sel->no_table_names_allowed)
6089
5383
              {
6090
5384
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6091
 
                         MYF(0), $1.str, thd->where);
 
5385
                         MYF(0), $1.str, session->where);
6092
5386
              }
6093
5387
              $$= (sel->parsing_place != IN_HAVING ||
6094
5388
                  sel->get_in_sum_expr() > 0) ?
6095
 
                  (Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
6096
 
                  (Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
 
5389
                  (Item*) new Item_field(Lex->current_context(),
 
5390
                                         (const char *)NULL, $1.str, $3.str) :
 
5391
                  (Item*) new Item_ref(Lex->current_context(),
 
5392
                                       (const char *)NULL, $1.str, $3.str);
6097
5393
            }
6098
5394
          }
6099
5395
        | '.' ident '.' ident
6100
5396
          {
6101
 
            THD *thd= YYTHD;
6102
 
            LEX *lex= thd->lex;
6103
 
            SELECT_LEX *sel= lex->current_select;
 
5397
            Session *session= YYSession;
 
5398
            LEX *lex= session->lex;
 
5399
            Select_Lex *sel= lex->current_select;
6104
5400
            if (sel->no_table_names_allowed)
6105
5401
            {
6106
5402
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6107
 
                       MYF(0), $2.str, thd->where);
 
5403
                       MYF(0), $2.str, session->where);
6108
5404
            }
6109
5405
            $$= (sel->parsing_place != IN_HAVING ||
6110
5406
                sel->get_in_sum_expr() > 0) ?
6111
 
                (Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
6112
 
                (Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
 
5407
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5408
                (Item*) new Item_ref(Lex->current_context(),
 
5409
                                     (const char *)NULL, $2.str, $4.str);
6113
5410
          }
6114
5411
        | ident '.' ident '.' ident
6115
5412
          {
6116
 
            THD *thd= YYTHD;
6117
 
            LEX *lex= thd->lex;
6118
 
            SELECT_LEX *sel= lex->current_select;
 
5413
            Session *session= YYSession;
 
5414
            LEX *lex= session->lex;
 
5415
            Select_Lex *sel= lex->current_select;
6119
5416
            if (sel->no_table_names_allowed)
6120
5417
            {
6121
5418
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6122
 
                       MYF(0), $3.str, thd->where);
 
5419
                       MYF(0), $3.str, session->where);
6123
5420
            }
6124
5421
            $$= (sel->parsing_place != IN_HAVING ||
6125
5422
                sel->get_in_sum_expr() > 0) ?
6126
 
                (Item*) new Item_field(Lex->current_context(),
6127
 
                                       (YYTHD->client_capabilities &
6128
 
                                       CLIENT_NO_SCHEMA ? NullS : $1.str),
6129
 
                                       $3.str, $5.str) :
6130
 
                (Item*) new Item_ref(Lex->current_context(),
6131
 
                                     (YYTHD->client_capabilities &
6132
 
                                     CLIENT_NO_SCHEMA ? NullS : $1.str),
6133
 
                                     $3.str, $5.str);
 
5423
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5424
                                       $5.str) :
 
5425
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5426
                                     $5.str);
6134
5427
          }
6135
5428
        ;
6136
5429
 
6138
5431
          ident { $$=$1;}
6139
5432
        | ident '.' ident '.' ident
6140
5433
          {
6141
 
            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
 
5434
            TableList *table=
 
5435
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6142
5436
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
6143
5437
            {
6144
5438
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
6154
5448
          }
6155
5449
        | ident '.' ident
6156
5450
          {
6157
 
            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
 
5451
            TableList *table=
 
5452
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6158
5453
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
6159
5454
            {
6160
5455
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
6167
5462
 
6168
5463
table_ident:
6169
5464
          ident { $$=new Table_ident($1); }
6170
 
        | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
 
5465
        | ident '.' ident { $$=new Table_ident($1,$3);}
6171
5466
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
6172
5467
        ;
6173
5468
 
6175
5470
          IDENT { $$= $1; }
6176
5471
        | IDENT_QUOTED
6177
5472
          {
6178
 
            THD *thd= YYTHD;
6179
 
 
6180
 
            if (thd->charset_is_system_charset)
 
5473
            const CHARSET_INFO * const cs= system_charset_info;
 
5474
            int dummy_error;
 
5475
            uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
 
5476
                                                 $1.str+$1.length,
 
5477
                                                 $1.length, &dummy_error);
 
5478
            if (wlen < $1.length)
6181
5479
            {
6182
 
              const CHARSET_INFO * const cs= system_charset_info;
6183
 
              int dummy_error;
6184
 
              uint wlen= cs->cset->well_formed_len(cs, $1.str,
6185
 
                                                   $1.str+$1.length,
6186
 
                                                   $1.length, &dummy_error);
6187
 
              if (wlen < $1.length)
6188
 
              {
6189
 
                my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
6190
 
                         cs->csname, $1.str + wlen);
6191
 
                DRIZZLE_YYABORT;
6192
 
              }
6193
 
              $$= $1;
 
5480
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
 
5481
                       cs->csname, $1.str + wlen);
 
5482
              DRIZZLE_YYABORT;
6194
5483
            }
6195
 
            else
6196
 
              thd->convert_string(&$$, system_charset_info,
6197
 
                                  $1.str, $1.length, thd->charset());
 
5484
            $$= $1;
6198
5485
          }
6199
5486
        ;
6200
5487
 
6201
5488
TEXT_STRING_sys:
6202
5489
          TEXT_STRING
6203
5490
          {
6204
 
            THD *thd= YYTHD;
6205
 
 
6206
 
            if (thd->charset_is_system_charset)
6207
 
              $$= $1;
6208
 
            else
6209
 
              thd->convert_string(&$$, system_charset_info,
6210
 
                                  $1.str, $1.length, thd->charset());
 
5491
            $$= $1;
6211
5492
          }
6212
5493
        ;
6213
5494
 
6214
5495
TEXT_STRING_literal:
6215
5496
          TEXT_STRING
6216
5497
          {
6217
 
            THD *thd= YYTHD;
6218
 
 
6219
 
            if (thd->charset_is_collation_connection)
6220
 
              $$= $1;
6221
 
            else
6222
 
              thd->convert_string(&$$, thd->variables.collation_connection,
6223
 
                                  $1.str, $1.length, thd->charset());
 
5498
            $$= $1;
6224
5499
          }
6225
5500
        ;
6226
5501
 
6227
5502
TEXT_STRING_filesystem:
6228
5503
          TEXT_STRING
6229
5504
          {
6230
 
            THD *thd= YYTHD;
6231
 
 
6232
 
            if (thd->charset_is_character_set_filesystem)
6233
 
              $$= $1;
6234
 
            else
6235
 
              thd->convert_string(&$$, thd->variables.character_set_filesystem,
6236
 
                                  $1.str, $1.length, thd->charset());
 
5505
            $$= $1;
6237
5506
          }
6238
5507
        ;
6239
5508
 
6241
5510
          IDENT_sys    { $$=$1; }
6242
5511
        | keyword
6243
5512
          {
6244
 
            THD *thd= YYTHD;
6245
 
            $$.str= thd->strmake($1.str, $1.length);
 
5513
            Session *session= YYSession;
 
5514
            $$.str= session->strmake($1.str, $1.length);
6246
5515
            $$.length= $1.length;
6247
5516
          }
6248
5517
        ;
6256
5525
/* Keyword that we allow for identifiers (except SP labels) */
6257
5526
keyword:
6258
5527
          keyword_sp            {}
6259
 
        | ASCII_SYM             {}
6260
5528
        | BEGIN_SYM             {}
6261
5529
        | BYTE_SYM              {}
6262
5530
        | CACHE_SYM             {}
6269
5537
        | DEALLOCATE_SYM        {}
6270
5538
        | END                   {}
6271
5539
        | FLUSH_SYM             {}
6272
 
        | HANDLER_SYM           {}
6273
5540
        | HOST_SYM              {}
6274
5541
        | INSTALL_SYM           {}
6275
5542
        | NO_SYM                {}
6277
5544
        | OPTIONS_SYM           {}
6278
5545
        | PORT_SYM              {}
6279
5546
        | REMOVE_SYM            {}
6280
 
        | REPAIR                {}
6281
5547
        | RESET_SYM             {}
6282
5548
        | ROLLBACK_SYM          {}
6283
5549
        | SAVEPOINT_SYM         {}
6284
5550
        | SECURITY_SYM          {}
6285
5551
        | SERVER_SYM            {}
6286
 
        | SIGNED_SYM            {}
6287
5552
        | SOCKET_SYM            {}
6288
 
        | SLAVE                 {}
6289
5553
        | SONAME_SYM            {}
6290
5554
        | START_SYM             {}
6291
5555
        | STOP_SYM              {}
6292
5556
        | TRUNCATE_SYM          {}
6293
 
        | UNICODE_SYM           {}
6294
 
        | UNINSTALL_SYM         {}
6295
 
        | WRAPPER_SYM           {}
6296
 
        | UPGRADE_SYM           {}
6297
5557
        ;
6298
5558
 
6299
5559
/*
6307
5567
        | ADDDATE_SYM              {}
6308
5568
        | AFTER_SYM                {}
6309
5569
        | AGGREGATE_SYM            {}
6310
 
        | ALGORITHM_SYM            {}
6311
5570
        | ANY_SYM                  {}
6312
5571
        | AT_SYM                   {}
6313
 
        | AUTHORS_SYM              {}
6314
5572
        | AUTO_INC                 {}
6315
 
        | AUTOEXTEND_SIZE_SYM      {}
6316
5573
        | AVG_ROW_LENGTH           {}
6317
5574
        | AVG_SYM                  {}
6318
5575
        | BINLOG_SYM               {}
6340
5597
        | CUBE_SYM                 {}
6341
5598
        | DATA_SYM                 {}
6342
5599
        | DATAFILE_SYM             {}
6343
 
        | DATETIME                 {}
 
5600
        | DATETIME_SYM             {}
6344
5601
        | DATE_SYM                 {}
6345
5602
        | DAY_SYM                  {}
6346
 
        | DELAY_KEY_WRITE_SYM      {}
6347
 
        | DIRECTORY_SYM            {}
6348
5603
        | DISABLE_SYM              {}
6349
5604
        | DISCARD                  {}
6350
5605
        | DUMPFILE                 {}
6351
5606
        | DUPLICATE_SYM            {}
6352
5607
        | DYNAMIC_SYM              {}
6353
5608
        | ENDS_SYM                 {}
6354
 
        | ENUM                     {}
 
5609
        | ENUM_SYM                 {}
6355
5610
        | ENGINE_SYM               {}
6356
5611
        | ERRORS                   {}
6357
5612
        | ESCAPE_SYM               {}
6358
 
        | EVENTS_SYM               {}
6359
5613
        | EXCLUSIVE_SYM            {}
6360
5614
        | EXTENDED_SYM             {}
6361
5615
        | EXTENT_SIZE_SYM          {}
6362
 
        | FAULTS_SYM               {}
6363
5616
        | FAST_SYM                 {}
6364
5617
        | FOUND_SYM                {}
6365
5618
        | ENABLE_SYM               {}
6368
5621
        | FIRST_SYM                {}
6369
5622
        | FIXED_SYM                {}
6370
5623
        | FRAC_SECOND_SYM          {}
6371
 
        | GET_FORMAT               {}
6372
5624
        | GLOBAL_SYM               {}
6373
5625
        | HASH_SYM                 {}
6374
5626
        | HOSTS_SYM                {}
6376
5628
        | IDENTIFIED_SYM           {}
6377
5629
        | IMPORT                   {}
6378
5630
        | INDEXES                  {}
6379
 
        | INITIAL_SIZE_SYM         {}
6380
5631
        | ISOLATION                {}
6381
5632
        | INSERT_METHOD            {}
6382
5633
        | KEY_BLOCK_SIZE           {}
6383
5634
        | LAST_SYM                 {}
6384
 
        | LEAVES                   {}
6385
5635
        | LEVEL_SYM                {}
6386
 
        | LINESTRING               {}
6387
5636
        | LIST_SYM                 {}
6388
5637
        | LOCAL_SYM                {}
6389
5638
        | LOCKS_SYM                {}
6390
 
        | LOGFILE_SYM              {}
6391
5639
        | LOGS_SYM                 {}
6392
5640
        | MAX_ROWS                 {}
6393
 
        | MASTER_SYM               {}
6394
 
        | MASTER_HOST_SYM          {}
6395
 
        | MASTER_PORT_SYM          {}
6396
 
        | MASTER_LOG_FILE_SYM      {}
6397
 
        | MASTER_LOG_POS_SYM       {}
6398
 
        | MASTER_USER_SYM          {}
6399
 
        | MASTER_PASSWORD_SYM      {}
6400
 
        | MASTER_SERVER_ID_SYM     {}
6401
 
        | MASTER_CONNECT_RETRY_SYM {}
6402
 
        | MAX_CONNECTIONS_PER_HOUR {}
6403
 
        | MAX_QUERIES_PER_HOUR     {}
6404
5641
        | MAX_SIZE_SYM             {}
6405
 
        | MAX_UPDATES_PER_HOUR     {}
6406
 
        | MAX_USER_CONNECTIONS_SYM {}
6407
5642
        | MAX_VALUE_SYM            {}
6408
5643
        | MEDIUM_SYM               {}
6409
5644
        | MERGE_SYM                {}
6428
5663
        | ONE_SHOT_SYM             {}
6429
5664
        | ONE_SYM                  {}
6430
5665
        | ONLINE_SYM               {}
6431
 
        | PACK_KEYS_SYM            {}
6432
5666
        | PAGE_SYM                 {}
6433
 
        | PAGE_CHECKSUM_SYM        {}
6434
5667
        | PARTIAL                  {}
6435
5668
        | PHASE_SYM                {}
6436
 
        | PLUGIN_SYM               {}
6437
 
        | PLUGINS_SYM              {}
6438
5669
        | POINT_SYM                {}
6439
5670
        | PREV_SYM                 {}
6440
5671
        | PROCESS                  {}
6448
5679
        | REDO_BUFFER_SIZE_SYM     {}
6449
5680
        | REDOFILE_SYM             {}
6450
5681
        | REDUNDANT_SYM            {}
6451
 
        | RELAY_LOG_FILE_SYM       {}
6452
 
        | RELAY_LOG_POS_SYM        {}
6453
 
        | RELAY_THREAD             {}
6454
5682
        | RELOAD                   {}
6455
5683
        | REORGANIZE_SYM           {}
6456
5684
        | REPEATABLE_SYM           {}
6474
5702
        | SNAPSHOT_SYM             {}
6475
5703
        | SOURCE_SYM               {}
6476
5704
        | SQL_BUFFER_RESULT        {}
6477
 
        | SQL_THREAD               {}
6478
5705
        | STARTS_SYM               {}
6479
5706
        | STATUS_SYM               {}
6480
5707
        | STORAGE_SYM              {}
6481
5708
        | STRING_SYM               {}
6482
5709
        | SUBDATE_SYM              {}
6483
5710
        | SUBJECT_SYM              {}
6484
 
        | SUPER_SYM                {}
6485
5711
        | SUSPEND_SYM              {}
6486
5712
        | SWAPS_SYM                {}
6487
5713
        | SWITCHES_SYM             {}
6488
5714
        | TABLES                   {}
6489
 
        | TABLE_CHECKSUM_SYM       {}
6490
5715
        | TABLESPACE               {}
6491
 
        | TEMPORARY                {}
 
5716
        | TEMPORARY_SYM            {}
6492
5717
        | TEMPTABLE_SYM            {}
6493
5718
        | TEXT_SYM                 {}
6494
5719
        | THAN_SYM                 {}
6495
5720
        | TRANSACTION_SYM          {}
6496
 
        | TRANSACTIONAL_SYM        {}
6497
 
        | TIMESTAMP                {}
 
5721
        | TIMESTAMP_SYM            {}
6498
5722
        | TIMESTAMP_ADD            {}
6499
5723
        | TIMESTAMP_DIFF           {}
6500
 
        | TIME_SYM                 {}
6501
5724
        | TYPES_SYM                {}
6502
5725
        | TYPE_SYM                 {}
6503
5726
        | UNCOMMITTED_SYM          {}
6506
5729
        | UNKNOWN_SYM              {}
6507
5730
        | UNTIL_SYM                {}
6508
5731
        | USER                     {}
6509
 
        | USE_FRM                  {}
6510
5732
        | VARIABLES                {}
6511
5733
        | VALUE_SYM                {}
6512
5734
        | WARNINGS                 {}
6524
5746
          {
6525
5747
            LEX *lex=Lex;
6526
5748
            lex->sql_command= SQLCOM_SET_OPTION;
 
5749
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
5750
            lex->statement= statement;
 
5751
            if (lex->statement == NULL)
 
5752
              DRIZZLE_YYABORT;
6527
5753
            mysql_init_select(lex);
6528
5754
            lex->option_type=OPT_SESSION;
6529
5755
            lex->var_list.empty();
6530
 
            lex->one_shot_set= 0;
6531
 
            lex->autocommit= 0;
6532
5756
          }
6533
5757
          option_value_list
6534
5758
          {}
6561
5785
 
6562
5786
option_type2:
6563
5787
          /* empty */ { $$= OPT_DEFAULT; }
6564
 
        | ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
 
5788
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
6565
5789
        ;
6566
5790
 
6567
5791
opt_var_type:
6601
5825
            LEX *lex=Lex;
6602
5826
            lex->option_type= $1;
6603
5827
            lex->var_list.push_back(new set_var(lex->option_type,
6604
 
                                                find_sys_var(YYTHD, "tx_isolation"),
 
5828
                                                find_sys_var(YYSession, "tx_isolation"),
6605
5829
                                                &null_lex_str,
6606
5830
                                                new Item_int((int32_t) $5)));
6607
5831
          }
6617
5841
            LEX *lex=Lex;
6618
5842
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6619
5843
          }
6620
 
        | charset old_or_new_charset_name_or_default
6621
 
          {
6622
 
            THD *thd= YYTHD;
6623
 
            LEX *lex= thd->lex;
6624
 
            $2= $2 ? $2: global_system_variables.character_set_client;
6625
 
            lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
6626
 
          }
6627
 
        | NAMES_SYM charset_name_or_default opt_collate
6628
 
          {
6629
 
            LEX *lex= Lex;
6630
 
            $2= $2 ? $2 : global_system_variables.character_set_client;
6631
 
            $3= $3 ? $3 : $2;
6632
 
            if (!my_charset_same($2,$3))
6633
 
            {
6634
 
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
6635
 
                       $3->name, $2->csname);
6636
 
              DRIZZLE_YYABORT;
6637
 
            }
6638
 
            lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
6639
 
          }
6640
5844
        ;
6641
5845
 
6642
5846
internal_variable_name:
6643
5847
          ident
6644
5848
          {
6645
 
            THD *thd= YYTHD;
 
5849
            Session *session= YYSession;
6646
5850
 
6647
5851
            /* We have to lookup here since local vars can shadow sysvars */
6648
5852
            {
6649
5853
              /* Not an SP local variable */
6650
 
              sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
 
5854
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
6651
5855
              if (!tmp)
6652
5856
                DRIZZLE_YYABORT;
6653
5857
              $$.var= tmp;
6654
5858
              $$.base_name= null_lex_str;
6655
5859
            }
6656
5860
          }
6657
 
        | ident '.' ident
6658
 
          {
6659
 
            if (check_reserved_words(&$1))
6660
 
            {
6661
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
6662
 
              DRIZZLE_YYABORT;
6663
 
            }
6664
 
            {
6665
 
              sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
6666
 
              if (!tmp)
6667
 
                DRIZZLE_YYABORT;
6668
 
              if (!tmp->is_struct())
6669
 
                my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
6670
 
              $$.var= tmp;
6671
 
              $$.base_name= $1;
6672
 
            }
6673
 
          }
6674
 
        | DEFAULT '.' ident
6675
 
          {
6676
 
            sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
6677
 
            if (!tmp)
6678
 
              DRIZZLE_YYABORT;
6679
 
            if (!tmp->is_struct())
6680
 
              my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
6681
 
            $$.var= tmp;
6682
 
            $$.base_name.str=    (char*) "default";
6683
 
            $$.base_name.length= 7;
6684
 
          }
6685
5861
        ;
6686
5862
 
6687
5863
isolation_types:
6699
5875
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
6700
5876
        ;
6701
5877
 
6702
 
/* Lock function */
6703
 
 
6704
 
lock:
6705
 
          LOCK_SYM
6706
 
          {
6707
 
            /*
6708
 
              Transactional locks can be taken only if all requested locks
6709
 
              are transactional. Initialize lex->lock_transactional as
6710
 
              TRUE. Any non-transactional lock request turns this to FALSE.
6711
 
              Table specific variables keep track of the locking method
6712
 
              requested for the table. This is used to warn about a
6713
 
              changed locking method later.
6714
 
            */
6715
 
            Lex->lock_transactional= true;
6716
 
          }
6717
 
          table_or_tables
6718
 
          {
6719
 
            LEX *lex= Lex;
6720
 
            lex->sql_command= SQLCOM_LOCK_TABLES;
6721
 
          }
6722
 
          table_lock_list
6723
 
          {}
6724
 
        ;
6725
 
 
6726
5878
table_or_tables:
6727
5879
          TABLE_SYM
6728
5880
        | TABLES
6729
5881
        ;
6730
5882
 
6731
 
table_lock_list:
6732
 
          table_lock
6733
 
        | table_lock_list ',' table_lock
6734
 
        ;
6735
 
 
6736
 
table_lock:
6737
 
        table_ident opt_table_alias table_lock_info
6738
 
        {
6739
 
          TABLE_LIST *tlist;
6740
 
          if (!(tlist= Select->add_table_to_list(YYTHD, $1, $2, 0,
6741
 
                                                 $3.lock_type)))
6742
 
            DRIZZLE_YYABORT; /* purecov: inspected */
6743
 
          tlist->lock_timeout= $3.lock_timeout;
6744
 
          /* Store the requested lock method for later warning. */
6745
 
          tlist->lock_transactional= $3.lock_transactional;
6746
 
          /* Compute the resulting lock method for all tables. */
6747
 
          if (!$3.lock_transactional)
6748
 
            Lex->lock_transactional= false;
6749
 
        }
6750
 
        ;
6751
 
 
6752
 
table_lock_info:
6753
 
        READ_SYM
6754
 
        {
6755
 
          $$.lock_type=          TL_READ_NO_INSERT;
6756
 
          $$.lock_timeout=       -1;
6757
 
          $$.lock_transactional= false;
6758
 
        }
6759
 
        | WRITE_SYM
6760
 
        {
6761
 
          $$.lock_type=          TL_WRITE_DEFAULT;
6762
 
          $$.lock_timeout=       -1;
6763
 
          $$.lock_transactional= false;
6764
 
        }
6765
 
        | LOW_PRIORITY WRITE_SYM
6766
 
        {
6767
 
          $$.lock_type=          TL_WRITE_LOW_PRIORITY;
6768
 
          $$.lock_timeout=       -1;
6769
 
          $$.lock_transactional= false;
6770
 
        }
6771
 
        | READ_SYM LOCAL_SYM
6772
 
        {
6773
 
          $$.lock_type=          TL_READ;
6774
 
          $$.lock_timeout=       -1;
6775
 
          $$.lock_transactional= false;
6776
 
        }
6777
 
        | IN_SYM transactional_lock_mode MODE_SYM opt_transactional_lock_timeout
6778
 
        {
6779
 
          $$.lock_type=          $2;
6780
 
          $$.lock_timeout=       $4;
6781
 
          $$.lock_transactional= true;
6782
 
        }
6783
 
        ;
6784
 
 
6785
 
/* Use thr_lock_type here for easier fallback to non-trans locking. */
6786
 
transactional_lock_mode:
6787
 
        SHARE_SYM       { $$= TL_READ_NO_INSERT; }
6788
 
        | EXCLUSIVE_SYM { $$= TL_WRITE_DEFAULT; }
6789
 
        ;
6790
 
 
6791
 
opt_transactional_lock_timeout:
6792
 
        /* empty */     { $$= -1; }
6793
 
        | NOWAIT_SYM    { $$= 0; }
6794
 
        /* | WAIT_SYM opt_lock_timeout_value { $$= $2; } */
6795
 
        ;
6796
 
 
6797
 
/*
6798
 
  We have a timeout resolution of milliseconds. The WAIT argument is in
6799
 
  seconds with decimal fragments for sub-second resolution. E.g. 22.5, 0.015
6800
 
*/
6801
 
/* opt_lock_timeout_value: */
6802
 
        /* empty { $$= -1; } */
6803
 
        /* | NUM       { $$= (int) (atof($1.str) * 1000.0 + 0.5); } */
6804
 
 
6805
5883
unlock:
6806
5884
          UNLOCK_SYM
6807
5885
          {
6808
5886
            LEX *lex= Lex;
6809
5887
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
5888
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
5889
            if (lex->statement == NULL)
 
5890
              DRIZZLE_YYABORT;
6810
5891
          }
6811
5892
          table_or_tables
6812
5893
          {}
6817
5898
          {
6818
5899
            LEX *lex=Lex;
6819
5900
            lex->sql_command = SQLCOM_BEGIN;
6820
 
            lex->start_transaction_opt= 0;
 
5901
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
5902
            if (lex->statement == NULL)
 
5903
              DRIZZLE_YYABORT;
6821
5904
          }
6822
5905
          opt_work {}
6823
5906
        ;
6829
5912
 
6830
5913
opt_chain:
6831
5914
          /* empty */
6832
 
          { $$= (YYTHD->variables.completion_type == 1); }
 
5915
          { $$= (YYSession->variables.completion_type == 1); }
6833
5916
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
6834
5917
        | AND_SYM CHAIN_SYM        { $$=1; }
6835
5918
        ;
6836
5919
 
6837
5920
opt_release:
6838
5921
          /* empty */
6839
 
          { $$= (YYTHD->variables.completion_type == 2); }
 
5922
          { $$= (YYSession->variables.completion_type == 2); }
6840
5923
        | RELEASE_SYM        { $$=1; }
6841
5924
        | NO_SYM RELEASE_SYM { $$=0; }
6842
5925
;
6851
5934
          {
6852
5935
            LEX *lex=Lex;
6853
5936
            lex->sql_command= SQLCOM_COMMIT;
6854
 
            lex->tx_chain= $3; 
6855
 
            lex->tx_release= $4;
 
5937
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
5938
            lex->statement= statement;
 
5939
            if (lex->statement == NULL)
 
5940
              DRIZZLE_YYABORT;
 
5941
            statement->tx_chain= $3; 
 
5942
            statement->tx_release= $4;
6856
5943
          }
6857
5944
        ;
6858
5945
 
6861
5948
          {
6862
5949
            LEX *lex=Lex;
6863
5950
            lex->sql_command= SQLCOM_ROLLBACK;
6864
 
            lex->tx_chain= $3; 
6865
 
            lex->tx_release= $4;
 
5951
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
5952
            lex->statement= statement;
 
5953
            if (lex->statement == NULL)
 
5954
              DRIZZLE_YYABORT;
 
5955
            statement->tx_chain= $3; 
 
5956
            statement->tx_release= $4;
6866
5957
          }
6867
5958
        | ROLLBACK_SYM opt_work
6868
5959
          TO_SYM opt_savepoint ident
6869
5960
          {
6870
5961
            LEX *lex=Lex;
6871
5962
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
5963
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
5964
            if (lex->statement == NULL)
 
5965
              DRIZZLE_YYABORT;
6872
5966
            lex->ident= $5;
6873
5967
          }
6874
5968
        ;
6878
5972
          {
6879
5973
            LEX *lex=Lex;
6880
5974
            lex->sql_command= SQLCOM_SAVEPOINT;
 
5975
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
5976
            if (lex->statement == NULL)
 
5977
              DRIZZLE_YYABORT;
6881
5978
            lex->ident= $2;
6882
5979
          }
6883
5980
        ;
6887
5984
          {
6888
5985
            LEX *lex=Lex;
6889
5986
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
5987
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
5988
            if (lex->statement == NULL)
 
5989
              DRIZZLE_YYABORT;
6890
5990
            lex->ident= $3;
6891
5991
          }
6892
5992
        ;
6925
6025
 
6926
6026
union_order_or_limit:
6927
6027
          {
6928
 
            THD *thd= YYTHD;
6929
 
            LEX *lex= thd->lex;
 
6028
            Session *session= YYSession;
 
6029
            LEX *lex= session->lex;
6930
6030
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6931
 
            SELECT_LEX *sel= lex->current_select;
6932
 
            SELECT_LEX_UNIT *unit= sel->master_unit();
6933
 
            SELECT_LEX *fake= unit->fake_select_lex;
 
6031
            Select_Lex *sel= lex->current_select;
 
6032
            Select_Lex_Unit *unit= sel->master_unit();
 
6033
            Select_Lex *fake= unit->fake_select_lex;
6934
6034
            if (fake)
6935
6035
            {
6936
6036
              unit->global_parameters= fake;
6937
6037
              fake->no_table_names_allowed= 1;
6938
6038
              lex->current_select= fake;
6939
6039
            }
6940
 
            thd->where= "global ORDER clause";
 
6040
            session->where= "global ORDER clause";
6941
6041
          }
6942
6042
          order_or_limit
6943
6043
          {
6944
 
            THD *thd= YYTHD;
6945
 
            thd->lex->current_select->no_table_names_allowed= 0;
6946
 
            thd->where= "";
 
6044
            Session *session= YYSession;
 
6045
            session->lex->current_select->no_table_names_allowed= 0;
 
6046
            session->where= "";
6947
6047
          }
6948
6048
        ;
6949
6049
 
6995
6095
subselect_start:
6996
6096
          {
6997
6097
            LEX *lex=Lex;
6998
 
            if (!lex->expr_allows_subselect ||
6999
 
               lex->sql_command == (int)SQLCOM_PURGE)
 
6098
            if (!lex->expr_allows_subselect)
7000
6099
            {
7001
6100
              my_parse_error(ER(ER_SYNTAX_ERROR));
7002
6101
              DRIZZLE_YYABORT;
7017
6116
          {
7018
6117
            LEX *lex=Lex;
7019
6118
            lex->pop_context();
7020
 
            SELECT_LEX *child= lex->current_select;
 
6119
            Select_Lex *child= lex->current_select;
7021
6120
            lex->current_select = lex->current_select->return_after_parsing();
7022
6121
            lex->nest_level--;
7023
6122
            lex->current_select->n_child_sum_items += child->n_sum_items;