~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
38
#define Lex (YYSession->lex)
39
 
 
40
 
#include "config.h"
41
 
#include "drizzled/parser.h"
 
39
#include <drizzled/server_includes.h>
 
40
#include <drizzled/lex_symbol.h>
 
41
#include <drizzled/function/locate.h>
 
42
#include <drizzled/function/str/char.h>
 
43
#include <drizzled/function/str/collation.h>
 
44
#include <drizzled/function/str/database.h>
 
45
#include <drizzled/function/str/insert.h>
 
46
#include <drizzled/function/str/left.h>
 
47
#include <drizzled/function/str/repeat.h>
 
48
#include <drizzled/function/str/replace.h>
 
49
#include <drizzled/function/str/reverse.h>
 
50
#include <drizzled/function/str/right.h>
 
51
#include <drizzled/function/str/set_collation.h>
 
52
#include <drizzled/function/str/substr.h>
 
53
#include <drizzled/function/str/trim.h>
 
54
#include <drizzled/function/str/user.h>
 
55
#include <drizzled/function/str/weight_string.h>
 
56
 
 
57
#include <drizzled/function/time/curdate.h>
 
58
#include <drizzled/function/time/date_add_interval.h>
 
59
#include <drizzled/function/time/dayofmonth.h>
 
60
#include <drizzled/function/time/extract.h>
 
61
#include <drizzled/function/time/hour.h>
 
62
#include <drizzled/function/time/microsecond.h>
 
63
#include <drizzled/function/time/minute.h>
 
64
#include <drizzled/function/time/month.h>
 
65
#include <drizzled/function/time/now.h>
 
66
#include <drizzled/function/time/quarter.h>
 
67
#include <drizzled/function/time/second.h>
 
68
#include <drizzled/function/time/sysdate_local.h>
 
69
#include <drizzled/function/time/timestamp_diff.h>
 
70
#include <drizzled/function/time/typecast.h>
 
71
#include <drizzled/function/time/year.h>
 
72
 
 
73
#include <drizzled/error.h>
 
74
#include <drizzled/nested_join.h>
 
75
#include <drizzled/sql_parse.h>
 
76
#include <drizzled/item/copy_string.h>
 
77
#include <drizzled/item/cmpfunc.h>
 
78
#include <drizzled/item/uint.h>
 
79
#include <drizzled/item/null.h>
 
80
#include <drizzled/session.h>
 
81
#include <drizzled/item/func.h>
 
82
#include <drizzled/sql_base.h>
 
83
#include <drizzled/item/create.h>
 
84
#include <drizzled/item/default_value.h>
 
85
#include <drizzled/item/insert_value.h>
 
86
#include <drizzled/lex_string.h>
 
87
#include <drizzled/function/get_system_var.h>
 
88
#include <mysys/thr_lock.h>
 
89
#include <drizzled/message/table.pb.h>
 
90
#include <drizzled/statement.h>
 
91
#include <drizzled/statement/alter_schema.h>
 
92
#include <drizzled/statement/alter_table.h>
 
93
#include <drizzled/statement/analyze.h>
 
94
#include <drizzled/statement/change_schema.h>
 
95
#include <drizzled/statement/check.h>
 
96
#include <drizzled/statement/checksum.h>
 
97
#include <drizzled/statement/commit.h>
 
98
#include <drizzled/statement/create_index.h>
 
99
#include <drizzled/statement/create_schema.h>
 
100
#include <drizzled/statement/create_table.h>
 
101
#include <drizzled/statement/delete.h>
 
102
#include <drizzled/statement/drop_index.h>
 
103
#include <drizzled/statement/drop_schema.h>
 
104
#include <drizzled/statement/drop_table.h>
 
105
#include <drizzled/statement/empty_query.h>
 
106
#include <drizzled/statement/flush.h>
 
107
#include <drizzled/statement/insert.h>
 
108
#include <drizzled/statement/insert_select.h>
 
109
#include <drizzled/statement/kill.h>
 
110
#include <drizzled/statement/load.h>
 
111
#include <drizzled/statement/optimize.h>
 
112
#include <drizzled/statement/release_savepoint.h>
 
113
#include <drizzled/statement/rename_table.h>
 
114
#include <drizzled/statement/replace.h>
 
115
#include <drizzled/statement/replace_select.h>
 
116
#include <drizzled/statement/rollback.h>
 
117
#include <drizzled/statement/rollback_to_savepoint.h>
 
118
#include <drizzled/statement/savepoint.h>
 
119
#include <drizzled/statement/select.h>
 
120
#include <drizzled/statement/set_option.h>
 
121
#include <drizzled/statement/show_create.h>
 
122
#include <drizzled/statement/show_create_schema.h>
 
123
#include <drizzled/statement/show_engine_status.h>
 
124
#include <drizzled/statement/show_errors.h>
 
125
#include <drizzled/statement/show_processlist.h>
 
126
#include <drizzled/statement/show_status.h>
 
127
#include <drizzled/statement/show_warnings.h>
 
128
#include <drizzled/statement/start_transaction.h>
 
129
#include <drizzled/statement/truncate.h>
 
130
#include <drizzled/statement/unlock_tables.h>
 
131
#include <drizzled/statement/update.h>
 
132
 
 
133
using namespace drizzled;
 
134
 
 
135
class Table_ident;
 
136
class Item;
 
137
class Item_num;
42
138
 
43
139
int yylex(void *yylval, void *yysession);
44
140
 
45
141
#define yyoverflow(A,B,C,D,E,F)               \
46
142
  {                                           \
47
143
    ulong val= *(F);                          \
48
 
    if (drizzled::my_yyoverflow((B), (D), &val)) \
 
144
    if (my_yyoverflow((B), (D), &val))        \
49
145
    {                                         \
50
146
      yyerror((char*) (A));                   \
51
147
      return 2;                               \
73
169
 
74
170
#define YYDEBUG 0
75
171
 
76
 
namespace drizzled
77
 
{
78
 
 
79
 
class Table_ident;
80
 
class Item;
81
 
class Item_num;
82
 
 
83
 
 
84
 
static bool check_reserved_words(LEX_STRING *name)
85
 
{
86
 
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
87
 
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
88
 
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
89
 
    return true;
90
 
  return false;
91
 
}
92
 
 
93
172
/**
94
173
  @brief Push an error message into MySQL error stack with line
95
174
  and position information.
127
206
  The parser will abort immediately after invoking this callback.
128
207
 
129
208
  This function is not for use in semantic actions and is internal to
130
 
  the parser, as it performs some pre-return cleanup.
 
209
  the parser, as it performs some pre-return cleanup. 
131
210
  In semantic actions, please use my_parse_error or my_error to
132
211
  push an error into the error stack and DRIZZLE_YYABORT
133
212
  to abort from the parser.
271
350
   @return false if successful, true if an error was reported. In the latter
272
351
   case parsing should stop.
273
352
 */
274
 
static bool setup_select_in_parentheses(LEX *lex)
 
353
static bool setup_select_in_parentheses(LEX *lex) 
275
354
{
276
355
  Select_Lex * sel= lex->current_select;
277
356
  if (sel->set_braces(1))
301
380
  return false;
302
381
}
303
382
 
304
 
static Item* reserved_keyword_function(const std::string &name, List<Item> *item_list)
305
 
{
306
 
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
307
 
  Item *item= NULL;
308
 
 
309
 
  if (udf)
310
 
  {
311
 
    item= Create_udf_func::s_singleton.create(current_session, udf, item_list);
312
 
  } else {
313
 
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
314
 
  }
315
 
 
316
 
  return item;
317
 
}
318
 
 
319
 
} /* namespace drizzled; */
320
 
 
321
 
using namespace drizzled;
322
383
%}
323
384
%union {
324
385
  int  num;
325
386
  ulong ulong_num;
326
387
  uint64_t ulonglong_number;
327
388
  int64_t longlong_number;
328
 
  drizzled::LEX_STRING lex_str;
329
 
  drizzled::LEX_STRING *lex_str_ptr;
330
 
  drizzled::LEX_SYMBOL symbol;
331
 
  drizzled::Table_ident *table;
 
389
  LEX_STRING lex_str;
 
390
  LEX_STRING *lex_str_ptr;
 
391
  LEX_SYMBOL symbol;
 
392
  Table_ident *table;
332
393
  char *simple_string;
333
 
  drizzled::Item *item;
334
 
  drizzled::Item_num *item_num;
335
 
  drizzled::List<drizzled::Item> *item_list;
336
 
  drizzled::List<drizzled::String> *string_list;
337
 
  drizzled::String *string;
338
 
  drizzled::Key_part_spec *key_part;
339
 
  const drizzled::plugin::Function *udf;
340
 
  drizzled::TableList *table_list;
341
 
  struct drizzled::sys_var_with_base variable;
342
 
  enum drizzled::sql_var_t var_type;
343
 
  drizzled::Key::Keytype key_type;
344
 
  enum drizzled::ha_key_alg key_alg;
345
 
  enum drizzled::row_type row_type;
346
 
  enum drizzled::column_format_type column_format_type;
347
 
  enum drizzled::ha_rkey_function ha_rkey_mode;
348
 
  enum drizzled::enum_tx_isolation tx_isolation;
349
 
  enum drizzled::Cast_target cast_type;
350
 
  const drizzled::CHARSET_INFO *charset;
351
 
  drizzled::thr_lock_type lock_type;
352
 
  drizzled::interval_type interval, interval_time_st;
353
 
  enum drizzled::enum_drizzle_timestamp_type date_time_type;
354
 
  drizzled::Select_Lex *select_lex;
355
 
  drizzled::chooser_compare_func_creator boolfunc2creator;
356
 
  struct drizzled::st_lex *lex;
357
 
  enum drizzled::index_hint_type index_hint;
358
 
  enum drizzled::enum_filetype filetype;
359
 
  enum drizzled::ha_build_method build_method;
360
 
  enum drizzled::Foreign_key::fk_option m_fk_option;
 
394
  Item *item;
 
395
  Item_num *item_num;
 
396
  List<Item> *item_list;
 
397
  List<String> *string_list;
 
398
  String *string;
 
399
  Key_part_spec *key_part;
 
400
  const ::drizzled::plugin::Function *udf;
 
401
  TableList *table_list;
 
402
  struct sys_var_with_base variable;
 
403
  enum enum_var_type var_type;
 
404
  Key::Keytype key_type;
 
405
  enum ha_key_alg key_alg;
 
406
  StorageEngine *db_type;
 
407
  enum row_type row_type;
 
408
  enum column_format_type column_format_type;
 
409
  enum ha_rkey_function ha_rkey_mode;
 
410
  enum enum_tx_isolation tx_isolation;
 
411
  enum Cast_target cast_type;
 
412
  const CHARSET_INFO *charset;
 
413
  thr_lock_type lock_type;
 
414
  interval_type interval, interval_time_st;
 
415
  enum enum_drizzle_timestamp_type date_time_type;
 
416
  Select_Lex *select_lex;
 
417
  chooser_compare_func_creator boolfunc2creator;
 
418
  struct st_lex *lex;
 
419
  struct p_elem_val *p_elem_value;
 
420
  enum index_hint_type index_hint;
 
421
  enum enum_filetype filetype;
 
422
  enum ha_build_method build_method;
 
423
  enum Foreign_key::fk_option m_fk_option;
361
424
}
362
425
 
363
426
%{
364
 
namespace drizzled
365
 
{
366
427
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
367
 
}
368
428
%}
369
429
 
370
430
%pure_parser                                    /* We have threads */
392
452
*/
393
453
 
394
454
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
 
455
%token  ACCESSIBLE_SYM
395
456
%token  ACTION                        /* SQL-2003-N */
396
457
%token  ADD                           /* SQL-2003-R */
397
458
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
398
459
%token  AFTER_SYM                     /* SQL-2003-N */
399
460
%token  AGGREGATE_SYM
 
461
%token  ALGORITHM_SYM
400
462
%token  ALL                           /* SQL-2003-R */
401
463
%token  ALTER                         /* SQL-2003-R */
402
464
%token  ANALYZE_SYM
406
468
%token  ASC                           /* SQL-2003-N */
407
469
%token  ASENSITIVE_SYM                /* FUTURE-USE */
408
470
%token  AT_SYM                        /* SQL-2003-R */
 
471
%token  AUTOEXTEND_SIZE_SYM
409
472
%token  AUTO_INC
410
473
%token  AVG_ROW_LENGTH
411
474
%token  AVG_SYM                       /* SQL-2003-N */
414
477
%token  BETWEEN_SYM                   /* SQL-2003-R */
415
478
%token  BIGINT_SYM                    /* SQL-2003-R */
416
479
%token  BINARY                        /* SQL-2003-R */
 
480
%token  BINLOG_SYM
417
481
%token  BIN_NUM
418
482
%token  BIT_SYM                       /* MYSQL-FUNC */
419
483
%token  BLOB_SYM                      /* SQL-2003-R */
425
489
%token  BTREE_SYM
426
490
%token  BY                            /* SQL-2003-R */
427
491
%token  BYTE_SYM
 
492
%token  CACHE_SYM
428
493
%token  CALL_SYM                      /* SQL-2003-R */
429
494
%token  CASCADE                       /* SQL-2003-N */
430
495
%token  CASCADED                      /* SQL-2003-R */
432
497
%token  CAST_SYM                      /* SQL-2003-R */
433
498
%token  CHAIN_SYM                     /* SQL-2003-N */
434
499
%token  CHANGE
 
500
%token  CHANGED
 
501
%token  CHARSET
435
502
%token  CHAR_SYM                      /* SQL-2003-R */
436
503
%token  CHECKSUM_SYM
437
504
%token  CHECK_SYM                     /* SQL-2003-R */
445
512
%token  COMMITTED_SYM                 /* SQL-2003-N */
446
513
%token  COMMIT_SYM                    /* SQL-2003-R */
447
514
%token  COMPACT_SYM
 
515
%token  COMPLETION_SYM
448
516
%token  COMPRESSED_SYM
449
517
%token  CONCURRENT
450
518
%token  CONDITION_SYM                 /* SQL-2003-N */
452
520
%token  CONSISTENT_SYM
453
521
%token  CONSTRAINT                    /* SQL-2003-R */
454
522
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
523
%token  CONTEXT_SYM
455
524
%token  CONTINUE_SYM                  /* SQL-2003-R */
456
525
%token  CONVERT_SYM                   /* SQL-2003-N */
457
526
%token  COUNT_SYM                     /* SQL-2003-N */
509
578
%token  ESCAPE_SYM                    /* SQL-2003-R */
510
579
%token  EXCLUSIVE_SYM
511
580
%token  EXISTS                        /* SQL-2003-R */
 
581
%token  EXIT_SYM
512
582
%token  EXTENDED_SYM
 
583
%token  EXTENT_SIZE_SYM
513
584
%token  EXTRACT_SYM                   /* SQL-2003-N */
514
585
%token  FALSE_SYM                     /* SQL-2003-R */
 
586
%token  FAST_SYM
 
587
%token  FAULTS_SYM
515
588
%token  FETCH_SYM                     /* SQL-2003-R */
516
589
%token  COLUMN_FORMAT_SYM
517
590
%token  FILE_SYM
531
604
%token  GROUP_SYM                     /* SQL-2003-R */
532
605
%token  GROUP_CONCAT_SYM
533
606
%token  GT_SYM                        /* OPERATOR */
 
607
%token  HANDLER_SYM
534
608
%token  HASH_SYM
535
609
%token  HAVING                        /* SQL-2003-R */
536
610
%token  HEX_NUM
 
611
%token  HOST_SYM
 
612
%token  HOSTS_SYM
537
613
%token  HOUR_MICROSECOND_SYM
538
614
%token  HOUR_MINUTE_SYM
539
615
%token  HOUR_SECOND_SYM
547
623
%token  INDEXES
548
624
%token  INDEX_SYM
549
625
%token  INFILE
 
626
%token  INITIAL_SIZE_SYM
550
627
%token  INNER_SYM                     /* SQL-2003-R */
551
628
%token  INOUT_SYM                     /* SQL-2003-R */
552
629
%token  INSENSITIVE_SYM               /* SQL-2003-R */
553
630
%token  INSERT                        /* SQL-2003-R */
 
631
%token  INSERT_METHOD
 
632
%token  INSTALL_SYM
554
633
%token  INTERVAL_SYM                  /* SQL-2003-R */
555
634
%token  INTO                          /* SQL-2003-R */
556
635
%token  INT_SYM                       /* SQL-2003-R */
566
645
%token  LAST_SYM                      /* SQL-2003-N */
567
646
%token  LE                            /* OPERATOR */
568
647
%token  LEADING                       /* SQL-2003-R */
 
648
%token  LEAVES
569
649
%token  LEFT                          /* SQL-2003-R */
570
650
%token  LEVEL_SYM
571
651
%token  LEX_HOSTNAME
572
652
%token  LIKE                          /* SQL-2003-R */
573
653
%token  LIMIT
 
654
%token  LINEAR_SYM
574
655
%token  LINES
 
656
%token  LINESTRING
575
657
%token  LIST_SYM
576
658
%token  LOAD
577
659
%token  LOCAL_SYM                     /* SQL-2003-R */
578
660
%token  LOCATOR_SYM                   /* SQL-2003-N */
579
661
%token  LOCKS_SYM
580
662
%token  LOCK_SYM
 
663
%token  LOGFILE_SYM
581
664
%token  LOGS_SYM
582
665
%token  LONG_NUM
583
666
%token  LONG_SYM
591
674
%token  MEDIUM_SYM
592
675
%token  MERGE_SYM                     /* SQL-2003-R */
593
676
%token  MICROSECOND_SYM               /* MYSQL-FUNC */
 
677
%token  MIGRATE_SYM
594
678
%token  MINUTE_MICROSECOND_SYM
595
679
%token  MINUTE_SECOND_SYM
596
680
%token  MINUTE_SYM                    /* SQL-2003-R */
609
693
%token  NEG
610
694
%token  NEW_SYM                       /* SQL-2003-R */
611
695
%token  NEXT_SYM                      /* SQL-2003-N */
 
696
%token  NODEGROUP_SYM
612
697
%token  NONE_SYM                      /* SQL-2003-R */
613
698
%token  NOT_SYM                       /* SQL-2003-R */
614
699
%token  NOW_SYM
 
700
%token  NOWAIT_SYM
615
701
%token  NO_SYM                        /* SQL-2003-R */
 
702
%token  NO_WAIT_SYM
 
703
%token  NO_WRITE_TO_BINLOG
616
704
%token  NULL_SYM                      /* SQL-2003-R */
617
705
%token  NUM
618
706
%token  NUMERIC_SYM                   /* SQL-2003-R */
623
711
%token  ONE_SYM
624
712
%token  ONLINE_SYM
625
713
%token  OPEN_SYM                      /* SQL-2003-R */
626
 
%token  OPTIMIZE                      /* Leave assuming we might add it back */
 
714
%token  OPTIMIZE
 
715
%token  OPTIONS_SYM
627
716
%token  OPTION                        /* SQL-2003-N */
628
717
%token  OPTIONALLY
629
718
%token  ORDER_SYM                     /* SQL-2003-R */
632
721
%token  OUTFILE
633
722
%token  OUT_SYM                       /* SQL-2003-R */
634
723
%token  PAGE_SYM
 
724
%token  PARAM_MARKER
635
725
%token  PARTIAL                       /* SQL-2003-N */
636
726
%token  PHASE_SYM
 
727
%token  POINT_SYM
 
728
%token  PORT_SYM
637
729
%token  POSITION_SYM                  /* SQL-2003-N */
638
730
%token  PRECISION                     /* SQL-2003-R */
639
731
%token  PREV_SYM
640
732
%token  PRIMARY_SYM                   /* SQL-2003-R */
641
733
%token  PROCESS
642
734
%token  PROCESSLIST_SYM
 
735
%token  PURGE
643
736
%token  QUARTER_SYM
644
737
%token  QUERY_SYM
 
738
%token  QUICK
645
739
%token  RANGE_SYM                     /* SQL-2003-R */
646
740
%token  READS_SYM                     /* SQL-2003-R */
647
741
%token  READ_ONLY_SYM
648
742
%token  READ_SYM                      /* SQL-2003-N */
649
743
%token  READ_WRITE_SYM
650
744
%token  REAL                          /* SQL-2003-R */
 
745
%token  REBUILD_SYM
 
746
%token  RECOVER_SYM
 
747
%token  REDOFILE_SYM
 
748
%token  REDO_BUFFER_SIZE_SYM
651
749
%token  REDUNDANT_SYM
652
750
%token  REFERENCES                    /* SQL-2003-R */
653
751
%token  RELEASE_SYM                   /* SQL-2003-R */
 
752
%token  RELOAD
 
753
%token  REMOVE_SYM
654
754
%token  RENAME
 
755
%token  REORGANIZE_SYM
655
756
%token  REPEATABLE_SYM                /* SQL-2003-N */
656
757
%token  REPEAT_SYM                    /* MYSQL-FUNC */
657
758
%token  REPLACE                       /* MYSQL-FUNC */
 
759
%token  REPLICATION
 
760
%token  REQUIRE_SYM
 
761
%token  RESET_SYM
 
762
%token  RESOURCES
658
763
%token  RESTRICT
 
764
%token  RESUME_SYM
659
765
%token  RETURNS_SYM                   /* SQL-2003-R */
660
766
%token  RETURN_SYM                    /* SQL-2003-R */
661
767
%token  REVERSE_SYM
686
792
%token  SHUTDOWN
687
793
%token  SIMPLE_SYM                    /* SQL-2003-N */
688
794
%token  SNAPSHOT_SYM
 
795
%token  SOCKET_SYM
 
796
%token  SONAME_SYM
 
797
%token  SOURCE_SYM
689
798
%token  SPECIFIC_SYM                  /* SQL-2003-R */
690
799
%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
691
800
%token  SQLSTATE_SYM                  /* SQL-2003-R */
696
805
%token  SQL_SMALL_RESULT
697
806
%token  SQL_SYM                       /* SQL-2003-R */
698
807
%token  STARTING
 
808
%token  STARTS_SYM
699
809
%token  START_SYM                     /* SQL-2003-R */
700
810
%token  STATUS_SYM
701
811
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
718
828
%token  TABLE_REF_PRIORITY
719
829
%token  TABLE_SYM                     /* SQL-2003-R */
720
830
%token  TEMPORARY_SYM                 /* SQL-2003-N */
 
831
%token  TEMPTABLE_SYM
721
832
%token  TERMINATED
722
833
%token  TEXT_STRING
723
834
%token  TEXT_SYM
 
835
%token  THAN_SYM
724
836
%token  THEN_SYM                      /* SQL-2003-R */
725
837
%token  TIMESTAMP_SYM                 /* SQL-2003-R */
726
838
%token  TIMESTAMP_ADD
735
847
%token  TYPE_SYM                      /* SQL-2003-N */
736
848
%token  ULONGLONG_NUM
737
849
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
 
850
%token  UNDEFINED_SYM
738
851
%token  UNDOFILE_SYM
739
852
%token  UNDO_SYM                      /* FUTURE-USE */
740
853
%token  UNION_SYM                     /* SQL-2003-R */
741
854
%token  UNIQUE_SYM
742
855
%token  UNKNOWN_SYM                   /* SQL-2003-R */
743
856
%token  UNLOCK_SYM
 
857
%token  UNTIL_SYM
744
858
%token  UPDATE_SYM                    /* SQL-2003-R */
745
859
%token  USAGE                         /* SQL-2003-N */
746
860
%token  USER                          /* SQL-2003-R */
 
861
%token  USE_FRM
747
862
%token  USE_SYM
748
863
%token  USING                         /* SQL-2003-R */
749
864
%token  UTC_DATE_SYM
756
871
%token  VARIANCE_SYM
757
872
%token  VARYING                       /* SQL-2003-R */
758
873
%token  VAR_SAMP_SYM
 
874
%token  VIRTUAL_SYM
 
875
%token  WAIT_SYM
759
876
%token  WARNINGS
760
877
%token  WEEK_SYM
 
878
%token  WEIGHT_STRING_SYM
761
879
%token  WHEN_SYM                      /* SQL-2003-R */
762
880
%token  WHERE                         /* SQL-2003-R */
763
881
%token  WITH                          /* SQL-2003-R */
806
924
 
807
925
%type <num>
808
926
        type int_type real_type order_dir field_def
809
 
        if_exists opt_table_options
810
 
        opt_if_not_exists
 
927
        if_exists opt_table_options table_options
 
928
        table_option opt_if_not_exists
811
929
        opt_temporary all_or_any opt_distinct
812
930
        union_option
813
931
        start_transaction_opts opt_chain opt_release
817
935
        delete_option
818
936
 
819
937
%type <ulong_num>
820
 
        ulong_num
 
938
        ulong_num real_ulong_num
 
939
        ws_nweights
 
940
        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
 
941
        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
 
942
        ws_level_range ws_level_list_or_range  
821
943
 
822
944
%type <ulonglong_number>
823
945
        ulonglong_num
873
995
 
874
996
%type <interval_time_st> interval_time_stamp
875
997
 
 
998
%type <db_type> storage_engines known_storage_engines
 
999
 
876
1000
%type <row_type> row_types
877
1001
 
878
1002
%type <column_format_type> column_format_types
890
1014
%type <variable> internal_variable_name
891
1015
 
892
1016
%type <select_lex> subselect
893
 
        get_select_lex query_specification
 
1017
        get_select_lex query_specification 
894
1018
        query_expression_body
895
1019
 
896
1020
%type <boolfunc2creator> comp_op
900
1024
%type <NONE>
901
1025
        query verb_clause create select drop insert replace insert2
902
1026
        insert_values update delete truncate rename
903
 
        show describe load alter flush
 
1027
        show describe load alter optimize flush
904
1028
        begin commit rollback savepoint release
905
1029
        analyze check start checksum
906
1030
        field_list field_list_item field_spec kill column_def key_def
908
1032
        opt_limit_clause delete_limit_clause fields opt_values values
909
1033
        opt_precision opt_ignore opt_column
910
1034
        set unlock string_list
 
1035
        opt_binary
911
1036
        ref_list opt_match_clause opt_on_update_delete use
912
1037
        opt_delete_options opt_delete_option varchar
913
1038
        opt_outer table_list table_name
915
1040
        opt_attribute opt_attribute_list attribute
916
1041
        flush_options flush_option
917
1042
        equal optional_braces
918
 
        normal_join
 
1043
        opt_mi_check_type opt_to mi_check_types normal_join
919
1044
        table_to_table_list table_to_table opt_table_list opt_as
920
1045
        single_multi
921
1046
        union_clause union_list
970
1095
            else
971
1096
            {
972
1097
              session->lex->sql_command= SQLCOM_EMPTY_QUERY;
973
 
              session->lex->statement=
 
1098
              session->lex->statement= 
974
1099
                new(std::nothrow) statement::EmptyQuery(YYSession);
975
1100
              if (session->lex->statement == NULL)
976
1101
                DRIZZLE_YYABORT;
999
1124
        | insert
1000
1125
        | kill
1001
1126
        | load
 
1127
        | optimize
1002
1128
        | release
1003
1129
        | rename
1004
1130
        | replace
1022
1148
            Session *session= YYSession;
1023
1149
            LEX *lex= session->lex;
1024
1150
            lex->sql_command= SQLCOM_CREATE_TABLE;
1025
 
            statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1026
 
            lex->statement= statement;
 
1151
            lex->statement= new(std::nothrow) statement::CreateTable(YYSession);
1027
1152
            if (lex->statement == NULL)
1028
1153
              DRIZZLE_YYABORT;
1029
1154
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1030
1155
                                                   TL_OPTION_UPDATING,
1031
1156
                                                   TL_WRITE))
1032
1157
              DRIZZLE_YYABORT;
 
1158
            lex->alter_info.reset();
1033
1159
            lex->col_list.empty();
1034
 
            statement->change=NULL;
1035
 
            statement->is_if_not_exists= $4;
1036
 
            statement->create_info.db_type= NULL;
1037
 
            statement->create_info.default_table_charset= NULL;
 
1160
            lex->change=NULL;
 
1161
            memset(&lex->create_info, 0, sizeof(lex->create_info));
 
1162
            lex->create_info.options=$2 | $4;
 
1163
            lex->create_info.db_type= ha_default_storage_engine(session);
 
1164
            lex->create_info.default_table_charset= NULL;
1038
1165
            lex->name.str= 0;
1039
1166
 
1040
 
            message::Table &proto= statement->create_table_message;
1041
 
           
1042
 
            proto.set_name($5->table.str);
1043
 
            if ($2)
1044
 
              proto.set_type(message::Table::TEMPORARY);
 
1167
            message::Table *proto=
 
1168
              lex->create_table_proto= new(std::nothrow) message::Table();
 
1169
 
 
1170
            if (lex->create_table_proto == NULL)
 
1171
              DRIZZLE_YYABORT;
 
1172
            
 
1173
            proto->set_name($5->table.str);
 
1174
            if($2 & HA_LEX_CREATE_TMP_TABLE)
 
1175
              proto->set_type(message::Table::TEMPORARY);
1045
1176
            else
1046
 
              proto.set_type(message::Table::STANDARD);
 
1177
              proto->set_type(message::Table::STANDARD);
 
1178
 
 
1179
            {
 
1180
              message::Table::StorageEngine *protoengine;
 
1181
              protoengine= proto->mutable_engine();
 
1182
              StorageEngine *engine= ha_default_storage_engine(session);
 
1183
 
 
1184
              protoengine->set_name(engine->getName());
 
1185
            }
1047
1186
          }
1048
1187
          create2
1049
1188
          {
1050
1189
            LEX *lex= YYSession->lex;
1051
 
            lex->current_select= &lex->select_lex;
 
1190
            lex->current_select= &lex->select_lex; 
 
1191
            assert(lex->create_info.db_type);
1052
1192
          }
1053
 
        | CREATE build_method
 
1193
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
 
1194
          ON table_ident
1054
1195
          {
1055
1196
            LEX *lex=Lex;
1056
1197
            lex->sql_command= SQLCOM_CREATE_INDEX;
1057
 
            statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1058
 
            lex->statement= statement;
 
1198
            lex->statement= new(std::nothrow) 
 
1199
              statement::CreateIndex(YYSession);
1059
1200
            if (lex->statement == NULL)
1060
1201
              DRIZZLE_YYABORT;
1061
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1062
 
            statement->alter_info.build_method= $2;
1063
 
            lex->col_list.empty();
1064
 
            statement->change=NULL;
1065
 
          }
1066
 
          opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
1067
 
          {
1068
 
            LEX *lex=Lex;
1069
 
            statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1070
 
 
1071
 
            if (!lex->current_select->add_table_to_list(lex->session, $9,
 
1202
            if (!lex->current_select->add_table_to_list(lex->session, $8,
1072
1203
                                                        NULL,
1073
1204
                                                        TL_OPTION_UPDATING))
1074
1205
              DRIZZLE_YYABORT;
 
1206
            lex->alter_info.reset();
 
1207
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1208
            lex->alter_info.build_method= $2;
 
1209
            lex->col_list.empty();
 
1210
            lex->change=NULL;
 
1211
 
 
1212
            lex->create_table_proto= new message::Table();
 
1213
          }
 
1214
          '(' key_list ')' key_options
 
1215
          {
 
1216
            LEX *lex=Lex;
1075
1217
            Key *key;
1076
 
            key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1077
 
            statement->alter_info.key_list.push_back(key);
 
1218
            key= new Key($3, $5, &lex->key_create_info, 0,
 
1219
                         lex->col_list);
 
1220
            lex->alter_info.key_list.push_back(key);
1078
1221
            lex->col_list.empty();
1079
1222
          }
1080
1223
        | CREATE DATABASE opt_if_not_exists ident
1081
1224
          {
 
1225
            Lex->create_info.default_table_charset= NULL;
 
1226
            Lex->create_info.used_fields= 0;
 
1227
          }
 
1228
          opt_create_database_options
 
1229
          {
1082
1230
            LEX *lex=Lex;
1083
 
 
1084
1231
            lex->sql_command=SQLCOM_CREATE_DB;
1085
 
            statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1086
 
            lex->statement= statement;
 
1232
            lex->statement= new(std::nothrow) statement::CreateSchema(YYSession);
1087
1233
            if (lex->statement == NULL)
1088
1234
              DRIZZLE_YYABORT;
1089
 
            statement->is_if_not_exists= $3;
1090
 
          }
1091
 
          opt_create_database_options
1092
 
          {
1093
 
            Lex->name= $4;
 
1235
            lex->name= $4;
 
1236
            lex->create_info.options=$3;
1094
1237
          }
1095
1238
        ;
1096
1239
 
1098
1241
          '(' create2a {}
1099
1242
        | opt_create_table_options
1100
1243
          create3 {}
1101
 
        | LIKE table_ident opt_create_table_options
 
1244
        | LIKE table_ident
1102
1245
          {
1103
1246
            Session *session= YYSession;
1104
1247
            LEX *lex= session->lex;
1105
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1106
1248
 
1107
 
            statement->is_create_table_like= true;
 
1249
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1108
1250
            if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1109
1251
              DRIZZLE_YYABORT;
1110
1252
          }
1112
1254
          {
1113
1255
            Session *session= YYSession;
1114
1256
            LEX *lex= session->lex;
1115
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1116
1257
 
1117
 
            statement->is_create_table_like= true;
 
1258
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1118
1259
            if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1119
1260
              DRIZZLE_YYABORT;
1120
1261
          }
1146
1287
            if (lex->sql_command == SQLCOM_INSERT)
1147
1288
            {
1148
1289
              lex->sql_command= SQLCOM_INSERT_SELECT;
1149
 
              delete lex->statement;
1150
 
              lex->statement=
 
1290
              lex->statement= 
1151
1291
                new(std::nothrow) statement::InsertSelect(YYSession);
1152
1292
              if (lex->statement == NULL)
1153
1293
                DRIZZLE_YYABORT;
1155
1295
            else if (lex->sql_command == SQLCOM_REPLACE)
1156
1296
            {
1157
1297
              lex->sql_command= SQLCOM_REPLACE_SELECT;
1158
 
              delete lex->statement;
1159
 
              lex->statement=
 
1298
              lex->statement= 
1160
1299
                new(std::nothrow) statement::ReplaceSelect(YYSession);
1161
1300
              if (lex->statement == NULL)
1162
1301
                DRIZZLE_YYABORT;
1190
1329
 
1191
1330
opt_create_database_options:
1192
1331
          /* empty */ {}
1193
 
        | default_collation_schema {}
 
1332
        | create_database_options {}
 
1333
        ;
 
1334
 
 
1335
create_database_options:
 
1336
          create_database_option {}
 
1337
        | create_database_options create_database_option {}
 
1338
        ;
 
1339
 
 
1340
create_database_option:
 
1341
          default_collation {}
1194
1342
        ;
1195
1343
 
1196
1344
opt_table_options:
1197
 
          /* empty */ { $$= false; }
1198
 
        | TEMPORARY_SYM { $$= true; }
 
1345
          /* empty */ { $$= 0; }
 
1346
        | table_options  { $$= $1;}
 
1347
        ;
 
1348
 
 
1349
table_options:
 
1350
          table_option { $$=$1; }
 
1351
        | table_option table_options { $$= $1 | $2; }
 
1352
        ;
 
1353
 
 
1354
table_option:
 
1355
          TEMPORARY_SYM { $$=HA_LEX_CREATE_TMP_TABLE; }
1199
1356
        ;
1200
1357
 
1201
1358
opt_if_not_exists:
1202
 
          /* empty */ { $$= false; }
1203
 
        | IF not EXISTS { $$= true; }
 
1359
          /* empty */ { $$= 0; }
 
1360
        | IF not EXISTS { $$=HA_LEX_CREATE_IF_NOT_EXISTS; }
1204
1361
        ;
1205
1362
 
1206
1363
opt_create_table_options:
1220
1377
        ;
1221
1378
 
1222
1379
create_table_option:
1223
 
          ENGINE_SYM opt_equal ident_or_text
 
1380
          ENGINE_SYM opt_equal storage_engines
1224
1381
          {
1225
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1226
 
            message::Table::StorageEngine *protoengine;
1227
 
            protoengine= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine();
1228
 
 
1229
 
            statement->is_engine_set= true;
1230
 
 
1231
 
            protoengine->set_name($3.str);
 
1382
            Lex->create_info.db_type= $3;
 
1383
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1384
 
 
1385
            {
 
1386
              message::Table::StorageEngine *protoengine;
 
1387
              protoengine= Lex->create_table_proto->mutable_engine();
 
1388
 
 
1389
              protoengine->set_name($3->getName());
 
1390
            }
1232
1391
          }
1233
 
        | BLOCK_SIZE_SYM opt_equal ulong_num
1234
 
          {
1235
 
            message::Table::TableOptions *tableopts;
1236
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1237
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1238
 
 
1239
 
            tableopts->set_block_size($3);
1240
 
            statement->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
 
1392
        | BLOCK_SIZE_SYM opt_equal ulong_num    
 
1393
          { 
 
1394
            Lex->create_info.block_size= $3; 
 
1395
            Lex->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
1241
1396
          }
1242
1397
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1243
1398
          {
1244
1399
            message::Table::TableOptions *tableopts;
1245
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
 
1400
            tableopts= Lex->create_table_proto->mutable_options();
1246
1401
 
1247
1402
            tableopts->set_comment($3.str);
1248
1403
          }
1249
1404
        | AUTO_INC opt_equal ulonglong_num
1250
1405
          {
1251
 
            message::Table::TableOptions *tableopts;
1252
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1253
 
 
1254
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1255
 
 
1256
 
            statement->create_info.auto_increment_value=$3;
1257
 
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1258
 
            tableopts->set_auto_increment_value($3);
 
1406
            Lex->create_info.auto_increment_value=$3;
 
1407
            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
1259
1408
          }
1260
1409
        | ROW_FORMAT_SYM opt_equal row_types
1261
1410
          {
1262
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1263
 
            message::Table::TableOptions *table_options= statement->createTableMessage().mutable_options();
1264
 
 
1265
 
            statement->create_info.row_type= $3;
1266
 
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1267
 
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1268
 
 
1269
 
            switch(statement->create_info.row_type)
1270
 
            {
1271
 
            case ROW_TYPE_DEFAULT:
1272
 
              /* No use setting a default row type... just adds redundant info to message */
1273
 
              break;
1274
 
            case ROW_TYPE_FIXED:
1275
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_FIXED);
1276
 
              break;
1277
 
            case ROW_TYPE_DYNAMIC:
1278
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_DYNAMIC);
1279
 
              break;
1280
 
            case ROW_TYPE_COMPRESSED:
1281
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_COMPRESSED);
1282
 
              break;
1283
 
            case ROW_TYPE_REDUNDANT:
1284
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_REDUNDANT);
1285
 
              break;
1286
 
            case ROW_TYPE_COMPACT:
1287
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_COMPACT);
1288
 
              break;
1289
 
            case ROW_TYPE_PAGE:
1290
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_PAGE);
1291
 
              break;
1292
 
            default:
1293
 
              abort();
1294
 
            }
 
1411
            Lex->create_info.row_type= $3;
 
1412
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1413
            Lex->alter_info.flags.set(ALTER_ROW_FORMAT);
1295
1414
          }
1296
1415
        | default_collation
1297
1416
        | KEY_BLOCK_SIZE opt_equal ulong_num
1298
1417
          {
1299
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1300
 
 
1301
 
            statement->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1302
 
 
1303
 
            message::Table::TableOptions *tableopts;
1304
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1305
 
            tableopts->set_key_block_size($3);
 
1418
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1419
            Lex->create_info.key_block_size= $3;
1306
1420
          }
1307
1421
        ;
1308
1422
 
1309
1423
default_collation:
1310
1424
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1311
1425
          {
1312
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1313
 
 
1314
 
            HA_CREATE_INFO *cinfo= &statement->create_info;
 
1426
            HA_CREATE_INFO *cinfo= &Lex->create_info;
1315
1427
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1316
1428
                 cinfo->default_table_charset && $4 &&
1317
1429
                 !my_charset_same(cinfo->default_table_charset,$4))
1320
1432
                         $4->name, cinfo->default_table_charset->csname);
1321
1433
                DRIZZLE_YYABORT;
1322
1434
              }
1323
 
              statement->create_info.default_table_charset= $4;
1324
 
              statement->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1325
 
          }
1326
 
        ;
1327
 
 
1328
 
default_collation_schema:
1329
 
          opt_default COLLATE_SYM opt_equal collation_name_or_default
1330
 
          {
1331
 
            statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
1332
 
 
1333
 
            message::Schema &schema_message= statement->schema_message;
1334
 
            schema_message.set_collation($4->name);
 
1435
              Lex->create_info.default_table_charset= $4;
 
1436
              Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1437
          }
 
1438
        ;
 
1439
 
 
1440
storage_engines:
 
1441
          ident_or_text
 
1442
          {
 
1443
            const std::string engine_name($1.str);
 
1444
            StorageEngine *engine= ha_resolve_by_name(YYSession, engine_name);
 
1445
 
 
1446
            if (engine)
 
1447
              $$= engine;
 
1448
            else
 
1449
            {
 
1450
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1451
              DRIZZLE_YYABORT;
 
1452
            }
 
1453
          }
 
1454
        ;
 
1455
 
 
1456
known_storage_engines:
 
1457
          ident_or_text
 
1458
          {
 
1459
            const std::string engine_name($1.str);
 
1460
            StorageEngine *engine;
 
1461
            if ((engine= ha_resolve_by_name(YYSession, engine_name)))
 
1462
              $$= engine;
 
1463
            else
 
1464
            {
 
1465
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1466
              DRIZZLE_YYABORT;
 
1467
            }
1335
1468
          }
1336
1469
        ;
1337
1470
 
1369
1502
          field_spec opt_check_constraint
1370
1503
        | field_spec references
1371
1504
          {
1372
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1505
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1373
1506
          }
1374
1507
        ;
1375
1508
 
1377
1510
          key_type opt_ident key_alg '(' key_list ')' key_options
1378
1511
          {
1379
1512
            LEX *lex=Lex;
1380
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1381
 
            Key *key= new Key($1, $2, &statement->key_create_info, 0,
 
1513
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
1382
1514
                              lex->col_list);
1383
 
            statement->alter_info.key_list.push_back(key);
1384
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1515
            lex->alter_info.key_list.push_back(key);
 
1516
            lex->col_list.empty(); /* Alloced by sql_alloc */
1385
1517
          }
1386
1518
        | opt_constraint constraint_key_type opt_ident key_alg
1387
1519
          '(' key_list ')' key_options
1388
1520
          {
1389
1521
            LEX *lex=Lex;
1390
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1391
 
            Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
 
1522
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
1392
1523
                              lex->col_list);
1393
 
            statement->alter_info.key_list.push_back(key);
1394
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1524
            lex->alter_info.key_list.push_back(key);
 
1525
            lex->col_list.empty(); /* Alloced by sql_alloc */
1395
1526
          }
1396
1527
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1397
1528
          {
1398
1529
            LEX *lex=Lex;
1399
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1400
1530
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1401
1531
                                      $8,
1402
1532
                                      lex->ref_list,
1403
 
                                      statement->fk_delete_opt,
1404
 
                                      statement->fk_update_opt,
1405
 
                                      statement->fk_match_option);
1406
 
            statement->alter_info.key_list.push_back(key);
 
1533
                                      lex->fk_delete_opt,
 
1534
                                      lex->fk_update_opt,
 
1535
                                      lex->fk_match_option);
 
1536
            lex->alter_info.key_list.push_back(key);
1407
1537
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1408
1538
                         &default_key_create_info, 1,
1409
1539
                         lex->col_list);
1410
 
            statement->alter_info.key_list.push_back(key);
1411
 
            lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1540
            lex->alter_info.key_list.push_back(key);
 
1541
            lex->col_list.empty(); /* Alloced by sql_alloc */
1412
1542
            /* Only used for ALTER TABLE. Ignored otherwise. */
1413
 
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
1543
            lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
1414
1544
          }
1415
1545
        | constraint opt_check_constraint
1416
1546
          {
1417
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1547
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1418
1548
          }
1419
1549
        | opt_constraint check_constraint
1420
1550
          {
1421
 
            Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
1551
            Lex->col_list.empty(); /* Alloced by sql_alloc */
1422
1552
          }
1423
1553
        ;
1424
1554
 
1444
1574
          field_ident
1445
1575
          {
1446
1576
            LEX *lex=Lex;
1447
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1448
1577
            lex->length=lex->dec=0;
1449
1578
            lex->type=0;
1450
 
            statement->default_value= statement->on_update_value= 0;
1451
 
            statement->comment= null_lex_str;
 
1579
            lex->default_value= lex->on_update_value= 0;
 
1580
            lex->comment=null_lex_str;
1452
1581
            lex->charset=NULL;
1453
 
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1454
 
 
1455
 
            message::AlterTable &alter_proto=
1456
 
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1457
 
            statement->current_proto_field= alter_proto.add_added_field();
 
1582
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1458
1583
          }
1459
1584
          field_def
1460
1585
          {
1461
1586
            LEX *lex=Lex;
1462
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1463
 
 
1464
 
            if (statement->current_proto_field)
1465
 
              statement->current_proto_field->set_name($1.str);
1466
 
 
1467
1587
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1468
1588
                                  lex->length,lex->dec,lex->type,
1469
 
                                  statement->column_format,
1470
 
                                  statement->default_value, statement->on_update_value,
1471
 
                                  &statement->comment,
1472
 
                                  statement->change, &lex->interval_list, lex->charset))
 
1589
                                  lex->column_format,
 
1590
                                  lex->default_value, lex->on_update_value, 
 
1591
                                  &lex->comment,
 
1592
                                  lex->change,&lex->interval_list,lex->charset))
1473
1593
              DRIZZLE_YYABORT;
1474
 
 
1475
 
            statement->current_proto_field= NULL;
1476
1594
          }
1477
1595
        ;
1478
1596
field_def:
1481
1599
 
1482
1600
type:
1483
1601
        int_type
1484
 
        {
1485
 
          $$=$1;
 
1602
        { 
 
1603
          $$=$1; 
1486
1604
          Lex->length=(char*) 0; /* use default length */
1487
 
          statement::CreateTable *statement=
1488
 
            (statement::CreateTable *)Lex->statement;
1489
 
 
1490
 
          if (statement->current_proto_field)
1491
 
          {
1492
 
            if ($1 == DRIZZLE_TYPE_LONG)
1493
 
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1494
 
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
1495
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1496
 
            else
1497
 
              abort();
1498
 
          }
1499
 
          }
1500
 
        | real_type opt_precision
1501
 
          {
1502
 
            $$=$1;
1503
 
 
1504
 
            statement::CreateTable *statement=
1505
 
              (statement::CreateTable *)Lex->statement;
1506
 
 
1507
 
            if (statement->current_proto_field)
1508
 
            {
1509
 
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
1510
 
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1511
 
            }
1512
 
          }
1513
 
          | char '(' NUM ')'
1514
 
            {
1515
 
              Lex->length=$3.str;
1516
 
              $$=DRIZZLE_TYPE_VARCHAR;
1517
 
 
1518
 
            statement::CreateTable *statement=
1519
 
              (statement::CreateTable *)Lex->statement;
1520
 
 
1521
 
            if (statement->current_proto_field)
1522
 
            {
1523
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1524
 
              message::Table::Field::StringFieldOptions *string_field_options;
1525
 
 
1526
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1527
 
 
1528
 
              string_field_options->set_length(atoi($3.str));
1529
 
            }
1530
 
            }
1531
 
          | char
1532
 
            {
1533
 
              Lex->length=(char*) "1";
1534
 
              $$=DRIZZLE_TYPE_VARCHAR;
1535
 
 
1536
 
            statement::CreateTable *statement=
1537
 
              (statement::CreateTable *)Lex->statement;
1538
 
 
1539
 
            if (statement->current_proto_field)
1540
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1541
 
            }
1542
 
          | varchar '(' NUM ')'
1543
 
            {
1544
 
              Lex->length=$3.str;
1545
 
              $$= DRIZZLE_TYPE_VARCHAR;
1546
 
 
1547
 
            statement::CreateTable *statement=
1548
 
              (statement::CreateTable *)Lex->statement;
1549
 
 
1550
 
            if (statement->current_proto_field)
1551
 
            {
1552
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1553
 
 
1554
 
              message::Table::Field::StringFieldOptions *string_field_options;
1555
 
 
1556
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1557
 
 
1558
 
              string_field_options->set_length(atoi($3.str));
1559
 
            }
1560
 
            }
1561
 
          | VARBINARY '(' NUM ')'
1562
 
            {
1563
 
              Lex->length=$3.str;
1564
 
              Lex->charset=&my_charset_bin;
1565
 
              $$= DRIZZLE_TYPE_VARCHAR;
1566
 
 
1567
 
            statement::CreateTable *statement=
1568
 
              (statement::CreateTable *)Lex->statement;
1569
 
 
1570
 
            if (statement->current_proto_field)
1571
 
            {
1572
 
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1573
 
              message::Table::Field::StringFieldOptions *string_field_options;
1574
 
 
1575
 
              string_field_options= statement->current_proto_field->mutable_string_options();
1576
 
 
1577
 
              string_field_options->set_length(atoi($3.str));
1578
 
              string_field_options->set_collation_id(my_charset_bin.number);
1579
 
              string_field_options->set_collation(my_charset_bin.name);
1580
 
            }
1581
 
            }
1582
 
          | DATE_SYM
1583
 
          {
1584
 
            $$=DRIZZLE_TYPE_DATE;
1585
 
 
1586
 
            statement::CreateTable *statement=
1587
 
              (statement::CreateTable *)Lex->statement;
1588
 
 
1589
 
            if (statement->current_proto_field)
1590
 
              statement->current_proto_field->set_type(message::Table::Field::DATE);
1591
 
          }
1592
 
          | TIMESTAMP_SYM
1593
 
          {
1594
 
            $$=DRIZZLE_TYPE_TIMESTAMP;
1595
 
 
1596
 
            statement::CreateTable *statement=
1597
 
              (statement::CreateTable *)Lex->statement;
1598
 
 
1599
 
            if (statement->current_proto_field)
1600
 
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1601
 
          }
1602
 
          | DATETIME_SYM
1603
 
          {
1604
 
            $$=DRIZZLE_TYPE_DATETIME;
1605
 
 
1606
 
            statement::CreateTable *statement=
1607
 
              (statement::CreateTable *)Lex->statement;
1608
 
 
1609
 
            if (statement->current_proto_field)
1610
 
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1611
 
          }
1612
 
          | BLOB_SYM
1613
 
            {
1614
 
              Lex->charset=&my_charset_bin;
1615
 
              $$=DRIZZLE_TYPE_BLOB;
1616
 
              Lex->length=(char*) 0; /* use default length */
1617
 
 
1618
 
              statement::CreateTable *statement=
1619
 
                (statement::CreateTable *)Lex->statement;
1620
 
 
1621
 
              if (statement->current_proto_field)
1622
 
              {
1623
 
                statement->current_proto_field->set_type(message::Table::Field::BLOB);
1624
 
                message::Table::Field::StringFieldOptions *string_field_options;
1625
 
 
1626
 
                string_field_options= statement->current_proto_field->mutable_string_options();
1627
 
                string_field_options->set_collation_id(my_charset_bin.number);
1628
 
                string_field_options->set_collation(my_charset_bin.name);
1629
 
              }
1630
 
            }
1631
 
          | TEXT_SYM
1632
 
            {
1633
 
              $$=DRIZZLE_TYPE_BLOB;
1634
 
              Lex->length=(char*) 0; /* use default length */
1635
 
 
1636
 
            statement::CreateTable *statement=
1637
 
              (statement::CreateTable *)Lex->statement;
1638
 
 
1639
 
            if (statement->current_proto_field)
1640
 
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
1641
 
            }
1642
 
          | DECIMAL_SYM float_options
1643
 
          {
1644
 
            $$=DRIZZLE_TYPE_DECIMAL;
1645
 
 
1646
 
            statement::CreateTable *statement=
1647
 
              (statement::CreateTable *)Lex->statement;
1648
 
 
1649
 
            if (statement->current_proto_field)
1650
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1651
 
          }
1652
 
          | NUMERIC_SYM float_options
1653
 
          {
1654
 
            $$=DRIZZLE_TYPE_DECIMAL;
1655
 
 
1656
 
            statement::CreateTable *statement=
1657
 
              (statement::CreateTable *)Lex->statement;
1658
 
 
1659
 
            if (statement->current_proto_field)
1660
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1661
 
          }
1662
 
          | FIXED_SYM float_options
1663
 
          {
1664
 
            $$=DRIZZLE_TYPE_DECIMAL;
1665
 
 
1666
 
            statement::CreateTable *statement=
1667
 
              (statement::CreateTable *)Lex->statement;
1668
 
 
1669
 
            if (statement->current_proto_field)
1670
 
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1671
 
          }
1672
 
          | ENUM_SYM
1673
 
            {Lex->interval_list.empty();}
1674
 
            '(' string_list ')'
1675
 
          {
1676
 
            $$=DRIZZLE_TYPE_ENUM;
1677
 
 
1678
 
            statement::CreateTable *statement=
1679
 
              (statement::CreateTable *)Lex->statement;
1680
 
 
1681
 
            if (statement->current_proto_field)
1682
 
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
1683
 
          }
 
1605
        }
 
1606
        | real_type opt_precision { $$=$1; }
 
1607
        | char '(' NUM ')' opt_binary
 
1608
          {
 
1609
            Lex->length=$3.str;
 
1610
            $$=DRIZZLE_TYPE_VARCHAR;
 
1611
          }
 
1612
        | char opt_binary
 
1613
          {
 
1614
            Lex->length=(char*) "1";
 
1615
            $$=DRIZZLE_TYPE_VARCHAR;
 
1616
          }
 
1617
        | varchar '(' NUM ')' opt_binary
 
1618
          {
 
1619
            Lex->length=$3.str;
 
1620
            $$= DRIZZLE_TYPE_VARCHAR;
 
1621
          }
 
1622
        | VARBINARY '(' NUM ')'
 
1623
          {
 
1624
            Lex->length=$3.str;
 
1625
            Lex->charset=&my_charset_bin;
 
1626
            $$= DRIZZLE_TYPE_VARCHAR;
 
1627
          }
 
1628
        | DATE_SYM
 
1629
          { $$=DRIZZLE_TYPE_DATE; }
 
1630
        | TIMESTAMP_SYM
 
1631
          { $$=DRIZZLE_TYPE_TIMESTAMP; }
 
1632
        | DATETIME_SYM
 
1633
          { $$=DRIZZLE_TYPE_DATETIME; }
 
1634
        | BLOB_SYM
 
1635
          {
 
1636
            Lex->charset=&my_charset_bin;
 
1637
            $$=DRIZZLE_TYPE_BLOB;
 
1638
            Lex->length=(char*) 0; /* use default length */
 
1639
          }
 
1640
        | TEXT_SYM opt_binary
 
1641
          { 
 
1642
            $$=DRIZZLE_TYPE_BLOB; 
 
1643
            Lex->length=(char*) 0; /* use default length */
 
1644
          }
 
1645
        | DECIMAL_SYM float_options
 
1646
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1647
        | NUMERIC_SYM float_options
 
1648
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1649
        | FIXED_SYM float_options
 
1650
          { $$=DRIZZLE_TYPE_NEWDECIMAL;}
 
1651
        | ENUM_SYM
 
1652
          {Lex->interval_list.empty();}
 
1653
          '(' string_list ')' opt_binary
 
1654
          { $$=DRIZZLE_TYPE_ENUM; }
1684
1655
        | SERIAL_SYM
1685
1656
          {
1686
1657
            $$=DRIZZLE_TYPE_LONGLONG;
1687
1658
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1688
 
 
1689
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1690
 
            if (statement->current_proto_field)
1691
 
            {
1692
 
              message::Table::Field::FieldConstraints *constraints;
1693
 
              constraints= statement->current_proto_field->mutable_constraints();
1694
 
              constraints->set_is_nullable(false);
1695
 
 
1696
 
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1697
 
            }
1698
1659
          }
1699
1660
        ;
1700
1661
 
1762
1723
        ;
1763
1724
 
1764
1725
attribute:
1765
 
          NULL_SYM
1766
 
          {
1767
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1768
 
            Lex->type&= ~ NOT_NULL_FLAG;
1769
 
 
1770
 
            if (statement->current_proto_field)
1771
 
            {
1772
 
              message::Table::Field::FieldConstraints *constraints;
1773
 
              constraints= statement->current_proto_field->mutable_constraints();
1774
 
              constraints->set_is_nullable(true);
1775
 
            }
1776
 
          }
 
1726
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
1777
1727
        | COLUMN_FORMAT_SYM column_format_types
1778
1728
          {
1779
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1780
 
 
1781
 
            statement->column_format= $2;
1782
 
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1783
 
          }
1784
 
        | not NULL_SYM
1785
 
          {
1786
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1787
 
            Lex->type|= NOT_NULL_FLAG;
1788
 
 
1789
 
            if (statement->current_proto_field)
1790
 
            {
1791
 
              message::Table::Field::FieldConstraints *constraints;
1792
 
              constraints= statement->current_proto_field->mutable_constraints();
1793
 
              constraints->set_is_nullable(false);
1794
 
            }
1795
 
          }
1796
 
        | DEFAULT now_or_signed_literal
1797
 
          {
1798
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1799
 
 
1800
 
            statement->default_value=$2;
1801
 
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
1802
 
          }
1803
 
        | ON UPDATE_SYM NOW_SYM optional_braces
1804
 
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1805
 
        | AUTO_INC
1806
 
          {
1807
 
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
1808
 
 
1809
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1810
 
            if (statement->current_proto_field)
1811
 
            {
1812
 
              message::Table::Field::FieldConstraints *constraints;
1813
 
 
1814
 
              constraints= statement->current_proto_field->mutable_constraints();
1815
 
              constraints->set_is_nullable(false);
1816
 
            }
1817
 
          }
 
1729
            Lex->column_format= $2;
 
1730
            Lex->alter_info.flags.set(ALTER_COLUMN_FORMAT);
 
1731
          }
 
1732
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
 
1733
        | DEFAULT now_or_signed_literal 
 
1734
          { 
 
1735
            Lex->default_value=$2; 
 
1736
            Lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
1737
          }
 
1738
        | ON UPDATE_SYM NOW_SYM optional_braces 
 
1739
          { Lex->on_update_value= new Item_func_now_local(); }
 
1740
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1818
1741
        | SERIAL_SYM DEFAULT VALUE_SYM
1819
 
          {
 
1742
          { 
1820
1743
            LEX *lex=Lex;
1821
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1822
 
 
1823
1744
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1824
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1825
 
 
1826
 
            if (statement->current_proto_field)
1827
 
            {
1828
 
              message::Table::Field::FieldConstraints *constraints;
1829
 
              constraints= statement->current_proto_field->mutable_constraints();
1830
 
              constraints->set_is_nullable(false);
1831
 
            }
 
1745
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1832
1746
          }
1833
1747
        | opt_primary KEY_SYM
1834
1748
          {
1835
1749
            LEX *lex=Lex;
1836
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1837
 
 
1838
1750
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1839
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1840
 
 
1841
 
            if (statement->current_proto_field)
1842
 
            {
1843
 
              message::Table::Field::FieldConstraints *constraints;
1844
 
              constraints= statement->current_proto_field->mutable_constraints();
1845
 
              constraints->set_is_nullable(false);
1846
 
            }
 
1751
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1847
1752
          }
1848
1753
        | UNIQUE_SYM
1849
1754
          {
1850
1755
            LEX *lex=Lex;
1851
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1852
 
 
1853
 
            lex->type|= UNIQUE_FLAG;
1854
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1756
            lex->type|= UNIQUE_FLAG; 
 
1757
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
1855
1758
          }
1856
1759
        | UNIQUE_SYM KEY_SYM
1857
1760
          {
1858
1761
            LEX *lex=Lex;
1859
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1860
 
 
1861
 
            lex->type|= UNIQUE_KEY_FLAG;
1862
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1863
 
          }
1864
 
        | COMMENT_SYM TEXT_STRING_sys
1865
 
          {
1866
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1867
 
            statement->comment= $2;
1868
 
 
1869
 
            if (statement->current_proto_field)
1870
 
              statement->current_proto_field->set_comment($2.str);
1871
 
          }
 
1762
            lex->type|= UNIQUE_KEY_FLAG; 
 
1763
            lex->alter_info.flags.set(ALTER_ADD_INDEX);
 
1764
          }
 
1765
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
1872
1766
        | COLLATE_SYM collation_name
1873
1767
          {
1874
1768
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
1912
1806
        | DEFAULT {}
1913
1807
        ;
1914
1808
 
 
1809
opt_binary:
 
1810
          /* empty */ { Lex->charset=NULL; }
 
1811
        | BYTE_SYM { Lex->charset=&my_charset_bin; }
 
1812
        | BINARY { Lex->type|= BINCMP_FLAG; }
 
1813
        ;
 
1814
 
 
1815
ws_nweights:
 
1816
        '(' real_ulong_num
 
1817
        {
 
1818
          if ($2 == 0)
 
1819
          {
 
1820
            my_parse_error(ER(ER_SYNTAX_ERROR));
 
1821
            DRIZZLE_YYABORT;
 
1822
          }
 
1823
        }
 
1824
        ')'
 
1825
        { $$= $2; }
 
1826
        ;
 
1827
 
 
1828
ws_level_flag_desc:
 
1829
        ASC { $$= 0; }
 
1830
        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
 
1831
        ;
 
1832
 
 
1833
ws_level_flag_reverse:
 
1834
        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
 
1835
 
 
1836
ws_level_flags:
 
1837
        /* empty */ { $$= 0; }
 
1838
        | ws_level_flag_desc { $$= $1; }
 
1839
        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
 
1840
        | ws_level_flag_reverse { $$= $1 ; }
 
1841
        ;
 
1842
 
 
1843
ws_level_number:
 
1844
        real_ulong_num
 
1845
        {
 
1846
          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
 
1847
          $$--;
 
1848
        }
 
1849
        ;
 
1850
 
 
1851
ws_level_list_item:
 
1852
        ws_level_number ws_level_flags
 
1853
        {
 
1854
          $$= (1 | $2) << $1;
 
1855
        }
 
1856
        ;
 
1857
 
 
1858
ws_level_list:
 
1859
        ws_level_list_item { $$= $1; }
 
1860
        | ws_level_list ',' ws_level_list_item { $$|= $3; }
 
1861
        ;
 
1862
 
 
1863
ws_level_range:
 
1864
        ws_level_number '-' ws_level_number
 
1865
        {
 
1866
          uint32_t start= $1;
 
1867
          uint32_t end= $3;
 
1868
          for ($$= 0; start <= end; start++)
 
1869
            $$|= (1 << start);
 
1870
        }
 
1871
        ;
 
1872
 
 
1873
ws_level_list_or_range:
 
1874
        ws_level_list { $$= $1; }
 
1875
        | ws_level_range { $$= $1; }
 
1876
        ;
 
1877
 
 
1878
opt_ws_levels:
 
1879
        /* empty*/ { $$= 0; }
 
1880
        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
 
1881
        ;
 
1882
 
1915
1883
opt_primary:
1916
1884
          /* empty */
1917
1885
        | PRIMARY_SYM
1947
1915
 
1948
1916
opt_match_clause:
1949
1917
          /* empty */
1950
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
 
1918
          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
1951
1919
        | MATCH FULL
1952
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
 
1920
          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
1953
1921
        | MATCH PARTIAL
1954
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
 
1922
          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
1955
1923
        | MATCH SIMPLE_SYM
1956
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
 
1924
          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
1957
1925
        ;
1958
1926
 
1959
1927
opt_on_update_delete:
1960
1928
          /* empty */
1961
1929
          {
1962
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1963
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1930
            LEX *lex= Lex;
 
1931
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1932
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1964
1933
          }
1965
1934
        | ON UPDATE_SYM delete_option
1966
1935
          {
1967
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1968
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1936
            LEX *lex= Lex;
 
1937
            lex->fk_update_opt= $3;
 
1938
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
1969
1939
          }
1970
1940
        | ON DELETE_SYM delete_option
1971
1941
          {
1972
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1973
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
1942
            LEX *lex= Lex;
 
1943
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1944
            lex->fk_delete_opt= $3;
1974
1945
          }
1975
1946
        | ON UPDATE_SYM delete_option
1976
1947
          ON DELETE_SYM delete_option
1977
1948
          {
1978
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1979
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $6;
 
1949
            LEX *lex= Lex;
 
1950
            lex->fk_update_opt= $3;
 
1951
            lex->fk_delete_opt= $6;
1980
1952
          }
1981
1953
        | ON DELETE_SYM delete_option
1982
1954
          ON UPDATE_SYM delete_option
1983
1955
          {
1984
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $6;
1985
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
 
1956
            LEX *lex= Lex;
 
1957
            lex->fk_update_opt= $6;
 
1958
            lex->fk_delete_opt= $3;
1986
1959
          }
1987
1960
        ;
1988
1961
 
2026
1999
 
2027
2000
init_key_options:
2028
2001
          {
2029
 
            ((statement::CreateTable *)Lex->statement)->key_create_info= default_key_create_info;
 
2002
            Lex->key_create_info= default_key_create_info;
2030
2003
          }
2031
2004
        ;
2032
2005
 
2052
2025
        ;
2053
2026
 
2054
2027
key_using_alg:
2055
 
          USING btree_or_rtree     { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
2056
 
        | TYPE_SYM btree_or_rtree  { ((statement::CreateTable *)Lex->statement)->key_create_info.algorithm= $2; }
 
2028
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
 
2029
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
2057
2030
        ;
2058
2031
 
2059
2032
key_opt:
2060
2033
          key_using_alg
2061
2034
        | KEY_BLOCK_SIZE opt_equal ulong_num
2062
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.block_size= $3; }
 
2035
          { Lex->key_create_info.block_size= $3; }
2063
2036
        | COMMENT_SYM TEXT_STRING_sys
2064
 
          { ((statement::CreateTable *)Lex->statement)->key_create_info.comment= $2; }
 
2037
          { Lex->key_create_info.comment= $2; }
2065
2038
        ;
2066
2039
 
2067
2040
btree_or_rtree:
2113
2086
            lex->name.str= 0;
2114
2087
            lex->name.length= 0;
2115
2088
            lex->sql_command= SQLCOM_ALTER_TABLE;
2116
 
            statement::AlterTable *statement= new(std::nothrow) statement::AlterTable(YYSession);
2117
 
            lex->statement= statement;
 
2089
            lex->statement= new(std::nothrow) statement::AlterTable(YYSession);
2118
2090
            if (lex->statement == NULL)
2119
2091
              DRIZZLE_YYABORT;
2120
 
            lex->duplicates= DUP_ERROR;
 
2092
            lex->duplicates= DUP_ERROR; 
2121
2093
            if (!lex->select_lex.add_table_to_list(session, $5, NULL,
2122
2094
                                                   TL_OPTION_UPDATING))
2123
2095
              DRIZZLE_YYABORT;
 
2096
            lex->alter_info.reset();
2124
2097
            lex->col_list.empty();
2125
2098
            lex->select_lex.init_order();
2126
2099
            lex->select_lex.db=
2127
2100
              ((TableList*) lex->select_lex.table_list.first)->db;
2128
 
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
2129
 
            statement->alter_info.build_method= $2;
 
2101
            memset(&lex->create_info, 0, sizeof(lex->create_info));
 
2102
            lex->create_info.db_type= 0;
 
2103
            lex->create_info.default_table_charset= NULL;
 
2104
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
 
2105
            lex->alter_info.reset();
 
2106
            lex->alter_info.build_method= $2;
 
2107
 
 
2108
            lex->create_table_proto= new message::Table();
2130
2109
          }
2131
2110
          alter_commands
2132
2111
          {}
2133
2112
        | ALTER DATABASE ident_or_empty
2134
2113
          {
 
2114
            Lex->create_info.default_table_charset= NULL;
 
2115
            Lex->create_info.used_fields= 0;
 
2116
          }
 
2117
          create_database_options
 
2118
          {
2135
2119
            LEX *lex=Lex;
2136
2120
            lex->sql_command=SQLCOM_ALTER_DB;
2137
2121
            lex->statement= new(std::nothrow) statement::AlterSchema(YYSession);
2138
2122
            if (lex->statement == NULL)
2139
2123
              DRIZZLE_YYABORT;
2140
 
          }
2141
 
          default_collation_schema
2142
 
          {
2143
 
            LEX *lex=Lex;
2144
2124
            lex->name= $3;
2145
2125
            if (lex->name.str == NULL &&
2146
2126
                lex->copy_db_to(&lex->name.str, &lex->name.length))
2155
2135
 
2156
2136
alter_commands:
2157
2137
          /* empty */
2158
 
        | DISCARD TABLESPACE
2159
 
          {
2160
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2161
 
            statement->alter_info.tablespace_op= DISCARD_TABLESPACE;
2162
 
          }
2163
 
        | IMPORT TABLESPACE
2164
 
          {
2165
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2166
 
            statement->alter_info.tablespace_op= IMPORT_TABLESPACE;
2167
 
          }
 
2138
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
 
2139
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
2168
2140
        | alter_list
2169
2141
        ;
2170
2142
 
2191
2163
add_column:
2192
2164
          ADD opt_column
2193
2165
          {
2194
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2195
 
 
2196
 
            statement->change=0;
2197
 
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2166
            LEX *lex=Lex;
 
2167
            lex->change=0;
 
2168
            lex->alter_info.flags.set(ALTER_ADD_COLUMN);
2198
2169
          }
2199
2170
        ;
2200
2171
 
2202
2173
          add_column column_def opt_place { }
2203
2174
        | ADD key_def
2204
2175
          {
2205
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2206
 
 
2207
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
2176
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
2208
2177
          }
2209
2178
        | add_column '(' field_list ')'
2210
2179
          {
2211
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2212
 
 
2213
 
            statement->alter_info.flags.set(ALTER_ADD_COLUMN);
2214
 
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
2180
            Lex->alter_info.flags.set(ALTER_ADD_COLUMN);
 
2181
            Lex->alter_info.flags.set(ALTER_ADD_INDEX);
2215
2182
          }
2216
2183
        | CHANGE opt_column field_ident
2217
2184
          {
2218
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2219
 
            statement->change= $3.str;
2220
 
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2185
            LEX *lex=Lex;
 
2186
            lex->change= $3.str;
 
2187
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2221
2188
          }
2222
2189
          field_spec opt_place
2223
2190
        | MODIFY_SYM opt_column field_ident
2224
2191
          {
2225
2192
            LEX *lex=Lex;
2226
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2227
2193
            lex->length=lex->dec=0; lex->type=0;
2228
 
            statement->default_value= statement->on_update_value= 0;
2229
 
            statement->comment= null_lex_str;
 
2194
            lex->default_value= lex->on_update_value= 0;
 
2195
            lex->comment=null_lex_str;
2230
2196
            lex->charset= NULL;
2231
 
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2232
 
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2233
 
 
2234
 
            statement->current_proto_field= NULL;
 
2197
            lex->alter_info.flags.set(ALTER_CHANGE_COLUMN);
 
2198
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2235
2199
          }
2236
2200
          field_def
2237
2201
          {
2238
2202
            LEX *lex=Lex;
2239
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2240
 
 
2241
2203
            if (add_field_to_list(lex->session,&$3,
2242
2204
                                  (enum enum_field_types) $5,
2243
 
                                  lex->length, lex->dec, lex->type,
2244
 
                                  statement->column_format,
2245
 
                                  statement->default_value,
2246
 
                                  statement->on_update_value,
2247
 
                                  &statement->comment,
 
2205
                                  lex->length,lex->dec,lex->type,
 
2206
                                  lex->column_format,
 
2207
                                  lex->default_value, lex->on_update_value,
 
2208
                                  &lex->comment,
2248
2209
                                  $3.str, &lex->interval_list, lex->charset))
2249
2210
              DRIZZLE_YYABORT;
2250
2211
          }
2251
2212
          opt_place
2252
2213
        | DROP opt_column field_ident
2253
2214
          {
2254
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2255
 
 
2256
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::COLUMN, $3.str));
2257
 
            statement->alter_info.flags.set(ALTER_DROP_COLUMN);
 
2215
            LEX *lex=Lex;
 
2216
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
 
2217
                                                               $3.str));
 
2218
            lex->alter_info.flags.set(ALTER_DROP_COLUMN);
2258
2219
          }
2259
2220
        | DROP FOREIGN KEY_SYM opt_ident
2260
2221
          {
2261
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2262
 
 
2263
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2264
 
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
2222
            Lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
2223
            Lex->alter_info.flags.set(ALTER_FOREIGN_KEY);
2265
2224
          }
2266
2225
        | DROP PRIMARY_SYM KEY_SYM
2267
2226
          {
2268
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2269
 
 
2270
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
 
2227
            LEX *lex=Lex;
 
2228
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2271
2229
                                                               "PRIMARY"));
2272
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2230
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
2273
2231
          }
2274
2232
        | DROP key_or_index field_ident
2275
2233
          {
2276
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2277
 
 
2278
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY,
2279
 
                                                                    $3.str));
2280
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
2234
            LEX *lex=Lex;
 
2235
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
2236
                                                               $3.str));
 
2237
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
2281
2238
          }
2282
2239
        | DISABLE_SYM KEYS
2283
2240
          {
2284
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2285
 
 
2286
 
            statement->alter_info.keys_onoff= DISABLE;
2287
 
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
2241
            LEX *lex=Lex;
 
2242
            lex->alter_info.keys_onoff= DISABLE;
 
2243
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
2288
2244
          }
2289
2245
        | ENABLE_SYM KEYS
2290
2246
          {
2291
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2292
 
 
2293
 
            statement->alter_info.keys_onoff= ENABLE;
2294
 
            statement->alter_info.flags.set(ALTER_KEYS_ONOFF);
 
2247
            LEX *lex=Lex;
 
2248
            lex->alter_info.keys_onoff= ENABLE;
 
2249
            lex->alter_info.flags.set(ALTER_KEYS_ONOFF);
2295
2250
          }
2296
2251
        | ALTER opt_column field_ident SET DEFAULT signed_literal
2297
2252
          {
2298
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2299
 
 
2300
 
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str,$6));
2301
 
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
2253
            LEX *lex=Lex;
 
2254
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
 
2255
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2302
2256
          }
2303
2257
        | ALTER opt_column field_ident DROP DEFAULT
2304
2258
          {
2305
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2306
 
 
2307
 
            statement->alter_info.alter_list.push_back(new AlterColumn($3.str, (Item*) 0));
2308
 
            statement->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
 
2259
            LEX *lex=Lex;
 
2260
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
 
2261
                                                                  (Item*) 0));
 
2262
            lex->alter_info.flags.set(ALTER_COLUMN_DEFAULT);
2309
2263
          }
2310
2264
        | RENAME opt_to table_ident
2311
2265
          {
2312
2266
            LEX *lex=Lex;
2313
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2314
2267
            size_t dummy;
2315
 
 
2316
2268
            lex->select_lex.db=$3->db.str;
2317
2269
            if (lex->select_lex.db == NULL &&
2318
2270
                lex->copy_db_to(&lex->select_lex.db, &dummy))
2319
2271
            {
2320
2272
              DRIZZLE_YYABORT;
2321
2273
            }
2322
 
 
2323
 
            if (check_table_name($3->table.str,$3->table.length))
 
2274
            if (check_table_name($3->table.str,$3->table.length) || ($3->db.str && check_db_name(&$3->db)))
2324
2275
            {
2325
2276
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
2326
2277
              DRIZZLE_YYABORT;
2327
2278
            }
2328
 
 
2329
2279
            lex->name= $3->table;
2330
 
            statement->alter_info.flags.set(ALTER_RENAME);
 
2280
            lex->alter_info.flags.set(ALTER_RENAME);
2331
2281
          }
2332
2282
        | CONVERT_SYM TO_SYM collation_name_or_default
2333
2283
          {
2334
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2335
 
 
2336
 
            statement->create_info.table_charset=
2337
 
            statement->create_info.default_table_charset= $3;
2338
 
            statement->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
 
2284
            LEX *lex= Lex;
 
2285
            lex->create_info.table_charset=
 
2286
            lex->create_info.default_table_charset= $3;
 
2287
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2339
2288
              HA_CREATE_USED_DEFAULT_CHARSET);
2340
 
            statement->alter_info.flags.set(ALTER_CONVERT);
 
2289
            lex->alter_info.flags.set(ALTER_CONVERT);
2341
2290
          }
2342
2291
        | create_table_options_space_separated
2343
2292
          {
2344
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2345
 
 
2346
 
            statement->alter_info.flags.set(ALTER_OPTIONS);
 
2293
            LEX *lex=Lex;
 
2294
            lex->alter_info.flags.set(ALTER_OPTIONS);
2347
2295
          }
2348
2296
        | FORCE_SYM
2349
2297
          {
2350
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2351
 
 
2352
 
            statement->alter_info.flags.set(ALTER_FORCE);
 
2298
            Lex->alter_info.flags.set(ALTER_FORCE);
2353
2299
          }
2354
2300
        | alter_order_clause
2355
2301
          {
2356
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2357
 
 
2358
 
            statement->alter_info.flags.set(ALTER_ORDER);
 
2302
            LEX *lex=Lex;
 
2303
            lex->alter_info.flags.set(ALTER_ORDER);
2359
2304
          }
2360
2305
        ;
2361
2306
 
2373
2318
          /* empty */ {}
2374
2319
        | AFTER_SYM ident
2375
2320
          {
2376
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2377
 
 
2378
2321
            store_position_for_column($2.str);
2379
 
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
2322
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
2380
2323
          }
2381
2324
        | FIRST_SYM
2382
2325
          {
2383
 
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2384
 
 
2385
2326
            store_position_for_column(first_keyword);
2386
 
            statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
 
2327
            Lex->alter_info.flags.set(ALTER_COLUMN_ORDER);
2387
2328
          }
2388
2329
        ;
2389
2330
 
2399
2340
          {
2400
2341
            LEX *lex= Lex;
2401
2342
            lex->sql_command= SQLCOM_BEGIN;
2402
 
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession, (start_transaction_option_t)$3);
 
2343
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
2403
2344
            if (lex->statement == NULL)
2404
2345
              DRIZZLE_YYABORT;
 
2346
            lex->start_transaction_opt= $3;
2405
2347
          }
2406
2348
        ;
2407
2349
 
2408
2350
start_transaction_opts:
2409
 
          /*empty*/ { $$ = START_TRANS_NO_OPTIONS; }
 
2351
          /*empty*/ { $$ = 0; }
2410
2352
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
2411
2353
          {
2412
 
            $$= START_TRANS_OPT_WITH_CONS_SNAPSHOT;
 
2354
            $$= DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
2413
2355
          }
2414
2356
        ;
2415
2357
 
2423
2365
            if (lex->statement == NULL)
2424
2366
              DRIZZLE_YYABORT;
2425
2367
          }
2426
 
          table_list
 
2368
          table_list opt_checksum_type
2427
2369
          {}
2428
2370
        ;
2429
2371
 
 
2372
opt_checksum_type:
 
2373
          /* nothing */ { Lex->check_opt.flags= 0; }
 
2374
        | QUICK         { Lex->check_opt.flags= T_QUICK; }
 
2375
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
 
2376
        ;
 
2377
 
2430
2378
 
2431
2379
analyze:
2432
2380
          ANALYZE_SYM table_or_tables
2436
2384
            lex->statement= new(std::nothrow) statement::Analyze(YYSession);
2437
2385
            if (lex->statement == NULL)
2438
2386
              DRIZZLE_YYABORT;
 
2387
            lex->check_opt.init();
2439
2388
          }
2440
2389
          table_list
2441
2390
          {}
2450
2399
            lex->statement= new(std::nothrow) statement::Check(YYSession);
2451
2400
            if (lex->statement == NULL)
2452
2401
              DRIZZLE_YYABORT;
 
2402
            lex->check_opt.init();
 
2403
          }
 
2404
          table_list opt_mi_check_type
 
2405
          {}
 
2406
        ;
 
2407
 
 
2408
opt_mi_check_type:
 
2409
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2410
        | mi_check_types {}
 
2411
        ;
 
2412
 
 
2413
mi_check_types:
 
2414
          mi_check_type {}
 
2415
        | mi_check_type mi_check_types {}
 
2416
        ;
 
2417
 
 
2418
mi_check_type:
 
2419
          QUICK               { Lex->check_opt.flags|= T_QUICK; }
 
2420
        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
 
2421
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
 
2422
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
 
2423
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
 
2424
        ;
 
2425
 
 
2426
optimize:
 
2427
          OPTIMIZE table_or_tables
 
2428
          {
 
2429
            LEX *lex=Lex;
 
2430
            lex->sql_command = SQLCOM_OPTIMIZE;
 
2431
            lex->statement= new(std::nothrow) statement::Optimize(YYSession);
 
2432
            if (lex->statement == NULL)
 
2433
              DRIZZLE_YYABORT;
 
2434
            lex->check_opt.init();
2453
2435
          }
2454
2436
          table_list
2455
2437
          {}
2495
2477
          {
2496
2478
            LEX *lex= Lex;
2497
2479
            lex->sql_command= SQLCOM_SELECT;
2498
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
2480
            lex->statement= new(std::nothrow) statement::Select(SQLCOM_SELECT,
 
2481
                                                            YYSession);
2499
2482
            if (lex->statement == NULL)
2500
2483
              DRIZZLE_YYABORT;
2501
2484
          }
2574
2557
          opt_order_clause opt_limit_clause
2575
2558
          {
2576
2559
            Lex->current_select->context.table_list=
2577
 
              Lex->current_select->context.first_name_resolution_table=
 
2560
              Lex->current_select->context.first_name_resolution_table= 
2578
2561
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
2579
2562
          }
2580
2563
        ;
2846
2829
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
2847
2830
          }
2848
2831
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2849
 
          {
 
2832
          { 
2850
2833
            $6->push_front($4);
2851
2834
            $6->push_front($1);
2852
2835
            $$= new (YYSession->mem_root) Item_func_in(*$6);
2947
2930
        | '-' simple_expr %prec NEG
2948
2931
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
2949
2932
        | '(' subselect ')'
2950
 
          {
 
2933
          { 
2951
2934
            $$= new (YYSession->mem_root) Item_singlerow_subselect($2);
2952
2935
          }
2953
2936
        | '(' expr ')' { $$= $2; }
3014
2997
          { $$= new (YYSession->mem_root) Item_func_char(*$3); }
3015
2998
        | CURRENT_USER optional_braces
3016
2999
          {
3017
 
            std::string user_str("user");
3018
 
            if (! ($$= reserved_keyword_function(user_str, NULL)))
3019
 
            {
3020
 
              DRIZZLE_YYABORT;
3021
 
            }
 
3000
            $$= new (YYSession->mem_root) Item_func_current_user(Lex->current_context());
3022
3001
          }
3023
3002
        | DATE_SYM '(' expr ')'
3024
3003
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3075
3054
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3076
3055
        | USER '(' ')'
3077
3056
          {
3078
 
            std::string user_str("user");
3079
 
            if (! ($$= reserved_keyword_function(user_str, NULL)))
3080
 
            {
3081
 
              DRIZZLE_YYABORT;
3082
 
            }
 
3057
            $$= new (YYSession->mem_root) Item_func_user();
3083
3058
          }
3084
3059
        | YEAR_SYM '(' expr ')'
3085
3060
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3132
3107
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3133
3108
          { $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
3134
3109
        | SUBSTRING '(' expr ',' expr ',' expr ')'
3135
 
          {
3136
 
            std::string reverse_str("substr");
3137
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3138
 
            args->push_back($3);
3139
 
            args->push_back($5);
3140
 
            args->push_back($7);
3141
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
3142
 
            {
3143
 
              DRIZZLE_YYABORT;
3144
 
            }
3145
 
          }
 
3110
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3146
3111
        | SUBSTRING '(' expr ',' expr ')'
3147
 
          {
3148
 
            std::string reverse_str("substr");
3149
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3150
 
            args->push_back($3);
3151
 
            args->push_back($5);
3152
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
3153
 
            {
3154
 
              DRIZZLE_YYABORT;
3155
 
            }
3156
 
          }
 
3112
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3157
3113
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3158
 
          {
3159
 
            std::string reverse_str("substr");
3160
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3161
 
            args->push_back($3);
3162
 
            args->push_back($5);
3163
 
            args->push_back($7);
3164
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
3165
 
            {
3166
 
              DRIZZLE_YYABORT;
3167
 
            }
3168
 
          }
 
3114
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5,$7); }
3169
3115
        | SUBSTRING '(' expr FROM expr ')'
3170
 
          {
3171
 
            std::string reverse_str("substr");
3172
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3173
 
            args->push_back($3);
3174
 
            args->push_back($5);
3175
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
3176
 
            {
3177
 
              DRIZZLE_YYABORT;
3178
 
            }
3179
 
          }
 
3116
          { $$= new (YYSession->mem_root) Item_func_substr($3,$5); }
3180
3117
        | SYSDATE optional_braces
3181
3118
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
3182
3119
        | SYSDATE '(' expr ')'
3207
3144
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3208
3145
        | DATABASE '(' ')'
3209
3146
          {
3210
 
            std::string database_str("database");
3211
 
            if (! ($$= reserved_keyword_function(database_str, NULL)))
3212
 
            {
3213
 
              DRIZZLE_YYABORT;
3214
 
            }
3215
 
          }
 
3147
            $$= new (YYSession->mem_root) Item_func_database();
 
3148
          }
3216
3149
        | IF '(' expr ',' expr ',' expr ')'
3217
3150
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3218
3151
        | MICROSECOND_SYM '(' expr ')'
3226
3159
        | REPLACE '(' expr ',' expr ',' expr ')'
3227
3160
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3228
3161
        | REVERSE_SYM '(' expr ')'
3229
 
          {
3230
 
            std::string reverse_str("reverse");
3231
 
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3232
 
            args->push_back($3);
3233
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
3234
 
            {
3235
 
              DRIZZLE_YYABORT;
3236
 
            }
3237
 
          }
 
3162
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
3238
3163
        | TRUNCATE_SYM '(' expr ',' expr ')'
3239
3164
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
 
3165
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
 
3166
          { $$= new (YYSession->mem_root) Item_func_weight_string($3, 0, $4); }
 
3167
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
 
3168
          {
 
3169
            $$= new (YYSession->mem_root)
 
3170
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
 
3171
          }
 
3172
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
 
3173
          {
 
3174
            $3= create_func_char_cast(YYSession, $3, $6, &my_charset_bin);
 
3175
            $$= new (YYSession->mem_root)
 
3176
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
 
3177
          }
3240
3178
        ;
3241
3179
 
3242
3180
/*
3250
3188
function_call_generic:
3251
3189
          IDENT_sys '('
3252
3190
          {
3253
 
            const plugin::Function *udf= plugin::Function::get($1.str, $1.length);
 
3191
            plugin::Registry &plugins= plugin::Registry::singleton();
 
3192
            const plugin::Function *udf= plugins.function.get($1.str, $1.length);
3254
3193
 
3255
3194
            /* Temporary placing the result of getFunction in $3 */
3256
3195
            $<udf>$= udf;
3277
3216
            }
3278
3217
            else
3279
3218
            {
3280
 
              /* Retrieving the result of service::Function::get */
 
3219
              /* Retrieving the result of slot::Function::get */
3281
3220
              const plugin::Function *udf= $<udf>3;
3282
3221
              if (udf)
3283
3222
              {
3440
3379
          {
3441
3380
            Select_Lex *select= Lex->current_select;
3442
3381
            select->gorder_list=
3443
 
              (SQL_LIST*) memory::sql_memdup((char*) &select->order_list,
 
3382
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3444
3383
                                     sizeof(st_sql_list));
3445
3384
            select->order_list.empty();
3446
3385
          }
3466
3405
cast_type:
3467
3406
          BINARY opt_len
3468
3407
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
3469
 
        | CHAR_SYM opt_len
 
3408
        | CHAR_SYM opt_len opt_binary
3470
3409
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
3471
3410
        | DATE_SYM
3472
3411
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
3637
3576
            DRIZZLE_YYABORT_UNLESS($1 && $5);
3638
3577
          }
3639
3578
          USING '(' using_list ')'
3640
 
          {
3641
 
            add_join_natural($1,$5,$9,Lex->current_select);
3642
 
            $5->outer_join|=JOIN_TYPE_LEFT;
3643
 
            $$=$5;
 
3579
          { 
 
3580
            add_join_natural($1,$5,$9,Lex->current_select); 
 
3581
            $5->outer_join|=JOIN_TYPE_LEFT; 
 
3582
            $$=$5; 
3644
3583
          }
3645
3584
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3646
3585
          {
3696
3635
        | CROSS JOIN_SYM {}
3697
3636
        ;
3698
3637
 
3699
 
/*
 
3638
/* 
3700
3639
   This is a flattening of the rules <table factor> and <table primary>
3701
3640
   in the SQL:2003 standard, since we don't have <sample clause>
3702
3641
 
3703
3642
   I.e.
3704
3643
   <table factor> ::= <table primary> [ <sample clause> ]
3705
 
*/  
 
3644
*/   
3706
3645
/* Warning - may return NULL in case of incomplete SELECT */
3707
3646
table_factor:
3708
3647
          {
3744
3683
            Represents a flattening of the following rules from the SQL:2003
3745
3684
            standard. This sub-rule corresponds to the sub-rule
3746
3685
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
3747
 
           
 
3686
            
3748
3687
            The following rules have been flattened into query_expression_body
3749
3688
            (since we have no <with clause>).
3750
3689
 
3934
3873
index_hint_clause:
3935
3874
          /* empty */
3936
3875
          {
3937
 
            $$= INDEX_HINT_MASK_ALL;
 
3876
            $$= INDEX_HINT_MASK_ALL; 
3938
3877
          }
3939
3878
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
3940
3879
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
3943
3882
 
3944
3883
index_hint_type:
3945
3884
          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
3946
 
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
 
3885
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; } 
3947
3886
        ;
3948
3887
 
3949
3888
index_hint_definition:
4026
3965
 
4027
3966
interval_time_stamp:
4028
3967
        interval_time_st        {}
4029
 
        | FRAC_SECOND_SYM       {
4030
 
                                  $$=INTERVAL_MICROSECOND;
 
3968
        | FRAC_SECOND_SYM       { 
 
3969
                                  $$=INTERVAL_MICROSECOND; 
4031
3970
                                  /*
4032
3971
                                    FRAC_SECOND was mistakenly implemented with
4033
3972
                                    a wrong resolution. According to the ODBC
4064
4003
opt_table_alias:
4065
4004
          /* empty */ { $$=0; }
4066
4005
        | table_alias ident
4067
 
          { $$= (drizzled::LEX_STRING*) memory::sql_memdup(&$2,sizeof(drizzled::LEX_STRING)); }
 
4006
          { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
4068
4007
        ;
4069
4008
 
4070
4009
opt_all:
4105
4044
        ;
4106
4045
 
4107
4046
opt_escape:
4108
 
          ESCAPE_SYM simple_expr
 
4047
          ESCAPE_SYM simple_expr 
4109
4048
          {
4110
4049
            Lex->escape_used= true;
4111
4050
            $$= $2;
4213
4152
              */
4214
4153
              Select_Lex *first_sl= unit->first_select();
4215
4154
              if (!unit->is_union() &&
4216
 
                  (first_sl->order_list.elements ||
4217
 
                   first_sl->select_limit) &&           
 
4155
                  (first_sl->order_list.elements || 
 
4156
                   first_sl->select_limit) &&            
4218
4157
                  unit->add_fake_select_lex(lex->session))
4219
4158
                DRIZZLE_YYABORT;
4220
4159
            }
4300
4239
        ;
4301
4240
 
4302
4241
ulong_num:
4303
 
          NUM           { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4242
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
4304
4243
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
4305
 
        | LONG_NUM      { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4306
 
        | ULONGLONG_NUM { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4307
 
        | DECIMAL_NUM   { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
4308
 
        | FLOAT_NUM     { int error; $$= (ulong) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4244
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4245
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4246
        | DECIMAL_NUM   { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4247
        | FLOAT_NUM     { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
4309
4248
        ;
4310
4249
 
 
4250
real_ulong_num:
 
4251
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4252
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
4253
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4254
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
4255
        | dec_num_error { }
 
4256
        ;
 
4257
 
4311
4258
ulonglong_num:
4312
 
          NUM           { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4313
 
        | ULONGLONG_NUM { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4314
 
        | LONG_NUM      { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4315
 
        | DECIMAL_NUM   { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
4316
 
        | FLOAT_NUM     { int error; $$= (uint64_t) internal::my_strtoll10($1.str, (char**) 0, &error); }
 
4259
          NUM           { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4260
        | ULONGLONG_NUM { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4261
        | LONG_NUM      { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4262
        | DECIMAL_NUM   { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4263
        | FLOAT_NUM     { int error; $$= (uint64_t) my_strtoll10($1.str, (char**) 0, &error); }
 
4264
        ;
 
4265
 
 
4266
dec_num_error:
 
4267
          dec_num
 
4268
          { my_parse_error(ER(ER_ONLY_INTEGERS_ALLOWED)); }
 
4269
        ;
 
4270
 
 
4271
dec_num:
 
4272
          DECIMAL_NUM
 
4273
        | FLOAT_NUM
4317
4274
        ;
4318
4275
 
4319
4276
select_var_list_init:
4331
4288
        | select_var_ident {}
4332
4289
        ;
4333
4290
 
4334
 
select_var_ident: 
 
4291
select_var_ident:  
4335
4292
          '@' ident_or_text
4336
4293
          {
4337
4294
            LEX *lex=Lex;
4338
 
            if (lex->result)
4339
 
              ((select_dumpvar *)lex->result)->var_list.push_back( new var($2,0,0,(enum_field_types)0));
 
4295
            if (lex->result) 
 
4296
              ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
4340
4297
            else
4341
4298
              /*
4342
4299
                The parser won't create select_result instance only
4385
4342
          {
4386
4343
            LEX *lex=Lex;
4387
4344
            lex->sql_command = SQLCOM_DROP_TABLE;
4388
 
            statement::DropTable *statement= new(std::nothrow) statement::DropTable(YYSession);
4389
 
            lex->statement= statement;
 
4345
            lex->statement= new(std::nothrow) statement::DropTable(YYSession);
4390
4346
            if (lex->statement == NULL)
4391
4347
              DRIZZLE_YYABORT;
4392
 
            statement->drop_temporary= $2;
4393
 
            statement->drop_if_exists= $4;
 
4348
            lex->drop_temporary= $2;
 
4349
            lex->drop_if_exists= $4;
4394
4350
          }
4395
4351
        | DROP build_method INDEX_SYM ident ON table_ident {}
4396
4352
          {
4397
4353
            LEX *lex=Lex;
4398
4354
            lex->sql_command= SQLCOM_DROP_INDEX;
4399
 
            statement::DropIndex *statement= new(std::nothrow) statement::DropIndex(YYSession);
4400
 
            lex->statement= statement;
 
4355
            lex->statement= new(std::nothrow) 
 
4356
              statement::DropIndex(YYSession);
4401
4357
            if (lex->statement == NULL)
4402
4358
              DRIZZLE_YYABORT;
4403
 
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
4404
 
            statement->alter_info.build_method= $2;
4405
 
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, $4.str));
 
4359
            lex->alter_info.reset();
 
4360
            lex->alter_info.flags.set(ALTER_DROP_INDEX);
 
4361
            lex->alter_info.build_method= $2;
 
4362
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
4363
                                                               $4.str));
4406
4364
            if (!lex->current_select->add_table_to_list(lex->session, $6, NULL,
4407
4365
                                                        TL_OPTION_UPDATING))
4408
4366
              DRIZZLE_YYABORT;
 
4367
 
 
4368
            lex->create_table_proto= new message::Table();
4409
4369
          }
4410
4370
        | DROP DATABASE if_exists ident
4411
4371
          {
4412
4372
            LEX *lex=Lex;
4413
4373
            lex->sql_command= SQLCOM_DROP_DB;
4414
 
            statement::DropSchema *statement= new(std::nothrow) statement::DropSchema(YYSession);
4415
 
            lex->statement= statement;
 
4374
            lex->statement= new(std::nothrow) statement::DropSchema(YYSession);
4416
4375
            if (lex->statement == NULL)
4417
4376
              DRIZZLE_YYABORT;
4418
 
            statement->drop_if_exists=$3;
 
4377
            lex->drop_if_exists=$3;
4419
4378
            lex->name= $4;
4420
4379
          }
4421
4380
table_list:
4452
4411
            lex->statement= new(std::nothrow) statement::Insert(YYSession);
4453
4412
            if (lex->statement == NULL)
4454
4413
              DRIZZLE_YYABORT;
4455
 
            lex->duplicates= DUP_ERROR;
 
4414
            lex->duplicates= DUP_ERROR; 
4456
4415
            mysql_init_select(lex);
4457
4416
            /* for subselects */
4458
4417
            lex->lock_option= TL_READ;
4615
4574
            if (lex->statement == NULL)
4616
4575
              DRIZZLE_YYABORT;
4617
4576
            lex->lock_option= TL_UNLOCK; /* Will be set later */
4618
 
            lex->duplicates= DUP_ERROR;
 
4577
            lex->duplicates= DUP_ERROR; 
4619
4578
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4620
4579
              DRIZZLE_YYABORT;
4621
4580
          }
4661
4620
          simple_ident_nospvar equal expr_or_default
4662
4621
          {
4663
4622
          LEX *lex= Lex;
4664
 
          if (lex->update_list.push_back($1) ||
 
4623
          if (lex->update_list.push_back($1) || 
4665
4624
              lex->value_list.push_back($3))
4666
4625
              DRIZZLE_YYABORT;
4667
4626
          }
4702
4661
        ;
4703
4662
 
4704
4663
opt_delete_option:
4705
 
         IGNORE_SYM   { Lex->ignore= 1; }
 
4664
          QUICK        { Lex->current_select->options|= OPTION_QUICK; }
 
4665
        | IGNORE_SYM   { Lex->ignore= 1; }
4706
4666
        ;
4707
4667
 
4708
4668
truncate:
4733
4693
            lex->lock_option= TL_READ;
4734
4694
            mysql_init_select(lex);
4735
4695
            lex->current_select->parsing_place= SELECT_LIST;
 
4696
            memset(&lex->create_info, 0, sizeof(lex->create_info));
4736
4697
          }
4737
4698
          show_param
4738
4699
          {}
4742
4703
           DATABASES show_wild
4743
4704
           {
4744
4705
             LEX *lex= Lex;
4745
 
             Session *session= YYSession;
4746
 
 
4747
 
             lex->sql_command= SQLCOM_SELECT;
4748
 
             lex->statement=
4749
 
               new(std::nothrow) statement::Select(session);
4750
 
             if (lex->statement == NULL)
4751
 
               DRIZZLE_YYABORT;
4752
 
 
4753
 
             std::string column_name= "Database";
4754
 
             if (Lex->wild)
4755
 
             {
4756
 
               column_name.append(" (");
4757
 
               column_name.append(Lex->wild->ptr());
4758
 
               column_name.append(")");
4759
 
             }
4760
 
 
4761
 
             if (Lex->current_select->where)
4762
 
             {
4763
 
               if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4764
 
                 DRIZZLE_YYABORT;
4765
 
             }
4766
 
             else
4767
 
             {
4768
 
               if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4769
 
                 DRIZZLE_YYABORT;
4770
 
             }
4771
 
 
4772
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4773
 
             my_field->is_autogenerated_name= false;
4774
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4775
 
 
4776
 
             if (session->add_item_to_list(my_field))
4777
 
               DRIZZLE_YYABORT;
4778
 
           }
4779
 
         | TABLES opt_db show_wild
4780
 
           {
4781
 
             LEX *lex= Lex;
4782
 
             Session *session= YYSession;
4783
 
 
4784
 
             lex->sql_command= SQLCOM_SELECT;
4785
 
 
4786
 
             statement::Select *select=
4787
 
               new(std::nothrow) statement::Select(YYSession);
4788
 
 
4789
 
             lex->statement= select;
4790
 
 
4791
 
             if (lex->statement == NULL)
4792
 
               DRIZZLE_YYABORT;
4793
 
 
4794
 
 
4795
 
              std::string column_name= "Tables_in_";
4796
 
 
4797
 
              if ($2)
4798
 
              {
4799
 
                SchemaIdentifier identifier($2);
4800
 
                column_name.append($2);
4801
 
                lex->select_lex.db= $2;
4802
 
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
4803
 
                {
4804
 
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4805
 
                }
4806
 
                select->setShowPredicate($2, "");
4807
 
              }
4808
 
              else if (not session->db.empty())
4809
 
              {
4810
 
                column_name.append(session->db);
4811
 
                select->setShowPredicate(session->db, "");
4812
 
              }
4813
 
              else
4814
 
              {
4815
 
                 my_error(ER_NO_DB_ERROR, MYF(0));
4816
 
              }
4817
 
 
4818
 
 
4819
 
             if (Lex->wild)
4820
 
             {
4821
 
               column_name.append(" (");
4822
 
               column_name.append(Lex->wild->ptr());
4823
 
               column_name.append(")");
4824
 
             }
4825
 
 
4826
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4827
 
               DRIZZLE_YYABORT;
4828
 
 
4829
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4830
 
             my_field->is_autogenerated_name= false;
4831
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4832
 
 
4833
 
             if (session->add_item_to_list(my_field))
4834
 
               DRIZZLE_YYABORT;
4835
 
           }
4836
 
         | TEMPORARY_SYM TABLES show_wild
4837
 
           {
4838
 
             LEX *lex= Lex;
4839
 
             Session *session= YYSession;
4840
 
 
4841
 
             lex->sql_command= SQLCOM_SELECT;
4842
 
 
4843
 
             statement::Select *select=
4844
 
               new(std::nothrow) statement::Select(YYSession);
4845
 
 
4846
 
             lex->statement= select;
4847
 
 
4848
 
             if (lex->statement == NULL)
4849
 
               DRIZZLE_YYABORT;
4850
 
 
4851
 
 
4852
 
             if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4853
 
               DRIZZLE_YYABORT;
4854
 
 
4855
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4856
 
                                                           context,
4857
 
                                                           NULL, NULL, "*")))
4858
 
               DRIZZLE_YYABORT;
4859
 
             (session->lex->current_select->with_wild)++;
4860
 
 
 
4706
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
4707
             lex->statement=
 
4708
               new(std::nothrow) statement::Select(SQLCOM_SHOW_DATABASES, 
 
4709
                                                 YYSession);
 
4710
             if (lex->statement == NULL)
 
4711
               DRIZZLE_YYABORT;
 
4712
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
 
4713
               DRIZZLE_YYABORT;
 
4714
           }
 
4715
         | opt_full TABLES opt_db show_wild
 
4716
           {
 
4717
             LEX *lex= Lex;
 
4718
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4719
             lex->statement=
 
4720
               new(std::nothrow) statement::Select(SQLCOM_SHOW_TABLES,
 
4721
                                                 YYSession);
 
4722
             if (lex->statement == NULL)
 
4723
               DRIZZLE_YYABORT;
 
4724
             lex->select_lex.db= $3;
 
4725
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
 
4726
               DRIZZLE_YYABORT;
4861
4727
           }
4862
4728
         | TABLE_SYM STATUS_SYM opt_db show_wild
4863
4729
           {
4864
4730
             LEX *lex= Lex;
4865
 
             lex->sql_command= SQLCOM_SELECT;
4866
 
             statement::Select *select=
4867
 
               new(std::nothrow) statement::Select(YYSession);
4868
 
 
4869
 
             lex->statement= select;
4870
 
 
 
4731
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4732
             lex->statement=
 
4733
               new(std::nothrow) statement::Select(SQLCOM_SHOW_TABLE_STATUS,
 
4734
                                                 YYSession);
4871
4735
             if (lex->statement == NULL)
4872
4736
               DRIZZLE_YYABORT;
4873
 
 
4874
 
             Session *session= YYSession;
4875
 
 
4876
 
             std::string column_name= "Tables_in_";
4877
 
 
4878
 
             if ($3)
4879
 
             {
4880
 
               lex->select_lex.db= $3;
4881
 
 
4882
 
               SchemaIdentifier identifier($3);
4883
 
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
4884
 
               {
4885
 
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4886
 
               }
4887
 
 
4888
 
               select->setShowPredicate($3, "");
4889
 
             }
4890
 
             else
4891
 
             {
4892
 
               select->setShowPredicate(session->db, "");
4893
 
             }
4894
 
 
4895
 
             if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
4896
 
               DRIZZLE_YYABORT;
4897
 
 
4898
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4899
 
                                                           context,
4900
 
                                                           NULL, NULL, "*")))
4901
 
               DRIZZLE_YYABORT;
4902
 
             (session->lex->current_select->with_wild)++;
 
4737
             lex->select_lex.db= $3;
 
4738
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
 
4739
               DRIZZLE_YYABORT;
4903
4740
           }
4904
 
        | COLUMNS from_or_in table_ident opt_db show_wild
4905
 
          {
4906
 
             LEX *lex= Lex;
4907
 
             Session *session= YYSession;
4908
 
             statement::Select *select;
4909
 
 
4910
 
             lex->sql_command= SQLCOM_SELECT;
4911
 
 
4912
 
             select= new(std::nothrow) statement::Select(session);
4913
 
 
4914
 
             lex->statement= select;
4915
 
 
4916
 
             if (lex->statement == NULL)
4917
 
               DRIZZLE_YYABORT;
4918
 
 
4919
 
             if ($4)
4920
 
              select->setShowPredicate($4, $3->table.str);
4921
 
             else if ($3->db.str)
4922
 
              select->setShowPredicate($3->db.str, $3->table.str);
4923
 
             else
4924
 
              select->setShowPredicate(session->db, $3->table.str);
4925
 
 
4926
 
             {
4927
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4928
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4929
 
               {
4930
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
4931
 
                            select->getShowSchema().c_str(), 
4932
 
                            $3->table.str);
4933
 
               }
4934
 
             }
4935
 
 
4936
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
4937
 
               DRIZZLE_YYABORT;
4938
 
 
4939
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4940
 
                                                           context,
4941
 
                                                           NULL, NULL, "*")))
4942
 
               DRIZZLE_YYABORT;
4943
 
             (session->lex->current_select->with_wild)++;
4944
 
 
 
4741
        | OPEN_SYM TABLES opt_db show_wild
 
4742
          {
 
4743
            LEX *lex= Lex;
 
4744
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
4745
            lex->statement=
 
4746
              new(std::nothrow) statement::Select(SQLCOM_SHOW_OPEN_TABLES,
 
4747
                                                YYSession);
 
4748
            if (lex->statement == NULL)
 
4749
              DRIZZLE_YYABORT;
 
4750
            lex->select_lex.db= $3;
 
4751
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
 
4752
              DRIZZLE_YYABORT;
 
4753
          }
 
4754
        | ENGINE_SYM known_storage_engines STATUS_SYM /* This should either go... well it should go */
 
4755
          { 
 
4756
            Lex->show_engine= $2; 
 
4757
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
 
4758
            Lex->statement= 
 
4759
              new(std::nothrow) statement::ShowEngineStatus(YYSession);
 
4760
            if (Lex->statement == NULL)
 
4761
              DRIZZLE_YYABORT;
 
4762
          }
 
4763
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
 
4764
          {
 
4765
            LEX *lex= Lex;
 
4766
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4767
            lex->statement=
 
4768
              new(std::nothrow) statement::Select(SQLCOM_SHOW_FIELDS, YYSession);
 
4769
            if (lex->statement == NULL)
 
4770
              DRIZZLE_YYABORT;
 
4771
            if ($5)
 
4772
              $4->change_db($5);
 
4773
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
 
4774
              DRIZZLE_YYABORT;
4945
4775
          }
4946
4776
        | keys_or_index from_or_in table_ident opt_db where_clause
4947
4777
          {
4948
 
             LEX *lex= Lex;
4949
 
             Session *session= YYSession;
4950
 
             statement::Select *select;
4951
 
 
4952
 
             lex->sql_command= SQLCOM_SELECT;
4953
 
 
4954
 
             select= new(std::nothrow) statement::Select(session);
4955
 
 
4956
 
             lex->statement= select;
4957
 
 
4958
 
             if (lex->statement == NULL)
4959
 
               DRIZZLE_YYABORT;
4960
 
 
4961
 
             if ($4)
4962
 
              select->setShowPredicate($4, $3->table.str);
4963
 
             else if ($3->db.str)
4964
 
              select->setShowPredicate($3->db.str, $3->table.str);
4965
 
             else
4966
 
              select->setShowPredicate(session->db, $3->table.str);
4967
 
 
4968
 
             {
4969
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4970
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4971
 
               {
4972
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
4973
 
                            select->getShowSchema().c_str(), 
4974
 
                            $3->table.str);
4975
 
               }
4976
 
             }
4977
 
 
4978
 
             if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
4979
 
               DRIZZLE_YYABORT;
4980
 
 
4981
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4982
 
                                                           context,
4983
 
                                                           NULL, NULL, "*")))
4984
 
               DRIZZLE_YYABORT;
4985
 
             (session->lex->current_select->with_wild)++;
 
4778
            LEX *lex= Lex;
 
4779
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
4780
            lex->statement= new(std::nothrow) statement::Select(SQLCOM_SHOW_KEYS,
 
4781
                                                            YYSession);
 
4782
            if (lex->statement == NULL)
 
4783
              DRIZZLE_YYABORT;
 
4784
            if ($4)
 
4785
              $3->change_db($4);
 
4786
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
 
4787
              DRIZZLE_YYABORT;
4986
4788
          }
4987
4789
        | COUNT_SYM '(' '*' ')' WARNINGS
4988
 
          {
4989
 
            (void) create_select_for_variable("warning_count");
 
4790
          { 
 
4791
            (void) create_select_for_variable("warning_count"); 
4990
4792
            LEX *lex= Lex;
4991
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4793
            lex->statement= new(std::nothrow) statement::Select(SQLCOM_SELECT,
 
4794
                                                            YYSession);
4992
4795
            if (lex->statement == NULL)
4993
4796
              DRIZZLE_YYABORT;
4994
4797
          }
4995
4798
        | COUNT_SYM '(' '*' ')' ERRORS
4996
 
          {
4997
 
            (void) create_select_for_variable("error_count");
 
4799
          { 
 
4800
            (void) create_select_for_variable("error_count"); 
4998
4801
            LEX *lex= Lex;
4999
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
4802
            lex->statement= new(std::nothrow) statement::Select(SQLCOM_SELECT,
 
4803
                                                            YYSession);
5000
4804
            if (lex->statement == NULL)
5001
4805
              DRIZZLE_YYABORT;
5002
4806
          }
5003
4807
        | WARNINGS opt_limit_clause_init
5004
 
          {
 
4808
          { 
5005
4809
            Lex->sql_command = SQLCOM_SHOW_WARNS;
5006
4810
            Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5007
4811
            if (Lex->statement == NULL)
5008
4812
              DRIZZLE_YYABORT;
5009
4813
          }
5010
4814
        | ERRORS opt_limit_clause_init
5011
 
          {
 
4815
          { 
5012
4816
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
5013
4817
            Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5014
4818
            if (Lex->statement == NULL)
5015
4819
              DRIZZLE_YYABORT;
5016
4820
          }
5017
4821
        | opt_var_type STATUS_SYM show_wild
5018
 
           {
5019
 
             LEX *lex= Lex;
5020
 
             lex->sql_command= SQLCOM_SELECT;
5021
 
             lex->statement=
5022
 
               new(std::nothrow) statement::Select(YYSession);
5023
 
             if (lex->statement == NULL)
5024
 
               DRIZZLE_YYABORT;
5025
 
 
5026
 
             Session *session= YYSession;
5027
 
 
5028
 
             if ($1 == OPT_GLOBAL)
5029
 
             {
5030
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5031
 
                 DRIZZLE_YYABORT;
5032
 
             }
5033
 
             else
5034
 
             {
5035
 
               if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5036
 
                 DRIZZLE_YYABORT;
5037
 
             }
5038
 
 
5039
 
             std::string key("Variable_name");
5040
 
             std::string value("Value");
5041
 
 
5042
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5043
 
             my_field->is_autogenerated_name= false;
5044
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5045
 
 
5046
 
             if (session->add_item_to_list(my_field))
5047
 
               DRIZZLE_YYABORT;
5048
 
 
5049
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5050
 
             my_field->is_autogenerated_name= false;
5051
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5052
 
 
5053
 
             if (session->add_item_to_list(my_field))
5054
 
               DRIZZLE_YYABORT;
5055
 
           }
5056
 
        | PROCESSLIST_SYM
5057
4822
          {
5058
 
           {
5059
 
             LEX *lex= Lex;
5060
 
             lex->sql_command= SQLCOM_SELECT;
5061
 
             lex->statement=
5062
 
               new(std::nothrow) statement::Select(YYSession);
5063
 
             if (lex->statement == NULL)
5064
 
               DRIZZLE_YYABORT;
5065
 
 
5066
 
             Session *session= YYSession;
5067
 
 
5068
 
             if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5069
 
               DRIZZLE_YYABORT;
5070
 
 
5071
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5072
 
                                                           context,
5073
 
                                                           NULL, NULL, "*")))
5074
 
               DRIZZLE_YYABORT;
5075
 
             (session->lex->current_select->with_wild)++;
5076
 
           }
 
4823
            LEX *lex= Lex;
 
4824
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
4825
            lex->statement=
 
4826
              new(std::nothrow) statement::ShowStatus(YYSession,
 
4827
                                                    &LOCK_status);
 
4828
            if (lex->statement == NULL)
 
4829
              DRIZZLE_YYABORT;
 
4830
            lex->option_type= $1;
 
4831
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
 
4832
              DRIZZLE_YYABORT;
 
4833
          }
 
4834
        | opt_full PROCESSLIST_SYM
 
4835
          { 
 
4836
            Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;
 
4837
            Lex->statement= 
 
4838
              new(std::nothrow) statement::ShowProcesslist(YYSession);
 
4839
            if (Lex->statement == NULL)
 
4840
              DRIZZLE_YYABORT;
5077
4841
          }
5078
4842
        | opt_var_type  VARIABLES show_wild
5079
 
           {
5080
 
             LEX *lex= Lex;
5081
 
             lex->sql_command= SQLCOM_SELECT;
5082
 
             lex->statement=
5083
 
               new(std::nothrow) statement::Select(YYSession);
5084
 
             if (lex->statement == NULL)
5085
 
               DRIZZLE_YYABORT;
5086
 
 
5087
 
             Session *session= YYSession;
5088
 
 
5089
 
             if ($1 == OPT_GLOBAL)
5090
 
             {
5091
 
               if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5092
 
                 DRIZZLE_YYABORT;
5093
 
             }
5094
 
             else
5095
 
             {
5096
 
               if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5097
 
                 DRIZZLE_YYABORT;
5098
 
             }
5099
 
 
5100
 
             std::string key("Variable_name");
5101
 
             std::string value("Value");
5102
 
 
5103
 
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5104
 
             my_field->is_autogenerated_name= false;
5105
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5106
 
 
5107
 
             if (session->add_item_to_list(my_field))
5108
 
               DRIZZLE_YYABORT;
5109
 
 
5110
 
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5111
 
             my_field->is_autogenerated_name= false;
5112
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5113
 
 
5114
 
             if (session->add_item_to_list(my_field))
5115
 
               DRIZZLE_YYABORT;
5116
 
           }
 
4843
          {
 
4844
            LEX *lex= Lex;
 
4845
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
4846
            lex->statement=
 
4847
              new(std::nothrow) statement::Select(SQLCOM_SHOW_VARIABLES, 
 
4848
                                                YYSession);
 
4849
            if (lex->statement == NULL)
 
4850
              DRIZZLE_YYABORT;
 
4851
            lex->option_type= $1;
 
4852
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
 
4853
              DRIZZLE_YYABORT;
 
4854
          }
5117
4855
        | CREATE DATABASE opt_if_not_exists ident
5118
4856
          {
5119
4857
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5120
 
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
5121
 
            Lex->statement= statement;
 
4858
            Lex->statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
5122
4859
            if (Lex->statement == NULL)
5123
4860
              DRIZZLE_YYABORT;
5124
 
            statement->is_if_not_exists= $3;
 
4861
            Lex->create_info.options=$3;
5125
4862
            Lex->name= $4;
5126
4863
          }
5127
4864
        | CREATE TABLE_SYM table_ident
5140
4877
        | from_or_in ident { $$= $2.str; }
5141
4878
        ;
5142
4879
 
 
4880
opt_full:
 
4881
          /* empty */ { Lex->verbose=0; }
 
4882
        | FULL        { Lex->verbose=1; }
 
4883
        ;
 
4884
 
5143
4885
from_or_in:
5144
4886
          FROM
5145
4887
        | IN_SYM
5166
4908
describe:
5167
4909
          describe_command table_ident
5168
4910
          {
5169
 
            Session *session= YYSession;
5170
 
            statement::Select *select;
5171
4911
            LEX *lex= Lex;
5172
4912
            lex->lock_option= TL_READ;
5173
4913
            mysql_init_select(lex);
5174
4914
            lex->current_select->parsing_place= SELECT_LIST;
5175
 
            lex->sql_command= SQLCOM_SELECT;
5176
 
            select= new(std::nothrow) statement::Select(session);
5177
 
            lex->statement= select;
 
4915
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4916
            lex->statement= new(std::nothrow) statement::Select(SQLCOM_SHOW_FIELDS,
 
4917
                                                            YYSession);
5178
4918
            if (lex->statement == NULL)
5179
4919
              DRIZZLE_YYABORT;
5180
4920
            lex->select_lex.db= 0;
5181
 
 
5182
 
             if ($2->db.str)
5183
 
              select->setShowPredicate($2->db.str, $2->table.str);
5184
 
             else
5185
 
              select->setShowPredicate(session->db, $2->table.str);
5186
 
 
5187
 
             {
5188
 
               drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $2->table.str);
5189
 
               if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5190
 
               {
5191
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5192
 
                            select->getShowSchema().c_str(), 
5193
 
                            $2->table.str);
5194
 
               }
5195
 
             }
5196
 
 
5197
 
             if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5198
 
               DRIZZLE_YYABORT;
5199
 
 
5200
 
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5201
 
                                                           context,
5202
 
                                                           NULL, NULL, "*")))
5203
 
               DRIZZLE_YYABORT;
5204
 
             (session->lex->current_select->with_wild)++;
5205
 
 
 
4921
            lex->verbose= 0;
 
4922
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
 
4923
              DRIZZLE_YYABORT;
5206
4924
          }
5207
4925
          opt_describe_column {}
5208
4926
        | describe_command opt_extended_describe
5259
4977
 
5260
4978
flush_option:
5261
4979
          table_or_tables
5262
 
          {
5263
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5264
 
            statement->setFlushTables(true);
5265
 
          }
 
4980
          { Lex->type|= REFRESH_TABLES; }
5266
4981
          opt_table_list {}
5267
4982
        | TABLES WITH READ_SYM LOCK_SYM
5268
 
          {
5269
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5270
 
            statement->setFlushTablesWithReadLock(true);
5271
 
          }
 
4983
          { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
5272
4984
        | LOGS_SYM
5273
 
          {
5274
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5275
 
            statement->setFlushLog(true);
5276
 
          }
 
4985
          { Lex->type|= REFRESH_LOG; }
5277
4986
        | STATUS_SYM
5278
 
          {
5279
 
            statement::Flush *statement= (statement::Flush*)Lex->statement;
5280
 
            statement->setFlushStatus(true);
5281
 
          }
 
4987
          { Lex->type|= REFRESH_STATUS; }
5282
4988
        ;
5283
4989
 
5284
4990
opt_table_list:
5328
5034
          {
5329
5035
            Session *session= YYSession;
5330
5036
            LEX *lex= session->lex;
 
5037
            Lex_input_stream *lip= session->m_lip;
5331
5038
 
 
5039
            lex->fname_start= lip->get_ptr();
 
5040
          }
 
5041
          load_data_lock INFILE TEXT_STRING_filesystem
 
5042
          {
 
5043
            LEX *lex=Lex;
5332
5044
            lex->sql_command= SQLCOM_LOAD;
5333
 
            statement::Load *statement= new(std::nothrow) statement::Load(YYSession);
5334
 
            lex->statement= statement;
 
5045
            lex->statement= new(std::nothrow) statement::Load(YYSession);
5335
5046
            if (lex->statement == NULL)
5336
5047
              DRIZZLE_YYABORT;
5337
 
 
5338
 
            Lex_input_stream *lip= session->m_lip;
5339
 
            statement->fname_start= lip->get_ptr();
5340
 
          }
5341
 
          load_data_lock INFILE TEXT_STRING_filesystem
5342
 
          {
5343
 
            LEX *lex=Lex;
5344
5048
            lex->lock_option= $4;
5345
5049
            lex->duplicates= DUP_ERROR;
5346
5050
            lex->ignore= 0;
5350
5054
          opt_duplicate INTO
5351
5055
          {
5352
5056
            Session *session= YYSession;
 
5057
            LEX *lex= session->lex;
5353
5058
            Lex_input_stream *lip= session->m_lip;
5354
 
            ((statement::Load *)Lex->statement)->fname_end= lip->get_ptr();
 
5059
            lex->fname_end= lip->get_ptr();
5355
5060
          }
5356
5061
          TABLE_SYM table_ident
5357
5062
          {
5397
5102
        ;
5398
5103
 
5399
5104
field_term:
5400
 
          TERMINATED BY text_string
 
5105
          TERMINATED BY text_string 
5401
5106
          {
5402
5107
            assert(Lex->exchange != 0);
5403
5108
            Lex->exchange->field_term= $3;
5491
5196
          $$ = new Item_string($1.str, $1.length, session->variables.getCollation());
5492
5197
        }
5493
5198
        | text_literal TEXT_STRING_literal
5494
 
          {
5495
 
            ((Item_string*) $1)->append($2.str, $2.length);
 
5199
          { 
 
5200
            ((Item_string*) $1)->append($2.str, $2.length); 
5496
5201
          }
5497
5202
        ;
5498
5203
 
5556
5261
          NUM
5557
5262
          {
5558
5263
            int error;
5559
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5264
            $$ = new Item_int($1.str, (int64_t) my_strtoll10($1.str, NULL, &error), $1.length);
5560
5265
          }
5561
5266
        | LONG_NUM
5562
5267
          {
5563
5268
            int error;
5564
 
            $$ = new Item_int($1.str, (int64_t) internal::my_strtoll10($1.str, NULL, &error), $1.length);
 
5269
            $$ = new Item_int($1.str, (int64_t) my_strtoll10($1.str, NULL, &error), $1.length);
5565
5270
          }
5566
5271
        | ULONGLONG_NUM
5567
5272
          { $$ = new Item_uint($1.str, $1.length); }
5797
5502
          keyword_sp            {}
5798
5503
        | BEGIN_SYM             {}
5799
5504
        | BYTE_SYM              {}
 
5505
        | CACHE_SYM             {}
 
5506
        | CHARSET               {}
5800
5507
        | CHECKSUM_SYM          {}
5801
5508
        | CLOSE_SYM             {}
5802
5509
        | COMMENT_SYM           {}
5805
5512
        | DEALLOCATE_SYM        {}
5806
5513
        | END                   {}
5807
5514
        | FLUSH_SYM             {}
 
5515
        | HANDLER_SYM           {}
 
5516
        | HOST_SYM              {}
 
5517
        | INSTALL_SYM           {}
5808
5518
        | NO_SYM                {}
5809
5519
        | OPEN_SYM              {}
 
5520
        | OPTIONS_SYM           {}
 
5521
        | PORT_SYM              {}
 
5522
        | REMOVE_SYM            {}
 
5523
        | RESET_SYM             {}
5810
5524
        | ROLLBACK_SYM          {}
5811
5525
        | SAVEPOINT_SYM         {}
5812
5526
        | SECURITY_SYM          {}
5813
5527
        | SERVER_SYM            {}
 
5528
        | SOCKET_SYM            {}
 
5529
        | SONAME_SYM            {}
5814
5530
        | START_SYM             {}
5815
5531
        | STOP_SYM              {}
5816
5532
        | TRUNCATE_SYM          {}
5827
5543
        | ADDDATE_SYM              {}
5828
5544
        | AFTER_SYM                {}
5829
5545
        | AGGREGATE_SYM            {}
 
5546
        | ALGORITHM_SYM            {}
5830
5547
        | ANY_SYM                  {}
5831
5548
        | AT_SYM                   {}
5832
5549
        | AUTO_INC                 {}
 
5550
        | AUTOEXTEND_SIZE_SYM      {}
5833
5551
        | AVG_ROW_LENGTH           {}
5834
5552
        | AVG_SYM                  {}
 
5553
        | BINLOG_SYM               {}
5835
5554
        | BIT_SYM                  {}
5836
5555
        | BLOCK_SIZE_SYM           {}
5837
5556
        | BLOCK_SYM                {}
5840
5559
        | BTREE_SYM                {}
5841
5560
        | CASCADED                 {}
5842
5561
        | CHAIN_SYM                {}
 
5562
        | CHANGED                  {}
5843
5563
        | COALESCE                 {}
5844
5564
        | COLLATION_SYM            {}
5845
5565
        | COLUMN_FORMAT_SYM        {}
5846
5566
        | COLUMNS                  {}
5847
5567
        | COMMITTED_SYM            {}
5848
5568
        | COMPACT_SYM              {}
 
5569
        | COMPLETION_SYM           {}
5849
5570
        | COMPRESSED_SYM           {}
5850
5571
        | CONCURRENT               {}
5851
5572
        | CONNECTION_SYM           {}
5852
5573
        | CONSISTENT_SYM           {}
 
5574
        | CONTEXT_SYM              {}
5853
5575
        | CUBE_SYM                 {}
5854
5576
        | DATA_SYM                 {}
5855
 
        | DATABASES                {}
5856
5577
        | DATAFILE_SYM             {}
5857
5578
        | DATETIME_SYM             {}
5858
5579
        | DATE_SYM                 {}
5869
5590
        | ESCAPE_SYM               {}
5870
5591
        | EXCLUSIVE_SYM            {}
5871
5592
        | EXTENDED_SYM             {}
 
5593
        | EXTENT_SIZE_SYM          {}
 
5594
        | FAULTS_SYM               {}
 
5595
        | FAST_SYM                 {}
5872
5596
        | FOUND_SYM                {}
5873
5597
        | ENABLE_SYM               {}
5874
5598
        | FULL                     {}
5878
5602
        | FRAC_SECOND_SYM          {}
5879
5603
        | GLOBAL_SYM               {}
5880
5604
        | HASH_SYM                 {}
 
5605
        | HOSTS_SYM                {}
5881
5606
        | HOUR_SYM                 {}
5882
5607
        | IDENTIFIED_SYM           {}
5883
5608
        | IMPORT                   {}
5884
5609
        | INDEXES                  {}
 
5610
        | INITIAL_SIZE_SYM         {}
5885
5611
        | ISOLATION                {}
 
5612
        | INSERT_METHOD            {}
5886
5613
        | KEY_BLOCK_SIZE           {}
5887
5614
        | LAST_SYM                 {}
 
5615
        | LEAVES                   {}
5888
5616
        | LEVEL_SYM                {}
 
5617
        | LINESTRING               {}
5889
5618
        | LIST_SYM                 {}
5890
5619
        | LOCAL_SYM                {}
5891
5620
        | LOCKS_SYM                {}
 
5621
        | LOGFILE_SYM              {}
5892
5622
        | LOGS_SYM                 {}
5893
5623
        | MAX_ROWS                 {}
5894
5624
        | MAX_SIZE_SYM             {}
5896
5626
        | MEDIUM_SYM               {}
5897
5627
        | MERGE_SYM                {}
5898
5628
        | MICROSECOND_SYM          {}
 
5629
        | MIGRATE_SYM              {}
5899
5630
        | MINUTE_SYM               {}
5900
5631
        | MIN_ROWS                 {}
5901
5632
        | MODIFY_SYM               {}
5906
5637
        | NATIONAL_SYM             {}
5907
5638
        | NEXT_SYM                 {}
5908
5639
        | NEW_SYM                  {}
 
5640
        | NO_WAIT_SYM              {}
 
5641
        | NODEGROUP_SYM            {}
5909
5642
        | NONE_SYM                 {}
 
5643
        | NOWAIT_SYM               {}
5910
5644
        | OFFLINE_SYM              {}
5911
5645
        | OFFSET_SYM               {}
5912
5646
        | ONE_SHOT_SYM             {}
5915
5649
        | PAGE_SYM                 {}
5916
5650
        | PARTIAL                  {}
5917
5651
        | PHASE_SYM                {}
 
5652
        | POINT_SYM                {}
5918
5653
        | PREV_SYM                 {}
5919
5654
        | PROCESS                  {}
5920
5655
        | PROCESSLIST_SYM          {}
5921
5656
        | QUARTER_SYM              {}
5922
5657
        | QUERY_SYM                {}
 
5658
        | QUICK                    {}
5923
5659
        | READ_ONLY_SYM            {}
 
5660
        | REBUILD_SYM              {}
 
5661
        | RECOVER_SYM              {}
 
5662
        | REDO_BUFFER_SIZE_SYM     {}
 
5663
        | REDOFILE_SYM             {}
5924
5664
        | REDUNDANT_SYM            {}
 
5665
        | RELOAD                   {}
 
5666
        | REORGANIZE_SYM           {}
5925
5667
        | REPEATABLE_SYM           {}
 
5668
        | REPLICATION              {}
 
5669
        | RESOURCES                {}
 
5670
        | RESUME_SYM               {}
5926
5671
        | RETURNS_SYM              {}
5927
5672
        | REVERSE_SYM              {}
5928
5673
        | ROLLUP_SYM               {}
5938
5683
        | SHARE_SYM                {}
5939
5684
        | SHUTDOWN                 {}
5940
5685
        | SNAPSHOT_SYM             {}
 
5686
        | SOURCE_SYM               {}
5941
5687
        | SQL_BUFFER_RESULT        {}
 
5688
        | STARTS_SYM               {}
5942
5689
        | STATUS_SYM               {}
5943
5690
        | STORAGE_SYM              {}
5944
5691
        | STRING_SYM               {}
5950
5697
        | TABLES                   {}
5951
5698
        | TABLESPACE               {}
5952
5699
        | TEMPORARY_SYM            {}
 
5700
        | TEMPTABLE_SYM            {}
5953
5701
        | TEXT_SYM                 {}
 
5702
        | THAN_SYM                 {}
5954
5703
        | TRANSACTION_SYM          {}
5955
5704
        | TIMESTAMP_SYM            {}
5956
5705
        | TIMESTAMP_ADD            {}
5958
5707
        | TYPES_SYM                {}
5959
5708
        | TYPE_SYM                 {}
5960
5709
        | UNCOMMITTED_SYM          {}
 
5710
        | UNDEFINED_SYM            {}
5961
5711
        | UNDOFILE_SYM             {}
5962
5712
        | UNKNOWN_SYM              {}
 
5713
        | UNTIL_SYM                {}
5963
5714
        | USER                     {}
 
5715
        | USE_FRM                  {}
5964
5716
        | VARIABLES                {}
5965
5717
        | VALUE_SYM                {}
5966
5718
        | WARNINGS                 {}
 
5719
        | WAIT_SYM                 {}
5967
5720
        | WEEK_SYM                 {}
 
5721
        | WEIGHT_STRING_SYM        {}
5968
5722
        | WORK_SYM                 {}
5969
5723
        | YEAR_SYM                 {}
5970
5724
        ;
5976
5730
          {
5977
5731
            LEX *lex=Lex;
5978
5732
            lex->sql_command= SQLCOM_SET_OPTION;
5979
 
            statement::SetOption *statement= new(std::nothrow) statement::SetOption(YYSession);
5980
 
            lex->statement= statement;
 
5733
            lex->statement= new(std::nothrow) statement::SetOption(YYSession);
5981
5734
            if (lex->statement == NULL)
5982
5735
              DRIZZLE_YYABORT;
5983
5736
            mysql_init_select(lex);
5984
5737
            lex->option_type=OPT_SESSION;
5985
5738
            lex->var_list.empty();
 
5739
            lex->one_shot_set= 0;
5986
5740
          }
5987
5741
          option_value_list
5988
5742
          {}
6015
5769
 
6016
5770
option_type2:
6017
5771
          /* empty */ { $$= OPT_DEFAULT; }
6018
 
        | ONE_SHOT_SYM { ((statement::SetOption *)Lex->statement)->one_shot_set= true; $$= OPT_SESSION; }
 
5772
        | ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
6019
5773
        ;
6020
5774
 
6021
5775
opt_var_type:
6131
5885
            lex->statement= new(std::nothrow) statement::StartTransaction(YYSession);
6132
5886
            if (lex->statement == NULL)
6133
5887
              DRIZZLE_YYABORT;
 
5888
            lex->start_transaction_opt= 0;
6134
5889
          }
6135
5890
          opt_work {}
6136
5891
        ;
6164
5919
          {
6165
5920
            LEX *lex=Lex;
6166
5921
            lex->sql_command= SQLCOM_COMMIT;
6167
 
            statement::Commit *statement= new(std::nothrow) statement::Commit(YYSession);
6168
 
            lex->statement= statement;
 
5922
            lex->statement= new(std::nothrow) statement::Commit(YYSession);
6169
5923
            if (lex->statement == NULL)
6170
5924
              DRIZZLE_YYABORT;
6171
 
            statement->tx_chain= $3;
6172
 
            statement->tx_release= $4;
 
5925
            lex->tx_chain= $3; 
 
5926
            lex->tx_release= $4;
6173
5927
          }
6174
5928
        ;
6175
5929
 
6178
5932
          {
6179
5933
            LEX *lex=Lex;
6180
5934
            lex->sql_command= SQLCOM_ROLLBACK;
6181
 
            statement::Rollback *statement= new(std::nothrow) statement::Rollback(YYSession);
6182
 
            lex->statement= statement;
 
5935
            lex->statement= new(std::nothrow) statement::Rollback(YYSession);
6183
5936
            if (lex->statement == NULL)
6184
5937
              DRIZZLE_YYABORT;
6185
 
            statement->tx_chain= $3;
6186
 
            statement->tx_release= $4;
 
5938
            lex->tx_chain= $3; 
 
5939
            lex->tx_release= $4;
6187
5940
          }
6188
5941
        | ROLLBACK_SYM opt_work
6189
5942
          TO_SYM opt_savepoint ident
6290
6043
 
6291
6044
query_specification:
6292
6045
          SELECT_SYM select_init2_derived
6293
 
          {
 
6046
          { 
6294
6047
            $$= Lex->current_select->master_unit()->first_select();
6295
6048
          }
6296
6049
        | '(' select_paren_derived ')'
6302
6055
query_expression_body:
6303
6056
          query_specification
6304
6057
        | query_expression_body
6305
 
          UNION_SYM union_option
 
6058
          UNION_SYM union_option 
6306
6059
          {
6307
6060
            if (add_select_to_union_list(Lex, (bool)$3))
6308
6061
              DRIZZLE_YYABORT;
6317
6070
/* Corresponds to <query expression> in the SQL:2003 standard. */
6318
6071
subselect:
6319
6072
          subselect_start query_expression_body subselect_end
6320
 
          {
 
6073
          { 
6321
6074
            $$= $2;
6322
6075
          }
6323
6076
        ;
6330
6083
              my_parse_error(ER(ER_SYNTAX_ERROR));
6331
6084
              DRIZZLE_YYABORT;
6332
6085
            }
6333
 
            /*
 
6086
            /* 
6334
6087
              we are making a "derived table" for the parenthesis
6335
 
              as we need to have a lex level to fit the union
6336
 
              after the parenthesis, e.g.
6337
 
              (SELECT .. ) UNION ...  becomes
 
6088
              as we need to have a lex level to fit the union 
 
6089
              after the parenthesis, e.g. 
 
6090
              (SELECT .. ) UNION ...  becomes 
6338
6091
              SELECT * FROM ((SELECT ...) UNION ...)
6339
6092
            */
6340
6093
            if (mysql_new_select(Lex, 1))