~drizzle-pbxt/drizzle/drizzle-pbxt-2

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Paul McCullagh
  • Date: 2009-11-10 14:18:39 UTC
  • mfrom: (1038.1.7 drizzle-pbxt-pre-merge)
  • Revision ID: paul.mccullagh@primebase.org-20091110141839-2j3k43b17ag6f605
Merged Drizzle trunk and PBXT 1.0.09

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
*/
28
28
#define YYPARSE_PARAM yysession
29
29
#define YYLEX_PARAM yysession
30
 
#define YYSession ((Session *)yysession)
 
30
#define YYSession (static_cast<Session *>(yysession))
31
31
 
32
32
#define YYENABLE_NLS 0
33
33
#define YYLTYPE_IS_TRIVIAL 0
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
38
#define Lex (YYSession->lex)
39
 
#define Select Lex->current_select
40
39
#include <drizzled/server_includes.h>
41
40
#include <drizzled/lex_symbol.h>
42
41
#include <drizzled/function/locate.h>
88
87
#include <drizzled/function/get_system_var.h>
89
88
#include <mysys/thr_lock.h>
90
89
#include <drizzled/message/table.pb.h>
 
90
#include <drizzled/statement.h>
 
91
#include <drizzled/statement/alter_schema.h>
 
92
#include <drizzled/statement/alter_table.h>
 
93
#include <drizzled/statement/analyze.h>
 
94
#include <drizzled/statement/change_schema.h>
 
95
#include <drizzled/statement/check.h>
 
96
#include <drizzled/statement/checksum.h>
 
97
#include <drizzled/statement/commit.h>
 
98
#include <drizzled/statement/create_index.h>
 
99
#include <drizzled/statement/create_schema.h>
 
100
#include <drizzled/statement/create_table.h>
 
101
#include <drizzled/statement/delete.h>
 
102
#include <drizzled/statement/drop_index.h>
 
103
#include <drizzled/statement/drop_schema.h>
 
104
#include <drizzled/statement/drop_table.h>
 
105
#include <drizzled/statement/empty_query.h>
 
106
#include <drizzled/statement/flush.h>
 
107
#include <drizzled/statement/insert.h>
 
108
#include <drizzled/statement/insert_select.h>
 
109
#include <drizzled/statement/kill.h>
 
110
#include <drizzled/statement/load.h>
 
111
#include <drizzled/statement/optimize.h>
 
112
#include <drizzled/statement/release_savepoint.h>
 
113
#include <drizzled/statement/rename_table.h>
 
114
#include <drizzled/statement/replace.h>
 
115
#include <drizzled/statement/replace_select.h>
 
116
#include <drizzled/statement/rollback.h>
 
117
#include <drizzled/statement/rollback_to_savepoint.h>
 
118
#include <drizzled/statement/savepoint.h>
 
119
#include <drizzled/statement/select.h>
 
120
#include <drizzled/statement/set_option.h>
 
121
#include <drizzled/statement/show_create.h>
 
122
#include <drizzled/statement/show_create_schema.h>
 
123
#include <drizzled/statement/show_engine_status.h>
 
124
#include <drizzled/statement/show_errors.h>
 
125
#include <drizzled/statement/show_processlist.h>
 
126
#include <drizzled/statement/show_status.h>
 
127
#include <drizzled/statement/show_warnings.h>
 
128
#include <drizzled/statement/start_transaction.h>
 
129
#include <drizzled/statement/truncate.h>
 
130
#include <drizzled/statement/unlock_tables.h>
 
131
#include <drizzled/statement/update.h>
 
132
 
 
133
using namespace drizzled;
91
134
 
92
135
class Table_ident;
93
136
class Item;
137
180
  parser.
138
181
*/
139
182
 
140
 
void my_parse_error(const char *s)
 
183
static void my_parse_error(const char *s)
141
184
{
142
185
  Session *session= current_session;
143
186
  Lex_input_stream *lip= session->m_lip;
169
212
  to abort from the parser.
170
213
*/
171
214
 
172
 
void DRIZZLEerror(const char *s)
 
215
static void DRIZZLEerror(const char *s)
173
216
{
174
217
  Session *session= current_session;
175
218
 
197
240
  @param expr first and only expression of the in value list
198
241
  @return an expression representing the IN predicate.
199
242
*/
200
 
Item* handle_sql2003_note184_exception(Session *session, Item* left, bool equal,
201
 
                                       Item *expr)
 
243
static Item* handle_sql2003_note184_exception(Session *session,
 
244
                                              Item* left, bool equal,
 
245
                                              Item *expr)
202
246
{
203
247
  /*
204
248
    Relevant references for this issue:
274
318
   @return <code>false</code> if successful, <code>true</code> if an error was
275
319
   reported. In the latter case parsing should stop.
276
320
 */
277
 
bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
321
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
278
322
{
279
323
  if (lex->result)
280
324
  {
306
350
   @return false if successful, true if an error was reported. In the latter
307
351
   case parsing should stop.
308
352
 */
309
 
bool setup_select_in_parentheses(LEX *lex) 
 
353
static bool setup_select_in_parentheses(LEX *lex) 
310
354
{
311
355
  Select_Lex * sel= lex->current_select;
312
356
  if (sel->set_braces(1))
353
397
  List<String> *string_list;
354
398
  String *string;
355
399
  Key_part_spec *key_part;
356
 
  Function_builder *udf;
 
400
  const ::drizzled::plugin::Function *udf;
357
401
  TableList *table_list;
358
402
  struct sys_var_with_base variable;
359
403
  enum enum_var_type var_type;
360
404
  Key::Keytype key_type;
361
405
  enum ha_key_alg key_alg;
362
 
  StorageEngine *db_type;
363
406
  enum row_type row_type;
364
407
  enum column_format_type column_format_type;
365
408
  enum ha_rkey_function ha_rkey_mode;
366
409
  enum enum_tx_isolation tx_isolation;
367
410
  enum Cast_target cast_type;
368
 
  enum ha_choice choice;
369
411
  const CHARSET_INFO *charset;
370
412
  thr_lock_type lock_type;
371
 
  struct st_table_lock_info table_lock_info;
372
413
  interval_type interval, interval_time_st;
373
414
  enum enum_drizzle_timestamp_type date_time_type;
374
415
  Select_Lex *select_lex;
375
416
  chooser_compare_func_creator boolfunc2creator;
376
 
  struct { int vars, conds, hndlrs, curs; } spblock;
377
417
  struct st_lex *lex;
378
418
  struct p_elem_val *p_elem_value;
379
419
  enum index_hint_type index_hint;
388
428
 
389
429
%pure_parser                                    /* We have threads */
390
430
/*
391
 
  Currently there are 90 shift/reduce conflicts.
 
431
  Currently there are 88 shift/reduce conflicts.
392
432
  We should not introduce new conflicts any more.
393
433
*/
394
 
%expect 90
 
434
%expect 88
395
435
 
396
436
/*
397
437
   Comments for TOKENS.
411
451
*/
412
452
 
413
453
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
414
 
%token  ACCESSIBLE_SYM
415
454
%token  ACTION                        /* SQL-2003-N */
416
455
%token  ADD                           /* SQL-2003-R */
417
456
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
418
457
%token  AFTER_SYM                     /* SQL-2003-N */
419
458
%token  AGGREGATE_SYM
420
 
%token  ALGORITHM_SYM
421
459
%token  ALL                           /* SQL-2003-R */
422
460
%token  ALTER                         /* SQL-2003-R */
423
461
%token  ANALYZE_SYM
425
463
%token  ANY_SYM                       /* SQL-2003-R */
426
464
%token  AS                            /* SQL-2003-R */
427
465
%token  ASC                           /* SQL-2003-N */
428
 
%token  ASCII_SYM                     /* MYSQL-FUNC */
429
466
%token  ASENSITIVE_SYM                /* FUTURE-USE */
430
467
%token  AT_SYM                        /* SQL-2003-R */
431
 
%token  AUTOEXTEND_SIZE_SYM
432
468
%token  AUTO_INC
433
469
%token  AVG_ROW_LENGTH
434
470
%token  AVG_SYM                       /* SQL-2003-N */
508
544
%token  DECIMAL_SYM                   /* SQL-2003-R */
509
545
%token  DECLARE_SYM                   /* SQL-2003-R */
510
546
%token  DEFAULT                       /* SQL-2003-R */
511
 
%token  DELAY_KEY_WRITE_SYM
512
547
%token  DELETE_SYM                    /* SQL-2003-R */
513
548
%token  DESC                          /* SQL-2003-N */
514
549
%token  DESCRIBE                      /* SQL-2003-R */
515
550
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
516
 
%token  DIRECTORY_SYM
517
551
%token  DISABLE_SYM
518
552
%token  DISCARD
519
553
%token  DISTINCT                      /* SQL-2003-R */
546
580
%token  EXTRACT_SYM                   /* SQL-2003-N */
547
581
%token  FALSE_SYM                     /* SQL-2003-R */
548
582
%token  FAST_SYM
549
 
%token  FAULTS_SYM
550
583
%token  FETCH_SYM                     /* SQL-2003-R */
551
584
%token  COLUMN_FORMAT_SYM
552
585
%token  FILE_SYM
566
599
%token  GROUP_SYM                     /* SQL-2003-R */
567
600
%token  GROUP_CONCAT_SYM
568
601
%token  GT_SYM                        /* OPERATOR */
569
 
%token  HANDLER_SYM
570
602
%token  HASH_SYM
571
603
%token  HAVING                        /* SQL-2003-R */
572
604
%token  HEX_NUM
585
617
%token  INDEXES
586
618
%token  INDEX_SYM
587
619
%token  INFILE
588
 
%token  INITIAL_SIZE_SYM
589
620
%token  INNER_SYM                     /* SQL-2003-R */
590
621
%token  INOUT_SYM                     /* SQL-2003-R */
591
622
%token  INSENSITIVE_SYM               /* SQL-2003-R */
607
638
%token  LAST_SYM                      /* SQL-2003-N */
608
639
%token  LE                            /* OPERATOR */
609
640
%token  LEADING                       /* SQL-2003-R */
610
 
%token  LEAVES
611
641
%token  LEFT                          /* SQL-2003-R */
612
642
%token  LEVEL_SYM
613
643
%token  LEX_HOSTNAME
614
644
%token  LIKE                          /* SQL-2003-R */
615
645
%token  LIMIT
616
 
%token  LINEAR_SYM
617
646
%token  LINES
618
 
%token  LINESTRING
619
647
%token  LIST_SYM
620
648
%token  LOAD
621
649
%token  LOCAL_SYM                     /* SQL-2003-R */
622
650
%token  LOCATOR_SYM                   /* SQL-2003-N */
623
651
%token  LOCKS_SYM
624
652
%token  LOCK_SYM
625
 
%token  LOGFILE_SYM
626
653
%token  LOGS_SYM
627
654
%token  LONG_NUM
628
655
%token  LONG_SYM
682
709
%token  OUTER
683
710
%token  OUTFILE
684
711
%token  OUT_SYM                       /* SQL-2003-R */
685
 
%token  PACK_KEYS_SYM
686
712
%token  PAGE_SYM
687
 
%token  PAGE_CHECKSUM_SYM
688
713
%token  PARAM_MARKER
689
714
%token  PARTIAL                       /* SQL-2003-N */
690
715
%token  PHASE_SYM
717
742
%token  REMOVE_SYM
718
743
%token  RENAME
719
744
%token  REORGANIZE_SYM
720
 
%token  REPAIR
721
745
%token  REPEATABLE_SYM                /* SQL-2003-N */
722
746
%token  REPEAT_SYM                    /* MYSQL-FUNC */
723
747
%token  REPLACE                       /* MYSQL-FUNC */
784
808
%token  SUBJECT_SYM
785
809
%token  SUBSTRING                     /* SQL-2003-N */
786
810
%token  SUM_SYM                       /* SQL-2003-N */
787
 
%token  SUPER_SYM
788
811
%token  SUSPEND_SYM
789
812
%token  SWAPS_SYM
790
813
%token  SWITCHES_SYM
793
816
%token  TABLESPACE
794
817
%token  TABLE_REF_PRIORITY
795
818
%token  TABLE_SYM                     /* SQL-2003-R */
796
 
%token  TABLE_CHECKSUM_SYM
797
819
%token  TEMPORARY_SYM                 /* SQL-2003-N */
798
820
%token  TEMPTABLE_SYM
799
821
%token  TERMINATED
825
847
%token  UPDATE_SYM                    /* SQL-2003-R */
826
848
%token  USAGE                         /* SQL-2003-N */
827
849
%token  USER                          /* SQL-2003-R */
828
 
%token  USE_FRM
829
850
%token  USE_SYM
830
851
%token  USING                         /* SQL-2003-R */
831
852
%token  UTC_DATE_SYM
838
859
%token  VARIANCE_SYM
839
860
%token  VARYING                       /* SQL-2003-R */
840
861
%token  VAR_SAMP_SYM
841
 
%token  VIRTUAL_SYM
842
862
%token  WAIT_SYM
843
863
%token  WARNINGS
844
864
%token  WEEK_SYM
873
893
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
874
894
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
875
895
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
876
 
        opt_component key_cache_name
 
896
        opt_component
877
897
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
878
898
        opt_constraint constraint opt_ident
879
899
 
897
917
        union_option
898
918
        start_transaction_opts opt_chain opt_release
899
919
        union_opt select_derived_init option_type2
900
 
        /* opt_lock_timeout_value */
901
920
 
902
921
%type <m_fk_option>
903
922
        delete_option
912
931
%type <ulonglong_number>
913
932
        ulonglong_num
914
933
 
915
 
%type <choice> choice
916
 
 
917
934
%type <lock_type>
918
935
        load_data_lock
919
936
 
920
 
%type <table_lock_info>
921
 
        table_lock_info
922
 
 
923
937
%type <item>
924
938
        literal text_literal insert_ident order_ident
925
939
        simple_ident expr opt_expr opt_else sum_expr in_sum_expr
968
982
 
969
983
%type <interval_time_st> interval_time_stamp
970
984
 
971
 
%type <db_type> storage_engines known_storage_engines
972
 
 
973
985
%type <row_type> row_types
974
986
 
975
987
%type <column_format_type> column_format_types
997
1009
%type <NONE>
998
1010
        query verb_clause create select drop insert replace insert2
999
1011
        insert_values update delete truncate rename
1000
 
        show describe load alter optimize keycache flush
 
1012
        show describe load alter optimize flush
1001
1013
        begin commit rollback savepoint release
1002
 
        repair analyze check start checksum
 
1014
        analyze check start checksum
1003
1015
        field_list field_list_item field_spec kill column_def key_def
1004
 
        keycache_list assign_to_keycache
1005
1016
        select_item_list select_item values_list no_braces
1006
1017
        opt_limit_clause delete_limit_clause fields opt_values values
1007
1018
        opt_precision opt_ignore opt_column
1008
 
        set lock unlock string_list
1009
 
        opt_binary table_lock_list table_lock
 
1019
        set unlock string_list
 
1020
        opt_binary
1010
1021
        ref_list opt_match_clause opt_on_update_delete use
1011
1022
        opt_delete_options opt_delete_option varchar
1012
 
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
 
1023
        opt_outer table_list table_name
1013
1024
        opt_option opt_place
1014
1025
        opt_attribute opt_attribute_list attribute
1015
1026
        flush_options flush_option
1016
1027
        equal optional_braces
1017
1028
        opt_mi_check_type opt_to mi_check_types normal_join
1018
1029
        table_to_table_list table_to_table opt_table_list opt_as
1019
 
        single_multi table_wild_list table_wild_one opt_wild
 
1030
        single_multi
1020
1031
        union_clause union_list
1021
1032
        precision subselect_start
1022
1033
        subselect_end select_var_list select_var_list_init opt_len
1069
1080
            else
1070
1081
            {
1071
1082
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1083
              session->lex->statement= 
 
1084
                new(std::nothrow) statement::EmptyQuery(YYSession);
 
1085
              if (session->lex->statement == NULL)
 
1086
                DRIZZLE_YYABORT;
1072
1087
            }
1073
1088
          }
1074
1089
        | verb_clause END_OF_INPUT {}
1094
1109
        | insert
1095
1110
        | kill
1096
1111
        | load
1097
 
        | lock
1098
1112
        | optimize
1099
 
        | keycache
1100
1113
        | release
1101
1114
        | rename
1102
 
        | repair
1103
1115
        | replace
1104
1116
        | rollback
1105
1117
        | savepoint
1121
1133
            Session *session= YYSession;
1122
1134
            LEX *lex= session->lex;
1123
1135
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1136
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
 
1137
            lex->statement= statement;
 
1138
            if (lex->statement == NULL)
 
1139
              DRIZZLE_YYABORT;
1124
1140
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1125
1141
                                                   TL_OPTION_UPDATING,
1126
1142
                                                   TL_WRITE))
1127
1143
              DRIZZLE_YYABORT;
1128
 
            lex->alter_info.reset();
1129
1144
            lex->col_list.empty();
1130
 
            lex->change=NULL;
1131
 
            memset(&lex->create_info, 0, sizeof(lex->create_info));
1132
 
            lex->create_info.options=$2 | $4;
1133
 
            lex->create_info.db_type= ha_default_storage_engine(session);
1134
 
            lex->create_info.default_table_charset= NULL;
 
1145
            statement->change=NULL;
 
1146
            statement->create_info.options=$2 | $4;
 
1147
            statement->create_info.db_type= NULL;
 
1148
            statement->create_info.default_table_charset= NULL;
1135
1149
            lex->name.str= 0;
1136
1150
 
1137
 
            drizzled::message::Table *proto=
1138
 
              lex->create_table_proto= new drizzled::message::Table();
 
1151
            message::Table *proto= &statement->create_table_proto;
1139
1152
            
1140
1153
            proto->set_name($5->table.str);
1141
1154
            if($2 & HA_LEX_CREATE_TMP_TABLE)
1142
 
              proto->set_type(drizzled::message::Table::TEMPORARY);
 
1155
              proto->set_type(message::Table::TEMPORARY);
1143
1156
            else
1144
 
              proto->set_type(drizzled::message::Table::STANDARD);
1145
 
 
 
1157
              proto->set_type(message::Table::STANDARD);
1146
1158
          }
1147
1159
          create2
1148
1160
          {
1149
1161
            LEX *lex= YYSession->lex;
1150
1162
            lex->current_select= &lex->select_lex; 
1151
 
            assert(lex->create_info.db_type);
1152
1163
          }
1153
 
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
1154
 
          ON table_ident
 
1164
        | CREATE build_method
1155
1165
          {
1156
1166
            LEX *lex=Lex;
1157
1167
            lex->sql_command= SQLCOM_CREATE_INDEX;
1158
 
            if (!lex->current_select->add_table_to_list(lex->session, $8,
 
1168
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
 
1169
            lex->statement= statement;
 
1170
            if (lex->statement == NULL)
 
1171
              DRIZZLE_YYABORT;
 
1172
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1173
            statement->alter_info.build_method= $2;
 
1174
            lex->col_list.empty();
 
1175
            statement->change=NULL;
 
1176
          }
 
1177
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
 
1178
          {
 
1179
            LEX *lex=Lex;
 
1180
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
 
1181
 
 
1182
            if (!lex->current_select->add_table_to_list(lex->session, $9,
1159
1183
                                                        NULL,
1160
1184
                                                        TL_OPTION_UPDATING))
1161
1185
              DRIZZLE_YYABORT;
1162
 
            lex->alter_info.reset();
1163
 
            lex->alter_info.flags= ALTER_ADD_INDEX;
1164
 
            lex->alter_info.build_method= $2;
1165
 
            lex->col_list.empty();
1166
 
            lex->change=NULL;
1167
 
          }
1168
 
          '(' key_list ')' key_options
1169
 
          {
1170
 
            LEX *lex=Lex;
1171
1186
            Key *key;
1172
 
            key= new Key($3, $5, &lex->key_create_info, 0,
1173
 
                         lex->col_list);
1174
 
            lex->alter_info.key_list.push_back(key);
 
1187
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
 
1188
            statement->alter_info.key_list.push_back(key);
1175
1189
            lex->col_list.empty();
1176
1190
          }
1177
1191
        | CREATE DATABASE opt_if_not_exists ident
1178
1192
          {
1179
 
            Lex->create_info.default_table_charset= NULL;
1180
 
            Lex->create_info.used_fields= 0;
 
1193
            LEX *lex=Lex;
 
1194
 
 
1195
            lex->sql_command=SQLCOM_CREATE_DB;
 
1196
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
 
1197
            lex->statement= statement;
 
1198
            if (lex->statement == NULL)
 
1199
              DRIZZLE_YYABORT;
 
1200
            statement->create_info.options=$3;
1181
1201
          }
1182
1202
          opt_create_database_options
1183
1203
          {
1184
 
            LEX *lex=Lex;
1185
 
            lex->sql_command=SQLCOM_CREATE_DB;
1186
 
            lex->name= $4;
1187
 
            lex->create_info.options=$3;
 
1204
            Lex->name= $4;
1188
1205
          }
1189
1206
        ;
1190
1207
 
1192
1209
          '(' create2a {}
1193
1210
        | opt_create_table_options
1194
1211
          create3 {}
1195
 
        | LIKE table_ident
 
1212
        | LIKE table_ident opt_create_table_options
1196
1213
          {
1197
1214
            Session *session= YYSession;
1198
1215
            LEX *lex= session->lex;
 
1216
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1199
1217
 
1200
 
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1218
            statement->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1201
1219
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1202
1220
              DRIZZLE_YYABORT;
1203
1221
          }
1205
1223
          {
1206
1224
            Session *session= YYSession;
1207
1225
            LEX *lex= session->lex;
 
1226
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1208
1227
 
1209
 
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1228
            statement->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1210
1229
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1211
1230
              DRIZZLE_YYABORT;
1212
1231
          }
1216
1235
          field_list ')' opt_create_table_options
1217
1236
          create3 {}
1218
1237
        |  create_select ')'
1219
 
           { Select->set_braces(1);}
 
1238
           { Lex->current_select->set_braces(1);}
1220
1239
           union_opt {}
1221
1240
        ;
1222
1241
 
1223
1242
create3:
1224
1243
          /* empty */ {}
1225
1244
        | opt_duplicate opt_as create_select
1226
 
          { Select->set_braces(0);}
 
1245
          { Lex->current_select->set_braces(0);}
1227
1246
          union_clause {}
1228
1247
        | opt_duplicate opt_as '(' create_select ')'
1229
 
          { Select->set_braces(1);}
 
1248
          { Lex->current_select->set_braces(1);}
1230
1249
          union_opt {}
1231
1250
        ;
1232
1251
 
1236
1255
            LEX *lex=Lex;
1237
1256
            lex->lock_option= TL_READ;
1238
1257
            if (lex->sql_command == SQLCOM_INSERT)
 
1258
            {
1239
1259
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1260
              delete lex->statement;
 
1261
              lex->statement= 
 
1262
                new(std::nothrow) statement::InsertSelect(YYSession);
 
1263
              if (lex->statement == NULL)
 
1264
                DRIZZLE_YYABORT;
 
1265
            }
1240
1266
            else if (lex->sql_command == SQLCOM_REPLACE)
 
1267
            {
1241
1268
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1269
              delete lex->statement;
 
1270
              lex->statement= 
 
1271
                new(std::nothrow) statement::ReplaceSelect(YYSession);
 
1272
              if (lex->statement == NULL)
 
1273
                DRIZZLE_YYABORT;
 
1274
            }
1242
1275
            /*
1243
1276
              The following work only with the local list, the global list
1244
1277
              is created correctly in this case
1249
1282
          }
1250
1283
          select_options select_item_list
1251
1284
          {
1252
 
            Select->parsing_place= NO_MATTER;
 
1285
            Lex->current_select->parsing_place= NO_MATTER;
1253
1286
          }
1254
1287
          opt_select_from
1255
1288
          {
1268
1301
 
1269
1302
opt_create_database_options:
1270
1303
          /* empty */ {}
1271
 
        | create_database_options {}
1272
 
        ;
1273
 
 
1274
 
create_database_options:
1275
 
          create_database_option {}
1276
 
        | create_database_options create_database_option {}
1277
 
        ;
1278
 
 
1279
 
create_database_option:
1280
 
          default_collation {}
 
1304
        | default_collation_schema {}
1281
1305
        ;
1282
1306
 
1283
1307
opt_table_options:
1316
1340
        ;
1317
1341
 
1318
1342
create_table_option:
1319
 
          ENGINE_SYM opt_equal storage_engines
1320
 
          {
1321
 
            Lex->create_info.db_type= $3;
1322
 
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
1323
 
          }
1324
 
        | MAX_ROWS opt_equal ulonglong_num
1325
 
          {
1326
 
            Lex->create_info.max_rows= $3;
1327
 
            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
1328
 
          }
1329
 
        | MIN_ROWS opt_equal ulonglong_num
1330
 
          {
1331
 
            Lex->create_info.min_rows= $3;
1332
 
            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
1333
 
          }
1334
 
        | AVG_ROW_LENGTH opt_equal ulong_num
1335
 
          {
1336
 
            Lex->create_info.avg_row_length=$3;
1337
 
            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
 
1343
          ENGINE_SYM opt_equal ident_or_text
 
1344
          {
 
1345
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1346
 
 
1347
            statement->create_info.db_type= NULL;
 
1348
            statement->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1349
 
 
1350
            {
 
1351
              message::Table::StorageEngine *protoengine;
 
1352
              protoengine= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_engine();
 
1353
 
 
1354
              protoengine->set_name($3.str);
 
1355
            }
1338
1356
          }
1339
1357
        | BLOCK_SIZE_SYM opt_equal ulong_num    
1340
1358
          { 
1341
 
            Lex->create_info.block_size= $3; 
1342
 
            Lex->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
 
1359
            message::Table::TableOptions *tableopts;
 
1360
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1361
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1362
 
 
1363
            tableopts->set_block_size($3);
 
1364
            statement->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
1343
1365
          }
1344
1366
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1345
1367
          {
1346
 
            Lex->create_info.comment=$3;
1347
 
            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
 
1368
            message::Table::TableOptions *tableopts;
 
1369
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_proto.mutable_options();
 
1370
 
 
1371
            tableopts->set_comment($3.str);
1348
1372
          }
1349
1373
        | AUTO_INC opt_equal ulonglong_num
1350
1374
          {
1351
 
            Lex->create_info.auto_increment_value=$3;
1352
 
            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
1353
 
          }
1354
 
        | PACK_KEYS_SYM opt_equal ulong_num
1355
 
          {
1356
 
            switch($3) {
1357
 
            case 0:
1358
 
                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
1359
 
                break;
1360
 
            case 1:
1361
 
                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
1362
 
                break;
1363
 
            default:
1364
 
                my_parse_error(ER(ER_SYNTAX_ERROR));
1365
 
                DRIZZLE_YYABORT;
1366
 
            }
1367
 
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
1368
 
          }
1369
 
        | PACK_KEYS_SYM opt_equal DEFAULT
1370
 
          {
1371
 
            Lex->create_info.table_options&=
1372
 
              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
1373
 
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
1374
 
          }
1375
 
        | CHECKSUM_SYM opt_equal ulong_num
1376
 
          {
1377
 
            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
1378
 
            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
1379
 
          }
1380
 
        | TABLE_CHECKSUM_SYM opt_equal ulong_num
1381
 
          {
1382
 
             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
1383
 
             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
1384
 
          }
1385
 
        | PAGE_CHECKSUM_SYM opt_equal choice
1386
 
          {
1387
 
            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
1388
 
            Lex->create_info.page_checksum= $3;
1389
 
          }
1390
 
        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
1391
 
          {
1392
 
            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
1393
 
            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
 
1375
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1376
 
 
1377
            statement->create_info.auto_increment_value=$3;
 
1378
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1394
1379
          }
1395
1380
        | ROW_FORMAT_SYM opt_equal row_types
1396
1381
          {
1397
 
            Lex->create_info.row_type= $3;
1398
 
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1399
 
            Lex->alter_info.flags|= ALTER_ROW_FORMAT;
 
1382
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1383
 
 
1384
            statement->create_info.row_type= $3;
 
1385
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1386
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1400
1387
          }
1401
1388
        | default_collation
1402
 
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1403
 
          {
1404
 
            Lex->create_info.data_file_name= $4.str;
1405
 
            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
1406
 
          }
1407
 
        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1408
 
          {
1409
 
            Lex->create_info.index_file_name= $4.str;
1410
 
            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
1411
 
          }
1412
 
        | CONNECTION_SYM opt_equal TEXT_STRING_sys
1413
 
          {
1414
 
            Lex->create_info.connect_string.str= $3.str;
1415
 
            Lex->create_info.connect_string.length= $3.length;
1416
 
            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
1417
 
          }
1418
1389
        | KEY_BLOCK_SIZE opt_equal ulong_num
1419
1390
          {
1420
 
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1421
 
            Lex->create_info.key_block_size= $3;
 
1391
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1392
 
 
1393
            statement->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1394
            statement->create_info.key_block_size= $3;
1422
1395
          }
1423
1396
        ;
1424
1397
 
1425
1398
default_collation:
1426
1399
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1427
1400
          {
1428
 
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1401
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1402
 
 
1403
            HA_CREATE_INFO *cinfo= &statement->create_info;
1429
1404
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1430
1405
                 cinfo->default_table_charset && $4 &&
1431
1406
                 !my_charset_same(cinfo->default_table_charset,$4))
1434
1409
                         $4->name, cinfo->default_table_charset->csname);
1435
1410
                DRIZZLE_YYABORT;
1436
1411
              }
1437
 
              Lex->create_info.default_table_charset= $4;
1438
 
              Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1439
 
          }
1440
 
        ;
1441
 
 
1442
 
storage_engines:
1443
 
          ident_or_text
1444
 
          {
1445
 
            StorageEngine *engine= ha_resolve_by_name(YYSession, &$1);
1446
 
 
1447
 
            if (engine)
1448
 
              $$= engine;
1449
 
            else
1450
 
            {
1451
 
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1452
 
              DRIZZLE_YYABORT;
1453
 
            }
1454
 
          }
1455
 
        ;
1456
 
 
1457
 
known_storage_engines:
1458
 
          ident_or_text
1459
 
          {
1460
 
            StorageEngine *engine;
1461
 
            if ((engine= ha_resolve_by_name(YYSession, &$1)))
1462
 
              $$= engine;
1463
 
            else
1464
 
            {
1465
 
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1466
 
              DRIZZLE_YYABORT;
1467
 
            }
 
1412
              statement->create_info.default_table_charset= $4;
 
1413
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1414
          }
 
1415
        ;
 
1416
 
 
1417
default_collation_schema:
 
1418
          opt_default COLLATE_SYM opt_equal collation_name_or_default
 
1419
          {
 
1420
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1421
 
 
1422
            statement->create_info.default_table_charset= $4;
 
1423
            statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1468
1424
          }
1469
1425
        ;
1470
1426
 
1510
1466
          key_type opt_ident key_alg '(' key_list ')' key_options
1511
1467
          {
1512
1468
            LEX *lex=Lex;
1513
 
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
 
1469
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1470
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
1514
1471
                              lex->col_list);
1515
 
            lex->alter_info.key_list.push_back(key);
 
1472
            statement->alter_info.key_list.push_back(key);
1516
1473
            lex->col_list.empty(); /* Alloced by sql_alloc */
1517
1474
          }
1518
1475
        | opt_constraint constraint_key_type opt_ident key_alg
1519
1476
          '(' key_list ')' key_options
1520
1477
          {
1521
1478
            LEX *lex=Lex;
1522
 
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
 
1479
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1480
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1523
1481
                              lex->col_list);
1524
 
            lex->alter_info.key_list.push_back(key);
 
1482
            statement->alter_info.key_list.push_back(key);
1525
1483
            lex->col_list.empty(); /* Alloced by sql_alloc */
1526
1484
          }
1527
1485
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1528
1486
          {
1529
1487
            LEX *lex=Lex;
 
1488
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1530
1489
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1531
1490
                                      $8,
1532
1491
                                      lex->ref_list,
1533
 
                                      lex->fk_delete_opt,
1534
 
                                      lex->fk_update_opt,
1535
 
                                      lex->fk_match_option);
1536
 
            lex->alter_info.key_list.push_back(key);
 
1492
                                      statement->fk_delete_opt,
 
1493
                                      statement->fk_update_opt,
 
1494
                                      statement->fk_match_option);
 
1495
            statement->alter_info.key_list.push_back(key);
1537
1496
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1538
1497
                         &default_key_create_info, 1,
1539
1498
                         lex->col_list);
1540
 
            lex->alter_info.key_list.push_back(key);
 
1499
            statement->alter_info.key_list.push_back(key);
1541
1500
            lex->col_list.empty(); /* Alloced by sql_alloc */
1542
1501
            /* Only used for ALTER TABLE. Ignored otherwise. */
1543
 
            lex->alter_info.flags|= ALTER_FOREIGN_KEY;
 
1502
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1544
1503
          }
1545
1504
        | constraint opt_check_constraint
1546
1505
          {
1574
1533
          field_ident
1575
1534
          {
1576
1535
            LEX *lex=Lex;
 
1536
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1577
1537
            lex->length=lex->dec=0;
1578
1538
            lex->type=0;
1579
 
            lex->default_value= lex->on_update_value= 0;
1580
 
            lex->comment=null_lex_str;
 
1539
            statement->default_value= statement->on_update_value= 0;
 
1540
            statement->comment= null_lex_str;
1581
1541
            lex->charset=NULL;
1582
 
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1542
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1583
1543
          }
1584
1544
          field_def
1585
1545
          {
1586
1546
            LEX *lex=Lex;
 
1547
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1587
1548
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1588
1549
                                  lex->length,lex->dec,lex->type,
1589
 
                                  lex->column_format,
1590
 
                                  lex->default_value, lex->on_update_value, 
1591
 
                                  &lex->comment,
1592
 
                                  lex->change,&lex->interval_list,lex->charset))
 
1550
                                  statement->column_format,
 
1551
                                  statement->default_value, statement->on_update_value, 
 
1552
                                  &statement->comment,
 
1553
                                  statement->change, &lex->interval_list, lex->charset))
1593
1554
              DRIZZLE_YYABORT;
1594
1555
          }
1595
1556
        ;
1726
1687
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
1727
1688
        | COLUMN_FORMAT_SYM column_format_types
1728
1689
          {
1729
 
            Lex->column_format= $2;
1730
 
            Lex->alter_info.flags|= ALTER_COLUMN_FORMAT;
 
1690
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1691
 
 
1692
            statement->column_format= $2;
 
1693
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1731
1694
          }
1732
1695
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
1733
1696
        | DEFAULT now_or_signed_literal 
1734
1697
          { 
1735
 
            Lex->default_value=$2; 
1736
 
            Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
1698
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1699
 
 
1700
            statement->default_value=$2; 
 
1701
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1737
1702
          }
1738
1703
        | ON UPDATE_SYM NOW_SYM optional_braces 
1739
 
          { Lex->on_update_value= new Item_func_now_local(); }
 
1704
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1740
1705
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1741
1706
        | SERIAL_SYM DEFAULT VALUE_SYM
1742
1707
          { 
1743
1708
            LEX *lex=Lex;
 
1709
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1710
 
1744
1711
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1745
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1712
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1746
1713
          }
1747
1714
        | opt_primary KEY_SYM
1748
1715
          {
1749
1716
            LEX *lex=Lex;
 
1717
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1718
 
1750
1719
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1751
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1720
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1752
1721
          }
1753
1722
        | UNIQUE_SYM
1754
1723
          {
1755
1724
            LEX *lex=Lex;
 
1725
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1726
 
1756
1727
            lex->type|= UNIQUE_FLAG; 
1757
 
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
1728
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1758
1729
          }
1759
1730
        | UNIQUE_SYM KEY_SYM
1760
1731
          {
1761
1732
            LEX *lex=Lex;
 
1733
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1734
 
1762
1735
            lex->type|= UNIQUE_KEY_FLAG; 
1763
 
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
1736
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1764
1737
          }
1765
 
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
 
1738
        | COMMENT_SYM TEXT_STRING_sys { ((statement::AlterTable *)Lex->statement)->comment= $2; }
1766
1739
        | COLLATE_SYM collation_name
1767
1740
          {
1768
1741
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
1915
1888
 
1916
1889
opt_match_clause:
1917
1890
          /* empty */
1918
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
 
1891
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
1919
1892
        | MATCH FULL
1920
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
 
1893
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
1921
1894
        | MATCH PARTIAL
1922
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
 
1895
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
1923
1896
        | MATCH SIMPLE_SYM
1924
 
          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
 
1897
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
1925
1898
        ;
1926
1899
 
1927
1900
opt_on_update_delete:
1928
1901
          /* empty */
1929
1902
          {
1930
 
            LEX *lex= Lex;
1931
 
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1932
 
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1903
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1904
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1933
1905
          }
1934
1906
        | ON UPDATE_SYM delete_option
1935
1907
          {
1936
 
            LEX *lex= Lex;
1937
 
            lex->fk_update_opt= $3;
1938
 
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1908
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
 
1909
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1939
1910
          }
1940
1911
        | ON DELETE_SYM delete_option
1941
1912
          {
1942
 
            LEX *lex= Lex;
1943
 
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1944
 
            lex->fk_delete_opt= $3;
 
1913
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1914
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1945
1915
          }
1946
1916
        | ON UPDATE_SYM delete_option
1947
1917
          ON DELETE_SYM delete_option
1948
1918
          {
1949
 
            LEX *lex= Lex;
1950
 
            lex->fk_update_opt= $3;
1951
 
            lex->fk_delete_opt= $6;
 
1919
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
 
1920
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
1952
1921
          }
1953
1922
        | ON DELETE_SYM delete_option
1954
1923
          ON UPDATE_SYM delete_option
1955
1924
          {
1956
 
            LEX *lex= Lex;
1957
 
            lex->fk_update_opt= $6;
1958
 
            lex->fk_delete_opt= $3;
 
1925
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
 
1926
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1959
1927
          }
1960
1928
        ;
1961
1929
 
1999
1967
 
2000
1968
init_key_options:
2001
1969
          {
2002
 
            Lex->key_create_info= default_key_create_info;
 
1970
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
2003
1971
          }
2004
1972
        ;
2005
1973
 
2025
1993
        ;
2026
1994
 
2027
1995
key_using_alg:
2028
 
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
2029
 
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
 
1996
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
1997
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2030
1998
        ;
2031
1999
 
2032
2000
key_opt:
2033
2001
          key_using_alg
2034
2002
        | KEY_BLOCK_SIZE opt_equal ulong_num
2035
 
          { Lex->key_create_info.block_size= $3; }
 
2003
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
2036
2004
        | COMMENT_SYM TEXT_STRING_sys
2037
 
          { Lex->key_create_info.comment= $2; }
 
2005
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
2038
2006
        ;
2039
2007
 
2040
2008
btree_or_rtree:
2086
2054
            lex->name.str= 0;
2087
2055
            lex->name.length= 0;
2088
2056
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2057
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
 
2058
            lex->statement= statement;
 
2059
            if (lex->statement == NULL)
 
2060
              DRIZZLE_YYABORT;
2089
2061
            lex->duplicates= DUP_ERROR; 
2090
2062
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2091
2063
                                                   TL_OPTION_UPDATING))
2092
2064
              DRIZZLE_YYABORT;
2093
 
            lex->alter_info.reset();
2094
2065
            lex->col_list.empty();
2095
2066
            lex->select_lex.init_order();
2096
2067
            lex->select_lex.db=
2097
2068
              ((TableList*) lex->select_lex.table_list.first)->db;
2098
 
            memset(&lex->create_info, 0, sizeof(lex->create_info));
2099
 
            lex->create_info.db_type= 0;
2100
 
            lex->create_info.default_table_charset= NULL;
2101
 
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
2102
 
            lex->alter_info.reset();
2103
 
            lex->alter_info.build_method= $2;
 
2069
            statement->create_info.db_type= 0;
 
2070
            statement->create_info.default_table_charset= NULL;
 
2071
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
 
2072
            statement->alter_info.build_method= $2;
2104
2073
          }
2105
2074
          alter_commands
2106
2075
          {}
2107
2076
        | ALTER DATABASE ident_or_empty
2108
 
          {
2109
 
            Lex->create_info.default_table_charset= NULL;
2110
 
            Lex->create_info.used_fields= 0;
2111
 
          }
2112
 
          create_database_options
2113
 
          {
 
2077
          { 
2114
2078
            LEX *lex=Lex;
2115
2079
            lex->sql_command=SQLCOM_ALTER_DB;
 
2080
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
 
2081
            if (lex->statement == NULL)
 
2082
              DRIZZLE_YYABORT;
 
2083
          }
 
2084
          default_collation_schema
 
2085
          {
 
2086
            LEX *lex=Lex;
2116
2087
            lex->name= $3;
2117
2088
            if (lex->name.str == NULL &&
2118
2089
                lex->copy_db_to(&lex->name.str, &lex->name.length))
2127
2098
 
2128
2099
alter_commands:
2129
2100
          /* empty */
2130
 
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
2131
 
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
 
2101
        | DISCARD TABLESPACE 
 
2102
          { 
 
2103
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2104
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE; 
 
2105
          }
 
2106
        | IMPORT TABLESPACE 
 
2107
          { 
 
2108
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2109
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE; 
 
2110
          }
2132
2111
        | alter_list
2133
2112
        ;
2134
2113
 
2155
2134
add_column:
2156
2135
          ADD opt_column
2157
2136
          {
2158
 
            LEX *lex=Lex;
2159
 
            lex->change=0;
2160
 
            lex->alter_info.flags|= ALTER_ADD_COLUMN;
 
2137
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2138
 
 
2139
            statement->change=0;
 
2140
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2161
2141
          }
2162
2142
        ;
2163
2143
 
2165
2145
          add_column column_def opt_place { }
2166
2146
        | ADD key_def
2167
2147
          {
2168
 
            Lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2148
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2149
 
 
2150
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2169
2151
          }
2170
2152
        | add_column '(' field_list ')'
2171
2153
          {
2172
 
            Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX;
 
2154
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2155
 
 
2156
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2157
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
2173
2158
          }
2174
2159
        | CHANGE opt_column field_ident
2175
2160
          {
2176
 
            LEX *lex=Lex;
2177
 
            lex->change= $3.str;
2178
 
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2161
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2162
            statement->change= $3.str;
 
2163
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2179
2164
          }
2180
2165
          field_spec opt_place
2181
2166
        | MODIFY_SYM opt_column field_ident
2182
2167
          {
2183
2168
            LEX *lex=Lex;
 
2169
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2184
2170
            lex->length=lex->dec=0; lex->type=0;
2185
 
            lex->default_value= lex->on_update_value= 0;
2186
 
            lex->comment=null_lex_str;
 
2171
            statement->default_value= statement->on_update_value= 0;
 
2172
            statement->comment= null_lex_str;
2187
2173
            lex->charset= NULL;
2188
 
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
2189
 
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
2174
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2175
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2190
2176
          }
2191
2177
          field_def
2192
2178
          {
2193
2179
            LEX *lex=Lex;
 
2180
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2181
 
2194
2182
            if (add_field_to_list(lex->session,&$3,
2195
2183
                                  (enum enum_field_types) $5,
2196
 
                                  lex->length,lex->dec,lex->type,
2197
 
                                  lex->column_format,
2198
 
                                  lex->default_value, lex->on_update_value,
2199
 
                                  &lex->comment,
 
2184
                                  lex->length, lex->dec, lex->type,
 
2185
                                  statement->column_format,
 
2186
                                  statement->default_value, 
 
2187
                                  statement->on_update_value,
 
2188
                                  &statement->comment,
2200
2189
                                  $3.str, &lex->interval_list, lex->charset))
2201
2190
              DRIZZLE_YYABORT;
2202
2191
          }
2203
2192
          opt_place
2204
2193
        | DROP opt_column field_ident
2205
2194
          {
2206
 
            LEX *lex=Lex;
2207
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
2208
 
                                                               $3.str));
2209
 
            lex->alter_info.flags|= ALTER_DROP_COLUMN;
 
2195
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2196
 
 
2197
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN, $3.str));
 
2198
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
2210
2199
          }
2211
2200
        | DROP FOREIGN KEY_SYM opt_ident
2212
2201
          {
2213
 
            Lex->alter_info.flags|= ALTER_DROP_INDEX | ALTER_FOREIGN_KEY;
 
2202
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2203
 
 
2204
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2205
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
2214
2206
          }
2215
2207
        | DROP PRIMARY_SYM KEY_SYM
2216
2208
          {
2217
 
            LEX *lex=Lex;
2218
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
2209
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2210
 
 
2211
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
2219
2212
                                                               "PRIMARY"));
2220
 
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2213
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2221
2214
          }
2222
2215
        | DROP key_or_index field_ident
2223
2216
          {
2224
 
            LEX *lex=Lex;
2225
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2226
 
                                                               $3.str));
2227
 
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2217
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2218
 
 
2219
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2220
                                                                    $3.str));
 
2221
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2228
2222
          }
2229
2223
        | DISABLE_SYM KEYS
2230
2224
          {
2231
 
            LEX *lex=Lex;
2232
 
            lex->alter_info.keys_onoff= DISABLE;
2233
 
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2225
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2226
 
 
2227
            statement->alter_info.keys_onoff= DISABLE;
 
2228
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2234
2229
          }
2235
2230
        | ENABLE_SYM KEYS
2236
2231
          {
2237
 
            LEX *lex=Lex;
2238
 
            lex->alter_info.keys_onoff= ENABLE;
2239
 
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2232
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2233
 
 
2234
            statement->alter_info.keys_onoff= ENABLE;
 
2235
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
2240
2236
          }
2241
2237
        | ALTER opt_column field_ident SET DEFAULT signed_literal
2242
2238
          {
2243
 
            LEX *lex=Lex;
2244
 
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
2245
 
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2239
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2240
 
 
2241
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
 
2242
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2246
2243
          }
2247
2244
        | ALTER opt_column field_ident DROP DEFAULT
2248
2245
          {
2249
 
            LEX *lex=Lex;
2250
 
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
2251
 
                                                                  (Item*) 0));
2252
 
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2246
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2247
 
 
2248
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str, (Item*) 0));
 
2249
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2253
2250
          }
2254
2251
        | RENAME opt_to table_ident
2255
2252
          {
2256
2253
            LEX *lex=Lex;
 
2254
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2257
2255
            size_t dummy;
 
2256
 
2258
2257
            lex->select_lex.db=$3->db.str;
2259
2258
            if (lex->select_lex.db == NULL &&
2260
2259
                lex->copy_db_to(&lex->select_lex.db, &dummy))
2267
2266
              DRIZZLE_YYABORT;
2268
2267
            }
2269
2268
            lex->name= $3->table;
2270
 
            lex->alter_info.flags|= ALTER_RENAME;
 
2269
            statement->alter_info.flags.set(ALTER_RENAME);
2271
2270
          }
2272
2271
        | CONVERT_SYM TO_SYM collation_name_or_default
2273
2272
          {
2274
 
            LEX *lex= Lex;
2275
 
            lex->create_info.table_charset=
2276
 
            lex->create_info.default_table_charset= $3;
2277
 
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
 
2273
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2274
 
 
2275
            statement->create_info.table_charset=
 
2276
            statement->create_info.default_table_charset= $3;
 
2277
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2278
2278
              HA_CREATE_USED_DEFAULT_CHARSET);
2279
 
            lex->alter_info.flags|= ALTER_CONVERT;
 
2279
            statement->alter_info.flags.set(ALTER_CONVERT);
2280
2280
          }
2281
2281
        | create_table_options_space_separated
2282
2282
          {
2283
 
            LEX *lex=Lex;
2284
 
            lex->alter_info.flags|= ALTER_OPTIONS;
 
2283
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2284
 
 
2285
            statement->alter_info.flags.set(ALTER_OPTIONS);
2285
2286
          }
2286
2287
        | FORCE_SYM
2287
2288
          {
2288
 
            Lex->alter_info.flags|= ALTER_FORCE;
 
2289
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2290
 
 
2291
            statement->alter_info.flags.set(ALTER_FORCE);
2289
2292
          }
2290
2293
        | alter_order_clause
2291
2294
          {
2292
 
            LEX *lex=Lex;
2293
 
            lex->alter_info.flags|= ALTER_ORDER;
 
2295
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2296
 
 
2297
            statement->alter_info.flags.set(ALTER_ORDER);
2294
2298
          }
2295
2299
        ;
2296
2300
 
2308
2312
          /* empty */ {}
2309
2313
        | AFTER_SYM ident
2310
2314
          {
 
2315
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2316
 
2311
2317
            store_position_for_column($2.str);
2312
 
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2318
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
2313
2319
          }
2314
2320
        | FIRST_SYM
2315
2321
          {
 
2322
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
2323
 
2316
2324
            store_position_for_column(first_keyword);
2317
 
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2325
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
2318
2326
          }
2319
2327
        ;
2320
2328
 
2330
2338
          {
2331
2339
            LEX *lex= Lex;
2332
2340
            lex->sql_command= SQLCOM_BEGIN;
 
2341
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
2342
            if (lex->statement == NULL)
 
2343
              DRIZZLE_YYABORT;
2333
2344
            lex->start_transaction_opt= $3;
2334
2345
          }
2335
2346
        ;
2348
2359
          {
2349
2360
            LEX *lex=Lex;
2350
2361
            lex->sql_command = SQLCOM_CHECKSUM;
 
2362
            lex->statement= new(std::nothrow) statement::Checksum(YYSession);
 
2363
            if (lex->statement == NULL)
 
2364
              DRIZZLE_YYABORT;
2351
2365
          }
2352
2366
          table_list opt_checksum_type
2353
2367
          {}
2354
2368
        ;
2355
2369
 
2356
2370
opt_checksum_type:
2357
 
          /* nothing */ { Lex->check_opt.flags= 0; }
2358
 
        | QUICK         { Lex->check_opt.flags= T_QUICK; }
2359
 
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
2360
 
        ;
2361
 
 
2362
 
repair:
2363
 
          REPAIR table_or_tables
2364
 
          {
2365
 
            LEX *lex=Lex;
2366
 
            lex->sql_command = SQLCOM_REPAIR;
2367
 
            lex->check_opt.init();
2368
 
          }
2369
 
          table_list opt_mi_repair_type
2370
 
          {}
2371
 
        ;
2372
 
 
2373
 
opt_mi_repair_type:
2374
 
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
2375
 
        | mi_repair_types {}
2376
 
        ;
2377
 
 
2378
 
mi_repair_types:
2379
 
          mi_repair_type {}
2380
 
        | mi_repair_type mi_repair_types {}
2381
 
        ;
2382
 
 
2383
 
mi_repair_type:
2384
 
          QUICK        { Lex->check_opt.flags|= T_QUICK; }
2385
 
        | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
2386
 
        | USE_FRM      { Lex->check_opt.use_frm= true; }
2387
 
        ;
 
2371
          /* nothing */ { ((statement::Checksum *)Lex->statement)->check_opt.flags= 0; }
 
2372
        | QUICK         { ((statement::Checksum *)Lex->statement)->check_opt.flags= T_QUICK; }
 
2373
        | EXTENDED_SYM  { ((statement::Checksum *)Lex->statement)->check_opt.flags= T_EXTEND; }
 
2374
        ;
 
2375
 
2388
2376
 
2389
2377
analyze:
2390
2378
          ANALYZE_SYM table_or_tables
2391
2379
          {
2392
2380
            LEX *lex=Lex;
2393
2381
            lex->sql_command = SQLCOM_ANALYZE;
2394
 
            lex->check_opt.init();
 
2382
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
 
2383
            if (lex->statement == NULL)
 
2384
              DRIZZLE_YYABORT;
2395
2385
          }
2396
2386
          table_list
2397
2387
          {}
2403
2393
            LEX *lex=Lex;
2404
2394
 
2405
2395
            lex->sql_command = SQLCOM_CHECK;
2406
 
            lex->check_opt.init();
 
2396
            lex->statement= new(std::nothrow) statement::Check(YYSession);
 
2397
            if (lex->statement == NULL)
 
2398
              DRIZZLE_YYABORT;
2407
2399
          }
2408
2400
          table_list opt_mi_check_type
2409
2401
          {}
2410
2402
        ;
2411
2403
 
2412
2404
opt_mi_check_type:
2413
 
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2405
          /* empty */ { ((statement::Check *)Lex->statement)->check_opt.flags = T_MEDIUM; }
2414
2406
        | mi_check_types {}
2415
2407
        ;
2416
2408
 
2420
2412
        ;
2421
2413
 
2422
2414
mi_check_type:
2423
 
          QUICK               { Lex->check_opt.flags|= T_QUICK; }
2424
 
        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
2425
 
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
2426
 
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
2427
 
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
 
2415
          QUICK               { ((statement::Check *)Lex->statement)->check_opt.flags|= T_QUICK; }
 
2416
        | FAST_SYM            { ((statement::Check *)Lex->statement)->check_opt.flags|= T_FAST; }
 
2417
        | MEDIUM_SYM          { ((statement::Check *)Lex->statement)->check_opt.flags|= T_MEDIUM; }
 
2418
        | EXTENDED_SYM        { ((statement::Check *)Lex->statement)->check_opt.flags|= T_EXTEND; }
 
2419
        | CHANGED             { ((statement::Check *)Lex->statement)->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
2428
2420
        ;
2429
2421
 
2430
2422
optimize:
2432
2424
          {
2433
2425
            LEX *lex=Lex;
2434
2426
            lex->sql_command = SQLCOM_OPTIMIZE;
2435
 
            lex->check_opt.init();
 
2427
            statement::Optimize *statement= new(std::nothrow) statement::Optimize(YYSession);
 
2428
            lex->statement= statement;
 
2429
            if (lex->statement == NULL)
 
2430
              DRIZZLE_YYABORT;
2436
2431
          }
2437
2432
          table_list
2438
2433
          {}
2442
2437
          RENAME table_or_tables
2443
2438
          {
2444
2439
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
2440
            Lex->statement= new(std::nothrow) statement::RenameTable(YYSession);
 
2441
            if (Lex->statement == NULL)
 
2442
              DRIZZLE_YYABORT;
2445
2443
          }
2446
2444
          table_to_table_list
2447
2445
          {}
2465
2463
          }
2466
2464
        ;
2467
2465
 
2468
 
keycache:
2469
 
          CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
2470
 
          {
2471
 
            LEX *lex=Lex;
2472
 
            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
2473
 
            lex->ident= $5;
2474
 
          }
2475
 
        ;
2476
 
 
2477
 
keycache_list:
2478
 
          assign_to_keycache
2479
 
        | keycache_list ',' assign_to_keycache
2480
 
        ;
2481
 
 
2482
 
assign_to_keycache:
2483
 
          table_ident cache_keys_spec
2484
 
          {
2485
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
2486
 
                                           Select->pop_index_hints()))
2487
 
              DRIZZLE_YYABORT;
2488
 
          }
2489
 
        ;
2490
 
 
2491
 
key_cache_name:
2492
 
          ident    { $$= $1; }
2493
 
        | DEFAULT  { $$ = default_key_cache_base; }
2494
 
        ;
2495
 
 
2496
 
cache_keys_spec:
2497
 
          {
2498
 
            Lex->select_lex.alloc_index_hints(YYSession);
2499
 
            Select->set_index_hint_type(INDEX_HINT_USE, INDEX_HINT_MASK_ALL);
2500
 
          }
2501
 
          cache_key_list_or_empty
2502
 
        ;
2503
 
 
2504
 
cache_key_list_or_empty:
2505
 
          /* empty */ { }
2506
 
        | key_or_index '(' opt_key_usage_list ')'
2507
 
        ;
2508
 
 
2509
2466
/*
2510
2467
  Select : retrieve data from table
2511
2468
*/
2516
2473
          {
2517
2474
            LEX *lex= Lex;
2518
2475
            lex->sql_command= SQLCOM_SELECT;
 
2476
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2477
            if (lex->statement == NULL)
 
2478
              DRIZZLE_YYABORT;
2519
2479
          }
2520
2480
        ;
2521
2481
 
2574
2534
          }
2575
2535
          select_options select_item_list
2576
2536
          {
2577
 
            Select->parsing_place= NO_MATTER;
 
2537
            Lex->current_select->parsing_place= NO_MATTER;
2578
2538
          }
2579
2539
          select_into select_lock_type
2580
2540
        ;
2591
2551
          FROM join_table_list where_clause group_clause having_clause
2592
2552
          opt_order_clause opt_limit_clause
2593
2553
          {
2594
 
            Select->context.table_list=
2595
 
              Select->context.first_name_resolution_table= 
2596
 
                (TableList *) Select->table_list.first;
 
2554
            Lex->current_select->context.table_list=
 
2555
              Lex->current_select->context.first_name_resolution_table= 
 
2556
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
2597
2557
          }
2598
2558
        ;
2599
2559
 
2601
2561
          /* empty*/
2602
2562
        | select_option_list
2603
2563
          {
2604
 
            if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
 
2564
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2565
                Lex->current_select->options & SELECT_ALL)
2605
2566
            {
2606
2567
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2607
2568
              DRIZZLE_YYABORT;
2615
2576
        ;
2616
2577
 
2617
2578
select_option:
2618
 
          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
2619
 
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
2620
 
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
2621
 
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
 
2579
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2580
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2581
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2582
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2622
2583
        | SQL_BUFFER_RESULT
2623
2584
          {
2624
2585
            if (check_simple_select())
2625
2586
              DRIZZLE_YYABORT;
2626
 
            Select->options|= OPTION_BUFFER_RESULT;
 
2587
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2627
2588
          }
2628
2589
        | SQL_CALC_FOUND_ROWS
2629
2590
          {
2630
2591
            if (check_simple_select())
2631
2592
              DRIZZLE_YYABORT;
2632
 
            Select->options|= OPTION_FOUND_ROWS;
 
2593
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2633
2594
          }
2634
 
        | ALL { Select->options|= SELECT_ALL; }
 
2595
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2635
2596
        ;
2636
2597
 
2637
2598
select_lock_type:
3172
3133
  a dedicated rule is needed here.
3173
3134
*/
3174
3135
function_call_conflict:
3175
 
          ASCII_SYM '(' expr ')'
3176
 
          { $$= new (YYSession->mem_root) Item_func_ascii($3); }
3177
 
        | COALESCE '(' expr_list ')'
 
3136
        COALESCE '(' expr_list ')'
3178
3137
          { $$= new (YYSession->mem_root) Item_func_coalesce(* $3); }
3179
3138
        | COLLATION_SYM '(' expr ')'
3180
3139
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3224
3183
function_call_generic:
3225
3184
          IDENT_sys '('
3226
3185
          {
3227
 
            Function_builder *udf= 0;
3228
 
            udf= find_udf($1.str, $1.length);
 
3186
            const plugin::Function *udf= plugin::Function::get($1.str, $1.length);
3229
3187
 
3230
 
            /* Temporary placing the result of find_udf in $3 */
 
3188
            /* Temporary placing the result of getFunction in $3 */
3231
3189
            $<udf>$= udf;
3232
3190
          }
3233
3191
          opt_udf_expr_list ')'
3252
3210
            }
3253
3211
            else
3254
3212
            {
3255
 
              /* Retrieving the result of find_udf */
3256
 
              Function_builder *udf= $<udf>3;
 
3213
              /* Retrieving the result of service::Function::get */
 
3214
              const plugin::Function *udf= $<udf>3;
3257
3215
              if (udf)
3258
3216
              {
3259
3217
                item= Create_udf_func::s_singleton.create(session, udf, $4);
3318
3276
        | COUNT_SYM '(' in_sum_expr ')'
3319
3277
          { $$=new Item_sum_count($3); }
3320
3278
        | COUNT_SYM '(' DISTINCT
3321
 
          { Select->in_sum_expr++; }
 
3279
          { Lex->current_select->in_sum_expr++; }
3322
3280
          expr_list
3323
 
          { Select->in_sum_expr--; }
 
3281
          { Lex->current_select->in_sum_expr--; }
3324
3282
          ')'
3325
3283
          { $$=new Item_sum_count_distinct(* $5); }
3326
3284
        | MIN_SYM '(' in_sum_expr ')'
3349
3307
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3350
3308
          { $$=new Item_sum_sum_distinct($4); }
3351
3309
        | GROUP_CONCAT_SYM '(' opt_distinct
3352
 
          { Select->in_sum_expr++; }
 
3310
          { Lex->current_select->in_sum_expr++; }
3353
3311
          expr_list opt_gorder_clause
3354
3312
          opt_gconcat_separator
3355
3313
          ')'
3356
3314
          {
3357
 
            Select_Lex *sel= Select;
 
3315
            Select_Lex *sel= Lex->current_select;
3358
3316
            sel->in_sum_expr--;
3359
3317
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3360
3318
                                          sel->gorder_list, $7);
3409
3367
opt_gorder_clause:
3410
3368
          /* empty */
3411
3369
          {
3412
 
            Select->gorder_list = NULL;
 
3370
            Lex->current_select->gorder_list = NULL;
3413
3371
          }
3414
3372
        | order_clause
3415
3373
          {
3416
 
            Select_Lex *select= Select;
 
3374
            Select_Lex *select= Lex->current_select;
3417
3375
            select->gorder_list=
3418
3376
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3419
3377
                                     sizeof(st_sql_list));
3433
3391
          }
3434
3392
          expr
3435
3393
          {
3436
 
            Select->in_sum_expr--;
 
3394
            Lex->current_select->in_sum_expr--;
3437
3395
            $$= $3;
3438
3396
          }
3439
3397
        ;
3552
3510
            /* Change the current name resolution context to a local context. */
3553
3511
            if (push_new_name_resolution_context(YYSession, $1, $3))
3554
3512
              DRIZZLE_YYABORT;
3555
 
            Select->parsing_place= IN_ON;
 
3513
            Lex->current_select->parsing_place= IN_ON;
3556
3514
          }
3557
3515
          expr
3558
3516
          {
3559
3517
            add_join_on($3,$6);
3560
3518
            Lex->pop_context();
3561
 
            Select->parsing_place= NO_MATTER;
 
3519
            Lex->current_select->parsing_place= NO_MATTER;
3562
3520
          }
3563
3521
        | table_ref STRAIGHT_JOIN table_factor
3564
3522
          ON
3567
3525
            /* Change the current name resolution context to a local context. */
3568
3526
            if (push_new_name_resolution_context(YYSession, $1, $3))
3569
3527
              DRIZZLE_YYABORT;
3570
 
            Select->parsing_place= IN_ON;
 
3528
            Lex->current_select->parsing_place= IN_ON;
3571
3529
          }
3572
3530
          expr
3573
3531
          {
3574
3532
            $3->straight=1;
3575
3533
            add_join_on($3,$6);
3576
3534
            Lex->pop_context();
3577
 
            Select->parsing_place= NO_MATTER;
 
3535
            Lex->current_select->parsing_place= NO_MATTER;
3578
3536
          }
3579
3537
        | table_ref normal_join table_ref
3580
3538
          USING
3582
3540
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3583
3541
          }
3584
3542
          '(' using_list ')'
3585
 
          { add_join_natural($1,$3,$7,Select); $$=$3; }
 
3543
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
3586
3544
        | table_ref NATURAL JOIN_SYM table_factor
3587
3545
          {
3588
3546
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
3589
 
            add_join_natural($1,$4,NULL,Select);
 
3547
            add_join_natural($1,$4,NULL,Lex->current_select);
3590
3548
          }
3591
3549
 
3592
3550
          /* LEFT JOIN variants */
3597
3555
            /* Change the current name resolution context to a local context. */
3598
3556
            if (push_new_name_resolution_context(YYSession, $1, $5))
3599
3557
              DRIZZLE_YYABORT;
3600
 
            Select->parsing_place= IN_ON;
 
3558
            Lex->current_select->parsing_place= IN_ON;
3601
3559
          }
3602
3560
          expr
3603
3561
          {
3605
3563
            Lex->pop_context();
3606
3564
            $5->outer_join|=JOIN_TYPE_LEFT;
3607
3565
            $$=$5;
3608
 
            Select->parsing_place= NO_MATTER;
 
3566
            Lex->current_select->parsing_place= NO_MATTER;
3609
3567
          }
3610
3568
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3611
3569
          {
3613
3571
          }
3614
3572
          USING '(' using_list ')'
3615
3573
          { 
3616
 
            add_join_natural($1,$5,$9,Select); 
 
3574
            add_join_natural($1,$5,$9,Lex->current_select); 
3617
3575
            $5->outer_join|=JOIN_TYPE_LEFT; 
3618
3576
            $$=$5; 
3619
3577
          }
3620
3578
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3621
3579
          {
3622
3580
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3623
 
            add_join_natural($1,$6,NULL,Select);
 
3581
            add_join_natural($1,$6,NULL,Lex->current_select);
3624
3582
            $6->outer_join|=JOIN_TYPE_LEFT;
3625
3583
            $$=$6;
3626
3584
          }
3633
3591
            /* Change the current name resolution context to a local context. */
3634
3592
            if (push_new_name_resolution_context(YYSession, $1, $5))
3635
3593
              DRIZZLE_YYABORT;
3636
 
            Select->parsing_place= IN_ON;
 
3594
            Lex->current_select->parsing_place= IN_ON;
3637
3595
          }
3638
3596
          expr
3639
3597
          {
3642
3600
              DRIZZLE_YYABORT;
3643
3601
            add_join_on($$, $8);
3644
3602
            Lex->pop_context();
3645
 
            Select->parsing_place= NO_MATTER;
 
3603
            Lex->current_select->parsing_place= NO_MATTER;
3646
3604
          }
3647
3605
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3648
3606
          {
3653
3611
            LEX *lex= Lex;
3654
3612
            if (!($$= lex->current_select->convert_right_join()))
3655
3613
              DRIZZLE_YYABORT;
3656
 
            add_join_natural($$,$5,$9,Select);
 
3614
            add_join_natural($$,$5,$9,Lex->current_select);
3657
3615
          }
3658
3616
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3659
3617
          {
3660
3618
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3661
 
            add_join_natural($6,$1,NULL,Select);
 
3619
            add_join_natural($6,$1,NULL,Lex->current_select);
3662
3620
            LEX *lex= Lex;
3663
3621
            if (!($$= lex->current_select->convert_right_join()))
3664
3622
              DRIZZLE_YYABORT;
3681
3639
/* Warning - may return NULL in case of incomplete SELECT */
3682
3640
table_factor:
3683
3641
          {
3684
 
            Select_Lex *sel= Select;
 
3642
            Select_Lex *sel= Lex->current_select;
3685
3643
            sel->table_join_options= 0;
3686
3644
          }
3687
3645
          table_ident opt_table_alias opt_key_definition
3688
3646
          {
3689
 
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
3690
 
                                                Select->get_table_join_options(),
3691
 
                                                Lex->lock_option,
3692
 
                                                Select->pop_index_hints())))
 
3647
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
 
3648
                             Lex->current_select->get_table_join_options(),
 
3649
                             Lex->lock_option,
 
3650
                             Lex->current_select->pop_index_hints())))
3693
3651
              DRIZZLE_YYABORT;
3694
 
            Select->add_joined_table($$);
 
3652
            Lex->current_select->add_joined_table($$);
3695
3653
          }
3696
3654
        | select_derived_init get_select_lex select_derived2
3697
3655
          {
3825
3783
          }
3826
3784
          select_options select_item_list
3827
3785
          {
3828
 
            Select->parsing_place= NO_MATTER;
 
3786
            Lex->current_select->parsing_place= NO_MATTER;
3829
3787
          }
3830
3788
          opt_select_from select_lock_type
3831
3789
        ;
3872
3830
          }
3873
3831
          select_options select_item_list
3874
3832
          {
3875
 
            Select->parsing_place= NO_MATTER;
 
3833
            Lex->current_select->parsing_place= NO_MATTER;
3876
3834
          }
3877
3835
          opt_select_from
3878
3836
        ;
3879
3837
 
3880
3838
get_select_lex:
3881
 
          /* Empty */ { $$= Select; }
 
3839
          /* Empty */ { $$= Lex->current_select; }
3882
3840
        ;
3883
3841
 
3884
3842
select_derived_init:
3894
3852
              my_parse_error(ER(ER_SYNTAX_ERROR));
3895
3853
              DRIZZLE_YYABORT;
3896
3854
            }
3897
 
            embedding= Select->embedding;
 
3855
            embedding= Lex->current_select->embedding;
3898
3856
            $$= embedding &&
3899
3857
                !embedding->nested_join->join_list.elements;
3900
3858
            /* return true if we are deeply nested */
3924
3882
index_hint_definition:
3925
3883
          index_hint_type key_or_index index_hint_clause
3926
3884
          {
3927
 
            Select->set_index_hint_type($1, $3);
 
3885
            Lex->current_select->set_index_hint_type($1, $3);
3928
3886
          }
3929
3887
          '(' key_usage_list ')'
3930
3888
        | USE_SYM key_or_index index_hint_clause
3931
3889
          {
3932
 
            Select->set_index_hint_type(INDEX_HINT_USE, $3);
 
3890
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
3933
3891
          }
3934
3892
          '(' opt_key_usage_list ')'
3935
3893
       ;
3941
3899
 
3942
3900
opt_index_hints_list:
3943
3901
          /* empty */
3944
 
        | { Select->alloc_index_hints(YYSession); } index_hints_list
 
3902
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
3945
3903
        ;
3946
3904
 
3947
3905
opt_key_definition:
3948
 
          {  Select->clear_index_hints(); }
 
3906
          {  Lex->current_select->clear_index_hints(); }
3949
3907
          opt_index_hints_list
3950
3908
        ;
3951
3909
 
3952
3910
opt_key_usage_list:
3953
 
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
 
3911
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
3954
3912
        | key_usage_list {}
3955
3913
        ;
3956
3914
 
3957
3915
key_usage_element:
3958
3916
          ident
3959
 
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
 
3917
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
3960
3918
        | PRIMARY_SYM
3961
 
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
 
3919
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
3962
3920
        ;
3963
3921
 
3964
3922
key_usage_list:
4048
4006
        ;
4049
4007
 
4050
4008
where_clause:
4051
 
          /* empty */  { Select->where= 0; }
 
4009
          /* empty */  { Lex->current_select->where= 0; }
4052
4010
        | WHERE
4053
4011
          {
4054
 
            Select->parsing_place= IN_WHERE;
 
4012
            Lex->current_select->parsing_place= IN_WHERE;
4055
4013
          }
4056
4014
          expr
4057
4015
          {
4058
 
            Select_Lex *select= Select;
 
4016
            Select_Lex *select= Lex->current_select;
4059
4017
            select->where= $3;
4060
4018
            select->parsing_place= NO_MATTER;
4061
4019
            if ($3)
4067
4025
          /* empty */
4068
4026
        | HAVING
4069
4027
          {
4070
 
            Select->parsing_place= IN_HAVING;
 
4028
            Lex->current_select->parsing_place= IN_HAVING;
4071
4029
          }
4072
4030
          expr
4073
4031
          {
4074
 
            Select_Lex *sel= Select;
 
4032
            Select_Lex *sel= Lex->current_select;
4075
4033
            sel->having= $3;
4076
4034
            sel->parsing_place= NO_MATTER;
4077
4035
            if ($3)
4233
4191
limit_options:
4234
4192
          limit_option
4235
4193
          {
4236
 
            Select_Lex *sel= Select;
 
4194
            Select_Lex *sel= Lex->current_select;
4237
4195
            sel->select_limit= $1;
4238
4196
            sel->offset_limit= 0;
4239
4197
            sel->explicit_limit= 1;
4240
4198
          }
4241
4199
        | limit_option ',' limit_option
4242
4200
          {
4243
 
            Select_Lex *sel= Select;
 
4201
            Select_Lex *sel= Lex->current_select;
4244
4202
            sel->select_limit= $3;
4245
4203
            sel->offset_limit= $1;
4246
4204
            sel->explicit_limit= 1;
4247
4205
          }
4248
4206
        | limit_option OFFSET_SYM limit_option
4249
4207
          {
4250
 
            Select_Lex *sel= Select;
 
4208
            Select_Lex *sel= Lex->current_select;
4251
4209
            sel->select_limit= $1;
4252
4210
            sel->offset_limit= $3;
4253
4211
            sel->explicit_limit= 1;
4268
4226
          }
4269
4227
        | LIMIT limit_option
4270
4228
          {
4271
 
            Select_Lex *sel= Select;
 
4229
            Select_Lex *sel= Lex->current_select;
4272
4230
            sel->select_limit= $2;
4273
4231
            sel->explicit_limit= 1;
4274
4232
          }
4309
4267
        | FLOAT_NUM
4310
4268
        ;
4311
4269
 
4312
 
choice:
4313
 
        ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
4314
 
        | DEFAULT { $$= HA_CHOICE_UNDEF; }
4315
 
        ;
4316
 
 
4317
4270
select_var_list_init:
4318
4271
          {
4319
4272
            LEX *lex=Lex;
4383
4336
          {
4384
4337
            LEX *lex=Lex;
4385
4338
            lex->sql_command = SQLCOM_DROP_TABLE;
4386
 
            lex->drop_temporary= $2;
4387
 
            lex->drop_if_exists= $4;
 
4339
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
 
4340
            lex->statement= statement;
 
4341
            if (lex->statement == NULL)
 
4342
              DRIZZLE_YYABORT;
 
4343
            statement->drop_temporary= $2;
 
4344
            statement->drop_if_exists= $4;
4388
4345
          }
4389
4346
        | DROP build_method INDEX_SYM ident ON table_ident {}
4390
4347
          {
4391
4348
            LEX *lex=Lex;
4392
4349
            lex->sql_command= SQLCOM_DROP_INDEX;
4393
 
            lex->alter_info.reset();
4394
 
            lex->alter_info.flags= ALTER_DROP_INDEX;
4395
 
            lex->alter_info.build_method= $2;
4396
 
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
4397
 
                                                               $4.str));
 
4350
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
 
4351
            lex->statement= statement;
 
4352
            if (lex->statement == NULL)
 
4353
              DRIZZLE_YYABORT;
 
4354
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
4355
            statement->alter_info.build_method= $2;
 
4356
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
4398
4357
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4399
4358
                                                        TL_OPTION_UPDATING))
4400
4359
              DRIZZLE_YYABORT;
4403
4362
          {
4404
4363
            LEX *lex=Lex;
4405
4364
            lex->sql_command= SQLCOM_DROP_DB;
4406
 
            lex->drop_if_exists=$3;
 
4365
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
 
4366
            lex->statement= statement;
 
4367
            if (lex->statement == NULL)
 
4368
              DRIZZLE_YYABORT;
 
4369
            statement->drop_if_exists=$3;
4407
4370
            lex->name= $4;
4408
4371
          }
4409
4372
table_list:
4414
4377
table_name:
4415
4378
          table_ident
4416
4379
          {
4417
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4418
 
              DRIZZLE_YYABORT;
4419
 
          }
4420
 
        ;
4421
 
 
4422
 
table_alias_ref_list:
4423
 
          table_alias_ref
4424
 
        | table_alias_ref_list ',' table_alias_ref
4425
 
        ;
4426
 
 
4427
 
table_alias_ref:
4428
 
          table_ident
4429
 
          {
4430
 
            if (!Select->add_table_to_list(YYSession, $1, NULL,
4431
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4432
 
                                           Lex->lock_option ))
 
4380
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4433
4381
              DRIZZLE_YYABORT;
4434
4382
          }
4435
4383
        ;
4452
4400
          {
4453
4401
            LEX *lex= Lex;
4454
4402
            lex->sql_command= SQLCOM_INSERT;
 
4403
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
 
4404
            if (lex->statement == NULL)
 
4405
              DRIZZLE_YYABORT;
4455
4406
            lex->duplicates= DUP_ERROR; 
4456
4407
            mysql_init_select(lex);
4457
4408
            /* for subselects */
4459
4410
          }
4460
4411
          opt_ignore insert2
4461
4412
          {
4462
 
            Select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
 
4413
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4463
4414
            Lex->current_select= &Lex->select_lex;
4464
4415
          }
4465
4416
          insert_field_spec opt_insert_update
4469
4420
replace:
4470
4421
          REPLACE
4471
4422
          {
4472
 
            LEX *lex=Lex;
4473
 
            lex->sql_command = SQLCOM_REPLACE;
 
4423
            LEX *lex= Lex;
 
4424
            lex->sql_command= SQLCOM_REPLACE;
 
4425
            lex->statement= new(std::nothrow) statement::Replace(YYSession);
 
4426
            if (lex->statement == NULL)
 
4427
              DRIZZLE_YYABORT;
4474
4428
            lex->duplicates= DUP_REPLACE;
4475
4429
            mysql_init_select(lex);
4476
4430
          }
4477
4431
          insert2
4478
4432
          {
4479
 
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4433
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4480
4434
            Lex->current_select= &Lex->select_lex;
4481
4435
          }
4482
4436
          insert_field_spec
4520
4474
          VALUES values_list {}
4521
4475
        | VALUE_SYM values_list {}
4522
4476
        | create_select
4523
 
          { Select->set_braces(0);}
 
4477
          { Lex->current_select->set_braces(0);}
4524
4478
          union_clause {}
4525
4479
        | '(' create_select ')'
4526
 
          { Select->set_braces(1);}
 
4480
          { Lex->current_select->set_braces(1);}
4527
4481
          union_opt {}
4528
4482
        ;
4529
4483
 
4603
4557
/* Update rows in a table */
4604
4558
 
4605
4559
update:
4606
 
          UPDATE_SYM
 
4560
          UPDATE_SYM opt_ignore table_ident
4607
4561
          {
4608
4562
            LEX *lex= Lex;
4609
4563
            mysql_init_select(lex);
4610
4564
            lex->sql_command= SQLCOM_UPDATE;
 
4565
            lex->statement= new(std::nothrow) statement::Update(YYSession);
 
4566
            if (lex->statement == NULL)
 
4567
              DRIZZLE_YYABORT;
4611
4568
            lex->lock_option= TL_UNLOCK; /* Will be set later */
4612
4569
            lex->duplicates= DUP_ERROR; 
 
4570
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
 
4571
              DRIZZLE_YYABORT;
4613
4572
          }
4614
 
          opt_ignore join_table_list
4615
4573
          SET update_list
4616
4574
          {
4617
4575
            LEX *lex= Lex;
4618
 
            if (lex->select_lex.table_list.elements > 1)
4619
 
              lex->sql_command= SQLCOM_UPDATE_MULTI;
4620
 
            else if (lex->select_lex.get_table_list()->derived)
 
4576
            if (lex->select_lex.get_table_list()->derived)
4621
4577
            {
4622
4578
              /* it is single table update and it is update of derived table */
4623
4579
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
4629
4585
              be too pessimistic. We will decrease lock level if possible in
4630
4586
              mysql_multi_update().
4631
4587
            */
4632
 
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4588
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4633
4589
          }
4634
4590
          where_clause opt_order_clause delete_limit_clause {}
4635
4591
        ;
4669
4625
          {
4670
4626
            LEX *lex= Lex;
4671
4627
            lex->sql_command= SQLCOM_DELETE;
 
4628
            lex->statement= new(std::nothrow) statement::Delete(YYSession);
 
4629
            if (lex->statement == NULL)
 
4630
              DRIZZLE_YYABORT;
4672
4631
            mysql_init_select(lex);
4673
4632
            lex->lock_option= TL_WRITE_DEFAULT;
4674
4633
            lex->ignore= 0;
4680
4639
single_multi:
4681
4640
          FROM table_ident
4682
4641
          {
4683
 
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
 
4642
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4684
4643
                                           Lex->lock_option))
4685
4644
              DRIZZLE_YYABORT;
4686
4645
          }
4687
4646
          where_clause opt_order_clause
4688
4647
          delete_limit_clause {}
4689
 
        | table_wild_list
4690
 
          { mysql_init_multi_delete(Lex); }
4691
 
          FROM join_table_list where_clause
4692
 
          {
4693
 
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
4694
 
              DRIZZLE_YYABORT;
4695
 
          }
4696
 
        | FROM table_alias_ref_list
4697
 
          { mysql_init_multi_delete(Lex); }
4698
 
          USING join_table_list where_clause
4699
 
          {
4700
 
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
4701
 
              DRIZZLE_YYABORT;
4702
 
          }
4703
 
        ;
4704
 
 
4705
 
table_wild_list:
4706
 
          table_wild_one
4707
 
        | table_wild_list ',' table_wild_one
4708
 
        ;
4709
 
 
4710
 
table_wild_one:
4711
 
          ident opt_wild
4712
 
          {
4713
 
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
4714
 
                                           NULL,
4715
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4716
 
                                           Lex->lock_option))
4717
 
              DRIZZLE_YYABORT;
4718
 
          }
4719
 
        | ident '.' ident opt_wild
4720
 
          {
4721
 
            if (!Select->add_table_to_list(YYSession,
4722
 
                                           new Table_ident(YYSession, $1, $3, 0),
4723
 
                                           NULL,
4724
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4725
 
                                           Lex->lock_option))
4726
 
              DRIZZLE_YYABORT;
4727
 
          }
4728
 
        ;
4729
 
 
4730
 
opt_wild:
4731
 
          /* empty */ {}
4732
 
        | '.' '*' {}
4733
4648
        ;
4734
4649
 
4735
4650
opt_delete_options:
4738
4653
        ;
4739
4654
 
4740
4655
opt_delete_option:
4741
 
          QUICK        { Select->options|= OPTION_QUICK; }
 
4656
          QUICK        { Lex->current_select->options|= OPTION_QUICK; }
4742
4657
        | IGNORE_SYM   { Lex->ignore= 1; }
4743
4658
        ;
4744
4659
 
4747
4662
          {
4748
4663
            LEX* lex= Lex;
4749
4664
            lex->sql_command= SQLCOM_TRUNCATE;
 
4665
            lex->statement= new(std::nothrow) statement::Truncate(YYSession);
 
4666
            if (lex->statement == NULL)
 
4667
              DRIZZLE_YYABORT;
4750
4668
            lex->select_lex.options= 0;
4751
4669
            lex->select_lex.init_order();
4752
4670
          }
4767
4685
            lex->lock_option= TL_READ;
4768
4686
            mysql_init_select(lex);
4769
4687
            lex->current_select->parsing_place= SELECT_LIST;
4770
 
            memset(&lex->create_info, 0, sizeof(lex->create_info));
4771
4688
          }
4772
4689
          show_param
4773
4690
          {}
4778
4695
           {
4779
4696
             LEX *lex= Lex;
4780
4697
             lex->sql_command= SQLCOM_SHOW_DATABASES;
4781
 
             if (prepare_schema_table(YYSession, lex, 0, SCH_SCHEMATA))
 
4698
             lex->statement=
 
4699
               new(std::nothrow) statement::Select(YYSession);
 
4700
             if (lex->statement == NULL)
 
4701
               DRIZZLE_YYABORT;
 
4702
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
4782
4703
               DRIZZLE_YYABORT;
4783
4704
           }
4784
4705
         | opt_full TABLES opt_db show_wild
4785
4706
           {
4786
4707
             LEX *lex= Lex;
4787
4708
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4709
             lex->statement=
 
4710
               new(std::nothrow) statement::Select(YYSession);
 
4711
             if (lex->statement == NULL)
 
4712
               DRIZZLE_YYABORT;
4788
4713
             lex->select_lex.db= $3;
4789
 
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLE_NAMES))
 
4714
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
4790
4715
               DRIZZLE_YYABORT;
4791
4716
           }
4792
4717
         | TABLE_SYM STATUS_SYM opt_db show_wild
4793
4718
           {
4794
4719
             LEX *lex= Lex;
4795
4720
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4721
             lex->statement=
 
4722
               new(std::nothrow) statement::Select(YYSession);
 
4723
             if (lex->statement == NULL)
 
4724
               DRIZZLE_YYABORT;
4796
4725
             lex->select_lex.db= $3;
4797
 
             if (prepare_schema_table(YYSession, lex, 0, SCH_TABLES))
 
4726
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
4798
4727
               DRIZZLE_YYABORT;
4799
4728
           }
4800
4729
        | OPEN_SYM TABLES opt_db show_wild
4801
4730
          {
4802
4731
            LEX *lex= Lex;
4803
4732
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
4733
            lex->statement=
 
4734
              new(std::nothrow) statement::Select(YYSession);
 
4735
            if (lex->statement == NULL)
 
4736
              DRIZZLE_YYABORT;
4804
4737
            lex->select_lex.db= $3;
4805
 
            if (prepare_schema_table(YYSession, lex, 0, SCH_OPEN_TABLES))
 
4738
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
4806
4739
              DRIZZLE_YYABORT;
4807
4740
          }
4808
 
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
 
4741
        | ENGINE_SYM ident_or_text STATUS_SYM /* This should either go... well it should go */
4809
4742
          { 
4810
 
            Lex->create_info.db_type= $2; 
4811
4743
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
 
4744
            Lex->statement= 
 
4745
              new(std::nothrow) statement::ShowEngineStatus(YYSession, $2.str);
 
4746
            if (Lex->statement == NULL)
 
4747
              DRIZZLE_YYABORT;
4812
4748
          }
4813
4749
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
4814
4750
          {
4815
4751
            LEX *lex= Lex;
4816
4752
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4753
            lex->statement=
 
4754
              new(std::nothrow) statement::Select(YYSession);
 
4755
            if (lex->statement == NULL)
 
4756
              DRIZZLE_YYABORT;
4817
4757
            if ($5)
4818
4758
              $4->change_db($5);
4819
 
            if (prepare_schema_table(YYSession, lex, $4, SCH_COLUMNS))
 
4759
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
4820
4760
              DRIZZLE_YYABORT;
4821
4761
          }
4822
4762
        | keys_or_index from_or_in table_ident opt_db where_clause
4823
4763
          {
4824
4764
            LEX *lex= Lex;
4825
4765
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
4766
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4767
            if (lex->statement == NULL)
 
4768
              DRIZZLE_YYABORT;
4826
4769
            if ($4)
4827
4770
              $3->change_db($4);
4828
 
            if (prepare_schema_table(YYSession, lex, $3, SCH_STATISTICS))
 
4771
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
4829
4772
              DRIZZLE_YYABORT;
4830
4773
          }
4831
4774
        | COUNT_SYM '(' '*' ')' WARNINGS
4832
 
          { (void) create_select_for_variable("warning_count"); }
 
4775
          { 
 
4776
            (void) create_select_for_variable("warning_count"); 
 
4777
            LEX *lex= Lex;
 
4778
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4779
            if (lex->statement == NULL)
 
4780
              DRIZZLE_YYABORT;
 
4781
          }
4833
4782
        | COUNT_SYM '(' '*' ')' ERRORS
4834
 
          { (void) create_select_for_variable("error_count"); }
 
4783
          { 
 
4784
            (void) create_select_for_variable("error_count"); 
 
4785
            LEX *lex= Lex;
 
4786
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4787
            if (lex->statement == NULL)
 
4788
              DRIZZLE_YYABORT;
 
4789
          }
4835
4790
        | WARNINGS opt_limit_clause_init
4836
 
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
 
4791
          { 
 
4792
            Lex->sql_command = SQLCOM_SHOW_WARNS;
 
4793
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
 
4794
            if (Lex->statement == NULL)
 
4795
              DRIZZLE_YYABORT;
 
4796
          }
4837
4797
        | ERRORS opt_limit_clause_init
4838
 
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
 
4798
          { 
 
4799
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
 
4800
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
 
4801
            if (Lex->statement == NULL)
 
4802
              DRIZZLE_YYABORT;
 
4803
          }
4839
4804
        | opt_var_type STATUS_SYM show_wild
4840
4805
          {
4841
4806
            LEX *lex= Lex;
4842
4807
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
4808
            lex->statement=
 
4809
              new(std::nothrow) statement::ShowStatus(YYSession,
 
4810
                                                    &LOCK_status);
 
4811
            if (lex->statement == NULL)
 
4812
              DRIZZLE_YYABORT;
4843
4813
            lex->option_type= $1;
4844
 
            if (prepare_schema_table(YYSession, lex, 0, SCH_STATUS))
 
4814
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
4845
4815
              DRIZZLE_YYABORT;
4846
4816
          }
4847
4817
        | opt_full PROCESSLIST_SYM
4848
 
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
 
4818
          { 
 
4819
            Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;
 
4820
            Lex->statement= 
 
4821
              new(std::nothrow) statement::ShowProcesslist(YYSession);
 
4822
            if (Lex->statement == NULL)
 
4823
              DRIZZLE_YYABORT;
 
4824
          }
4849
4825
        | opt_var_type  VARIABLES show_wild
4850
4826
          {
4851
4827
            LEX *lex= Lex;
4852
4828
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
4829
            lex->statement=
 
4830
              new(std::nothrow) statement::Select(YYSession);
 
4831
            if (lex->statement == NULL)
 
4832
              DRIZZLE_YYABORT;
4853
4833
            lex->option_type= $1;
4854
 
            if (prepare_schema_table(YYSession, lex, 0, SCH_VARIABLES))
 
4834
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
4855
4835
              DRIZZLE_YYABORT;
4856
4836
          }
4857
4837
        | CREATE DATABASE opt_if_not_exists ident
4858
4838
          {
4859
4839
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
4860
 
            Lex->create_info.options=$3;
 
4840
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
 
4841
            Lex->statement= statement;
 
4842
            if (Lex->statement == NULL)
 
4843
              DRIZZLE_YYABORT;
 
4844
            statement->create_info.options=$3;
4861
4845
            Lex->name= $4;
4862
4846
          }
4863
4847
        | CREATE TABLE_SYM table_ident
4864
4848
          {
4865
4849
            LEX *lex= Lex;
4866
4850
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
4851
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
 
4852
            if (lex->statement == NULL)
 
4853
              DRIZZLE_YYABORT;
4867
4854
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4868
4855
              DRIZZLE_YYABORT;
4869
4856
          }
4874
4861
        ;
4875
4862
 
4876
4863
opt_full:
4877
 
          /* empty */ { Lex->verbose=0; }
4878
 
        | FULL        { Lex->verbose=1; }
 
4864
          /* empty */ { Lex->verbose= false; }
 
4865
        | FULL        { Lex->verbose= true; }
4879
4866
        ;
4880
4867
 
4881
4868
from_or_in:
4889
4876
          {
4890
4877
            Lex->wild= new (YYSession->mem_root) String($2.str, $2.length,
4891
4878
                                                    system_charset_info);
 
4879
            if (Lex->wild == NULL)
 
4880
              DRIZZLE_YYABORT;
 
4881
          }
 
4882
        | WHERE expr
 
4883
          {
 
4884
            Lex->current_select->where= $2;
 
4885
            if ($2)
 
4886
              $2->top_level_item();
4892
4887
          }
4893
4888
        ;
4894
4889
 
4901
4896
            mysql_init_select(lex);
4902
4897
            lex->current_select->parsing_place= SELECT_LIST;
4903
4898
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4899
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4900
            if (lex->statement == NULL)
 
4901
              DRIZZLE_YYABORT;
4904
4902
            lex->select_lex.db= 0;
4905
4903
            lex->verbose= 0;
4906
 
            if (prepare_schema_table(YYSession, lex, $2, SCH_COLUMNS))
 
4904
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
4907
4905
              DRIZZLE_YYABORT;
4908
4906
          }
4909
4907
          opt_describe_column {}
4945
4943
          {
4946
4944
            LEX *lex=Lex;
4947
4945
            lex->sql_command= SQLCOM_FLUSH;
 
4946
            lex->statement= new(std::nothrow) statement::Flush(YYSession);
 
4947
            if (lex->statement == NULL)
 
4948
              DRIZZLE_YYABORT;
4948
4949
            lex->type= 0;
4949
4950
          }
4950
4951
          flush_options
4982
4983
            lex->value_list.empty();
4983
4984
            lex->value_list.push_front($3);
4984
4985
            lex->sql_command= SQLCOM_KILL;
 
4986
            lex->statement= new(std::nothrow) statement::Kill(YYSession);
 
4987
            if (lex->statement == NULL)
 
4988
              DRIZZLE_YYABORT;
4985
4989
          }
4986
4990
        ;
4987
4991
 
4998
5002
          {
4999
5003
            LEX *lex=Lex;
5000
5004
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5005
            lex->statement= new(std::nothrow) statement::ChangeSchema(YYSession);
 
5006
            if (lex->statement == NULL)
 
5007
              DRIZZLE_YYABORT;
5001
5008
            lex->select_lex.db= $2.str;
5002
5009
          }
5003
5010
        ;
5009
5016
          {
5010
5017
            Session *session= YYSession;
5011
5018
            LEX *lex= session->lex;
 
5019
 
 
5020
            lex->sql_command= SQLCOM_LOAD;
 
5021
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
 
5022
            lex->statement= statement;
 
5023
            if (lex->statement == NULL)
 
5024
              DRIZZLE_YYABORT;
 
5025
 
5012
5026
            Lex_input_stream *lip= session->m_lip;
5013
 
 
5014
 
            lex->fname_start= lip->get_ptr();
 
5027
            statement->fname_start= lip->get_ptr();
5015
5028
          }
5016
5029
          load_data_lock INFILE TEXT_STRING_filesystem
5017
5030
          {
5018
5031
            LEX *lex=Lex;
5019
 
            lex->sql_command= SQLCOM_LOAD;
5020
5032
            lex->lock_option= $4;
5021
5033
            lex->duplicates= DUP_ERROR;
5022
5034
            lex->ignore= 0;
5026
5038
          opt_duplicate INTO
5027
5039
          {
5028
5040
            Session *session= YYSession;
5029
 
            LEX *lex= session->lex;
5030
5041
            Lex_input_stream *lip= session->m_lip;
5031
 
            lex->fname_end= lip->get_ptr();
 
5042
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
5032
5043
          }
5033
5044
          TABLE_SYM table_ident
5034
5045
          {
5035
5046
            LEX *lex=Lex;
5036
 
            if (!Select->add_table_to_list(YYSession, $12, NULL, TL_OPTION_UPDATING,
5037
 
                                           lex->lock_option))
 
5047
            if (!Lex->current_select->add_table_to_list(YYSession,
 
5048
                    $12, NULL, TL_OPTION_UPDATING,
 
5049
                    lex->lock_option))
5038
5050
              DRIZZLE_YYABORT;
5039
5051
            lex->field_list.empty();
5040
5052
            lex->update_list.empty();
5271
5283
table_wild:
5272
5284
          ident '.' '*'
5273
5285
          {
5274
 
            Select_Lex *sel= Select;
 
5286
            Select_Lex *sel= Lex->current_select;
5275
5287
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
5276
5288
            sel->with_wild++;
5277
5289
          }
5278
5290
        | ident '.' ident '.' '*'
5279
5291
          {
5280
 
            Select_Lex *sel= Select;
5281
 
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
5282
 
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
5283
 
                                $3.str,"*");
 
5292
            Select_Lex *sel= Lex->current_select;
 
5293
            $$ = new Item_field(Lex->current_context(), $1.str, $3.str,"*");
5284
5294
            sel->with_wild++;
5285
5295
          }
5286
5296
        ;
5293
5303
          ident
5294
5304
          {
5295
5305
            {
5296
 
              Select_Lex *sel=Select;
 
5306
              Select_Lex *sel=Lex->current_select;
5297
5307
              $$= (sel->parsing_place != IN_HAVING ||
5298
5308
                  sel->get_in_sum_expr() > 0) ?
5299
5309
                  (Item*) new Item_field(Lex->current_context(),
5308
5318
simple_ident_nospvar:
5309
5319
          ident
5310
5320
          {
5311
 
            Select_Lex *sel=Select;
 
5321
            Select_Lex *sel=Lex->current_select;
5312
5322
            $$= (sel->parsing_place != IN_HAVING ||
5313
5323
                sel->get_in_sum_expr() > 0) ?
5314
5324
                (Item*) new Item_field(Lex->current_context(),
5368
5378
            }
5369
5379
            $$= (sel->parsing_place != IN_HAVING ||
5370
5380
                sel->get_in_sum_expr() > 0) ?
5371
 
                (Item*) new Item_field(Lex->current_context(),
5372
 
                                       (YYSession->client_capabilities &
5373
 
                                       CLIENT_NO_SCHEMA ? NULL : $1.str),
5374
 
                                       $3.str, $5.str) :
5375
 
                (Item*) new Item_ref(Lex->current_context(),
5376
 
                                     (YYSession->client_capabilities &
5377
 
                                     CLIENT_NO_SCHEMA ? NULL : $1.str),
5378
 
                                     $3.str, $5.str);
 
5381
                (Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
 
5382
                                       $5.str) :
 
5383
                (Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
 
5384
                                     $5.str);
5379
5385
          }
5380
5386
        ;
5381
5387
 
5383
5389
          ident { $$=$1;}
5384
5390
        | ident '.' ident '.' ident
5385
5391
          {
5386
 
            TableList *table= (TableList*) Select->table_list.first;
 
5392
            TableList *table=
 
5393
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5387
5394
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5388
5395
            {
5389
5396
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5399
5406
          }
5400
5407
        | ident '.' ident
5401
5408
          {
5402
 
            TableList *table= (TableList*) Select->table_list.first;
 
5409
            TableList *table=
 
5410
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5403
5411
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5404
5412
            {
5405
5413
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
5412
5420
 
5413
5421
table_ident:
5414
5422
          ident { $$=new Table_ident($1); }
5415
 
        | ident '.' ident { $$=new Table_ident(YYSession, $1,$3,0);}
 
5423
        | ident '.' ident { $$=new Table_ident($1,$3);}
5416
5424
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
5417
5425
        ;
5418
5426
 
5475
5483
/* Keyword that we allow for identifiers (except SP labels) */
5476
5484
keyword:
5477
5485
          keyword_sp            {}
5478
 
        | ASCII_SYM             {}
5479
5486
        | BEGIN_SYM             {}
5480
5487
        | BYTE_SYM              {}
5481
5488
        | CACHE_SYM             {}
5488
5495
        | DEALLOCATE_SYM        {}
5489
5496
        | END                   {}
5490
5497
        | FLUSH_SYM             {}
5491
 
        | HANDLER_SYM           {}
5492
5498
        | HOST_SYM              {}
5493
5499
        | INSTALL_SYM           {}
5494
5500
        | NO_SYM                {}
5496
5502
        | OPTIONS_SYM           {}
5497
5503
        | PORT_SYM              {}
5498
5504
        | REMOVE_SYM            {}
5499
 
        | REPAIR                {}
5500
5505
        | RESET_SYM             {}
5501
5506
        | ROLLBACK_SYM          {}
5502
5507
        | SAVEPOINT_SYM         {}
5520
5525
        | ADDDATE_SYM              {}
5521
5526
        | AFTER_SYM                {}
5522
5527
        | AGGREGATE_SYM            {}
5523
 
        | ALGORITHM_SYM            {}
5524
5528
        | ANY_SYM                  {}
5525
5529
        | AT_SYM                   {}
5526
5530
        | AUTO_INC                 {}
5527
 
        | AUTOEXTEND_SIZE_SYM      {}
5528
5531
        | AVG_ROW_LENGTH           {}
5529
5532
        | AVG_SYM                  {}
5530
5533
        | BINLOG_SYM               {}
5555
5558
        | DATETIME_SYM             {}
5556
5559
        | DATE_SYM                 {}
5557
5560
        | DAY_SYM                  {}
5558
 
        | DELAY_KEY_WRITE_SYM      {}
5559
 
        | DIRECTORY_SYM            {}
5560
5561
        | DISABLE_SYM              {}
5561
5562
        | DISCARD                  {}
5562
5563
        | DUMPFILE                 {}
5570
5571
        | EXCLUSIVE_SYM            {}
5571
5572
        | EXTENDED_SYM             {}
5572
5573
        | EXTENT_SIZE_SYM          {}
5573
 
        | FAULTS_SYM               {}
5574
5574
        | FAST_SYM                 {}
5575
5575
        | FOUND_SYM                {}
5576
5576
        | ENABLE_SYM               {}
5586
5586
        | IDENTIFIED_SYM           {}
5587
5587
        | IMPORT                   {}
5588
5588
        | INDEXES                  {}
5589
 
        | INITIAL_SIZE_SYM         {}
5590
5589
        | ISOLATION                {}
5591
5590
        | INSERT_METHOD            {}
5592
5591
        | KEY_BLOCK_SIZE           {}
5593
5592
        | LAST_SYM                 {}
5594
 
        | LEAVES                   {}
5595
5593
        | LEVEL_SYM                {}
5596
 
        | LINESTRING               {}
5597
5594
        | LIST_SYM                 {}
5598
5595
        | LOCAL_SYM                {}
5599
5596
        | LOCKS_SYM                {}
5600
 
        | LOGFILE_SYM              {}
5601
5597
        | LOGS_SYM                 {}
5602
5598
        | MAX_ROWS                 {}
5603
5599
        | MAX_SIZE_SYM             {}
5625
5621
        | ONE_SHOT_SYM             {}
5626
5622
        | ONE_SYM                  {}
5627
5623
        | ONLINE_SYM               {}
5628
 
        | PACK_KEYS_SYM            {}
5629
5624
        | PAGE_SYM                 {}
5630
 
        | PAGE_CHECKSUM_SYM        {}
5631
5625
        | PARTIAL                  {}
5632
5626
        | PHASE_SYM                {}
5633
5627
        | POINT_SYM                {}
5672
5666
        | STRING_SYM               {}
5673
5667
        | SUBDATE_SYM              {}
5674
5668
        | SUBJECT_SYM              {}
5675
 
        | SUPER_SYM                {}
5676
5669
        | SUSPEND_SYM              {}
5677
5670
        | SWAPS_SYM                {}
5678
5671
        | SWITCHES_SYM             {}
5679
5672
        | TABLES                   {}
5680
 
        | TABLE_CHECKSUM_SYM       {}
5681
5673
        | TABLESPACE               {}
5682
5674
        | TEMPORARY_SYM            {}
5683
5675
        | TEMPTABLE_SYM            {}
5695
5687
        | UNKNOWN_SYM              {}
5696
5688
        | UNTIL_SYM                {}
5697
5689
        | USER                     {}
5698
 
        | USE_FRM                  {}
5699
5690
        | VARIABLES                {}
5700
5691
        | VALUE_SYM                {}
5701
5692
        | WARNINGS                 {}
5713
5704
          {
5714
5705
            LEX *lex=Lex;
5715
5706
            lex->sql_command= SQLCOM_SET_OPTION;
 
5707
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
 
5708
            lex->statement= statement;
 
5709
            if (lex->statement == NULL)
 
5710
              DRIZZLE_YYABORT;
5716
5711
            mysql_init_select(lex);
5717
5712
            lex->option_type=OPT_SESSION;
5718
5713
            lex->var_list.empty();
5719
 
            lex->one_shot_set= 0;
5720
5714
          }
5721
5715
          option_value_list
5722
5716
          {}
5749
5743
 
5750
5744
option_type2:
5751
5745
          /* empty */ { $$= OPT_DEFAULT; }
5752
 
        | ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
 
5746
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
5753
5747
        ;
5754
5748
 
5755
5749
opt_var_type:
5822
5816
              $$.base_name= null_lex_str;
5823
5817
            }
5824
5818
          }
5825
 
        | ident '.' ident
5826
 
          {
5827
 
            if (check_reserved_words(&$1))
5828
 
            {
5829
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
5830
 
              DRIZZLE_YYABORT;
5831
 
            }
5832
 
            {
5833
 
              sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
5834
 
              if (!tmp)
5835
 
                DRIZZLE_YYABORT;
5836
 
              if (!tmp->is_struct())
5837
 
                my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
5838
 
              $$.var= tmp;
5839
 
              $$.base_name= $1;
5840
 
            }
5841
 
          }
5842
 
        | DEFAULT '.' ident
5843
 
          {
5844
 
            sys_var *tmp=find_sys_var(YYSession, $3.str, $3.length);
5845
 
            if (!tmp)
5846
 
              DRIZZLE_YYABORT;
5847
 
            if (!tmp->is_struct())
5848
 
              my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
5849
 
            $$.var= tmp;
5850
 
            $$.base_name.str=    (char*) "default";
5851
 
            $$.base_name.length= 7;
5852
 
          }
5853
5819
        ;
5854
5820
 
5855
5821
isolation_types:
5867
5833
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
5868
5834
        ;
5869
5835
 
5870
 
/* Lock function */
5871
 
 
5872
 
lock:
5873
 
          LOCK_SYM
5874
 
          {
5875
 
            /*
5876
 
              Transactional locks can be taken only if all requested locks
5877
 
              are transactional. Initialize lex->lock_transactional as
5878
 
              TRUE. Any non-transactional lock request turns this to FALSE.
5879
 
              Table specific variables keep track of the locking method
5880
 
              requested for the table. This is used to warn about a
5881
 
              changed locking method later.
5882
 
            */
5883
 
            Lex->lock_transactional= true;
5884
 
          }
5885
 
          table_or_tables
5886
 
          {
5887
 
            LEX *lex= Lex;
5888
 
            lex->sql_command= SQLCOM_LOCK_TABLES;
5889
 
          }
5890
 
          table_lock_list
5891
 
          {}
5892
 
        ;
5893
 
 
5894
5836
table_or_tables:
5895
5837
          TABLE_SYM
5896
5838
        | TABLES
5897
5839
        ;
5898
5840
 
5899
 
table_lock_list:
5900
 
          table_lock
5901
 
        | table_lock_list ',' table_lock
5902
 
        ;
5903
 
 
5904
 
table_lock:
5905
 
        table_ident opt_table_alias table_lock_info
5906
 
        {
5907
 
          TableList *tlist;
5908
 
          if (!(tlist= Select->add_table_to_list(YYSession, $1, $2, 0,
5909
 
                                                 $3.lock_type)))
5910
 
            DRIZZLE_YYABORT; /* purecov: inspected */
5911
 
          tlist->lock_timeout= $3.lock_timeout;
5912
 
          /* Store the requested lock method for later warning. */
5913
 
          tlist->lock_transactional= $3.lock_transactional;
5914
 
          /* Compute the resulting lock method for all tables. */
5915
 
          if (!$3.lock_transactional)
5916
 
            Lex->lock_transactional= false;
5917
 
        }
5918
 
        ;
5919
 
 
5920
 
table_lock_info:
5921
 
        READ_SYM
5922
 
        {
5923
 
          $$.lock_type=          TL_READ_NO_INSERT;
5924
 
          $$.lock_timeout=       -1;
5925
 
          $$.lock_transactional= false;
5926
 
        }
5927
 
        | WRITE_SYM
5928
 
        {
5929
 
          $$.lock_type=          TL_WRITE_DEFAULT;
5930
 
          $$.lock_timeout=       -1;
5931
 
          $$.lock_transactional= false;
5932
 
        }
5933
 
        | READ_SYM LOCAL_SYM
5934
 
        {
5935
 
          $$.lock_type=          TL_READ;
5936
 
          $$.lock_timeout=       -1;
5937
 
          $$.lock_transactional= false;
5938
 
        }
5939
 
        ;
5940
 
 
5941
 
/*
5942
 
  We have a timeout resolution of milliseconds. The WAIT argument is in
5943
 
  seconds with decimal fragments for sub-second resolution. E.g. 22.5, 0.015
5944
 
*/
5945
 
/* opt_lock_timeout_value: */
5946
 
        /* empty { $$= -1; } */
5947
 
        /* | NUM       { $$= (int) (atof($1.str) * 1000.0 + 0.5); } */
5948
 
 
5949
5841
unlock:
5950
5842
          UNLOCK_SYM
5951
5843
          {
5952
5844
            LEX *lex= Lex;
5953
5845
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
5846
            lex->statement= new(std::nothrow) statement::UnlockTables(YYSession);
 
5847
            if (lex->statement == NULL)
 
5848
              DRIZZLE_YYABORT;
5954
5849
          }
5955
5850
          table_or_tables
5956
5851
          {}
5961
5856
          {
5962
5857
            LEX *lex=Lex;
5963
5858
            lex->sql_command = SQLCOM_BEGIN;
5964
 
            lex->start_transaction_opt= 0;
 
5859
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
 
5860
            if (lex->statement == NULL)
 
5861
              DRIZZLE_YYABORT;
5965
5862
          }
5966
5863
          opt_work {}
5967
5864
        ;
5995
5892
          {
5996
5893
            LEX *lex=Lex;
5997
5894
            lex->sql_command= SQLCOM_COMMIT;
5998
 
            lex->tx_chain= $3; 
5999
 
            lex->tx_release= $4;
 
5895
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
 
5896
            lex->statement= statement;
 
5897
            if (lex->statement == NULL)
 
5898
              DRIZZLE_YYABORT;
 
5899
            statement->tx_chain= $3; 
 
5900
            statement->tx_release= $4;
6000
5901
          }
6001
5902
        ;
6002
5903
 
6005
5906
          {
6006
5907
            LEX *lex=Lex;
6007
5908
            lex->sql_command= SQLCOM_ROLLBACK;
6008
 
            lex->tx_chain= $3; 
6009
 
            lex->tx_release= $4;
 
5909
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
 
5910
            lex->statement= statement;
 
5911
            if (lex->statement == NULL)
 
5912
              DRIZZLE_YYABORT;
 
5913
            statement->tx_chain= $3; 
 
5914
            statement->tx_release= $4;
6010
5915
          }
6011
5916
        | ROLLBACK_SYM opt_work
6012
5917
          TO_SYM opt_savepoint ident
6013
5918
          {
6014
5919
            LEX *lex=Lex;
6015
5920
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
5921
            lex->statement= new(std::nothrow) statement::RollbackToSavepoint(YYSession);
 
5922
            if (lex->statement == NULL)
 
5923
              DRIZZLE_YYABORT;
6016
5924
            lex->ident= $5;
6017
5925
          }
6018
5926
        ;
6022
5930
          {
6023
5931
            LEX *lex=Lex;
6024
5932
            lex->sql_command= SQLCOM_SAVEPOINT;
 
5933
            lex->statement= new(std::nothrow) statement::Savepoint(YYSession);
 
5934
            if (lex->statement == NULL)
 
5935
              DRIZZLE_YYABORT;
6025
5936
            lex->ident= $2;
6026
5937
          }
6027
5938
        ;
6031
5942
          {
6032
5943
            LEX *lex=Lex;
6033
5944
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
5945
            lex->statement= new(std::nothrow) statement::ReleaseSavepoint(YYSession);
 
5946
            if (lex->statement == NULL)
 
5947
              DRIZZLE_YYABORT;
6034
5948
            lex->ident= $3;
6035
5949
          }
6036
5950
        ;