~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-07-11 19:23:04 UTC
  • mfrom: (1089.1.14 merge)
  • Revision ID: brian@gaz-20090711192304-ootijyl5yf9jq9kd
Merge Brian

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 ((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)
 
38
#define Lex (YYSession->lex)
39
39
#define Select Lex->current_select
40
40
#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);
 
41
#include <drizzled/lex_symbol.h>
 
42
#include <drizzled/function/locate.h>
 
43
#include <drizzled/function/str/char.h>
 
44
#include <drizzled/function/str/collation.h>
 
45
#include <drizzled/function/str/database.h>
 
46
#include <drizzled/function/str/insert.h>
 
47
#include <drizzled/function/str/left.h>
 
48
#include <drizzled/function/str/repeat.h>
 
49
#include <drizzled/function/str/replace.h>
 
50
#include <drizzled/function/str/reverse.h>
 
51
#include <drizzled/function/str/right.h>
 
52
#include <drizzled/function/str/set_collation.h>
 
53
#include <drizzled/function/str/substr.h>
 
54
#include <drizzled/function/str/trim.h>
 
55
#include <drizzled/function/str/user.h>
 
56
#include <drizzled/function/str/weight_string.h>
 
57
 
 
58
#include <drizzled/function/time/curdate.h>
 
59
#include <drizzled/function/time/date_add_interval.h>
 
60
#include <drizzled/function/time/dayofmonth.h>
 
61
#include <drizzled/function/time/extract.h>
 
62
#include <drizzled/function/time/hour.h>
 
63
#include <drizzled/function/time/microsecond.h>
 
64
#include <drizzled/function/time/minute.h>
 
65
#include <drizzled/function/time/month.h>
 
66
#include <drizzled/function/time/now.h>
 
67
#include <drizzled/function/time/quarter.h>
 
68
#include <drizzled/function/time/second.h>
 
69
#include <drizzled/function/time/sysdate_local.h>
 
70
#include <drizzled/function/time/timestamp_diff.h>
 
71
#include <drizzled/function/time/typecast.h>
 
72
#include <drizzled/function/time/year.h>
 
73
 
 
74
#include <drizzled/error.h>
 
75
#include <drizzled/nested_join.h>
 
76
#include <drizzled/sql_parse.h>
 
77
#include <drizzled/item/copy_string.h>
 
78
#include <drizzled/item/cmpfunc.h>
 
79
#include <drizzled/item/uint.h>
 
80
#include <drizzled/item/null.h>
 
81
#include <drizzled/session.h>
 
82
#include <drizzled/item/func.h>
 
83
#include <drizzled/sql_base.h>
 
84
#include <drizzled/item/create.h>
 
85
#include <drizzled/item/default_value.h>
 
86
#include <drizzled/item/insert_value.h>
 
87
#include <drizzled/lex_string.h>
 
88
#include <drizzled/function/get_system_var.h>
 
89
#include <mysys/thr_lock.h>
 
90
#include <drizzled/message/table.pb.h>
 
91
 
 
92
class Table_ident;
 
93
class Item;
 
94
class Item_num;
 
95
 
 
96
int yylex(void *yylval, void *yysession);
46
97
 
47
98
#define yyoverflow(A,B,C,D,E,F)               \
48
99
  {                                           \
61
112
#define DRIZZLE_YYABORT                         \
62
113
  do                                          \
63
114
  {                                           \
64
 
    LEX::cleanup_lex_after_parse_error(YYTHD);\
 
115
    LEX::cleanup_lex_after_parse_error(YYSession);\
65
116
    YYABORT;                                  \
66
117
  } while (0)
67
118
 
72
123
    DRIZZLE_YYABORT;                      \
73
124
  }
74
125
 
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
126
 
97
127
#define YYDEBUG 0
98
128
 
107
137
  parser.
108
138
*/
109
139
 
110
 
void my_parse_error(const char *s)
 
140
static void my_parse_error(const char *s)
111
141
{
112
 
  THD *thd= current_thd;
113
 
  Lex_input_stream *lip= thd->m_lip;
 
142
  Session *session= current_session;
 
143
  Lex_input_stream *lip= session->m_lip;
114
144
 
115
145
  const char *yytext= lip->get_tok_start();
116
146
  /* Push an error into the error stack */
139
169
  to abort from the parser.
140
170
*/
141
171
 
142
 
void MYSQLerror(const char *s)
 
172
static void DRIZZLEerror(const char *s)
143
173
{
144
 
  THD *thd= current_thd;
 
174
  Session *session= current_session;
145
175
 
146
176
  /*
147
177
    Restore the original LEX if it was replaced when parsing
148
178
    a stored procedure. We must ensure that a parsing error
149
 
    does not leave any side effects in the THD.
 
179
    does not leave any side effects in the Session.
150
180
  */
151
 
  LEX::cleanup_lex_after_parse_error(thd);
 
181
  LEX::cleanup_lex_after_parse_error(session);
152
182
 
153
183
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
154
184
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
161
191
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
162
192
  This function returns the proper item for the SQL expression
163
193
  <code>left [NOT] IN ( expr )</code>
164
 
  @param thd the current thread
 
194
  @param session the current thread
165
195
  @param left the in predicand
166
196
  @param equal true for IN predicates, false for NOT IN predicates
167
197
  @param expr first and only expression of the in value list
168
198
  @return an expression representing the IN predicate.
169
199
*/
170
 
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
171
 
                                       Item *expr)
 
200
static Item* handle_sql2003_note184_exception(Session *session,
 
201
                                              Item* left, bool equal,
 
202
                                              Item *expr)
172
203
{
173
204
  /*
174
205
    Relevant references for this issue:
201
232
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
202
233
    {
203
234
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
204
 
      st_select_lex *subselect;
 
235
      Select_Lex *subselect;
205
236
 
206
237
      /*
207
238
        Implement the mandated change, by altering the semantic tree:
212
243
          Item_in_subselect(left, subselect)
213
244
      */
214
245
      subselect= expr3->invalidate_and_restore_select_lex();
215
 
      result= new (thd->mem_root) Item_in_subselect(left, subselect);
 
246
      result= new (session->mem_root) Item_in_subselect(left, subselect);
216
247
 
217
248
      if (! equal)
218
 
        result = negate_expression(thd, result);
 
249
        result = negate_expression(session, result);
219
250
 
220
251
      return(result);
221
252
    }
222
253
  }
223
254
 
224
255
  if (equal)
225
 
    result= new (thd->mem_root) Item_func_eq(left, expr);
 
256
    result= new (session->mem_root) Item_func_eq(left, expr);
226
257
  else
227
 
    result= new (thd->mem_root) Item_func_ne(left, expr);
 
258
    result= new (session->mem_root) Item_func_ne(left, expr);
228
259
 
229
260
  return(result);
230
261
}
231
262
 
232
263
/**
233
 
   @brief Creates a new SELECT_LEX for a UNION branch.
 
264
   @brief Creates a new Select_Lex for a UNION branch.
234
265
 
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..=
 
266
   Sets up and initializes a Select_Lex structure for a query once the parser
 
267
   discovers a UNION token. The current Select_Lex is pushed on the stack and
 
268
   the new Select_Lex becomes the current one..=
238
269
 
239
270
   @lex The parser state.
240
271
 
244
275
   @return <code>false</code> if successful, <code>true</code> if an error was
245
276
   reported. In the latter case parsing should stop.
246
277
 */
247
 
bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
278
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
248
279
{
249
280
  if (lex->result)
250
281
  {
270
301
}
271
302
 
272
303
/**
273
 
   @brief Initializes a SELECT_LEX for a query within parentheses (aka
 
304
   @brief Initializes a Select_Lex for a query within parentheses (aka
274
305
   braces).
275
306
 
276
307
   @return false if successful, true if an error was reported. In the latter
277
308
   case parsing should stop.
278
309
 */
279
 
bool setup_select_in_parentheses(LEX *lex) 
 
310
static bool setup_select_in_parentheses(LEX *lex) 
280
311
{
281
 
  SELECT_LEX * sel= lex->current_select;
 
312
  Select_Lex * sel= lex->current_select;
282
313
  if (sel->set_braces(1))
283
314
  {
284
315
    my_parse_error(ER(ER_SYNTAX_ERROR));
323
354
  List<String> *string_list;
324
355
  String *string;
325
356
  Key_part_spec *key_part;
326
 
  TABLE_LIST *table_list;
327
 
  udf_func *udf;
328
 
  LEX_USER *lex_user;
 
357
  Function_builder *udf;
 
358
  TableList *table_list;
329
359
  struct sys_var_with_base variable;
330
360
  enum enum_var_type var_type;
331
361
  Key::Keytype key_type;
332
362
  enum ha_key_alg key_alg;
333
 
  handlerton *db_type;
 
363
  StorageEngine *db_type;
334
364
  enum row_type row_type;
335
365
  enum column_format_type column_format_type;
336
366
  enum ha_rkey_function ha_rkey_mode;
339
369
  enum ha_choice choice;
340
370
  const CHARSET_INFO *charset;
341
371
  thr_lock_type lock_type;
342
 
  struct st_table_lock_info table_lock_info;
343
372
  interval_type interval, interval_time_st;
344
 
  timestamp_type date_time_type;
345
 
  st_select_lex *select_lex;
 
373
  enum enum_drizzle_timestamp_type date_time_type;
 
374
  Select_Lex *select_lex;
346
375
  chooser_compare_func_creator boolfunc2creator;
347
 
  struct sp_cond_type *spcondtype;
348
 
  struct { int vars, conds, hndlrs, curs; } spblock;
349
376
  struct st_lex *lex;
350
377
  struct p_elem_val *p_elem_value;
351
378
  enum index_hint_type index_hint;
360
387
 
361
388
%pure_parser                                    /* We have threads */
362
389
/*
363
 
  Currently there are 100 shift/reduce conflicts.
 
390
  Currently there are 90 shift/reduce conflicts.
364
391
  We should not introduce new conflicts any more.
365
392
*/
366
 
%expect 95
 
393
%expect 90
367
394
 
368
395
/*
369
396
   Comments for TOKENS.
400
427
%token  ASCII_SYM                     /* MYSQL-FUNC */
401
428
%token  ASENSITIVE_SYM                /* FUTURE-USE */
402
429
%token  AT_SYM                        /* SQL-2003-R */
403
 
%token  AUTHORS_SYM
404
430
%token  AUTOEXTEND_SIZE_SYM
405
431
%token  AUTO_INC
406
432
%token  AVG_ROW_LENGTH
408
434
%token  BEFORE_SYM                    /* SQL-2003-N */
409
435
%token  BEGIN_SYM                     /* SQL-2003-R */
410
436
%token  BETWEEN_SYM                   /* SQL-2003-R */
411
 
%token  BIGINT                        /* SQL-2003-R */
 
437
%token  BIGINT_SYM                    /* SQL-2003-R */
412
438
%token  BINARY                        /* SQL-2003-R */
413
439
%token  BINLOG_SYM
414
440
%token  BIN_NUM
463
489
%token  CURDATE                       /* MYSQL-FUNC */
464
490
%token  CURRENT_USER                  /* SQL-2003-R */
465
491
%token  CURSOR_SYM                    /* SQL-2003-R */
466
 
%token  CURTIME                       /* MYSQL-FUNC */
467
492
%token  DATABASE
468
493
%token  DATABASES
469
494
%token  DATAFILE_SYM
470
495
%token  DATA_SYM                      /* SQL-2003-N */
471
 
%token  DATETIME
 
496
%token  DATETIME_SYM
472
497
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
473
498
%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
474
499
%token  DATE_SYM                      /* SQL-2003-R */
482
507
%token  DECIMAL_SYM                   /* SQL-2003-R */
483
508
%token  DECLARE_SYM                   /* SQL-2003-R */
484
509
%token  DEFAULT                       /* SQL-2003-R */
485
 
%token  DELAYED_SYM
486
510
%token  DELAY_KEY_WRITE_SYM
487
511
%token  DELETE_SYM                    /* SQL-2003-R */
488
512
%token  DESC                          /* SQL-2003-N */
507
531
%token  ENDS_SYM
508
532
%token  END_OF_INPUT                  /* INTERNAL */
509
533
%token  ENGINE_SYM
510
 
%token  ENUM
 
534
%token  ENUM_SYM
511
535
%token  EQ                            /* OPERATOR */
512
536
%token  EQUAL_SYM                     /* OPERATOR */
513
537
%token  ERRORS
514
538
%token  ESCAPED
515
539
%token  ESCAPE_SYM                    /* SQL-2003-R */
516
 
%token  EVENTS_SYM
517
540
%token  EXCLUSIVE_SYM
518
541
%token  EXISTS                        /* SQL-2003-R */
519
542
%token  EXIT_SYM
538
561
%token  FROM
539
562
%token  FULL                          /* SQL-2003-R */
540
563
%token  GE
541
 
%token  GET_FORMAT                    /* MYSQL-FUNC */
542
564
%token  GLOBAL_SYM                    /* SQL-2003-R */
543
565
%token  GROUP_SYM                     /* SQL-2003-R */
544
566
%token  GROUP_CONCAT_SYM
547
569
%token  HASH_SYM
548
570
%token  HAVING                        /* SQL-2003-R */
549
571
%token  HEX_NUM
550
 
%token  HIGH_PRIORITY
551
572
%token  HOST_SYM
552
573
%token  HOSTS_SYM
553
574
%token  HOUR_MICROSECOND_SYM
605
626
%token  LONG_NUM
606
627
%token  LONG_SYM
607
628
%token  LOOP_SYM
608
 
%token  LOW_PRIORITY
609
629
%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
630
%token  MATCH                         /* SQL-2003-R */
621
 
%token  MAX_CONNECTIONS_PER_HOUR
622
 
%token  MAX_QUERIES_PER_HOUR
623
631
%token  MAX_ROWS
624
632
%token  MAX_SIZE_SYM
625
633
%token  MAX_SYM                       /* SQL-2003-N */
626
 
%token  MAX_UPDATES_PER_HOUR
627
 
%token  MAX_USER_CONNECTIONS_SYM
628
634
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
629
635
%token  MEDIUM_SYM
630
636
%token  MERGE_SYM                     /* SQL-2003-R */
681
687
%token  PARAM_MARKER
682
688
%token  PARTIAL                       /* SQL-2003-N */
683
689
%token  PHASE_SYM
684
 
%token  PLUGINS_SYM
685
 
%token  PLUGIN_SYM
686
690
%token  POINT_SYM
687
691
%token  PORT_SYM
688
692
%token  POSITION_SYM                  /* SQL-2003-N */
707
711
%token  REDO_BUFFER_SIZE_SYM
708
712
%token  REDUNDANT_SYM
709
713
%token  REFERENCES                    /* SQL-2003-R */
710
 
%token  RELAY_LOG_FILE_SYM
711
 
%token  RELAY_LOG_POS_SYM
712
 
%token  RELAY_THREAD
713
714
%token  RELEASE_SYM                   /* SQL-2003-R */
714
715
%token  RELOAD
715
716
%token  REMOVE_SYM
716
717
%token  RENAME
717
718
%token  REORGANIZE_SYM
718
 
%token  REPAIR
719
719
%token  REPEATABLE_SYM                /* SQL-2003-N */
720
720
%token  REPEAT_SYM                    /* MYSQL-FUNC */
721
721
%token  REPLACE                       /* MYSQL-FUNC */
753
753
%token  SHARE_SYM
754
754
%token  SHOW
755
755
%token  SHUTDOWN
756
 
%token  SIGNED_SYM
757
756
%token  SIMPLE_SYM                    /* SQL-2003-N */
758
 
%token  SLAVE
759
 
%token  SMALLINT                      /* SQL-2003-R */
760
757
%token  SNAPSHOT_SYM
761
758
%token  SOCKET_SYM
762
759
%token  SONAME_SYM
770
767
%token  SQL_CALC_FOUND_ROWS
771
768
%token  SQL_SMALL_RESULT
772
769
%token  SQL_SYM                       /* SQL-2003-R */
773
 
%token  SQL_THREAD
774
770
%token  STARTING
775
771
%token  STARTS_SYM
776
772
%token  START_SYM                     /* SQL-2003-R */
779
775
%token  STD_SYM
780
776
%token  STOP_SYM
781
777
%token  STORAGE_SYM
 
778
%token  STORED_SYM
782
779
%token  STRAIGHT_JOIN
783
780
%token  STRING_SYM
784
781
%token  SUBDATE_SYM
795
792
%token  TABLE_REF_PRIORITY
796
793
%token  TABLE_SYM                     /* SQL-2003-R */
797
794
%token  TABLE_CHECKSUM_SYM
798
 
%token  TEMPORARY                     /* SQL-2003-N */
 
795
%token  TEMPORARY_SYM                 /* SQL-2003-N */
799
796
%token  TEMPTABLE_SYM
800
797
%token  TERMINATED
801
798
%token  TEXT_STRING
802
799
%token  TEXT_SYM
803
800
%token  THAN_SYM
804
801
%token  THEN_SYM                      /* SQL-2003-R */
805
 
%token  TIMESTAMP                     /* SQL-2003-R */
 
802
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
806
803
%token  TIMESTAMP_ADD
807
804
%token  TIMESTAMP_DIFF
808
 
%token  TIME_SYM                      /* SQL-2003-R */
809
 
%token  TINYINT
810
805
%token  TO_SYM                        /* SQL-2003-R */
811
806
%token  TRAILING                      /* SQL-2003-R */
812
807
%token  TRANSACTION_SYM
813
 
%token  TRANSACTIONAL_SYM
814
808
%token  TRIM                          /* SQL-2003-N */
815
809
%token  TRUE_SYM                      /* SQL-2003-R */
816
810
%token  TRUNCATE_SYM
819
813
%token  ULONGLONG_NUM
820
814
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
821
815
%token  UNDEFINED_SYM
822
 
%token  UNDERSCORE_CHARSET
823
816
%token  UNDOFILE_SYM
824
817
%token  UNDO_SYM                      /* FUTURE-USE */
825
 
%token  UNICODE_SYM
826
 
%token  UNINSTALL_SYM
827
818
%token  UNION_SYM                     /* SQL-2003-R */
828
819
%token  UNIQUE_SYM
829
820
%token  UNKNOWN_SYM                   /* SQL-2003-R */
830
821
%token  UNLOCK_SYM
831
 
%token  UNSIGNED
832
822
%token  UNTIL_SYM
833
823
%token  UPDATE_SYM                    /* SQL-2003-R */
834
 
%token  UPGRADE_SYM
835
824
%token  USAGE                         /* SQL-2003-N */
836
825
%token  USER                          /* SQL-2003-R */
837
826
%token  USE_FRM
839
828
%token  USING                         /* SQL-2003-R */
840
829
%token  UTC_DATE_SYM
841
830
%token  UTC_TIMESTAMP_SYM
842
 
%token  UTC_TIME_SYM
843
831
%token  VALUES                        /* SQL-2003-R */
844
832
%token  VALUE_SYM                     /* SQL-2003-R */
845
833
%token  VARBINARY
846
 
%token  VARCHAR                       /* SQL-2003-R */
 
834
%token  VARCHAR_SYM                   /* SQL-2003-R */
847
835
%token  VARIABLES
848
836
%token  VARIANCE_SYM
849
837
%token  VARYING                       /* SQL-2003-R */
850
838
%token  VAR_SAMP_SYM
 
839
%token  VIRTUAL_SYM
851
840
%token  WAIT_SYM
852
841
%token  WARNINGS
853
842
%token  WEEK_SYM
855
844
%token  WHEN_SYM                      /* SQL-2003-R */
856
845
%token  WHERE                         /* SQL-2003-R */
857
846
%token  WITH                          /* SQL-2003-R */
858
 
%token  WITH_CUBE_SYM                 /* INTERNAL */
859
847
%token  WITH_ROLLUP_SYM               /* INTERNAL */
860
848
%token  WORK_SYM                      /* SQL-2003-N */
861
 
%token  WRAPPER_SYM
862
849
%token  WRITE_SYM                     /* SQL-2003-N */
863
850
%token  XOR
864
851
%token  YEAR_MONTH_SYM
901
888
        text_string opt_gconcat_separator
902
889
 
903
890
%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
 
891
        type int_type real_type order_dir field_def
 
892
        if_exists opt_table_options table_options
 
893
        table_option opt_if_not_exists
907
894
        opt_temporary all_or_any opt_distinct
908
895
        union_option
909
896
        start_transaction_opts opt_chain opt_release
910
897
        union_opt select_derived_init option_type2
911
 
        opt_transactional_lock_timeout
912
 
        /* opt_lock_timeout_value */
913
898
 
914
899
%type <m_fk_option>
915
900
        delete_option
927
912
%type <choice> choice
928
913
 
929
914
%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
 
915
        load_data_lock
935
916
 
936
917
%type <item>
937
918
        literal text_literal insert_ident order_ident
975
956
        select_derived derived_table_list
976
957
        select_derived_union
977
958
 
978
 
%type <date_time_type> date_time_type;
979
959
%type <interval> interval
980
960
 
981
961
%type <interval_time_st> interval_time_st
995
975
%type <symbol> keyword keyword_sp
996
976
 
997
977
%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
978
        collation_name
1004
979
        collation_name_or_default
1005
 
        opt_load_data_charset
1006
 
        UNDERSCORE_CHARSET
1007
980
 
1008
981
%type <variable> internal_variable_name
1009
982
 
1016
989
%type <build_method> build_method
1017
990
 
1018
991
%type <NONE>
1019
 
        query verb_clause create change select drop insert replace insert2
 
992
        query verb_clause create select drop insert replace insert2
1020
993
        insert_values update delete truncate rename
1021
994
        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
 
995
        begin commit rollback savepoint release
 
996
        analyze check start checksum
1025
997
        field_list field_list_item field_spec kill column_def key_def
1026
998
        keycache_list assign_to_keycache
1027
999
        select_item_list select_item values_list no_braces
1028
1000
        opt_limit_clause delete_limit_clause fields opt_values values
1029
1001
        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
 
1002
        set unlock string_list
 
1003
        opt_binary
1032
1004
        ref_list opt_match_clause opt_on_update_delete use
1033
1005
        opt_delete_options opt_delete_option varchar
1034
1006
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
1040
1012
        table_to_table_list table_to_table opt_table_list opt_as
1041
1013
        single_multi table_wild_list table_wild_one opt_wild
1042
1014
        union_clause union_list
1043
 
        precision subselect_start charset
 
1015
        precision subselect_start
1044
1016
        subselect_end select_var_list select_var_list_init opt_len
1045
1017
        opt_extended_describe
1046
1018
        statement
1047
1019
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1048
 
        binlog_base64_event
1049
1020
        init_key_options key_options key_opts key_opt key_using_alg
1050
1021
END_OF_INPUT
1051
1022
 
1083
1054
query:
1084
1055
          END_OF_INPUT
1085
1056
          {
1086
 
            THD *thd= YYTHD;
1087
 
            if (!thd->bootstrap &&
1088
 
              (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
 
1057
            Session *session= YYSession;
 
1058
            if (!(session->lex->select_lex.options & OPTION_FOUND_COMMENT))
1089
1059
            {
1090
1060
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
1091
1061
              DRIZZLE_YYABORT;
1092
1062
            }
1093
1063
            else
1094
1064
            {
1095
 
              thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1065
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
1096
1066
            }
1097
1067
          }
1098
1068
        | verb_clause END_OF_INPUT {}
1107
1077
statement:
1108
1078
          alter
1109
1079
        | analyze
1110
 
        | binlog_base64_event
1111
 
        | change
1112
1080
        | check
1113
1081
        | checksum
1114
1082
        | commit
1120
1088
        | insert
1121
1089
        | kill
1122
1090
        | load
1123
 
        | lock
1124
1091
        | optimize
1125
1092
        | keycache
1126
 
        | purge
1127
1093
        | release
1128
1094
        | rename
1129
 
        | repair
1130
1095
        | replace
1131
 
        | reset
1132
1096
        | rollback
1133
1097
        | savepoint
1134
1098
        | select
1135
1099
        | set
1136
1100
        | show
1137
 
        | slave
1138
1101
        | start
1139
1102
        | truncate
1140
1103
        | unlock
1142
1105
        | use
1143
1106
        ;
1144
1107
 
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
1108
/* create a table */
1262
1109
 
1263
1110
create:
1264
1111
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1265
1112
          {
1266
 
            THD *thd= YYTHD;
1267
 
            LEX *lex= thd->lex;
 
1113
            Session *session= YYSession;
 
1114
            LEX *lex= session->lex;
1268
1115
            lex->sql_command= SQLCOM_CREATE_TABLE;
1269
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
1116
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1270
1117
                                                   TL_OPTION_UPDATING,
1271
1118
                                                   TL_WRITE))
1272
1119
              DRIZZLE_YYABORT;
1273
1120
            lex->alter_info.reset();
1274
1121
            lex->col_list.empty();
1275
 
            lex->change=NullS;
 
1122
            lex->change=NULL;
1276
1123
            memset(&lex->create_info, 0, sizeof(lex->create_info));
1277
1124
            lex->create_info.options=$2 | $4;
1278
 
            lex->create_info.db_type= ha_default_handlerton(thd);
 
1125
            lex->create_info.db_type= ha_default_storage_engine(session);
1279
1126
            lex->create_info.default_table_charset= NULL;
1280
1127
            lex->name.str= 0;
1281
 
            lex->name.length= 0;
 
1128
 
 
1129
            drizzled::message::Table *proto=
 
1130
              lex->create_table_proto= new drizzled::message::Table();
 
1131
            
 
1132
            proto->set_name($5->table.str);
 
1133
            if($2 & HA_LEX_CREATE_TMP_TABLE)
 
1134
              proto->set_type(drizzled::message::Table::TEMPORARY);
 
1135
            else
 
1136
              proto->set_type(drizzled::message::Table::STANDARD);
 
1137
 
 
1138
            {
 
1139
              drizzled::message::Table::StorageEngine *protoengine;
 
1140
              protoengine= proto->mutable_engine();
 
1141
              StorageEngine *engine= ha_default_storage_engine(session);
 
1142
 
 
1143
              protoengine->set_name(engine->getName());
 
1144
            }
1282
1145
          }
1283
1146
          create2
1284
1147
          {
1285
 
            LEX *lex= YYTHD->lex;
 
1148
            LEX *lex= YYSession->lex;
1286
1149
            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
 
            }
 
1150
            assert(lex->create_info.db_type);
1296
1151
          }
1297
1152
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
1298
1153
          ON table_ident
1299
1154
          {
1300
1155
            LEX *lex=Lex;
1301
1156
            lex->sql_command= SQLCOM_CREATE_INDEX;
1302
 
            if (!lex->current_select->add_table_to_list(lex->thd, $8,
 
1157
            if (!lex->current_select->add_table_to_list(lex->session, $8,
1303
1158
                                                        NULL,
1304
1159
                                                        TL_OPTION_UPDATING))
1305
1160
              DRIZZLE_YYABORT;
1306
1161
            lex->alter_info.reset();
1307
 
            lex->alter_info.flags= ALTER_ADD_INDEX;
 
1162
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1308
1163
            lex->alter_info.build_method= $2;
1309
1164
            lex->col_list.empty();
1310
 
            lex->change=NullS;
 
1165
            lex->change=NULL;
1311
1166
          }
1312
1167
          '(' key_list ')' key_options
1313
1168
          {
1338
1193
          create3 {}
1339
1194
        | LIKE table_ident
1340
1195
          {
1341
 
            THD *thd= YYTHD;
1342
 
            LEX *lex= thd->lex;
 
1196
            Session *session= YYSession;
 
1197
            LEX *lex= session->lex;
1343
1198
 
1344
1199
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1345
 
            if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
 
1200
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1346
1201
              DRIZZLE_YYABORT;
1347
1202
          }
1348
1203
        | '(' LIKE table_ident ')'
1349
1204
          {
1350
 
            THD *thd= YYTHD;
1351
 
            LEX *lex= thd->lex;
 
1205
            Session *session= YYSession;
 
1206
            LEX *lex= session->lex;
1352
1207
 
1353
1208
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1354
 
            if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
 
1209
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1355
1210
              DRIZZLE_YYABORT;
1356
1211
          }
1357
1212
        ;
1378
1233
          SELECT_SYM
1379
1234
          {
1380
1235
            LEX *lex=Lex;
1381
 
            lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
 
1236
            lex->lock_option= TL_READ;
1382
1237
            if (lex->sql_command == SQLCOM_INSERT)
1383
1238
              lex->sql_command= SQLCOM_INSERT_SELECT;
1384
1239
            else if (lex->sql_command == SQLCOM_REPLACE)
1422
1277
 
1423
1278
create_database_option:
1424
1279
          default_collation {}
1425
 
        | default_charset {}
1426
1280
        ;
1427
1281
 
1428
1282
opt_table_options:
1436
1290
        ;
1437
1291
 
1438
1292
table_option:
1439
 
          TEMPORARY { $$=HA_LEX_CREATE_TMP_TABLE; }
 
1293
          TEMPORARY_SYM { $$=HA_LEX_CREATE_TMP_TABLE; }
1440
1294
        ;
1441
1295
 
1442
1296
opt_if_not_exists:
1465
1319
          {
1466
1320
            Lex->create_info.db_type= $3;
1467
1321
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1322
 
 
1323
            {
 
1324
              drizzled::message::Table::StorageEngine *protoengine;
 
1325
              protoengine= Lex->create_table_proto->mutable_engine();
 
1326
 
 
1327
              protoengine->set_name($3->getName());
 
1328
            }
1468
1329
          }
1469
1330
        | MAX_ROWS opt_equal ulonglong_num
1470
1331
          {
1541
1402
          {
1542
1403
            Lex->create_info.row_type= $3;
1543
1404
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1544
 
            Lex->alter_info.flags|= ALTER_ROW_FORMAT;
 
1405
            Lex->alter_info.flags.set(ALTER_ROW_FORMAT);
1545
1406
          }
1546
 
        | default_charset
1547
1407
        | default_collation
1548
1408
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1549
1409
          {
1566
1426
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1567
1427
            Lex->create_info.key_block_size= $3;
1568
1428
          }
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
 
        ;
1575
 
 
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;
1591
 
          }
1592
1429
        ;
1593
1430
 
1594
1431
default_collation:
1611
1448
storage_engines:
1612
1449
          ident_or_text
1613
1450
          {
1614
 
            plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
 
1451
            StorageEngine *engine= ha_resolve_by_name(YYSession, &$1);
1615
1452
 
1616
 
            if (plugin)
1617
 
              $$= plugin_data(plugin, handlerton*);
 
1453
            if (engine)
 
1454
              $$= engine;
1618
1455
            else
1619
1456
            {
1620
1457
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1626
1463
known_storage_engines:
1627
1464
          ident_or_text
1628
1465
          {
1629
 
            plugin_ref plugin;
1630
 
            if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
1631
 
              $$= plugin_data(plugin, handlerton*);
 
1466
            StorageEngine *engine;
 
1467
            if ((engine= ha_resolve_by_name(YYSession, &$1)))
 
1468
              $$= engine;
1632
1469
            else
1633
1470
            {
1634
1471
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1709
1546
            lex->alter_info.key_list.push_back(key);
1710
1547
            lex->col_list.empty(); /* Alloced by sql_alloc */
1711
1548
            /* Only used for ALTER TABLE. Ignored otherwise. */
1712
 
            lex->alter_info.flags|= ALTER_FOREIGN_KEY;
 
1549
            lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
1713
1550
          }
1714
1551
        | constraint opt_check_constraint
1715
1552
          {
1750
1587
            lex->charset=NULL;
1751
1588
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1752
1589
          }
1753
 
          type opt_attribute
 
1590
          field_def
1754
1591
          {
1755
1592
            LEX *lex=Lex;
1756
 
            if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
 
1593
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1757
1594
                                  lex->length,lex->dec,lex->type,
1758
1595
                                  lex->column_format,
1759
1596
                                  lex->default_value, lex->on_update_value, 
1762
1599
              DRIZZLE_YYABORT;
1763
1600
          }
1764
1601
        ;
 
1602
field_def:
 
1603
          type opt_attribute {}
 
1604
        ;
1765
1605
 
1766
1606
type:
1767
 
        int_type field_options 
 
1607
        int_type
1768
1608
        { 
1769
1609
          $$=$1; 
1770
1610
          Lex->length=(char*) 0; /* use default length */
1771
1611
        }
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
 
          }
 
1612
        | real_type opt_precision { $$=$1; }
1788
1613
        | char '(' NUM ')' opt_binary
1789
1614
          {
1790
1615
            Lex->length=$3.str;
1807
1632
            $$= DRIZZLE_TYPE_VARCHAR;
1808
1633
          }
1809
1634
        | 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
 
1635
          { $$=DRIZZLE_TYPE_DATE; }
 
1636
        | TIMESTAMP_SYM
 
1637
          { $$=DRIZZLE_TYPE_TIMESTAMP; }
 
1638
        | DATETIME_SYM
1820
1639
          { $$=DRIZZLE_TYPE_DATETIME; }
1821
1640
        | BLOB_SYM
1822
1641
          {
1829
1648
            $$=DRIZZLE_TYPE_BLOB; 
1830
1649
            Lex->length=(char*) 0; /* use default length */
1831
1650
          }
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
 
1651
        | DECIMAL_SYM float_options
 
1652
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1653
        | NUMERIC_SYM float_options
 
1654
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1655
        | FIXED_SYM float_options
 
1656
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1657
        | ENUM_SYM
1839
1658
          {Lex->interval_list.empty();}
1840
1659
          '(' string_list ')' opt_binary
1841
1660
          { $$=DRIZZLE_TYPE_ENUM; }
1842
1661
        | SERIAL_SYM
1843
1662
          {
1844
1663
            $$=DRIZZLE_TYPE_LONGLONG;
1845
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
1846
 
              UNIQUE_FLAG);
 
1664
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1847
1665
          }
1848
1666
        ;
1849
1667
 
1853
1671
 
1854
1672
varchar:
1855
1673
          char VARYING {}
1856
 
        | VARCHAR {}
 
1674
        | VARCHAR_SYM {}
1857
1675
        ;
1858
1676
 
1859
1677
int_type:
1860
 
          INT_SYM   { $$=DRIZZLE_TYPE_LONG; }
1861
 
        | TINYINT   { $$=DRIZZLE_TYPE_TINY; }
1862
 
        | SMALLINT  { $$=DRIZZLE_TYPE_SHORT; }
1863
 
        | BIGINT    { $$=DRIZZLE_TYPE_LONGLONG; }
 
1678
          INT_SYM    { $$=DRIZZLE_TYPE_LONG; }
 
1679
        | BIGINT_SYM { $$=DRIZZLE_TYPE_LONGLONG; }
1864
1680
        ;
1865
1681
 
1866
1682
real_type:
1892
1708
          }
1893
1709
        ;
1894
1710
 
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
1711
opt_len:
1911
1712
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
1912
1713
        | '(' NUM ')' { Lex->length= $2.str; }
1932
1733
        | COLUMN_FORMAT_SYM column_format_types
1933
1734
          {
1934
1735
            Lex->column_format= $2;
1935
 
            Lex->alter_info.flags|= ALTER_COLUMN_FORMAT;
 
1736
            Lex->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1936
1737
          }
1937
1738
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
1938
1739
        | DEFAULT now_or_signed_literal 
1939
1740
          { 
1940
1741
            Lex->default_value=$2; 
1941
 
            Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
1742
            Lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1942
1743
          }
1943
1744
        | ON UPDATE_SYM NOW_SYM optional_braces 
1944
1745
          { Lex->on_update_value= new Item_func_now_local(); }
1947
1748
          { 
1948
1749
            LEX *lex=Lex;
1949
1750
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1950
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1751
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1951
1752
          }
1952
1753
        | opt_primary KEY_SYM
1953
1754
          {
1954
1755
            LEX *lex=Lex;
1955
1756
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1956
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1757
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1957
1758
          }
1958
1759
        | UNIQUE_SYM
1959
1760
          {
1960
1761
            LEX *lex=Lex;
1961
1762
            lex->type|= UNIQUE_FLAG; 
1962
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1763
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1963
1764
          }
1964
1765
        | UNIQUE_SYM KEY_SYM
1965
1766
          {
1966
1767
            LEX *lex=Lex;
1967
1768
            lex->type|= UNIQUE_KEY_FLAG; 
1968
 
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
1769
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1969
1770
          }
1970
1771
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
1971
1772
        | COLLATE_SYM collation_name
1990
1791
          { $$=$1; }
1991
1792
        ;
1992
1793
 
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
1794
collation_name:
2039
1795
          ident_or_text
2040
1796
          {
2041
 
            if (!($$=get_charset_by_name($1.str,MYF(0))))
 
1797
            if (!($$=get_charset_by_name($1.str)))
2042
1798
            {
2043
1799
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
2044
1800
              DRIZZLE_YYABORT;
2046
1802
          }
2047
1803
        ;
2048
1804
 
2049
 
opt_collate:
2050
 
          /* empty */ { $$=NULL; }
2051
 
        | COLLATE_SYM collation_name_or_default { $$=$2; }
2052
 
        ;
2053
 
 
2054
1805
collation_name_or_default:
2055
1806
          collation_name { $$=$1; }
2056
1807
        | DEFAULT    { $$=NULL; }
2063
1814
 
2064
1815
opt_binary:
2065
1816
          /* empty */ { Lex->charset=NULL; }
2066
 
        | ASCII_SYM opt_bin_mod { Lex->charset=&my_charset_latin1; }
2067
1817
        | 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
1818
        | BINARY { Lex->type|= BINCMP_FLAG; }
2084
1819
        ;
2085
1820
 
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
1821
ws_nweights:
2102
1822
        '(' real_ulong_num
2103
1823
        {
2149
1869
ws_level_range:
2150
1870
        ws_level_number '-' ws_level_number
2151
1871
        {
2152
 
          uint start= $1;
2153
 
          uint end= $3;
 
1872
          uint32_t start= $1;
 
1873
          uint32_t end= $3;
2154
1874
          for ($$= 0; start <= end; start++)
2155
1875
            $$|= (1 << start);
2156
1876
        }
2367
2087
alter:
2368
2088
          ALTER build_method opt_ignore TABLE_SYM table_ident
2369
2089
          {
2370
 
            THD *thd= YYTHD;
2371
 
            LEX *lex= thd->lex;
 
2090
            Session *session= YYSession;
 
2091
            LEX *lex= session->lex;
2372
2092
            lex->name.str= 0;
2373
2093
            lex->name.length= 0;
2374
2094
            lex->sql_command= SQLCOM_ALTER_TABLE;
2375
2095
            lex->duplicates= DUP_ERROR; 
2376
 
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
2096
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2377
2097
                                                   TL_OPTION_UPDATING))
2378
2098
              DRIZZLE_YYABORT;
2379
2099
            lex->alter_info.reset();
2380
2100
            lex->col_list.empty();
2381
2101
            lex->select_lex.init_order();
2382
2102
            lex->select_lex.db=
2383
 
              ((TABLE_LIST*) lex->select_lex.table_list.first)->db;
 
2103
              ((TableList*) lex->select_lex.table_list.first)->db;
2384
2104
            memset(&lex->create_info, 0, sizeof(lex->create_info));
2385
2105
            lex->create_info.db_type= 0;
2386
2106
            lex->create_info.default_table_charset= NULL;
2387
2107
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
2388
2108
            lex->alter_info.reset();
2389
 
            lex->no_write_to_binlog= 0;
2390
2109
            lex->alter_info.build_method= $2;
 
2110
 
 
2111
            lex->create_table_proto= new drizzled::message::Table();
2391
2112
          }
2392
2113
          alter_commands
2393
2114
          {}
2444
2165
          {
2445
2166
            LEX *lex=Lex;
2446
2167
            lex->change=0;
2447
 
            lex->alter_info.flags|= ALTER_ADD_COLUMN;
 
2168
            lex->alter_info.flags.set(ALTER_ADD_COLUMN);
2448
2169
          }
2449
2170
        ;
2450
2171
 
2452
2173
          add_column column_def opt_place { }
2453
2174
        | ADD key_def
2454
2175
          {
2455
 
            Lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2176
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
2456
2177
          }
2457
2178
        | add_column '(' field_list ')'
2458
2179
          {
2459
 
            Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX;
 
2180
            Lex->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2181
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
2460
2182
          }
2461
2183
        | CHANGE opt_column field_ident
2462
2184
          {
2463
2185
            LEX *lex=Lex;
2464
2186
            lex->change= $3.str;
2465
 
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2187
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2466
2188
          }
2467
2189
          field_spec opt_place
2468
2190
        | MODIFY_SYM opt_column field_ident
2472
2194
            lex->default_value= lex->on_update_value= 0;
2473
2195
            lex->comment=null_lex_str;
2474
2196
            lex->charset= NULL;
2475
 
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2197
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2476
2198
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2477
2199
          }
2478
 
          type opt_attribute
 
2200
          field_def
2479
2201
          {
2480
2202
            LEX *lex=Lex;
2481
 
            if (add_field_to_list(lex->thd,&$3,
 
2203
            if (add_field_to_list(lex->session,&$3,
2482
2204
                                  (enum enum_field_types) $5,
2483
2205
                                  lex->length,lex->dec,lex->type,
2484
2206
                                  lex->column_format,
2493
2215
            LEX *lex=Lex;
2494
2216
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
2495
2217
                                                               $3.str));
2496
 
            lex->alter_info.flags|= ALTER_DROP_COLUMN;
 
2218
            lex->alter_info.flags.set(ALTER_DROP_COLUMN);
2497
2219
          }
2498
2220
        | DROP FOREIGN KEY_SYM opt_ident
2499
2221
          {
2500
 
            Lex->alter_info.flags|= ALTER_DROP_INDEX | ALTER_FOREIGN_KEY;
 
2222
            Lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
2223
            Lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
2501
2224
          }
2502
2225
        | DROP PRIMARY_SYM KEY_SYM
2503
2226
          {
2504
2227
            LEX *lex=Lex;
2505
2228
            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;
 
2229
                                                               "PRIMARY"));
 
2230
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
2508
2231
          }
2509
2232
        | DROP key_or_index field_ident
2510
2233
          {
2511
2234
            LEX *lex=Lex;
2512
2235
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2513
2236
                                                               $3.str));
2514
 
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2237
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
2515
2238
          }
2516
2239
        | DISABLE_SYM KEYS
2517
2240
          {
2518
2241
            LEX *lex=Lex;
2519
2242
            lex->alter_info.keys_onoff= DISABLE;
2520
 
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2243
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
2521
2244
          }
2522
2245
        | ENABLE_SYM KEYS
2523
2246
          {
2524
2247
            LEX *lex=Lex;
2525
2248
            lex->alter_info.keys_onoff= ENABLE;
2526
 
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2249
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
2527
2250
          }
2528
2251
        | ALTER opt_column field_ident SET DEFAULT signed_literal
2529
2252
          {
2530
2253
            LEX *lex=Lex;
2531
2254
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
2532
 
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2255
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2533
2256
          }
2534
2257
        | ALTER opt_column field_ident DROP DEFAULT
2535
2258
          {
2536
2259
            LEX *lex=Lex;
2537
2260
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
2538
2261
                                                                  (Item*) 0));
2539
 
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2262
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2540
2263
          }
2541
2264
        | RENAME opt_to table_ident
2542
2265
          {
2554
2277
              DRIZZLE_YYABORT;
2555
2278
            }
2556
2279
            lex->name= $3->table;
2557
 
            lex->alter_info.flags|= ALTER_RENAME;
 
2280
            lex->alter_info.flags.set(ALTER_RENAME);
2558
2281
          }
2559
 
        | CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
 
2282
        | CONVERT_SYM TO_SYM collation_name_or_default
2560
2283
          {
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
2284
            LEX *lex= Lex;
2574
2285
            lex->create_info.table_charset=
2575
 
            lex->create_info.default_table_charset= $5;
 
2286
            lex->create_info.default_table_charset= $3;
2576
2287
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2577
2288
              HA_CREATE_USED_DEFAULT_CHARSET);
2578
 
            lex->alter_info.flags|= ALTER_CONVERT;
 
2289
            lex->alter_info.flags.set(ALTER_CONVERT);
2579
2290
          }
2580
2291
        | create_table_options_space_separated
2581
2292
          {
2582
2293
            LEX *lex=Lex;
2583
 
            lex->alter_info.flags|= ALTER_OPTIONS;
 
2294
            lex->alter_info.flags.set(ALTER_OPTIONS);
2584
2295
          }
2585
2296
        | FORCE_SYM
2586
2297
          {
2587
 
            Lex->alter_info.flags|= ALTER_FORCE;
 
2298
            Lex->alter_info.flags.set(ALTER_FORCE);
2588
2299
          }
2589
2300
        | alter_order_clause
2590
2301
          {
2591
2302
            LEX *lex=Lex;
2592
 
            lex->alter_info.flags|= ALTER_ORDER;
 
2303
            lex->alter_info.flags.set(ALTER_ORDER);
2593
2304
          }
2594
2305
        ;
2595
2306
 
2608
2319
        | AFTER_SYM ident
2609
2320
          {
2610
2321
            store_position_for_column($2.str);
2611
 
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2322
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
2612
2323
          }
2613
2324
        | FIRST_SYM
2614
2325
          {
2615
2326
            store_position_for_column(first_keyword);
2616
 
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2327
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
2617
2328
          }
2618
2329
        ;
2619
2330
 
2624
2335
        | AS {}
2625
2336
        ;
2626
2337
 
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
2338
start:
2669
2339
          START_SYM TRANSACTION_SYM start_transaction_opts
2670
2340
          {
2682
2352
          }
2683
2353
        ;
2684
2354
 
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
2355
 
2723
2356
checksum:
2724
2357
          CHECKSUM_SYM table_or_tables
2736
2369
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
2737
2370
        ;
2738
2371
 
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
 
        ;
2766
2372
 
2767
2373
analyze:
2768
 
          ANALYZE_SYM opt_no_write_to_binlog table_or_tables
 
2374
          ANALYZE_SYM table_or_tables
2769
2375
          {
2770
2376
            LEX *lex=Lex;
2771
2377
            lex->sql_command = SQLCOM_ANALYZE;
2772
 
            lex->no_write_to_binlog= $2;
2773
2378
            lex->check_opt.init();
2774
2379
          }
2775
2380
          table_list
2776
2381
          {}
2777
2382
        ;
2778
2383
 
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
2384
check:
2788
2385
          CHECK_SYM table_or_tables
2789
2386
          {
2812
2409
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
2813
2410
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
2814
2411
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
2815
 
        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
2816
2412
        ;
2817
2413
 
2818
2414
optimize:
2819
 
          OPTIMIZE opt_no_write_to_binlog table_or_tables
 
2415
          OPTIMIZE table_or_tables
2820
2416
          {
2821
2417
            LEX *lex=Lex;
2822
2418
            lex->sql_command = SQLCOM_OPTIMIZE;
2823
 
            lex->no_write_to_binlog= $2;
2824
2419
            lex->check_opt.init();
2825
2420
          }
2826
2421
          table_list
2827
2422
          {}
2828
2423
        ;
2829
2424
 
2830
 
opt_no_write_to_binlog:
2831
 
          /* empty */ { $$= 0; }
2832
 
        | NO_WRITE_TO_BINLOG { $$= 1; }
2833
 
        | LOCAL_SYM { $$= 1; }
2834
 
        ;
2835
 
 
2836
2425
rename:
2837
2426
          RENAME table_or_tables
2838
2427
          {
2851
2440
          table_ident TO_SYM table_ident
2852
2441
          {
2853
2442
            LEX *lex=Lex;
2854
 
            SELECT_LEX *sl= lex->current_select;
2855
 
            if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
 
2443
            Select_Lex *sl= lex->current_select;
 
2444
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
2856
2445
                                       TL_IGNORE) ||
2857
 
                !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
 
2446
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
2858
2447
                                       TL_IGNORE))
2859
2448
              DRIZZLE_YYABORT;
2860
2449
          }
2877
2466
assign_to_keycache:
2878
2467
          table_ident cache_keys_spec
2879
2468
          {
2880
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ, 
 
2469
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
2881
2470
                                           Select->pop_index_hints()))
2882
2471
              DRIZZLE_YYABORT;
2883
2472
          }
2890
2479
 
2891
2480
cache_keys_spec:
2892
2481
          {
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);
 
2482
            Lex->select_lex.alloc_index_hints(YYSession);
 
2483
            Select->set_index_hint_type(INDEX_HINT_USE, INDEX_HINT_MASK_ALL);
2898
2484
          }
2899
2485
          cache_key_list_or_empty
2900
2486
        ;
2946
2532
          select_part2
2947
2533
          {
2948
2534
            LEX *lex= Lex;
2949
 
            SELECT_LEX * sel= lex->current_select;
 
2535
            Select_Lex * sel= lex->current_select;
2950
2536
            if (lex->current_select->set_braces(0))
2951
2537
            {
2952
2538
              my_parse_error(ER(ER_SYNTAX_ERROR));
2965
2551
select_part2:
2966
2552
          {
2967
2553
            LEX *lex= Lex;
2968
 
            SELECT_LEX *sel= lex->current_select;
 
2554
            Select_Lex *sel= lex->current_select;
2969
2555
            if (sel->linkage != UNION_TYPE)
2970
2556
              mysql_init_select(lex);
2971
2557
            lex->current_select->parsing_place= SELECT_LIST;
2991
2577
          {
2992
2578
            Select->context.table_list=
2993
2579
              Select->context.first_name_resolution_table= 
2994
 
                (TABLE_LIST *) Select->table_list.first;
 
2580
                (TableList *) Select->table_list.first;
2995
2581
          }
2996
2582
        ;
2997
2583
 
3014
2600
 
3015
2601
select_option:
3016
2602
          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
2603
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
3024
2604
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
3025
2605
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
3058
2638
        | select_item
3059
2639
        | '*'
3060
2640
          {
3061
 
            THD *thd= YYTHD;
3062
 
            if (add_item_to_list(thd,
3063
 
                                 new Item_field(&thd->lex->current_select->
3064
 
                                                context,
3065
 
                                                NULL, NULL, "*")))
 
2641
            Session *session= YYSession;
 
2642
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2643
                                                          context,
 
2644
                                                          NULL, NULL, "*")))
3066
2645
              DRIZZLE_YYABORT;
3067
 
            (thd->lex->current_select->with_wild)++;
 
2646
            (session->lex->current_select->with_wild)++;
3068
2647
          }
3069
2648
        ;
3070
2649
 
3071
2650
select_item:
3072
2651
          remember_name table_wild remember_end
3073
2652
          {
3074
 
            THD *thd= YYTHD;
 
2653
            Session *session= YYSession;
3075
2654
 
3076
 
            if (add_item_to_list(thd, $2))
 
2655
            if (session->add_item_to_list($2))
3077
2656
              DRIZZLE_YYABORT;
3078
2657
          }
3079
2658
        | remember_name expr remember_end select_alias
3080
2659
          {
3081
 
            THD *thd= YYTHD;
 
2660
            Session *session= YYSession;
3082
2661
            assert($1 < $3);
3083
2662
 
3084
 
            if (add_item_to_list(thd, $2))
 
2663
            if (session->add_item_to_list($2))
3085
2664
              DRIZZLE_YYABORT;
3086
2665
            if ($4.str)
3087
2666
            {
3090
2669
            }
3091
2670
            else if (!$2->name)
3092
2671
            {
3093
 
              $2->set_name($1, (uint) ($3 - $1), thd->charset());
 
2672
              $2->set_name($1, (uint) ($3 - $1), session->charset());
3094
2673
            }
3095
2674
          }
3096
2675
        ;
3097
2676
 
3098
2677
remember_name:
3099
2678
          {
3100
 
            THD *thd= YYTHD;
3101
 
            Lex_input_stream *lip= thd->m_lip;
 
2679
            Session *session= YYSession;
 
2680
            Lex_input_stream *lip= session->m_lip;
3102
2681
            $$= (char*) lip->get_cpp_tok_start();
3103
2682
          }
3104
2683
        ;
3105
2684
 
3106
2685
remember_end:
3107
2686
          {
3108
 
            THD *thd= YYTHD;
3109
 
            Lex_input_stream *lip= thd->m_lip;
 
2687
            Session *session= YYSession;
 
2688
            Lex_input_stream *lip= session->m_lip;
3110
2689
            $$= (char*) lip->get_cpp_tok_end();
3111
2690
          }
3112
2691
        ;
3130
2709
          {
3131
2710
            /*
3132
2711
              Design notes:
3133
 
              Do not use a manually maintained stack like thd->lex->xxx_list,
 
2712
              Do not use a manually maintained stack like session->lex->xxx_list,
3134
2713
              but use the internal bison stack ($$, $1 and $3) instead.
3135
2714
              Using the bison stack is:
3136
2715
              - more robust to changes in the grammar,
3172
2751
            else
3173
2752
            {
3174
2753
              /* X OR Y */
3175
 
              $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
 
2754
              $$ = new (YYSession->mem_root) Item_cond_or($1, $3);
3176
2755
            }
3177
2756
          }
3178
2757
        | expr XOR expr %prec XOR
3179
2758
          {
3180
2759
            /* XOR is a proprietary extension */
3181
 
            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
 
2760
            $$ = new (YYSession->mem_root) Item_cond_xor($1, $3);
3182
2761
          }
3183
2762
        | expr and expr %prec AND_SYM
3184
2763
          {
3218
2797
            else
3219
2798
            {
3220
2799
              /* X AND Y */
3221
 
              $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
 
2800
              $$ = new (YYSession->mem_root) Item_cond_and($1, $3);
3222
2801
            }
3223
2802
          }
3224
2803
        | NOT_SYM expr %prec NOT_SYM
3225
 
          { $$= negate_expression(YYTHD, $2); }
 
2804
          { $$= negate_expression(YYSession, $2); }
3226
2805
        | bool_pri IS TRUE_SYM %prec IS
3227
 
          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
 
2806
          { $$= new (YYSession->mem_root) Item_func_istrue($1); }
3228
2807
        | bool_pri IS not TRUE_SYM %prec IS
3229
 
          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
 
2808
          { $$= new (YYSession->mem_root) Item_func_isnottrue($1); }
3230
2809
        | bool_pri IS FALSE_SYM %prec IS
3231
 
          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
 
2810
          { $$= new (YYSession->mem_root) Item_func_isfalse($1); }
3232
2811
        | bool_pri IS not FALSE_SYM %prec IS
3233
 
          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
 
2812
          { $$= new (YYSession->mem_root) Item_func_isnotfalse($1); }
3234
2813
        | bool_pri IS UNKNOWN_SYM %prec IS
3235
2814
          { $$= new Item_func_isnull($1); }
3236
2815
        | bool_pri IS not UNKNOWN_SYM %prec IS
3255
2834
predicate:
3256
2835
          bit_expr IN_SYM '(' subselect ')'
3257
2836
          {
3258
 
            $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
 
2837
            $$= new (YYSession->mem_root) Item_in_subselect($1, $4);
3259
2838
          }
3260
2839
        | bit_expr not IN_SYM '(' subselect ')'
3261
2840
          {
3262
 
            THD *thd= YYTHD;
3263
 
            Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
3264
 
            $$= negate_expression(thd, item);
 
2841
            Session *session= YYSession;
 
2842
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
 
2843
            $$= negate_expression(session, item);
3265
2844
          }
3266
2845
        | bit_expr IN_SYM '(' expr ')'
3267
2846
          {
3268
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
 
2847
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
3269
2848
          }
3270
2849
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
3271
2850
          { 
3272
2851
            $6->push_front($4);
3273
2852
            $6->push_front($1);
3274
 
            $$= new (YYTHD->mem_root) Item_func_in(*$6);
 
2853
            $$= new (YYSession->mem_root) Item_func_in(*$6);
3275
2854
          }
3276
2855
        | bit_expr not IN_SYM '(' expr ')'
3277
2856
          {
3278
 
            $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
 
2857
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
3279
2858
          }
3280
2859
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
3281
2860
          {
3282
2861
            $7->push_front($5);
3283
2862
            $7->push_front($1);
3284
 
            Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
 
2863
            Item_func_in *item = new (YYSession->mem_root) Item_func_in(*$7);
3285
2864
            item->negate();
3286
2865
            $$= item;
3287
2866
          }
3356
2935
        | function_call_conflict
3357
2936
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
3358
2937
          {
3359
 
            THD *thd= YYTHD;
3360
 
            Item *i1= new (thd->mem_root) Item_string($3.str,
 
2938
            Session *session= YYSession;
 
2939
            Item *i1= new (session->mem_root) Item_string($3.str,
3361
2940
                                                      $3.length,
3362
 
                                                      thd->charset());
3363
 
            $$= new (thd->mem_root) Item_func_set_collation($1, i1);
 
2941
                                                      session->charset());
 
2942
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
3364
2943
          }
3365
2944
        | literal
3366
2945
        | variable
3367
2946
        | sum_expr
3368
2947
        | '+' simple_expr %prec NEG { $$= $2; }
3369
2948
        | '-' simple_expr %prec NEG
3370
 
          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
 
2949
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
3371
2950
        | '(' subselect ')'
3372
2951
          { 
3373
 
            $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
 
2952
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
3374
2953
          }
3375
2954
        | '(' expr ')' { $$= $2; }
3376
2955
        | '(' expr ',' expr_list ')'
3377
2956
          {
3378
2957
            $4->push_front($2);
3379
 
            $$= new (YYTHD->mem_root) Item_row(*$4);
 
2958
            $$= new (YYSession->mem_root) Item_row(*$4);
3380
2959
          }
3381
2960
        | ROW_SYM '(' expr ',' expr_list ')'
3382
2961
          {
3383
2962
            $5->push_front($3);
3384
 
            $$= new (YYTHD->mem_root) Item_row(*$5);
 
2963
            $$= new (YYSession->mem_root) Item_row(*$5);
3385
2964
          }
3386
2965
        | EXISTS '(' subselect ')'
3387
2966
          {
3388
 
            $$= new (YYTHD->mem_root) Item_exists_subselect($3);
 
2967
            $$= new (YYSession->mem_root) Item_exists_subselect($3);
3389
2968
          }
3390
2969
        | '{' ident expr '}' { $$= $3; }
3391
2970
        | BINARY simple_expr %prec NEG
3392
2971
          {
3393
 
            $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
 
2972
            $$= create_func_cast(YYSession, $2, ITEM_CAST_CHAR, NULL, NULL,
3394
2973
                                 &my_charset_bin);
3395
2974
          }
3396
2975
        | CAST_SYM '(' expr AS cast_type ')'
3397
2976
          {
3398
2977
            LEX *lex= Lex;
3399
 
            $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
 
2978
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
3400
2979
                                 lex->charset);
3401
2980
            if (!$$)
3402
2981
              DRIZZLE_YYABORT;
3403
2982
          }
3404
2983
        | CASE_SYM opt_expr when_list opt_else END
3405
 
          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
 
2984
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
3406
2985
        | CONVERT_SYM '(' expr ',' cast_type ')'
3407
2986
          {
3408
 
            $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
 
2987
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
3409
2988
                                 Lex->charset);
3410
2989
            if (!$$)
3411
2990
              DRIZZLE_YYABORT;
3412
2991
          }
3413
 
        | CONVERT_SYM '(' expr USING charset_name ')'
3414
 
          { $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5); }
3415
2992
        | DEFAULT '(' simple_ident ')'
3416
2993
          {
3417
 
            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
 
2994
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
3418
2995
                                                         $3);
3419
2996
          }
3420
2997
        | VALUES '(' simple_ident_nospvar ')'
3421
2998
          {
3422
 
            $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
 
2999
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
3423
3000
                                                        $3);
3424
3001
          }
3425
3002
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
3426
3003
          /* we cannot put interval before - */
3427
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
 
3004
          { $$= new (YYSession->mem_root) Item_date_add_interval($5,$2,$3,0); }
3428
3005
        ;
3429
3006
 
3430
3007
/*
3435
3012
*/
3436
3013
function_call_keyword:
3437
3014
          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); }
 
3015
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
3441
3016
        | CURRENT_USER optional_braces
3442
3017
          {
3443
 
            $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
3444
 
            Lex->set_stmt_unsafe();
 
3018
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
3445
3019
          }
3446
3020
        | DATE_SYM '(' expr ')'
3447
 
          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
 
3021
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3448
3022
        | DAY_SYM '(' expr ')'
3449
 
          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
 
3023
          { $$= new (YYSession->mem_root) Item_func_dayofmonth($3); }
3450
3024
        | HOUR_SYM '(' expr ')'
3451
 
          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
 
3025
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
3452
3026
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3453
 
          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3027
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
3454
3028
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3455
3029
          {
3456
 
            THD *thd= YYTHD;
3457
 
            List<Item> *list= new (thd->mem_root) List<Item>;
 
3030
            Session *session= YYSession;
 
3031
            List<Item> *list= new (session->mem_root) List<Item>;
3458
3032
            list->push_front($5);
3459
3033
            list->push_front($3);
3460
 
            Item_row *item= new (thd->mem_root) Item_row(*list);
3461
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3034
            Item_row *item= new (session->mem_root) Item_row(*list);
 
3035
            $$= new (session->mem_root) Item_func_interval(item);
3462
3036
          }
3463
3037
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3464
3038
          {
3465
 
            THD *thd= YYTHD;
 
3039
            Session *session= YYSession;
3466
3040
            $7->push_front($5);
3467
3041
            $7->push_front($3);
3468
 
            Item_row *item= new (thd->mem_root) Item_row(*$7);
3469
 
            $$= new (thd->mem_root) Item_func_interval(item);
 
3042
            Item_row *item= new (session->mem_root) Item_row(*$7);
 
3043
            $$= new (session->mem_root) Item_func_interval(item);
3470
3044
          }
3471
3045
        | LEFT '(' expr ',' expr ')'
3472
 
          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
 
3046
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3473
3047
        | MINUTE_SYM '(' expr ')'
3474
 
          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
 
3048
          { $$= new (YYSession->mem_root) Item_func_minute($3); }
3475
3049
        | MONTH_SYM '(' expr ')'
3476
 
          { $$= new (YYTHD->mem_root) Item_func_month($3); }
 
3050
          { $$= new (YYSession->mem_root) Item_func_month($3); }
3477
3051
        | RIGHT '(' expr ',' expr ')'
3478
 
          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
 
3052
          { $$= new (YYSession->mem_root) Item_func_right($3,$5); }
3479
3053
        | 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); }
 
3054
          { $$= new (YYSession->mem_root) Item_func_second($3); }
 
3055
        | TIMESTAMP_SYM '(' expr ')'
 
3056
          { $$= new (YYSession->mem_root) Item_datetime_typecast($3); }
3487
3057
        | TRIM '(' expr ')'
3488
 
          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
 
3058
          { $$= new (YYSession->mem_root) Item_func_trim($3); }
3489
3059
        | TRIM '(' LEADING expr FROM expr ')'
3490
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
 
3060
          { $$= new (YYSession->mem_root) Item_func_ltrim($6,$4); }
3491
3061
        | TRIM '(' TRAILING expr FROM expr ')'
3492
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
 
3062
          { $$= new (YYSession->mem_root) Item_func_rtrim($6,$4); }
3493
3063
        | TRIM '(' BOTH expr FROM expr ')'
3494
 
          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
 
3064
          { $$= new (YYSession->mem_root) Item_func_trim($6,$4); }
3495
3065
        | TRIM '(' LEADING FROM expr ')'
3496
 
          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
 
3066
          { $$= new (YYSession->mem_root) Item_func_ltrim($5); }
3497
3067
        | TRIM '(' TRAILING FROM expr ')'
3498
 
          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
 
3068
          { $$= new (YYSession->mem_root) Item_func_rtrim($5); }
3499
3069
        | TRIM '(' BOTH FROM expr ')'
3500
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
 
3070
          { $$= new (YYSession->mem_root) Item_func_trim($5); }
3501
3071
        | TRIM '(' expr FROM expr ')'
3502
 
          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
 
3072
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3503
3073
        | USER '(' ')'
3504
3074
          {
3505
 
            $$= new (YYTHD->mem_root) Item_func_user();
3506
 
            Lex->set_stmt_unsafe();
 
3075
            $$= new (YYSession->mem_root) Item_func_user();
3507
3076
          }
3508
3077
        | YEAR_SYM '(' expr ')'
3509
 
          { $$= new (YYTHD->mem_root) Item_func_year($3); }
 
3078
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3510
3079
        ;
3511
3080
 
3512
3081
/*
3517
3086
  MAINTAINER:
3518
3087
  The only reasons a function should be added here are:
3519
3088
  - for compatibility reasons with another SQL syntax (CURDATE),
3520
 
  - for typing reasons (GET_FORMAT)
3521
3089
  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
3522
3090
  discouraged.
3523
3091
*/
3524
3092
function_call_nonkeyword:
3525
3093
          ADDDATE_SYM '(' expr ',' expr ')'
3526
3094
          {
3527
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3095
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3528
3096
                                                             INTERVAL_DAY, 0);
3529
3097
          }
3530
3098
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3531
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
3099
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
3532
3100
        | CURDATE optional_braces
3533
3101
          {
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);
 
3102
            $$= new (YYSession->mem_root) Item_func_curdate_local();
3543
3103
          }
3544
3104
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3545
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
 
3105
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
3546
3106
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3547
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
 
3107
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,1); }
3548
3108
        | 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); }
 
3109
          { $$=new (YYSession->mem_root) Item_extract( $3, $5); }
3552
3110
        | NOW_SYM optional_braces
3553
3111
          {
3554
 
            $$= new (YYTHD->mem_root) Item_func_now_local();
 
3112
            $$= new (YYSession->mem_root) Item_func_now_local();
3555
3113
          }
3556
3114
        | NOW_SYM '(' expr ')'
3557
3115
          {
3558
 
            $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3116
            $$= new (YYSession->mem_root) Item_func_now_local($3);
3559
3117
          }
3560
3118
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3561
 
          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
 
3119
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
3562
3120
        | SUBDATE_SYM '(' expr ',' expr ')'
3563
3121
          {
3564
 
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3122
            $$= new (YYSession->mem_root) Item_date_add_interval($3, $5,
3565
3123
                                                             INTERVAL_DAY, 1);
3566
3124
          }
3567
3125
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3568
 
          { $$= 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); }
3569
3127
        | SUBSTRING '(' expr ',' expr ',' expr ')'
3570
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3128
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3571
3129
        | SUBSTRING '(' expr ',' expr ')'
3572
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3130
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3573
3131
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3574
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3132
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3575
3133
        | SUBSTRING '(' expr FROM expr ')'
3576
 
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3134
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3577
3135
        | 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
 
          }
 
3136
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
3584
3137
        | 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
 
          }
 
3138
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
3591
3139
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3592
 
          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
 
3140
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
3593
3141
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3594
 
          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
3142
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
3595
3143
        | UTC_DATE_SYM optional_braces
3596
3144
          {
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();
 
3145
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
3602
3146
          }
3603
3147
        | UTC_TIMESTAMP_SYM optional_braces
3604
3148
          {
3605
 
            $$= new (YYTHD->mem_root) Item_func_now_utc();
 
3149
            $$= new (YYSession->mem_root) Item_func_now_utc();
3606
3150
          }
3607
3151
        ;
3608
3152
 
3613
3157
*/
3614
3158
function_call_conflict:
3615
3159
          ASCII_SYM '(' expr ')'
3616
 
          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
3617
 
        | CHARSET '(' expr ')'
3618
 
          { $$= new (YYTHD->mem_root) Item_func_charset($3); }
 
3160
          { $$= new (YYSession->mem_root) Item_func_ascii($3); }
3619
3161
        | COALESCE '(' expr_list ')'
3620
 
          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
 
3162
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
3621
3163
        | COLLATION_SYM '(' expr ')'
3622
 
          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
 
3164
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3623
3165
        | DATABASE '(' ')'
3624
3166
          {
3625
 
            $$= new (YYTHD->mem_root) Item_func_database();
 
3167
            $$= new (YYSession->mem_root) Item_func_database();
3626
3168
          }
3627
3169
        | IF '(' expr ',' expr ',' expr ')'
3628
 
          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
 
3170
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3629
3171
        | MICROSECOND_SYM '(' expr ')'
3630
 
          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
 
3172
          { $$= new (YYSession->mem_root) Item_func_microsecond($3); }
3631
3173
        | MOD_SYM '(' expr ',' expr ')'
3632
 
          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
 
3174
          { $$ = new (YYSession->mem_root) Item_func_mod( $3, $5); }
3633
3175
        | QUARTER_SYM '(' expr ')'
3634
 
          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
 
3176
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
3635
3177
        | REPEAT_SYM '(' expr ',' expr ')'
3636
 
          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
 
3178
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
3637
3179
        | REPLACE '(' expr ',' expr ',' expr ')'
3638
 
          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
 
3180
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3639
3181
        | REVERSE_SYM '(' expr ')'
3640
 
          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
 
3182
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
3641
3183
        | 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); }
 
3184
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
3654
3185
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
3655
 
          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
 
3186
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
3656
3187
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
3657
3188
          {
3658
 
            $$= new (YYTHD->mem_root)
 
3189
            $$= new (YYSession->mem_root)
3659
3190
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
3660
3191
          }
3661
3192
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
3662
3193
          {
3663
 
            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
3664
 
            $$= new (YYTHD->mem_root)
 
3194
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3195
            $$= new (YYSession->mem_root)
3665
3196
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
3666
3197
          }
3667
3198
        ;
3672
3203
  introduce side effects to the language in general.
3673
3204
  MAINTAINER:
3674
3205
  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
 
3206
  this category.
3677
3207
*/
3678
3208
function_call_generic:
3679
3209
          IDENT_sys '('
3680
3210
          {
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
 
            }
 
3211
            Function_builder *udf= 0;
 
3212
            udf= find_udf($1.str, $1.length);
 
3213
 
3693
3214
            /* Temporary placing the result of find_udf in $3 */
3694
3215
            $<udf>$= udf;
3695
3216
          }
3696
3217
          opt_udf_expr_list ')'
3697
3218
          {
3698
 
            THD *thd= YYTHD;
 
3219
            Session *session= YYSession;
3699
3220
            Create_func *builder;
3700
3221
            Item *item= NULL;
3701
3222
 
3708
3229
 
3709
3230
              This will be revised with WL#2128 (SQL PATH)
3710
3231
            */
3711
 
            builder= find_native_function_builder(thd, $1);
 
3232
            builder= find_native_function_builder($1);
3712
3233
            if (builder)
3713
3234
            {
3714
 
              item= builder->create(thd, $1, $4);
 
3235
              item= builder->create(session, $1, $4);
3715
3236
            }
3716
3237
            else
3717
3238
            {
3718
3239
              /* Retrieving the result of find_udf */
3719
 
              udf_func *udf= $<udf>3;
 
3240
              Function_builder *udf= $<udf>3;
3720
3241
              if (udf)
3721
3242
              {
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 {
 
3243
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
3244
              } else {
3729
3245
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3730
3246
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3731
3247
              }
3746
3262
udf_expr_list:
3747
3263
          udf_expr
3748
3264
          {
3749
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3265
            $$= new (YYSession->mem_root) List<Item>;
3750
3266
            $$->push_back($1);
3751
3267
          }
3752
3268
        | udf_expr_list ',' udf_expr
3771
3287
              $2->set_name($4.str, $4.length, system_charset_info);
3772
3288
            }
3773
3289
            else
3774
 
              $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
 
3290
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
3775
3291
            $$= $2;
3776
3292
          }
3777
3293
        ;
3822
3338
          opt_gconcat_separator
3823
3339
          ')'
3824
3340
          {
3825
 
            SELECT_LEX *sel= Select;
 
3341
            Select_Lex *sel= Select;
3826
3342
            sel->in_sum_expr--;
3827
3343
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3828
3344
                                          sel->gorder_list, $7);
3832
3348
 
3833
3349
variable:
3834
3350
          '@'
3835
 
          {
3836
 
            if (! Lex->parsing_options.allows_variable)
3837
 
            {
3838
 
              my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
3839
 
              DRIZZLE_YYABORT;
3840
 
            }
3841
 
          }
 
3351
          { }
3842
3352
          variable_aux
3843
3353
          {
3844
3354
            $$= $3;
3862
3372
              my_parse_error(ER(ER_SYNTAX_ERROR));
3863
3373
              DRIZZLE_YYABORT;
3864
3374
            }
3865
 
            if (!($$= get_system_var(YYTHD, $2, $3, $4)))
 
3375
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3866
3376
              DRIZZLE_YYABORT;
3867
 
            if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
3868
 
              Lex->set_stmt_unsafe();
3869
3377
          }
3870
3378
        ;
3871
3379
 
3877
3385
opt_gconcat_separator:
3878
3386
          /* empty */
3879
3387
            {
3880
 
              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
 
3388
              $$= new (YYSession->mem_root) String(",", 1, &my_charset_utf8_general_ci);
3881
3389
            }
3882
3390
        | SEPARATOR_SYM text_string { $$ = $2; }
3883
3391
        ;
3889
3397
          }
3890
3398
        | order_clause
3891
3399
          {
3892
 
            SELECT_LEX *select= Select;
 
3400
            Select_Lex *select= Select;
3893
3401
            select->gorder_list=
3894
3402
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3895
3403
                                     sizeof(st_sql_list));
3919
3427
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3920
3428
        | CHAR_SYM opt_len opt_binary
3921
3429
          { $$=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
3430
        | DATE_SYM
3931
3431
          { $$=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
 
3432
        | DATETIME_SYM
3935
3433
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3936
3434
        | DECIMAL_SYM float_options
3937
3435
          { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
3940
3438
expr_list:
3941
3439
          expr
3942
3440
          {
3943
 
            $$= new (YYTHD->mem_root) List<Item>;
 
3441
            $$= new (YYSession->mem_root) List<Item>;
3944
3442
            $$->push_back($1);
3945
3443
          }
3946
3444
        | expr_list ',' expr
3982
3480
        | join_table
3983
3481
          {
3984
3482
            LEX *lex= Lex;
3985
 
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
 
3483
            if (!($$= lex->current_select->nest_last_join(lex->session)))
3986
3484
              DRIZZLE_YYABORT;
3987
3485
          }
3988
3486
        ;
4036
3534
          {
4037
3535
            DRIZZLE_YYABORT_UNLESS($1 && $3);
4038
3536
            /* Change the current name resolution context to a local context. */
4039
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3537
            if (push_new_name_resolution_context(YYSession, $1, $3))
4040
3538
              DRIZZLE_YYABORT;
4041
3539
            Select->parsing_place= IN_ON;
4042
3540
          }
4051
3549
          {
4052
3550
            DRIZZLE_YYABORT_UNLESS($1 && $3);
4053
3551
            /* Change the current name resolution context to a local context. */
4054
 
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
3552
            if (push_new_name_resolution_context(YYSession, $1, $3))
4055
3553
              DRIZZLE_YYABORT;
4056
3554
            Select->parsing_place= IN_ON;
4057
3555
          }
4081
3579
          {
4082
3580
            DRIZZLE_YYABORT_UNLESS($1 && $5);
4083
3581
            /* Change the current name resolution context to a local context. */
4084
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
3582
            if (push_new_name_resolution_context(YYSession, $1, $5))
4085
3583
              DRIZZLE_YYABORT;
4086
3584
            Select->parsing_place= IN_ON;
4087
3585
          }
4117
3615
          {
4118
3616
            DRIZZLE_YYABORT_UNLESS($1 && $5);
4119
3617
            /* Change the current name resolution context to a local context. */
4120
 
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
3618
            if (push_new_name_resolution_context(YYSession, $1, $5))
4121
3619
              DRIZZLE_YYABORT;
4122
3620
            Select->parsing_place= IN_ON;
4123
3621
          }
4167
3665
/* Warning - may return NULL in case of incomplete SELECT */
4168
3666
table_factor:
4169
3667
          {
4170
 
            SELECT_LEX *sel= Select;
 
3668
            Select_Lex *sel= Select;
4171
3669
            sel->table_join_options= 0;
4172
3670
          }
4173
3671
          table_ident opt_table_alias opt_key_definition
4174
3672
          {
4175
 
            if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
 
3673
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
4176
3674
                                                Select->get_table_join_options(),
4177
3675
                                                Lex->lock_option,
4178
3676
                                                Select->pop_index_hints())))
4182
3680
        | select_derived_init get_select_lex select_derived2
4183
3681
          {
4184
3682
            LEX *lex= Lex;
4185
 
            SELECT_LEX *sel= lex->current_select;
 
3683
            Select_Lex *sel= lex->current_select;
4186
3684
            if ($1)
4187
3685
            {
4188
3686
              if (sel->set_braces(1))
4195
3693
                sel->master_unit()->global_parameters=
4196
3694
                   sel->master_unit()->fake_select_lex;
4197
3695
            }
4198
 
            if ($2->init_nested_join(lex->thd))
 
3696
            if ($2->init_nested_join(lex->session))
4199
3697
              DRIZZLE_YYABORT;
4200
3698
            $$= 0;
4201
3699
            /* incomplete derived tables return NULL, we must be
4238
3736
                 are no outer parentheses, add_table_to_list() will throw
4239
3737
                 error in this case */
4240
3738
              LEX *lex=Lex;
4241
 
              SELECT_LEX *sel= lex->current_select;
4242
 
              SELECT_LEX_UNIT *unit= sel->master_unit();
 
3739
              Select_Lex *sel= lex->current_select;
 
3740
              Select_Lex_Unit *unit= sel->master_unit();
4243
3741
              lex->current_select= sel= unit->outer_select();
4244
 
              if (!($$= sel->add_table_to_list(lex->thd,
 
3742
              if (!($$= sel->add_table_to_list(lex->session,
4245
3743
                                               new Table_ident(unit), $5, 0,
4246
3744
                                               TL_READ)))
4247
3745
 
4285
3783
          select_part2_derived
4286
3784
          {
4287
3785
            LEX *lex= Lex;
4288
 
            SELECT_LEX * sel= lex->current_select;
 
3786
            Select_Lex * sel= lex->current_select;
4289
3787
            if (lex->current_select->set_braces(0))
4290
3788
            {
4291
3789
              my_parse_error(ER(ER_SYNTAX_ERROR));
4304
3802
select_part2_derived:
4305
3803
          {
4306
3804
            LEX *lex= Lex;
4307
 
            SELECT_LEX *sel= lex->current_select;
 
3805
            Select_Lex *sel= lex->current_select;
4308
3806
            if (sel->linkage != UNION_TYPE)
4309
3807
              mysql_init_select(lex);
4310
3808
            lex->current_select->parsing_place= SELECT_LIST;
4321
3819
          get_select_lex
4322
3820
          {
4323
3821
            LEX *lex= Lex;
4324
 
            if ($1->init_nested_join(lex->thd))
 
3822
            if ($1->init_nested_join(lex->session))
4325
3823
              DRIZZLE_YYABORT;
4326
3824
          }
4327
3825
          derived_table_list
4330
3828
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
4331
3829
               for derived tables, both must equal NULL */
4332
3830
 
4333
 
            if (!($$= $1->end_nested_join(lex->thd)) && $3)
 
3831
            if (!($$= $1->end_nested_join(lex->session)) && $3)
4334
3832
              DRIZZLE_YYABORT;
4335
3833
            if (!$3 && $$)
4336
3834
            {
4344
3842
          {
4345
3843
            LEX *lex= Lex;
4346
3844
            lex->derived_tables|= DERIVED_SUBQUERY;
4347
 
            if (!lex->expr_allows_subselect ||
4348
 
                lex->sql_command == (int)SQLCOM_PURGE)
 
3845
            if (!lex->expr_allows_subselect)
4349
3846
            {
4350
3847
              my_parse_error(ER(ER_SYNTAX_ERROR));
4351
3848
              DRIZZLE_YYABORT;
4373
3870
          {
4374
3871
            LEX *lex= Lex;
4375
3872
 
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))
 
3873
            Select_Lex *sel= lex->current_select;
 
3874
            TableList *embedding;
 
3875
            if (!sel->embedding || sel->end_nested_join(lex->session))
4385
3876
            {
4386
3877
              /* we are not in parentheses */
4387
3878
              my_parse_error(ER(ER_SYNTAX_ERROR));
4402
3893
index_hint_clause:
4403
3894
          /* empty */
4404
3895
          {
4405
 
            $$= global_system_variables.old_mode ? 
4406
 
                  INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL; 
 
3896
            $$= INDEX_HINT_MASK_ALL; 
4407
3897
          }
4408
3898
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
4409
3899
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
4435
3925
 
4436
3926
opt_index_hints_list:
4437
3927
          /* empty */
4438
 
        | { Select->alloc_index_hints(YYTHD); } index_hints_list
 
3928
        | { Select->alloc_index_hints(YYSession); } index_hints_list
4439
3929
        ;
4440
3930
 
4441
3931
opt_key_definition:
4444
3934
        ;
4445
3935
 
4446
3936
opt_key_usage_list:
4447
 
          /* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
 
3937
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
4448
3938
        | key_usage_list {}
4449
3939
        ;
4450
3940
 
4451
3941
key_usage_element:
4452
3942
          ident
4453
 
          { Select->add_index_hint(YYTHD, $1.str, $1.length); }
 
3943
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
4454
3944
        | PRIMARY_SYM
4455
 
          { Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
 
3945
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
4456
3946
        ;
4457
3947
 
4458
3948
key_usage_list:
4465
3955
          {
4466
3956
            if (!($$= new List<String>))
4467
3957
              DRIZZLE_YYABORT;
4468
 
            $$->push_back(new (YYTHD->mem_root)
 
3958
            $$->push_back(new (YYSession->mem_root)
4469
3959
                              String((const char *) $1.str, $1.length,
4470
3960
                                      system_charset_info));
4471
3961
          }
4472
3962
        | using_list ',' ident
4473
3963
          {
4474
 
            $1->push_back(new (YYTHD->mem_root)
 
3964
            $1->push_back(new (YYSession->mem_root)
4475
3965
                              String((const char *) $3.str, $3.length,
4476
3966
                                      system_charset_info));
4477
3967
            $$= $1;
4524
4014
        | YEAR_SYM        { $$=INTERVAL_YEAR; }
4525
4015
        ;
4526
4016
 
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
4017
table_alias:
4535
4018
          /* empty */
4536
4019
        | AS
4556
4039
          }
4557
4040
          expr
4558
4041
          {
4559
 
            SELECT_LEX *select= Select;
 
4042
            Select_Lex *select= Select;
4560
4043
            select->where= $3;
4561
4044
            select->parsing_place= NO_MATTER;
4562
4045
            if ($3)
4572
4055
          }
4573
4056
          expr
4574
4057
          {
4575
 
            SELECT_LEX *sel= Select;
 
4058
            Select_Lex *sel= Select;
4576
4059
            sel->having= $3;
4577
4060
            sel->parsing_place= NO_MATTER;
4578
4061
            if ($3)
4589
4072
        | /* empty */
4590
4073
          {
4591
4074
            Lex->escape_used= false;
4592
 
            $$= new Item_string("\\", 1, &my_charset_latin1);
 
4075
            $$= new Item_string("\\", 1, &my_charset_utf8_general_ci);
4593
4076
          }
4594
4077
        ;
4595
4078
 
4604
4087
 
4605
4088
group_list:
4606
4089
          group_list ',' order_ident order_dir
4607
 
          { if (add_group_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4090
          { if (YYSession->add_group_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
4608
4091
        | order_ident order_dir
4609
 
          { if (add_group_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4092
          { if (YYSession->add_group_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
4610
4093
        ;
4611
4094
 
4612
4095
olap_opt:
4613
4096
          /* 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
4097
        | WITH_ROLLUP_SYM
4635
4098
          {
4636
4099
            /*
4667
4130
alter_order_item:
4668
4131
          simple_ident_nospvar order_dir
4669
4132
          {
4670
 
            THD *thd= YYTHD;
 
4133
            Session *session= YYSession;
4671
4134
            bool ascending= ($2 == 1) ? true : false;
4672
 
            if (add_order_to_list(thd, $1, ascending))
 
4135
            if (session->add_order_to_list($1, ascending))
4673
4136
              DRIZZLE_YYABORT;
4674
4137
          }
4675
4138
        ;
4687
4150
          ORDER_SYM BY
4688
4151
          {
4689
4152
            LEX *lex=Lex;
4690
 
            SELECT_LEX *sel= lex->current_select;
4691
 
            SELECT_LEX_UNIT *unit= sel-> master_unit();
 
4153
            Select_Lex *sel= lex->current_select;
 
4154
            Select_Lex_Unit *unit= sel-> master_unit();
4692
4155
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4693
4156
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
4694
4157
                (sel->linkage != UNION_TYPE || sel->braces))
4704
4167
                executed in the same way as the query
4705
4168
                SELECT ... ORDER BY order_list
4706
4169
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
4707
 
                Otherwise we create a fake SELECT_LEX if it has not been created
 
4170
                Otherwise we create a fake Select_Lex if it has not been created
4708
4171
                yet.
4709
4172
              */
4710
 
              SELECT_LEX *first_sl= unit->first_select();
 
4173
              Select_Lex *first_sl= unit->first_select();
4711
4174
              if (!unit->is_union() &&
4712
4175
                  (first_sl->order_list.elements || 
4713
4176
                   first_sl->select_limit) &&            
4714
 
                  unit->add_fake_select_lex(lex->thd))
 
4177
                  unit->add_fake_select_lex(lex->session))
4715
4178
                DRIZZLE_YYABORT;
4716
4179
            }
4717
4180
          }
4720
4183
 
4721
4184
order_list:
4722
4185
          order_list ',' order_ident order_dir
4723
 
          { if (add_order_to_list(YYTHD, $3,(bool) $4)) DRIZZLE_YYABORT; }
 
4186
          { if (YYSession->add_order_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
4724
4187
        | order_ident order_dir
4725
 
          { if (add_order_to_list(YYTHD, $1,(bool) $2)) DRIZZLE_YYABORT; }
 
4188
          { if (YYSession->add_order_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
4726
4189
        ;
4727
4190
 
4728
4191
order_dir:
4735
4198
          /* empty */
4736
4199
          {
4737
4200
            LEX *lex= Lex;
4738
 
            SELECT_LEX *sel= lex->current_select;
 
4201
            Select_Lex *sel= lex->current_select;
4739
4202
            sel->offset_limit= 0;
4740
4203
            sel->select_limit= 0;
4741
4204
          }
4754
4217
limit_options:
4755
4218
          limit_option
4756
4219
          {
4757
 
            SELECT_LEX *sel= Select;
 
4220
            Select_Lex *sel= Select;
4758
4221
            sel->select_limit= $1;
4759
4222
            sel->offset_limit= 0;
4760
4223
            sel->explicit_limit= 1;
4761
4224
          }
4762
4225
        | limit_option ',' limit_option
4763
4226
          {
4764
 
            SELECT_LEX *sel= Select;
 
4227
            Select_Lex *sel= Select;
4765
4228
            sel->select_limit= $3;
4766
4229
            sel->offset_limit= $1;
4767
4230
            sel->explicit_limit= 1;
4768
4231
          }
4769
4232
        | limit_option OFFSET_SYM limit_option
4770
4233
          {
4771
 
            SELECT_LEX *sel= Select;
 
4234
            Select_Lex *sel= Select;
4772
4235
            sel->select_limit= $1;
4773
4236
            sel->offset_limit= $3;
4774
4237
            sel->explicit_limit= 1;
4789
4252
          }
4790
4253
        | LIMIT limit_option
4791
4254
          {
4792
 
            SELECT_LEX *sel= Select;
 
4255
            Select_Lex *sel= Select;
4793
4256
            sel->select_limit= $2;
4794
4257
            sel->explicit_limit= 1;
4795
4258
          }
4809
4272
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
4810
4273
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
4811
4274
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
4812
 
        | dec_num_error { DRIZZLE_YYABORT; }
4813
 
        ;
 
4275
        | dec_num_error { }
 
4276
        ;
4814
4277
 
4815
4278
ulonglong_num:
4816
4279
          NUM           { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
4867
4330
 
4868
4331
into:
4869
4332
          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
 
          }
 
4333
          { }
4877
4334
          into_destination
4878
4335
        ;
4879
4336
 
4881
4338
          OUTFILE TEXT_STRING_filesystem
4882
4339
          {
4883
4340
            LEX *lex= Lex;
4884
 
            if (!(lex->exchange= new sql_exchange($2.str, 0)) ||
 
4341
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
4885
4342
                !(lex->result= new select_export(lex->exchange)))
4886
4343
              DRIZZLE_YYABORT;
4887
4344
          }
4891
4348
            LEX *lex=Lex;
4892
4349
            if (!lex->describe)
4893
4350
            {
4894
 
              if (!(lex->exchange= new sql_exchange($2.str,1)))
 
4351
              if (!(lex->exchange= new file_exchange($2.str,1)))
4895
4352
                DRIZZLE_YYABORT;
4896
4353
              if (!(lex->result= new select_dump(lex->exchange)))
4897
4354
                DRIZZLE_YYABORT;
4918
4375
            LEX *lex=Lex;
4919
4376
            lex->sql_command= SQLCOM_DROP_INDEX;
4920
4377
            lex->alter_info.reset();
4921
 
            lex->alter_info.flags= ALTER_DROP_INDEX;
 
4378
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
4922
4379
            lex->alter_info.build_method= $2;
4923
4380
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
4924
4381
                                                               $4.str));
4925
 
            if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
 
4382
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4926
4383
                                                        TL_OPTION_UPDATING))
4927
4384
              DRIZZLE_YYABORT;
4928
4385
          }
4941
4398
table_name:
4942
4399
          table_ident
4943
4400
          {
4944
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
 
4401
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4945
4402
              DRIZZLE_YYABORT;
4946
4403
          }
4947
4404
        ;
4954
4411
table_alias_ref:
4955
4412
          table_ident
4956
4413
          {
4957
 
            if (!Select->add_table_to_list(YYTHD, $1, NULL,
 
4414
            if (!Select->add_table_to_list(YYSession, $1, NULL,
4958
4415
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4959
4416
                                           Lex->lock_option ))
4960
4417
              DRIZZLE_YYABORT;
4968
4425
 
4969
4426
opt_temporary:
4970
4427
          /* empty */ { $$= 0; }
4971
 
        | TEMPORARY { $$= 1; }
 
4428
        | TEMPORARY_SYM { $$= 1; }
4972
4429
        ;
4973
4430
/*
4974
4431
** Insert : add new data to table
4982
4439
            lex->duplicates= DUP_ERROR; 
4983
4440
            mysql_init_select(lex);
4984
4441
            /* for subselects */
4985
 
            lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
 
4442
            lex->lock_option= TL_READ;
4986
4443
          }
4987
 
          insert_lock_option
4988
4444
          opt_ignore insert2
4989
4445
          {
4990
 
            Select->set_lock_for_tables($3);
 
4446
            Select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4991
4447
            Lex->current_select= &Lex->select_lex;
4992
4448
          }
4993
4449
          insert_field_spec opt_insert_update
5002
4458
            lex->duplicates= DUP_REPLACE;
5003
4459
            mysql_init_select(lex);
5004
4460
          }
5005
 
          replace_lock_option insert2
 
4461
          insert2
5006
4462
          {
5007
 
            Select->set_lock_for_tables($3);
 
4463
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
5008
4464
            Lex->current_select= &Lex->select_lex;
5009
4465
          }
5010
4466
          insert_field_spec
5011
4467
          {}
5012
4468
        ;
5013
4469
 
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
4470
insert2:
5030
4471
          INTO insert_table {}
5031
4472
        | insert_table {}
5154
4595
            lex->lock_option= TL_UNLOCK; /* Will be set later */
5155
4596
            lex->duplicates= DUP_ERROR; 
5156
4597
          }
5157
 
          opt_low_priority opt_ignore join_table_list
 
4598
          opt_ignore join_table_list
5158
4599
          SET update_list
5159
4600
          {
5160
4601
            LEX *lex= Lex;
5172
4613
              be too pessimistic. We will decrease lock level if possible in
5173
4614
              mysql_multi_update().
5174
4615
            */
5175
 
            Select->set_lock_for_tables($3);
 
4616
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
5176
4617
          }
5177
4618
          where_clause opt_order_clause delete_limit_clause {}
5178
4619
        ;
5185
4626
update_elem:
5186
4627
          simple_ident_nospvar equal expr_or_default
5187
4628
          {
5188
 
            if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
 
4629
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
5189
4630
              DRIZZLE_YYABORT;
5190
4631
          }
5191
4632
        ;
5205
4646
          }
5206
4647
        ;
5207
4648
 
5208
 
opt_low_priority:
5209
 
          /* empty */ { $$= TL_WRITE_DEFAULT; }
5210
 
        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
5211
 
        ;
5212
 
 
5213
4649
/* Delete rows from a table */
5214
4650
 
5215
4651
delete:
5228
4664
single_multi:
5229
4665
          FROM table_ident
5230
4666
          {
5231
 
            if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
 
4667
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
5232
4668
                                           Lex->lock_option))
5233
4669
              DRIZZLE_YYABORT;
5234
4670
          }
5258
4694
table_wild_one:
5259
4695
          ident opt_wild
5260
4696
          {
5261
 
            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
 
4697
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
5262
4698
                                           NULL,
5263
4699
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5264
4700
                                           Lex->lock_option))
5266
4702
          }
5267
4703
        | ident '.' ident opt_wild
5268
4704
          {
5269
 
            if (!Select->add_table_to_list(YYTHD,
5270
 
                                           new Table_ident(YYTHD, $1, $3, 0),
 
4705
            if (!Select->add_table_to_list(YYSession,
 
4706
                                           new Table_ident(YYSession, $1, $3, 0),
5271
4707
                                           NULL,
5272
4708
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5273
4709
                                           Lex->lock_option))
5287
4723
 
5288
4724
opt_delete_option:
5289
4725
          QUICK        { Select->options|= OPTION_QUICK; }
5290
 
        | LOW_PRIORITY { Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
5291
4726
        | IGNORE_SYM   { Lex->ignore= 1; }
5292
4727
        ;
5293
4728
 
5323
4758
        ;
5324
4759
 
5325
4760
show_param:
5326
 
           DATABASES wild_and_where
 
4761
           DATABASES show_wild
5327
4762
           {
5328
4763
             LEX *lex= Lex;
5329
4764
             lex->sql_command= SQLCOM_SHOW_DATABASES;
5330
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
 
4765
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
5331
4766
               DRIZZLE_YYABORT;
5332
4767
           }
5333
 
         | opt_full TABLES opt_db wild_and_where
 
4768
         | opt_full TABLES opt_db show_wild
5334
4769
           {
5335
4770
             LEX *lex= Lex;
5336
4771
             lex->sql_command= SQLCOM_SHOW_TABLES;
5337
4772
             lex->select_lex.db= $3;
5338
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
 
4773
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
5339
4774
               DRIZZLE_YYABORT;
5340
4775
           }
5341
 
         | TABLE_SYM STATUS_SYM opt_db wild_and_where
 
4776
         | TABLE_SYM STATUS_SYM opt_db show_wild
5342
4777
           {
5343
4778
             LEX *lex= Lex;
5344
4779
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
5345
4780
             lex->select_lex.db= $3;
5346
 
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
 
4781
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
5347
4782
               DRIZZLE_YYABORT;
5348
4783
           }
5349
 
        | OPEN_SYM TABLES opt_db wild_and_where
 
4784
        | OPEN_SYM TABLES opt_db show_wild
5350
4785
          {
5351
4786
            LEX *lex= Lex;
5352
4787
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5353
4788
            lex->select_lex.db= $3;
5354
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
 
4789
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
5355
4790
              DRIZZLE_YYABORT;
5356
4791
          }
5357
4792
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
5358
4793
          { 
5359
 
            Lex->create_info.db_type= $2; 
 
4794
            Lex->show_engine= $2; 
5360
4795
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
5361
4796
          }
5362
 
        | opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
 
4797
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
5363
4798
          {
5364
4799
            LEX *lex= Lex;
5365
4800
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5366
4801
            if ($5)
5367
4802
              $4->change_db($5);
5368
 
            if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
 
4803
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
5369
4804
              DRIZZLE_YYABORT;
5370
4805
          }
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
4806
        | keys_or_index from_or_in table_ident opt_db where_clause
5385
4807
          {
5386
4808
            LEX *lex= Lex;
5387
4809
            lex->sql_command= SQLCOM_SHOW_KEYS;
5388
4810
            if ($4)
5389
4811
              $3->change_db($4);
5390
 
            if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
 
4812
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
5391
4813
              DRIZZLE_YYABORT;
5392
4814
          }
5393
4815
        | COUNT_SYM '(' '*' ')' WARNINGS
5398
4820
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
5399
4821
        | ERRORS opt_limit_clause_init
5400
4822
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
5401
 
        | opt_var_type STATUS_SYM wild_and_where
 
4823
        | opt_var_type STATUS_SYM show_wild
5402
4824
          {
5403
4825
            LEX *lex= Lex;
5404
4826
            lex->sql_command= SQLCOM_SHOW_STATUS;
5405
4827
            lex->option_type= $1;
5406
 
            if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
 
4828
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
5407
4829
              DRIZZLE_YYABORT;
5408
4830
          }
5409
4831
        | opt_full PROCESSLIST_SYM
5410
4832
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
5411
 
        | opt_var_type  VARIABLES wild_and_where
 
4833
        | opt_var_type  VARIABLES show_wild
5412
4834
          {
5413
4835
            LEX *lex= Lex;
5414
4836
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
5415
4837
            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))
 
4838
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
5431
4839
              DRIZZLE_YYABORT;
5432
4840
          }
5433
4841
        | CREATE DATABASE opt_if_not_exists ident
5440
4848
          {
5441
4849
            LEX *lex= Lex;
5442
4850
            lex->sql_command = SQLCOM_SHOW_CREATE;
5443
 
            if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
 
4851
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
5444
4852
              DRIZZLE_YYABORT;
5445
4853
          }
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
 
        ;
5459
4854
 
5460
4855
opt_db:
5461
4856
          /* empty */  { $$= 0; }
5472
4867
        | IN_SYM
5473
4868
        ;
5474
4869
 
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:
 
4870
show_wild:
5486
4871
          /* empty */
5487
4872
        | LIKE TEXT_STRING_sys
5488
4873
          {
5489
 
            Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
 
4874
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
5490
4875
                                                    system_charset_info);
 
4876
            if (Lex->wild == NULL)
 
4877
              DRIZZLE_YYABORT;
5491
4878
          }
5492
4879
        | WHERE expr
5493
4880
          {
5508
4895
            lex->sql_command= SQLCOM_SHOW_FIELDS;
5509
4896
            lex->select_lex.db= 0;
5510
4897
            lex->verbose= 0;
5511
 
            if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
 
4898
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
5512
4899
              DRIZZLE_YYABORT;
5513
4900
          }
5514
4901
          opt_describe_column {}
5536
4923
        | text_string { Lex->wild= $1; }
5537
4924
        | ident
5538
4925
          {
5539
 
            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
 
4926
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
5540
4927
                                                    $1.length,
5541
4928
                                                    system_charset_info);
5542
4929
          }
5546
4933
/* flush things */
5547
4934
 
5548
4935
flush:
5549
 
          FLUSH_SYM opt_no_write_to_binlog
 
4936
          FLUSH_SYM
5550
4937
          {
5551
4938
            LEX *lex=Lex;
5552
4939
            lex->sql_command= SQLCOM_FLUSH;
5553
4940
            lex->type= 0;
5554
 
            lex->no_write_to_binlog= $2;
5555
4941
          }
5556
4942
          flush_options
5557
4943
          {}
5568
4954
          opt_table_list {}
5569
4955
        | TABLES WITH READ_SYM LOCK_SYM
5570
4956
          { 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
4957
        | LOGS_SYM
5576
4958
          { Lex->type|= REFRESH_LOG; }
5577
4959
        | STATUS_SYM
5578
4960
          { 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
4961
        ;
5586
4962
 
5587
4963
opt_table_list:
5589
4965
        | table_list {}
5590
4966
        ;
5591
4967
 
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
4968
/* kill threads */
5643
4969
 
5644
4970
kill:
5673
4999
load:
5674
5000
          LOAD data_file
5675
5001
          {
5676
 
            THD *thd= YYTHD;
5677
 
            LEX *lex= thd->lex;
5678
 
            Lex_input_stream *lip= thd->m_lip;
 
5002
            Session *session= YYSession;
 
5003
            LEX *lex= session->lex;
 
5004
            Lex_input_stream *lip= session->m_lip;
5679
5005
 
5680
5006
            lex->fname_start= lip->get_ptr();
5681
5007
          }
5682
 
          load_data_lock opt_local INFILE TEXT_STRING_filesystem
 
5008
          load_data_lock INFILE TEXT_STRING_filesystem
5683
5009
          {
5684
5010
            LEX *lex=Lex;
5685
5011
            lex->sql_command= SQLCOM_LOAD;
5686
5012
            lex->lock_option= $4;
5687
 
            lex->local_file=  $5;
5688
5013
            lex->duplicates= DUP_ERROR;
5689
5014
            lex->ignore= 0;
5690
 
            if (!(lex->exchange= new sql_exchange($7.str, 0, $2)))
 
5015
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
5691
5016
              DRIZZLE_YYABORT;
5692
5017
          }
5693
5018
          opt_duplicate INTO
5694
5019
          {
5695
 
            THD *thd= YYTHD;
5696
 
            LEX *lex= thd->lex;
5697
 
            Lex_input_stream *lip= thd->m_lip;
 
5020
            Session *session= YYSession;
 
5021
            LEX *lex= session->lex;
 
5022
            Lex_input_stream *lip= session->m_lip;
5698
5023
            lex->fname_end= lip->get_ptr();
5699
5024
          }
5700
5025
          TABLE_SYM table_ident
5701
5026
          {
5702
5027
            LEX *lex=Lex;
5703
 
            if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
 
5028
            if (!Select->add_table_to_list(YYSession, $12, NULL, TL_OPTION_UPDATING,
5704
5029
                                           lex->lock_option))
5705
5030
              DRIZZLE_YYABORT;
5706
5031
            lex->field_list.empty();
5707
5032
            lex->update_list.empty();
5708
5033
            lex->value_list.empty();
5709
5034
          }
5710
 
          opt_load_data_charset
5711
 
          { Lex->exchange->cs= $15; }
5712
5035
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5713
5036
          opt_load_data_set_spec
5714
5037
          {}
5717
5040
data_file:
5718
5041
        DATA_SYM  { $$= FILETYPE_CSV; };
5719
5042
 
5720
 
opt_local:
5721
 
          /* empty */ { $$=0;}
5722
 
        | LOCAL_SYM { $$=1;}
5723
 
        ;
5724
 
 
5725
5043
load_data_lock:
5726
5044
          /* empty */ { $$= TL_WRITE_DEFAULT; }
5727
5045
        | CONCURRENT
5728
5046
          {
5729
5047
              $$= TL_WRITE_CONCURRENT_INSERT;
5730
5048
          }
5731
 
        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
5732
5049
        ;
5733
5050
 
5734
5051
opt_duplicate:
5836
5153
/* Common definitions */
5837
5154
 
5838
5155
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
 
          }
 
5156
        TEXT_STRING_literal
 
5157
        {
 
5158
          Session *session= YYSession;
 
5159
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
 
5160
        }
5865
5161
        | 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
 
            }
 
5162
          { 
 
5163
            ((Item_string*) $1)->append($2.str, $2.length); 
5880
5164
          }
5881
5165
        ;
5882
5166
 
5883
5167
text_string:
5884
5168
          TEXT_STRING_literal
5885
5169
          {
5886
 
            $$= new (YYTHD->mem_root) String($1.str,
 
5170
            $$= new (YYSession->mem_root) String($1.str,
5887
5171
                                             $1.length,
5888
 
                                             YYTHD->variables.collation_connection);
 
5172
                                             YYSession->variables.getCollation());
5889
5173
          }
5890
5174
        | HEX_NUM
5891
5175
          {
5926
5210
        | NULL_SYM
5927
5211
          {
5928
5212
            $$ = new Item_null();
5929
 
            YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
 
5213
            YYSession->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
5930
5214
          }
5931
5215
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
5932
5216
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
5933
5217
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
5934
5218
        | 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
5219
        | DATE_SYM text_literal { $$ = $2; }
5989
 
        | TIME_SYM text_literal { $$ = $2; }
5990
 
        | TIMESTAMP text_literal { $$ = $2; }
 
5220
        | TIMESTAMP_SYM text_literal { $$ = $2; }
5991
5221
        ;
5992
5222
 
5993
5223
NUM_literal:
6005
5235
          { $$ = new Item_uint($1.str, $1.length); }
6006
5236
        | DECIMAL_NUM
6007
5237
          {
6008
 
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
6009
 
            if (YYTHD->is_error())
 
5238
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
 
5239
            if (YYSession->is_error())
6010
5240
            {
6011
5241
              DRIZZLE_YYABORT;
6012
5242
            }
6014
5244
        | FLOAT_NUM
6015
5245
          {
6016
5246
            $$ = new Item_float($1.str, $1.length);
6017
 
            if (YYTHD->is_error())
 
5247
            if (YYSession->is_error())
6018
5248
            {
6019
5249
              DRIZZLE_YYABORT;
6020
5250
            }
6033
5263
table_wild:
6034
5264
          ident '.' '*'
6035
5265
          {
6036
 
            SELECT_LEX *sel= Select;
6037
 
            $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
 
5266
            Select_Lex *sel= Select;
 
5267
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
6038
5268
            sel->with_wild++;
6039
5269
          }
6040
5270
        | ident '.' ident '.' '*'
6041
5271
          {
6042
 
            SELECT_LEX *sel= Select;
6043
 
            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
6044
 
                                CLIENT_NO_SCHEMA ? NullS : $1.str),
 
5272
            Select_Lex *sel= Select;
 
5273
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
 
5274
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
6045
5275
                                $3.str,"*");
6046
5276
            sel->with_wild++;
6047
5277
          }
6055
5285
          ident
6056
5286
          {
6057
5287
            {
6058
 
              SELECT_LEX *sel=Select;
 
5288
              Select_Lex *sel=Select;
6059
5289
              $$= (sel->parsing_place != IN_HAVING ||
6060
5290
                  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);
 
5291
                  (Item*) new Item_field(Lex->current_context(),
 
5292
                                         (const char *)NULL, NULL, $1.str) :
 
5293
                  (Item*) new Item_ref(Lex->current_context(),
 
5294
                                       (const char *)NULL, NULL, $1.str);
6063
5295
            }
6064
5296
          }
6065
5297
        | simple_ident_q { $$= $1; }
6068
5300
simple_ident_nospvar:
6069
5301
          ident
6070
5302
          {
6071
 
            SELECT_LEX *sel=Select;
 
5303
            Select_Lex *sel=Select;
6072
5304
            $$= (sel->parsing_place != IN_HAVING ||
6073
5305
                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);
 
5306
                (Item*) new Item_field(Lex->current_context(),
 
5307
                                       (const char *)NULL, NULL, $1.str) :
 
5308
                (Item*) new Item_ref(Lex->current_context(),
 
5309
                                     (const char *)NULL, NULL, $1.str);
6076
5310
          }
6077
5311
        | simple_ident_q { $$= $1; }
6078
5312
        ;
6080
5314
simple_ident_q:
6081
5315
          ident '.' ident
6082
5316
          {
6083
 
            THD *thd= YYTHD;
6084
 
            LEX *lex= thd->lex;
 
5317
            Session *session= YYSession;
 
5318
            LEX *lex= session->lex;
6085
5319
 
6086
5320
            {
6087
 
              SELECT_LEX *sel= lex->current_select;
 
5321
              Select_Lex *sel= lex->current_select;
6088
5322
              if (sel->no_table_names_allowed)
6089
5323
              {
6090
5324
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6091
 
                         MYF(0), $1.str, thd->where);
 
5325
                         MYF(0), $1.str, session->where);
6092
5326
              }
6093
5327
              $$= (sel->parsing_place != IN_HAVING ||
6094
5328
                  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);
 
5329
                  (Item*) new Item_field(Lex->current_context(),
 
5330
                                         (const char *)NULL, $1.str, $3.str) :
 
5331
                  (Item*) new Item_ref(Lex->current_context(),
 
5332
                                       (const char *)NULL, $1.str, $3.str);
6097
5333
            }
6098
5334
          }
6099
5335
        | '.' ident '.' ident
6100
5336
          {
6101
 
            THD *thd= YYTHD;
6102
 
            LEX *lex= thd->lex;
6103
 
            SELECT_LEX *sel= lex->current_select;
 
5337
            Session *session= YYSession;
 
5338
            LEX *lex= session->lex;
 
5339
            Select_Lex *sel= lex->current_select;
6104
5340
            if (sel->no_table_names_allowed)
6105
5341
            {
6106
5342
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6107
 
                       MYF(0), $2.str, thd->where);
 
5343
                       MYF(0), $2.str, session->where);
6108
5344
            }
6109
5345
            $$= (sel->parsing_place != IN_HAVING ||
6110
5346
                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);
 
5347
                (Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
 
5348
                (Item*) new Item_ref(Lex->current_context(),
 
5349
                                     (const char *)NULL, $2.str, $4.str);
6113
5350
          }
6114
5351
        | ident '.' ident '.' ident
6115
5352
          {
6116
 
            THD *thd= YYTHD;
6117
 
            LEX *lex= thd->lex;
6118
 
            SELECT_LEX *sel= lex->current_select;
 
5353
            Session *session= YYSession;
 
5354
            LEX *lex= session->lex;
 
5355
            Select_Lex *sel= lex->current_select;
6119
5356
            if (sel->no_table_names_allowed)
6120
5357
            {
6121
5358
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6122
 
                       MYF(0), $3.str, thd->where);
 
5359
                       MYF(0), $3.str, session->where);
6123
5360
            }
6124
5361
            $$= (sel->parsing_place != IN_HAVING ||
6125
5362
                sel->get_in_sum_expr() > 0) ?
6126
5363
                (Item*) new Item_field(Lex->current_context(),
6127
 
                                       (YYTHD->client_capabilities &
6128
 
                                       CLIENT_NO_SCHEMA ? NullS : $1.str),
 
5364
                                       (YYSession->client_capabilities &
 
5365
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
6129
5366
                                       $3.str, $5.str) :
6130
5367
                (Item*) new Item_ref(Lex->current_context(),
6131
 
                                     (YYTHD->client_capabilities &
6132
 
                                     CLIENT_NO_SCHEMA ? NullS : $1.str),
 
5368
                                     (YYSession->client_capabilities &
 
5369
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
6133
5370
                                     $3.str, $5.str);
6134
5371
          }
6135
5372
        ;
6138
5375
          ident { $$=$1;}
6139
5376
        | ident '.' ident '.' ident
6140
5377
          {
6141
 
            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
 
5378
            TableList *table= (TableList*) Select->table_list.first;
6142
5379
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
6143
5380
            {
6144
5381
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
6154
5391
          }
6155
5392
        | ident '.' ident
6156
5393
          {
6157
 
            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
 
5394
            TableList *table= (TableList*) Select->table_list.first;
6158
5395
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
6159
5396
            {
6160
5397
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
6167
5404
 
6168
5405
table_ident:
6169
5406
          ident { $$=new Table_ident($1); }
6170
 
        | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
 
5407
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
6171
5408
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
6172
5409
        ;
6173
5410
 
6175
5412
          IDENT { $$= $1; }
6176
5413
        | IDENT_QUOTED
6177
5414
          {
6178
 
            THD *thd= YYTHD;
6179
 
 
6180
 
            if (thd->charset_is_system_charset)
 
5415
            const CHARSET_INFO * const cs= system_charset_info;
 
5416
            int dummy_error;
 
5417
            uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
 
5418
                                                 $1.str+$1.length,
 
5419
                                                 $1.length, &dummy_error);
 
5420
            if (wlen < $1.length)
6181
5421
            {
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;
 
5422
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
 
5423
                       cs->csname, $1.str + wlen);
 
5424
              DRIZZLE_YYABORT;
6194
5425
            }
6195
 
            else
6196
 
              thd->convert_string(&$$, system_charset_info,
6197
 
                                  $1.str, $1.length, thd->charset());
 
5426
            $$= $1;
6198
5427
          }
6199
5428
        ;
6200
5429
 
6201
5430
TEXT_STRING_sys:
6202
5431
          TEXT_STRING
6203
5432
          {
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());
 
5433
            $$= $1;
6211
5434
          }
6212
5435
        ;
6213
5436
 
6214
5437
TEXT_STRING_literal:
6215
5438
          TEXT_STRING
6216
5439
          {
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());
 
5440
            $$= $1;
6224
5441
          }
6225
5442
        ;
6226
5443
 
6227
5444
TEXT_STRING_filesystem:
6228
5445
          TEXT_STRING
6229
5446
          {
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());
 
5447
            $$= $1;
6237
5448
          }
6238
5449
        ;
6239
5450
 
6241
5452
          IDENT_sys    { $$=$1; }
6242
5453
        | keyword
6243
5454
          {
6244
 
            THD *thd= YYTHD;
6245
 
            $$.str= thd->strmake($1.str, $1.length);
 
5455
            Session *session= YYSession;
 
5456
            $$.str= session->strmake($1.str, $1.length);
6246
5457
            $$.length= $1.length;
6247
5458
          }
6248
5459
        ;
6277
5488
        | OPTIONS_SYM           {}
6278
5489
        | PORT_SYM              {}
6279
5490
        | REMOVE_SYM            {}
6280
 
        | REPAIR                {}
6281
5491
        | RESET_SYM             {}
6282
5492
        | ROLLBACK_SYM          {}
6283
5493
        | SAVEPOINT_SYM         {}
6284
5494
        | SECURITY_SYM          {}
6285
5495
        | SERVER_SYM            {}
6286
 
        | SIGNED_SYM            {}
6287
5496
        | SOCKET_SYM            {}
6288
 
        | SLAVE                 {}
6289
5497
        | SONAME_SYM            {}
6290
5498
        | START_SYM             {}
6291
5499
        | STOP_SYM              {}
6292
5500
        | TRUNCATE_SYM          {}
6293
 
        | UNICODE_SYM           {}
6294
 
        | UNINSTALL_SYM         {}
6295
 
        | WRAPPER_SYM           {}
6296
 
        | UPGRADE_SYM           {}
6297
5501
        ;
6298
5502
 
6299
5503
/*
6310
5514
        | ALGORITHM_SYM            {}
6311
5515
        | ANY_SYM                  {}
6312
5516
        | AT_SYM                   {}
6313
 
        | AUTHORS_SYM              {}
6314
5517
        | AUTO_INC                 {}
6315
5518
        | AUTOEXTEND_SIZE_SYM      {}
6316
5519
        | AVG_ROW_LENGTH           {}
6340
5543
        | CUBE_SYM                 {}
6341
5544
        | DATA_SYM                 {}
6342
5545
        | DATAFILE_SYM             {}
6343
 
        | DATETIME                 {}
 
5546
        | DATETIME_SYM             {}
6344
5547
        | DATE_SYM                 {}
6345
5548
        | DAY_SYM                  {}
6346
5549
        | DELAY_KEY_WRITE_SYM      {}
6351
5554
        | DUPLICATE_SYM            {}
6352
5555
        | DYNAMIC_SYM              {}
6353
5556
        | ENDS_SYM                 {}
6354
 
        | ENUM                     {}
 
5557
        | ENUM_SYM                 {}
6355
5558
        | ENGINE_SYM               {}
6356
5559
        | ERRORS                   {}
6357
5560
        | ESCAPE_SYM               {}
6358
 
        | EVENTS_SYM               {}
6359
5561
        | EXCLUSIVE_SYM            {}
6360
5562
        | EXTENDED_SYM             {}
6361
5563
        | EXTENT_SIZE_SYM          {}
6368
5570
        | FIRST_SYM                {}
6369
5571
        | FIXED_SYM                {}
6370
5572
        | FRAC_SECOND_SYM          {}
6371
 
        | GET_FORMAT               {}
6372
5573
        | GLOBAL_SYM               {}
6373
5574
        | HASH_SYM                 {}
6374
5575
        | HOSTS_SYM                {}
6390
5591
        | LOGFILE_SYM              {}
6391
5592
        | LOGS_SYM                 {}
6392
5593
        | 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
5594
        | MAX_SIZE_SYM             {}
6405
 
        | MAX_UPDATES_PER_HOUR     {}
6406
 
        | MAX_USER_CONNECTIONS_SYM {}
6407
5595
        | MAX_VALUE_SYM            {}
6408
5596
        | MEDIUM_SYM               {}
6409
5597
        | MERGE_SYM                {}
6433
5621
        | PAGE_CHECKSUM_SYM        {}
6434
5622
        | PARTIAL                  {}
6435
5623
        | PHASE_SYM                {}
6436
 
        | PLUGIN_SYM               {}
6437
 
        | PLUGINS_SYM              {}
6438
5624
        | POINT_SYM                {}
6439
5625
        | PREV_SYM                 {}
6440
5626
        | PROCESS                  {}
6448
5634
        | REDO_BUFFER_SIZE_SYM     {}
6449
5635
        | REDOFILE_SYM             {}
6450
5636
        | REDUNDANT_SYM            {}
6451
 
        | RELAY_LOG_FILE_SYM       {}
6452
 
        | RELAY_LOG_POS_SYM        {}
6453
 
        | RELAY_THREAD             {}
6454
5637
        | RELOAD                   {}
6455
5638
        | REORGANIZE_SYM           {}
6456
5639
        | REPEATABLE_SYM           {}
6474
5657
        | SNAPSHOT_SYM             {}
6475
5658
        | SOURCE_SYM               {}
6476
5659
        | SQL_BUFFER_RESULT        {}
6477
 
        | SQL_THREAD               {}
6478
5660
        | STARTS_SYM               {}
6479
5661
        | STATUS_SYM               {}
6480
5662
        | STORAGE_SYM              {}
6488
5670
        | TABLES                   {}
6489
5671
        | TABLE_CHECKSUM_SYM       {}
6490
5672
        | TABLESPACE               {}
6491
 
        | TEMPORARY                {}
 
5673
        | TEMPORARY_SYM            {}
6492
5674
        | TEMPTABLE_SYM            {}
6493
5675
        | TEXT_SYM                 {}
6494
5676
        | THAN_SYM                 {}
6495
5677
        | TRANSACTION_SYM          {}
6496
 
        | TRANSACTIONAL_SYM        {}
6497
 
        | TIMESTAMP                {}
 
5678
        | TIMESTAMP_SYM            {}
6498
5679
        | TIMESTAMP_ADD            {}
6499
5680
        | TIMESTAMP_DIFF           {}
6500
 
        | TIME_SYM                 {}
6501
5681
        | TYPES_SYM                {}
6502
5682
        | TYPE_SYM                 {}
6503
5683
        | UNCOMMITTED_SYM          {}
6528
5708
            lex->option_type=OPT_SESSION;
6529
5709
            lex->var_list.empty();
6530
5710
            lex->one_shot_set= 0;
6531
 
            lex->autocommit= 0;
6532
5711
          }
6533
5712
          option_value_list
6534
5713
          {}
6601
5780
            LEX *lex=Lex;
6602
5781
            lex->option_type= $1;
6603
5782
            lex->var_list.push_back(new set_var(lex->option_type,
6604
 
                                                find_sys_var(YYTHD, "tx_isolation"),
 
5783
                                                find_sys_var(YYSession, "tx_isolation"),
6605
5784
                                                &null_lex_str,
6606
5785
                                                new Item_int((int32_t) $5)));
6607
5786
          }
6617
5796
            LEX *lex=Lex;
6618
5797
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6619
5798
          }
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
5799
        ;
6641
5800
 
6642
5801
internal_variable_name:
6643
5802
          ident
6644
5803
          {
6645
 
            THD *thd= YYTHD;
 
5804
            Session *session= YYSession;
6646
5805
 
6647
5806
            /* We have to lookup here since local vars can shadow sysvars */
6648
5807
            {
6649
5808
              /* Not an SP local variable */
6650
 
              sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
 
5809
              sys_var *tmp=find_sys_var(session, $1.str, $1.length);
6651
5810
              if (!tmp)
6652
5811
                DRIZZLE_YYABORT;
6653
5812
              $$.var= tmp;
6662
5821
              DRIZZLE_YYABORT;
6663
5822
            }
6664
5823
            {
6665
 
              sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
5824
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
6666
5825
              if (!tmp)
6667
5826
                DRIZZLE_YYABORT;
6668
5827
              if (!tmp->is_struct())
6673
5832
          }
6674
5833
        | DEFAULT '.' ident
6675
5834
          {
6676
 
            sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
5835
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
6677
5836
            if (!tmp)
6678
5837
              DRIZZLE_YYABORT;
6679
5838
            if (!tmp->is_struct())
6699
5858
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
6700
5859
        ;
6701
5860
 
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
5861
table_or_tables:
6727
5862
          TABLE_SYM
6728
5863
        | TABLES
6729
5864
        ;
6730
5865
 
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
5866
unlock:
6806
5867
          UNLOCK_SYM
6807
5868
          {
6829
5890
 
6830
5891
opt_chain:
6831
5892
          /* empty */
6832
 
          { $$= (YYTHD->variables.completion_type == 1); }
 
5893
          { $$= (YYSession->variables.completion_type == 1); }
6833
5894
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
6834
5895
        | AND_SYM CHAIN_SYM        { $$=1; }
6835
5896
        ;
6836
5897
 
6837
5898
opt_release:
6838
5899
          /* empty */
6839
 
          { $$= (YYTHD->variables.completion_type == 2); }
 
5900
          { $$= (YYSession->variables.completion_type == 2); }
6840
5901
        | RELEASE_SYM        { $$=1; }
6841
5902
        | NO_SYM RELEASE_SYM { $$=0; }
6842
5903
;
6925
5986
 
6926
5987
union_order_or_limit:
6927
5988
          {
6928
 
            THD *thd= YYTHD;
6929
 
            LEX *lex= thd->lex;
 
5989
            Session *session= YYSession;
 
5990
            LEX *lex= session->lex;
6930
5991
            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;
 
5992
            Select_Lex *sel= lex->current_select;
 
5993
            Select_Lex_Unit *unit= sel->master_unit();
 
5994
            Select_Lex *fake= unit->fake_select_lex;
6934
5995
            if (fake)
6935
5996
            {
6936
5997
              unit->global_parameters= fake;
6937
5998
              fake->no_table_names_allowed= 1;
6938
5999
              lex->current_select= fake;
6939
6000
            }
6940
 
            thd->where= "global ORDER clause";
 
6001
            session->where= "global ORDER clause";
6941
6002
          }
6942
6003
          order_or_limit
6943
6004
          {
6944
 
            THD *thd= YYTHD;
6945
 
            thd->lex->current_select->no_table_names_allowed= 0;
6946
 
            thd->where= "";
 
6005
            Session *session= YYSession;
 
6006
            session->lex->current_select->no_table_names_allowed= 0;
 
6007
            session->where= "";
6947
6008
          }
6948
6009
        ;
6949
6010
 
6995
6056
subselect_start:
6996
6057
          {
6997
6058
            LEX *lex=Lex;
6998
 
            if (!lex->expr_allows_subselect ||
6999
 
               lex->sql_command == (int)SQLCOM_PURGE)
 
6059
            if (!lex->expr_allows_subselect)
7000
6060
            {
7001
6061
              my_parse_error(ER(ER_SYNTAX_ERROR));
7002
6062
              DRIZZLE_YYABORT;
7017
6077
          {
7018
6078
            LEX *lex=Lex;
7019
6079
            lex->pop_context();
7020
 
            SELECT_LEX *child= lex->current_select;
 
6080
            Select_Lex *child= lex->current_select;
7021
6081
            lex->current_select = lex->current_select->return_after_parsing();
7022
6082
            lex->nest_level--;
7023
6083
            lex->current_select->n_child_sum_items += child->n_sum_items;