~clint-fewbar/drizzle/regex-policy-cache-limiter

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Clint Byrum
  • Date: 2012-03-15 18:05:43 UTC
  • mfrom: (2224.1.302 workspace)
  • Revision ID: clint@ubuntu.com-20120315180543-9jxxm4q10k3np2ws
merging with latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 MySQL AB
 
1
/* 
 
2
   Copyright (C) 2010-2011 Brian Aker
 
3
   Copyright (C) 2000-2003 MySQL AB
2
4
 
3
5
   This program is free software; you can redistribute it and/or modify
4
6
   it under the terms of the GNU General Public License as published by
33
35
 
34
36
#define YYINITDEPTH 100
35
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
36
 
#define Lex (session->getLex())
 
38
#define Lex (session->lex())
37
39
 
38
40
#include <config.h>
39
41
#include <cstdio>
40
42
#include <drizzled/parser.h>
 
43
#include <drizzled/session.h>
41
44
#include <drizzled/alter_column.h>
42
 
#include <drizzled/alter_drop.h>
43
45
#include <drizzled/alter_info.h>
 
46
#include <drizzled/message/alter_table.pb.h>
44
47
#include <drizzled/item/subselect.h>
 
48
#include <drizzled/table_ident.h>
 
49
#include <drizzled/var.h>
 
50
#include <drizzled/system_variables.h>
 
51
#include <drizzled/lex_input_stream.h>
 
52
#include <drizzled/show.h>
45
53
 
46
54
int yylex(union ParserType *yylval, drizzled::Session *session);
47
55
 
50
58
    unsigned long val= *(F);                          \
51
59
    if (drizzled::my_yyoverflow((B), (D), &val)) \
52
60
    {                                         \
53
 
      yyerror(NULL, (char*) (A));                   \
 
61
      yyerror(NULL, (A));                   \
54
62
      return 2;                               \
55
63
    }                                         \
56
64
    else                                      \
107
115
  to abort from the parser.
108
116
*/
109
117
 
110
 
static void base_sql_error(drizzled::Session *session, const char *s)
 
118
static void base_sql_error(drizzled::Session *session, const char* s)
111
119
{
112
120
  parser::errorOn(session, s);
113
121
}
122
130
  unsigned long ulong_num;
123
131
  uint64_t ulonglong_number;
124
132
  int64_t longlong_number;
125
 
  drizzled::LEX_STRING lex_str;
126
 
  drizzled::LEX_STRING *lex_str_ptr;
 
133
  drizzled::lex_string_t lex_str;
 
134
  drizzled::lex_string_t *lex_str_ptr;
127
135
  drizzled::LEX_SYMBOL symbol;
128
136
  drizzled::Table_ident *table;
129
 
  char *simple_string;
 
137
  const char* simple_string;
130
138
  drizzled::Item *item;
131
139
  drizzled::Item_num *item_num;
132
140
  drizzled::List<drizzled::Item> *item_list;
143
151
  drizzled::ha_rkey_function ha_rkey_mode;
144
152
  drizzled::enum_tx_isolation tx_isolation;
145
153
  drizzled::Cast_target cast_type;
146
 
  const drizzled::CHARSET_INFO *charset;
 
154
  const drizzled::charset_info_st *charset;
147
155
  drizzled::thr_lock_type lock_type;
148
156
  drizzled::interval_type interval, interval_time_st;
149
157
  drizzled::type::timestamp_t date_time_type;
150
158
  drizzled::Select_Lex *select_lex;
151
159
  drizzled::chooser_compare_func_creator boolfunc2creator;
152
 
  drizzled::st_lex *lex;
 
160
  drizzled::LEX *lex;
153
161
  drizzled::index_hint_type index_hint;
154
162
  drizzled::enum_filetype filetype;
155
 
  drizzled::ha_build_method build_method;
156
163
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
157
164
  drizzled::execute_string_t execute_string;
158
165
}
165
172
%}
166
173
 
167
174
%debug
168
 
%require "2.2"
 
175
%require "2.4"
169
176
%pure-parser
170
177
%name-prefix="base_sql_"
171
178
%parse-param { drizzled::Session *session }
177
184
  Currently there are 70 shift/reduce conflicts.
178
185
  We should not introduce new conflicts any more.
179
186
*/
180
 
%expect 79
 
187
%expect 80
181
188
 
182
189
/*
183
190
   Comments for TOKENS.
198
205
 
199
206
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
200
207
%token  ACTION                        /* SQL-2003-N */
 
208
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
201
209
%token  ADD_SYM                           /* SQL-2003-R */
202
 
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
203
210
%token  AFTER_SYM                     /* SQL-2003-N */
204
211
%token  AGGREGATE_SYM
205
212
%token  ALL                           /* SQL-2003-R */
234
241
%token  CATALOG_SYM
235
242
%token  CHAIN_SYM                     /* SQL-2003-N */
236
243
%token  CHANGE_SYM
 
244
%token  CHARSET
237
245
%token  CHAR_SYM                      /* SQL-2003-R */
238
246
%token  CHECKSUM_SYM
239
247
%token  CHECK_SYM                     /* SQL-2003-R */
260
268
%token  CROSS                         /* SQL-2003-R */
261
269
%token  CUBE_SYM                      /* SQL-2003-R */
262
270
%token  CURDATE                       /* MYSQL-FUNC */
 
271
%token  CURTIME                       /* MYSQL-FUNC */
263
272
%token  CURRENT_USER                  /* SQL-2003-R */
264
273
%token  CURSOR_SYM                    /* SQL-2003-R */
265
274
%token  DATABASE
279
288
%token  DECIMAL_SYM                   /* SQL-2003-R */
280
289
%token  DECLARE_SYM                   /* SQL-2003-R */
281
290
%token  DEFAULT                       /* SQL-2003-R */
 
291
%token  DEFINER
282
292
%token  DELETE_SYM                    /* SQL-2003-R */
283
293
%token  DESC                          /* SQL-2003-N */
284
294
%token  DESCRIBE                      /* SQL-2003-R */
287
297
%token  DISCARD
288
298
%token  DISTINCT                      /* SQL-2003-R */
289
299
%token  DIV_SYM
 
300
%token  DOUBLE_SYM                    /* SQL-2003-R */
290
301
%token  DO_SYM
291
 
%token  DOUBLE_SYM                    /* SQL-2003-R */
292
302
%token  DROP                          /* SQL-2003-R */
293
303
%token  DUMPFILE
294
304
%token  DUPLICATE_SYM
326
336
%token  FULL                          /* SQL-2003-R */
327
337
%token  GE
328
338
%token  GLOBAL_SYM                    /* SQL-2003-R */
 
339
%token  GROUP_CONCAT_SYM
329
340
%token  GROUP_SYM                     /* SQL-2003-R */
330
 
%token  GROUP_CONCAT_SYM
331
341
%token  HASH_SYM
332
342
%token  HAVING                        /* SQL-2003-R */
333
343
%token  HEX_NUM
352
362
%token  INTERVAL_SYM                  /* SQL-2003-R */
353
363
%token  INTO                          /* SQL-2003-R */
354
364
%token  INT_SYM                       /* SQL-2003-R */
 
365
%token  INVOKER
355
366
%token  IN_SYM                        /* SQL-2003-R */
356
367
%token  IS                            /* SQL-2003-R */
357
368
%token  ISOLATION                     /* SQL-2003-R */
358
369
%token  ITERATE_SYM
 
370
%token  IPV6_SYM
359
371
%token  JOIN_SYM                      /* SQL-2003-R */
360
372
%token  KEYS
361
373
%token  KEY_BLOCK_SIZE
436
448
%token  READ_WRITE_SYM
437
449
%token  REAL                          /* SQL-2003-R */
438
450
%token  REDUNDANT_SYM
 
451
%token  REFERENCES                    /* SQL-2003-R */
439
452
%token  REGEXP_SYM
440
 
%token  REFERENCES                    /* SQL-2003-R */
441
453
%token  RELEASE_SYM                   /* SQL-2003-R */
442
454
%token  RENAME
443
455
%token  REPEATABLE_SYM                /* SQL-2003-N */
465
477
%token  SEPARATOR_SYM
466
478
%token  SERIALIZABLE_SYM              /* SQL-2003-N */
467
479
%token  SERIAL_SYM
 
480
%token  SERVER_SYM
468
481
%token  SESSION_SYM                   /* SQL-2003-N */
469
 
%token  SERVER_SYM
470
 
%token  SET_SYM                           /* SQL-2003-R */
 
482
%token  SET_SYM                       /* SQL-2003-R */
471
483
%token  SET_VAR
472
484
%token  SHARE_SYM
473
485
%token  SHOW
507
519
%token  TEXT_STRING
508
520
%token  TEXT_SYM
509
521
%token  THEN_SYM                      /* SQL-2003-R */
510
 
%token  TIME_SYM                 /* SQL-2003-R */
511
 
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
512
522
%token  TIMESTAMP_ADD
513
523
%token  TIMESTAMP_DIFF
 
524
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
 
525
%token  TIME_SYM                 /* SQL-2003-R */
514
526
%token  TO_SYM                        /* SQL-2003-R */
515
527
%token  TRAILING                      /* SQL-2003-R */
516
528
%token  TRANSACTION_SYM
533
545
%token  USE_SYM
534
546
%token  USING                         /* SQL-2003-R */
535
547
%token  UTC_DATE_SYM
 
548
%token  UTC_TIME_SYM
536
549
%token  UTC_TIMESTAMP_SYM
 
550
%token  UTF8_SYM
537
551
%token  UUID_SYM
538
552
%token  VALUES                        /* SQL-2003-R */
539
553
%token  VALUE_SYM                     /* SQL-2003-R */
573
587
%nonassoc IN_SYM
574
588
%nonassoc IS NULL_SYM TRUE_SYM FALSE_SYM
575
589
 
576
 
%nonassoc CONCAT
 
590
%left CONCAT
577
591
%nonassoc '|'
578
592
%nonassoc '&'
579
593
%nonassoc SHIFT_LEFT SHIFT_RIGHT
631
645
        opt_status
632
646
        opt_zerofill
633
647
        opt_if_not_exists
634
 
        if_exists 
635
 
        opt_temporary 
 
648
        if_exists
 
649
        opt_temporary
636
650
        opt_field_number_signed
637
651
 
638
652
%type <num>
730
744
 
731
745
%type <boolfunc2creator> comp_op
732
746
 
733
 
%type <build_method> build_method
734
 
 
735
747
%type <NONE>
736
748
        query verb_clause create select drop insert replace insert2
737
749
        insert_values update delete truncate rename
796
808
query:
797
809
          END_OF_INPUT
798
810
          {
799
 
            if (!(YYSession->getLex()->select_lex.options & OPTION_FOUND_COMMENT))
 
811
            if (!(YYSession->lex().select_lex.options & OPTION_FOUND_COMMENT))
800
812
            {
801
813
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
802
814
              DRIZZLE_YYABORT;
803
815
            }
804
816
            else
805
817
            {
806
 
              YYSession->getLex()->statement= new statement::EmptyQuery(YYSession);
 
818
              YYSession->lex().statement= new statement::EmptyQuery(YYSession);
807
819
            }
808
820
          }
809
821
        | verb_clause END_OF_INPUT {}
849
861
create:
850
862
          CREATE CATALOG_SYM catalog_name
851
863
          {
852
 
            Lex->statement= new statement::catalog::Create(YYSession, $3);
 
864
            Lex.statement= new statement::catalog::Create(YYSession, $3);
853
865
          }
854
866
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
855
867
          {
856
 
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
 
868
            Lex.statement= new statement::CreateTable(YYSession, $5, $2);
857
869
 
858
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
 
870
            if (not Lex.select_lex.add_table_to_list(YYSession, $5, NULL,
859
871
                                                     TL_OPTION_UPDATING,
860
872
                                                     TL_WRITE))
861
873
              DRIZZLE_YYABORT;
862
 
            Lex->col_list.clear();
 
874
            Lex.col_list.clear();
863
875
          }
864
876
          create_table_definition
865
877
          {
866
 
            Lex->current_select= &Lex->select_lex;
 
878
            Lex.current_select= &Lex.select_lex;
867
879
          }
868
880
        | CREATE build_method
869
881
          {
870
 
            Lex->statement= new statement::CreateIndex(YYSession, $2);
 
882
            Lex.statement= new statement::CreateIndex(YYSession);
871
883
          }
872
884
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
873
885
          {
874
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
 
886
            if (not Lex.current_select->add_table_to_list(Lex.session, $9,
875
887
                                                            NULL,
876
888
                                                            TL_OPTION_UPDATING))
877
889
              DRIZZLE_YYABORT;
878
890
 
879
 
            parser::buildKey(Lex, $4, $6);
 
891
            parser::buildKey(&Lex, $4, $6);
880
892
          }
881
893
        | CREATE DATABASE opt_if_not_exists schema_name
882
894
          {
883
 
            Lex->statement= new statement::CreateSchema(YYSession);
 
895
            Lex.statement= new statement::CreateSchema(YYSession);
884
896
          }
885
897
          opt_create_database_options
886
898
          {
887
 
            Lex->name= $4;
 
899
            Lex.name= $4;
888
900
          }
889
901
        ;
890
902
 
893
905
          { }
894
906
        | '(' create_select ')'
895
907
           {
896
 
             Lex->current_select->set_braces(1);
 
908
             Lex.current_select->set_braces(1);
897
909
           }
898
910
           union_opt {}
899
911
        |  '(' create_like ')' opt_create_table_options
900
912
          { }
901
913
        | create_like opt_create_table_options
902
914
          { }
903
 
        | opt_create_table_options create_select_as 
 
915
        | opt_create_table_options create_select_as
904
916
          { }
905
917
        ;
906
918
 
908
920
          /* empty */ {}
909
921
        | opt_duplicate_as create_select
910
922
          {
911
 
            Lex->current_select->set_braces(0);
 
923
            Lex.current_select->set_braces(0);
912
924
          }
913
925
          union_clause {}
914
926
        | opt_duplicate_as '(' create_select ')'
915
927
          {
916
 
            Lex->current_select->set_braces(1);
 
928
            Lex.current_select->set_braces(1);
917
929
          }
918
930
          union_opt {}
919
931
        ;
921
933
create_like:
922
934
          LIKE table_ident
923
935
          {
924
 
            ((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
 
936
            ((statement::CreateTable *)(YYSession->lex().statement))->is_create_table_like= true;
925
937
 
926
 
            if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
 
938
            if (not YYSession->lex().select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
927
939
              DRIZZLE_YYABORT;
928
940
          }
929
941
        ;
940
952
stored_select:
941
953
          SELECT_SYM
942
954
          {
943
 
            Lex->lock_option= TL_READ;
944
 
            if (Lex->sql_command == SQLCOM_INSERT)
 
955
            Lex.lock_option= TL_READ;
 
956
            if (Lex.sql_command == SQLCOM_INSERT)
945
957
            {
946
 
              delete Lex->statement;
947
 
              Lex->statement= new statement::InsertSelect(YYSession);
 
958
              delete Lex.statement;
 
959
              Lex.statement= new statement::InsertSelect(YYSession);
948
960
            }
949
 
            else if (Lex->sql_command == SQLCOM_REPLACE)
 
961
            else if (Lex.sql_command == SQLCOM_REPLACE)
950
962
            {
951
 
              delete Lex->statement;
952
 
              Lex->statement= new statement::ReplaceSelect(YYSession);
 
963
              delete Lex.statement;
 
964
              Lex.statement= new statement::ReplaceSelect(YYSession);
953
965
            }
954
966
            /*
955
967
              The following work only with the local list, the global list
956
968
              is created correctly in this case
957
969
            */
958
 
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
959
 
            init_select(Lex);
960
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
970
            Lex.current_select->table_list.save_and_clear(&Lex.save_list);
 
971
            init_select(&Lex);
 
972
            Lex.current_select->parsing_place= SELECT_LIST;
961
973
          }
962
974
          select_options select_item_list
963
975
          {
964
 
            Lex->current_select->parsing_place= NO_MATTER;
 
976
            Lex.current_select->parsing_place= NO_MATTER;
965
977
          }
966
978
          opt_select_from
967
979
          {
969
981
              The following work only with the local list, the global list
970
982
              is created correctly in this case
971
983
            */
972
 
            Lex->current_select->table_list.push_front(&Lex->save_list);
 
984
            Lex.current_select->table_list.push_front(&Lex.save_list);
973
985
          }
974
986
        ;
975
987
 
976
988
opt_create_database_options:
977
989
          /* empty */ {}
978
 
        | default_collation_schema {}
979
 
        | opt_database_custom_options {}
 
990
        | default_collation_schema
 
991
        | default_collation_schema opt_database_custom_options
 
992
        | default_collation_schema ',' opt_database_custom_options
 
993
        | opt_database_custom_options
980
994
        ;
981
995
 
982
996
opt_database_custom_options:
983
997
        custom_database_option
 
998
        | custom_database_option opt_database_custom_options
984
999
        | custom_database_option ',' opt_database_custom_options
985
1000
        ;
986
1001
 
987
1002
custom_database_option:
988
1003
          ident_or_text
989
1004
          {
990
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
991
 
            statement->schema_message.mutable_engine()->add_options()->set_name($1.str);
992
 
          }
993
 
        | REPLICATE opt_equal TRUE_SYM
994
 
          {
995
 
            parser::buildReplicationOption(Lex, true);
996
 
          }
997
 
        | REPLICATE opt_equal FALSE_SYM
998
 
          {
999
 
            parser::buildReplicationOption(Lex, false);
1000
 
          }
1001
 
        | ident_or_text equal ident_or_text
1002
 
          {
1003
 
            parser::buildSchemaOption(Lex, $1.str, $3);
1004
 
          }
1005
 
        | ident_or_text equal ulonglong_num
1006
 
          {
1007
 
            parser::buildSchemaOption(Lex, $1.str, $3);
 
1005
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex.statement;
 
1006
            statement->schema_message.mutable_engine()->add_options()->set_name($1.data());
 
1007
          }
 
1008
        | REPLICATE '=' TRUE_SYM
 
1009
          {
 
1010
            parser::buildReplicationOption(&Lex, true);
 
1011
          }
 
1012
        | REPLICATE '=' FALSE_SYM
 
1013
          {
 
1014
            parser::buildReplicationOption(&Lex, false);
 
1015
          }
 
1016
        | DEFINER TEXT_STRING_sys
 
1017
          {
 
1018
            parser::buildSchemaDefiner(&Lex, identifier::User($2));
 
1019
          }
 
1020
        | DEFINER CURRENT_USER optional_braces
 
1021
          {
 
1022
            parser::buildSchemaDefiner(&Lex, *session->user());
 
1023
          }
 
1024
        | ident_or_text '=' ident_or_text
 
1025
          {
 
1026
            parser::buildSchemaOption(&Lex, $1.data(), $3);
 
1027
          }
 
1028
        | ident_or_text '=' ulonglong_num
 
1029
          {
 
1030
            parser::buildSchemaOption(&Lex, $1.data(), $3);
1008
1031
          }
1009
1032
        ;
1010
1033
 
1015
1038
 
1016
1039
opt_if_not_exists:
1017
1040
          /* empty */ { $$= false; }
1018
 
        | IF NOT_SYM EXISTS { $$= true; YYSession->getLex()->setExists(); }
 
1041
        | IF NOT_SYM EXISTS { $$= true; YYSession->lex().setExists(); }
1019
1042
        ;
1020
1043
 
1021
1044
opt_create_table_options:
1037
1060
          custom_engine_option;
1038
1061
 
1039
1062
custom_engine_option:
1040
 
        ENGINE_SYM equal ident_or_text
 
1063
        ENGINE_SYM '=' ident_or_text
1041
1064
          {
1042
 
            Lex->table()->mutable_engine()->set_name($3.str);
 
1065
            Lex.table()->mutable_engine()->set_name($3.data());
1043
1066
          }
1044
1067
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1045
1068
          {
1046
 
            Lex->table()->mutable_options()->set_comment($3.str);
 
1069
            Lex.table()->mutable_options()->set_comment($3.data());
1047
1070
          }
1048
1071
        | AUTO_INC opt_equal ulonglong_num
1049
1072
          {
1050
 
            Lex->table()->mutable_options()->set_auto_increment_value($3);
1051
 
          }
1052
 
        | REPLICATE opt_equal TRUE_SYM
1053
 
          {
1054
 
            Lex->table()->mutable_options()->set_dont_replicate(false);
1055
 
          }
1056
 
        | REPLICATE opt_equal FALSE_SYM
1057
 
          {
1058
 
            Lex->table()->mutable_options()->set_dont_replicate(true);
1059
 
          }
1060
 
        |  ROW_FORMAT_SYM equal row_format_or_text
1061
 
          {
1062
 
            parser::buildEngineOption(Lex, "ROW_FORMAT", $3);
1063
 
          }
1064
 
        |  FILE_SYM equal TEXT_STRING_sys
1065
 
          {
1066
 
            parser::buildEngineOption(Lex, "FILE", $3);
1067
 
          }
1068
 
        |  ident_or_text equal engine_option_value
1069
 
          {
1070
 
            parser::buildEngineOption(Lex, $1.str, $3);
1071
 
          }
1072
 
        | ident_or_text equal ulonglong_num
1073
 
          {
1074
 
            parser::buildEngineOption(Lex, $1.str, $3);
1075
 
          }
 
1073
            Lex.table()->mutable_options()->set_auto_increment_value($3);
 
1074
          }
 
1075
        | REPLICATE '=' TRUE_SYM
 
1076
          {
 
1077
            message::set_is_replicated(*Lex.table(), true);
 
1078
          }
 
1079
        | REPLICATE '=' FALSE_SYM
 
1080
          {
 
1081
            message::set_is_replicated(*Lex.table(), false);
 
1082
          }
 
1083
        | DEFINER TEXT_STRING_sys
 
1084
          {
 
1085
            message::set_definer(*Lex.table(), identifier::User($2));
 
1086
          }
 
1087
        | DEFINER CURRENT_USER optional_braces
 
1088
          {
 
1089
            message::set_definer(*Lex.table(), *session->user());
 
1090
          }
 
1091
        |  ROW_FORMAT_SYM '=' row_format_or_text
 
1092
          {
 
1093
            parser::buildEngineOption(&Lex, "ROW_FORMAT", $3);
 
1094
          }
 
1095
        |  FILE_SYM '=' TEXT_STRING_sys
 
1096
          {
 
1097
            parser::buildEngineOption(&Lex, "FILE", $3);
 
1098
          }
 
1099
        |  ident_or_text '=' engine_option_value
 
1100
          {
 
1101
            parser::buildEngineOption(&Lex, $1.data(), $3);
 
1102
          }
 
1103
        | ident_or_text '=' ulonglong_num
 
1104
          {
 
1105
            parser::buildEngineOption(&Lex, $1.data(), $3);
 
1106
          }
 
1107
        | default_charset
1076
1108
        | default_collation
1077
1109
        ;
1078
1110
 
 
1111
charset:
 
1112
          CHAR_SYM SET_SYM {}
 
1113
        | CHARSET {}
 
1114
        ;
 
1115
 
 
1116
charset_name_or_default:
 
1117
          UTF8_SYM { } 
 
1118
        | DEFAULT    { }
 
1119
        ;
 
1120
 
 
1121
default_charset:
 
1122
          opt_default charset opt_equal charset_name_or_default
 
1123
        {
 
1124
        }
 
1125
 
1079
1126
default_collation:
1080
1127
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1081
1128
          {
1082
 
            if (not parser::buildCollation(Lex, $4))
 
1129
            if (not parser::buildCollation(&Lex, $4))
1083
1130
            {
1084
1131
              DRIZZLE_YYABORT;
1085
1132
            }
1089
1136
default_collation_schema:
1090
1137
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1091
1138
          {
1092
 
            ((statement::CreateSchema *)Lex->statement)->schema_message.set_collation($4->name);
 
1139
            ((statement::CreateSchema *)Lex.statement)->schema_message.set_collation($4->name);
1093
1140
          }
1094
1141
        ;
1095
1142
 
1105
1152
row_format_or_text:
1106
1153
          row_format
1107
1154
          {
1108
 
            $$.str= YYSession->strmake($1.str, $1.length);
1109
 
            $$.length= $1.length;
 
1155
            $$.assign(YYSession->mem.strdup($1.data(), $1.length), $1.length);
1110
1156
          }
1111
1157
        ;
1112
1158
 
1129
1175
          field_spec opt_check_constraint
1130
1176
        | field_spec references
1131
1177
          {
1132
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1178
            Lex.col_list.clear(); /* Alloced by memory::sql_alloc */
1133
1179
          }
1134
1180
        ;
1135
1181
 
1136
1182
key_def:
1137
1183
          key_type opt_ident key_alg '(' key_list ')' key_options
1138
1184
          {
1139
 
            parser::buildKey(Lex, $1, $2);
 
1185
            parser::buildKey(&Lex, $1, $2);
1140
1186
          }
1141
1187
        | opt_constraint constraint_key_type opt_ident key_alg
1142
1188
          '(' key_list ')' key_options
1143
1189
          {
1144
 
            parser::buildKey(Lex, $2, $3.str ? $3 : $1);
 
1190
            parser::buildKey(&Lex, $2, $3.data() ? $3 : $1);
1145
1191
          }
1146
1192
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1147
1193
          {
1148
 
            parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
 
1194
            parser::buildForeignKey(&Lex, $1.data() ? $1 : $4, $8);
1149
1195
          }
1150
1196
        | constraint opt_check_constraint
1151
1197
          {
1152
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1198
            Lex.col_list.clear(); /* Alloced by memory::sql_alloc */
1153
1199
          }
1154
1200
        | opt_constraint check_constraint
1155
1201
          {
1156
 
            Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
 
1202
            Lex.col_list.clear(); /* Alloced by memory::sql_alloc */
1157
1203
          }
1158
1204
        ;
1159
1205
 
1167
1213
        ;
1168
1214
 
1169
1215
opt_constraint:
1170
 
          /* empty */ { $$= null_lex_str; }
 
1216
          /* empty */ { $$= null_lex_string(); }
1171
1217
        | constraint { $$= $1; }
1172
1218
        ;
1173
1219
 
1178
1224
field_spec:
1179
1225
          field_ident
1180
1226
          {
1181
 
            parser::buildCreateFieldIdent(Lex);
 
1227
            parser::buildCreateFieldIdent(&Lex);
1182
1228
          }
1183
1229
          field_def opt_attribute_comment
1184
1230
          {
1185
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1231
            statement::CreateTable *statement= (statement::CreateTable*)Lex.statement;
1186
1232
 
1187
 
            if (Lex->field())
 
1233
            if (Lex.field())
1188
1234
            {
1189
 
              Lex->field()->set_name($1.str);
 
1235
              Lex.field()->set_name($1.data());
1190
1236
            }
1191
1237
 
1192
 
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1193
 
                                  Lex->length, Lex->dec, Lex->type,
 
1238
            if (add_field_to_list(Lex.session, $1, (enum_field_types) $3,
 
1239
                                  Lex.length, Lex.dec, Lex.type,
1194
1240
                                  statement->column_format,
1195
1241
                                  statement->default_value, statement->on_update_value,
1196
 
                                  &statement->comment,
1197
 
                                  statement->change, &Lex->interval_list, Lex->charset))
 
1242
                                  statement->comment,
 
1243
                                  statement->change, &Lex.interval_list, Lex.charset))
1198
1244
              DRIZZLE_YYABORT;
1199
1245
 
1200
 
            Lex->setField(NULL);
 
1246
            Lex.setField(NULL);
1201
1247
          }
1202
1248
        ;
1203
1249
 
1204
1250
field_def:
1205
1251
          TIMESTAMP_SYM opt_attribute_timestamp
1206
1252
          {
1207
 
            $$=parser::buildTimestampColumn(Lex, NULL);
 
1253
            $$=parser::buildTimestampColumn(&Lex, NULL);
1208
1254
          }
1209
1255
        | TIMESTAMP_SYM '(' NUM ')' opt_attribute_timestamp
1210
1256
          {
1211
 
            $$=parser::buildTimestampColumn(Lex, $3.str);
1212
 
          } 
 
1257
            $$=parser::buildTimestampColumn(&Lex, $3.data());
 
1258
          }
1213
1259
        | DATETIME_SYM opt_attribute_timestamp
1214
1260
          {
1215
1261
            $$=DRIZZLE_TYPE_DATETIME;
1216
1262
 
1217
 
            if (Lex->field())
1218
 
              Lex->field()->set_type(message::Table::Field::DATETIME);
1219
 
          } 
 
1263
            if (Lex.field())
 
1264
              Lex.field()->set_type(message::Table::Field::DATETIME);
 
1265
          }
1220
1266
        | int_type opt_attribute_number
1221
 
          { 
 
1267
          {
1222
1268
            $$= $1;
1223
1269
          }
1224
1270
        | CHAR_SYM opt_attribute_string
1225
1271
          {
1226
 
            $$= parser::buildVarcharColumn(Lex, "1");
 
1272
            $$= parser::buildVarcharColumn(&Lex, "1");
1227
1273
          }
1228
1274
        | varchar '(' NUM ')' opt_attribute_string
1229
1275
          {
1230
 
            $$= parser::buildVarcharColumn(Lex, $3.str);
 
1276
            $$= parser::buildVarcharColumn(&Lex, $3.data());
1231
1277
          }
1232
1278
        | TEXT_SYM opt_attribute_string
1233
1279
          {
1234
1280
            $$=DRIZZLE_TYPE_BLOB;
1235
 
            Lex->length=(char*) 0; /* use default length */
 
1281
            Lex.length= NULL; /* use default length */
1236
1282
 
1237
 
            if (Lex->field())
1238
 
              Lex->field()->set_type(message::Table::Field::BLOB);
 
1283
            if (Lex.field())
 
1284
              Lex.field()->set_type(message::Table::Field::BLOB);
1239
1285
          }
1240
1286
        | ENUM_SYM
1241
1287
          {
1242
 
            Lex->interval_list.clear();
 
1288
            Lex.interval_list.clear();
1243
1289
          }
1244
1290
          '(' string_list ')' opt_attribute_string
1245
1291
          {
1246
1292
            $$=DRIZZLE_TYPE_ENUM;
1247
1293
 
1248
 
            if (Lex->field())
1249
 
              Lex->field()->set_type(message::Table::Field::ENUM);
 
1294
            if (Lex.field())
 
1295
              Lex.field()->set_type(message::Table::Field::ENUM);
1250
1296
          }
1251
1297
        | VARBINARY '(' NUM ')' opt_attribute
1252
1298
          {
1253
 
            $$= parser::buildVarbinaryColumn(Lex, $3.str);
 
1299
            $$= parser::buildVarbinaryColumn(&Lex, $3.data());
1254
1300
          }
1255
1301
        | real_type opt_attribute_number
1256
1302
          {
1257
1303
            assert ($1 == DRIZZLE_TYPE_DOUBLE);
1258
 
            $$= parser::buildDoubleColumn(Lex);
1259
 
          } 
 
1304
            $$= parser::buildDoubleColumn(&Lex);
 
1305
          }
1260
1306
        | DATE_SYM opt_attribute
1261
1307
          {
1262
1308
            $$=DRIZZLE_TYPE_DATE;
1263
1309
 
1264
 
            if (Lex->field())
1265
 
              Lex->field()->set_type(message::Table::Field::DATE);
 
1310
            if (Lex.field())
 
1311
              Lex.field()->set_type(message::Table::Field::DATE);
1266
1312
          }
1267
1313
        | TIME_SYM opt_attribute
1268
1314
          {
1269
1315
            $$=DRIZZLE_TYPE_TIME;
1270
1316
 
1271
 
            if (Lex->field())
1272
 
              Lex->field()->set_type(message::Table::Field::TIME);
 
1317
            if (Lex.field())
 
1318
              Lex.field()->set_type(message::Table::Field::TIME);
1273
1319
          }
1274
1320
        | BLOB_SYM opt_attribute
1275
1321
          {
1276
 
            $$= parser::buildBlobColumn(Lex);
 
1322
            $$= parser::buildBlobColumn(&Lex);
1277
1323
          }
1278
1324
        | DECIMAL_SYM float_options opt_attribute_number
1279
1325
          {
1280
 
            $$= parser::buildDecimalColumn(Lex);
 
1326
            $$= parser::buildDecimalColumn(&Lex);
1281
1327
          }
1282
1328
        | NUMERIC_SYM float_options opt_attribute_number
1283
1329
          {
1284
 
            $$= parser::buildDecimalColumn(Lex);
 
1330
            $$= parser::buildDecimalColumn(&Lex);
1285
1331
          }
1286
1332
        | FIXED_SYM float_options opt_attribute_number
1287
1333
          {
1288
 
            $$= parser::buildDecimalColumn(Lex);
 
1334
            $$= parser::buildDecimalColumn(&Lex);
1289
1335
          }
1290
1336
        | UUID_SYM opt_attribute
1291
1337
          {
1292
 
            $$= parser::buildUuidColumn(Lex);
 
1338
            $$= parser::buildUuidColumn(&Lex);
 
1339
          }
 
1340
        | IPV6_SYM opt_attribute
 
1341
          {
 
1342
            $$= parser::buildIPv6Column(&Lex);
1293
1343
          }
1294
1344
        | BOOLEAN_SYM opt_attribute_boolean
1295
1345
          {
1296
 
            $$= parser::buildBooleanColumn(Lex);
 
1346
            $$= parser::buildBooleanColumn(&Lex);
1297
1347
          }
1298
1348
        | SERIAL_SYM
1299
1349
          {
1300
 
            $$= parser::buildSerialColumn(Lex);
 
1350
            $$= parser::buildSerialColumn(&Lex);
1301
1351
          }
1302
1352
        ;
1303
1353
 
1311
1361
        ;
1312
1362
 
1313
1363
int_type:
1314
 
          INT_SYM  ignored_field_number_length opt_field_number_signed opt_zerofill 
 
1364
          INT_SYM  ignored_field_number_length opt_field_number_signed opt_zerofill
1315
1365
          {
1316
 
            $$= parser::buildIntegerColumn(Lex, DRIZZLE_TYPE_LONG, ($3 or $4));
 
1366
            $$= parser::buildIntegerColumn(&Lex, DRIZZLE_TYPE_LONG, ($3 or $4));
1317
1367
          }
1318
 
        | BIGINT_SYM ignored_field_number_length opt_field_number_signed opt_zerofill 
 
1368
        | BIGINT_SYM ignored_field_number_length opt_field_number_signed opt_zerofill
1319
1369
          {
1320
 
            $$= parser::buildIntegerColumn(Lex, DRIZZLE_TYPE_LONGLONG, ($3 or $4));
 
1370
            $$= parser::buildIntegerColumn(&Lex, DRIZZLE_TYPE_LONGLONG, ($3 or $4));
1321
1371
          }
1322
1372
        ;
1323
1373
 
1338
1388
 
1339
1389
float_options:
1340
1390
          /* empty */
1341
 
          { Lex->dec=Lex->length= (char*)0; }
 
1391
          { Lex.dec=Lex.length= NULL; }
1342
1392
        | '(' NUM ')'
1343
 
          { Lex->length=$2.str; Lex->dec= (char*)0; }
 
1393
          { Lex.length=$2.data(); Lex.dec= NULL; }
1344
1394
        | precision
1345
1395
          {}
1346
1396
        ;
1348
1398
precision:
1349
1399
          '(' NUM ',' NUM ')'
1350
1400
          {
1351
 
            Lex->length= $2.str;
1352
 
            Lex->dec= $4.str;
 
1401
            Lex.length= $2.data();
 
1402
            Lex.dec= $4.data();
1353
1403
          }
1354
1404
        ;
1355
1405
 
1356
1406
opt_len:
1357
 
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
1358
 
        | '(' NUM ')' { Lex->length= $2.str; }
 
1407
          /* empty */ { Lex.length= NULL; /* use default length */ }
 
1408
        | '(' NUM ')' { Lex.length= $2.data(); }
1359
1409
        ;
1360
1410
 
1361
1411
opt_field_number_signed:
1362
1412
          /* empty */ { $$= false; }
1363
1413
        | SIGNED_SYM { $$= false; }
1364
 
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1414
        | UNSIGNED_SYM { $$= true; Lex.type|= UNSIGNED_FLAG; }
1365
1415
        ;
1366
1416
 
1367
1417
ignored_field_number_length:
1371
1421
 
1372
1422
opt_zerofill:
1373
1423
          /* empty */ { $$= false; }
1374
 
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
 
1424
        | ZEROFILL_SYM { $$= true; Lex.type|= UNSIGNED_FLAG; }
1375
1425
        ;
1376
1426
 
1377
1427
opt_precision:
1378
1428
          /* empty */
1379
 
          { Lex->dec=Lex->length= (char*)0; }
 
1429
          { Lex.dec=Lex.length= NULL; }
1380
1430
        | '(' NUM ')'
1381
 
          { Lex->length=Lex->dec= (char*)0; }
 
1431
          { Lex.length=Lex.dec= NULL; }
1382
1432
        | precision
1383
1433
          {}
1384
1434
        ;
1386
1436
opt_attribute_not_null:
1387
1437
          NULL_SYM
1388
1438
          {
1389
 
            Lex->type&= ~ NOT_NULL_FLAG;
 
1439
            Lex.type&= ~ NOT_NULL_FLAG;
1390
1440
          }
1391
1441
        | NOT_SYM NULL_SYM
1392
1442
          {
1393
 
            Lex->type|= NOT_NULL_FLAG;
 
1443
            Lex.type|= NOT_NULL_FLAG;
1394
1444
 
1395
 
            if (Lex->field())
 
1445
            if (Lex.field())
1396
1446
            {
1397
 
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1447
              Lex.field()->mutable_constraints()->set_is_notnull(true);
1398
1448
            }
1399
1449
          }
1400
1450
        ;
1402
1452
opt_attribute_index:
1403
1453
          opt_primary KEY_SYM
1404
1454
          {
1405
 
            parser::buildPrimaryOnColumn(Lex);
 
1455
            parser::buildPrimaryOnColumn(&Lex);
1406
1456
          }
1407
1457
        | UNIQUE_SYM
1408
1458
          {
1409
 
            parser::buildKeyOnColumn(Lex);
 
1459
            parser::buildKeyOnColumn(&Lex);
1410
1460
          }
1411
1461
        | UNIQUE_SYM KEY_SYM
1412
1462
          {
1413
 
            parser::buildKeyOnColumn(Lex);
 
1463
            parser::buildKeyOnColumn(&Lex);
1414
1464
          }
1415
1465
        ;
1416
1466
 
1420
1470
          { }
1421
1471
        | opt_attribute DEFAULT signed_literal
1422
1472
          {
1423
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1473
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1424
1474
 
1425
1475
            statement->default_value= $3;
1426
1476
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1435
1485
          { }
1436
1486
        | opt_attribute_boolean DEFAULT boolean_literal
1437
1487
          {
1438
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1488
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1439
1489
 
1440
1490
            statement->default_value= $3;
1441
1491
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1459
1509
          { }
1460
1510
        | DEFAULT signed_literal
1461
1511
          {
1462
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1512
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1463
1513
 
1464
1514
            statement->default_value=$2;
1465
1515
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1466
1516
          }
1467
1517
        | COLLATE_SYM collation_name
1468
1518
          {
1469
 
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
 
1519
            if (Lex.charset && !my_charset_same(Lex.charset,$2))
1470
1520
            {
1471
1521
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1472
 
                       $2->name,Lex->charset->csname);
 
1522
                       $2->name,Lex.charset->csname);
1473
1523
              DRIZZLE_YYABORT;
1474
1524
            }
1475
1525
            else
1476
1526
            {
1477
 
              Lex->charset=$2;
 
1527
              Lex.charset=$2;
1478
1528
            }
1479
1529
          }
1480
1530
        | opt_attribute_index
1496
1546
          { }
1497
1547
        | AUTO_INC
1498
1548
          {
1499
 
            parser::buildAutoOnColumn(Lex);
 
1549
            parser::buildAutoOnColumn(&Lex);
1500
1550
          }
1501
1551
        | SERIAL_SYM DEFAULT VALUE_SYM
1502
1552
          {
1503
 
            (void)parser::buildSerialColumn(Lex);
 
1553
            (void)parser::buildSerialColumn(&Lex);
1504
1554
          }
1505
1555
        | DEFAULT integer_literal
1506
1556
          {
1507
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1557
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1508
1558
 
1509
1559
            statement->default_value=$2;
1510
1560
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1528
1578
          { }
1529
1579
        | DEFAULT NOW_SYM optional_braces
1530
1580
          {
1531
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1581
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1532
1582
 
1533
1583
            statement->default_value= new Item_func_now_local();
1534
1584
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1535
1585
          }
1536
1586
        | DEFAULT date_literal
1537
1587
          {
1538
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1588
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1539
1589
 
1540
1590
            statement->default_value=$2;
1541
1591
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1542
1592
          }
1543
1593
        | ON UPDATE_SYM NOW_SYM optional_braces
1544
1594
          {
1545
 
            ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local();
 
1595
            ((statement::AlterTable*)Lex.statement)->on_update_value= new Item_func_now_local();
1546
1596
          }
1547
1597
        | opt_attribute_index
1548
1598
          { }
1552
1602
          /* empty */ { }
1553
1603
        | COMMENT_SYM TEXT_STRING_sys
1554
1604
          {
1555
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1605
            statement::AlterTable *statement= (statement::AlterTable*)Lex.statement;
1556
1606
            statement->comment= $2;
1557
1607
 
1558
 
            if (Lex->field())
1559
 
              Lex->field()->set_comment($2.str);
 
1608
            if (Lex.field())
 
1609
              Lex.field()->set_comment($2.data());
1560
1610
          }
1561
1611
        ;
1562
1612
 
1563
1613
collation_name:
1564
1614
          ident_or_text
1565
1615
          {
1566
 
            if (!($$=get_charset_by_name($1.str)))
 
1616
            if (!($$=get_charset_by_name($1.data())))
1567
1617
            {
1568
 
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
 
1618
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.data());
1569
1619
              DRIZZLE_YYABORT;
1570
1620
            }
1571
1621
          }
1595
1645
 
1596
1646
opt_ref_list:
1597
1647
          /* empty */
1598
 
          { Lex->ref_list.clear(); }
 
1648
          { Lex.ref_list.clear(); }
1599
1649
        | '(' ref_list ')'
1600
1650
        ;
1601
1651
 
1602
1652
ref_list:
1603
1653
          ref_list ',' ident
1604
 
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
 
1654
          { Lex.ref_list.push_back(new Key_part_spec($3, 0)); }
1605
1655
        | ident
1606
1656
          {
1607
 
            Lex->ref_list.clear();
1608
 
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1657
            Lex.ref_list.clear();
 
1658
            Lex.ref_list.push_back(new Key_part_spec($1, 0));
1609
1659
          }
1610
1660
        ;
1611
1661
 
1612
1662
opt_match_clause:
1613
1663
          /* empty */
1614
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
 
1664
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
1615
1665
        | MATCH FULL
1616
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
 
1666
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
1617
1667
        | MATCH PARTIAL
1618
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
 
1668
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
1619
1669
        | MATCH SIMPLE_SYM
1620
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
 
1670
          { ((statement::CreateTable*)Lex.statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
1621
1671
        ;
1622
1672
 
1623
1673
opt_on_update_delete:
1624
1674
          /* empty */
1625
1675
          {
1626
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1627
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1676
            ((statement::CreateTable*)Lex.statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1677
            ((statement::CreateTable*)Lex.statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1628
1678
          }
1629
1679
        | ON UPDATE_SYM delete_option
1630
1680
          {
1631
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1632
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1681
            ((statement::CreateTable*)Lex.statement)->fk_update_opt= $3;
 
1682
            ((statement::CreateTable*)Lex.statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1633
1683
          }
1634
1684
        | ON DELETE_SYM delete_option
1635
1685
          {
1636
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1637
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
1686
            ((statement::CreateTable*)Lex.statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1687
            ((statement::CreateTable*)Lex.statement)->fk_delete_opt= $3;
1638
1688
          }
1639
1689
        | ON UPDATE_SYM delete_option
1640
1690
          ON DELETE_SYM delete_option
1641
1691
          {
1642
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1643
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
 
1692
            ((statement::CreateTable *)Lex.statement)->fk_update_opt= $3;
 
1693
            ((statement::CreateTable *)Lex.statement)->fk_delete_opt= $6;
1644
1694
          }
1645
1695
        | ON DELETE_SYM delete_option
1646
1696
          ON UPDATE_SYM delete_option
1647
1697
          {
1648
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
1649
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
1698
            ((statement::CreateTable *)Lex.statement)->fk_update_opt= $6;
 
1699
            ((statement::CreateTable *)Lex.statement)->fk_delete_opt= $3;
1650
1700
          }
1651
1701
        ;
1652
1702
 
1690
1740
 
1691
1741
init_key_options:
1692
1742
          {
1693
 
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
 
1743
            ((statement::CreateTable *)Lex.statement)->key_create_info= default_key_create_info;
1694
1744
          }
1695
1745
        ;
1696
1746
 
1697
1747
/*
1698
 
  For now, key_alg initializies Lex->key_create_info.
 
1748
  For now, key_alg initializies Lex.key_create_info.
1699
1749
  In the future, when all key options are after key definition,
1700
1750
  we can remove key_alg and move init_key_options to key_options
1701
1751
*/
1716
1766
        ;
1717
1767
 
1718
1768
key_using_alg:
1719
 
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
1769
          USING btree_or_rtree     { ((statement::CreateTable *)Lex.statement)->key_create_info.algorithm= $2; }
1720
1770
        ;
1721
1771
 
1722
1772
key_opt:
1723
1773
          key_using_alg
1724
1774
        | KEY_BLOCK_SIZE opt_equal ulong_num
1725
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
 
1775
          { ((statement::CreateTable *)Lex.statement)->key_create_info.block_size= $3; }
1726
1776
        | COMMENT_SYM TEXT_STRING_sys
1727
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
 
1777
          { ((statement::CreateTable *)Lex.statement)->key_create_info.comment= $2; }
1728
1778
        ;
1729
1779
 
1730
1780
btree_or_rtree:
1733
1783
        ;
1734
1784
 
1735
1785
key_list:
1736
 
          key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
1737
 
        | key_part order_dir { Lex->col_list.push_back($1); }
 
1786
          key_list ',' key_part order_dir { Lex.col_list.push_back($3); }
 
1787
        | key_part order_dir { Lex.col_list.push_back($1); }
1738
1788
        ;
1739
1789
 
1740
1790
key_part:
1741
1791
          ident { $$=new Key_part_spec($1, 0); }
1742
1792
        | ident '(' NUM ')'
1743
1793
          {
1744
 
            int key_part_len= atoi($3.str);
 
1794
            int key_part_len= atoi($3.data());
1745
1795
            if (!key_part_len)
1746
1796
            {
1747
 
              my_error(ER_KEY_PART_0, MYF(0), $1.str);
 
1797
              my_error(ER_KEY_PART_0, MYF(0), $1.data());
1748
1798
            }
1749
1799
            $$=new Key_part_spec($1, (uint) key_part_len);
1750
1800
          }
1751
1801
        ;
1752
1802
 
1753
1803
opt_ident:
1754
 
          /* empty */ { $$= null_lex_str; }
 
1804
          /* empty */ { $$= null_lex_string(); }
1755
1805
        | field_ident { $$= $1; }
1756
1806
        ;
1757
1807
 
1758
1808
opt_component:
1759
 
          /* empty */    { $$= null_lex_str; }
 
1809
          /* empty */    { $$= null_lex_string(); }
1760
1810
        | '.' ident      { $$= $2; }
1761
1811
        ;
1762
1812
 
1763
1813
string_list:
1764
 
          text_string { Lex->interval_list.push_back($1); }
1765
 
        | string_list ',' text_string { Lex->interval_list.push_back($3); };
 
1814
          text_string { Lex.interval_list.push_back($1); }
 
1815
        | string_list ',' text_string { Lex.interval_list.push_back($3); };
1766
1816
 
1767
1817
/*
1768
1818
** Alter table
1771
1821
alter:
1772
1822
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
1773
1823
          {
1774
 
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5, $2);
1775
 
            Lex->statement= statement;
1776
 
            Lex->duplicates= DUP_ERROR;
1777
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
 
1824
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5);
 
1825
            Lex.statement= statement;
 
1826
            Lex.duplicates= DUP_ERROR;
 
1827
            if (not Lex.select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
1778
1828
            {
1779
1829
              DRIZZLE_YYABORT;
1780
1830
            }
1781
1831
 
1782
 
            Lex->col_list.clear();
1783
 
            Lex->select_lex.init_order();
1784
 
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
 
1832
            Lex.col_list.clear();
 
1833
            Lex.select_lex.init_order();
 
1834
            Lex.select_lex.db= ((TableList*) Lex.select_lex.table_list.first)->getSchemaName();
1785
1835
          }
1786
1836
          alter_commands
1787
1837
          {}
1788
1838
        | ALTER_SYM DATABASE schema_name
1789
1839
          {
1790
 
            Lex->statement= new statement::AlterSchema(YYSession);
 
1840
            Lex.statement= new statement::AlterSchema(YYSession);
1791
1841
          }
1792
1842
          default_collation_schema
1793
1843
          {
1794
 
            Lex->name= $3;
1795
 
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
1796
 
              DRIZZLE_YYABORT;
 
1844
            Lex.name= $3;
 
1845
            if (not Lex.name.data())
 
1846
            {
 
1847
              str_ref db = Lex.session->copy_db_to();
 
1848
              if (db.empty())
 
1849
                DRIZZLE_YYABORT;
 
1850
              Lex.name.assign(db.data(), db.size());
 
1851
            }
1797
1852
          }
1798
1853
        ;
1799
1854
 
1801
1856
          /* empty */
1802
1857
        | DISCARD TABLESPACE
1803
1858
          {
1804
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1805
 
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE;
 
1859
            message::AlterTable::AlterTableOperation *alter_operation;
 
1860
            alter_operation= Lex.alter_table()->add_operations();
 
1861
            alter_operation->set_operation(message::AlterTable::AlterTableOperation::DISCARD_TABLESPACE);
1806
1862
          }
1807
1863
        | IMPORT TABLESPACE
1808
1864
          {
1809
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1810
 
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE;
 
1865
            message::AlterTable::AlterTableOperation *alter_operation;
 
1866
            alter_operation= Lex.alter_table()->add_operations();
 
1867
            alter_operation->set_operation(message::AlterTable::AlterTableOperation::IMPORT_TABLESPACE);
1811
1868
          }
1812
1869
        | alter_list
1813
1870
        ;
1815
1872
build_method:
1816
1873
        /* empty */
1817
1874
          {
1818
 
            $$= HA_BUILD_DEFAULT;
 
1875
            Lex.alter_table()->set_build_method(message::AlterTable::BUILD_DEFAULT);
1819
1876
          }
1820
1877
        | ONLINE_SYM
1821
1878
          {
1822
 
            $$= HA_BUILD_ONLINE;
 
1879
            Lex.alter_table()->set_build_method(message::AlterTable::BUILD_ONLINE);
1823
1880
          }
1824
1881
        | OFFLINE_SYM
1825
1882
          {
1826
 
            $$= HA_BUILD_OFFLINE;
 
1883
            Lex.alter_table()->set_build_method(message::AlterTable::BUILD_OFFLINE);
1827
1884
          }
1828
1885
        ;
1829
1886
 
1835
1892
add_column:
1836
1893
          ADD_SYM opt_column
1837
1894
          {
1838
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1895
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1839
1896
 
1840
1897
            statement->change=0;
1841
1898
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1846
1903
          add_column column_def opt_place { }
1847
1904
        | ADD_SYM key_def
1848
1905
          {
1849
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1906
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1850
1907
 
1851
1908
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1852
1909
          }
1853
1910
        | add_column '(' field_list ')'
1854
1911
          {
1855
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1912
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1856
1913
 
1857
1914
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
1858
1915
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1859
1916
          }
1860
1917
        | CHANGE_SYM opt_column field_ident
1861
1918
          {
1862
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1863
 
            statement->change= $3.str;
 
1919
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
 
1920
            statement->change= $3.data();
1864
1921
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1865
1922
          }
1866
1923
          field_spec opt_place
1867
1924
        | MODIFY_SYM opt_column field_ident
1868
1925
          {
1869
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1870
 
            Lex->length= Lex->dec=0;
1871
 
            Lex->type= 0;
 
1926
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
 
1927
            Lex.length= Lex.dec=0;
 
1928
            Lex.type= 0;
1872
1929
            statement->default_value= statement->on_update_value= 0;
1873
 
            statement->comment= null_lex_str;
1874
 
            Lex->charset= NULL;
 
1930
            statement->comment= null_lex_string();
 
1931
            Lex.charset= NULL;
1875
1932
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
1876
1933
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1877
1934
 
1878
 
            Lex->setField(NULL);
 
1935
            Lex.setField(NULL);
1879
1936
          }
1880
1937
          field_def opt_attribute_comment
1881
1938
          {
1882
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1939
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1883
1940
 
1884
 
            if (add_field_to_list(Lex->session,&$3,
 
1941
            if (add_field_to_list(Lex.session, $3,
1885
1942
                                  (enum enum_field_types) $5,
1886
 
                                  Lex->length, Lex->dec, Lex->type,
 
1943
                                  Lex.length, Lex.dec, Lex.type,
1887
1944
                                  statement->column_format,
1888
1945
                                  statement->default_value,
1889
1946
                                  statement->on_update_value,
1890
 
                                  &statement->comment,
1891
 
                                  $3.str, &Lex->interval_list, Lex->charset))
 
1947
                                  statement->comment,
 
1948
                                  $3.data(), &Lex.interval_list, Lex.charset))
1892
1949
              DRIZZLE_YYABORT;
1893
1950
          }
1894
1951
          opt_place
1895
1952
        | DROP opt_column field_ident
1896
1953
          {
1897
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1954
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1898
1955
 
1899
 
            statement->alter_info.drop_list.push_back(AlterDrop(AlterDrop::COLUMN, $3.str));
1900
1956
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
 
1957
            message::AlterTable::AlterTableOperation *operation;
 
1958
            operation= Lex.alter_table()->add_operations();
 
1959
            operation->set_operation(message::AlterTable::AlterTableOperation::DROP_COLUMN);
 
1960
            operation->set_drop_name($3.data());
1901
1961
          }
1902
1962
        | DROP FOREIGN KEY_SYM opt_ident
1903
1963
          {
1904
 
            parser::buildAddAlterDropIndex(Lex, $4.str, true);
 
1964
            parser::buildAddAlterDropIndex(&Lex, $4.data(), true);
1905
1965
          }
1906
1966
        | DROP PRIMARY_SYM KEY_SYM
1907
1967
          {
1908
 
            parser::buildAddAlterDropIndex(Lex, "PRIMARY");
 
1968
            parser::buildAddAlterDropIndex(&Lex, "PRIMARY");
1909
1969
          }
1910
1970
        | DROP key_or_index field_ident
1911
1971
          {
1912
 
            parser::buildAddAlterDropIndex(Lex, $3.str);
 
1972
            parser::buildAddAlterDropIndex(&Lex, $3.data());
1913
1973
          }
1914
1974
        | DISABLE_SYM KEYS
1915
1975
          {
1916
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1976
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1917
1977
 
1918
 
            statement->alter_info.keys_onoff= DISABLE;
1919
1978
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
1979
 
 
1980
            message::AlterTable::AlterKeysOnOff *alter_keys_operation;
 
1981
            alter_keys_operation= Lex.alter_table()->mutable_alter_keys_onoff();
 
1982
            alter_keys_operation->set_enable(false);
1920
1983
          }
1921
1984
        | ENABLE_SYM KEYS
1922
1985
          {
1923
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1986
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1924
1987
 
1925
 
            statement->alter_info.keys_onoff= ENABLE;
1926
1988
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
1989
            message::AlterTable::AlterKeysOnOff *alter_keys_operation;
 
1990
            alter_keys_operation= Lex.alter_table()->mutable_alter_keys_onoff();
 
1991
            alter_keys_operation->set_enable(true);
1927
1992
          }
1928
1993
        | ALTER_SYM opt_column field_ident SET_SYM DEFAULT signed_literal
1929
1994
          {
1930
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1995
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1931
1996
 
1932
 
            statement->alter_info.alter_list.push_back(AlterColumn($3.str,$6));
 
1997
            statement->alter_info.alter_list.push_back(AlterColumn($3.data(),$6));
1933
1998
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1934
1999
          }
1935
2000
        | ALTER_SYM opt_column field_ident DROP DEFAULT
1936
2001
          {
1937
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2002
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1938
2003
 
1939
 
            statement->alter_info.alter_list.push_back(AlterColumn($3.str, (Item*) 0));
 
2004
            statement->alter_info.alter_list.push_back(AlterColumn($3.data(), NULL));
1940
2005
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1941
2006
          }
1942
2007
        | RENAME opt_to table_ident
1943
2008
          {
1944
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1945
 
            size_t dummy;
1946
 
 
1947
 
            Lex->select_lex.db=$3->db.str;
1948
 
            if (Lex->select_lex.db == NULL &&
1949
 
                Lex->copy_db_to(&Lex->select_lex.db, &dummy))
1950
 
            {
1951
 
              DRIZZLE_YYABORT;
1952
 
            }
1953
 
 
1954
 
            if (check_table_name($3->table.str,$3->table.length))
1955
 
            {
1956
 
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
1957
 
              DRIZZLE_YYABORT;
1958
 
            }
1959
 
 
1960
 
            Lex->name= $3->table;
 
2009
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
 
2010
            Lex.select_lex.db= $3->db.data();
 
2011
            if (not Lex.select_lex.db)
 
2012
            {
 
2013
              str_ref db = Lex.session->copy_db_to();
 
2014
              if (db.empty())
 
2015
                DRIZZLE_YYABORT;
 
2016
              Lex.select_lex.db = db.data();
 
2017
            }
 
2018
 
 
2019
            if (check_table_name($3->table))
 
2020
            {
 
2021
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.data());
 
2022
              DRIZZLE_YYABORT;
 
2023
            }
 
2024
 
 
2025
            Lex.name= $3->table;
1961
2026
            statement->alter_info.flags.set(ALTER_RENAME);
 
2027
 
 
2028
            message::AlterTable::RenameTable *rename_operation;
 
2029
            rename_operation= Lex.alter_table()->mutable_rename();
 
2030
            rename_operation->set_to_schema(Lex.select_lex.db);
 
2031
            rename_operation->set_to_name(Lex.name.data());
1962
2032
          }
1963
2033
        | CONVERT_SYM TO_SYM collation_name_or_default
1964
2034
          {
1965
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2035
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1966
2036
 
1967
2037
            statement->create_info().table_charset=
1968
2038
            statement->create_info().default_table_charset= $3;
1972
2042
          }
1973
2043
        | create_table_options_space_separated
1974
2044
          {
1975
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2045
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1976
2046
 
1977
2047
            statement->alter_info.flags.set(ALTER_OPTIONS);
1978
2048
          }
1979
2049
        | FORCE_SYM
1980
2050
          {
1981
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2051
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1982
2052
 
1983
2053
            statement->alter_info.flags.set(ALTER_FORCE);
1984
2054
          }
1985
2055
        | alter_order_clause
1986
2056
          {
1987
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2057
            statement::AlterTable *statement= (statement::AlterTable *)Lex.statement;
1988
2058
 
1989
2059
            statement->alter_info.flags.set(ALTER_ORDER);
1990
2060
          }
1996
2066
        ;
1997
2067
 
1998
2068
opt_ignore:
1999
 
          /* empty */ { Lex->ignore= 0;}
2000
 
        | IGNORE_SYM { Lex->ignore= 1;}
 
2069
          /* empty */ { Lex.ignore= 0;}
 
2070
        | IGNORE_SYM { Lex.ignore= 1;}
2001
2071
        ;
2002
2072
 
2003
2073
opt_place:
2004
2074
          /* empty */ {}
2005
2075
        | AFTER_SYM ident
2006
2076
          {
2007
 
            parser::storeAlterColumnPosition(Lex, $2.str);
 
2077
            parser::storeAlterColumnPosition(&Lex, $2.data());
2008
2078
          }
2009
2079
        | FIRST_SYM
2010
2080
          {
2011
 
            parser::storeAlterColumnPosition(Lex, first_keyword);
 
2081
            parser::storeAlterColumnPosition(&Lex, first_keyword);
2012
2082
          }
2013
2083
        ;
2014
2084
 
2021
2091
start:
2022
2092
          START_SYM TRANSACTION_SYM start_transaction_opts
2023
2093
          {
2024
 
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2094
            Lex.statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2025
2095
          }
2026
2096
        ;
2027
2097
 
2036
2106
analyze:
2037
2107
          ANALYZE_SYM table_or_tables
2038
2108
          {
2039
 
            Lex->statement= new statement::Analyze(YYSession);
 
2109
            Lex.statement= new statement::Analyze(YYSession);
2040
2110
          }
2041
2111
          table_list
2042
2112
          {}
2045
2115
check:
2046
2116
          CHECK_SYM table_or_tables
2047
2117
          {
2048
 
            Lex->statement= new statement::Check(YYSession);
 
2118
            Lex.statement= new statement::Check(YYSession);
2049
2119
          }
2050
2120
          table_list
2051
2121
          {}
2054
2124
rename:
2055
2125
          RENAME table_or_tables
2056
2126
          {
2057
 
            Lex->statement= new statement::RenameTable(YYSession);
 
2127
            Lex.statement= new statement::RenameTable(YYSession);
2058
2128
          }
2059
2129
          table_to_table_list
2060
2130
          {}
2068
2138
table_to_table:
2069
2139
          table_ident TO_SYM table_ident
2070
2140
          {
2071
 
            Select_Lex *sl= Lex->current_select;
2072
 
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2141
            Select_Lex *sl= Lex.current_select;
 
2142
            if (!sl->add_table_to_list(Lex.session, $1,NULL,TL_OPTION_UPDATING,
2073
2143
                                       TL_IGNORE) ||
2074
 
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2144
                !sl->add_table_to_list(Lex.session, $3,NULL,TL_OPTION_UPDATING,
2075
2145
                                       TL_IGNORE))
2076
2146
              DRIZZLE_YYABORT;
2077
2147
          }
2085
2155
select:
2086
2156
          select_init
2087
2157
          {
2088
 
            Lex->statement= new statement::Select(YYSession);
 
2158
            Lex.statement= new statement::Select(YYSession);
2089
2159
          }
2090
2160
        ;
2091
2161
 
2098
2168
select_paren:
2099
2169
          SELECT_SYM select_part2
2100
2170
          {
2101
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2171
            if (parser::setup_select_in_parentheses(YYSession, &Lex))
2102
2172
              DRIZZLE_YYABORT;
2103
2173
          }
2104
2174
        | '(' select_paren ')'
2108
2178
select_paren_derived:
2109
2179
          SELECT_SYM select_part2_derived
2110
2180
          {
2111
 
            if (parser::setup_select_in_parentheses(YYSession, Lex))
 
2181
            if (parser::setup_select_in_parentheses(YYSession, &Lex))
2112
2182
              DRIZZLE_YYABORT;
2113
2183
          }
2114
2184
        | '(' select_paren_derived ')'
2117
2187
select_init2:
2118
2188
          select_part2
2119
2189
          {
2120
 
            Select_Lex * sel= Lex->current_select;
2121
 
            if (Lex->current_select->set_braces(0))
 
2190
            Select_Lex * sel= Lex.current_select;
 
2191
            if (Lex.current_select->set_braces(0))
2122
2192
            {
2123
2193
              parser::my_parse_error(YYSession->m_lip);
2124
2194
              DRIZZLE_YYABORT;
2135
2205
 
2136
2206
select_part2:
2137
2207
          {
2138
 
            Select_Lex *sel= Lex->current_select;
 
2208
            Select_Lex *sel= Lex.current_select;
2139
2209
            if (sel->linkage != UNION_TYPE)
2140
 
              init_select(Lex);
2141
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
2210
              init_select(&Lex);
 
2211
            Lex.current_select->parsing_place= SELECT_LIST;
2142
2212
          }
2143
2213
          select_options select_item_list
2144
2214
          {
2145
 
            Lex->current_select->parsing_place= NO_MATTER;
 
2215
            Lex.current_select->parsing_place= NO_MATTER;
2146
2216
          }
2147
2217
          select_into select_lock_type
2148
2218
        ;
2159
2229
          FROM join_table_list where_clause group_clause having_clause
2160
2230
          opt_order_clause opt_limit_clause
2161
2231
          {
2162
 
            Lex->current_select->context.table_list=
2163
 
              Lex->current_select->context.first_name_resolution_table=
2164
 
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
 
2232
            Lex.current_select->context.table_list=
 
2233
              Lex.current_select->context.first_name_resolution_table=
 
2234
                reinterpret_cast<TableList *>(Lex.current_select->table_list.first);
2165
2235
          }
2166
2236
        ;
2167
2237
 
2179
2249
select_option_distinct_or_all:
2180
2250
          DISTINCT
2181
2251
          {
2182
 
            Lex->current_select->options|= SELECT_DISTINCT; 
 
2252
            Lex.current_select->options|= SELECT_DISTINCT;
2183
2253
 
2184
 
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
 
2254
            if (Lex.current_select->options & SELECT_DISTINCT && Lex.current_select->options & SELECT_ALL)
2185
2255
            {
2186
2256
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2187
2257
              DRIZZLE_YYABORT;
2189
2259
          }
2190
2260
        | ALL
2191
2261
          {
2192
 
            Lex->current_select->options|= SELECT_ALL; 
 
2262
            Lex.current_select->options|= SELECT_ALL;
2193
2263
 
2194
 
            if (Lex->current_select->options & SELECT_DISTINCT && Lex->current_select->options & SELECT_ALL)
 
2264
            if (Lex.current_select->options & SELECT_DISTINCT && Lex.current_select->options & SELECT_ALL)
2195
2265
            {
2196
2266
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2197
2267
              DRIZZLE_YYABORT;
2202
2272
select_option_small_or_big:
2203
2273
          SQL_SMALL_RESULT
2204
2274
          {
2205
 
            Lex->current_select->options|= SELECT_SMALL_RESULT;
 
2275
            Lex.current_select->options|= SELECT_SMALL_RESULT;
2206
2276
 
2207
 
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
 
2277
            if (Lex.current_select->options & SELECT_SMALL_RESULT && Lex.current_select->options & SELECT_BIG_RESULT)
2208
2278
            {
2209
2279
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2210
2280
              DRIZZLE_YYABORT;
2212
2282
          }
2213
2283
        | SQL_BIG_RESULT
2214
2284
          {
2215
 
            Lex->current_select->options|= SELECT_BIG_RESULT;
 
2285
            Lex.current_select->options|= SELECT_BIG_RESULT;
2216
2286
 
2217
 
            if (Lex->current_select->options & SELECT_SMALL_RESULT && Lex->current_select->options & SELECT_BIG_RESULT)
 
2287
            if (Lex.current_select->options & SELECT_SMALL_RESULT && Lex.current_select->options & SELECT_BIG_RESULT)
2218
2288
            {
2219
2289
              my_error(ER_WRONG_USAGE, MYF(0), "SELECT_SMALL_RESULT", "SELECT_SMALL_RESULT");
2220
2290
              DRIZZLE_YYABORT;
2224
2294
 
2225
2295
 
2226
2296
select_option:
2227
 
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2297
          STRAIGHT_JOIN { Lex.current_select->options|= SELECT_STRAIGHT_JOIN; }
2228
2298
        | SQL_BUFFER_RESULT
2229
2299
          {
2230
2300
            if (check_simple_select(YYSession))
2231
2301
              DRIZZLE_YYABORT;
2232
 
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
 
2302
            Lex.current_select->options|= OPTION_BUFFER_RESULT;
2233
2303
          }
2234
2304
        | select_option_small_or_big
2235
2305
          { }
2239
2309
          {
2240
2310
            if (check_simple_select(YYSession))
2241
2311
              DRIZZLE_YYABORT;
2242
 
            Lex->current_select->options|= OPTION_FOUND_ROWS;
 
2312
            Lex.current_select->options|= OPTION_FOUND_ROWS;
2243
2313
          }
2244
2314
        ;
2245
2315
 
2247
2317
          /* empty */
2248
2318
        | FOR_SYM UPDATE_SYM
2249
2319
          {
2250
 
            Lex->current_select->set_lock_for_tables(TL_WRITE);
 
2320
            Lex.current_select->set_lock_for_tables(TL_WRITE);
2251
2321
          }
2252
2322
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2253
2323
          {
2254
 
            Lex->current_select->
 
2324
            Lex.current_select->
2255
2325
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2256
2326
          }
2257
2327
        ;
2261
2331
        | select_item
2262
2332
        | '*'
2263
2333
          {
2264
 
            if (YYSession->add_item_to_list( new Item_field(&YYSession->getLex()->current_select->context, NULL, NULL, "*")))
2265
 
              DRIZZLE_YYABORT;
2266
 
 
2267
 
            (YYSession->getLex()->current_select->with_wild)++;
 
2334
            YYSession->add_item_to_list( new Item_field(&YYSession->lex().current_select->context, NULL, NULL, "*"));
 
2335
            YYSession->lex().current_select->with_wild++;
2268
2336
          }
2269
2337
        ;
2270
2338
 
2271
2339
select_item:
2272
2340
          remember_name table_wild remember_end
2273
2341
          {
2274
 
            if (YYSession->add_item_to_list($2))
2275
 
              DRIZZLE_YYABORT;
 
2342
            YYSession->add_item_to_list($2);
2276
2343
          }
2277
2344
        | remember_name expr remember_end select_alias
2278
2345
          {
2279
2346
            assert($1 < $3);
2280
2347
 
2281
 
            if (YYSession->add_item_to_list($2))
2282
 
              DRIZZLE_YYABORT;
 
2348
            YYSession->add_item_to_list($2);
2283
2349
 
2284
 
            if ($4.str)
 
2350
            if ($4.data())
2285
2351
            {
2286
2352
              $2->is_autogenerated_name= false;
2287
 
              $2->set_name($4.str, $4.length, system_charset_info);
 
2353
              $2->set_name($4.data(), $4.size(), system_charset_info);
2288
2354
            }
2289
2355
            else if (!$2->name)
2290
2356
            {
2296
2362
remember_name:
2297
2363
          {
2298
2364
            Lex_input_stream *lip= YYSession->m_lip;
2299
 
            $$= (char*) lip->get_cpp_tok_start();
 
2365
            $$= lip->get_cpp_tok_start();
2300
2366
          }
2301
2367
        ;
2302
2368
 
2303
2369
remember_end:
2304
2370
          {
2305
2371
            Lex_input_stream *lip= YYSession->m_lip;
2306
 
            $$= (char*) lip->get_cpp_tok_end();
 
2372
            $$= lip->get_cpp_tok_end();
2307
2373
          }
2308
2374
        ;
2309
2375
 
2310
2376
select_alias:
2311
 
          /* empty */ { $$=null_lex_str;}
 
2377
          /* empty */ { $$= null_lex_string();}
2312
2378
        | AS ident { $$=$2; }
2313
2379
        | AS TEXT_STRING_sys { $$=$2; }
2314
2380
        | ident { $$=$1; }
2326
2392
          {
2327
2393
            /*
2328
2394
              Design notes:
2329
 
              Do not use a manually maintained stack like session->lex->xxx_list,
 
2395
              Do not use a manually maintained stack like session->Lex.xxx_list,
2330
2396
              but use the internal bison stack ($$, $1 and $3) instead.
2331
2397
              Using the bison stack is:
2332
2398
              - more robust to changes in the grammar,
2420
2486
        | NOT_SYM expr %prec NOT_SYM
2421
2487
          { $$= negate_expression(YYSession, $2); }
2422
2488
        | bool_pri IS TRUE_SYM %prec IS
2423
 
          { 
 
2489
          {
2424
2490
            $$= new (YYSession->mem_root) Item_func_istrue($1);
2425
2491
          }
2426
2492
        | bool_pri IS NOT_SYM TRUE_SYM %prec IS
2513
2579
            $$= item;
2514
2580
          }
2515
2581
        | bit_expr LIKE simple_expr opt_escape
2516
 
          { 
2517
 
            $$= new Item_func_like($1,$3,$4,Lex->escape_used);
 
2582
          {
 
2583
            $$= new Item_func_like($1,$3,$4,Lex.escape_used);
2518
2584
          }
2519
2585
        | bit_expr NOT_SYM LIKE simple_expr opt_escape
2520
 
          { 
2521
 
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used));
 
2586
          {
 
2587
            $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex.escape_used));
2522
2588
          }
2523
2589
        | bit_expr REGEXP_SYM bit_expr
2524
 
          { 
 
2590
          {
2525
2591
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2526
2592
            args->push_back($1);
2527
2593
            args->push_back($3);
2531
2597
            }
2532
2598
          }
2533
2599
        | bit_expr NOT_SYM REGEXP_SYM bit_expr
2534
 
          { 
 
2600
          {
2535
2601
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2536
2602
            args->push_back($1);
2537
2603
            args->push_back($4);
2566
2632
            $$= new Item_func_plus($1,$3);
2567
2633
          }
2568
2634
        | bit_expr '-' bit_expr %prec '-'
2569
 
          { 
 
2635
          {
2570
2636
            $$= new Item_func_minus($1,$3);
2571
2637
          }
2572
2638
        | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
2626
2692
        | function_call_conflict
2627
2693
        | simple_expr COLLATE_SYM ident_or_text %prec UMINUS
2628
2694
          {
2629
 
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
2630
 
                                                      $3.length,
2631
 
                                                      YYSession->charset());
 
2695
            Item *i1= new (YYSession->mem_root) Item_string($3, YYSession->charset());
2632
2696
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
2633
2697
          }
2634
2698
        | literal
2635
2699
        | variable
2636
2700
        | sum_expr
2637
2701
          {
2638
 
            Lex->setSumExprUsed();
 
2702
            Lex.setSumExprUsed();
2639
2703
          }
2640
2704
        | simple_expr CONCAT simple_expr
2641
2705
          {
2677
2741
          }
2678
2742
        | CAST_SYM '(' expr AS cast_type ')'
2679
2743
          {
2680
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2681
 
                                 Lex->charset);
 
2744
            $$= create_func_cast(YYSession, $3, $5, Lex.length, Lex.dec,
 
2745
                                 Lex.charset);
2682
2746
            if (!$$)
2683
2747
              DRIZZLE_YYABORT;
2684
2748
          }
2686
2750
          { $$= new (YYSession->mem_root) Item_func_case(* $3, $2, $4 ); }
2687
2751
        | CONVERT_SYM '(' expr ',' cast_type ')'
2688
2752
          {
2689
 
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
2690
 
                                 Lex->charset);
 
2753
            $$= create_func_cast(YYSession, $3, $5, Lex.length, Lex.dec,
 
2754
                                 Lex.charset);
2691
2755
            if (!$$)
2692
2756
              DRIZZLE_YYABORT;
2693
2757
          }
2694
2758
        | DEFAULT '(' simple_ident ')'
2695
2759
          {
2696
 
            $$= new (YYSession->mem_root) Item_default_value(Lex->current_context(),
 
2760
            $$= new (YYSession->mem_root) Item_default_value(Lex.current_context(),
2697
2761
                                                         $3);
2698
2762
          }
2699
2763
        | VALUES '(' simple_ident ')'
2700
2764
          {
2701
 
            $$= new (YYSession->mem_root) Item_insert_value(Lex->current_context(),
 
2765
            $$= new (YYSession->mem_root) Item_insert_value(Lex.current_context(),
2702
2766
                                                        $3);
2703
2767
          }
2704
2768
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
2721
2785
            {
2722
2786
              DRIZZLE_YYABORT;
2723
2787
            }
2724
 
            Lex->setCacheable(false);
 
2788
            Lex.setCacheable(false);
2725
2789
          }
2726
2790
        | DATE_SYM '(' expr ')'
2727
2791
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
2780
2844
            {
2781
2845
              DRIZZLE_YYABORT;
2782
2846
            }
2783
 
            Lex->setCacheable(false);
 
2847
            Lex.setCacheable(false);
2784
2848
          }
2785
2849
        | YEAR_SYM '(' expr ')'
2786
2850
          { $$= new (YYSession->mem_root) Item_func_year($3); }
2805
2869
          }
2806
2870
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
2807
2871
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
2872
        | CURTIME optional_braces
 
2873
          {
 
2874
            $$= new (YYSession->mem_root) Item_func_curtime_local();
 
2875
            Lex.setCacheable(false);
 
2876
          }
2808
2877
        | CURDATE optional_braces
2809
2878
          {
2810
2879
            $$= new (YYSession->mem_root) Item_func_curdate_local();
2811
 
            Lex->setCacheable(false);
 
2880
            Lex.setCacheable(false);
2812
2881
          }
2813
2882
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
2814
2883
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
2819
2888
        | NOW_SYM optional_braces
2820
2889
          {
2821
2890
            $$= new (YYSession->mem_root) Item_func_now_local();
2822
 
            Lex->setCacheable(false);
 
2891
            Lex.setCacheable(false);
2823
2892
          }
2824
2893
        | NOW_SYM '(' expr ')'
2825
2894
          {
2826
2895
            $$= new (YYSession->mem_root) Item_func_now_local($3);
2827
 
            Lex->setCacheable(false);
 
2896
            Lex.setCacheable(false);
2828
2897
          }
2829
2898
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
2830
2899
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
2878
2947
            }
2879
2948
          }
2880
2949
        | SYSDATE optional_braces
2881
 
          { 
2882
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
2883
 
            Lex->setCacheable(false);
 
2950
          {
 
2951
            $$= new (YYSession->mem_root) Item_func_sysdate_local();
 
2952
            Lex.setCacheable(false);
2884
2953
          }
2885
2954
        | SYSDATE '(' expr ')'
2886
 
          { 
2887
 
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
2888
 
            Lex->setCacheable(false);
 
2955
          {
 
2956
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3);
 
2957
            Lex.setCacheable(false);
2889
2958
          }
2890
2959
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
2891
2960
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
2892
2961
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
2893
2962
          { $$= new (YYSession->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
2963
        | UTC_TIME_SYM optional_braces
 
2964
          {
 
2965
            $$= new (YYSession->mem_root) Item_func_curtime_utc();
 
2966
            Lex.setCacheable(false);
 
2967
          }
2894
2968
        | UTC_DATE_SYM optional_braces
2895
2969
          {
2896
2970
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
2897
 
            Lex->setCacheable(false);
 
2971
            Lex.setCacheable(false);
2898
2972
          }
2899
2973
        | UTC_TIMESTAMP_SYM optional_braces
2900
2974
          {
2901
2975
            $$= new (YYSession->mem_root) Item_func_now_utc();
2902
 
            Lex->setCacheable(false);
 
2976
            Lex.setCacheable(false);
2903
2977
          }
2904
2978
        ;
2905
2979
 
2919
2993
            {
2920
2994
              DRIZZLE_YYABORT;
2921
2995
            }
2922
 
            Lex->setCacheable(false);
 
2996
            Lex.setCacheable(false);
2923
2997
          }
2924
2998
        | CATALOG_SYM '(' ')'
2925
2999
          {
2927
3001
            {
2928
3002
              DRIZZLE_YYABORT;
2929
3003
            }
2930
 
            Lex->setCacheable(false);
 
3004
            Lex.setCacheable(false);
2931
3005
          }
2932
3006
        | EXECUTE_SYM '(' expr ')' opt_wait
2933
3007
          {
2945
3019
            }
2946
3020
          }
2947
3021
        | IF '(' expr ',' expr ',' expr ')'
2948
 
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
 
3022
          { 
 
3023
            $$= new (YYSession->mem_root) Item_func_if($3,$5,$7);
 
3024
          }
2949
3025
        | KILL_SYM kill_option '(' expr ')'
2950
3026
          {
2951
3027
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2988
3064
            {
2989
3065
              DRIZZLE_YYABORT;
2990
3066
            }
2991
 
            Lex->setCacheable(false);
 
3067
            Lex.setCacheable(false);
 
3068
          }
 
3069
        | IPV6_SYM '(' ')'
 
3070
          {
 
3071
            if (! ($$= parser::reserved_keyword_function(YYSession, "ipv6", NULL)))
 
3072
            {
 
3073
              DRIZZLE_YYABORT;
 
3074
            }
 
3075
            Lex.setCacheable(false);
2992
3076
          }
2993
3077
        | WAIT_SYM '(' expr ',' expr ')'
2994
3078
          {
3013
3097
function_call_generic:
3014
3098
          IDENT_sys '('
3015
3099
          {
3016
 
            const plugin::Function *udf= plugin::Function::get(std::string($1.str, $1.length));
 
3100
            const plugin::Function *udf= plugin::Function::get(to_string($1));
3017
3101
 
3018
3102
            /* Temporary placing the result of getFunction in $3 */
3019
3103
            $<udf>$= udf;
3020
3104
          }
3021
3105
          opt_udf_expr_list ')'
3022
3106
          {
3023
 
            Create_func *builder;
3024
3107
            Item *item= NULL;
3025
3108
 
3026
3109
            /*
3032
3115
 
3033
3116
              This will be revised with WL#2128 (SQL PATH)
3034
3117
            */
3035
 
            builder= find_native_function_builder($1);
3036
 
            if (builder)
 
3118
            if (Create_func* builder= find_native_function_builder($1))
3037
3119
            {
3038
3120
              item= builder->create(YYSession, $1, $4);
3039
3121
            }
3040
 
            else
 
3122
            else if (const plugin::Function* udf= $<udf>3) /* Retrieving the result of service::Function::get */
3041
3123
            {
3042
 
              /* Retrieving the result of service::Function::get */
3043
 
              const plugin::Function *udf= $<udf>3;
3044
 
              if (udf)
3045
 
              {
3046
 
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
3047
 
              } else {
3048
 
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3049
 
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3050
 
              }
 
3124
                  item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
 
3125
            } 
 
3126
                        else 
 
3127
                        {
 
3128
              /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
 
3129
              my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.data());
3051
3130
            }
3052
3131
 
3053
 
            if (! ($$= item))
 
3132
            if (not ($$= item))
3054
3133
            {
3055
3134
              DRIZZLE_YYABORT;
3056
3135
            }
3057
 
            Lex->setCacheable(false);
 
3136
            Lex.setCacheable(false);
3058
3137
          }
3059
3138
        ;
3060
3139
 
3085
3164
             because the syntax will not allow having an explicit name here.
3086
3165
             See WL#1017 re. udf attributes.
3087
3166
            */
3088
 
            if ($4.str)
 
3167
            if ($4.data())
3089
3168
            {
3090
3169
              $2->is_autogenerated_name= false;
3091
 
              $2->set_name($4.str, $4.length, system_charset_info);
 
3170
              $2->set_name($4.data(), $4.size(), system_charset_info);
3092
3171
            }
3093
3172
            else
3094
3173
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
3102
3181
        | AVG_SYM '(' DISTINCT in_sum_expr ')'
3103
3182
          { $$=new Item_sum_avg_distinct($4); }
3104
3183
        | COUNT_SYM '(' opt_all '*' ')'
3105
 
          { $$=new Item_sum_count(new Item_int((int32_t) 0L,1)); }
 
3184
          { $$=new Item_sum_count(new Item_int(0, 1)); }
3106
3185
        | COUNT_SYM '(' in_sum_expr ')'
3107
3186
          { $$=new Item_sum_count($3); }
3108
3187
        | COUNT_SYM '(' DISTINCT
3109
 
          { Lex->current_select->in_sum_expr++; }
 
3188
          { Lex.current_select->in_sum_expr++; }
3110
3189
          expr_list
3111
 
          { Lex->current_select->in_sum_expr--; }
 
3190
          { Lex.current_select->in_sum_expr--; }
3112
3191
          ')'
3113
3192
          { $$=new Item_sum_count_distinct(* $5); }
3114
3193
        | MIN_SYM '(' in_sum_expr ')'
3137
3216
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3138
3217
          { $$=new Item_sum_sum_distinct($4); }
3139
3218
        | GROUP_CONCAT_SYM '(' opt_distinct
3140
 
          { Lex->current_select->in_sum_expr++; }
 
3219
          { Lex.current_select->in_sum_expr++; }
3141
3220
          expr_list opt_gorder_clause
3142
3221
          opt_gconcat_separator
3143
3222
          ')'
3144
3223
          {
3145
 
            Select_Lex *sel= Lex->current_select;
 
3224
            Select_Lex *sel= Lex.current_select;
3146
3225
            sel->in_sum_expr--;
3147
 
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
 
3226
            $$=new Item_func_group_concat(Lex.current_context(), $3, $5,
3148
3227
                                          sel->gorder_list, $7);
3149
3228
            $5->clear();
3150
3229
          }
3163
3242
          user_variable_ident SET_VAR expr
3164
3243
          {
3165
3244
            $$= new Item_func_set_user_var($1, $3);
3166
 
            Lex->setCacheable(false);
 
3245
            Lex.setCacheable(false);
3167
3246
          }
3168
3247
        | user_variable_ident
3169
3248
          {
3170
3249
            $$= new Item_func_get_user_var(*YYSession, $1);
3171
 
            Lex->setCacheable(false);
 
3250
            Lex.setCacheable(false);
3172
3251
          }
3173
3252
        | '@' opt_var_ident_type user_variable_ident opt_component
3174
3253
          {
3175
3254
            /* disallow "SELECT @@global.global.variable" */
3176
 
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
 
3255
            if ($3.data() && $4.data() && parser::check_reserved_words($3))
3177
3256
            {
3178
3257
              parser::my_parse_error(YYSession->m_lip);
3179
3258
              DRIZZLE_YYABORT;
3199
3278
opt_gorder_clause:
3200
3279
          /* empty */
3201
3280
          {
3202
 
            Lex->current_select->gorder_list = NULL;
 
3281
            Lex.current_select->gorder_list = NULL;
3203
3282
          }
3204
3283
        | order_clause
3205
3284
          {
3206
 
            Select_Lex *select= Lex->current_select;
3207
 
            select->gorder_list=
3208
 
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
3209
 
                                     sizeof(st_sql_list));
 
3285
            Select_Lex *select= Lex.current_select;
 
3286
            select->gorder_list= (SQL_LIST*) memory::sql_memdup(&select->order_list, sizeof(SQL_LIST));
3210
3287
            select->order_list.clear();
3211
3288
          }
3212
3289
        ;
3214
3291
in_sum_expr:
3215
3292
          opt_all
3216
3293
          {
3217
 
            if (Lex->current_select->inc_in_sum_expr())
 
3294
            if (Lex.current_select->inc_in_sum_expr())
3218
3295
            {
3219
3296
              parser::my_parse_error(YYSession->m_lip);
3220
3297
              DRIZZLE_YYABORT;
3222
3299
          }
3223
3300
          expr
3224
3301
          {
3225
 
            Lex->current_select->in_sum_expr--;
 
3302
            Lex.current_select->in_sum_expr--;
3226
3303
            $$= $3;
3227
3304
          }
3228
3305
        ;
3229
3306
 
3230
3307
cast_type:
3231
3308
          BINARY opt_len
3232
 
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
 
3309
          { $$=ITEM_CAST_CHAR; Lex.charset= &my_charset_bin; Lex.dec= 0; }
3233
3310
        | BOOLEAN_SYM
3234
 
          { $$=ITEM_CAST_BOOLEAN; Lex->charset= &my_charset_bin; Lex->dec= 0; }
 
3311
          { $$=ITEM_CAST_BOOLEAN; Lex.charset= &my_charset_bin; Lex.dec= 0; }
3235
3312
        | SIGNED_SYM
3236
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3313
          { $$=ITEM_CAST_SIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3237
3314
        | SIGNED_SYM INT_SYM
3238
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3315
          { $$=ITEM_CAST_SIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3239
3316
        | INT_SYM
3240
 
          { $$=ITEM_CAST_SIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3317
          { $$=ITEM_CAST_SIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3241
3318
        | UNSIGNED_SYM
3242
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3319
          { $$=ITEM_CAST_UNSIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3243
3320
        | UNSIGNED_SYM INT_SYM
3244
 
          { $$=ITEM_CAST_UNSIGNED; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3321
          { $$=ITEM_CAST_UNSIGNED; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3245
3322
        | CHAR_SYM opt_len
3246
 
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
 
3323
          { $$=ITEM_CAST_CHAR; Lex.dec= 0; }
3247
3324
        | DATE_SYM
3248
 
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3325
          { $$=ITEM_CAST_DATE; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3249
3326
        | TIME_SYM
3250
 
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3327
          { $$=ITEM_CAST_TIME; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3251
3328
        | DATETIME_SYM
3252
 
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
3329
          { $$=ITEM_CAST_DATETIME; Lex.charset= NULL; Lex.dec=Lex.length= NULL; }
3253
3330
        | DECIMAL_SYM float_options
3254
 
          { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
 
3331
          { $$=ITEM_CAST_DECIMAL; Lex.charset= NULL; }
3255
3332
        ;
3256
3333
 
3257
3334
expr_list:
3298
3375
          table_factor { $$=$1; }
3299
3376
        | join_table
3300
3377
          {
3301
 
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
 
3378
            if (!($$= Lex.current_select->nest_last_join(Lex.session)))
3302
3379
              DRIZZLE_YYABORT;
3303
3380
          }
3304
3381
        ;
3344
3421
            left-associative joins.
3345
3422
          */
3346
3423
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
3347
 
          { 
 
3424
          {
3348
3425
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
3349
 
            Lex->is_cross= false;
 
3426
            Lex.is_cross= false;
3350
3427
          }
3351
3428
        | table_ref STRAIGHT_JOIN table_factor
3352
 
          { 
3353
 
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
 
3429
          {
 
3430
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1;
3354
3431
          }
3355
3432
        | table_ref normal_join table_ref
3356
3433
          ON
3357
3434
          {
3358
3435
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3359
 
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
 
3436
            DRIZZLE_YYABORT_UNLESS( not Lex.is_cross );
3360
3437
            /* Change the current name resolution context to a local context. */
3361
 
            if (push_new_name_resolution_context(YYSession, $1, $3))
3362
 
              DRIZZLE_YYABORT;
3363
 
            Lex->current_select->parsing_place= IN_ON;
 
3438
            push_new_name_resolution_context(*YYSession, *$1, *$3);
 
3439
            Lex.current_select->parsing_place= IN_ON;
3364
3440
          }
3365
3441
          expr
3366
3442
          {
3367
3443
            add_join_on($3,$6);
3368
 
            Lex->pop_context();
3369
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3444
            Lex.pop_context();
 
3445
            Lex.current_select->parsing_place= NO_MATTER;
3370
3446
          }
3371
3447
        | table_ref STRAIGHT_JOIN table_factor
3372
3448
          ON
3373
3449
          {
3374
3450
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3375
3451
            /* Change the current name resolution context to a local context. */
3376
 
            if (push_new_name_resolution_context(YYSession, $1, $3))
3377
 
              DRIZZLE_YYABORT;
3378
 
            Lex->current_select->parsing_place= IN_ON;
 
3452
            push_new_name_resolution_context(*YYSession, *$1, *$3);
 
3453
            Lex.current_select->parsing_place= IN_ON;
3379
3454
          }
3380
3455
          expr
3381
3456
          {
3382
3457
            $3->straight=1;
3383
3458
            add_join_on($3,$6);
3384
 
            Lex->pop_context();
3385
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3459
            Lex.pop_context();
 
3460
            Lex.current_select->parsing_place= NO_MATTER;
3386
3461
          }
3387
3462
        | table_ref normal_join table_ref
3388
3463
          USING
3390
3465
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3391
3466
          }
3392
3467
          '(' using_list ')'
3393
 
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
 
3468
          { add_join_natural($1,$3,$7,Lex.current_select); $$=$3; }
3394
3469
        | table_ref NATURAL JOIN_SYM table_factor
3395
3470
          {
3396
3471
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
3397
 
            add_join_natural($1,$4,NULL,Lex->current_select);
 
3472
            add_join_natural($1,$4,NULL,Lex.current_select);
3398
3473
          }
3399
3474
 
3400
3475
          /* LEFT JOIN variants */
3403
3478
          {
3404
3479
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3405
3480
            /* Change the current name resolution context to a local context. */
3406
 
            if (push_new_name_resolution_context(YYSession, $1, $5))
3407
 
              DRIZZLE_YYABORT;
3408
 
            Lex->current_select->parsing_place= IN_ON;
 
3481
            push_new_name_resolution_context(*YYSession, *$1, *$5);
 
3482
            Lex.current_select->parsing_place= IN_ON;
3409
3483
          }
3410
3484
          expr
3411
3485
          {
3412
3486
            add_join_on($5,$8);
3413
 
            Lex->pop_context();
 
3487
            Lex.pop_context();
3414
3488
            $5->outer_join|=JOIN_TYPE_LEFT;
3415
3489
            $$=$5;
3416
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3490
            Lex.current_select->parsing_place= NO_MATTER;
3417
3491
          }
3418
3492
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3419
3493
          {
3421
3495
          }
3422
3496
          USING '(' using_list ')'
3423
3497
          {
3424
 
            add_join_natural($1,$5,$9,Lex->current_select);
 
3498
            add_join_natural($1,$5,$9,Lex.current_select);
3425
3499
            $5->outer_join|=JOIN_TYPE_LEFT;
3426
3500
            $$=$5;
3427
3501
          }
3428
3502
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3429
3503
          {
3430
3504
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3431
 
            add_join_natural($1,$6,NULL,Lex->current_select);
 
3505
            add_join_natural($1,$6,NULL,Lex.current_select);
3432
3506
            $6->outer_join|=JOIN_TYPE_LEFT;
3433
3507
            $$=$6;
3434
3508
          }
3439
3513
          {
3440
3514
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3441
3515
            /* Change the current name resolution context to a local context. */
3442
 
            if (push_new_name_resolution_context(YYSession, $1, $5))
3443
 
              DRIZZLE_YYABORT;
3444
 
            Lex->current_select->parsing_place= IN_ON;
 
3516
            push_new_name_resolution_context(*YYSession, *$1, *$5);
 
3517
            Lex.current_select->parsing_place= IN_ON;
3445
3518
          }
3446
3519
          expr
3447
3520
          {
3448
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3521
            if (!($$= Lex.current_select->convert_right_join()))
3449
3522
              DRIZZLE_YYABORT;
3450
3523
            add_join_on($$, $8);
3451
 
            Lex->pop_context();
3452
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3524
            Lex.pop_context();
 
3525
            Lex.current_select->parsing_place= NO_MATTER;
3453
3526
          }
3454
3527
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3455
3528
          {
3457
3530
          }
3458
3531
          USING '(' using_list ')'
3459
3532
          {
3460
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3533
            if (!($$= Lex.current_select->convert_right_join()))
3461
3534
              DRIZZLE_YYABORT;
3462
 
            add_join_natural($$,$5,$9,Lex->current_select);
 
3535
            add_join_natural($$,$5,$9,Lex.current_select);
3463
3536
          }
3464
3537
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3465
3538
          {
3466
3539
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3467
 
            add_join_natural($6,$1,NULL,Lex->current_select);
3468
 
            if (!($$= Lex->current_select->convert_right_join()))
 
3540
            add_join_natural($6,$1,NULL,Lex.current_select);
 
3541
            if (!($$= Lex.current_select->convert_right_join()))
3469
3542
              DRIZZLE_YYABORT;
3470
3543
          }
3471
3544
        ;
3475
3548
        | INNER_SYM JOIN_SYM {}
3476
3549
        | CROSS JOIN_SYM
3477
3550
          {
3478
 
            Lex->is_cross= true;
3479
 
            Lex->current_select->is_cross= true;
 
3551
            Lex.is_cross= true;
 
3552
            Lex.current_select->is_cross= true;
3480
3553
          }
3481
3554
        ;
3482
3555
 
3486
3559
 
3487
3560
   I.e.
3488
3561
   <table factor> ::= <table primary> [ <sample clause> ]
3489
 
*/  
 
3562
*/
3490
3563
/* Warning - may return NULL in case of incomplete SELECT */
3491
3564
table_factor:
3492
3565
          {
3493
3566
          }
3494
3567
          table_ident opt_table_alias opt_key_definition
3495
3568
          {
3496
 
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
 
3569
            if (!($$= Lex.current_select->add_table_to_list(YYSession, $2, $3,
3497
3570
                             0,
3498
 
                             Lex->lock_option,
3499
 
                             Lex->current_select->pop_index_hints())))
 
3571
                             Lex.lock_option,
 
3572
                             Lex.current_select->pop_index_hints())))
3500
3573
              DRIZZLE_YYABORT;
3501
 
            Lex->current_select->add_joined_table($$);
 
3574
            Lex.current_select->add_joined_table($$);
3502
3575
          }
3503
3576
        | select_derived_init get_select_lex select_derived2
3504
3577
          {
3505
 
            Select_Lex *sel= Lex->current_select;
 
3578
            Select_Lex *sel= Lex.current_select;
3506
3579
            if ($1)
3507
3580
            {
3508
3581
              if (sel->set_braces(1))
3515
3588
                sel->master_unit()->global_parameters=
3516
3589
                   sel->master_unit()->fake_select_lex;
3517
3590
            }
3518
 
            if ($2->init_nested_join(Lex->session))
3519
 
              DRIZZLE_YYABORT;
 
3591
            $2->init_nested_join(*Lex.session);
3520
3592
            $$= 0;
3521
3593
            /* incomplete derived tables return NULL, we must be
3522
3594
               nested in select_derived rule to be here. */
3525
3597
            Represents a flattening of the following rules from the SQL:2003
3526
3598
            standard. This sub-rule corresponds to the sub-rule
3527
3599
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
3528
 
           
 
3600
 
3529
3601
            The following rules have been flattened into query_expression_body
3530
3602
            (since we have no <with clause>).
3531
3603
 
3541
3613
          */
3542
3614
        | '(' get_select_lex select_derived_union ')' opt_table_alias
3543
3615
          {
3544
 
            /* Use $2 instead of Lex->current_select as derived table will
3545
 
               alter value of Lex->current_select. */
 
3616
            /* Use $2 instead of Lex.current_select as derived table will
 
3617
               alter value of Lex.current_select. */
3546
3618
            if (!($3 || $5) && $2->embedding &&
3547
3619
                !$2->embedding->getNestedJoin()->join_list.size())
3548
3620
            {
3557
3629
              /* Handle case of derived table, alias may be NULL if there
3558
3630
                 are no outer parentheses, add_table_to_list() will throw
3559
3631
                 error in this case */
3560
 
              Select_Lex *sel= Lex->current_select;
 
3632
              Select_Lex *sel= Lex.current_select;
3561
3633
              Select_Lex_Unit *unit= sel->master_unit();
3562
 
              Lex->current_select= sel= unit->outer_select();
3563
 
              if (!($$= sel->add_table_to_list(Lex->session,
 
3634
              Lex.current_select= sel= unit->outer_select();
 
3635
              if (!($$= sel->add_table_to_list(Lex.session,
3564
3636
                                               new Table_ident(unit), $5, 0,
3565
3637
                                               TL_READ)))
3566
3638
 
3567
3639
                DRIZZLE_YYABORT;
3568
3640
              sel->add_joined_table($$);
3569
 
              Lex->pop_context();
 
3641
              Lex.pop_context();
3570
3642
            }
3571
3643
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3572
3644
            {
3585
3657
          UNION_SYM
3586
3658
          union_option
3587
3659
          {
3588
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3660
            if (parser::add_select_to_union_list(YYSession, &Lex, (bool)$3))
3589
3661
              DRIZZLE_YYABORT;
3590
3662
          }
3591
3663
          query_specification
3594
3666
              Remove from the name resolution context stack the context of the
3595
3667
              last select in the union.
3596
3668
             */
3597
 
            Lex->pop_context();
 
3669
            Lex.pop_context();
3598
3670
          }
3599
3671
          opt_order_clause opt_limit_clause
3600
3672
        ;
3603
3675
select_init2_derived:
3604
3676
          select_part2_derived
3605
3677
          {
3606
 
            Select_Lex * sel= Lex->current_select;
3607
 
            if (Lex->current_select->set_braces(0))
 
3678
            Select_Lex * sel= Lex.current_select;
 
3679
            if (Lex.current_select->set_braces(0))
3608
3680
            {
3609
3681
              parser::my_parse_error(YYSession->m_lip);
3610
3682
              DRIZZLE_YYABORT;
3621
3693
/* The equivalent of select_part2 for nested queries. */
3622
3694
select_part2_derived:
3623
3695
          {
3624
 
            Select_Lex *sel= Lex->current_select;
 
3696
            Select_Lex *sel= Lex.current_select;
3625
3697
            if (sel->linkage != UNION_TYPE)
3626
 
              init_select(Lex);
3627
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3698
              init_select(&Lex);
 
3699
            Lex.current_select->parsing_place= SELECT_LIST;
3628
3700
          }
3629
3701
          select_options select_item_list
3630
3702
          {
3631
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3703
            Lex.current_select->parsing_place= NO_MATTER;
3632
3704
          }
3633
3705
          opt_select_from select_lock_type
3634
3706
        ;
3637
3709
select_derived:
3638
3710
          get_select_lex
3639
3711
          {
3640
 
            if ($1->init_nested_join(Lex->session))
3641
 
              DRIZZLE_YYABORT;
 
3712
            $1->init_nested_join(*Lex.session);
3642
3713
          }
3643
3714
          derived_table_list
3644
3715
          {
3645
3716
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
3646
3717
               for derived tables, both must equal NULL */
3647
3718
 
3648
 
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
 
3719
            if (!($$= $1->end_nested_join()) && $3)
3649
3720
              DRIZZLE_YYABORT;
3650
3721
 
3651
3722
            if (!$3 && $$)
3658
3729
 
3659
3730
select_derived2:
3660
3731
          {
3661
 
            Lex->derived_tables|= DERIVED_SUBQUERY;
3662
 
            if (not Lex->expr_allows_subselect)
 
3732
            Lex.derived_tables|= DERIVED_SUBQUERY;
 
3733
            if (not Lex.expr_allows_subselect)
3663
3734
            {
3664
3735
              parser::my_parse_error(YYSession->m_lip);
3665
3736
              DRIZZLE_YYABORT;
3666
3737
            }
3667
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
 
3738
            if (Lex.current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(&Lex, 1))
3668
3739
              DRIZZLE_YYABORT;
3669
 
            init_select(Lex);
3670
 
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
3671
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
3740
            init_select(&Lex);
 
3741
            Lex.current_select->linkage= DERIVED_TABLE_TYPE;
 
3742
            Lex.current_select->parsing_place= SELECT_LIST;
3672
3743
          }
3673
3744
          select_options select_item_list
3674
3745
          {
3675
 
            Lex->current_select->parsing_place= NO_MATTER;
 
3746
            Lex.current_select->parsing_place= NO_MATTER;
3676
3747
          }
3677
3748
          opt_select_from
3678
3749
        ;
3679
3750
 
3680
3751
get_select_lex:
3681
 
          /* Empty */ { $$= Lex->current_select; }
 
3752
          /* Empty */ { $$= Lex.current_select; }
3682
3753
        ;
3683
3754
 
3684
3755
select_derived_init:
3685
3756
          SELECT_SYM
3686
3757
          {
3687
 
            Select_Lex *sel= Lex->current_select;
 
3758
            Select_Lex *sel= Lex.current_select;
3688
3759
            TableList *embedding;
3689
 
            if (!sel->embedding || sel->end_nested_join(Lex->session))
 
3760
            if (!sel->embedding || sel->end_nested_join())
3690
3761
            {
3691
3762
              /* we are not in parentheses */
3692
3763
              parser::my_parse_error(YYSession->m_lip);
3693
3764
              DRIZZLE_YYABORT;
3694
3765
            }
3695
 
            embedding= Lex->current_select->embedding;
 
3766
            embedding= Lex.current_select->embedding;
3696
3767
            $$= embedding &&
3697
3768
                !embedding->getNestedJoin()->join_list.size();
3698
3769
            /* return true if we are deeply nested */
3722
3793
index_hint_definition:
3723
3794
          index_hint_type key_or_index index_hint_clause
3724
3795
          {
3725
 
            Lex->current_select->set_index_hint_type($1, $3);
 
3796
            Lex.current_select->set_index_hint_type($1, $3);
3726
3797
          }
3727
3798
          '(' key_usage_list ')'
3728
3799
        | USE_SYM key_or_index index_hint_clause
3729
3800
          {
3730
 
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
 
3801
            Lex.current_select->set_index_hint_type(INDEX_HINT_USE, $3);
3731
3802
          }
3732
3803
          '(' opt_key_usage_list ')'
3733
3804
       ;
3739
3810
 
3740
3811
opt_index_hints_list:
3741
3812
          /* empty */
3742
 
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
 
3813
        | { Lex.current_select->alloc_index_hints(YYSession); } index_hints_list
3743
3814
        ;
3744
3815
 
3745
3816
opt_key_definition:
3746
 
          {  Lex->current_select->clear_index_hints(); }
 
3817
          {  Lex.current_select->clear_index_hints(); }
3747
3818
          opt_index_hints_list
3748
3819
        ;
3749
3820
 
3750
3821
opt_key_usage_list:
3751
 
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
 
3822
          /* empty */ { Lex.current_select->add_index_hint(YYSession, NULL); }
3752
3823
        | key_usage_list {}
3753
3824
        ;
3754
3825
 
3755
3826
key_usage_element:
3756
3827
          ident
3757
 
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
 
3828
          { Lex.current_select->add_index_hint(YYSession, $1.data()); }
3758
3829
        | PRIMARY_SYM
3759
 
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
 
3830
          { Lex.current_select->add_index_hint(YYSession, "PRIMARY"); }
3760
3831
        ;
3761
3832
 
3762
3833
key_usage_list:
3767
3838
using_list:
3768
3839
          ident
3769
3840
          {
3770
 
            if (!($$= new List<String>))
3771
 
              DRIZZLE_YYABORT;
3772
 
            $$->push_back(new (YYSession->mem_root)
3773
 
                              String((const char *) $1.str, $1.length,
3774
 
                                      system_charset_info));
 
3841
            $$= new List<String>;
 
3842
            $$->push_back(new (YYSession->mem_root) String($1.data(), $1.size(), system_charset_info));
3775
3843
          }
3776
3844
        | using_list ',' ident
3777
3845
          {
3778
 
            $1->push_back(new (YYSession->mem_root)
3779
 
                              String((const char *) $3.str, $3.length,
3780
 
                                      system_charset_info));
 
3846
            $1->push_back(new (YYSession->mem_root) String($3.data(), $3.size(), system_charset_info));
3781
3847
            $$= $1;
3782
3848
          }
3783
3849
        ;
3837
3903
          /* empty */ { $$=0; }
3838
3904
        | table_alias ident
3839
3905
          {
3840
 
            $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING));
 
3906
            $$= (drizzled::lex_string_t*) memory::sql_memdup(&$2,sizeof(drizzled::lex_string_t));
3841
3907
          }
3842
3908
        ;
3843
3909
 
3847
3913
        ;
3848
3914
 
3849
3915
where_clause:
3850
 
          /* empty */  { Lex->current_select->where= 0; }
 
3916
          /* empty */  { Lex.current_select->where= 0; }
3851
3917
        | WHERE
3852
3918
          {
3853
 
            Lex->current_select->parsing_place= IN_WHERE;
 
3919
            Lex.current_select->parsing_place= IN_WHERE;
3854
3920
          }
3855
3921
          expr
3856
3922
          {
3857
 
            Select_Lex *select= Lex->current_select;
 
3923
            Select_Lex *select= Lex.current_select;
3858
3924
            select->where= $3;
3859
3925
            select->parsing_place= NO_MATTER;
3860
3926
            if ($3)
3866
3932
          /* empty */
3867
3933
        | HAVING
3868
3934
          {
3869
 
            Lex->current_select->parsing_place= IN_HAVING;
 
3935
            Lex.current_select->parsing_place= IN_HAVING;
3870
3936
          }
3871
3937
          expr
3872
3938
          {
3873
 
            Select_Lex *sel= Lex->current_select;
 
3939
            Select_Lex *sel= Lex.current_select;
3874
3940
            sel->having= $3;
3875
3941
            sel->parsing_place= NO_MATTER;
3876
3942
            if ($3)
3881
3947
opt_escape:
3882
3948
          ESCAPE_SYM simple_expr
3883
3949
          {
3884
 
            Lex->escape_used= true;
 
3950
            Lex.escape_used= true;
3885
3951
            $$= $2;
3886
3952
          }
3887
3953
        | /* empty */
3888
3954
          {
3889
 
            Lex->escape_used= false;
3890
 
            $$= new Item_string("\\", 1, &my_charset_utf8_general_ci);
 
3955
            Lex.escape_used= false;
 
3956
            $$= new Item_string(str_ref("\\"), &my_charset_utf8_general_ci);
3891
3957
          }
3892
3958
        ;
3893
3959
 
3902
3968
 
3903
3969
group_list:
3904
3970
          group_list ',' order_ident order_dir
3905
 
          { if (YYSession->add_group_to_list($3,(bool) $4)) DRIZZLE_YYABORT; }
 
3971
          { YYSession->add_group_to_list($3,(bool) $4); }
3906
3972
        | order_ident order_dir
3907
 
          { if (YYSession->add_group_to_list($1,(bool) $2)) DRIZZLE_YYABORT; }
 
3973
          { YYSession->add_group_to_list($1,(bool) $2); }
3908
3974
        ;
3909
3975
 
3910
3976
olap_opt:
3918
3984
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
3919
3985
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
3920
3986
            */
3921
 
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
3987
            if (Lex.current_select->linkage == GLOBAL_OPTIONS_TYPE)
3922
3988
            {
3923
3989
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
3924
3990
                       "global union parameters");
3925
3991
              DRIZZLE_YYABORT;
3926
3992
            }
3927
 
            Lex->current_select->olap= ROLLUP_TYPE;
 
3993
            Lex.current_select->olap= ROLLUP_TYPE;
3928
3994
          }
3929
3995
        ;
3930
3996
 
3944
4010
alter_order_item:
3945
4011
          simple_ident order_dir
3946
4012
          {
3947
 
            bool ascending= ($2 == 1) ? true : false;
3948
 
            if (YYSession->add_order_to_list($1, ascending))
3949
 
              DRIZZLE_YYABORT;
 
4013
            bool ascending= $2 == 1;
 
4014
            YYSession->add_order_to_list($1, ascending);
3950
4015
          }
3951
4016
        ;
3952
4017
 
3962
4027
order_clause:
3963
4028
          ORDER_SYM BY
3964
4029
          {
3965
 
            if (not parser::buildOrderBy(Lex))
 
4030
            if (not parser::buildOrderBy(&Lex))
3966
4031
              DRIZZLE_YYABORT;
3967
4032
          }
3968
4033
          order_list
3971
4036
order_list:
3972
4037
          order_list ',' order_ident order_dir
3973
4038
          {
3974
 
            if (YYSession->add_order_to_list($3,(bool) $4))
3975
 
              DRIZZLE_YYABORT;
 
4039
            YYSession->add_order_to_list($3,(bool) $4);
3976
4040
          }
3977
4041
        | order_ident order_dir
3978
4042
          {
3979
 
            if (YYSession->add_order_to_list($1,(bool) $2))
3980
 
              DRIZZLE_YYABORT;
 
4043
            YYSession->add_order_to_list($1,(bool) $2);
3981
4044
          }
3982
4045
        ;
3983
4046
 
3990
4053
opt_limit_clause_init:
3991
4054
          /* empty */
3992
4055
          {
3993
 
            Select_Lex *sel= Lex->current_select;
 
4056
            Select_Lex *sel= Lex.current_select;
3994
4057
            sel->offset_limit= 0;
3995
4058
            sel->select_limit= 0;
3996
4059
          }
4009
4072
limit_options:
4010
4073
          limit_option
4011
4074
          {
4012
 
            Select_Lex *sel= Lex->current_select;
 
4075
            Select_Lex *sel= Lex.current_select;
4013
4076
            sel->select_limit= $1;
4014
4077
            sel->offset_limit= 0;
4015
4078
            sel->explicit_limit= 1;
4016
4079
          }
4017
4080
        | limit_option ',' limit_option
4018
4081
          {
4019
 
            Select_Lex *sel= Lex->current_select;
 
4082
            Select_Lex *sel= Lex.current_select;
4020
4083
            sel->select_limit= $3;
4021
4084
            sel->offset_limit= $1;
4022
4085
            sel->explicit_limit= 1;
4023
4086
          }
4024
4087
        | limit_option OFFSET_SYM limit_option
4025
4088
          {
4026
 
            Select_Lex *sel= Lex->current_select;
 
4089
            Select_Lex *sel= Lex.current_select;
4027
4090
            sel->select_limit= $1;
4028
4091
            sel->offset_limit= $3;
4029
4092
            sel->explicit_limit= 1;
4031
4094
        ;
4032
4095
 
4033
4096
limit_option:
4034
 
          ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
4035
 
        | LONG_NUM      { $$= new Item_uint($1.str, $1.length); }
4036
 
        | NUM           { $$= new Item_uint($1.str, $1.length); }
 
4097
          ULONGLONG_NUM { $$= new Item_uint($1.data(), $1.size()); }
 
4098
        | LONG_NUM      { $$= new Item_uint($1.data(), $1.size()); }
 
4099
        | NUM           { $$= new Item_uint($1.data(), $1.size()); }
4037
4100
        ;
4038
4101
 
4039
4102
delete_limit_clause:
4040
4103
          /* empty */
4041
4104
          {
4042
 
            Lex->current_select->select_limit= 0;
 
4105
            Lex.current_select->select_limit= 0;
4043
4106
          }
4044
4107
        | LIMIT limit_option
4045
4108
          {
4046
 
            Select_Lex *sel= Lex->current_select;
 
4109
            Select_Lex *sel= Lex.current_select;
4047
4110
            sel->select_limit= $2;
4048
4111
            sel->explicit_limit= 1;
4049
4112
          }
4050
4113
        ;
4051
4114
 
4052
4115
ulong_num:
4053
 
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
4054
 
        | HEX_NUM       { $$= (unsigned long) strtol($1.str, (char**) 0, 16); }
4055
 
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
4056
 
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
4057
 
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
4058
 
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4116
          NUM           { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
 
4117
        | HEX_NUM       { $$= (unsigned long) strtol($1.data(), NULL, 16); }
 
4118
        | LONG_NUM      { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
 
4119
        | ULONGLONG_NUM { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
 
4120
        | DECIMAL_NUM   { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
 
4121
        | FLOAT_NUM     { int error; $$= (unsigned long) internal::my_strtoll10($1.data(), NULL, &error); }
4059
4122
        ;
4060
4123
 
4061
4124
ulonglong_num:
4062
 
          NUM           { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4063
 
        | ULONGLONG_NUM { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4064
 
        | LONG_NUM      { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4065
 
        | DECIMAL_NUM   { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4066
 
        | FLOAT_NUM     { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4125
          NUM           { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
 
4126
        | ULONGLONG_NUM { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
 
4127
        | LONG_NUM      { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
 
4128
        | DECIMAL_NUM   { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
 
4129
        | FLOAT_NUM     { int error; $$= (uint64_t) internal::my_strtoll10($1.data(), NULL, &error); }
4067
4130
        ;
4068
4131
 
4069
4132
select_var_list_init:
4070
4133
          {
4071
 
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
4072
 
              DRIZZLE_YYABORT;
 
4134
            if (not Lex.describe)
 
4135
                          Lex.result= new select_dumpvar;
4073
4136
          }
4074
4137
          select_var_list
4075
4138
          {}
4080
4143
        | select_var_ident {}
4081
4144
        ;
4082
4145
 
4083
 
select_var_ident: 
 
4146
select_var_ident:
4084
4147
          '@' user_variable_ident
4085
4148
          {
4086
 
            if (Lex->result)
 
4149
            if (Lex.result)
4087
4150
            {
4088
 
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
 
4151
              ((select_dumpvar *)Lex.result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
4089
4152
            }
4090
4153
            else
4091
4154
            {
4093
4156
                The parser won't create select_result instance only
4094
4157
                if it's an EXPLAIN.
4095
4158
              */
4096
 
              assert(Lex->describe);
 
4159
              assert(Lex.describe);
4097
4160
            }
4098
4161
          }
4099
4162
        ;
4107
4170
into_destination:
4108
4171
          OUTFILE TEXT_STRING_filesystem
4109
4172
          {
4110
 
            Lex->setCacheable(false);
4111
 
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
4112
 
                !(Lex->result= new select_export(Lex->exchange)))
4113
 
              DRIZZLE_YYABORT;
 
4173
            Lex.setCacheable(false);
 
4174
            Lex.exchange= new file_exchange($2.data(), 0);
 
4175
            Lex.result= new select_export(Lex.exchange);
4114
4176
          }
4115
4177
          opt_field_term opt_line_term
4116
4178
        | DUMPFILE TEXT_STRING_filesystem
4117
4179
          {
4118
 
            if (not Lex->describe)
 
4180
            if (not Lex.describe)
4119
4181
            {
4120
 
              Lex->setCacheable(false);
4121
 
              if (not (Lex->exchange= new file_exchange($2.str,1)))
4122
 
                DRIZZLE_YYABORT;
4123
 
              if (not (Lex->result= new select_dump(Lex->exchange)))
4124
 
                DRIZZLE_YYABORT;
 
4182
              Lex.setCacheable(false);
 
4183
              Lex.exchange= new file_exchange($2.data(),1);
 
4184
              Lex.result= new select_dump(Lex.exchange);
4125
4185
            }
4126
4186
          }
4127
4187
        | select_var_list_init
4128
 
          {Lex->setCacheable(false);}
 
4188
          {Lex.setCacheable(false);}
4129
4189
        ;
4130
4190
 
4131
4191
/*
4135
4195
drop:
4136
4196
          DROP CATALOG_SYM catalog_name
4137
4197
          {
4138
 
            Lex->statement= new statement::catalog::Drop(YYSession, $3);
 
4198
            Lex.statement= new statement::catalog::Drop(YYSession, $3);
4139
4199
          }
4140
4200
        | DROP opt_temporary table_or_tables if_exists table_list
4141
4201
          {
4142
4202
            statement::DropTable *statement= new statement::DropTable(YYSession);
4143
 
            Lex->statement= statement;
 
4203
            Lex.statement= statement;
4144
4204
            statement->drop_temporary= $2;
4145
4205
            statement->drop_if_exists= $4;
4146
4206
          }
4147
4207
        | DROP build_method INDEX_SYM ident ON table_ident {}
4148
4208
          {
4149
4209
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
4150
 
            Lex->statement= statement;
 
4210
            Lex.statement= statement;
4151
4211
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4152
 
            statement->alter_info.build_method= $2;
4153
 
            statement->alter_info.drop_list.push_back(AlterDrop(AlterDrop::KEY, $4.str));
4154
 
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
 
4212
 
 
4213
            if (not Lex.current_select->add_table_to_list(Lex.session, $6, NULL,
4155
4214
                                                          TL_OPTION_UPDATING))
4156
4215
              DRIZZLE_YYABORT;
 
4216
 
 
4217
            message::AlterTable::AlterTableOperation *operation;
 
4218
            operation= Lex.alter_table()->add_operations();
 
4219
            operation->set_operation(message::AlterTable::AlterTableOperation::DROP_KEY);
 
4220
            operation->set_drop_name($4.data());
 
4221
 
4157
4222
          }
4158
4223
        | DROP DATABASE if_exists schema_name
4159
4224
          {
4160
4225
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
4161
 
            Lex->statement= statement;
 
4226
            Lex.statement= statement;
4162
4227
            statement->drop_if_exists=$3;
4163
 
            Lex->name= $4;
 
4228
            Lex.name= $4;
4164
4229
          }
4165
4230
        ;
4166
4231
 
4172
4237
table_name:
4173
4238
          table_ident
4174
4239
          {
4175
 
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
 
4240
            if (!Lex.current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4176
4241
              DRIZZLE_YYABORT;
4177
4242
          }
4178
4243
        ;
4194
4259
execute:
4195
4260
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
4196
4261
        {
4197
 
          Lex->statement= new statement::Execute(YYSession, $2, $3, $4, $5);
 
4262
          Lex.statement= new statement::Execute(YYSession, $2, $3, $4, $5);
4198
4263
        }
4199
4264
 
4200
4265
 
4230
4295
insert:
4231
4296
          INSERT
4232
4297
          {
4233
 
            Lex->statement= new statement::Insert(YYSession);
4234
 
            Lex->duplicates= DUP_ERROR;
4235
 
            init_select(Lex);
 
4298
            Lex.statement= new statement::Insert(YYSession);
 
4299
            Lex.duplicates= DUP_ERROR;
 
4300
            init_select(&Lex);
4236
4301
            /* for subselects */
4237
 
            Lex->lock_option= TL_READ;
 
4302
            Lex.lock_option= TL_READ;
4238
4303
          }
4239
4304
          opt_ignore insert2
4240
4305
          {
4241
 
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4242
 
            Lex->current_select= &Lex->select_lex;
 
4306
            Lex.current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
 
4307
            Lex.current_select= &Lex.select_lex;
4243
4308
          }
4244
4309
          insert_field_spec opt_insert_update
4245
4310
          {}
4248
4313
replace:
4249
4314
          REPLACE
4250
4315
          {
4251
 
            Lex->statement= new statement::Replace(YYSession);
4252
 
            Lex->duplicates= DUP_REPLACE;
4253
 
            init_select(Lex);
 
4316
            Lex.statement= new statement::Replace(YYSession);
 
4317
            Lex.duplicates= DUP_REPLACE;
 
4318
            init_select(&Lex);
4254
4319
          }
4255
4320
          insert2
4256
4321
          {
4257
 
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4258
 
            Lex->current_select= &Lex->select_lex;
 
4322
            Lex.current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4323
            Lex.current_select= &Lex.select_lex;
4259
4324
          }
4260
4325
          insert_field_spec
4261
4326
          {}
4269
4334
insert_table:
4270
4335
          table_name
4271
4336
          {
4272
 
            Lex->field_list.clear();
4273
 
            Lex->many_values.clear();
4274
 
            Lex->insert_list=0;
 
4337
            Lex.field_list.clear();
 
4338
            Lex.many_values.clear();
 
4339
            Lex.insert_list=0;
4275
4340
          };
4276
4341
 
4277
4342
insert_field_spec:
4280
4345
        | '(' fields ')' insert_values {}
4281
4346
        | SET_SYM
4282
4347
          {
4283
 
            if (not (Lex->insert_list = new List_item) ||
4284
 
                Lex->many_values.push_back(Lex->insert_list))
4285
 
              DRIZZLE_YYABORT;
 
4348
            Lex.insert_list = new List_item;
 
4349
            Lex.many_values.push_back(Lex.insert_list);
4286
4350
          }
4287
4351
          ident_eq_list
4288
4352
        ;
4289
4353
 
4290
4354
fields:
4291
 
          fields ',' insert_ident { Lex->field_list.push_back($3); }
4292
 
        | insert_ident { Lex->field_list.push_back($1); }
 
4355
          fields ',' insert_ident { Lex.field_list.push_back($3); }
 
4356
        | insert_ident { Lex.field_list.push_back($1); }
4293
4357
        ;
4294
4358
 
4295
4359
insert_values:
4297
4361
        | VALUE_SYM values_list {}
4298
4362
        | stored_select
4299
4363
          {
4300
 
            Lex->current_select->set_braces(0);
 
4364
            Lex.current_select->set_braces(0);
4301
4365
          }
4302
4366
          union_clause {}
4303
4367
        | '(' stored_select ')'
4304
4368
          {
4305
 
            Lex->current_select->set_braces(1);
 
4369
            Lex.current_select->set_braces(1);
4306
4370
          }
4307
4371
          union_opt {}
4308
4372
        ;
4320
4384
ident_eq_value:
4321
4385
          simple_ident equal expr_or_default
4322
4386
          {
4323
 
            if (Lex->field_list.push_back($1) ||
4324
 
                Lex->insert_list->push_back($3))
4325
 
              DRIZZLE_YYABORT;
 
4387
            Lex.field_list.push_back($1);
 
4388
            Lex.insert_list->push_back($3);
4326
4389
          }
4327
4390
        ;
4328
4391
 
4333
4396
 
4334
4397
opt_equal:
4335
4398
          /* empty */ {}
4336
 
        | equal {}
 
4399
        | '=' {}
4337
4400
        ;
4338
4401
 
4339
4402
no_braces:
4340
4403
          '('
4341
4404
          {
4342
 
              if (!(Lex->insert_list = new List_item))
4343
 
                DRIZZLE_YYABORT;
 
4405
              Lex.insert_list = new List_item;
4344
4406
          }
4345
4407
          opt_values ')'
4346
4408
          {
4347
 
            if (Lex->many_values.push_back(Lex->insert_list))
4348
 
              DRIZZLE_YYABORT;
 
4409
            Lex.many_values.push_back(Lex.insert_list);
4349
4410
          }
4350
4411
        ;
4351
4412
 
4357
4418
values:
4358
4419
          values ','  expr_or_default
4359
4420
          {
4360
 
            if (Lex->insert_list->push_back($3))
4361
 
              DRIZZLE_YYABORT;
 
4421
            Lex.insert_list->push_back($3);
4362
4422
          }
4363
4423
        | expr_or_default
4364
4424
          {
4365
 
            if (Lex->insert_list->push_back($1))
4366
 
              DRIZZLE_YYABORT;
 
4425
            Lex.insert_list->push_back($1);
4367
4426
          }
4368
4427
        ;
4369
4428
 
4370
4429
expr_or_default:
4371
4430
          expr { $$= $1;}
4372
 
        | DEFAULT {$$= new Item_default_value(Lex->current_context()); }
 
4431
        | DEFAULT {$$= new Item_default_value(Lex.current_context()); }
4373
4432
        ;
4374
4433
 
4375
4434
opt_insert_update:
4376
4435
          /* empty */
4377
 
        | ON DUPLICATE_SYM { Lex->duplicates= DUP_UPDATE; }
 
4436
        | ON DUPLICATE_SYM { Lex.duplicates= DUP_UPDATE; }
4378
4437
          KEY_SYM UPDATE_SYM insert_update_list
4379
4438
        ;
4380
4439
 
4383
4442
update:
4384
4443
          UPDATE_SYM opt_ignore table_ident SET_SYM update_list
4385
4444
          {
4386
 
            init_select(Lex);
4387
 
            Lex->statement= new statement::Update(YYSession);
4388
 
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
4389
 
            Lex->duplicates= DUP_ERROR;
4390
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4445
            init_select(&Lex);
 
4446
            Lex.statement= new statement::Update(YYSession);
 
4447
            Lex.lock_option= TL_UNLOCK; /* Will be set later */
 
4448
            Lex.duplicates= DUP_ERROR;
 
4449
            if (not Lex.select_lex.add_table_to_list(YYSession, $3, NULL,0))
4391
4450
              DRIZZLE_YYABORT;
4392
4451
 
4393
 
            if (Lex->select_lex.get_table_list()->derived)
 
4452
            if (Lex.select_lex.get_table_list()->derived)
4394
4453
            {
4395
4454
              /* it is single table update and it is update of derived table */
4396
4455
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4397
 
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
 
4456
                       Lex.select_lex.get_table_list()->alias, "UPDATE");
4398
4457
              DRIZZLE_YYABORT;
4399
4458
            }
4400
4459
            /*
4402
4461
              be too pessimistic. We will decrease lock level if possible in
4403
4462
              multi_update().
4404
4463
            */
4405
 
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4464
            Lex.current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4406
4465
          }
4407
4466
          where_clause opt_order_clause delete_limit_clause {}
4408
4467
        ;
4415
4474
update_elem:
4416
4475
          simple_ident equal expr_or_default
4417
4476
          {
4418
 
            if (YYSession->add_item_to_list($1) || YYSession->add_value_to_list($3))
4419
 
              DRIZZLE_YYABORT;
 
4477
            YYSession->add_item_to_list($1);
 
4478
                        YYSession->add_value_to_list($3);
4420
4479
          }
4421
4480
        ;
4422
4481
 
4428
4487
insert_update_elem:
4429
4488
          simple_ident equal expr_or_default
4430
4489
          {
4431
 
          if (Lex->update_list.push_back($1) ||
4432
 
              Lex->value_list.push_back($3))
4433
 
              DRIZZLE_YYABORT;
 
4490
                        Lex.update_list.push_back($1);
 
4491
            Lex.value_list.push_back($3);
4434
4492
          }
4435
4493
        ;
4436
4494
 
4439
4497
delete:
4440
4498
          DELETE_SYM opt_delete_option FROM table_ident
4441
4499
          {
4442
 
            Lex->statement= new statement::Delete(YYSession);
4443
 
            init_select(Lex);
4444
 
            Lex->lock_option= TL_WRITE_DEFAULT;
4445
 
            Lex->select_lex.init_order();
4446
 
 
4447
 
            if (!Lex->current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING,
4448
 
                                           Lex->lock_option))
4449
 
              DRIZZLE_YYABORT;
 
4500
            Lex.statement= new statement::Delete(YYSession);
 
4501
            init_select(&Lex);
 
4502
            Lex.lock_option= TL_WRITE_DEFAULT;
 
4503
            Lex.select_lex.init_order();
 
4504
            Lex.current_select->add_table_to_list(YYSession, $4, NULL, TL_OPTION_UPDATING, Lex.lock_option);
4450
4505
          }
4451
4506
          where_clause opt_order_clause
4452
4507
          delete_limit_clause {}
4453
4508
        ;
4454
4509
 
4455
4510
opt_delete_option:
4456
 
           /* empty */ { Lex->ignore= 0; }
4457
 
         | IGNORE_SYM  { Lex->ignore= 1; }
 
4511
           /* empty */ { Lex.ignore= 0; }
 
4512
         | IGNORE_SYM  { Lex.ignore= 1; }
4458
4513
        ;
4459
4514
 
4460
4515
truncate:
4461
4516
          TRUNCATE_SYM opt_table_sym table_name
4462
4517
          {
4463
 
            Lex->statement= new statement::Truncate(YYSession);
4464
 
            Lex->select_lex.options= 0;
4465
 
            Lex->select_lex.init_order();
 
4518
            Lex.statement= new statement::Truncate(YYSession);
 
4519
            Lex.select_lex.options= 0;
 
4520
            Lex.select_lex.init_order();
4466
4521
          }
4467
4522
        ;
4468
4523
 
4476
4531
show:
4477
4532
          SHOW
4478
4533
          {
4479
 
            Lex->lock_option= TL_READ;
4480
 
            init_select(Lex);
4481
 
            Lex->current_select->parsing_place= SELECT_LIST;
 
4534
            Lex.lock_option= TL_READ;
 
4535
            init_select(&Lex);
 
4536
            Lex.current_select->parsing_place= SELECT_LIST;
4482
4537
          }
4483
4538
          show_param
4484
4539
          {}
4488
4543
show_param:
4489
4544
           DATABASES show_wild
4490
4545
           {
4491
 
             if (not show::buildScemas(YYSession))
4492
 
               DRIZZLE_YYABORT;
 
4546
             if (not show::buildSchemas(YYSession))
 
4547
                                DRIZZLE_YYABORT;
4493
4548
           }
4494
4549
           /* SHOW TABLES */
4495
4550
         | TABLES opt_db show_wild
4570
4625
 
4571
4626
opt_db:
4572
4627
          /* empty */  { $$= 0; }
4573
 
        | from_or_in ident { $$= $2.str; }
 
4628
        | from_or_in ident { $$= $2.data(); }
4574
4629
        ;
4575
4630
 
4576
4631
from_or_in:
4582
4637
          /* empty */
4583
4638
        | LIKE TEXT_STRING_sys
4584
4639
          {
4585
 
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
4586
 
                                                    system_charset_info);
4587
 
            if (Lex->wild == NULL)
4588
 
              DRIZZLE_YYABORT;
 
4640
            Lex.wild= new (YYSession->mem_root) String($2.data(), $2.size(), system_charset_info);
4589
4641
          }
4590
4642
        | WHERE expr
4591
4643
          {
4592
 
            Lex->current_select->where= $2;
 
4644
            Lex.current_select->where= $2;
4593
4645
            if ($2)
4594
4646
              $2->top_level_item();
4595
4647
          }
4606
4658
          }
4607
4659
          opt_describe_column {}
4608
4660
        | describe_command opt_extended_describe
4609
 
          { Lex->describe|= DESCRIBE_NORMAL; }
 
4661
          { Lex.describe|= DESCRIBE_NORMAL; }
4610
4662
          select
4611
4663
          {
4612
 
            Lex->select_lex.options|= SELECT_DESCRIBE;
 
4664
            Lex.select_lex.options|= SELECT_DESCRIBE;
4613
4665
          }
4614
4666
        ;
4615
4667
 
4620
4672
 
4621
4673
opt_extended_describe:
4622
4674
          /* empty */ {}
4623
 
        | EXTENDED_SYM   { Lex->describe|= DESCRIBE_EXTENDED; }
 
4675
        | EXTENDED_SYM   { Lex.describe|= DESCRIBE_EXTENDED; }
4624
4676
        ;
4625
4677
 
4626
4678
opt_describe_column:
4627
4679
          /* empty */ {}
4628
 
        | text_string { Lex->wild= $1; }
 
4680
        | text_string { Lex.wild= $1; }
4629
4681
        | ident
4630
4682
          {
4631
 
            Lex->wild= new (YYSession->mem_root) String((const char*) $1.str,
4632
 
                                                    $1.length,
4633
 
                                                    system_charset_info);
 
4683
            Lex.wild= new (YYSession->mem_root) String($1.data(), $1.size(), system_charset_info);
4634
4684
          }
4635
4685
        ;
4636
4686
 
4640
4690
flush:
4641
4691
          FLUSH_SYM
4642
4692
          {
4643
 
            Lex->statement= new statement::Flush(YYSession);
 
4693
            Lex.statement= new statement::Flush(YYSession);
4644
4694
          }
4645
4695
          flush_options
4646
4696
          {}
4654
4704
flush_option:
4655
4705
          table_or_tables
4656
4706
          {
4657
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
 
4707
            statement::Flush *statement= (statement::Flush*)Lex.statement;
4658
4708
            statement->setFlushTables(true);
4659
4709
          }
4660
4710
          opt_table_list {}
4661
4711
        | TABLES WITH READ_SYM LOCK_SYM
4662
4712
          {
4663
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
 
4713
            statement::Flush *statement= (statement::Flush*)Lex.statement;
4664
4714
            statement->setFlushTablesWithReadLock(true);
4665
4715
          }
4666
4716
        | LOGS_SYM
4667
4717
          {
4668
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
 
4718
            statement::Flush *statement= (statement::Flush*)Lex.statement;
4669
4719
            statement->setFlushLog(true);
4670
4720
          }
4671
4721
        | STATUS_SYM
4672
4722
          {
4673
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
 
4723
            statement::Flush *statement= (statement::Flush*)Lex.statement;
4674
4724
            statement->setFlushStatus(true);
4675
4725
          }
4676
4726
        | GLOBAL_SYM STATUS_SYM
4677
4727
          {
4678
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
 
4728
            statement::Flush *statement= (statement::Flush*)Lex.statement;
4679
4729
            statement->setFlushGlobalStatus(true);
4680
4730
          }
4681
4731
        ;
4690
4740
kill:
4691
4741
          KILL_SYM kill_option expr
4692
4742
          {
4693
 
            Lex->statement= new statement::Kill(YYSession, $3, $2);
 
4743
            Lex.statement= new statement::Kill(YYSession, $3, $2);
4694
4744
          }
4695
4745
        ;
4696
4746
 
4705
4755
use:
4706
4756
          USE_SYM schema_name
4707
4757
          {
4708
 
            Lex->statement= new statement::ChangeSchema(YYSession);
4709
 
            Lex->select_lex.db= $2.str;
 
4758
            Lex.statement= new statement::ChangeSchema(YYSession);
 
4759
            Lex.select_lex.db= $2.data();
4710
4760
          }
4711
4761
        ;
4712
4762
 
4716
4766
          LOAD data_file
4717
4767
          {
4718
4768
            statement::Load *statement= new statement::Load(YYSession);
4719
 
            Lex->statement= statement;
 
4769
            Lex.statement= statement;
4720
4770
 
4721
4771
            Lex_input_stream *lip= YYSession->m_lip;
4722
4772
            statement->fname_start= lip->get_ptr();
4723
4773
          }
4724
4774
          load_data_lock INFILE TEXT_STRING_filesystem
4725
4775
          {
4726
 
            Lex->lock_option= $4;
4727
 
            Lex->duplicates= DUP_ERROR;
4728
 
            Lex->ignore= 0;
4729
 
            if (not (Lex->exchange= new file_exchange($6.str, 0, $2)))
4730
 
              DRIZZLE_YYABORT;
 
4776
            Lex.lock_option= $4;
 
4777
            Lex.duplicates= DUP_ERROR;
 
4778
            Lex.ignore= 0;
 
4779
            Lex.exchange= new file_exchange($6.data(), 0, $2);
4731
4780
          }
4732
4781
          opt_duplicate INTO
4733
4782
          {
4734
4783
            Lex_input_stream *lip= YYSession->m_lip;
4735
 
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
 
4784
            ((statement::Load *)Lex.statement)->fname_end= lip->get_ptr();
4736
4785
          }
4737
4786
          TABLE_SYM table_ident
4738
4787
          {
4739
 
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4788
            if (!Lex.current_select->add_table_to_list(YYSession,
4740
4789
                    $12, NULL, TL_OPTION_UPDATING,
4741
 
                    Lex->lock_option))
 
4790
                    Lex.lock_option))
4742
4791
              DRIZZLE_YYABORT;
4743
 
            Lex->field_list.clear();
4744
 
            Lex->update_list.clear();
4745
 
            Lex->value_list.clear();
 
4792
            Lex.field_list.clear();
 
4793
            Lex.update_list.clear();
 
4794
            Lex.value_list.clear();
4746
4795
          }
4747
4796
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
4748
4797
          opt_load_data_set_spec
4761
4810
        ;
4762
4811
 
4763
4812
opt_duplicate:
4764
 
          /* empty */ { Lex->duplicates=DUP_ERROR; }
4765
 
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
4766
 
        | IGNORE_SYM { Lex->ignore= 1; }
 
4813
          /* empty */ { Lex.duplicates=DUP_ERROR; }
 
4814
        | REPLACE { Lex.duplicates=DUP_REPLACE; }
 
4815
        | IGNORE_SYM { Lex.ignore= 1; }
4767
4816
        ;
4768
4817
 
4769
4818
opt_duplicate_as:
4770
 
          /* empty */ { Lex->duplicates=DUP_ERROR; }
4771
 
        | AS { Lex->duplicates=DUP_ERROR; }
4772
 
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
4773
 
        | IGNORE_SYM { Lex->ignore= true; }
4774
 
        | REPLACE AS { Lex->duplicates=DUP_REPLACE; }
4775
 
        | IGNORE_SYM AS { Lex->ignore= true; }
 
4819
          /* empty */ { Lex.duplicates=DUP_ERROR; }
 
4820
        | AS { Lex.duplicates=DUP_ERROR; }
 
4821
        | REPLACE { Lex.duplicates=DUP_REPLACE; }
 
4822
        | IGNORE_SYM { Lex.ignore= true; }
 
4823
        | REPLACE AS { Lex.duplicates=DUP_REPLACE; }
 
4824
        | IGNORE_SYM AS { Lex.ignore= true; }
4776
4825
        ;
4777
4826
 
4778
4827
opt_field_term:
4788
4837
field_term:
4789
4838
          TERMINATED BY text_string
4790
4839
          {
4791
 
            assert(Lex->exchange != 0);
4792
 
            Lex->exchange->field_term= $3;
 
4840
            assert(Lex.exchange != 0);
 
4841
            Lex.exchange->field_term= $3;
4793
4842
          }
4794
4843
        | OPTIONALLY ENCLOSED BY text_string
4795
4844
          {
4796
 
            assert(Lex->exchange != 0);
4797
 
            Lex->exchange->enclosed= $4;
4798
 
            Lex->exchange->opt_enclosed= 1;
 
4845
            assert(Lex.exchange != 0);
 
4846
            Lex.exchange->enclosed= $4;
 
4847
            Lex.exchange->opt_enclosed= 1;
4799
4848
          }
4800
4849
        | ENCLOSED BY text_string
4801
4850
          {
4802
 
            assert(Lex->exchange != 0);
4803
 
            Lex->exchange->enclosed= $3;
 
4851
            assert(Lex.exchange != 0);
 
4852
            Lex.exchange->enclosed= $3;
4804
4853
          }
4805
4854
        | ESCAPED BY text_string
4806
4855
          {
4807
 
            assert(Lex->exchange != 0);
4808
 
            Lex->exchange->escaped= $3;
 
4856
            assert(Lex.exchange != 0);
 
4857
            Lex.exchange->escaped= $3;
4809
4858
          }
4810
4859
        ;
4811
4860
 
4822
4871
line_term:
4823
4872
          TERMINATED BY text_string
4824
4873
          {
4825
 
            assert(Lex->exchange != 0);
4826
 
            Lex->exchange->line_term= $3;
 
4874
            assert(Lex.exchange != 0);
 
4875
            Lex.exchange->line_term= $3;
4827
4876
          }
4828
4877
        | STARTING BY text_string
4829
4878
          {
4830
 
            assert(Lex->exchange != 0);
4831
 
            Lex->exchange->line_start= $3;
 
4879
            assert(Lex.exchange != 0);
 
4880
            Lex.exchange->line_start= $3;
4832
4881
          }
4833
4882
        ;
4834
4883
 
4836
4885
          /* empty */
4837
4886
        | IGNORE_SYM NUM lines_or_rows
4838
4887
          {
4839
 
            assert(Lex->exchange != 0);
4840
 
            Lex->exchange->skip_lines= atol($2.str);
 
4888
            assert(Lex.exchange != 0);
 
4889
            Lex.exchange->skip_lines= atol($2.data());
4841
4890
          }
4842
4891
        ;
4843
4892
 
4854
4903
 
4855
4904
fields_or_vars:
4856
4905
          fields_or_vars ',' field_or_var
4857
 
          { Lex->field_list.push_back($3); }
 
4906
          { Lex.field_list.push_back($3); }
4858
4907
        | field_or_var
4859
 
          { Lex->field_list.push_back($1); }
 
4908
          { Lex.field_list.push_back($1); }
4860
4909
        ;
4861
4910
 
4862
4911
field_or_var:
4875
4924
text_literal:
4876
4925
        TEXT_STRING_literal
4877
4926
        {
4878
 
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
 
4927
          $$ = new Item_string($1.data(), $1.size(), YYSession->variables.getCollation());
4879
4928
        }
4880
4929
        | text_literal TEXT_STRING_literal
4881
4930
          {
4882
 
            ((Item_string*) $1)->append($2.str, $2.length);
 
4931
            ((Item_string*) $1)->append($2);
4883
4932
          }
4884
4933
        ;
4885
4934
 
4886
4935
text_string:
4887
4936
          TEXT_STRING_literal
4888
4937
          {
4889
 
            $$= new (YYSession->mem_root) String($1.str,
4890
 
                                             $1.length,
4891
 
                                             YYSession->variables.getCollation());
 
4938
            $$= new (YYSession->mem_root) String($1.data(), $1.size(), YYSession->variables.getCollation());
4892
4939
          }
4893
4940
        | HEX_NUM
4894
4941
          {
4895
 
            Item *tmp= new Item_hex_string($1.str, $1.length);
 
4942
            Item *tmp= new Item_hex_string($1);
4896
4943
            /*
4897
4944
              it is OK only emulate fix_fields, because we need only
4898
4945
              value of constant
4899
4946
            */
4900
 
            $$= tmp ?
4901
 
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
4902
 
              (String*) 0;
 
4947
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str(NULL) : NULL;
4903
4948
          }
4904
4949
        | BIN_NUM
4905
4950
          {
4906
 
            Item *tmp= new Item_bin_string($1.str, $1.length);
 
4951
            Item *tmp= new Item_bin_string($1);
4907
4952
            /*
4908
4953
              it is OK only emulate fix_fields, because we need only
4909
4954
              value of constant
4910
4955
            */
4911
 
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str((String*) 0) :
4912
 
              (String*) 0;
 
4956
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str(NULL) : NULL;
4913
4957
          }
4914
4958
        ;
4915
4959
 
4933
4977
          }
4934
4978
        | FALSE_SYM { $$= new drizzled::item::False(); }
4935
4979
        | TRUE_SYM { $$= new drizzled::item::True(); }
4936
 
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4937
 
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
 
4980
        | HEX_NUM { $$ = new Item_hex_string($1);}
 
4981
        | BIN_NUM { $$= new Item_bin_string($1); }
4938
4982
        | DATE_SYM text_literal { $$ = $2; }
4939
4983
        | TIMESTAMP_SYM text_literal { $$ = $2; }
4940
4984
        ;
4941
4985
 
4942
4986
integer_literal:
4943
4987
          text_literal { $$ = $1; }
4944
 
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
4945
 
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
 
4988
        | HEX_NUM { $$ = new Item_hex_string($1);}
 
4989
        | BIN_NUM { $$= new Item_bin_string($1); }
4946
4990
        | NUM_literal { $$ = $1; }
4947
4991
        | NULL_SYM
4948
4992
          {
4989
5033
          NUM
4990
5034
          {
4991
5035
            int error;
4992
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5036
            $$ = new Item_int($1.data(), internal::my_strtoll10($1.data(), NULL, &error), $1.size());
4993
5037
          }
4994
5038
        | LONG_NUM
4995
5039
          {
4996
5040
            int error;
4997
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5041
            $$ = new Item_int($1.data(), internal::my_strtoll10($1.data(), NULL, &error), $1.size());
4998
5042
          }
4999
5043
        | ULONGLONG_NUM
5000
 
          { $$ = new Item_uint($1.str, $1.length); }
 
5044
          { $$ = new Item_uint($1.data(), $1.size()); }
5001
5045
        | DECIMAL_NUM
5002
5046
          {
5003
 
            $$= new Item_decimal($1.str, $1.length, YYSession->charset());
 
5047
            $$= new Item_decimal($1.data(), $1.size(), YYSession->charset());
5004
5048
            if (YYSession->is_error())
5005
5049
            {
5006
5050
              DRIZZLE_YYABORT;
5008
5052
          }
5009
5053
        | FLOAT_NUM
5010
5054
          {
5011
 
            $$ = new Item_float($1.str, $1.length);
 
5055
            $$ = new Item_float($1.data(), $1.size());
5012
5056
            if (YYSession->is_error())
5013
5057
            {
5014
5058
              DRIZZLE_YYABORT;
5028
5072
table_wild:
5029
5073
          ident '.' '*'
5030
5074
          {
5031
 
            $$= parser::buildTableWild(Lex, NULL_LEX_STRING, $1);
 
5075
            $$= parser::buildTableWild(&Lex, null_lex_string(), $1);
5032
5076
          }
5033
5077
        | ident '.' ident '.' '*'
5034
5078
          {
5035
 
            $$= parser::buildTableWild(Lex, $1, $3);
 
5079
            $$= parser::buildTableWild(&Lex, $1, $3);
5036
5080
          }
5037
5081
        ;
5038
5082
 
5043
5087
simple_ident:
5044
5088
          ident
5045
5089
          {
5046
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, NULL_LEX_STRING, $1);
 
5090
            $$= parser::buildIdent(&Lex, null_lex_string(), null_lex_string(), $1);
5047
5091
          }
5048
5092
        | simple_ident_q { $$= $1; }
5049
5093
        ;
5051
5095
simple_ident_q:
5052
5096
          ident '.' ident
5053
5097
          {
5054
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
 
5098
            $$= parser::buildIdent(&Lex, null_lex_string(), $1, $3);
5055
5099
          }
5056
5100
        | '.' ident '.' ident
5057
5101
          {
5058
 
            $$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
 
5102
            $$= parser::buildIdent(&Lex, null_lex_string(), $2, $4);
5059
5103
          }
5060
5104
        | ident '.' ident '.' ident
5061
5105
          {
5062
 
            $$= parser::buildIdent(Lex, $1, $3, $5);
 
5106
            $$= parser::buildIdent(&Lex, $1, $3, $5);
5063
5107
          }
5064
5108
        ;
5065
5109
 
5066
5110
field_ident:
5067
 
          ident 
 
5111
          ident
5068
5112
          {
5069
5113
            $$=$1;
5070
5114
          }
5071
5115
        | ident '.' ident '.' ident
5072
5116
          {
5073
 
            if (not parser::checkFieldIdent(Lex, $1, $3))
 
5117
            if (not parser::checkFieldIdent(&Lex, $1, $3))
5074
5118
              DRIZZLE_YYABORT;
5075
5119
 
5076
5120
            $$=$5;
5077
5121
          }
5078
5122
        | ident '.' ident
5079
5123
          {
5080
 
            if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
 
5124
            if (not parser::checkFieldIdent(&Lex, null_lex_string(), $1))
5081
5125
              DRIZZLE_YYABORT;
5082
5126
 
5083
5127
            $$=$3;
5084
5128
          }
5085
 
        | '.' ident 
 
5129
        | '.' ident
5086
5130
          { /* For Delphi */
5087
5131
            $$=$2;
5088
5132
          }
5112
5156
        ;
5113
5157
 
5114
5158
IDENT_sys:
5115
 
          IDENT 
 
5159
          IDENT
5116
5160
          {
5117
5161
            $$= $1;
5118
5162
          }
5119
5163
        | IDENT_QUOTED
5120
5164
          {
5121
 
            const CHARSET_INFO * const cs= system_charset_info;
 
5165
            const charset_info_st * const cs= system_charset_info;
5122
5166
            int dummy_error;
5123
 
            uint32_t wlen= cs->cset->well_formed_len(cs, $1.str,
5124
 
                                                 $1.str+$1.length,
5125
 
                                                 $1.length, &dummy_error);
5126
 
            if (wlen < $1.length)
 
5167
            uint32_t wlen= cs->cset->well_formed_len(*cs, $1, $1.size(), &dummy_error);
 
5168
            if (wlen < $1.size())
5127
5169
            {
5128
 
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
5129
 
                       cs->csname, $1.str + wlen);
 
5170
              my_error(ER_INVALID_CHARACTER_STRING, MYF(0), cs->csname, $1.data() + wlen);
5130
5171
              DRIZZLE_YYABORT;
5131
5172
            }
5132
5173
            $$= $1;
5158
5199
          IDENT_sys    { $$=$1; }
5159
5200
        | keyword
5160
5201
          {
5161
 
            $$.str= YYSession->strmake($1.str, $1.length);
5162
 
            $$.length= $1.length;
 
5202
            $$.assign(YYSession->mem.strdup($1.data(), $1.length), $1.length);
5163
5203
          }
5164
5204
        ;
5165
5205
 
5266
5306
        | IMPORT                   {}
5267
5307
        | INDEXES                  {}
5268
5308
        | ISOLATION                {}
 
5309
        | IPV6_SYM                 {}
5269
5310
        | KEY_BLOCK_SIZE           {}
5270
5311
        | LAST_SYM                 {}
5271
5312
        | LEVEL_SYM                {}
5344
5385
set:
5345
5386
          SET_SYM opt_option
5346
5387
          {
5347
 
            Lex->statement= new statement::SetOption(YYSession);
 
5388
            Lex.statement= new statement::SetOption(YYSession);
5348
5389
          }
5349
5390
          option_value_list
5350
5391
          {}
5375
5416
 
5376
5417
option_type2:
5377
5418
          /* empty */ { $$= OPT_DEFAULT; }
5378
 
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
 
5419
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex.statement)->one_shot_set= true; $$= OPT_SESSION; }
5379
5420
        ;
5380
5421
 
5381
5422
opt_var_type:
5404
5445
            { /* System variable */
5405
5446
              if ($1)
5406
5447
              {
5407
 
                Lex->option_type= $1;
 
5448
                Lex.option_type= $1;
5408
5449
              }
5409
 
              Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type, $2.var, &$2.base_name, $4)));
 
5450
              Lex.var_list.push_back(SetVarPtr(new set_var(Lex.option_type, $2.var, $2.base_name, $4)));
5410
5451
            }
5411
5452
          }
5412
5453
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
5413
5454
          {
5414
 
            Lex->option_type= $1;
5415
 
            Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type,
5416
 
                                              find_sys_var("tx_isolation"),
5417
 
                                              &null_lex_str,
5418
 
                                              new Item_int((int32_t)
5419
 
                                              $5))));
 
5455
            Lex.option_type= $1;
 
5456
            Lex.var_list.push_back(SetVarPtr(new set_var(Lex.option_type, find_sys_var("tx_isolation"), str_ref(), new Item_int((int32_t) $5))));
5420
5457
          }
5421
5458
        ;
5422
5459
 
5423
5460
option_value:
5424
5461
          '@' user_variable_ident equal expr
5425
5462
          {
5426
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
 
5463
            Lex.var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
5427
5464
          }
5428
5465
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
5429
5466
          {
5430
 
            Lex->var_list.push_back(SetVarPtr(new set_var($3, $4.var, &$4.base_name, $6)));
 
5467
            Lex.var_list.push_back(SetVarPtr(new set_var($3, $4.var, $4.base_name, $6)));
5431
5468
          }
5432
5469
        ;
5433
5470
 
5440
5477
internal_variable_ident:
5441
5478
          keyword_exception_for_variable
5442
5479
          {
5443
 
            $$.str= YYSession->strmake($1.str, $1.length);
5444
 
            $$.length= $1.length;
 
5480
            $$.assign(YYSession->mem.strdup($1.data(), $1.length), $1.length);
5445
5481
          }
5446
5482
        | IDENT_sys    { $$=$1; }
5447
5483
        ;
5452
5488
            /* We have to lookup here since local vars can shadow sysvars */
5453
5489
            {
5454
5490
              /* Not an SP local variable */
5455
 
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
5456
 
              if (!tmp)
 
5491
              sys_var *tmp= find_sys_var(to_string($1));
 
5492
              if (not tmp)
5457
5493
                DRIZZLE_YYABORT;
5458
5494
              $$.var= tmp;
5459
 
              $$.base_name= null_lex_str;
 
5495
              $$.base_name= null_lex_string();
5460
5496
            }
5461
5497
          }
5462
5498
        ;
5471
5507
set_expr_or_default:
5472
5508
          expr { $$=$1; }
5473
5509
        | DEFAULT { $$=0; }
5474
 
        | ON     { $$=new Item_string("ON",  2, system_charset_info); }
5475
 
        | ALL    { $$=new Item_string("ALL", 3, system_charset_info); }
5476
 
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
 
5510
        | ON     { $$=new Item_string(str_ref("ON"), system_charset_info); }
 
5511
        | ALL    { $$=new Item_string(str_ref("ALL"), system_charset_info); }
 
5512
        | BINARY { $$=new Item_string(str_ref("binary"), system_charset_info); }
5477
5513
        ;
5478
5514
 
5479
5515
table_or_tables:
5484
5520
unlock:
5485
5521
          UNLOCK_SYM
5486
5522
          {
5487
 
            Lex->statement= new statement::UnlockTables(YYSession);
 
5523
            Lex.statement= new statement::UnlockTables(YYSession);
5488
5524
          }
5489
5525
          table_or_tables
5490
5526
          {}
5493
5529
begin:
5494
5530
          BEGIN_SYM
5495
5531
          {
5496
 
            Lex->statement= new statement::StartTransaction(YYSession);
 
5532
            Lex.statement= new statement::StartTransaction(YYSession);
5497
5533
          }
5498
5534
          opt_work {}
5499
5535
        ;
5525
5561
commit:
5526
5562
          COMMIT_SYM opt_work opt_chain opt_release
5527
5563
          {
5528
 
            Lex->statement= new statement::Commit(YYSession, $3, $4);
 
5564
            Lex.statement= new statement::Commit(YYSession, $3, $4);
5529
5565
          }
5530
5566
        ;
5531
5567
 
5532
5568
rollback:
5533
5569
          ROLLBACK_SYM opt_work opt_chain opt_release
5534
5570
          {
5535
 
            Lex->statement= new statement::Rollback(YYSession, $3, $4);
 
5571
            Lex.statement= new statement::Rollback(YYSession, $3, $4);
5536
5572
          }
5537
5573
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
5538
5574
          {
5539
 
            Lex->statement= new statement::RollbackToSavepoint(YYSession, $5);
 
5575
            Lex.statement= new statement::RollbackToSavepoint(YYSession, $5);
5540
5576
          }
5541
5577
        ;
5542
5578
 
5543
5579
savepoint:
5544
5580
          SAVEPOINT_SYM savepoint_ident
5545
5581
          {
5546
 
            Lex->statement= new statement::Savepoint(YYSession, $2);
 
5582
            Lex.statement= new statement::Savepoint(YYSession, $2);
5547
5583
          }
5548
5584
        ;
5549
5585
 
5550
5586
release:
5551
5587
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
5552
5588
          {
5553
 
            Lex->statement= new statement::ReleaseSavepoint(YYSession, $3);
 
5589
            Lex.statement= new statement::ReleaseSavepoint(YYSession, $3);
5554
5590
          }
5555
5591
        ;
5556
5592
 
5571
5607
union_list:
5572
5608
          UNION_SYM union_option
5573
5609
          {
5574
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
 
5610
            if (parser::add_select_to_union_list(YYSession, &Lex, (bool)$2))
5575
5611
              DRIZZLE_YYABORT;
5576
5612
          }
5577
5613
          select_init
5580
5616
              Remove from the name resolution context stack the context of the
5581
5617
              last select in the union.
5582
5618
            */
5583
 
            Lex->pop_context();
 
5619
            Lex.pop_context();
5584
5620
          }
5585
5621
        ;
5586
5622
 
5592
5628
 
5593
5629
union_order_or_limit:
5594
5630
          {
5595
 
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
5596
 
            Select_Lex *sel= Lex->current_select;
 
5631
            assert(Lex.current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
5632
            Select_Lex *sel= Lex.current_select;
5597
5633
            Select_Lex_Unit *unit= sel->master_unit();
5598
5634
            Select_Lex *fake= unit->fake_select_lex;
5599
5635
            if (fake)
5600
5636
            {
5601
5637
              unit->global_parameters= fake;
5602
5638
              fake->no_table_names_allowed= 1;
5603
 
              Lex->current_select= fake;
 
5639
              Lex.current_select= fake;
5604
5640
            }
5605
5641
            YYSession->setWhere("global ORDER clause");
5606
5642
          }
5607
5643
          order_or_limit
5608
5644
          {
5609
 
            YYSession->getLex()->current_select->no_table_names_allowed= 0;
 
5645
            YYSession->lex().current_select->no_table_names_allowed= 0;
5610
5646
            YYSession->setWhere("");
5611
5647
          }
5612
5648
        ;
5625
5661
query_specification:
5626
5662
          SELECT_SYM select_init2_derived
5627
5663
          {
5628
 
            $$= Lex->current_select->master_unit()->first_select();
 
5664
            $$= Lex.current_select->master_unit()->first_select();
5629
5665
          }
5630
5666
        | '(' select_paren_derived ')'
5631
5667
          {
5632
 
            $$= Lex->current_select->master_unit()->first_select();
 
5668
            $$= Lex.current_select->master_unit()->first_select();
5633
5669
          }
5634
5670
        ;
5635
5671
 
5638
5674
        | query_expression_body
5639
5675
          UNION_SYM union_option
5640
5676
          {
5641
 
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
 
5677
            if (parser::add_select_to_union_list(YYSession, &Lex, (bool)$3))
5642
5678
              DRIZZLE_YYABORT;
5643
5679
          }
5644
5680
          query_specification
5645
5681
          {
5646
 
            Lex->pop_context();
 
5682
            Lex.pop_context();
5647
5683
            $$= $1;
5648
5684
          }
5649
5685
        ;
5658
5694
 
5659
5695
subselect_start:
5660
5696
          {
5661
 
            if (not Lex->expr_allows_subselect)
 
5697
            if (not Lex.expr_allows_subselect)
5662
5698
            {
5663
5699
              parser::my_parse_error(YYSession->m_lip);
5664
5700
              DRIZZLE_YYABORT;
5670
5706
              (SELECT .. ) UNION ...  becomes
5671
5707
              SELECT * FROM ((SELECT ...) UNION ...)
5672
5708
            */
5673
 
            if (new_select(Lex, 1))
 
5709
            if (new_select(&Lex, 1))
5674
5710
              DRIZZLE_YYABORT;
5675
5711
          }
5676
5712
        ;
5677
5713
 
5678
5714
subselect_end:
5679
5715
          {
5680
 
            Lex->pop_context();
5681
 
            Select_Lex *child= Lex->current_select;
5682
 
            Lex->current_select= Lex->current_select->return_after_parsing();
5683
 
            Lex->nest_level--;
5684
 
            Lex->current_select->n_child_sum_items += child->n_sum_items;
 
5716
            Lex.pop_context();
 
5717
            Select_Lex *child= Lex.current_select;
 
5718
            Lex.current_select= Lex.current_select->return_after_parsing();
 
5719
            Lex.nest_level--;
 
5720
            Lex.current_select->n_child_sum_items += child->n_sum_items;
5685
5721
            /*
5686
5722
              A subselect can add fields to an outer select. Reserve space for
5687
5723
              them.
5688
5724
            */
5689
 
            Lex->current_select->select_n_where_fields+=
 
5725
            Lex.current_select->select_n_where_fields+=
5690
5726
            child->select_n_where_fields;
5691
5727
          }
5692
5728
        ;