~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_SQL_LEX_H
21
 
#define DRIZZLED_SQL_LEX_H
 
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
 
21
#define DRIZZLE_SERVER_SQL_LEX_H
22
22
 
23
23
/**
24
24
  @defgroup Semantic_Analysis Semantic Analysis
25
25
*/
26
 
#include <drizzled/message/table.pb.h>
27
 
 
28
 
#include "drizzled/plugin/function.h"
 
26
#include "drizzled/sql_udf.h"
29
27
#include "drizzled/name_resolution_context.h"
30
28
#include "drizzled/item/subselect.h"
 
29
#include "drizzled/item/param.h"
 
30
#include "drizzled/item/outer_ref.h"
31
31
#include "drizzled/table_list.h"
32
32
#include "drizzled/function/math/real.h"
33
33
#include "drizzled/alter_drop.h"
34
34
#include "drizzled/alter_column.h"
35
 
#include "drizzled/alter_info.h"
36
 
#include "drizzled/key_part_spec.h"
 
35
#include "drizzled/key.h"
 
36
#include "drizzled/foreign_key.h"
 
37
#include "drizzled/item/param.h"
37
38
#include "drizzled/index_hint.h"
38
 
#include "drizzled/statement.h"
39
 
#include "drizzled/optimizer/explain_plan.h"
40
 
 
41
 
#include <bitset>
42
 
#include <string>
43
 
 
44
 
namespace drizzled
45
 
{
46
39
 
47
40
class select_result_interceptor;
 
41
class virtual_column_info;
48
42
 
49
43
/* YACC and LEX Definitions */
50
44
 
54
48
class Lex_Column;
55
49
class Item_outer_ref;
56
50
 
57
 
} /* namespace drizzled */
58
 
 
59
51
/*
60
52
  The following hack is needed because mysql_yacc.cc does not define
61
53
  YYSTYPE before including this file
68
60
#  define LEX_YYSTYPE void *
69
61
# else
70
62
#  if defined(DRIZZLE_LEX)
71
 
#   include <drizzled/foreign_key.h>
72
63
#   include <drizzled/lex_symbol.h>
73
64
#   include <drizzled/sql_yacc.h>
74
65
#   define LEX_YYSTYPE YYSTYPE *
87
78
#define DERIVED_NONE    0
88
79
#define DERIVED_SUBQUERY        1
89
80
 
90
 
namespace drizzled
91
 
{
92
 
 
93
81
typedef List<Item> List_item;
94
82
 
 
83
/* SERVERS CACHE CHANGES */
 
84
typedef struct st_lex_server_options
 
85
{
 
86
  int32_t port;
 
87
  uint32_t server_name_length;
 
88
  char *server_name, *host, *db, *username, *password, *scheme, *owner;
 
89
} LEX_SERVER_OPTIONS;
 
90
 
 
91
 
95
92
enum sub_select_type
96
93
{
97
 
  UNSPECIFIED_TYPE,
98
 
  UNION_TYPE,
99
 
  INTERSECT_TYPE,
100
 
  EXCEPT_TYPE,
101
 
  GLOBAL_OPTIONS_TYPE,
102
 
  DERIVED_TABLE_TYPE,
103
 
  OLAP_TYPE
 
94
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
 
95
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
104
96
};
105
97
 
106
98
enum olap_type
107
99
{
108
 
  UNSPECIFIED_OLAP_TYPE,
109
 
  CUBE_TYPE,
110
 
  ROLLUP_TYPE
 
100
  UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
 
101
};
 
102
 
 
103
enum tablespace_op_type
 
104
{
 
105
  NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
111
106
};
112
107
 
113
108
/*
255
250
 
256
251
  static void *operator new(size_t size)
257
252
  {
258
 
    return memory::sql_alloc(size);
 
253
    return sql_alloc(size);
259
254
  }
260
 
  static void *operator new(size_t size, memory::Root *mem_root)
 
255
  static void *operator new(size_t size, MEM_ROOT *mem_root)
261
256
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
262
257
  static void operator delete(void *, size_t)
263
 
  {  }
264
 
  static void operator delete(void *, memory::Root *)
 
258
  { TRASH(ptr, size); }
 
259
  static void operator delete(void *, MEM_ROOT *)
265
260
  {}
266
261
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
267
262
  virtual ~Select_Lex_Node() {}
406
401
public:
407
402
  Name_resolution_context context;
408
403
  char *db;
409
 
  /* An Item representing the WHERE clause */
410
 
  Item *where;
411
 
  /* An Item representing the HAVING clause */
412
 
  Item *having;
 
404
  Item *where, *having;                         /* WHERE & HAVING clauses */
413
405
  /* Saved values of the WHERE and HAVING clauses*/
414
 
  Item::cond_result cond_value;
415
 
  Item::cond_result having_value;
 
406
  Item::cond_result cond_value, having_value;
416
407
  /* point on lex in which it was created, used in view subquery detection */
417
408
  LEX *parent_lex;
418
409
  enum olap_type olap;
419
410
  /* FROM clause - points to the beginning of the TableList::next_local list. */
420
 
  SQL_LIST table_list;
421
 
  SQL_LIST group_list; /* GROUP BY clause. */
422
 
  List<Item> item_list;  /* list of fields & expressions */
423
 
  List<String> interval_list;
424
 
  bool is_item_list_lookup;
 
411
  SQL_LIST            table_list;
 
412
  SQL_LIST            group_list; /* GROUP BY clause. */
 
413
  List<Item>          item_list;  /* list of fields & expressions */
 
414
  List<String>        interval_list;
 
415
  bool                is_item_list_lookup;
 
416
  /*
 
417
    Despite their names, the following are used in unions. This should
 
418
    be rewritten. -Brian
 
419
  */
 
420
  List<Item_real_func> *ftfunc_list;
 
421
  List<Item_real_func> ftfunc_list_alloc;
425
422
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
426
423
  List<TableList> top_join_list; /* join list of the top level          */
427
424
  List<TableList> *join_list;    /* list for the currently parsed join  */
433
430
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
434
431
  */
435
432
  TableList *leaf_tables;
436
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
433
  const char *type;               /* type of select for EXPLAIN          */
437
434
 
438
435
  SQL_LIST order_list;                /* ORDER clause */
439
436
  SQL_LIST *gorder_list;
440
437
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
441
 
  /* Arrays of pointers to top elements of all_fields list */
 
438
  // Arrays of pointers to top elements of all_fields list
442
439
  Item **ref_pointer_array;
443
440
 
444
441
  /*
464
461
  int8_t nest_level;     /* nesting level of select */
465
462
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
466
463
  uint32_t with_wild; /* item list contain '*' */
467
 
  bool braces;          /* SELECT ... UNION (SELECT ... ) <- this braces */
 
464
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
468
465
  /* true when having fix field called in processing of this SELECT */
469
466
  bool having_fix_field;
470
467
  /* List of references to fields referenced from inner selects */
490
487
  /* index in the select list of the expression currently being fixed */
491
488
  int cur_pos_in_select_list;
492
489
 
 
490
  List<Function_builder>     udf_list;                  /* udf function calls stack */
493
491
  /*
494
492
    This is a copy of the original JOIN USING list that comes from
495
493
    the parser. The parser :
513
511
      1 - aggregate functions are used in this select,
514
512
          defined as SUM_FUNC_USED.
515
513
  */
516
 
  std::bitset<2> full_group_by_flag;
 
514
  uint8_t full_group_by_flag;
517
515
  void init_query();
518
516
  void init_select();
519
517
  Select_Lex_Unit* master_unit();
522
520
    return (Select_Lex_Unit*) slave;
523
521
  }
524
522
  Select_Lex* outer_select();
525
 
  Select_Lex* next_select()
526
 
  {
527
 
    return (Select_Lex*) next;
528
 
  }
 
523
  Select_Lex* next_select() { return (Select_Lex*) next; }
529
524
  Select_Lex* next_select_in_list()
530
525
  {
531
526
    return (Select_Lex*) link_next;
548
543
  bool add_item_to_list(Session *session, Item *item);
549
544
  bool add_group_to_list(Session *session, Item *item, bool asc);
550
545
  bool add_order_to_list(Session *session, Item *item, bool asc);
551
 
  TableList* add_table_to_list(Session *session,
552
 
                               Table_ident *table,
553
 
                               LEX_STRING *alias,
554
 
                               uint32_t table_options,
555
 
                               thr_lock_type flags= TL_UNLOCK,
556
 
                               List<Index_hint> *hints= 0,
557
 
                               LEX_STRING *option= 0);
 
546
  TableList* add_table_to_list(Session *session, Table_ident *table,
 
547
                                LEX_STRING *alias,
 
548
                                uint32_t table_options,
 
549
                                thr_lock_type flags= TL_UNLOCK,
 
550
                                List<Index_hint> *hints= 0,
 
551
                                LEX_STRING *option= 0);
558
552
  TableList* get_table_list();
559
553
  bool init_nested_join(Session *session);
560
554
  TableList *end_nested_join(Session *session);
576
570
    to LEX (LEX::unit & LEX::select, for other purposes there are
577
571
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
578
572
  */
579
 
  void cut_subtree()
580
 
  {
581
 
    slave= 0;
582
 
  }
 
573
  void cut_subtree() { slave= 0; }
583
574
  bool test_limit();
584
575
 
585
576
  friend void lex_start(Session *session);
641
632
    first_select()->next_select()->linkage == UNION_TYPE;
642
633
}
643
634
 
644
 
enum xa_option_words
 
635
#define ALTER_ADD_COLUMN        (1L << 0)
 
636
#define ALTER_DROP_COLUMN       (1L << 1)
 
637
#define ALTER_CHANGE_COLUMN     (1L << 2)
 
638
#define ALTER_COLUMN_STORAGE    (1L << 3)
 
639
#define ALTER_COLUMN_FORMAT     (1L << 4)
 
640
#define ALTER_COLUMN_ORDER      (1L << 5)
 
641
#define ALTER_ADD_INDEX         (1L << 6)
 
642
#define ALTER_DROP_INDEX        (1L << 7)
 
643
#define ALTER_RENAME            (1L << 8)
 
644
#define ALTER_ORDER             (1L << 9)
 
645
#define ALTER_OPTIONS           (1L << 10)
 
646
#define ALTER_COLUMN_DEFAULT    (1L << 11)
 
647
#define ALTER_KEYS_ONOFF        (1L << 12)
 
648
#define ALTER_STORAGE           (1L << 13)
 
649
#define ALTER_ROW_FORMAT        (1L << 14)
 
650
#define ALTER_CONVERT           (1L << 15)
 
651
#define ALTER_FORCE             (1L << 16)
 
652
#define ALTER_RECREATE          (1L << 17)
 
653
#define ALTER_TABLE_REORG        (1L << 24)
 
654
#define ALTER_FOREIGN_KEY         (1L << 31)
 
655
 
 
656
/**
 
657
  @brief Parsing data for CREATE or ALTER Table.
 
658
 
 
659
  This structure contains a list of columns or indexes to be created,
 
660
  altered or dropped.
 
661
*/
 
662
 
 
663
class Alter_info
645
664
{
646
 
  XA_NONE
647
 
, XA_JOIN
648
 
, XA_RESUME
649
 
, XA_ONE_PHASE
650
 
, XA_SUSPEND
651
 
, XA_FOR_MIGRATE
 
665
public:
 
666
  List<Alter_drop>              drop_list;
 
667
  List<Alter_column>            alter_list;
 
668
  List<Key>                     key_list;
 
669
  List<Create_field>            create_list;
 
670
  uint32_t                          flags;
 
671
  enum enum_enable_or_disable   keys_onoff;
 
672
  enum tablespace_op_type       tablespace_op;
 
673
  uint32_t                          no_parts;
 
674
  enum ha_build_method          build_method;
 
675
  Create_field                 *datetime_field;
 
676
  bool                          error_if_not_empty;
 
677
 
 
678
 
 
679
  Alter_info() :
 
680
    flags(0),
 
681
    keys_onoff(LEAVE_AS_IS),
 
682
    tablespace_op(NO_TABLESPACE_OP),
 
683
    no_parts(0),
 
684
    build_method(HA_BUILD_DEFAULT),
 
685
    datetime_field(NULL),
 
686
    error_if_not_empty(false)
 
687
  {}
 
688
 
 
689
  void reset()
 
690
  {
 
691
    drop_list.empty();
 
692
    alter_list.empty();
 
693
    key_list.empty();
 
694
    create_list.empty();
 
695
    flags= 0;
 
696
    keys_onoff= LEAVE_AS_IS;
 
697
    tablespace_op= NO_TABLESPACE_OP;
 
698
    no_parts= 0;
 
699
    build_method= HA_BUILD_DEFAULT;
 
700
    datetime_field= 0;
 
701
    error_if_not_empty= false;
 
702
  }
 
703
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
 
704
private:
 
705
  Alter_info &operator=(const Alter_info &rhs); // not implemented
 
706
  Alter_info(const Alter_info &rhs);            // not implemented
652
707
};
653
708
 
 
709
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
 
710
                      XA_SUSPEND, XA_FOR_MIGRATE};
 
711
 
654
712
extern const LEX_STRING null_lex_str;
655
713
 
 
714
 
656
715
/*
657
716
  Class representing list of all tables used by statement.
658
717
  It also contains information about stored functions used by statement
663
722
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
664
723
  methods to save and restore this information.
665
724
*/
 
725
 
666
726
class Query_tables_list
667
727
{
668
728
public:
683
743
    of Query_tables_list instances which are used as backup storage.
684
744
  */
685
745
  Query_tables_list() {}
686
 
  virtual ~Query_tables_list() {}
 
746
  ~Query_tables_list() {}
687
747
 
688
748
  /* Initializes (or resets) Query_tables_list object for "real" use. */
689
749
  void reset_query_tables_list(bool init);
 
750
  void destroy_query_tables_list();
 
751
  void set_query_tables_list(Query_tables_list *state)
 
752
  {
 
753
    *this= *state;
 
754
  }
690
755
 
691
756
  /*
692
757
    Direct addition to the list of query tables.
714
779
  }
715
780
};
716
781
 
 
782
 
 
783
/*
 
784
  st_parsing_options contains the flags for constructions that are
 
785
  allowed in the current statement.
 
786
*/
 
787
 
 
788
struct st_parsing_options
 
789
{
 
790
  bool allows_select_procedure;
 
791
 
 
792
  st_parsing_options() { reset(); }
 
793
  void reset();
 
794
};
 
795
 
 
796
 
717
797
/**
718
798
  The state of the lexical parser, when parsing comments.
719
799
*/
737
817
  DISCARD_COMMENT
738
818
};
739
819
 
740
 
} /* namespace drizzled */
741
 
 
742
 
#include "drizzled/lex_input_stream.h"
743
 
 
744
 
namespace drizzled
 
820
 
 
821
/**
 
822
  @brief This class represents the character input stream consumed during
 
823
  lexical analysis.
 
824
 
 
825
  In addition to consuming the input stream, this class performs some
 
826
  comment pre processing, by filtering out out of bound special text
 
827
  from the query input stream.
 
828
  Two buffers, with pointers inside each buffers, are maintained in
 
829
  parallel. The 'raw' buffer is the original query text, which may
 
830
  contain out-of-bound comments. The 'cpp' (for comments pre processor)
 
831
  is the pre-processed buffer that contains only the query text that
 
832
  should be seen once out-of-bound data is removed.
 
833
*/
 
834
 
 
835
class Lex_input_stream
745
836
{
 
837
public:
 
838
  Lex_input_stream(Session *session, const char* buff, unsigned int length);
 
839
  ~Lex_input_stream();
 
840
 
 
841
  /**
 
842
    Set the echo mode.
 
843
 
 
844
    When echo is true, characters parsed from the raw input stream are
 
845
    preserved. When false, characters parsed are silently ignored.
 
846
    @param echo the echo mode.
 
847
  */
 
848
  void set_echo(bool echo)
 
849
  {
 
850
    m_echo= echo;
 
851
  }
 
852
 
 
853
  /**
 
854
    Skip binary from the input stream.
 
855
    @param n number of bytes to accept.
 
856
  */
 
857
  void skip_binary(int n)
 
858
  {
 
859
    if (m_echo)
 
860
    {
 
861
      memcpy(m_cpp_ptr, m_ptr, n);
 
862
      m_cpp_ptr += n;
 
863
    }
 
864
    m_ptr += n;
 
865
  }
 
866
 
 
867
  /**
 
868
    Get a character, and advance in the stream.
 
869
    @return the next character to parse.
 
870
  */
 
871
  char yyGet()
 
872
  {
 
873
    char c= *m_ptr++;
 
874
    if (m_echo)
 
875
      *m_cpp_ptr++ = c;
 
876
    return c;
 
877
  }
 
878
 
 
879
  /**
 
880
    Get the last character accepted.
 
881
    @return the last character accepted.
 
882
  */
 
883
  char yyGetLast()
 
884
  {
 
885
    return m_ptr[-1];
 
886
  }
 
887
 
 
888
  /**
 
889
    Look at the next character to parse, but do not accept it.
 
890
  */
 
891
  char yyPeek()
 
892
  {
 
893
    return m_ptr[0];
 
894
  }
 
895
 
 
896
  /**
 
897
    Look ahead at some character to parse.
 
898
    @param n offset of the character to look up
 
899
  */
 
900
  char yyPeekn(int n)
 
901
  {
 
902
    return m_ptr[n];
 
903
  }
 
904
 
 
905
  /**
 
906
    Cancel the effect of the last yyGet() or yySkip().
 
907
    Note that the echo mode should not change between calls to yyGet / yySkip
 
908
    and yyUnget. The caller is responsible for ensuring that.
 
909
  */
 
910
  void yyUnget()
 
911
  {
 
912
    m_ptr--;
 
913
    if (m_echo)
 
914
      m_cpp_ptr--;
 
915
  }
 
916
 
 
917
  /**
 
918
    Accept a character, by advancing the input stream.
 
919
  */
 
920
  void yySkip()
 
921
  {
 
922
    if (m_echo)
 
923
      *m_cpp_ptr++ = *m_ptr++;
 
924
    else
 
925
      m_ptr++;
 
926
  }
 
927
 
 
928
  /**
 
929
    Accept multiple characters at once.
 
930
    @param n the number of characters to accept.
 
931
  */
 
932
  void yySkipn(int n)
 
933
  {
 
934
    if (m_echo)
 
935
    {
 
936
      memcpy(m_cpp_ptr, m_ptr, n);
 
937
      m_cpp_ptr += n;
 
938
    }
 
939
    m_ptr += n;
 
940
  }
 
941
 
 
942
  /**
 
943
    End of file indicator for the query text to parse.
 
944
    @return true if there are no more characters to parse
 
945
  */
 
946
  bool eof()
 
947
  {
 
948
    return (m_ptr >= m_end_of_query);
 
949
  }
 
950
 
 
951
  /**
 
952
    End of file indicator for the query text to parse.
 
953
    @param n number of characters expected
 
954
    @return true if there are less than n characters to parse
 
955
  */
 
956
  bool eof(int n)
 
957
  {
 
958
    return ((m_ptr + n) >= m_end_of_query);
 
959
  }
 
960
 
 
961
  /** Get the raw query buffer. */
 
962
  const char *get_buf()
 
963
  {
 
964
    return m_buf;
 
965
  }
 
966
 
 
967
  /** Get the pre-processed query buffer. */
 
968
  const char *get_cpp_buf()
 
969
  {
 
970
    return m_cpp_buf;
 
971
  }
 
972
 
 
973
  /** Get the end of the raw query buffer. */
 
974
  const char *get_end_of_query()
 
975
  {
 
976
    return m_end_of_query;
 
977
  }
 
978
 
 
979
  /** Mark the stream position as the start of a new token. */
 
980
  void start_token()
 
981
  {
 
982
    m_tok_start_prev= m_tok_start;
 
983
    m_tok_start= m_ptr;
 
984
    m_tok_end= m_ptr;
 
985
 
 
986
    m_cpp_tok_start_prev= m_cpp_tok_start;
 
987
    m_cpp_tok_start= m_cpp_ptr;
 
988
    m_cpp_tok_end= m_cpp_ptr;
 
989
  }
 
990
 
 
991
  /**
 
992
    Adjust the starting position of the current token.
 
993
    This is used to compensate for starting whitespace.
 
994
  */
 
995
  void restart_token()
 
996
  {
 
997
    m_tok_start= m_ptr;
 
998
    m_cpp_tok_start= m_cpp_ptr;
 
999
  }
 
1000
 
 
1001
  /** Get the token start position, in the raw buffer. */
 
1002
  const char *get_tok_start()
 
1003
  {
 
1004
    return m_tok_start;
 
1005
  }
 
1006
 
 
1007
  /** Get the token start position, in the pre-processed buffer. */
 
1008
  const char *get_cpp_tok_start()
 
1009
  {
 
1010
    return m_cpp_tok_start;
 
1011
  }
 
1012
 
 
1013
  /** Get the token end position, in the raw buffer. */
 
1014
  const char *get_tok_end()
 
1015
  {
 
1016
    return m_tok_end;
 
1017
  }
 
1018
 
 
1019
  /** Get the token end position, in the pre-processed buffer. */
 
1020
  const char *get_cpp_tok_end()
 
1021
  {
 
1022
    return m_cpp_tok_end;
 
1023
  }
 
1024
 
 
1025
  /** Get the previous token start position, in the raw buffer. */
 
1026
  const char *get_tok_start_prev()
 
1027
  {
 
1028
    return m_tok_start_prev;
 
1029
  }
 
1030
 
 
1031
  /** Get the current stream pointer, in the raw buffer. */
 
1032
  const char *get_ptr()
 
1033
  {
 
1034
    return m_ptr;
 
1035
  }
 
1036
 
 
1037
  /** Get the current stream pointer, in the pre-processed buffer. */
 
1038
  const char *get_cpp_ptr()
 
1039
  {
 
1040
    return m_cpp_ptr;
 
1041
  }
 
1042
 
 
1043
  /** Get the length of the current token, in the raw buffer. */
 
1044
  uint32_t yyLength()
 
1045
  {
 
1046
    /*
 
1047
      The assumption is that the lexical analyser is always 1 character ahead,
 
1048
      which the -1 account for.
 
1049
    */
 
1050
    assert(m_ptr > m_tok_start);
 
1051
    return (uint32_t) ((m_ptr - m_tok_start) - 1);
 
1052
  }
 
1053
 
 
1054
  /** Get the utf8-body string. */
 
1055
  const char *get_body_utf8_str()
 
1056
  {
 
1057
    return m_body_utf8;
 
1058
  }
 
1059
 
 
1060
  /** Get the utf8-body length. */
 
1061
  uint32_t get_body_utf8_length()
 
1062
  {
 
1063
    return m_body_utf8_ptr - m_body_utf8;
 
1064
  }
 
1065
 
 
1066
  void body_utf8_start(Session *session, const char *begin_ptr);
 
1067
  void body_utf8_append(const char *ptr);
 
1068
  void body_utf8_append(const char *ptr, const char *end_ptr);
 
1069
  void body_utf8_append_literal(Session *session,
 
1070
                                const LEX_STRING *txt,
 
1071
                                const CHARSET_INFO * const txt_cs,
 
1072
                                const char *end_ptr);
 
1073
 
 
1074
  /** Current thread. */
 
1075
  Session *m_session;
 
1076
 
 
1077
  /** Current line number. */
 
1078
  uint32_t yylineno;
 
1079
 
 
1080
  /** Length of the last token parsed. */
 
1081
  uint32_t yytoklen;
 
1082
 
 
1083
  /** Interface with bison, value of the last token parsed. */
 
1084
  LEX_YYSTYPE yylval;
 
1085
 
 
1086
  /** LALR(2) resolution, look ahead token.*/
 
1087
  int lookahead_token;
 
1088
 
 
1089
  /** LALR(2) resolution, value of the look ahead token.*/
 
1090
  LEX_YYSTYPE lookahead_yylval;
 
1091
 
 
1092
private:
 
1093
  /** Pointer to the current position in the raw input stream. */
 
1094
  const char *m_ptr;
 
1095
 
 
1096
  /** Starting position of the last token parsed, in the raw buffer. */
 
1097
  const char *m_tok_start;
 
1098
 
 
1099
  /** Ending position of the previous token parsed, in the raw buffer. */
 
1100
  const char *m_tok_end;
 
1101
 
 
1102
  /** End of the query text in the input stream, in the raw buffer. */
 
1103
  const char *m_end_of_query;
 
1104
 
 
1105
  /** Starting position of the previous token parsed, in the raw buffer. */
 
1106
  const char *m_tok_start_prev;
 
1107
 
 
1108
  /** Begining of the query text in the input stream, in the raw buffer. */
 
1109
  const char *m_buf;
 
1110
 
 
1111
  /** Length of the raw buffer. */
 
1112
  uint32_t m_buf_length;
 
1113
 
 
1114
  /** Echo the parsed stream to the pre-processed buffer. */
 
1115
  bool m_echo;
 
1116
 
 
1117
  /** Pre-processed buffer. */
 
1118
  char *m_cpp_buf;
 
1119
 
 
1120
  /** Pointer to the current position in the pre-processed input stream. */
 
1121
  char *m_cpp_ptr;
 
1122
 
 
1123
  /**
 
1124
    Starting position of the last token parsed,
 
1125
    in the pre-processed buffer.
 
1126
  */
 
1127
  const char *m_cpp_tok_start;
 
1128
 
 
1129
  /**
 
1130
    Starting position of the previous token parsed,
 
1131
    in the pre-procedded buffer.
 
1132
  */
 
1133
  const char *m_cpp_tok_start_prev;
 
1134
 
 
1135
  /**
 
1136
    Ending position of the previous token parsed,
 
1137
    in the pre-processed buffer.
 
1138
  */
 
1139
  const char *m_cpp_tok_end;
 
1140
 
 
1141
  /** UTF8-body buffer created during parsing. */
 
1142
  char *m_body_utf8;
 
1143
 
 
1144
  /** Pointer to the current position in the UTF8-body buffer. */
 
1145
  char *m_body_utf8_ptr;
 
1146
 
 
1147
  /**
 
1148
    Position in the pre-processed buffer. The query from m_cpp_buf to
 
1149
    m_cpp_utf_processed_ptr is converted to UTF8-body.
 
1150
  */
 
1151
  const char *m_cpp_utf8_processed_ptr;
 
1152
 
 
1153
public:
 
1154
 
 
1155
  /** Current state of the lexical analyser. */
 
1156
  enum my_lex_states next_state;
 
1157
 
 
1158
  /**
 
1159
    Position of ';' in the stream, to delimit multiple queries.
 
1160
    This delimiter is in the raw buffer.
 
1161
  */
 
1162
  const char *found_semicolon;
 
1163
 
 
1164
  /** Token character bitmaps, to detect 7bit strings. */
 
1165
  unsigned char tok_bitmap;
 
1166
 
 
1167
  /** SQL_MODE = IGNORE_SPACE. */
 
1168
  bool ignore_space;
 
1169
 
 
1170
  /** State of the lexical analyser for comments. */
 
1171
  enum_comment_state in_comment;
 
1172
 
 
1173
  /**
 
1174
    Starting position of the TEXT_STRING or IDENT in the pre-processed
 
1175
    buffer.
 
1176
 
 
1177
    NOTE: this member must be used within DRIZZLElex() function only.
 
1178
  */
 
1179
  const char *m_cpp_text_start;
 
1180
 
 
1181
  /**
 
1182
    Ending position of the TEXT_STRING or IDENT in the pre-processed
 
1183
    buffer.
 
1184
 
 
1185
    NOTE: this member must be used within DRIZZLElex() function only.
 
1186
    */
 
1187
  const char *m_cpp_text_end;
 
1188
 
 
1189
  /**
 
1190
    Character set specified by the character-set-introducer.
 
1191
 
 
1192
    NOTE: this member must be used within DRIZZLElex() function only.
 
1193
  */
 
1194
  const CHARSET_INFO *m_underscore_cs;
 
1195
};
 
1196
 
746
1197
 
747
1198
/* The state of the lex parsing. This is saved in the Session struct */
 
1199
 
748
1200
class LEX : public Query_tables_list
749
1201
{
750
1202
public:
755
1207
  /* list of all Select_Lex */
756
1208
  Select_Lex *all_selects_list;
757
1209
 
758
 
  /* This is the "scale" for DECIMAL (S,P) notation */ 
759
 
  char *length;
760
 
  /* This is the decimal precision in DECIMAL(S,P) notation */
761
 
  char *dec;
762
 
  
763
 
  /**
764
 
   * This is used kind of like the "ident" member variable below, as 
765
 
   * a place to store certain names of identifiers.  Unfortunately, it
766
 
   * is used differently depending on the Command (SELECT on a derived
767
 
   * table vs CREATE)
768
 
   */
 
1210
  char *length,*dec,*change;
769
1211
  LEX_STRING name;
770
 
  /* The string literal used in a LIKE expression */
771
1212
  String *wild;
772
1213
  file_exchange *exchange;
773
1214
  select_result *result;
774
 
 
775
 
  /**
776
 
   * This is current used to store the name of a named key cache
777
 
   * or a named savepoint.  It should probably be refactored out into
778
 
   * the eventual Command class built for the Keycache and Savepoint
779
 
   * commands.
780
 
   */ 
781
 
  LEX_STRING ident;
782
 
 
 
1215
  Item *default_value, *on_update_value;
 
1216
  LEX_STRING comment, ident;
 
1217
  XID *xid;
783
1218
  unsigned char* yacc_yyss, *yacc_yyvs;
784
 
  /* The owning Session of this LEX */
785
1219
  Session *session;
 
1220
  virtual_column_info *vcol_info;
 
1221
 
786
1222
  const CHARSET_INFO *charset;
787
1223
  bool text_string_is_7bit;
788
1224
  /* store original leaf_tables for INSERT SELECT and PS/SP */
795
1231
  List<Item>          *insert_list,field_list,value_list,update_list;
796
1232
  List<List_item>     many_values;
797
1233
  List<set_var_base>  var_list;
 
1234
  List<Item_param>    param_list;
798
1235
  /*
799
1236
    A stack of name resolution contexts for the query. This stack is used
800
1237
    at parse time to set local name resolution contexts for various parts
809
1246
    required a local context, the parser pops the top-most context.
810
1247
  */
811
1248
  List<Name_resolution_context> context_stack;
 
1249
  List<LEX_STRING>     db_list;
812
1250
 
813
 
  SQL_LIST auxiliary_table_list;
814
 
  SQL_LIST save_list;
815
 
  CreateField *last_field;
 
1251
  SQL_LIST            auxiliary_table_list, save_list;
 
1252
  Create_field        *last_field;
816
1253
  Item_sum *in_sum_func;
817
 
  plugin::Function *udf;
 
1254
  Function_builder *udf;
 
1255
  HA_CHECK_OPT   check_opt;                     // check/repair options
 
1256
  HA_CREATE_INFO create_info;
 
1257
  KEY_CREATE_INFO key_create_info;
818
1258
  uint32_t type;
819
1259
  /*
820
1260
    This variable is used in post-parse stage to declare that sum-functions,
827
1267
  */
828
1268
  nesting_map allow_sum_func;
829
1269
  enum_sql_command sql_command;
830
 
  statement::Statement *statement;
831
1270
  /*
832
1271
    Usually `expr` rule of yacc is quite reused but some commands better
833
1272
    not support subqueries which comes standard with this rule, like
835
1274
    syntax error back.
836
1275
  */
837
1276
  bool expr_allows_subselect;
 
1277
  /*
 
1278
    A special command "PARSE_VCOL_EXPR" is defined for the parser
 
1279
    to translate an expression statement of a virtual column \
 
1280
    (stored in the *.frm file as a string) into an Item object.
 
1281
    The following flag is used to prevent other applications to use
 
1282
    this command.
 
1283
  */
 
1284
  bool parse_vcol_expr;
838
1285
 
839
1286
  thr_lock_type lock_option;
840
1287
  enum enum_duplicates duplicates;
 
1288
  enum enum_tx_isolation tx_isolation;
 
1289
  enum enum_ha_read_modes ha_read_mode;
841
1290
  union {
842
1291
    enum ha_rkey_function ha_rkey_mode;
843
1292
    enum xa_option_words xa_opt;
 
1293
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
844
1294
  };
845
 
  sql_var_t option_type;
 
1295
  enum enum_var_type option_type;
846
1296
 
 
1297
  uint32_t profile_query_id;
 
1298
  uint32_t profile_options;
 
1299
  enum column_format_type column_format;
 
1300
  uint32_t which_columns;
 
1301
  enum Foreign_key::fk_match_opt fk_match_option;
 
1302
  enum Foreign_key::fk_option fk_update_opt;
 
1303
  enum Foreign_key::fk_option fk_delete_opt;
 
1304
  uint32_t slave_session_opt, start_transaction_opt;
847
1305
  int nest_level;
 
1306
  /*
 
1307
    In LEX representing update which were transformed to multi-update
 
1308
    stores total number of tables. For LEX representing multi-delete
 
1309
    holds number of tables from which we will delete records.
 
1310
  */
 
1311
  uint32_t table_count;
848
1312
  uint8_t describe;
849
1313
  /*
850
1314
    A flag that indicates what kinds of derived tables are present in the
851
1315
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
852
1316
  */
853
1317
  uint8_t derived_tables;
854
 
 
855
 
  /* Was the IGNORE symbol found in statement */
856
 
  bool ignore;
 
1318
  bool drop_if_exists, drop_temporary, one_shot_set;
 
1319
  bool autocommit;
 
1320
  bool verbose;
 
1321
 
 
1322
  bool tx_chain, tx_release;
 
1323
  bool subqueries, ignore;
 
1324
  st_parsing_options parsing_options;
 
1325
  Alter_info alter_info;
 
1326
 
 
1327
  /*
 
1328
    Pointers to part of LOAD DATA statement that should be rewritten
 
1329
    during replication ("LOCAL 'filename' REPLACE INTO" part).
 
1330
  */
 
1331
  const char *fname_start;
 
1332
  const char *fname_end;
857
1333
 
858
1334
  /**
859
1335
    During name resolution search only in the table list given by
863
1339
  */
864
1340
  bool use_only_table_context;
865
1341
 
866
 
  /* Was the ESCAPE keyword used? */
867
1342
  bool escape_used;
868
1343
  bool is_lex_started; /* If lex_start() did run. For debugging. */
869
1344
 
870
1345
  LEX();
871
1346
 
872
 
  /* Note that init and de-init mostly happen in lex_start and lex_end
873
 
     and not here. This is because LEX isn't delete/new for each new
874
 
     statement in a session. It's re-used by doing lex_end, lex_start
875
 
     in sql_lex.cc
876
 
  */
877
1347
  virtual ~LEX()
878
1348
  {
 
1349
    destroy_query_tables_list();
879
1350
  }
880
1351
 
881
1352
  TableList *unlink_first_table(bool *link_to_local);
931
1402
  }
932
1403
};
933
1404
 
 
1405
struct st_lex_local: public LEX
 
1406
{
 
1407
  static void *operator new(size_t size) throw()
 
1408
  {
 
1409
    return sql_alloc(size);
 
1410
  }
 
1411
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
 
1412
  {
 
1413
    return (void*) alloc_root(mem_root, (uint32_t) size);
 
1414
  }
 
1415
  static void operator delete(void *, size_t)
 
1416
  { TRASH(ptr, size); }
 
1417
  static void operator delete(void *, MEM_ROOT *)
 
1418
  { /* Never called */ }
 
1419
};
 
1420
 
934
1421
extern void lex_start(Session *session);
935
1422
extern void lex_end(LEX *lex);
 
1423
 
936
1424
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
 
1425
 
937
1426
extern bool is_lex_native_function(const LEX_STRING *name);
938
1427
 
939
1428
/**
940
1429
  @} (End of group Semantic_Analysis)
941
1430
*/
942
1431
 
943
 
} /* namespace drizzled */
944
 
 
945
1432
#endif /* DRIZZLE_SERVER */
946
 
#endif /* DRIZZLED_SQL_LEX_H */
 
1433
#endif /* DRIZZLE_SERVER_SQL_LEX_H */