~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Brian Aker
  • Date: 2010-04-05 23:46:43 UTC
  • Revision ID: brian@gaz-20100405234643-0he3xnj902rc70r8
Fixing tests to work with PBXT.

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 DRIZZLE_SERVER_SQL_LEX_H
21
 
#define DRIZZLE_SERVER_SQL_LEX_H
 
20
#ifndef DRIZZLED_SQL_LEX_H
 
21
#define DRIZZLED_SQL_LEX_H
22
22
 
23
23
/**
24
24
  @defgroup Semantic_Analysis Semantic Analysis
25
25
*/
26
 
#include "drizzled/sql_udf.h"
 
26
#include <drizzled/message/table.pb.h>
 
27
 
 
28
#include "drizzled/plugin/function.h"
27
29
#include "drizzled/name_resolution_context.h"
28
30
#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/key.h"
36
 
#include "drizzled/foreign_key.h"
37
 
#include "drizzled/item/param.h"
 
35
#include "drizzled/alter_info.h"
 
36
#include "drizzled/key_part_spec.h"
38
37
#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
{
39
46
 
40
47
class select_result_interceptor;
41
 
class virtual_column_info;
42
48
 
43
49
/* YACC and LEX Definitions */
44
50
 
48
54
class Lex_Column;
49
55
class Item_outer_ref;
50
56
 
 
57
} /* namespace drizzled */
 
58
 
51
59
/*
52
60
  The following hack is needed because mysql_yacc.cc does not define
53
61
  YYSTYPE before including this file
60
68
#  define LEX_YYSTYPE void *
61
69
# else
62
70
#  if defined(DRIZZLE_LEX)
 
71
#   include <drizzled/foreign_key.h>
63
72
#   include <drizzled/lex_symbol.h>
64
73
#   include <drizzled/sql_yacc.h>
65
74
#   define LEX_YYSTYPE YYSTYPE *
78
87
#define DERIVED_NONE    0
79
88
#define DERIVED_SUBQUERY        1
80
89
 
 
90
namespace drizzled
 
91
{
 
92
 
81
93
typedef List<Item> List_item;
82
94
 
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
 
 
92
95
enum sub_select_type
93
96
{
94
 
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
95
 
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
 
97
  UNSPECIFIED_TYPE,
 
98
  UNION_TYPE,
 
99
  INTERSECT_TYPE,
 
100
  EXCEPT_TYPE,
 
101
  GLOBAL_OPTIONS_TYPE,
 
102
  DERIVED_TABLE_TYPE,
 
103
  OLAP_TYPE
96
104
};
97
105
 
98
106
enum olap_type
99
107
{
100
 
  UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
101
 
};
102
 
 
103
 
enum tablespace_op_type
104
 
{
105
 
  NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
 
108
  UNSPECIFIED_OLAP_TYPE,
 
109
  CUBE_TYPE,
 
110
  ROLLUP_TYPE
106
111
};
107
112
 
108
113
/*
250
255
 
251
256
  static void *operator new(size_t size)
252
257
  {
253
 
    return sql_alloc(size);
 
258
    return memory::sql_alloc(size);
254
259
  }
255
 
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
260
  static void *operator new(size_t size, memory::Root *mem_root)
256
261
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
257
262
  static void operator delete(void *, size_t)
258
 
  { TRASH(ptr, size); }
259
 
  static void operator delete(void *, MEM_ROOT *)
 
263
  {  }
 
264
  static void operator delete(void *, memory::Root *)
260
265
  {}
261
266
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
262
267
  virtual ~Select_Lex_Node() {}
401
406
public:
402
407
  Name_resolution_context context;
403
408
  char *db;
404
 
  Item *where, *having;                         /* WHERE & HAVING clauses */
 
409
  /* An Item representing the WHERE clause */
 
410
  Item *where;
 
411
  /* An Item representing the HAVING clause */
 
412
  Item *having;
405
413
  /* Saved values of the WHERE and HAVING clauses*/
406
 
  Item::cond_result cond_value, having_value;
 
414
  Item::cond_result cond_value;
 
415
  Item::cond_result having_value;
407
416
  /* point on lex in which it was created, used in view subquery detection */
408
417
  LEX *parent_lex;
409
418
  enum olap_type olap;
410
419
  /* FROM clause - points to the beginning of the TableList::next_local list. */
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;
 
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;
422
425
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
423
426
  List<TableList> top_join_list; /* join list of the top level          */
424
427
  List<TableList> *join_list;    /* list for the currently parsed join  */
430
433
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
431
434
  */
432
435
  TableList *leaf_tables;
433
 
  const char *type;               /* type of select for EXPLAIN          */
 
436
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
434
437
 
435
438
  SQL_LIST order_list;                /* ORDER clause */
436
439
  SQL_LIST *gorder_list;
437
440
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
438
 
  // Arrays of pointers to top elements of all_fields list
 
441
  /* Arrays of pointers to top elements of all_fields list */
439
442
  Item **ref_pointer_array;
440
443
 
441
444
  /*
461
464
  int8_t nest_level;     /* nesting level of select */
462
465
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
463
466
  uint32_t with_wild; /* item list contain '*' */
464
 
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
 
467
  bool braces;          /* SELECT ... UNION (SELECT ... ) <- this braces */
465
468
  /* true when having fix field called in processing of this SELECT */
466
469
  bool having_fix_field;
467
470
  /* List of references to fields referenced from inner selects */
487
490
  /* index in the select list of the expression currently being fixed */
488
491
  int cur_pos_in_select_list;
489
492
 
490
 
  List<Function_builder>     udf_list;                  /* udf function calls stack */
491
493
  /*
492
494
    This is a copy of the original JOIN USING list that comes from
493
495
    the parser. The parser :
511
513
      1 - aggregate functions are used in this select,
512
514
          defined as SUM_FUNC_USED.
513
515
  */
514
 
  uint8_t full_group_by_flag;
 
516
  std::bitset<2> full_group_by_flag;
515
517
  void init_query();
516
518
  void init_select();
517
519
  Select_Lex_Unit* master_unit();
520
522
    return (Select_Lex_Unit*) slave;
521
523
  }
522
524
  Select_Lex* outer_select();
523
 
  Select_Lex* next_select() { return (Select_Lex*) next; }
 
525
  Select_Lex* next_select()
 
526
  {
 
527
    return (Select_Lex*) next;
 
528
  }
524
529
  Select_Lex* next_select_in_list()
525
530
  {
526
531
    return (Select_Lex*) link_next;
543
548
  bool add_item_to_list(Session *session, Item *item);
544
549
  bool add_group_to_list(Session *session, Item *item, bool asc);
545
550
  bool add_order_to_list(Session *session, Item *item, bool asc);
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);
 
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);
552
558
  TableList* get_table_list();
553
559
  bool init_nested_join(Session *session);
554
560
  TableList *end_nested_join(Session *session);
570
576
    to LEX (LEX::unit & LEX::select, for other purposes there are
571
577
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
572
578
  */
573
 
  void cut_subtree() { slave= 0; }
 
579
  void cut_subtree()
 
580
  {
 
581
    slave= 0;
 
582
  }
574
583
  bool test_limit();
575
584
 
576
585
  friend void lex_start(Session *session);
632
641
    first_select()->next_select()->linkage == UNION_TYPE;
633
642
}
634
643
 
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
 
644
enum xa_option_words
664
645
{
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
 
646
  XA_NONE
 
647
, XA_JOIN
 
648
, XA_RESUME
 
649
, XA_ONE_PHASE
 
650
, XA_SUSPEND
 
651
, XA_FOR_MIGRATE
707
652
};
708
653
 
709
 
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
710
 
                      XA_SUSPEND, XA_FOR_MIGRATE};
711
 
 
712
654
extern const LEX_STRING null_lex_str;
713
655
 
714
 
 
715
656
/*
716
657
  Class representing list of all tables used by statement.
717
658
  It also contains information about stored functions used by statement
722
663
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
723
664
  methods to save and restore this information.
724
665
*/
725
 
 
726
666
class Query_tables_list
727
667
{
728
668
public:
743
683
    of Query_tables_list instances which are used as backup storage.
744
684
  */
745
685
  Query_tables_list() {}
746
 
  ~Query_tables_list() {}
 
686
  virtual ~Query_tables_list() {}
747
687
 
748
688
  /* Initializes (or resets) Query_tables_list object for "real" use. */
749
689
  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
 
  }
755
690
 
756
691
  /*
757
692
    Direct addition to the list of query tables.
779
714
  }
780
715
};
781
716
 
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
 
 
797
717
/**
798
718
  The state of the lexical parser, when parsing comments.
799
719
*/
817
737
  DISCARD_COMMENT
818
738
};
819
739
 
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
 
740
} /* namespace drizzled */
 
741
 
 
742
#include "drizzled/lex_input_stream.h"
 
743
 
 
744
namespace drizzled
836
745
{
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
 
 
1197
746
 
1198
747
/* The state of the lex parsing. This is saved in the Session struct */
1199
 
 
1200
748
class LEX : public Query_tables_list
1201
749
{
1202
750
public:
1207
755
  /* list of all Select_Lex */
1208
756
  Select_Lex *all_selects_list;
1209
757
 
1210
 
  char *length,*dec,*change;
 
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
   */
1211
769
  LEX_STRING name;
 
770
  /* The string literal used in a LIKE expression */
1212
771
  String *wild;
1213
772
  file_exchange *exchange;
1214
773
  select_result *result;
1215
 
  Item *default_value, *on_update_value;
1216
 
  LEX_STRING comment, ident;
1217
 
  XID *xid;
 
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
 
1218
783
  unsigned char* yacc_yyss, *yacc_yyvs;
 
784
  /* The owning Session of this LEX */
1219
785
  Session *session;
1220
 
  virtual_column_info *vcol_info;
1221
 
 
1222
786
  const CHARSET_INFO *charset;
1223
787
  bool text_string_is_7bit;
1224
788
  /* store original leaf_tables for INSERT SELECT and PS/SP */
1231
795
  List<Item>          *insert_list,field_list,value_list,update_list;
1232
796
  List<List_item>     many_values;
1233
797
  List<set_var_base>  var_list;
1234
 
  List<Item_param>    param_list;
1235
798
  /*
1236
799
    A stack of name resolution contexts for the query. This stack is used
1237
800
    at parse time to set local name resolution contexts for various parts
1246
809
    required a local context, the parser pops the top-most context.
1247
810
  */
1248
811
  List<Name_resolution_context> context_stack;
1249
 
  List<LEX_STRING>     db_list;
1250
812
 
1251
 
  SQL_LIST            auxiliary_table_list, save_list;
1252
 
  Create_field        *last_field;
 
813
  SQL_LIST auxiliary_table_list;
 
814
  SQL_LIST save_list;
 
815
  CreateField *last_field;
1253
816
  Item_sum *in_sum_func;
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;
 
817
  plugin::Function *udf;
1258
818
  uint32_t type;
1259
819
  /*
1260
820
    This variable is used in post-parse stage to declare that sum-functions,
1267
827
  */
1268
828
  nesting_map allow_sum_func;
1269
829
  enum_sql_command sql_command;
 
830
  statement::Statement *statement;
1270
831
  /*
1271
832
    Usually `expr` rule of yacc is quite reused but some commands better
1272
833
    not support subqueries which comes standard with this rule, like
1274
835
    syntax error back.
1275
836
  */
1276
837
  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;
1285
838
 
1286
839
  thr_lock_type lock_option;
1287
840
  enum enum_duplicates duplicates;
1288
 
  enum enum_tx_isolation tx_isolation;
1289
 
  enum enum_ha_read_modes ha_read_mode;
1290
841
  union {
1291
842
    enum ha_rkey_function ha_rkey_mode;
1292
843
    enum xa_option_words xa_opt;
1293
 
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
1294
844
  };
1295
 
  enum enum_var_type option_type;
 
845
  sql_var_t option_type;
1296
846
 
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;
1305
847
  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;
1312
848
  uint8_t describe;
1313
849
  /*
1314
850
    A flag that indicates what kinds of derived tables are present in the
1315
851
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1316
852
  */
1317
853
  uint8_t derived_tables;
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;
 
854
 
 
855
  /* Was the IGNORE symbol found in statement */
 
856
  bool ignore;
1333
857
 
1334
858
  /**
1335
859
    During name resolution search only in the table list given by
1339
863
  */
1340
864
  bool use_only_table_context;
1341
865
 
 
866
  /* Was the ESCAPE keyword used? */
1342
867
  bool escape_used;
1343
868
  bool is_lex_started; /* If lex_start() did run. For debugging. */
1344
869
 
1345
870
  LEX();
1346
871
 
 
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
  */
1347
877
  virtual ~LEX()
1348
878
  {
1349
 
    destroy_query_tables_list();
1350
879
  }
1351
880
 
1352
881
  TableList *unlink_first_table(bool *link_to_local);
1402
931
  }
1403
932
};
1404
933
 
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
 
 
1421
934
extern void lex_start(Session *session);
1422
935
extern void lex_end(LEX *lex);
1423
 
 
1424
936
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1425
 
 
1426
937
extern bool is_lex_native_function(const LEX_STRING *name);
1427
938
 
1428
939
/**
1429
940
  @} (End of group Semantic_Analysis)
1430
941
*/
1431
942
 
 
943
} /* namespace drizzled */
 
944
 
1432
945
#endif /* DRIZZLE_SERVER */
1433
 
#endif /* DRIZZLE_SERVER_SQL_LEX_H */
 
946
#endif /* DRIZZLED_SQL_LEX_H */