~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Lee Bieber
  • Date: 2011-01-08 03:39:25 UTC
  • mfrom: (2062.1.2 build)
  • Revision ID: kalebral@gmail.com-20110108033925-koobar399kwrm4ba
Merge Brian - parser clean up
Merge Marisa - latest doc updates, fix sphinx warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
using namespace drizzled;
345
345
%}
346
346
%union {
 
347
  bool boolean;
347
348
  int  num;
348
349
  ulong ulong_num;
349
350
  uint64_t ulonglong_number;
361
362
  drizzled::Key_part_spec *key_part;
362
363
  const drizzled::plugin::Function *udf;
363
364
  drizzled::TableList *table_list;
 
365
  enum drizzled::enum_field_types field_val;
364
366
  struct drizzled::sys_var_with_base variable;
365
367
  enum drizzled::sql_var_t var_type;
366
368
  drizzled::Key::Keytype key_type;
390
392
}
391
393
%}
392
394
 
 
395
%debug
393
396
%pure_parser                                    /* We have threads */
 
397
 
394
398
/*
395
399
  Currently there are 88 shift/reduce conflicts.
396
400
  We should not introduce new conflicts any more.
397
401
*/
398
 
%expect 95
 
402
%expect 77
399
403
 
400
404
/*
401
405
   Comments for TOKENS.
430
434
%token  ASENSITIVE_SYM                /* FUTURE-USE */
431
435
%token  AT_SYM                        /* SQL-2003-R */
432
436
%token  AUTO_INC
433
 
%token  AVG_ROW_LENGTH
434
437
%token  AVG_SYM                       /* SQL-2003-N */
435
438
%token  BEFORE_SYM                    /* SQL-2003-N */
436
439
%token  BEGIN_SYM                     /* SQL-2003-R */
445
448
%token  BOTH                          /* SQL-2003-R */
446
449
%token  BTREE_SYM
447
450
%token  BY                            /* SQL-2003-R */
448
 
%token  BYTE_SYM
449
451
%token  CALL_SYM                      /* SQL-2003-R */
450
452
%token  CASCADE                       /* SQL-2003-N */
451
453
%token  CASCADED                      /* SQL-2003-R */
473
475
%token  CONSISTENT_SYM
474
476
%token  CONSTRAINT                    /* SQL-2003-R */
475
477
%token  CONTAINS_SYM                  /* SQL-2003-N */
476
 
%token  CONTINUE_SYM                  /* SQL-2003-R */
477
478
%token  CONVERT_SYM                   /* SQL-2003-N */
478
479
%token  COUNT_SYM                     /* SQL-2003-N */
479
480
%token  CREATE                        /* SQL-2003-R */
484
485
%token  CURSOR_SYM                    /* SQL-2003-R */
485
486
%token  DATABASE
486
487
%token  DATABASES
487
 
%token  DATAFILE_SYM
488
488
%token  DATA_SYM                      /* SQL-2003-N */
489
489
%token  DATETIME_SYM
490
490
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
508
508
%token  DISCARD
509
509
%token  DISTINCT                      /* SQL-2003-R */
510
510
%token  DIV_SYM
 
511
%token  DO_SYM
511
512
%token  DOUBLE_SYM                    /* SQL-2003-R */
512
513
%token  DROP                          /* SQL-2003-R */
513
514
%token  DUMPFILE
515
516
%token  DYNAMIC_SYM                   /* SQL-2003-R */
516
517
%token  EACH_SYM                      /* SQL-2003-R */
517
518
%token  ELSE                          /* SQL-2003-R */
518
 
%token  ELSEIF_SYM
519
519
%token  ENABLE_SYM
520
520
%token  ENCLOSED
521
521
%token  END                           /* SQL-2003-R */
529
529
%token  ESCAPED
530
530
%token  ESCAPE_SYM                    /* SQL-2003-R */
531
531
%token  EXCLUSIVE_SYM
532
 
%token  EXECUTE_SYM
 
532
%token  EXECUTE_SYM                   /* SQL-2003-R */
533
533
%token  EXISTS                        /* SQL-2003-R */
534
534
%token  EXTENDED_SYM
535
535
%token  EXTRACT_SYM                   /* SQL-2003-N */
536
536
%token  FALSE_SYM                     /* SQL-2003-R */
537
 
%token  FETCH_SYM                     /* SQL-2003-R */
538
537
%token  COLUMN_FORMAT_SYM
539
538
%token  FILE_SYM
540
539
%token  FIRST_SYM                     /* SQL-2003-N */
562
561
%token  HOUR_SYM                      /* SQL-2003-R */
563
562
%token  IDENT
564
563
%token  IDENTIFIED_SYM
 
564
%token  IDENTITY_SYM                  /* SQL-2003-R */
565
565
%token  IDENT_QUOTED
566
566
%token  IF
567
567
%token  IGNORE_SYM
594
594
%token  LIKE                          /* SQL-2003-R */
595
595
%token  LIMIT
596
596
%token  LINES
597
 
%token  LIST_SYM
598
597
%token  LOAD
599
598
%token  LOCAL_SYM                     /* SQL-2003-R */
600
 
%token  LOCATOR_SYM                   /* SQL-2003-N */
601
599
%token  LOCKS_SYM
602
600
%token  LOCK_SYM
603
601
%token  LOGS_SYM
604
602
%token  LONG_NUM
605
603
%token  LONG_SYM
606
 
%token  LOOP_SYM
607
604
%token  LT                            /* OPERATOR */
608
605
%token  MATCH                         /* SQL-2003-R */
609
 
%token  MAX_ROWS
610
 
%token  MAX_SIZE_SYM
611
606
%token  MAX_SYM                       /* SQL-2003-N */
612
607
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
613
608
%token  MEDIUM_SYM
616
611
%token  MINUTE_MICROSECOND_SYM
617
612
%token  MINUTE_SECOND_SYM
618
613
%token  MINUTE_SYM                    /* SQL-2003-R */
619
 
%token  MIN_ROWS
620
614
%token  MIN_SYM                       /* SQL-2003-N */
621
615
%token  MODE_SYM
622
616
%token  MODIFIES_SYM                  /* SQL-2003-R */
653
647
%token  OUTER
654
648
%token  OUTFILE
655
649
%token  OUT_SYM                       /* SQL-2003-R */
656
 
%token  PAGE_SYM
657
650
%token  PARTIAL                       /* SQL-2003-N */
658
 
%token  PHASE_SYM
659
651
%token  POSITION_SYM                  /* SQL-2003-N */
660
652
%token  PRECISION                     /* SQL-2003-R */
661
653
%token  PREV_SYM
666
658
%token  QUERY_SYM
667
659
%token  RANGE_SYM                     /* SQL-2003-R */
668
660
%token  READS_SYM                     /* SQL-2003-R */
669
 
%token  READ_ONLY_SYM
670
661
%token  READ_SYM                      /* SQL-2003-N */
671
662
%token  READ_WRITE_SYM
672
663
%token  REAL                          /* SQL-2003-R */
681
672
%token  RESTRICT
682
673
%token  RETURNS_SYM                   /* SQL-2003-R */
683
674
%token  RETURN_SYM                    /* SQL-2003-R */
684
 
%token  REVERSE_SYM
685
675
%token  REVOKE                        /* SQL-2003-R */
686
676
%token  RIGHT                         /* SQL-2003-R */
687
677
%token  ROLLBACK_SYM                  /* SQL-2003-R */
701
691
%token  SERIAL_SYM
702
692
%token  SESSION_SYM                   /* SQL-2003-N */
703
693
%token  SERVER_SYM
704
 
%token  SERVER_OPTIONS
705
694
%token  SET_SYM                           /* SQL-2003-R */
706
695
%token  SET_VAR
707
696
%token  SHARE_SYM
724
713
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
725
714
%token  STD_SYM
726
715
%token  STOP_SYM
727
 
%token  STORAGE_SYM
728
716
%token  STORED_SYM
729
717
%token  STRAIGHT_JOIN
730
718
%token  STRING_SYM
733
721
%token  SUBSTRING                     /* SQL-2003-N */
734
722
%token  SUM_SYM                       /* SQL-2003-N */
735
723
%token  SUSPEND_SYM
736
 
%token  SWAPS_SYM
737
 
%token  SWITCHES_SYM
738
724
%token  SYSDATE
739
725
%token  TABLES
740
726
%token  TABLESPACE
755
741
%token  TRIM                          /* SQL-2003-N */
756
742
%token  TRUE_SYM                      /* SQL-2003-R */
757
743
%token  TRUNCATE_SYM
758
 
%token  TYPES_SYM
759
744
%token  TYPE_SYM                      /* SQL-2003-N */
760
745
%token  ULONGLONG_NUM
761
746
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
814
799
 
815
800
%type <lex_str>
816
801
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
817
 
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
 
802
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias
 
803
        ident
 
804
        ident_or_text
 
805
        internal_variable_ident
 
806
        user_variable_ident
 
807
        row_format_or_text
818
808
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
 
809
        schema_name
819
810
        opt_component
820
 
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
811
        engine_option_value
 
812
        savepoint_ident
 
813
        BIN_NUM TEXT_STRING_filesystem
821
814
        opt_constraint constraint opt_ident
822
815
 
823
816
%type <execute_string>
835
828
%type <string>
836
829
        text_string opt_gconcat_separator
837
830
 
 
831
%type <field_val>
 
832
      field_definition
 
833
      int_type
 
834
      real_type
 
835
 
 
836
%type <boolean>
 
837
        opt_wait
 
838
        opt_concurrent
 
839
        opt_status
 
840
        opt_zerofill
 
841
        opt_if_not_exists
 
842
        if_exists 
 
843
        opt_temporary 
 
844
        opt_field_number_signed
 
845
 
838
846
%type <num>
839
 
        type int_type real_type order_dir field_def
840
 
        if_exists opt_table_options
841
 
        opt_if_not_exists
842
 
        opt_temporary all_or_any opt_distinct
 
847
        order_dir
 
848
        field_def
 
849
        opt_table_options
 
850
        all_or_any opt_distinct
843
851
        union_option
844
852
        start_transaction_opts opt_chain opt_release
845
853
        union_opt select_derived_init option_type2
846
 
        opt_status
847
 
        opt_concurrent
848
 
        opt_wait
849
 
        opt_zerofill
850
 
        opt_field_number_signed
851
854
        kill_option
852
855
 
853
856
%type <m_fk_option>
916
919
 
917
920
%type <cast_type> cast_type
918
921
 
919
 
%type <symbol> keyword keyword_sp
 
922
%type <symbol>
 
923
        keyword
 
924
        keyword_sp
 
925
        keyword_exception_for_variable
 
926
        row_format
920
927
 
921
928
%type <charset>
922
929
        collation_name
951
958
        flush_options flush_option
952
959
        equal optional_braces
953
960
        normal_join
954
 
        table_to_table_list table_to_table opt_table_list opt_as
 
961
        table_to_table_list table_to_table opt_table_list
955
962
        single_multi
956
963
        union_clause union_list
957
964
        precision subselect_start
1006
1013
            else
1007
1014
            {
1008
1015
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
1009
 
              session->lex->statement=
1010
 
                new(std::nothrow) statement::EmptyQuery(YYSession);
1011
 
              if (session->lex->statement == NULL)
1012
 
                DRIZZLE_YYABORT;
 
1016
              session->lex->statement= new statement::EmptyQuery(YYSession);
1013
1017
            }
1014
1018
          }
1015
1019
        | verb_clause END_OF_INPUT {}
1055
1059
create:
1056
1060
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1057
1061
          {
1058
 
            Session *session= YYSession;
1059
 
            LEX *lex= session->lex;
1060
 
            lex->sql_command= SQLCOM_CREATE_TABLE;
1061
 
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1062
 
            lex->statement= statement;
1063
 
            if (lex->statement == NULL)
1064
 
              DRIZZLE_YYABORT;
1065
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1066
 
                                                   TL_OPTION_UPDATING,
1067
 
                                                   TL_WRITE))
1068
 
              DRIZZLE_YYABORT;
1069
 
            lex->col_list.empty();
1070
 
            statement->change=NULL;
1071
 
            statement->is_if_not_exists= $4;
1072
 
            statement->create_info.db_type= NULL;
1073
 
            statement->create_info.default_table_charset= NULL;
1074
 
            lex->name.str= 0;
1075
 
 
1076
 
            message::Table &proto= statement->create_table_message;
1077
 
           
1078
 
            proto.set_name($5->table.str);
 
1062
            Lex->sql_command= SQLCOM_CREATE_TABLE;
 
1063
            Lex->statement= new statement::CreateTable(YYSession);
 
1064
 
 
1065
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
 
1066
                                                     TL_OPTION_UPDATING,
 
1067
                                                     TL_WRITE))
 
1068
              DRIZZLE_YYABORT;
 
1069
            Lex->col_list.empty();
 
1070
 
 
1071
            Lex->table()->set_name($5->table.str);
1079
1072
            if ($2)
1080
 
              proto.set_type(message::Table::TEMPORARY);
 
1073
              Lex->table()->set_type(message::Table::TEMPORARY);
1081
1074
            else
1082
 
              proto.set_type(message::Table::STANDARD);
 
1075
              Lex->table()->set_type(message::Table::STANDARD);
1083
1076
          }
1084
 
          create2
 
1077
          create_table_definition
1085
1078
          {
1086
 
            LEX *lex= YYSession->lex;
1087
 
            lex->current_select= &lex->select_lex;
 
1079
            Lex->current_select= &Lex->select_lex;
1088
1080
          }
1089
1081
        | CREATE build_method
1090
1082
          {
1091
 
            LEX *lex=Lex;
1092
 
            lex->sql_command= SQLCOM_CREATE_INDEX;
1093
 
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1094
 
            lex->statement= statement;
1095
 
            if (lex->statement == NULL)
1096
 
              DRIZZLE_YYABORT;
 
1083
            Lex->sql_command= SQLCOM_CREATE_INDEX;
 
1084
            statement::CreateIndex *statement= new statement::CreateIndex(YYSession);
 
1085
            Lex->statement= statement;
 
1086
 
1097
1087
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1098
1088
            statement->alter_info.build_method= $2;
1099
 
            lex->col_list.empty();
 
1089
            Lex->col_list.empty();
1100
1090
            statement->change=NULL;
1101
1091
          }
1102
1092
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
1103
1093
          {
1104
 
            LEX *lex=Lex;
1105
1094
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1106
1095
 
1107
 
            if (!lex->current_select->add_table_to_list(lex->session, $9,
1108
 
                                                        NULL,
1109
 
                                                        TL_OPTION_UPDATING))
 
1096
            if (not Lex->current_select->add_table_to_list(Lex->session, $9,
 
1097
                                                            NULL,
 
1098
                                                            TL_OPTION_UPDATING))
1110
1099
              DRIZZLE_YYABORT;
1111
1100
            Key *key;
1112
 
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1101
            key= new Key($4, $6, &statement->key_create_info, 0, Lex->col_list);
1113
1102
            statement->alter_info.key_list.push_back(key);
1114
 
            lex->col_list.empty();
 
1103
            Lex->col_list.empty();
1115
1104
          }
1116
 
        | CREATE DATABASE opt_if_not_exists ident
 
1105
        | CREATE DATABASE opt_if_not_exists schema_name
1117
1106
          {
1118
 
            LEX *lex=Lex;
1119
 
 
1120
 
            lex->sql_command=SQLCOM_CREATE_DB;
1121
 
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1122
 
            lex->statement= statement;
1123
 
            if (lex->statement == NULL)
1124
 
              DRIZZLE_YYABORT;
1125
 
            statement->is_if_not_exists= $3;
 
1107
            Lex->sql_command=SQLCOM_CREATE_DB;
 
1108
            Lex->statement= new statement::CreateSchema(YYSession);
1126
1109
          }
1127
1110
          opt_create_database_options
1128
1111
          {
1130
1113
          }
1131
1114
        ;
1132
1115
 
1133
 
create2:
1134
 
          '(' create2a {}
1135
 
        | opt_create_table_options
1136
 
          create3 {}
1137
 
        | LIKE table_ident opt_create_table_options
1138
 
          {
1139
 
            Session *session= YYSession;
1140
 
            LEX *lex= session->lex;
1141
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1142
 
 
1143
 
            statement->is_create_table_like= true;
1144
 
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1145
 
              DRIZZLE_YYABORT;
1146
 
          }
1147
 
        | '(' LIKE table_ident ')'
1148
 
          {
1149
 
            Session *session= YYSession;
1150
 
            LEX *lex= session->lex;
1151
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1152
 
 
1153
 
            statement->is_create_table_like= true;
1154
 
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1155
 
              DRIZZLE_YYABORT;
1156
 
          }
1157
 
        ;
1158
 
 
1159
 
create2a:
1160
 
          field_list ')' opt_create_table_options
1161
 
          create3 {}
1162
 
        |  create_select ')'
1163
 
           { Lex->current_select->set_braces(1);}
 
1116
create_table_definition:
 
1117
          '(' field_list ')' opt_create_table_options  create_select_as
 
1118
          { }
 
1119
        | '(' create_select ')'
 
1120
           {
 
1121
             Lex->current_select->set_braces(1);
 
1122
           }
1164
1123
           union_opt {}
 
1124
        |  '(' create_like ')' opt_create_table_options
 
1125
          { }
 
1126
        | create_like opt_create_table_options
 
1127
          { }
 
1128
        | opt_create_table_options create_select_as 
 
1129
          { }
1165
1130
        ;
1166
1131
 
1167
 
create3:
 
1132
create_select_as:
1168
1133
          /* empty */ {}
1169
 
        | opt_duplicate opt_as create_select
1170
 
          { Lex->current_select->set_braces(0);}
 
1134
        | opt_duplicate_as create_select
 
1135
          {
 
1136
            Lex->current_select->set_braces(0);
 
1137
          }
1171
1138
          union_clause {}
1172
 
        | opt_duplicate opt_as '(' create_select ')'
1173
 
          { Lex->current_select->set_braces(1);}
 
1139
        | opt_duplicate_as '(' create_select ')'
 
1140
          {
 
1141
            Lex->current_select->set_braces(1);
 
1142
          }
1174
1143
          union_opt {}
1175
1144
        ;
1176
1145
 
 
1146
create_like:
 
1147
          LIKE table_ident
 
1148
          {
 
1149
            ((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
 
1150
 
 
1151
            if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
 
1152
              DRIZZLE_YYABORT;
 
1153
          }
 
1154
        ;
 
1155
 
1177
1156
create_select:
 
1157
          stored_select
 
1158
          {
 
1159
          }
 
1160
        ;
 
1161
 
 
1162
/*
 
1163
  This rule is used for both CREATE TABLE .. SELECT,  AND INSERT ... SELECT
 
1164
*/
 
1165
stored_select:
1178
1166
          SELECT_SYM
1179
1167
          {
1180
 
            LEX *lex=Lex;
1181
 
            lex->lock_option= TL_READ;
1182
 
            if (lex->sql_command == SQLCOM_INSERT)
 
1168
            Lex->lock_option= TL_READ;
 
1169
            if (Lex->sql_command == SQLCOM_INSERT)
1183
1170
            {
1184
 
              lex->sql_command= SQLCOM_INSERT_SELECT;
1185
 
              delete lex->statement;
1186
 
              lex->statement=
1187
 
                new(std::nothrow) statement::InsertSelect(YYSession);
1188
 
              if (lex->statement == NULL)
1189
 
                DRIZZLE_YYABORT;
 
1171
              Lex->sql_command= SQLCOM_INSERT_SELECT;
 
1172
              delete Lex->statement;
 
1173
              Lex->statement= new statement::InsertSelect(YYSession);
1190
1174
            }
1191
 
            else if (lex->sql_command == SQLCOM_REPLACE)
 
1175
            else if (Lex->sql_command == SQLCOM_REPLACE)
1192
1176
            {
1193
 
              lex->sql_command= SQLCOM_REPLACE_SELECT;
1194
 
              delete lex->statement;
1195
 
              lex->statement=
1196
 
                new(std::nothrow) statement::ReplaceSelect(YYSession);
1197
 
              if (lex->statement == NULL)
1198
 
                DRIZZLE_YYABORT;
 
1177
              Lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1178
              delete Lex->statement;
 
1179
              Lex->statement= new statement::ReplaceSelect(YYSession);
1199
1180
            }
1200
1181
            /*
1201
1182
              The following work only with the local list, the global list
1202
1183
              is created correctly in this case
1203
1184
            */
1204
 
            lex->current_select->table_list.save_and_clear(&lex->save_list);
1205
 
            init_select(lex);
1206
 
            lex->current_select->parsing_place= SELECT_LIST;
 
1185
            Lex->current_select->table_list.save_and_clear(&Lex->save_list);
 
1186
            init_select(Lex);
 
1187
            Lex->current_select->parsing_place= SELECT_LIST;
1207
1188
          }
1208
1189
          select_options select_item_list
1209
1190
          {
1219
1200
          }
1220
1201
        ;
1221
1202
 
1222
 
opt_as:
1223
 
          /* empty */ {}
1224
 
        | AS {}
1225
 
        ;
1226
 
 
1227
1203
opt_create_database_options:
1228
1204
          /* empty */ {}
1229
1205
        | default_collation_schema {}
1272
1248
 
1273
1249
opt_if_not_exists:
1274
1250
          /* empty */ { $$= false; }
1275
 
        | IF not EXISTS { $$= true; }
 
1251
        | IF not EXISTS { $$= true; YYSession->getLex()->setExists(); }
1276
1252
        ;
1277
1253
 
1278
1254
opt_create_table_options:
1296
1272
custom_engine_option:
1297
1273
        ENGINE_SYM equal ident_or_text
1298
1274
          {
1299
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1300
 
 
1301
 
            statement->is_engine_set= true;
1302
 
 
1303
 
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
 
1275
            Lex->table()->mutable_engine()->set_name($3.str);
1304
1276
          }
1305
1277
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1306
1278
          {
1307
 
            message::Table::TableOptions *tableopts;
1308
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1309
 
 
1310
 
            tableopts->set_comment($3.str);
 
1279
            Lex->table()->mutable_options()->set_comment($3.str);
1311
1280
          }
1312
1281
        | AUTO_INC opt_equal ulonglong_num
1313
1282
          {
1314
 
            message::Table::TableOptions *tableopts;
1315
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1316
 
 
1317
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1318
 
 
1319
 
            statement->create_info.auto_increment_value=$3;
1320
 
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1321
 
            tableopts->set_auto_increment_value($3);
1322
 
          }
1323
 
        |  ident_or_text equal ident_or_text
1324
 
          {
1325
 
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1283
            Lex->table()->mutable_options()->set_auto_increment_value($3);
 
1284
          }
 
1285
        |  ROW_FORMAT_SYM equal row_format_or_text
 
1286
          {
 
1287
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
 
1288
 
 
1289
            opt->set_name("ROW_FORMAT");
 
1290
            opt->set_state($3.str);
 
1291
          }
 
1292
        |  FILE_SYM equal TEXT_STRING_sys
 
1293
          {
 
1294
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
 
1295
 
 
1296
            opt->set_name("FILE");
 
1297
            opt->set_state($3.str);
 
1298
          }
 
1299
        |  ident_or_text equal engine_option_value
 
1300
          {
 
1301
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
1326
1302
 
1327
1303
            opt->set_name($1.str);
1328
1304
            opt->set_state($3.str);
1332
1308
            char number_as_string[22];
1333
1309
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
1334
1310
 
1335
 
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1311
            drizzled::message::Engine::Option *opt= Lex->table()->mutable_engine()->add_options();
1336
1312
            opt->set_name($1.str);
1337
1313
            opt->set_state(number_as_string);
1338
1314
          }
1344
1320
          {
1345
1321
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1346
1322
 
1347
 
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1323
            HA_CREATE_INFO *cinfo= &statement->create_info();
1348
1324
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1349
1325
                 cinfo->default_table_charset && $4 &&
1350
1326
                 !my_charset_same(cinfo->default_table_charset,$4))
1353
1329
                         $4->name, cinfo->default_table_charset->csname);
1354
1330
                DRIZZLE_YYABORT;
1355
1331
              }
1356
 
              statement->create_info.default_table_charset= $4;
1357
 
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1332
              statement->create_info().default_table_charset= $4;
 
1333
              statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1358
1334
          }
1359
1335
        ;
1360
1336
 
1368
1344
          }
1369
1345
        ;
1370
1346
 
 
1347
row_format:
 
1348
          COMPACT_SYM  {}
 
1349
        | COMPRESSED_SYM  {}
 
1350
        | DEFAULT  {}
 
1351
        | DYNAMIC_SYM  {}
 
1352
        | FIXED_SYM  {}
 
1353
        | REDUNDANT_SYM  {}
 
1354
        ;
 
1355
 
 
1356
row_format_or_text:
 
1357
          row_format
 
1358
          {
 
1359
            $$.str= YYSession->strmake($1.str, $1.length);
 
1360
            $$.length= $1.length;
 
1361
          }
 
1362
        ;
 
1363
 
1371
1364
column_format_types:
1372
1365
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
1373
1366
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
1400
1393
key_def:
1401
1394
          key_type opt_ident key_alg '(' key_list ')' key_options
1402
1395
          {
1403
 
            LEX *lex=Lex;
1404
1396
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1405
1397
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1406
 
                              lex->col_list);
 
1398
                              Lex->col_list);
1407
1399
            statement->alter_info.key_list.push_back(key);
1408
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1400
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1409
1401
          }
1410
1402
        | opt_constraint constraint_key_type opt_ident key_alg
1411
1403
          '(' key_list ')' key_options
1412
1404
          {
1413
 
            LEX *lex=Lex;
1414
1405
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1415
1406
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1416
 
                              lex->col_list);
 
1407
                              Lex->col_list);
1417
1408
            statement->alter_info.key_list.push_back(key);
1418
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1409
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1419
1410
          }
1420
1411
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1421
1412
          {
1422
 
            LEX *lex=Lex;
1423
1413
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1424
 
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
 
1414
            Key *key= new Foreign_key($1.str ? $1 : $4, Lex->col_list,
1425
1415
                                      $8,
1426
 
                                      lex->ref_list,
 
1416
                                      Lex->ref_list,
1427
1417
                                      statement->fk_delete_opt,
1428
1418
                                      statement->fk_update_opt,
1429
1419
                                      statement->fk_match_option);
1431
1421
            statement->alter_info.key_list.push_back(key);
1432
1422
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1433
1423
                         &default_key_create_info, 1,
1434
 
                         lex->col_list);
 
1424
                         Lex->col_list);
1435
1425
            statement->alter_info.key_list.push_back(key);
1436
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1426
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1437
1427
            /* Only used for ALTER TABLE. Ignored otherwise. */
1438
1428
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1439
1429
          }
1468
1458
field_spec:
1469
1459
          field_ident
1470
1460
          {
1471
 
            LEX *lex=Lex;
1472
1461
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1473
 
            lex->length=lex->dec=0;
1474
 
            lex->type=0;
 
1462
            Lex->length= Lex->dec=0;
 
1463
            Lex->type=0;
1475
1464
            statement->default_value= statement->on_update_value= 0;
1476
1465
            statement->comment= null_lex_str;
1477
 
            lex->charset=NULL;
 
1466
            Lex->charset= NULL;
1478
1467
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1479
1468
 
1480
 
            message::AlterTable &alter_proto=
1481
 
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1482
 
            statement->current_proto_field= alter_proto.add_added_field();
 
1469
            message::AlterTable &alter_proto= ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1470
            Lex->setField(alter_proto.add_added_field());
1483
1471
          }
1484
1472
          field_def
1485
1473
          {
1486
 
            LEX *lex=Lex;
1487
1474
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1488
1475
 
1489
 
            if (statement->current_proto_field)
1490
 
              statement->current_proto_field->set_name($1.str);
 
1476
            if (Lex->field())
 
1477
            {
 
1478
              Lex->field()->set_name($1.str);
 
1479
            }
1491
1480
 
1492
 
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1493
 
                                  lex->length,lex->dec,lex->type,
 
1481
            if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
 
1482
                                  Lex->length, Lex->dec, Lex->type,
1494
1483
                                  statement->column_format,
1495
1484
                                  statement->default_value, statement->on_update_value,
1496
1485
                                  &statement->comment,
1497
 
                                  statement->change, &lex->interval_list, lex->charset))
 
1486
                                  statement->change, &Lex->interval_list, Lex->charset))
1498
1487
              DRIZZLE_YYABORT;
1499
1488
 
1500
 
            statement->current_proto_field= NULL;
 
1489
            Lex->setField(NULL);
1501
1490
          }
1502
1491
        ;
1503
1492
field_def:
1504
 
          type opt_attribute {}
 
1493
          field_definition opt_attribute {}
1505
1494
        ;
1506
1495
 
1507
 
type:
 
1496
field_definition:
1508
1497
          int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1509
1498
          { 
1510
1499
            $$= $1;
1511
1500
            Lex->length=(char*) 0; /* use default length */
1512
 
            statement::CreateTable *statement=
1513
 
              (statement::CreateTable *)Lex->statement;
1514
1501
 
1515
1502
            if ($3 or $4)
1516
1503
            {
1517
1504
              $1= DRIZZLE_TYPE_LONGLONG;
1518
1505
            }
1519
1506
 
1520
 
            if (statement->current_proto_field)
 
1507
            if (Lex->field())
1521
1508
            {
1522
1509
              assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
1523
1510
              // We update the type for unsigned types
1524
1511
              if ($3 or $4)
1525
1512
              {
1526
 
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1527
 
                statement->current_proto_field->mutable_constraints()->set_is_unsigned(true);
 
1513
                Lex->field()->set_type(message::Table::Field::BIGINT);
 
1514
                Lex->field()->mutable_constraints()->set_is_unsigned(true);
1528
1515
              }
1529
1516
              if ($1 == DRIZZLE_TYPE_LONG)
1530
1517
              {
1531
 
                statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1518
                Lex->field()->set_type(message::Table::Field::INTEGER);
1532
1519
              }
1533
1520
              else if ($1 == DRIZZLE_TYPE_LONGLONG)
1534
1521
              {
1535
 
                statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1522
                Lex->field()->set_type(message::Table::Field::BIGINT);
1536
1523
              }
1537
1524
            }
1538
1525
          }
1540
1527
          {
1541
1528
            $$=$1;
1542
1529
 
1543
 
            statement::CreateTable *statement=
1544
 
              (statement::CreateTable *)Lex->statement;
1545
 
 
1546
 
            if (statement->current_proto_field)
 
1530
            if (Lex->field())
1547
1531
            {
1548
1532
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
1549
 
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1533
              Lex->field()->set_type(message::Table::Field::DOUBLE);
1550
1534
            }
1551
1535
          }
1552
1536
          | char '(' NUM ')'
1554
1538
              Lex->length=$3.str;
1555
1539
              $$=DRIZZLE_TYPE_VARCHAR;
1556
1540
 
1557
 
            statement::CreateTable *statement=
1558
 
              (statement::CreateTable *)Lex->statement;
1559
 
 
1560
 
            if (statement->current_proto_field)
 
1541
            if (Lex->field())
1561
1542
            {
1562
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1543
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1563
1544
              message::Table::Field::StringFieldOptions *string_field_options;
1564
1545
 
1565
 
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1546
              string_field_options= Lex->field()->mutable_string_options();
1566
1547
 
1567
1548
              string_field_options->set_length(atoi($3.str));
1568
1549
            }
1572
1553
              Lex->length=(char*) "1";
1573
1554
              $$=DRIZZLE_TYPE_VARCHAR;
1574
1555
 
1575
 
            statement::CreateTable *statement=
1576
 
              (statement::CreateTable *)Lex->statement;
1577
 
 
1578
 
            if (statement->current_proto_field)
1579
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1556
            if (Lex->field())
 
1557
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1580
1558
            }
1581
1559
          | varchar '(' NUM ')'
1582
1560
            {
1583
1561
              Lex->length=$3.str;
1584
1562
              $$= DRIZZLE_TYPE_VARCHAR;
1585
1563
 
1586
 
            statement::CreateTable *statement=
1587
 
              (statement::CreateTable *)Lex->statement;
1588
 
 
1589
 
            if (statement->current_proto_field)
 
1564
            if (Lex->field())
1590
1565
            {
1591
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1566
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1592
1567
 
1593
1568
              message::Table::Field::StringFieldOptions *string_field_options;
1594
1569
 
1595
 
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1570
              string_field_options= Lex->field()->mutable_string_options();
1596
1571
 
1597
1572
              string_field_options->set_length(atoi($3.str));
1598
1573
            }
1603
1578
              Lex->charset=&my_charset_bin;
1604
1579
              $$= DRIZZLE_TYPE_VARCHAR;
1605
1580
 
1606
 
            statement::CreateTable *statement=
1607
 
              (statement::CreateTable *)Lex->statement;
1608
 
 
1609
 
            if (statement->current_proto_field)
 
1581
            if (Lex->field())
1610
1582
            {
1611
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1583
              Lex->field()->set_type(message::Table::Field::VARCHAR);
1612
1584
              message::Table::Field::StringFieldOptions *string_field_options;
1613
1585
 
1614
 
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1586
              string_field_options= Lex->field()->mutable_string_options();
1615
1587
 
1616
1588
              string_field_options->set_length(atoi($3.str));
1617
1589
              string_field_options->set_collation_id(my_charset_bin.number);
1622
1594
          {
1623
1595
            $$=DRIZZLE_TYPE_DATE;
1624
1596
 
1625
 
            statement::CreateTable *statement=
1626
 
              (statement::CreateTable *)Lex->statement;
1627
 
 
1628
 
            if (statement->current_proto_field)
1629
 
              statement->current_proto_field->set_type(message::Table::Field::DATE);
 
1597
            if (Lex->field())
 
1598
              Lex->field()->set_type(message::Table::Field::DATE);
1630
1599
          }
1631
1600
          | TIME_SYM
1632
1601
          {
1633
1602
            $$=DRIZZLE_TYPE_TIME;
1634
1603
 
1635
 
            statement::CreateTable *statement=
1636
 
              (statement::CreateTable *)Lex->statement;
1637
 
 
1638
 
            if (statement->current_proto_field)
1639
 
              statement->current_proto_field->set_type(message::Table::Field::TIME);
 
1604
            if (Lex->field())
 
1605
              Lex->field()->set_type(message::Table::Field::TIME);
1640
1606
          }
1641
1607
          | TIMESTAMP_SYM
1642
1608
          {
1643
1609
            $$=DRIZZLE_TYPE_TIMESTAMP;
1644
1610
 
1645
 
            statement::CreateTable *statement=
1646
 
              (statement::CreateTable *)Lex->statement;
1647
 
 
1648
 
            if (statement->current_proto_field)
1649
 
              statement->current_proto_field->set_type(message::Table::Field::EPOCH);
1650
 
          }
1651
 
          | LONG_SYM TIMESTAMP_SYM
1652
 
          {
1653
 
            $$=DRIZZLE_TYPE_TIMESTAMP;
1654
 
 
1655
 
            statement::CreateTable *statement=
1656
 
              (statement::CreateTable *)Lex->statement;
1657
 
 
1658
 
            if (statement->current_proto_field)
1659
 
            {
1660
 
              statement->current_proto_field->set_type(message::Table::Field::EPOCH);
1661
 
              statement->current_proto_field->mutable_time_options()->set_microseconds(true);
1662
 
            }
 
1611
            if (Lex->field())
 
1612
              Lex->field()->set_type(message::Table::Field::EPOCH);
1663
1613
          }
1664
1614
          | DATETIME_SYM
1665
1615
          {
1666
1616
            $$=DRIZZLE_TYPE_DATETIME;
1667
1617
 
1668
 
            statement::CreateTable *statement=
1669
 
              (statement::CreateTable *)Lex->statement;
1670
 
 
1671
 
            if (statement->current_proto_field)
1672
 
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1618
            if (Lex->field())
 
1619
              Lex->field()->set_type(message::Table::Field::DATETIME);
1673
1620
          }
1674
1621
          | BLOB_SYM
1675
1622
            {
1677
1624
              $$=DRIZZLE_TYPE_BLOB;
1678
1625
              Lex->length=(char*) 0; /* use default length */
1679
1626
 
1680
 
              statement::CreateTable *statement=
1681
 
                (statement::CreateTable *)Lex->statement;
1682
 
 
1683
 
              if (statement->current_proto_field)
 
1627
              if (Lex->field())
1684
1628
              {
1685
 
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1629
                Lex->field()->set_type(message::Table::Field::BLOB);
1686
1630
                message::Table::Field::StringFieldOptions *string_field_options;
1687
1631
 
1688
 
                string_field_options= statement->current_proto_field->mutable_string_options();
 
1632
                string_field_options= Lex->field()->mutable_string_options();
1689
1633
                string_field_options->set_collation_id(my_charset_bin.number);
1690
1634
                string_field_options->set_collation(my_charset_bin.name);
1691
1635
              }
1695
1639
              $$=DRIZZLE_TYPE_BLOB;
1696
1640
              Lex->length=(char*) 0; /* use default length */
1697
1641
 
1698
 
            statement::CreateTable *statement=
1699
 
              (statement::CreateTable *)Lex->statement;
1700
 
 
1701
 
            if (statement->current_proto_field)
1702
 
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1642
            if (Lex->field())
 
1643
              Lex->field()->set_type(message::Table::Field::BLOB);
1703
1644
            }
1704
1645
          | DECIMAL_SYM float_options
1705
1646
          {
1706
1647
            $$=DRIZZLE_TYPE_DECIMAL;
1707
1648
 
1708
 
            statement::CreateTable *statement=
1709
 
              (statement::CreateTable *)Lex->statement;
1710
 
 
1711
 
            if (statement->current_proto_field)
1712
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1649
            if (Lex->field())
 
1650
              Lex->field()->set_type(message::Table::Field::DECIMAL);
1713
1651
          }
1714
1652
          | NUMERIC_SYM float_options
1715
1653
          {
1716
1654
            $$=DRIZZLE_TYPE_DECIMAL;
1717
1655
 
1718
 
            statement::CreateTable *statement=
1719
 
              (statement::CreateTable *)Lex->statement;
1720
 
 
1721
 
            if (statement->current_proto_field)
1722
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1656
            if (Lex->field())
 
1657
              Lex->field()->set_type(message::Table::Field::DECIMAL);
1723
1658
          }
1724
1659
          | FIXED_SYM float_options
1725
1660
          {
1726
1661
            $$=DRIZZLE_TYPE_DECIMAL;
1727
1662
 
1728
 
            statement::CreateTable *statement=
1729
 
              (statement::CreateTable *)Lex->statement;
1730
 
 
1731
 
            if (statement->current_proto_field)
1732
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1663
            if (Lex->field())
 
1664
              Lex->field()->set_type(message::Table::Field::DECIMAL);
1733
1665
          }
1734
1666
          | ENUM_SYM
1735
1667
            {Lex->interval_list.empty();}
1737
1669
          {
1738
1670
            $$=DRIZZLE_TYPE_ENUM;
1739
1671
 
1740
 
            statement::CreateTable *statement=
1741
 
              (statement::CreateTable *)Lex->statement;
1742
 
 
1743
 
            if (statement->current_proto_field)
1744
 
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
 
1672
            if (Lex->field())
 
1673
              Lex->field()->set_type(message::Table::Field::ENUM);
1745
1674
          }
1746
 
          | UUID_SYM
 
1675
        | UUID_SYM
1747
1676
          {
1748
1677
            $$=DRIZZLE_TYPE_UUID;
1749
1678
 
1750
 
            statement::CreateTable *statement=
1751
 
              (statement::CreateTable *)Lex->statement;
1752
 
 
1753
 
            if (statement->current_proto_field)
1754
 
              statement->current_proto_field->set_type(message::Table::Field::UUID);
 
1679
            if (Lex->field())
 
1680
              Lex->field()->set_type(message::Table::Field::UUID);
1755
1681
          }
1756
 
        | BOOL_SYM
1757
 
        {
1758
 
          $$=DRIZZLE_TYPE_BOOLEAN;
1759
 
 
1760
 
          statement::CreateTable *statement=
1761
 
            (statement::CreateTable *)Lex->statement;
1762
 
 
1763
 
          if (statement->current_proto_field)
1764
 
            statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
1765
 
        }
1766
1682
        | BOOLEAN_SYM
1767
 
        {
1768
 
          $$=DRIZZLE_TYPE_BOOLEAN;
1769
 
 
1770
 
          statement::CreateTable *statement=
1771
 
            (statement::CreateTable *)Lex->statement;
1772
 
 
1773
 
          if (statement->current_proto_field)
1774
 
            statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
1775
 
        }
 
1683
          {
 
1684
            $$=DRIZZLE_TYPE_BOOLEAN;
 
1685
 
 
1686
            if (Lex->field())
 
1687
              Lex->field()->set_type(message::Table::Field::BOOLEAN);
 
1688
          }
1776
1689
        | SERIAL_SYM
1777
1690
          {
1778
1691
            $$=DRIZZLE_TYPE_LONGLONG;
1779
1692
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1780
1693
 
1781
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1782
 
            if (statement->current_proto_field)
 
1694
            if (Lex->field())
1783
1695
            {
1784
1696
              message::Table::Field::FieldConstraints *constraints;
1785
 
              constraints= statement->current_proto_field->mutable_constraints();
 
1697
              constraints= Lex->field()->mutable_constraints();
1786
1698
              constraints->set_is_nullable(false);
1787
1699
 
1788
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1700
              Lex->field()->set_type(message::Table::Field::BIGINT);
1789
1701
            }
1790
1702
          }
1791
1703
        ;
1827
1739
precision:
1828
1740
          '(' NUM ',' NUM ')'
1829
1741
          {
1830
 
            LEX *lex=Lex;
1831
 
            lex->length=$2.str;
1832
 
            lex->dec=$4.str;
 
1742
            Lex->length= $2.str;
 
1743
            Lex->dec= $4.str;
1833
1744
          }
1834
1745
        ;
1835
1746
 
1839
1750
        ;
1840
1751
 
1841
1752
opt_field_number_signed:
1842
 
          /* empty */ { $$= 0; }
1843
 
        | SIGNED_SYM { $$= 0; }
1844
 
        | UNSIGNED_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
 
1753
          /* empty */ { $$= false; }
 
1754
        | SIGNED_SYM { $$= false; }
 
1755
        | UNSIGNED_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1845
1756
        ;
1846
1757
 
1847
1758
ignored_field_number_length:
1850
1761
        ;
1851
1762
 
1852
1763
opt_zerofill:
1853
 
          /* empty */ { $$= 0; }
1854
 
        | ZEROFILL_SYM { $$= 1; Lex->type|= UNSIGNED_FLAG; }
 
1764
          /* empty */ { $$= false; }
 
1765
        | ZEROFILL_SYM { $$= true; Lex->type|= UNSIGNED_FLAG; }
1855
1766
        ;
1856
1767
 
1857
1768
opt_precision:
1872
1783
attribute:
1873
1784
          NULL_SYM
1874
1785
          {
1875
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1876
1786
            Lex->type&= ~ NOT_NULL_FLAG;
1877
1787
 
1878
 
            if (statement->current_proto_field)
 
1788
            if (Lex->field())
1879
1789
            {
1880
1790
              message::Table::Field::FieldConstraints *constraints;
1881
 
              constraints= statement->current_proto_field->mutable_constraints();
 
1791
              constraints= Lex->field()->mutable_constraints();
1882
1792
              constraints->set_is_nullable(true);
1883
1793
            }
1884
1794
          }
1891
1801
          }
1892
1802
        | not NULL_SYM
1893
1803
          {
1894
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1895
1804
            Lex->type|= NOT_NULL_FLAG;
1896
1805
 
1897
 
            if (statement->current_proto_field)
 
1806
            if (Lex->field())
1898
1807
            {
1899
1808
              message::Table::Field::FieldConstraints *constraints;
1900
 
              constraints= statement->current_proto_field->mutable_constraints();
 
1809
              constraints= Lex->field()->mutable_constraints();
1901
1810
              constraints->set_is_nullable(false);
1902
1811
            }
1903
1812
          }
1914
1823
          {
1915
1824
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1916
1825
 
1917
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1918
 
            if (statement->current_proto_field)
 
1826
            if (Lex->field())
1919
1827
            {
1920
1828
              message::Table::Field::FieldConstraints *constraints;
1921
1829
 
1922
 
              constraints= statement->current_proto_field->mutable_constraints();
 
1830
              constraints= Lex->field()->mutable_constraints();
1923
1831
              constraints->set_is_nullable(false);
1924
1832
            }
1925
1833
          }
1926
1834
        | SERIAL_SYM DEFAULT VALUE_SYM
1927
1835
          {
1928
 
            LEX *lex=Lex;
1929
1836
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1930
1837
 
1931
 
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1838
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1932
1839
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1933
1840
 
1934
 
            if (statement->current_proto_field)
 
1841
            if (Lex->field())
1935
1842
            {
1936
1843
              message::Table::Field::FieldConstraints *constraints;
1937
 
              constraints= statement->current_proto_field->mutable_constraints();
 
1844
              constraints= Lex->field()->mutable_constraints();
1938
1845
              constraints->set_is_nullable(false);
1939
1846
            }
1940
1847
          }
1941
1848
        | opt_primary KEY_SYM
1942
1849
          {
1943
 
            LEX *lex=Lex;
1944
1850
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1945
1851
 
1946
 
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
1852
            Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1947
1853
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1948
1854
 
1949
 
            if (statement->current_proto_field)
 
1855
            if (Lex->field())
1950
1856
            {
1951
1857
              message::Table::Field::FieldConstraints *constraints;
1952
 
              constraints= statement->current_proto_field->mutable_constraints();
 
1858
              constraints= Lex->field()->mutable_constraints();
1953
1859
              constraints->set_is_nullable(false);
1954
1860
            }
1955
1861
          }
1956
1862
        | UNIQUE_SYM
1957
1863
          {
1958
 
            LEX *lex=Lex;
1959
1864
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1960
1865
 
1961
 
            lex->type|= UNIQUE_FLAG;
 
1866
            Lex->type|= UNIQUE_FLAG;
1962
1867
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1963
1868
          }
1964
1869
        | UNIQUE_SYM KEY_SYM
1965
1870
          {
1966
 
            LEX *lex=Lex;
1967
1871
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1968
1872
 
1969
 
            lex->type|= UNIQUE_KEY_FLAG;
 
1873
            Lex->type|= UNIQUE_KEY_FLAG;
1970
1874
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1971
1875
          }
1972
1876
        | COMMENT_SYM TEXT_STRING_sys
1974
1878
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1975
1879
            statement->comment= $2;
1976
1880
 
1977
 
            if (statement->current_proto_field)
1978
 
              statement->current_proto_field->set_comment($2.str);
 
1881
            if (Lex->field())
 
1882
              Lex->field()->set_comment($2.str);
1979
1883
          }
1980
1884
        | COLLATE_SYM collation_name
1981
1885
          {
2047
1951
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
2048
1952
        | ident
2049
1953
          {
2050
 
            LEX *lex= Lex;
2051
 
            lex->ref_list.empty();
2052
 
            lex->ref_list.push_back(new Key_part_spec($1, 0));
 
1954
            Lex->ref_list.empty();
 
1955
            Lex->ref_list.push_back(new Key_part_spec($1, 0));
2053
1956
          }
2054
1957
        ;
2055
1958
 
2139
2042
        ;
2140
2043
 
2141
2044
/*
2142
 
  For now, key_alg initializies lex->key_create_info.
 
2045
  For now, key_alg initializies Lex->key_create_info.
2143
2046
  In the future, when all key options are after key definition,
2144
2047
  we can remove key_alg and move init_key_options to key_options
2145
2048
*/
2216
2119
alter:
2217
2120
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
2218
2121
          {
2219
 
            Session *session= YYSession;
2220
 
            LEX *lex= session->lex;
2221
 
            lex->name.str= 0;
2222
 
            lex->name.length= 0;
2223
 
            lex->sql_command= SQLCOM_ALTER_TABLE;
2224
 
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
2225
 
            lex->statement= statement;
2226
 
            if (lex->statement == NULL)
2227
 
              DRIZZLE_YYABORT;
2228
 
            lex->duplicates= DUP_ERROR;
2229
 
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2230
 
                                                   TL_OPTION_UPDATING))
2231
 
              DRIZZLE_YYABORT;
2232
 
            lex->col_list.empty();
2233
 
            lex->select_lex.init_order();
2234
 
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
 
2122
            Lex->sql_command= SQLCOM_ALTER_TABLE;
 
2123
            statement::AlterTable *statement= new statement::AlterTable(YYSession);
 
2124
            Lex->statement= statement;
 
2125
            Lex->duplicates= DUP_ERROR;
 
2126
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
 
2127
                                                     TL_OPTION_UPDATING))
 
2128
              DRIZZLE_YYABORT;
 
2129
 
 
2130
            Lex->col_list.empty();
 
2131
            Lex->select_lex.init_order();
 
2132
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
2235
2133
            statement->alter_info.build_method= $2;
2236
2134
          }
2237
2135
          alter_commands
2238
2136
          {}
2239
 
        | ALTER_SYM DATABASE ident_or_empty
 
2137
        | ALTER_SYM DATABASE schema_name
2240
2138
          {
2241
 
            LEX *lex=Lex;
2242
 
            lex->sql_command=SQLCOM_ALTER_DB;
2243
 
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
2244
 
            if (lex->statement == NULL)
2245
 
              DRIZZLE_YYABORT;
 
2139
            Lex->sql_command=SQLCOM_ALTER_DB;
 
2140
            Lex->statement= new statement::AlterSchema(YYSession);
2246
2141
          }
2247
2142
          default_collation_schema
2248
2143
          {
2249
 
            LEX *lex=Lex;
2250
 
            lex->name= $3;
2251
 
            if (lex->name.str == NULL &&
2252
 
                lex->copy_db_to(&lex->name.str, &lex->name.length))
 
2144
            Lex->name= $3;
 
2145
            if (Lex->name.str == NULL && Lex->copy_db_to(&Lex->name.str, &Lex->name.length))
2253
2146
              DRIZZLE_YYABORT;
2254
2147
          }
2255
2148
        ;
2256
2149
 
2257
 
ident_or_empty:
2258
 
          /* empty */ { $$.str= 0; $$.length= 0; }
2259
 
        | ident { $$= $1; }
2260
 
        ;
2261
 
 
2262
2150
alter_commands:
2263
2151
          /* empty */
2264
2152
        | DISCARD TABLESPACE
2328
2216
          field_spec opt_place
2329
2217
        | MODIFY_SYM opt_column field_ident
2330
2218
          {
2331
 
            LEX *lex=Lex;
2332
2219
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2333
 
            lex->length=lex->dec=0; lex->type=0;
 
2220
            Lex->length= Lex->dec=0;
 
2221
            Lex->type= 0;
2334
2222
            statement->default_value= statement->on_update_value= 0;
2335
2223
            statement->comment= null_lex_str;
2336
 
            lex->charset= NULL;
 
2224
            Lex->charset= NULL;
2337
2225
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2338
2226
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2339
2227
 
2340
 
            statement->current_proto_field= NULL;
 
2228
            Lex->setField(NULL);
2341
2229
          }
2342
2230
          field_def
2343
2231
          {
2344
 
            LEX *lex=Lex;
2345
2232
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2346
2233
 
2347
 
            if (add_field_to_list(lex->session,&$3,
 
2234
            if (add_field_to_list(Lex->session,&$3,
2348
2235
                                  (enum enum_field_types) $5,
2349
 
                                  lex->length, lex->dec, lex->type,
 
2236
                                  Lex->length, Lex->dec, Lex->type,
2350
2237
                                  statement->column_format,
2351
2238
                                  statement->default_value,
2352
2239
                                  statement->on_update_value,
2353
2240
                                  &statement->comment,
2354
 
                                  $3.str, &lex->interval_list, lex->charset))
 
2241
                                  $3.str, &Lex->interval_list, Lex->charset))
2355
2242
              DRIZZLE_YYABORT;
2356
2243
          }
2357
2244
          opt_place
2416
2303
          }
2417
2304
        | RENAME opt_to table_ident
2418
2305
          {
2419
 
            LEX *lex=Lex;
2420
2306
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2421
2307
            size_t dummy;
2422
2308
 
2423
 
            lex->select_lex.db=$3->db.str;
2424
 
            if (lex->select_lex.db == NULL &&
2425
 
                lex->copy_db_to(&lex->select_lex.db, &dummy))
 
2309
            Lex->select_lex.db=$3->db.str;
 
2310
            if (Lex->select_lex.db == NULL &&
 
2311
                Lex->copy_db_to(&Lex->select_lex.db, &dummy))
2426
2312
            {
2427
2313
              DRIZZLE_YYABORT;
2428
2314
            }
2433
2319
              DRIZZLE_YYABORT;
2434
2320
            }
2435
2321
 
2436
 
            lex->name= $3->table;
 
2322
            Lex->name= $3->table;
2437
2323
            statement->alter_info.flags.set(ALTER_RENAME);
2438
2324
          }
2439
2325
        | CONVERT_SYM TO_SYM collation_name_or_default
2440
2326
          {
2441
2327
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2442
2328
 
2443
 
            statement->create_info.table_charset=
2444
 
            statement->create_info.default_table_charset= $3;
2445
 
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
 
2329
            statement->create_info().table_charset=
 
2330
            statement->create_info().default_table_charset= $3;
 
2331
            statement->create_info().used_fields|= (HA_CREATE_USED_CHARSET |
2446
2332
              HA_CREATE_USED_DEFAULT_CHARSET);
2447
2333
            statement->alter_info.flags.set(ALTER_CONVERT);
2448
2334
          }
2504
2390
start:
2505
2391
          START_SYM TRANSACTION_SYM start_transaction_opts
2506
2392
          {
2507
 
            LEX *lex= Lex;
2508
 
            lex->sql_command= SQLCOM_BEGIN;
2509
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2510
 
            if (lex->statement == NULL)
2511
 
              DRIZZLE_YYABORT;
 
2393
            Lex->sql_command= SQLCOM_BEGIN;
 
2394
            Lex->statement= new statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
2512
2395
          }
2513
2396
        ;
2514
2397
 
2523
2406
analyze:
2524
2407
          ANALYZE_SYM table_or_tables
2525
2408
          {
2526
 
            LEX *lex=Lex;
2527
 
            lex->sql_command = SQLCOM_ANALYZE;
2528
 
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
2529
 
            if (lex->statement == NULL)
2530
 
              DRIZZLE_YYABORT;
 
2409
            Lex->sql_command = SQLCOM_ANALYZE;
 
2410
            Lex->statement= new statement::Analyze(YYSession);
2531
2411
          }
2532
2412
          table_list
2533
2413
          {}
2536
2416
check:
2537
2417
          CHECK_SYM table_or_tables
2538
2418
          {
2539
 
            LEX *lex=Lex;
2540
 
 
2541
 
            lex->sql_command = SQLCOM_CHECK;
2542
 
            lex->statement= new(std::nothrow) statement::Check(YYSession);
2543
 
            if (lex->statement == NULL)
2544
 
              DRIZZLE_YYABORT;
 
2419
            Lex->sql_command = SQLCOM_CHECK;
 
2420
            Lex->statement= new statement::Check(YYSession);
2545
2421
          }
2546
2422
          table_list
2547
2423
          {}
2551
2427
          RENAME table_or_tables
2552
2428
          {
2553
2429
            Lex->sql_command= SQLCOM_RENAME_TABLE;
2554
 
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
2555
 
            if (Lex->statement == NULL)
2556
 
              DRIZZLE_YYABORT;
 
2430
            Lex->statement= new statement::RenameTable(YYSession);
2557
2431
          }
2558
2432
          table_to_table_list
2559
2433
          {}
2567
2441
table_to_table:
2568
2442
          table_ident TO_SYM table_ident
2569
2443
          {
2570
 
            LEX *lex=Lex;
2571
 
            Select_Lex *sl= lex->current_select;
2572
 
            if (!sl->add_table_to_list(lex->session, $1,NULL,TL_OPTION_UPDATING,
 
2444
            Select_Lex *sl= Lex->current_select;
 
2445
            if (!sl->add_table_to_list(Lex->session, $1,NULL,TL_OPTION_UPDATING,
2573
2446
                                       TL_IGNORE) ||
2574
 
                !sl->add_table_to_list(lex->session, $3,NULL,TL_OPTION_UPDATING,
 
2447
                !sl->add_table_to_list(Lex->session, $3,NULL,TL_OPTION_UPDATING,
2575
2448
                                       TL_IGNORE))
2576
2449
              DRIZZLE_YYABORT;
2577
2450
          }
2585
2458
select:
2586
2459
          select_init
2587
2460
          {
2588
 
            LEX *lex= Lex;
2589
 
            lex->sql_command= SQLCOM_SELECT;
2590
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
2591
 
            if (lex->statement == NULL)
2592
 
              DRIZZLE_YYABORT;
 
2461
            Lex->sql_command= SQLCOM_SELECT;
 
2462
            Lex->statement= new statement::Select(YYSession);
2593
2463
          }
2594
2464
        ;
2595
2465
 
2621
2491
select_init2:
2622
2492
          select_part2
2623
2493
          {
2624
 
            LEX *lex= Lex;
2625
 
            Select_Lex * sel= lex->current_select;
2626
 
            if (lex->current_select->set_braces(0))
 
2494
            Select_Lex * sel= Lex->current_select;
 
2495
            if (Lex->current_select->set_braces(0))
2627
2496
            {
2628
2497
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2629
2498
              my_parse_error(&pass);
2642
2511
 
2643
2512
select_part2:
2644
2513
          {
2645
 
            LEX *lex= Lex;
2646
 
            Select_Lex *sel= lex->current_select;
 
2514
            Select_Lex *sel= Lex->current_select;
2647
2515
            if (sel->linkage != UNION_TYPE)
2648
 
              init_select(lex);
2649
 
            lex->current_select->parsing_place= SELECT_LIST;
 
2516
              init_select(Lex);
 
2517
            Lex->current_select->parsing_place= SELECT_LIST;
2650
2518
          }
2651
2519
          select_options select_item_list
2652
2520
          {
2715
2583
          /* empty */
2716
2584
        | FOR_SYM UPDATE_SYM
2717
2585
          {
2718
 
            LEX *lex=Lex;
2719
 
            lex->current_select->set_lock_for_tables(TL_WRITE);
 
2586
            Lex->current_select->set_lock_for_tables(TL_WRITE);
2720
2587
          }
2721
2588
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2722
2589
          {
2723
 
            LEX *lex=Lex;
2724
 
            lex->current_select->
 
2590
            Lex->current_select->
2725
2591
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2726
2592
          }
2727
2593
        ;
2731
2597
        | select_item
2732
2598
        | '*'
2733
2599
          {
2734
 
            Session *session= YYSession;
2735
 
            if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
2600
            if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
2736
2601
                                                          context,
2737
2602
                                                          NULL, NULL, "*")))
2738
2603
              DRIZZLE_YYABORT;
2739
 
            (session->lex->current_select->with_wild)++;
 
2604
            (YYSession->lex->current_select->with_wild)++;
2740
2605
          }
2741
2606
        ;
2742
2607
 
2743
2608
select_item:
2744
2609
          remember_name table_wild remember_end
2745
2610
          {
2746
 
            Session *session= YYSession;
2747
 
 
2748
 
            if (session->add_item_to_list($2))
 
2611
            if (YYSession->add_item_to_list($2))
2749
2612
              DRIZZLE_YYABORT;
2750
2613
          }
2751
2614
        | remember_name expr remember_end select_alias
2752
2615
          {
2753
 
            Session *session= YYSession;
2754
2616
            assert($1 < $3);
2755
2617
 
2756
 
            if (session->add_item_to_list($2))
 
2618
            if (YYSession->add_item_to_list($2))
2757
2619
              DRIZZLE_YYABORT;
 
2620
 
2758
2621
            if ($4.str)
2759
2622
            {
2760
2623
              $2->is_autogenerated_name= false;
2762
2625
            }
2763
2626
            else if (!$2->name)
2764
2627
            {
2765
 
              $2->set_name($1, (uint) ($3 - $1), session->charset());
 
2628
              $2->set_name($1, (uint) ($3 - $1), YYSession->charset());
2766
2629
            }
2767
2630
          }
2768
2631
        ;
2769
2632
 
2770
2633
remember_name:
2771
2634
          {
2772
 
            Session *session= YYSession;
2773
 
            Lex_input_stream *lip= session->m_lip;
 
2635
            Lex_input_stream *lip= YYSession->m_lip;
2774
2636
            $$= (char*) lip->get_cpp_tok_start();
2775
2637
          }
2776
2638
        ;
2777
2639
 
2778
2640
remember_end:
2779
2641
          {
2780
 
            Session *session= YYSession;
2781
 
            Lex_input_stream *lip= session->m_lip;
 
2642
            Lex_input_stream *lip= YYSession->m_lip;
2782
2643
            $$= (char*) lip->get_cpp_tok_end();
2783
2644
          }
2784
2645
        ;
2931
2792
          }
2932
2793
        | bit_expr not IN_SYM '(' subselect ')'
2933
2794
          {
2934
 
            Session *session= YYSession;
2935
 
            Item *item= new (session->mem_root) Item_in_subselect($1, $5);
2936
 
            $$= negate_expression(session, item);
 
2795
            Item *item= new (YYSession->mem_root) Item_in_subselect($1, $5);
 
2796
            $$= negate_expression(YYSession, item);
2937
2797
          }
2938
2798
        | bit_expr IN_SYM '(' expr ')'
2939
2799
          {
3055
2915
        | function_call_conflict
3056
2916
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
3057
2917
          {
3058
 
            Session *session= YYSession;
3059
 
            Item *i1= new (session->mem_root) Item_string($3.str,
 
2918
            Item *i1= new (YYSession->mem_root) Item_string($3.str,
3060
2919
                                                      $3.length,
3061
 
                                                      session->charset());
3062
 
            $$= new (session->mem_root) Item_func_set_collation($1, i1);
 
2920
                                                      YYSession->charset());
 
2921
            $$= new (YYSession->mem_root) Item_func_set_collation($1, i1);
3063
2922
          }
3064
2923
        | literal
3065
2924
        | variable
3097
2956
          }
3098
2957
        | CAST_SYM '(' expr AS cast_type ')'
3099
2958
          {
3100
 
            LEX *lex= Lex;
3101
 
            $$= create_func_cast(YYSession, $3, $5, lex->length, lex->dec,
3102
 
                                 lex->charset);
 
2959
            $$= create_func_cast(YYSession, $3, $5, Lex->length, Lex->dec,
 
2960
                                 Lex->charset);
3103
2961
            if (!$$)
3104
2962
              DRIZZLE_YYABORT;
3105
2963
          }
3155
3013
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
3156
3014
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3157
3015
          {
3158
 
            Session *session= YYSession;
3159
 
            List<Item> *list= new (session->mem_root) List<Item>;
 
3016
            List<Item> *list= new (YYSession->mem_root) List<Item>;
3160
3017
            list->push_front($5);
3161
3018
            list->push_front($3);
3162
 
            Item_row *item= new (session->mem_root) Item_row(*list);
3163
 
            $$= new (session->mem_root) Item_func_interval(item);
 
3019
            Item_row *item= new (YYSession->mem_root) Item_row(*list);
 
3020
            $$= new (YYSession->mem_root) Item_func_interval(item);
3164
3021
          }
3165
3022
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3166
3023
          {
3167
 
            Session *session= YYSession;
3168
3024
            $7->push_front($5);
3169
3025
            $7->push_front($3);
3170
 
            Item_row *item= new (session->mem_root) Item_row(*$7);
3171
 
            $$= new (session->mem_root) Item_func_interval(item);
 
3026
            Item_row *item= new (YYSession->mem_root) Item_row(*$7);
 
3027
            $$= new (YYSession->mem_root) Item_func_interval(item);
3172
3028
          }
3173
3029
        | LEFT '(' expr ',' expr ')'
3174
3030
          { $$= new (YYSession->mem_root) Item_func_left($3,$5); }
3200
3056
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3201
3057
        | USER '(' ')'
3202
3058
          {
3203
 
            std::string user_str("user");
3204
 
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
 
3059
            if (! ($$= reserved_keyword_function(YYSession, "user", NULL)))
3205
3060
            {
3206
3061
              DRIZZLE_YYABORT;
3207
3062
            }
3394
3249
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
3395
3250
        | REPLACE '(' expr ',' expr ',' expr ')'
3396
3251
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
3397
 
        | REVERSE_SYM '(' expr ')'
3398
 
          {
3399
 
            std::string reverse_str("reverse");
3400
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3401
 
            args->push_back($3);
3402
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3403
 
            {
3404
 
              DRIZZLE_YYABORT;
3405
 
            }
3406
 
          }
3407
3252
        | TRUNCATE_SYM '(' expr ',' expr ')'
3408
3253
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
3409
3254
        | WAIT_SYM '(' expr ')'
3455
3300
          }
3456
3301
          opt_udf_expr_list ')'
3457
3302
          {
3458
 
            Session *session= YYSession;
3459
3303
            Create_func *builder;
3460
3304
            Item *item= NULL;
3461
3305
 
3471
3315
            builder= find_native_function_builder($1);
3472
3316
            if (builder)
3473
3317
            {
3474
 
              item= builder->create(session, $1, $4);
 
3318
              item= builder->create(YYSession, $1, $4);
3475
3319
            }
3476
3320
            else
3477
3321
            {
3479
3323
              const plugin::Function *udf= $<udf>3;
3480
3324
              if (udf)
3481
3325
              {
3482
 
                item= Create_udf_func::s_singleton.create(session, udf, $4);
 
3326
                item= Create_udf_func::s_singleton.create(YYSession, udf, $4);
3483
3327
              } else {
3484
3328
                /* fix for bug 250065, from Andrew Garner <muzazzi@gmail.com> */
3485
3329
                my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", $1.str);
3596
3440
        ;
3597
3441
 
3598
3442
variable_aux:
3599
 
          ident_or_text SET_VAR expr
 
3443
          user_variable_ident SET_VAR expr
3600
3444
          {
3601
3445
            $$= new Item_func_set_user_var($1, $3);
3602
3446
            Lex->setCacheable(false);
3603
3447
          }
3604
 
        | ident_or_text
 
3448
        | user_variable_ident
3605
3449
          {
3606
3450
            $$= new Item_func_get_user_var(*YYSession, $1);
3607
3451
            Lex->setCacheable(false);
3608
3452
          }
3609
 
        | '@' opt_var_ident_type ident_or_text opt_component
 
3453
        | '@' opt_var_ident_type user_variable_ident opt_component
3610
3454
          {
3611
3455
            /* disallow "SELECT @@global.global.variable" */
3612
3456
            if ($3.str && $4.str && check_reserved_words(&$3))
3621
3465
        ;
3622
3466
 
3623
3467
opt_distinct:
3624
 
          /* empty */ { $$ = 0; }
3625
 
        | DISTINCT    { $$ = 1; }
 
3468
          /* empty */ { $$ = false; }
 
3469
        | DISTINCT    { $$ = true; }
3626
3470
        ;
3627
3471
 
3628
3472
opt_gconcat_separator:
3651
3495
in_sum_expr:
3652
3496
          opt_all
3653
3497
          {
3654
 
            LEX *lex= Lex;
3655
 
            if (lex->current_select->inc_in_sum_expr())
 
3498
            if (Lex->current_select->inc_in_sum_expr())
3656
3499
            {
3657
3500
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3658
3501
              my_parse_error(&pass);
3737
3580
          table_factor { $$=$1; }
3738
3581
        | join_table
3739
3582
          {
3740
 
            LEX *lex= Lex;
3741
 
            if (!($$= lex->current_select->nest_last_join(lex->session)))
 
3583
            if (!($$= Lex->current_select->nest_last_join(Lex->session)))
3742
3584
              DRIZZLE_YYABORT;
3743
3585
          }
3744
3586
        ;
3885
3727
          }
3886
3728
          expr
3887
3729
          {
3888
 
            LEX *lex= Lex;
3889
 
            if (!($$= lex->current_select->convert_right_join()))
 
3730
            if (!($$= Lex->current_select->convert_right_join()))
3890
3731
              DRIZZLE_YYABORT;
3891
3732
            add_join_on($$, $8);
3892
3733
            Lex->pop_context();
3898
3739
          }
3899
3740
          USING '(' using_list ')'
3900
3741
          {
3901
 
            LEX *lex= Lex;
3902
 
            if (!($$= lex->current_select->convert_right_join()))
 
3742
            if (!($$= Lex->current_select->convert_right_join()))
3903
3743
              DRIZZLE_YYABORT;
3904
3744
            add_join_natural($$,$5,$9,Lex->current_select);
3905
3745
          }
3907
3747
          {
3908
3748
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3909
3749
            add_join_natural($6,$1,NULL,Lex->current_select);
3910
 
            LEX *lex= Lex;
3911
 
            if (!($$= lex->current_select->convert_right_join()))
 
3750
            if (!($$= Lex->current_select->convert_right_join()))
3912
3751
              DRIZZLE_YYABORT;
3913
3752
          }
3914
3753
        ;
3941
3780
          }
3942
3781
        | select_derived_init get_select_lex select_derived2
3943
3782
          {
3944
 
            LEX *lex= Lex;
3945
 
            Select_Lex *sel= lex->current_select;
 
3783
            Select_Lex *sel= Lex->current_select;
3946
3784
            if ($1)
3947
3785
            {
3948
3786
              if (sel->set_braces(1))
3956
3794
                sel->master_unit()->global_parameters=
3957
3795
                   sel->master_unit()->fake_select_lex;
3958
3796
            }
3959
 
            if ($2->init_nested_join(lex->session))
 
3797
            if ($2->init_nested_join(Lex->session))
3960
3798
              DRIZZLE_YYABORT;
3961
3799
            $$= 0;
3962
3800
            /* incomplete derived tables return NULL, we must be
3998
3836
              /* Handle case of derived table, alias may be NULL if there
3999
3837
                 are no outer parentheses, add_table_to_list() will throw
4000
3838
                 error in this case */
4001
 
              LEX *lex=Lex;
4002
 
              Select_Lex *sel= lex->current_select;
 
3839
              Select_Lex *sel= Lex->current_select;
4003
3840
              Select_Lex_Unit *unit= sel->master_unit();
4004
 
              lex->current_select= sel= unit->outer_select();
4005
 
              if (!($$= sel->add_table_to_list(lex->session,
 
3841
              Lex->current_select= sel= unit->outer_select();
 
3842
              if (!($$= sel->add_table_to_list(Lex->session,
4006
3843
                                               new Table_ident(unit), $5, 0,
4007
3844
                                               TL_READ)))
4008
3845
 
4009
3846
                DRIZZLE_YYABORT;
4010
3847
              sel->add_joined_table($$);
4011
 
              lex->pop_context();
 
3848
              Lex->pop_context();
4012
3849
            }
4013
3850
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
4014
3851
            {
4046
3883
select_init2_derived:
4047
3884
          select_part2_derived
4048
3885
          {
4049
 
            LEX *lex= Lex;
4050
 
            Select_Lex * sel= lex->current_select;
4051
 
            if (lex->current_select->set_braces(0))
 
3886
            Select_Lex * sel= Lex->current_select;
 
3887
            if (Lex->current_select->set_braces(0))
4052
3888
            {
4053
3889
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
4054
3890
              my_parse_error(&pass);
4067
3903
/* The equivalent of select_part2 for nested queries. */
4068
3904
select_part2_derived:
4069
3905
          {
4070
 
            LEX *lex= Lex;
4071
 
            Select_Lex *sel= lex->current_select;
 
3906
            Select_Lex *sel= Lex->current_select;
4072
3907
            if (sel->linkage != UNION_TYPE)
4073
 
              init_select(lex);
4074
 
            lex->current_select->parsing_place= SELECT_LIST;
 
3908
              init_select(Lex);
 
3909
            Lex->current_select->parsing_place= SELECT_LIST;
4075
3910
          }
4076
3911
          select_options select_item_list
4077
3912
          {
4084
3919
select_derived:
4085
3920
          get_select_lex
4086
3921
          {
4087
 
            LEX *lex= Lex;
4088
 
            if ($1->init_nested_join(lex->session))
 
3922
            if ($1->init_nested_join(Lex->session))
4089
3923
              DRIZZLE_YYABORT;
4090
3924
          }
4091
3925
          derived_table_list
4092
3926
          {
4093
 
            LEX *lex= Lex;
4094
3927
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
4095
3928
               for derived tables, both must equal NULL */
4096
3929
 
4097
 
            if (!($$= $1->end_nested_join(lex->session)) && $3)
 
3930
            if (!($$= $1->end_nested_join(Lex->session)) && $3)
4098
3931
              DRIZZLE_YYABORT;
4099
3932
            if (!$3 && $$)
4100
3933
            {
4107
3940
 
4108
3941
select_derived2:
4109
3942
          {
4110
 
            LEX *lex= Lex;
4111
 
            lex->derived_tables|= DERIVED_SUBQUERY;
4112
 
            if (!lex->expr_allows_subselect)
 
3943
            Lex->derived_tables|= DERIVED_SUBQUERY;
 
3944
            if (not Lex->expr_allows_subselect)
4113
3945
            {
4114
3946
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
4115
3947
              my_parse_error(&pass);
4116
3948
              DRIZZLE_YYABORT;
4117
3949
            }
4118
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
4119
 
                new_select(lex, 1))
 
3950
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
4120
3951
              DRIZZLE_YYABORT;
4121
 
            init_select(lex);
4122
 
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
4123
 
            lex->current_select->parsing_place= SELECT_LIST;
 
3952
            init_select(Lex);
 
3953
            Lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
3954
            Lex->current_select->parsing_place= SELECT_LIST;
4124
3955
          }
4125
3956
          select_options select_item_list
4126
3957
          {
4136
3967
select_derived_init:
4137
3968
          SELECT_SYM
4138
3969
          {
4139
 
            LEX *lex= Lex;
4140
 
 
4141
 
            Select_Lex *sel= lex->current_select;
 
3970
            Select_Lex *sel= Lex->current_select;
4142
3971
            TableList *embedding;
4143
 
            if (!sel->embedding || sel->end_nested_join(lex->session))
 
3972
            if (!sel->embedding || sel->end_nested_join(Lex->session))
4144
3973
            {
4145
3974
              /* we are not in parentheses */
4146
3975
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
4372
4201
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
4373
4202
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
4374
4203
            */
4375
 
            LEX *lex= Lex;
4376
 
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4204
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4377
4205
            {
4378
4206
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
4379
4207
                       "global union parameters");
4380
4208
              DRIZZLE_YYABORT;
4381
4209
            }
4382
 
            lex->current_select->olap= ROLLUP_TYPE;
 
4210
            Lex->current_select->olap= ROLLUP_TYPE;
4383
4211
          }
4384
4212
        ;
4385
4213
 
4399
4227
alter_order_item:
4400
4228
          simple_ident_nospvar order_dir
4401
4229
          {
4402
 
            Session *session= YYSession;
4403
4230
            bool ascending= ($2 == 1) ? true : false;
4404
 
            if (session->add_order_to_list($1, ascending))
 
4231
            if (YYSession->add_order_to_list($1, ascending))
4405
4232
              DRIZZLE_YYABORT;
4406
4233
          }
4407
4234
        ;
4418
4245
order_clause:
4419
4246
          ORDER_SYM BY
4420
4247
          {
4421
 
            LEX *lex=Lex;
4422
 
            Select_Lex *sel= lex->current_select;
 
4248
            Select_Lex *sel= Lex->current_select;
4423
4249
            Select_Lex_Unit *unit= sel-> master_unit();
4424
4250
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4425
4251
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
4429
4255
                       "CUBE/ROLLUP", "ORDER BY");
4430
4256
              DRIZZLE_YYABORT;
4431
4257
            }
4432
 
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4258
            if (Lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
4433
4259
            {
4434
4260
              /*
4435
4261
                A query of the of the form (SELECT ...) ORDER BY order_list is
4443
4269
              if (!unit->is_union() &&
4444
4270
                  (first_sl->order_list.elements ||
4445
4271
                   first_sl->select_limit) &&           
4446
 
                  unit->add_fake_select_lex(lex->session))
 
4272
                  unit->add_fake_select_lex(Lex->session))
4447
4273
                DRIZZLE_YYABORT;
4448
4274
            }
4449
4275
          }
4466
4292
opt_limit_clause_init:
4467
4293
          /* empty */
4468
4294
          {
4469
 
            LEX *lex= Lex;
4470
 
            Select_Lex *sel= lex->current_select;
 
4295
            Select_Lex *sel= Lex->current_select;
4471
4296
            sel->offset_limit= 0;
4472
4297
            sel->select_limit= 0;
4473
4298
          }
4516
4341
delete_limit_clause:
4517
4342
          /* empty */
4518
4343
          {
4519
 
            LEX *lex=Lex;
4520
 
            lex->current_select->select_limit= 0;
 
4344
            Lex->current_select->select_limit= 0;
4521
4345
          }
4522
4346
        | LIMIT limit_option
4523
4347
          {
4546
4370
 
4547
4371
select_var_list_init:
4548
4372
          {
4549
 
            LEX *lex=Lex;
4550
 
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
 
4373
            if (not Lex->describe && (not (Lex->result= new select_dumpvar())))
4551
4374
              DRIZZLE_YYABORT;
4552
4375
          }
4553
4376
          select_var_list
4560
4383
        ;
4561
4384
 
4562
4385
select_var_ident: 
4563
 
          '@' ident_or_text
 
4386
          '@' user_variable_ident
4564
4387
          {
4565
 
            LEX *lex=Lex;
4566
 
            if (lex->result)
4567
 
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
 
4388
            if (Lex->result)
 
4389
            {
 
4390
              ((select_dumpvar *)Lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
 
4391
            }
4568
4392
            else
 
4393
            {
4569
4394
              /*
4570
4395
                The parser won't create select_result instance only
4571
4396
                if it's an EXPLAIN.
4572
4397
              */
4573
 
              assert(lex->describe);
 
4398
              assert(Lex->describe);
 
4399
            }
4574
4400
          }
4575
4401
        ;
4576
4402
 
4583
4409
into_destination:
4584
4410
          OUTFILE TEXT_STRING_filesystem
4585
4411
          {
4586
 
            LEX *lex= Lex;
4587
 
            lex->setCacheable(false);
4588
 
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
4589
 
                !(lex->result= new select_export(lex->exchange)))
 
4412
            Lex->setCacheable(false);
 
4413
            if (!(Lex->exchange= new file_exchange($2.str, 0)) ||
 
4414
                !(Lex->result= new select_export(Lex->exchange)))
4590
4415
              DRIZZLE_YYABORT;
4591
4416
          }
4592
4417
          opt_field_term opt_line_term
4593
4418
        | DUMPFILE TEXT_STRING_filesystem
4594
4419
          {
4595
 
            LEX *lex=Lex;
4596
 
            if (!lex->describe)
 
4420
            if (not Lex->describe)
4597
4421
            {
4598
 
              lex->setCacheable(false);
4599
 
              if (!(lex->exchange= new file_exchange($2.str,1)))
 
4422
              Lex->setCacheable(false);
 
4423
              if (not (Lex->exchange= new file_exchange($2.str,1)))
4600
4424
                DRIZZLE_YYABORT;
4601
 
              if (!(lex->result= new select_dump(lex->exchange)))
 
4425
              if (not (Lex->result= new select_dump(Lex->exchange)))
4602
4426
                DRIZZLE_YYABORT;
4603
4427
            }
4604
4428
          }
4613
4437
drop:
4614
4438
          DROP opt_temporary table_or_tables if_exists table_list
4615
4439
          {
4616
 
            LEX *lex=Lex;
4617
 
            lex->sql_command = SQLCOM_DROP_TABLE;
4618
 
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
4619
 
            lex->statement= statement;
4620
 
            if (lex->statement == NULL)
4621
 
              DRIZZLE_YYABORT;
 
4440
            Lex->sql_command = SQLCOM_DROP_TABLE;
 
4441
            statement::DropTable *statement= new statement::DropTable(YYSession);
 
4442
            Lex->statement= statement;
4622
4443
            statement->drop_temporary= $2;
4623
4444
            statement->drop_if_exists= $4;
4624
4445
          }
4625
4446
        | DROP build_method INDEX_SYM ident ON table_ident {}
4626
4447
          {
4627
 
            LEX *lex=Lex;
4628
 
            lex->sql_command= SQLCOM_DROP_INDEX;
4629
 
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
4630
 
            lex->statement= statement;
4631
 
            if (lex->statement == NULL)
4632
 
              DRIZZLE_YYABORT;
 
4448
            Lex->sql_command= SQLCOM_DROP_INDEX;
 
4449
            statement::DropIndex *statement= new statement::DropIndex(YYSession);
 
4450
            Lex->statement= statement;
4633
4451
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4634
4452
            statement->alter_info.build_method= $2;
4635
4453
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4636
 
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4637
 
                                                        TL_OPTION_UPDATING))
 
4454
            if (not Lex->current_select->add_table_to_list(Lex->session, $6, NULL,
 
4455
                                                          TL_OPTION_UPDATING))
4638
4456
              DRIZZLE_YYABORT;
4639
4457
          }
4640
 
        | DROP DATABASE if_exists ident
 
4458
        | DROP DATABASE if_exists schema_name
4641
4459
          {
4642
 
            LEX *lex=Lex;
4643
 
            lex->sql_command= SQLCOM_DROP_DB;
4644
 
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
4645
 
            lex->statement= statement;
4646
 
            if (lex->statement == NULL)
4647
 
              DRIZZLE_YYABORT;
 
4460
            Lex->sql_command= SQLCOM_DROP_DB;
 
4461
            statement::DropSchema *statement= new statement::DropSchema(YYSession);
 
4462
            Lex->statement= statement;
4648
4463
            statement->drop_if_exists=$3;
4649
 
            lex->name= $4;
 
4464
            Lex->name= $4;
4650
4465
          }
 
4466
        ;
 
4467
 
4651
4468
table_list:
4652
4469
          table_name
4653
4470
        | table_list ',' table_name
4662
4479
        ;
4663
4480
 
4664
4481
if_exists:
4665
 
          /* empty */ { $$= 0; }
4666
 
        | IF EXISTS { $$= 1; }
 
4482
          /* empty */ { $$= false; }
 
4483
        | IF EXISTS { $$= true; }
4667
4484
        ;
4668
4485
 
4669
4486
opt_temporary:
4670
 
          /* empty */ { $$= 0; }
4671
 
        | TEMPORARY_SYM { $$= 1; }
 
4487
          /* empty */ { $$= false; }
 
4488
        | TEMPORARY_SYM { $$= true; }
4672
4489
        ;
4673
4490
 
4674
4491
/*
4675
4492
  Execute a string as dynamic SQL.
4676
 
  */
 
4493
*/
4677
4494
 
4678
4495
execute:
4679
4496
       EXECUTE_SYM execute_var_or_string opt_status opt_concurrent opt_wait
4680
 
       {
4681
 
          LEX *lex= Lex;
4682
 
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession, $2, $3, $4, $5);
4683
 
          lex->statement= statement;
4684
 
          if (lex->statement == NULL)
4685
 
            DRIZZLE_YYABORT;
4686
 
       }
 
4497
        {
 
4498
          Lex->statement= new statement::Execute(YYSession, $2, $3, $4, $5);
 
4499
        }
4687
4500
 
4688
4501
 
4689
4502
execute_var_or_string:
4690
 
         ident_or_text
 
4503
         user_variable_ident
4691
4504
         {
4692
4505
            $$.set($1);
4693
4506
         }
4694
 
        | '@' ident_or_text
 
4507
        | '@' user_variable_ident
4695
4508
        {
4696
4509
            $$.set($2, true);
4697
4510
        }
4698
4511
 
4699
4512
opt_status:
4700
 
          /* empty */ { $$= 0; }
4701
 
        | WITH NO_SYM RETURN_SYM { $$= 1; }
 
4513
          /* empty */ { $$= false; }
 
4514
        | WITH NO_SYM RETURN_SYM { $$= true; }
4702
4515
        ;
4703
4516
 
4704
4517
opt_concurrent:
4705
 
          /* empty */ { $$= 0; }
4706
 
        | CONCURRENT { $$= 1; }
 
4518
          /* empty */ { $$= false; }
 
4519
        | CONCURRENT { $$= true; }
4707
4520
        ;
4708
4521
 
4709
4522
opt_wait:
4710
 
          /* empty */ { $$= 0; }
4711
 
        | WAIT_SYM { $$= 1; }
 
4523
          /* empty */ { $$= false; }
 
4524
        | WAIT_SYM { $$= true; }
4712
4525
        ;
4713
4526
 
4714
4527
/*
4718
4531
insert:
4719
4532
          INSERT
4720
4533
          {
4721
 
            LEX *lex= Lex;
4722
 
            lex->sql_command= SQLCOM_INSERT;
4723
 
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
4724
 
            if (lex->statement == NULL)
4725
 
              DRIZZLE_YYABORT;
4726
 
            lex->duplicates= DUP_ERROR;
4727
 
            init_select(lex);
 
4534
            Lex->sql_command= SQLCOM_INSERT;
 
4535
            Lex->statement= new statement::Insert(YYSession);
 
4536
            Lex->duplicates= DUP_ERROR;
 
4537
            init_select(Lex);
4728
4538
            /* for subselects */
4729
 
            lex->lock_option= TL_READ;
 
4539
            Lex->lock_option= TL_READ;
4730
4540
          }
4731
4541
          opt_ignore insert2
4732
4542
          {
4740
4550
replace:
4741
4551
          REPLACE
4742
4552
          {
4743
 
            LEX *lex= Lex;
4744
 
            lex->sql_command= SQLCOM_REPLACE;
4745
 
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
4746
 
            if (lex->statement == NULL)
4747
 
              DRIZZLE_YYABORT;
4748
 
            lex->duplicates= DUP_REPLACE;
4749
 
            init_select(lex);
 
4553
            Lex->sql_command= SQLCOM_REPLACE;
 
4554
            Lex->statement= new statement::Replace(YYSession);
 
4555
            Lex->duplicates= DUP_REPLACE;
 
4556
            init_select(Lex);
4750
4557
          }
4751
4558
          insert2
4752
4559
          {
4765
4572
insert_table:
4766
4573
          table_name
4767
4574
          {
4768
 
            LEX *lex=Lex;
4769
 
            lex->field_list.empty();
4770
 
            lex->many_values.empty();
4771
 
            lex->insert_list=0;
 
4575
            Lex->field_list.empty();
 
4576
            Lex->many_values.empty();
 
4577
            Lex->insert_list=0;
4772
4578
          };
4773
4579
 
4774
4580
insert_field_spec:
4777
4583
        | '(' fields ')' insert_values {}
4778
4584
        | SET_SYM
4779
4585
          {
4780
 
            LEX *lex=Lex;
4781
 
            if (!(lex->insert_list = new List_item) ||
4782
 
                lex->many_values.push_back(lex->insert_list))
 
4586
            if (not (Lex->insert_list = new List_item) ||
 
4587
                Lex->many_values.push_back(Lex->insert_list))
4783
4588
              DRIZZLE_YYABORT;
4784
4589
          }
4785
4590
          ident_eq_list
4793
4598
insert_values:
4794
4599
          VALUES values_list {}
4795
4600
        | VALUE_SYM values_list {}
4796
 
        | create_select
4797
 
          { Lex->current_select->set_braces(0);}
 
4601
        | stored_select
 
4602
          {
 
4603
            Lex->current_select->set_braces(0);
 
4604
          }
4798
4605
          union_clause {}
4799
 
        | '(' create_select ')'
4800
 
          { Lex->current_select->set_braces(1);}
 
4606
        | '(' stored_select ')'
 
4607
          {
 
4608
            Lex->current_select->set_braces(1);
 
4609
          }
4801
4610
          union_opt {}
4802
4611
        ;
4803
4612
 
4814
4623
ident_eq_value:
4815
4624
          simple_ident_nospvar equal expr_or_default
4816
4625
          {
4817
 
            LEX *lex=Lex;
4818
 
            if (lex->field_list.push_back($1) ||
4819
 
                lex->insert_list->push_back($3))
 
4626
            if (Lex->field_list.push_back($1) ||
 
4627
                Lex->insert_list->push_back($3))
4820
4628
              DRIZZLE_YYABORT;
4821
4629
          }
4822
4630
        ;
4839
4647
          }
4840
4648
          opt_values ')'
4841
4649
          {
4842
 
            LEX *lex=Lex;
4843
 
            if (lex->many_values.push_back(lex->insert_list))
 
4650
            if (Lex->many_values.push_back(Lex->insert_list))
4844
4651
              DRIZZLE_YYABORT;
4845
4652
          }
4846
4653
        ;
4879
4686
update:
4880
4687
          UPDATE_SYM opt_ignore table_ident
4881
4688
          {
4882
 
            LEX *lex= Lex;
4883
 
            init_select(lex);
4884
 
            lex->sql_command= SQLCOM_UPDATE;
4885
 
            lex->statement= new(std::nothrow) statement::Update(YYSession);
4886
 
            if (lex->statement == NULL)
4887
 
              DRIZZLE_YYABORT;
4888
 
            lex->lock_option= TL_UNLOCK; /* Will be set later */
4889
 
            lex->duplicates= DUP_ERROR;
4890
 
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4689
            init_select(Lex);
 
4690
            Lex->sql_command= SQLCOM_UPDATE;
 
4691
            Lex->statement= new statement::Update(YYSession);
 
4692
            Lex->lock_option= TL_UNLOCK; /* Will be set later */
 
4693
            Lex->duplicates= DUP_ERROR;
 
4694
            if (not Lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4891
4695
              DRIZZLE_YYABORT;
4892
4696
          }
4893
4697
          SET_SYM update_list
4894
4698
          {
4895
 
            LEX *lex= Lex;
4896
 
            if (lex->select_lex.get_table_list()->derived)
 
4699
            if (Lex->select_lex.get_table_list()->derived)
4897
4700
            {
4898
4701
              /* it is single table update and it is update of derived table */
4899
4702
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4900
 
                       lex->select_lex.get_table_list()->alias, "UPDATE");
 
4703
                       Lex->select_lex.get_table_list()->alias, "UPDATE");
4901
4704
              DRIZZLE_YYABORT;
4902
4705
            }
4903
4706
            /*
4931
4734
insert_update_elem:
4932
4735
          simple_ident_nospvar equal expr_or_default
4933
4736
          {
4934
 
          LEX *lex= Lex;
4935
 
          if (lex->update_list.push_back($1) ||
4936
 
              lex->value_list.push_back($3))
 
4737
          if (Lex->update_list.push_back($1) ||
 
4738
              Lex->value_list.push_back($3))
4937
4739
              DRIZZLE_YYABORT;
4938
4740
          }
4939
4741
        ;
4943
4745
delete:
4944
4746
          DELETE_SYM
4945
4747
          {
4946
 
            LEX *lex= Lex;
4947
 
            lex->sql_command= SQLCOM_DELETE;
4948
 
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
4949
 
            if (lex->statement == NULL)
4950
 
              DRIZZLE_YYABORT;
4951
 
            init_select(lex);
4952
 
            lex->lock_option= TL_WRITE_DEFAULT;
4953
 
            lex->ignore= 0;
4954
 
            lex->select_lex.init_order();
 
4748
            Lex->sql_command= SQLCOM_DELETE;
 
4749
            Lex->statement= new statement::Delete(YYSession);
 
4750
            init_select(Lex);
 
4751
            Lex->lock_option= TL_WRITE_DEFAULT;
 
4752
            Lex->ignore= 0;
 
4753
            Lex->select_lex.init_order();
4955
4754
          }
4956
4755
          opt_delete_options single_multi
4957
4756
        ;
4979
4778
truncate:
4980
4779
          TRUNCATE_SYM opt_table_sym table_name
4981
4780
          {
4982
 
            LEX* lex= Lex;
4983
 
            lex->sql_command= SQLCOM_TRUNCATE;
4984
 
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
4985
 
            if (lex->statement == NULL)
4986
 
              DRIZZLE_YYABORT;
4987
 
            lex->select_lex.options= 0;
4988
 
            lex->select_lex.init_order();
 
4781
            Lex->sql_command= SQLCOM_TRUNCATE;
 
4782
            Lex->statement= new statement::Truncate(YYSession);
 
4783
            Lex->select_lex.options= 0;
 
4784
            Lex->select_lex.init_order();
4989
4785
          }
4990
4786
        ;
4991
4787
 
4999
4795
show:
5000
4796
          SHOW
5001
4797
          {
5002
 
            LEX *lex=Lex;
5003
 
            lex->wild=0;
5004
 
            lex->lock_option= TL_READ;
5005
 
            init_select(lex);
5006
 
            lex->current_select->parsing_place= SELECT_LIST;
 
4798
            Lex->wild=0;
 
4799
            Lex->lock_option= TL_READ;
 
4800
            init_select(Lex);
 
4801
            Lex->current_select->parsing_place= SELECT_LIST;
5007
4802
          }
5008
4803
          show_param
5009
4804
          {}
5013
4808
show_param:
5014
4809
           DATABASES show_wild
5015
4810
           {
5016
 
             LEX *lex= Lex;
5017
 
             Session *session= YYSession;
5018
 
 
5019
 
             lex->sql_command= SQLCOM_SELECT;
5020
 
             lex->statement=
5021
 
               new(std::nothrow) statement::Show(session);
5022
 
             if (lex->statement == NULL)
5023
 
               DRIZZLE_YYABORT;
 
4811
             Lex->sql_command= SQLCOM_SELECT;
 
4812
             Lex->statement= new statement::Show(YYSession);
5024
4813
 
5025
4814
             std::string column_name= "Database";
5026
4815
             if (Lex->wild)
5032
4821
 
5033
4822
             if (Lex->current_select->where)
5034
4823
             {
5035
 
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
 
4824
               if (prepare_new_schema_table(YYSession, Lex, "SCHEMAS"))
5036
4825
                 DRIZZLE_YYABORT;
5037
4826
             }
5038
4827
             else
5039
4828
             {
5040
 
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
 
4829
               if (prepare_new_schema_table(YYSession, Lex, "SHOW_SCHEMAS"))
5041
4830
                 DRIZZLE_YYABORT;
5042
4831
             }
5043
4832
 
5044
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4833
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5045
4834
             my_field->is_autogenerated_name= false;
5046
4835
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5047
4836
 
5048
 
             if (session->add_item_to_list(my_field))
 
4837
             if (YYSession->add_item_to_list(my_field))
5049
4838
               DRIZZLE_YYABORT;
5050
4839
 
5051
 
              if (session->add_order_to_list(my_field, true))
 
4840
              if (YYSession->add_order_to_list(my_field, true))
5052
4841
                DRIZZLE_YYABORT;
5053
4842
           }
5054
4843
           /* SHOW TABLES */
5055
4844
         | TABLES opt_db show_wild
5056
4845
           {
5057
 
             LEX *lex= Lex;
5058
 
             Session *session= YYSession;
5059
 
 
5060
 
             lex->sql_command= SQLCOM_SELECT;
5061
 
 
5062
 
             statement::Show *select=
5063
 
               new(std::nothrow) statement::Show(YYSession);
5064
 
 
5065
 
             lex->statement= select;
5066
 
 
5067
 
             if (lex->statement == NULL)
5068
 
               DRIZZLE_YYABORT;
5069
 
 
 
4846
             Lex->sql_command= SQLCOM_SELECT;
 
4847
 
 
4848
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
4849
             Lex->statement= select;
5070
4850
 
5071
4851
              std::string column_name= "Tables_in_";
5072
4852
 
5073
 
              util::string::const_shared_ptr schema(session->schema());
 
4853
              util::string::const_shared_ptr schema(YYSession->schema());
5074
4854
              if ($2)
5075
4855
              {
5076
4856
                SchemaIdentifier identifier($2);
5077
4857
                column_name.append($2);
5078
 
                lex->select_lex.db= $2;
 
4858
                Lex->select_lex.db= $2;
5079
4859
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
5080
4860
                {
5081
4861
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
5101
4881
               column_name.append(")");
5102
4882
             }
5103
4883
 
5104
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
 
4884
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLES"))
5105
4885
               DRIZZLE_YYABORT;
5106
4886
 
5107
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4887
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5108
4888
             my_field->is_autogenerated_name= false;
5109
4889
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5110
4890
 
5111
 
             if (session->add_item_to_list(my_field))
 
4891
             if (YYSession->add_item_to_list(my_field))
5112
4892
               DRIZZLE_YYABORT;
5113
4893
 
5114
 
              if (session->add_order_to_list(my_field, true))
 
4894
              if (YYSession->add_order_to_list(my_field, true))
5115
4895
                DRIZZLE_YYABORT;
5116
4896
           }
5117
4897
           /* SHOW TEMPORARY TABLES */
5118
4898
         | TEMPORARY_SYM TABLES show_wild
5119
4899
           {
5120
 
             LEX *lex= Lex;
5121
 
             Session *session= YYSession;
5122
 
 
5123
 
             lex->sql_command= SQLCOM_SELECT;
5124
 
 
5125
 
             statement::Show *select=
5126
 
               new(std::nothrow) statement::Show(YYSession);
5127
 
 
5128
 
             lex->statement= select;
5129
 
 
5130
 
             if (lex->statement == NULL)
5131
 
               DRIZZLE_YYABORT;
5132
 
 
5133
 
 
5134
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
5135
 
               DRIZZLE_YYABORT;
5136
 
 
5137
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4900
             Lex->sql_command= SQLCOM_SELECT;
 
4901
 
 
4902
             Lex->statement= new statement::Show(YYSession);
 
4903
 
 
4904
 
 
4905
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TEMPORARY_TABLES"))
 
4906
               DRIZZLE_YYABORT;
 
4907
 
 
4908
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5138
4909
                                                           context,
5139
4910
                                                           NULL, NULL, "*")))
5140
4911
               DRIZZLE_YYABORT;
5141
 
             (session->lex->current_select->with_wild)++;
 
4912
             (YYSession->lex->current_select->with_wild)++;
5142
4913
 
5143
4914
           }
5144
4915
           /* SHOW TABLE STATUS */
5145
4916
         | TABLE_SYM STATUS_SYM opt_db show_wild
5146
4917
           {
5147
 
             LEX *lex= Lex;
5148
 
             lex->sql_command= SQLCOM_SELECT;
5149
 
             statement::Show *select=
5150
 
               new(std::nothrow) statement::Show(YYSession);
5151
 
 
5152
 
             lex->statement= select;
5153
 
 
5154
 
             if (lex->statement == NULL)
5155
 
               DRIZZLE_YYABORT;
5156
 
 
5157
 
             Session *session= YYSession;
 
4918
             Lex->sql_command= SQLCOM_SELECT;
 
4919
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
4920
             Lex->statement= select;
5158
4921
 
5159
4922
             std::string column_name= "Tables_in_";
5160
4923
 
5161
 
             util::string::const_shared_ptr schema(session->schema());
 
4924
             util::string::const_shared_ptr schema(YYSession->schema());
5162
4925
             if ($3)
5163
4926
             {
5164
 
               lex->select_lex.db= $3;
 
4927
               Lex->select_lex.db= $3;
5165
4928
 
5166
4929
               SchemaIdentifier identifier($3);
5167
4930
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
5181
4944
               DRIZZLE_YYABORT;
5182
4945
             }
5183
4946
 
5184
 
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
 
4947
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLE_STATUS"))
5185
4948
               DRIZZLE_YYABORT;
5186
4949
 
5187
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4950
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5188
4951
                                                           context,
5189
4952
                                                           NULL, NULL, "*")))
5190
4953
               DRIZZLE_YYABORT;
5191
 
             (session->lex->current_select->with_wild)++;
 
4954
             (YYSession->lex->current_select->with_wild)++;
5192
4955
           }
5193
4956
           /* SHOW COLUMNS FROM table_name */
5194
4957
        | COLUMNS from_or_in table_ident opt_db show_wild
5195
4958
          {
5196
 
             LEX *lex= Lex;
5197
 
             Session *session= YYSession;
5198
 
             statement::Show *select;
5199
 
 
5200
 
             lex->sql_command= SQLCOM_SELECT;
5201
 
 
5202
 
             select= new(std::nothrow) statement::Show(session);
5203
 
 
5204
 
             lex->statement= select;
5205
 
 
5206
 
             if (lex->statement == NULL)
5207
 
               DRIZZLE_YYABORT;
5208
 
 
5209
 
             util::string::const_shared_ptr schema(session->schema());
 
4959
             Lex->sql_command= SQLCOM_SELECT;
 
4960
 
 
4961
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
4962
             Lex->statement= select;
 
4963
 
 
4964
             util::string::const_shared_ptr schema(YYSession->schema());
5210
4965
             if ($4)
5211
4966
             {
5212
4967
              select->setShowPredicate($4, $3->table.str);
5227
4982
 
5228
4983
             {
5229
4984
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5230
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
4985
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5231
4986
               {
5232
4987
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5233
4988
                            select->getShowSchema().c_str(), 
5235
4990
               }
5236
4991
             }
5237
4992
 
5238
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
4993
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
5239
4994
               DRIZZLE_YYABORT;
5240
4995
 
5241
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4996
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5242
4997
                                                           context,
5243
4998
                                                           NULL, NULL, "*")))
5244
4999
               DRIZZLE_YYABORT;
5245
 
             (session->lex->current_select->with_wild)++;
 
5000
             (YYSession->lex->current_select->with_wild)++;
5246
5001
 
5247
5002
          }
5248
5003
          /* SHOW INDEXES from table */
5249
5004
        | keys_or_index from_or_in table_ident opt_db where_clause
5250
5005
          {
5251
 
             LEX *lex= Lex;
5252
 
             Session *session= YYSession;
5253
 
             statement::Show *select;
5254
 
 
5255
 
             lex->sql_command= SQLCOM_SELECT;
5256
 
 
5257
 
             select= new(std::nothrow) statement::Show(session);
5258
 
 
5259
 
             lex->statement= select;
5260
 
 
5261
 
             if (lex->statement == NULL)
5262
 
               DRIZZLE_YYABORT;
5263
 
 
5264
 
             util::string::const_shared_ptr schema(session->schema());
 
5006
             Lex->sql_command= SQLCOM_SELECT;
 
5007
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
5008
             Lex->statement= select;
 
5009
 
 
5010
             util::string::const_shared_ptr schema(YYSession->schema());
5265
5011
             if ($4)
5266
5012
             {
5267
5013
              select->setShowPredicate($4, $3->table.str);
5282
5028
 
5283
5029
             {
5284
5030
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5285
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5031
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5286
5032
               {
5287
5033
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5288
5034
                            select->getShowSchema().c_str(), 
5290
5036
               }
5291
5037
             }
5292
5038
 
5293
 
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
 
5039
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_INDEXES"))
5294
5040
               DRIZZLE_YYABORT;
5295
5041
 
5296
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5042
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5297
5043
                                                           context,
5298
5044
                                                           NULL, NULL, "*")))
5299
5045
               DRIZZLE_YYABORT;
5300
 
             (session->lex->current_select->with_wild)++;
 
5046
             (YYSession->lex->current_select->with_wild)++;
5301
5047
          }
5302
5048
        | COUNT_SYM '(' '*' ')' WARNINGS
5303
5049
          {
5304
5050
            (void) create_select_for_variable("warning_count");
5305
 
            LEX *lex= Lex;
5306
 
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5307
 
            if (lex->statement == NULL)
5308
 
              DRIZZLE_YYABORT;
 
5051
             Lex->statement= new statement::Show(YYSession);
5309
5052
          }
5310
5053
        | COUNT_SYM '(' '*' ')' ERRORS
5311
5054
          {
5312
5055
            (void) create_select_for_variable("error_count");
5313
 
            LEX *lex= Lex;
5314
 
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5315
 
            if (lex->statement == NULL)
5316
 
              DRIZZLE_YYABORT;
 
5056
             Lex->statement= new statement::Show(YYSession);
5317
5057
          }
5318
5058
        | WARNINGS opt_limit_clause_init
5319
5059
          {
5320
5060
            Lex->sql_command = SQLCOM_SHOW_WARNS;
5321
 
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5322
 
            if (Lex->statement == NULL)
5323
 
              DRIZZLE_YYABORT;
 
5061
            Lex->statement= new statement::ShowWarnings(YYSession);
5324
5062
          }
5325
5063
        | ERRORS opt_limit_clause_init
5326
5064
          {
5327
5065
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
5328
 
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5329
 
            if (Lex->statement == NULL)
5330
 
              DRIZZLE_YYABORT;
 
5066
            Lex->statement= new statement::ShowErrors(YYSession);
5331
5067
          }
5332
5068
        | opt_var_type STATUS_SYM show_wild
5333
5069
           {
5334
 
             LEX *lex= Lex;
5335
 
             lex->sql_command= SQLCOM_SELECT;
5336
 
             lex->statement=
5337
 
               new(std::nothrow) statement::Show(YYSession);
5338
 
             if (lex->statement == NULL)
5339
 
               DRIZZLE_YYABORT;
5340
 
 
5341
 
             Session *session= YYSession;
 
5070
             Lex->sql_command= SQLCOM_SELECT;
 
5071
             Lex->statement= new statement::Show(YYSession);
5342
5072
 
5343
5073
             if ($1 == OPT_GLOBAL)
5344
5074
             {
5345
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
 
5075
               if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_STATUS"))
5346
5076
                 DRIZZLE_YYABORT;
5347
5077
             }
5348
5078
             else
5349
5079
             {
5350
 
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
 
5080
               if (prepare_new_schema_table(YYSession, Lex, "SESSION_STATUS"))
5351
5081
                 DRIZZLE_YYABORT;
5352
5082
             }
5353
5083
 
5354
5084
             std::string key("Variable_name");
5355
5085
             std::string value("Value");
5356
5086
 
5357
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5087
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5358
5088
             my_field->is_autogenerated_name= false;
5359
5089
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5360
5090
 
5361
 
             if (session->add_item_to_list(my_field))
 
5091
             if (YYSession->add_item_to_list(my_field))
5362
5092
               DRIZZLE_YYABORT;
5363
5093
 
5364
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5094
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5365
5095
             my_field->is_autogenerated_name= false;
5366
5096
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5367
5097
 
5368
 
             if (session->add_item_to_list(my_field))
 
5098
             if (YYSession->add_item_to_list(my_field))
5369
5099
               DRIZZLE_YYABORT;
5370
5100
           }
5371
5101
        | CREATE TABLE_SYM table_ident
5372
5102
           {
5373
 
             LEX *lex= Lex;
5374
 
             lex->sql_command= SQLCOM_SELECT;
5375
 
             statement::Show *select=
5376
 
               new(std::nothrow) statement::Show(YYSession);
5377
 
 
5378
 
             lex->statement= select;
5379
 
 
5380
 
             if (lex->statement == NULL)
5381
 
               DRIZZLE_YYABORT;
5382
 
 
5383
 
             Session *session= YYSession;
5384
 
 
5385
 
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5386
 
               DRIZZLE_YYABORT;
5387
 
 
5388
 
             util::string::const_shared_ptr schema(session->schema());
 
5103
             Lex->sql_command= SQLCOM_SELECT;
 
5104
             statement::Show *select= new statement::Show(YYSession);
 
5105
             Lex->statement= select;
 
5106
 
 
5107
             if (Lex->statement == NULL)
 
5108
               DRIZZLE_YYABORT;
 
5109
 
 
5110
             if (prepare_new_schema_table(YYSession, Lex, "TABLE_SQL_DEFINITION"))
 
5111
               DRIZZLE_YYABORT;
 
5112
 
 
5113
             util::string::const_shared_ptr schema(YYSession->schema());
5389
5114
             if ($3->db.str)
5390
5115
             {
5391
5116
               select->setShowPredicate($3->db.str, $3->table.str);
5403
5128
             std::string key("Table");
5404
5129
             std::string value("Create Table");
5405
5130
 
5406
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5131
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5407
5132
             my_field->is_autogenerated_name= false;
5408
5133
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5409
5134
 
5410
 
             if (session->add_item_to_list(my_field))
 
5135
             if (YYSession->add_item_to_list(my_field))
5411
5136
               DRIZZLE_YYABORT;
5412
5137
 
5413
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5138
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5414
5139
             my_field->is_autogenerated_name= false;
5415
5140
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5416
5141
 
5417
 
             if (session->add_item_to_list(my_field))
 
5142
             if (YYSession->add_item_to_list(my_field))
5418
5143
               DRIZZLE_YYABORT;
5419
5144
           }
5420
5145
        | PROCESSLIST_SYM
5421
5146
          {
5422
5147
           {
5423
 
             LEX *lex= Lex;
5424
 
             lex->sql_command= SQLCOM_SELECT;
5425
 
             lex->statement=
5426
 
               new(std::nothrow) statement::Show(YYSession);
5427
 
             if (lex->statement == NULL)
5428
 
               DRIZZLE_YYABORT;
5429
 
 
5430
 
             Session *session= YYSession;
5431
 
 
5432
 
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5433
 
               DRIZZLE_YYABORT;
5434
 
 
5435
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5148
             Lex->sql_command= SQLCOM_SELECT;
 
5149
             Lex->statement= new statement::Show(YYSession);
 
5150
 
 
5151
             if (prepare_new_schema_table(YYSession, Lex, "PROCESSLIST"))
 
5152
               DRIZZLE_YYABORT;
 
5153
 
 
5154
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5436
5155
                                                           context,
5437
5156
                                                           NULL, NULL, "*")))
5438
5157
               DRIZZLE_YYABORT;
5439
 
             (session->lex->current_select->with_wild)++;
 
5158
             (YYSession->lex->current_select->with_wild)++;
5440
5159
           }
5441
5160
          }
5442
5161
        | opt_var_type  VARIABLES show_wild
5443
5162
           {
5444
 
             LEX *lex= Lex;
5445
 
             lex->sql_command= SQLCOM_SELECT;
5446
 
             lex->statement=
5447
 
               new(std::nothrow) statement::Show(YYSession);
5448
 
             if (lex->statement == NULL)
5449
 
               DRIZZLE_YYABORT;
5450
 
 
5451
 
             Session *session= YYSession;
 
5163
             Lex->sql_command= SQLCOM_SELECT;
 
5164
             Lex->statement= new statement::Show(YYSession);
5452
5165
 
5453
5166
             if ($1 == OPT_GLOBAL)
5454
5167
             {
5455
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
 
5168
               if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_VARIABLES"))
5456
5169
                 DRIZZLE_YYABORT;
5457
5170
             }
5458
5171
             else
5459
5172
             {
5460
 
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
 
5173
               if (prepare_new_schema_table(YYSession, Lex, "SESSION_VARIABLES"))
5461
5174
                 DRIZZLE_YYABORT;
5462
5175
             }
5463
5176
 
5464
5177
             std::string key("Variable_name");
5465
5178
             std::string value("Value");
5466
5179
 
5467
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
5180
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5468
5181
             my_field->is_autogenerated_name= false;
5469
5182
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5470
5183
 
5471
 
             if (session->add_item_to_list(my_field))
 
5184
             if (YYSession->add_item_to_list(my_field))
5472
5185
               DRIZZLE_YYABORT;
5473
5186
 
5474
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
5187
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5475
5188
             my_field->is_autogenerated_name= false;
5476
5189
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5477
5190
 
5478
 
             if (session->add_item_to_list(my_field))
 
5191
             if (YYSession->add_item_to_list(my_field))
5479
5192
               DRIZZLE_YYABORT;
5480
5193
           }
5481
5194
        | CREATE DATABASE opt_if_not_exists ident
5482
5195
           {
5483
 
             LEX *lex= Lex;
5484
 
             lex->sql_command= SQLCOM_SELECT;
5485
 
             statement::Show *select=
5486
 
               new(std::nothrow) statement::Show(YYSession);
5487
 
 
5488
 
             lex->statement= select;
5489
 
 
5490
 
             if (lex->statement == NULL)
5491
 
               DRIZZLE_YYABORT;
5492
 
 
5493
 
             Session *session= YYSession;
5494
 
 
5495
 
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5496
 
               DRIZZLE_YYABORT;
5497
 
 
5498
 
             util::string::const_shared_ptr schema(session->schema());
 
5196
             Lex->sql_command= SQLCOM_SELECT;
 
5197
             drizzled::statement::Show *select= new statement::Show(YYSession);
 
5198
             Lex->statement= select;
 
5199
 
 
5200
             if (prepare_new_schema_table(YYSession, Lex, "SCHEMA_SQL_DEFINITION"))
 
5201
               DRIZZLE_YYABORT;
 
5202
 
 
5203
             util::string::const_shared_ptr schema(YYSession->schema());
5499
5204
             if ($4.str)
5500
5205
             {
5501
5206
              select->setShowPredicate($4.str);
5513
5218
             std::string key("Database");
5514
5219
             std::string value("Create Database");
5515
5220
 
5516
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5221
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5517
5222
             my_field->is_autogenerated_name= false;
5518
5223
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5519
5224
 
5520
 
             if (session->add_item_to_list(my_field))
 
5225
             if (YYSession->add_item_to_list(my_field))
5521
5226
               DRIZZLE_YYABORT;
5522
5227
 
5523
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5228
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5524
5229
             my_field->is_autogenerated_name= false;
5525
5230
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5526
5231
 
5527
 
             if (session->add_item_to_list(my_field))
 
5232
             if (YYSession->add_item_to_list(my_field))
5528
5233
               DRIZZLE_YYABORT;
5529
5234
           }
5530
5235
 
5559
5264
describe:
5560
5265
          describe_command table_ident
5561
5266
          {
5562
 
            Session *session= YYSession;
5563
 
            statement::Show *select;
5564
 
            LEX *lex= Lex;
5565
 
            lex->lock_option= TL_READ;
5566
 
            init_select(lex);
5567
 
            lex->current_select->parsing_place= SELECT_LIST;
5568
 
            lex->sql_command= SQLCOM_SELECT;
5569
 
            select= new(std::nothrow) statement::Show(session);
5570
 
            lex->statement= select;
5571
 
            if (lex->statement == NULL)
5572
 
              DRIZZLE_YYABORT;
5573
 
            lex->select_lex.db= 0;
 
5267
            Lex->lock_option= TL_READ;
 
5268
            init_select(Lex);
 
5269
            Lex->current_select->parsing_place= SELECT_LIST;
 
5270
            Lex->sql_command= SQLCOM_SELECT;
 
5271
            drizzled::statement::Show *select= new statement::Show(YYSession);
 
5272
            Lex->statement= select;
 
5273
            Lex->select_lex.db= 0;
5574
5274
 
5575
 
             util::string::const_shared_ptr schema(session->schema());
 
5275
             util::string::const_shared_ptr schema(YYSession->schema());
5576
5276
             if ($2->db.str)
5577
5277
             {
5578
5278
               select->setShowPredicate($2->db.str, $2->table.str);
5589
5289
 
5590
5290
             {
5591
5291
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
5592
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
 
5292
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5593
5293
               {
5594
5294
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5595
5295
                            select->getShowSchema().c_str(), 
5597
5297
               }
5598
5298
             }
5599
5299
 
5600
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
 
5300
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
5601
5301
               DRIZZLE_YYABORT;
5602
5302
 
5603
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
5303
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5604
5304
                                                           context,
5605
5305
                                                           NULL, NULL, "*")))
5606
5306
             {
5607
5307
               DRIZZLE_YYABORT;
5608
5308
             }
5609
 
             (session->lex->current_select->with_wild)++;
 
5309
             (YYSession->lex->current_select->with_wild)++;
5610
5310
 
5611
5311
          }
5612
5312
          opt_describe_column {}
5614
5314
          { Lex->describe|= DESCRIBE_NORMAL; }
5615
5315
          select
5616
5316
          {
5617
 
            LEX *lex=Lex;
5618
 
            lex->select_lex.options|= SELECT_DESCRIBE;
 
5317
            Lex->select_lex.options|= SELECT_DESCRIBE;
5619
5318
          }
5620
5319
        ;
5621
5320
 
5646
5345
flush:
5647
5346
          FLUSH_SYM
5648
5347
          {
5649
 
            LEX *lex=Lex;
5650
 
            lex->sql_command= SQLCOM_FLUSH;
5651
 
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
5652
 
            if (lex->statement == NULL)
5653
 
              DRIZZLE_YYABORT;
5654
 
            lex->type= 0;
 
5348
            Lex->sql_command= SQLCOM_FLUSH;
 
5349
            Lex->statement= new statement::Flush(YYSession);
 
5350
            Lex->type= 0;
5655
5351
          }
5656
5352
          flush_options
5657
5353
          {}
5701
5397
kill:
5702
5398
          KILL_SYM kill_option expr
5703
5399
          {
5704
 
            LEX *lex=Lex;
5705
 
 
5706
5400
            if ($2)
5707
5401
            {
5708
5402
              Lex->type= ONLY_KILL_QUERY;
5709
5403
            }
5710
 
            else
5711
 
            {
5712
 
              Lex->type= 0;
5713
 
            }
5714
5404
 
5715
 
            lex->value_list.empty();
5716
 
            lex->value_list.push_front($3);
5717
 
            lex->sql_command= SQLCOM_KILL;
5718
 
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
5719
 
            if (lex->statement == NULL)
5720
 
              DRIZZLE_YYABORT;
 
5405
            Lex->value_list.empty();
 
5406
            Lex->value_list.push_front($3);
 
5407
            Lex->sql_command= SQLCOM_KILL;
 
5408
            Lex->statement= new statement::Kill(YYSession);
5721
5409
          }
5722
5410
        ;
5723
5411
 
5724
5412
kill_option:
5725
 
          /* empty */ { $$= 0; }
5726
 
        | CONNECTION_SYM { $$= 0; }
5727
 
        | QUERY_SYM      { $$= 1; }
 
5413
          /* empty */ { $$= false; }
 
5414
        | CONNECTION_SYM { $$= false; }
 
5415
        | QUERY_SYM      { $$= true; }
5728
5416
        ;
5729
5417
 
5730
5418
/* change database */
5731
5419
 
5732
5420
use:
5733
 
          USE_SYM ident
 
5421
          USE_SYM schema_name
5734
5422
          {
5735
 
            LEX *lex=Lex;
5736
 
            lex->sql_command=SQLCOM_CHANGE_DB;
5737
 
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
5738
 
            if (lex->statement == NULL)
5739
 
              DRIZZLE_YYABORT;
5740
 
            lex->select_lex.db= $2.str;
 
5423
            Lex->sql_command=SQLCOM_CHANGE_DB;
 
5424
            Lex->statement= new statement::ChangeSchema(YYSession);
 
5425
            Lex->select_lex.db= $2.str;
5741
5426
          }
5742
5427
        ;
5743
5428
 
5746
5431
load:
5747
5432
          LOAD data_file
5748
5433
          {
5749
 
            Session *session= YYSession;
5750
 
            LEX *lex= session->lex;
5751
 
 
5752
 
            lex->sql_command= SQLCOM_LOAD;
5753
 
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
5754
 
            lex->statement= statement;
5755
 
            if (lex->statement == NULL)
5756
 
              DRIZZLE_YYABORT;
5757
 
 
5758
 
            Lex_input_stream *lip= session->m_lip;
 
5434
            Lex->sql_command= SQLCOM_LOAD;
 
5435
            statement::Load *statement= new statement::Load(YYSession);
 
5436
            Lex->statement= statement;
 
5437
 
 
5438
            Lex_input_stream *lip= YYSession->m_lip;
5759
5439
            statement->fname_start= lip->get_ptr();
5760
5440
          }
5761
5441
          load_data_lock INFILE TEXT_STRING_filesystem
5762
5442
          {
5763
 
            LEX *lex=Lex;
5764
 
            lex->lock_option= $4;
5765
 
            lex->duplicates= DUP_ERROR;
5766
 
            lex->ignore= 0;
5767
 
            if (!(lex->exchange= new file_exchange($6.str, 0, $2)))
 
5443
            Lex->lock_option= $4;
 
5444
            Lex->duplicates= DUP_ERROR;
 
5445
            Lex->ignore= 0;
 
5446
            if (not (Lex->exchange= new file_exchange($6.str, 0, $2)))
5768
5447
              DRIZZLE_YYABORT;
5769
5448
          }
5770
5449
          opt_duplicate INTO
5771
5450
          {
5772
 
            Session *session= YYSession;
5773
 
            Lex_input_stream *lip= session->m_lip;
 
5451
            Lex_input_stream *lip= YYSession->m_lip;
5774
5452
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
5775
5453
          }
5776
5454
          TABLE_SYM table_ident
5777
5455
          {
5778
 
            LEX *lex=Lex;
5779
5456
            if (!Lex->current_select->add_table_to_list(YYSession,
5780
5457
                    $12, NULL, TL_OPTION_UPDATING,
5781
 
                    lex->lock_option))
 
5458
                    Lex->lock_option))
5782
5459
              DRIZZLE_YYABORT;
5783
 
            lex->field_list.empty();
5784
 
            lex->update_list.empty();
5785
 
            lex->value_list.empty();
 
5460
            Lex->field_list.empty();
 
5461
            Lex->update_list.empty();
 
5462
            Lex->value_list.empty();
5786
5463
          }
5787
5464
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
5788
5465
          opt_load_data_set_spec
5806
5483
        | IGNORE_SYM { Lex->ignore= 1; }
5807
5484
        ;
5808
5485
 
 
5486
opt_duplicate_as:
 
5487
          /* empty */ { Lex->duplicates=DUP_ERROR; }
 
5488
        | AS { Lex->duplicates=DUP_ERROR; }
 
5489
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
 
5490
        | IGNORE_SYM { Lex->ignore= true; }
 
5491
        | REPLACE AS { Lex->duplicates=DUP_REPLACE; }
 
5492
        | IGNORE_SYM AS { Lex->ignore= true; }
 
5493
        ;
 
5494
 
5809
5495
opt_field_term:
5810
5496
          /* empty */
5811
5497
        | COLUMNS field_term_list
5824
5510
          }
5825
5511
        | OPTIONALLY ENCLOSED BY text_string
5826
5512
          {
5827
 
            LEX *lex= Lex;
5828
 
            assert(lex->exchange != 0);
5829
 
            lex->exchange->enclosed= $4;
5830
 
            lex->exchange->opt_enclosed= 1;
 
5513
            assert(Lex->exchange != 0);
 
5514
            Lex->exchange->enclosed= $4;
 
5515
            Lex->exchange->opt_enclosed= 1;
5831
5516
          }
5832
5517
        | ENCLOSED BY text_string
5833
5518
          {
5893
5578
 
5894
5579
field_or_var:
5895
5580
          simple_ident_nospvar {$$= $1;}
5896
 
        | '@' ident_or_text
 
5581
        | '@' user_variable_ident
5897
5582
          { $$= new Item_user_var_as_out_param($2); }
5898
5583
        ;
5899
5584
 
5907
5592
text_literal:
5908
5593
        TEXT_STRING_literal
5909
5594
        {
5910
 
          Session *session= YYSession;
5911
 
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
 
5595
          $$ = new Item_string($1.str, $1.length, YYSession->variables.getCollation());
5912
5596
        }
5913
5597
        | text_literal TEXT_STRING_literal
5914
5598
          {
6064
5748
simple_ident_q:
6065
5749
          ident '.' ident
6066
5750
          {
6067
 
            Session *session= YYSession;
6068
 
            LEX *lex= session->lex;
6069
 
 
6070
5751
            {
6071
 
              Select_Lex *sel= lex->current_select;
 
5752
              Select_Lex *sel= Lex->current_select;
6072
5753
              if (sel->no_table_names_allowed)
6073
5754
              {
6074
5755
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6075
 
                         MYF(0), $1.str, session->where);
 
5756
                         MYF(0), $1.str, YYSession->where);
6076
5757
              }
6077
5758
              $$= (sel->parsing_place != IN_HAVING ||
6078
5759
                  sel->get_in_sum_expr() > 0) ?
6084
5765
          }
6085
5766
        | '.' ident '.' ident
6086
5767
          {
6087
 
            Session *session= YYSession;
6088
 
            LEX *lex= session->lex;
6089
 
            Select_Lex *sel= lex->current_select;
 
5768
            Select_Lex *sel= Lex->current_select;
6090
5769
            if (sel->no_table_names_allowed)
6091
5770
            {
6092
5771
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6093
 
                       MYF(0), $2.str, session->where);
 
5772
                       MYF(0), $2.str, YYSession->where);
6094
5773
            }
6095
5774
            $$= (sel->parsing_place != IN_HAVING ||
6096
5775
                sel->get_in_sum_expr() > 0) ?
6100
5779
          }
6101
5780
        | ident '.' ident '.' ident
6102
5781
          {
6103
 
            Session *session= YYSession;
6104
 
            LEX *lex= session->lex;
6105
 
            Select_Lex *sel= lex->current_select;
 
5782
            Select_Lex *sel= Lex->current_select;
6106
5783
            if (sel->no_table_names_allowed)
6107
5784
            {
6108
5785
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6109
 
                       MYF(0), $3.str, session->where);
 
5786
                       MYF(0), $3.str, YYSession->where);
6110
5787
            }
6111
5788
            $$= (sel->parsing_place != IN_HAVING ||
6112
5789
                sel->get_in_sum_expr() > 0) ?
6152
5829
 
6153
5830
table_ident:
6154
5831
          ident { $$=new Table_ident($1); }
6155
 
        | ident '.' ident { $$=new Table_ident($1,$3);}
 
5832
        | schema_name '.' ident { $$=new Table_ident($1,$3);}
6156
5833
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
6157
5834
        ;
6158
5835
 
 
5836
schema_name:
 
5837
          ident
 
5838
        ;
 
5839
 
6159
5840
IDENT_sys:
6160
 
          IDENT { $$= $1; }
 
5841
          IDENT 
 
5842
          {
 
5843
            $$= $1;
 
5844
          }
6161
5845
        | IDENT_QUOTED
6162
5846
          {
6163
5847
            const CHARSET_INFO * const cs= system_charset_info;
6200
5884
          IDENT_sys    { $$=$1; }
6201
5885
        | keyword
6202
5886
          {
6203
 
            Session *session= YYSession;
6204
 
            $$.str= session->strmake($1.str, $1.length);
 
5887
            $$.str= YYSession->strmake($1.str, $1.length);
6205
5888
            $$.length= $1.length;
6206
5889
          }
6207
5890
        ;
6208
5891
 
6209
5892
ident_or_text:
6210
 
          ident           { $$=$1;}
6211
 
        | TEXT_STRING_sys { $$=$1;}
6212
 
        | LEX_HOSTNAME { $$=$1;}
 
5893
          IDENT_sys           { $$=$1;}
 
5894
        | TEXT_STRING_sys { $$=$1;}
 
5895
        ;
 
5896
 
 
5897
engine_option_value:
 
5898
          IDENT_sys           { $$=$1;}
 
5899
        | TEXT_STRING_sys { $$=$1;}
 
5900
        ;
 
5901
 
 
5902
keyword_exception_for_variable:
 
5903
          TIMESTAMP_SYM         {}
 
5904
        | SQL_BUFFER_RESULT     {}
 
5905
        | IDENTITY_SYM          {}
6213
5906
        ;
6214
5907
 
6215
5908
/* Keyword that we allow for identifiers (except SP labels) */
6216
5909
keyword:
6217
5910
          keyword_sp            {}
6218
5911
        | BEGIN_SYM             {}
6219
 
        | BYTE_SYM              {}
6220
5912
        | CHECKSUM_SYM          {}
6221
5913
        | CLOSE_SYM             {}
6222
5914
        | COMMENT_SYM           {}
6223
5915
        | COMMIT_SYM            {}
6224
5916
        | CONTAINS_SYM          {}
6225
5917
        | DEALLOCATE_SYM        {}
 
5918
        | DO_SYM                {}
6226
5919
        | END                   {}
6227
5920
        | FLUSH_SYM             {}
6228
5921
        | NO_SYM                {}
6231
5924
        | SAVEPOINT_SYM         {}
6232
5925
        | SECURITY_SYM          {}
6233
5926
        | SERVER_SYM            {}
 
5927
        | SIGNED_SYM            {}
6234
5928
        | START_SYM             {}
6235
5929
        | STOP_SYM              {}
6236
5930
        | TRUNCATE_SYM          {}
6250
5944
        | ANY_SYM                  {}
6251
5945
        | AT_SYM                   {}
6252
5946
        | AUTO_INC                 {}
6253
 
        | AVG_ROW_LENGTH           {}
6254
5947
        | AVG_SYM                  {}
6255
5948
        | BIT_SYM                  {}
6256
5949
        | BOOL_SYM                 {}
6271
5964
        | CUBE_SYM                 {}
6272
5965
        | DATA_SYM                 {}
6273
5966
        | DATABASES                {}
6274
 
        | DATAFILE_SYM             {}
6275
5967
        | DATETIME_SYM             {}
6276
5968
        | DATE_SYM                 {}
6277
5969
        | DAY_SYM                  {}
6304
5996
        | KEY_BLOCK_SIZE           {}
6305
5997
        | LAST_SYM                 {}
6306
5998
        | LEVEL_SYM                {}
6307
 
        | LIST_SYM                 {}
6308
5999
        | LOCAL_SYM                {}
6309
6000
        | LOCKS_SYM                {}
6310
6001
        | LOGS_SYM                 {}
6311
 
        | MAX_ROWS                 {}
6312
 
        | MAX_SIZE_SYM             {}
6313
6002
        | MAX_VALUE_SYM            {}
6314
6003
        | MEDIUM_SYM               {}
6315
6004
        | MERGE_SYM                {}
6316
6005
        | MICROSECOND_SYM          {}
6317
6006
        | MINUTE_SYM               {}
6318
 
        | MIN_ROWS                 {}
6319
6007
        | MODIFY_SYM               {}
6320
6008
        | MODE_SYM                 {}
6321
6009
        | MONTH_SYM                {}
6330
6018
        | ONE_SHOT_SYM             {}
6331
6019
        | ONE_SYM                  {}
6332
6020
        | ONLINE_SYM               {}
6333
 
        | PAGE_SYM                 {}
6334
6021
        | PARTIAL                  {}
6335
 
        | PHASE_SYM                {}
6336
6022
        | PREV_SYM                 {}
6337
6023
        | PROCESS                  {}
6338
6024
        | PROCESSLIST_SYM          {}
6339
6025
        | QUARTER_SYM              {}
6340
6026
        | QUERY_SYM                {}
6341
 
        | READ_ONLY_SYM            {}
6342
6027
        | REDUNDANT_SYM            {}
6343
6028
        | REPEATABLE_SYM           {}
6344
6029
        | RETURNS_SYM              {}
6345
 
        | REVERSE_SYM              {}
6346
6030
        | ROLLUP_SYM               {}
6347
6031
        | ROUTINE_SYM              {}
6348
6032
        | ROWS_SYM                 {}
6357
6041
        | SNAPSHOT_SYM             {}
6358
6042
        | SQL_BUFFER_RESULT        {}
6359
6043
        | STATUS_SYM               {}
6360
 
        | STORAGE_SYM              {}
6361
6044
        | STRING_SYM               {}
6362
6045
        | SUBDATE_SYM              {}
6363
6046
        | SUBJECT_SYM              {}
6364
6047
        | SUSPEND_SYM              {}
6365
 
        | SWAPS_SYM                {}
6366
 
        | SWITCHES_SYM             {}
6367
6048
        | TABLES                   {}
6368
6049
        | TABLESPACE               {}
6369
6050
        | TEMPORARY_SYM            {}
6370
6051
        | TEXT_SYM                 {}
6371
6052
        | TRANSACTION_SYM          {}
6372
6053
        | TIME_SYM                 {}
6373
 
        | TIMESTAMP_SYM            {}
6374
6054
        | TIMESTAMP_ADD            {}
6375
6055
        | TIMESTAMP_DIFF           {}
6376
 
        | TYPES_SYM                {}
6377
6056
        | TYPE_SYM                 {}
6378
6057
        | UNCOMMITTED_SYM          {}
6379
6058
        | UNDOFILE_SYM             {}
6392
6071
set:
6393
6072
          SET_SYM opt_option
6394
6073
          {
6395
 
            LEX *lex=Lex;
6396
 
            lex->sql_command= SQLCOM_SET_OPTION;
6397
 
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
6398
 
            lex->statement= statement;
6399
 
            if (lex->statement == NULL)
6400
 
              DRIZZLE_YYABORT;
6401
 
            init_select(lex);
6402
 
            lex->option_type=OPT_SESSION;
6403
 
            lex->var_list.empty();
 
6074
            Lex->sql_command= SQLCOM_SET_OPTION;
 
6075
            Lex->statement= new statement::SetOption(YYSession);
 
6076
            init_select(Lex);
 
6077
            Lex->option_type=OPT_SESSION;
 
6078
            Lex->var_list.empty();
6404
6079
          }
6405
6080
          option_value_list
6406
6081
          {}
6458
6133
sys_option_value:
6459
6134
          option_type internal_variable_name equal set_expr_or_default
6460
6135
          {
6461
 
            LEX *lex=Lex;
6462
 
 
6463
6136
            if ($2.var)
6464
6137
            { /* System variable */
6465
6138
              if ($1)
6466
 
                lex->option_type= $1;
6467
 
              lex->var_list.push_back(SetVarPtr(new set_var(lex->option_type, $2.var,
6468
 
                                      &$2.base_name, $4)));
 
6139
              {
 
6140
                Lex->option_type= $1;
 
6141
              }
 
6142
              Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type, $2.var, &$2.base_name, $4)));
6469
6143
            }
6470
6144
          }
6471
6145
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
6472
6146
          {
6473
 
            LEX *lex=Lex;
6474
 
            lex->option_type= $1;
6475
 
            lex->var_list.push_back(SetVarPtr(new set_var(lex->option_type,
6476
 
                                                find_sys_var("tx_isolation"),
6477
 
                                                &null_lex_str,
6478
 
                                                new Item_int((int32_t)
6479
 
                                                $5))));
 
6147
            Lex->option_type= $1;
 
6148
            Lex->var_list.push_back(SetVarPtr(new set_var(Lex->option_type,
 
6149
                                              find_sys_var("tx_isolation"),
 
6150
                                              &null_lex_str,
 
6151
                                              new Item_int((int32_t)
 
6152
                                              $5))));
6480
6153
          }
6481
6154
        ;
6482
6155
 
6483
6156
option_value:
6484
 
          '@' ident_or_text equal expr
 
6157
          '@' user_variable_ident equal expr
6485
6158
          {
6486
 
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new
6487
 
                    Item_func_set_user_var($2,$4))));
 
6159
            Lex->var_list.push_back(SetVarPtr(new set_var_user(new Item_func_set_user_var($2,$4))));
6488
6160
          }
6489
6161
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6490
6162
          {
6491
 
            LEX *lex=Lex;
6492
 
            lex->var_list.push_back(SetVarPtr(new set_var($3, $4.var,
6493
 
                    &$4.base_name, $6)));
6494
 
          }
 
6163
            Lex->var_list.push_back(SetVarPtr(new set_var($3, $4.var, &$4.base_name, $6)));
 
6164
          }
 
6165
        ;
 
6166
 
 
6167
user_variable_ident:
 
6168
          internal_variable_ident { $$=$1;}
 
6169
        | TEXT_STRING_sys { $$=$1;}
 
6170
        | LEX_HOSTNAME { $$=$1;}
 
6171
        ;
 
6172
 
 
6173
internal_variable_ident:
 
6174
          keyword_exception_for_variable
 
6175
          {
 
6176
            $$.str= YYSession->strmake($1.str, $1.length);
 
6177
            $$.length= $1.length;
 
6178
          }
 
6179
        | IDENT_sys    { $$=$1; }
6495
6180
        ;
6496
6181
 
6497
6182
internal_variable_name:
6498
 
          ident
 
6183
          internal_variable_ident
6499
6184
          {
6500
6185
            /* We have to lookup here since local vars can shadow sysvars */
6501
6186
            {
6502
6187
              /* Not an SP local variable */
6503
 
              sys_var *tmp=find_sys_var($1.str);
 
6188
              sys_var *tmp= find_sys_var(std::string($1.str, $1.length));
6504
6189
              if (!tmp)
6505
6190
                DRIZZLE_YYABORT;
6506
6191
              $$.var= tmp;
6532
6217
unlock:
6533
6218
          UNLOCK_SYM
6534
6219
          {
6535
 
            LEX *lex= Lex;
6536
 
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
6537
 
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
6538
 
            if (lex->statement == NULL)
6539
 
              DRIZZLE_YYABORT;
 
6220
            Lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
6221
            Lex->statement= new statement::UnlockTables(YYSession);
6540
6222
          }
6541
6223
          table_or_tables
6542
6224
          {}
6545
6227
begin:
6546
6228
          BEGIN_SYM
6547
6229
          {
6548
 
            LEX *lex=Lex;
6549
 
            lex->sql_command = SQLCOM_BEGIN;
6550
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
6551
 
            if (lex->statement == NULL)
6552
 
              DRIZZLE_YYABORT;
 
6230
            Lex->sql_command = SQLCOM_BEGIN;
 
6231
            Lex->statement= new statement::StartTransaction(YYSession);
6553
6232
          }
6554
6233
          opt_work {}
6555
6234
        ;
6581
6260
commit:
6582
6261
          COMMIT_SYM opt_work opt_chain opt_release
6583
6262
          {
6584
 
            LEX *lex=Lex;
6585
 
            lex->sql_command= SQLCOM_COMMIT;
6586
 
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
6587
 
            lex->statement= statement;
6588
 
            if (lex->statement == NULL)
6589
 
              DRIZZLE_YYABORT;
 
6263
            Lex->sql_command= SQLCOM_COMMIT;
 
6264
            statement::Commit *statement= new statement::Commit(YYSession);
 
6265
            Lex->statement= statement;
6590
6266
            statement->tx_chain= $3;
6591
6267
            statement->tx_release= $4;
6592
6268
          }
6595
6271
rollback:
6596
6272
          ROLLBACK_SYM opt_work opt_chain opt_release
6597
6273
          {
6598
 
            LEX *lex=Lex;
6599
 
            lex->sql_command= SQLCOM_ROLLBACK;
6600
 
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
6601
 
            lex->statement= statement;
6602
 
            if (lex->statement == NULL)
6603
 
              DRIZZLE_YYABORT;
 
6274
            Lex->sql_command= SQLCOM_ROLLBACK;
 
6275
            statement::Rollback *statement= new statement::Rollback(YYSession);
 
6276
            Lex->statement= statement;
6604
6277
            statement->tx_chain= $3;
6605
6278
            statement->tx_release= $4;
6606
6279
          }
6607
 
        | ROLLBACK_SYM opt_work
6608
 
          TO_SYM opt_savepoint ident
 
6280
        | ROLLBACK_SYM opt_work TO_SYM opt_savepoint savepoint_ident
6609
6281
          {
6610
 
            LEX *lex=Lex;
6611
 
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
6612
 
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
6613
 
            if (lex->statement == NULL)
6614
 
              DRIZZLE_YYABORT;
6615
 
            lex->ident= $5;
 
6282
            Lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
6283
            Lex->statement= new statement::RollbackToSavepoint(YYSession);
 
6284
            Lex->ident= $5;
6616
6285
          }
6617
6286
        ;
6618
6287
 
6619
6288
savepoint:
6620
 
          SAVEPOINT_SYM ident
 
6289
          SAVEPOINT_SYM savepoint_ident
6621
6290
          {
6622
 
            LEX *lex=Lex;
6623
 
            lex->sql_command= SQLCOM_SAVEPOINT;
6624
 
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
6625
 
            if (lex->statement == NULL)
6626
 
              DRIZZLE_YYABORT;
6627
 
            lex->ident= $2;
 
6291
            Lex->sql_command= SQLCOM_SAVEPOINT;
 
6292
            Lex->statement= new statement::Savepoint(YYSession);
 
6293
            Lex->ident= $2;
6628
6294
          }
6629
6295
        ;
6630
6296
 
6631
6297
release:
6632
 
          RELEASE_SYM SAVEPOINT_SYM ident
 
6298
          RELEASE_SYM SAVEPOINT_SYM savepoint_ident
6633
6299
          {
6634
 
            LEX *lex=Lex;
6635
 
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
6636
 
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
6637
 
            if (lex->statement == NULL)
6638
 
              DRIZZLE_YYABORT;
6639
 
            lex->ident= $3;
 
6300
            Lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
6301
            Lex->statement= new statement::ReleaseSavepoint(YYSession);
 
6302
            Lex->ident= $3;
6640
6303
          }
6641
6304
        ;
6642
6305
 
 
6306
savepoint_ident:
 
6307
               IDENT_sys
 
6308
               ;
 
6309
 
6643
6310
/*
6644
6311
   UNIONS : glue selects together
6645
6312
*/
6674
6341
 
6675
6342
union_order_or_limit:
6676
6343
          {
6677
 
            Session *session= YYSession;
6678
 
            LEX *lex= session->lex;
6679
 
            assert(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
6680
 
            Select_Lex *sel= lex->current_select;
 
6344
            assert(Lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
6345
            Select_Lex *sel= Lex->current_select;
6681
6346
            Select_Lex_Unit *unit= sel->master_unit();
6682
6347
            Select_Lex *fake= unit->fake_select_lex;
6683
6348
            if (fake)
6684
6349
            {
6685
6350
              unit->global_parameters= fake;
6686
6351
              fake->no_table_names_allowed= 1;
6687
 
              lex->current_select= fake;
 
6352
              Lex->current_select= fake;
6688
6353
            }
6689
 
            session->where= "global ORDER clause";
 
6354
            YYSession->where= "global ORDER clause";
6690
6355
          }
6691
6356
          order_or_limit
6692
6357
          {
6693
 
            Session *session= YYSession;
6694
 
            session->lex->current_select->no_table_names_allowed= 0;
6695
 
            session->where= "";
 
6358
            YYSession->lex->current_select->no_table_names_allowed= 0;
 
6359
            YYSession->where= "";
6696
6360
          }
6697
6361
        ;
6698
6362
 
6743
6407
 
6744
6408
subselect_start:
6745
6409
          {
6746
 
            LEX *lex=Lex;
6747
 
            if (!lex->expr_allows_subselect)
 
6410
            if (not Lex->expr_allows_subselect)
6748
6411
            {
6749
6412
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
6750
6413
              my_parse_error(&pass);
6764
6427
 
6765
6428
subselect_end:
6766
6429
          {
6767
 
            LEX *lex=Lex;
6768
 
            lex->pop_context();
6769
 
            Select_Lex *child= lex->current_select;
6770
 
            lex->current_select = lex->current_select->return_after_parsing();
6771
 
            lex->nest_level--;
6772
 
            lex->current_select->n_child_sum_items += child->n_sum_items;
 
6430
            Lex->pop_context();
 
6431
            Select_Lex *child= Lex->current_select;
 
6432
            Lex->current_select= Lex->current_select->return_after_parsing();
 
6433
            Lex->nest_level--;
 
6434
            Lex->current_select->n_child_sum_items += child->n_sum_items;
6773
6435
            /*
6774
6436
              A subselect can add fields to an outer select. Reserve space for
6775
6437
              them.
6776
6438
            */
6777
 
            lex->current_select->select_n_where_fields+=
 
6439
            Lex->current_select->select_n_where_fields+=
6778
6440
            child->select_n_where_fields;
6779
6441
          }
6780
6442
        ;