~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-24 15:33:01 UTC
  • mto: (968.2.18 mordred)
  • mto: This revision was merged to the branch mainline in revision 971.
  • Revision ID: osullivan.padraig@gmail.com-20090324153301-90gw63j1lsie1k9j
Removing a very mis-leading comment from sql_locale.cc

The comment was totally wrong and read "This file is build from
my_locale.pl"

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
62
54
*/
63
55
 
64
56
#ifdef DRIZZLE_SERVER
65
 
/* set_var should change to set_var here ... */
66
 
# include <drizzled/sys_var.h>
 
57
# include <drizzled/set_var.h>
67
58
# include <drizzled/item/func.h>
68
59
# ifdef DRIZZLE_YACC
69
60
#  define LEX_YYSTYPE void *
70
61
# else
71
62
#  if defined(DRIZZLE_LEX)
72
 
#   include <drizzled/foreign_key.h>
73
63
#   include <drizzled/lex_symbol.h>
74
64
#   include <drizzled/sql_yacc.h>
75
65
#   define LEX_YYSTYPE YYSTYPE *
88
78
#define DERIVED_NONE    0
89
79
#define DERIVED_SUBQUERY        1
90
80
 
91
 
namespace drizzled
92
 
{
93
 
 
94
81
typedef List<Item> List_item;
95
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
 
96
92
enum sub_select_type
97
93
{
98
 
  UNSPECIFIED_TYPE,
99
 
  UNION_TYPE,
100
 
  INTERSECT_TYPE,
101
 
  EXCEPT_TYPE,
102
 
  GLOBAL_OPTIONS_TYPE,
103
 
  DERIVED_TABLE_TYPE,
104
 
  OLAP_TYPE
 
94
  UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
 
95
  EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
105
96
};
106
97
 
107
98
enum olap_type
108
99
{
109
 
  UNSPECIFIED_OLAP_TYPE,
110
 
  CUBE_TYPE,
111
 
  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
112
106
};
113
107
 
114
108
/*
249
243
      UNCACHEABLE_EXPLAIN
250
244
      UNCACHEABLE_PREPARE
251
245
  */
252
 
  std::bitset<8> uncacheable;
 
246
  uint8_t uncacheable;
253
247
  enum sub_select_type linkage;
254
248
  bool no_table_names_allowed; /* used for global order by */
255
249
  bool no_error; /* suppress error message (convert it to warnings) */
256
250
 
257
251
  static void *operator new(size_t size)
258
252
  {
259
 
    return memory::sql_alloc(size);
 
253
    return sql_alloc(size);
260
254
  }
261
 
  static void *operator new(size_t size, memory::Root *mem_root)
262
 
  { return (void*) mem_root->alloc_root((uint32_t) size); }
 
255
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
256
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
263
257
  static void operator delete(void *, size_t)
264
 
  {  }
265
 
  static void operator delete(void *, memory::Root *)
 
258
  { TRASH(ptr, size); }
 
259
  static void operator delete(void *, MEM_ROOT *)
266
260
  {}
267
261
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
268
262
  virtual ~Select_Lex_Node() {}
284
278
  virtual uint32_t get_in_sum_expr();
285
279
  virtual TableList* get_table_list();
286
280
  virtual List<Item>* get_item_list();
 
281
  virtual uint32_t get_table_join_options();
287
282
  virtual TableList *add_table_to_list(Session *session, Table_ident *table,
288
 
                                       LEX_STRING *alias,
289
 
                                       const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
290
 
                                       thr_lock_type flags= TL_UNLOCK,
291
 
                                       List<Index_hint> *hints= 0,
292
 
                                       LEX_STRING *option= 0);
 
283
                                        LEX_STRING *alias,
 
284
                                        uint32_t table_options,
 
285
                                        thr_lock_type flags= TL_UNLOCK,
 
286
                                        List<Index_hint> *hints= 0,
 
287
                                        LEX_STRING *option= 0);
293
288
  virtual void set_lock_for_tables(thr_lock_type)
294
289
  {}
295
290
 
305
300
*/
306
301
class Session;
307
302
class select_result;
308
 
class Join;
 
303
class JOIN;
309
304
class select_union;
310
305
class Select_Lex_Unit: public Select_Lex_Node {
311
306
protected:
404
399
class Select_Lex: public Select_Lex_Node
405
400
{
406
401
public:
407
 
 
408
 
  Select_Lex() :
409
 
    context(),
410
 
    db(0),
411
 
    where(0),
412
 
    having(0),
413
 
    cond_value(),
414
 
    having_value(),
415
 
    parent_lex(0),
416
 
    olap(UNSPECIFIED_OLAP_TYPE),
417
 
    table_list(),
418
 
    group_list(),
419
 
    item_list(),
420
 
    interval_list(),
421
 
    is_item_list_lookup(false),
422
 
    join(0),
423
 
    top_join_list(),
424
 
    join_list(0),
425
 
    embedding(0),
426
 
    sj_nests(),
427
 
    leaf_tables(0),
428
 
    type(optimizer::ST_PRIMARY),
429
 
    order_list(),
430
 
    gorder_list(0),
431
 
    select_limit(0),
432
 
    offset_limit(0),
433
 
    ref_pointer_array(0),
434
 
    select_n_having_items(0),
435
 
    cond_count(0),
436
 
    between_count(0),
437
 
    max_equal_elems(0),
438
 
    select_n_where_fields(0),
439
 
    parsing_place(NO_MATTER),
440
 
    with_sum_func(0),
441
 
    in_sum_expr(0),
442
 
    select_number(0),
443
 
    nest_level(0),
444
 
    inner_sum_func_list(0),
445
 
    with_wild(0),
446
 
    braces(0),
447
 
    having_fix_field(0),
448
 
    inner_refs_list(),
449
 
    n_sum_items(0),
450
 
    n_child_sum_items(0),
451
 
    explicit_limit(0),
452
 
    subquery_in_having(0),
453
 
    is_correlated(0),
454
 
    exclude_from_table_unique_test(0),
455
 
    non_agg_fields(),
456
 
    cur_pos_in_select_list(0),
457
 
    prev_join_using(0),
458
 
    full_group_by_flag(),
459
 
    current_index_hint_type(INDEX_HINT_IGNORE),
460
 
    current_index_hint_clause(),
461
 
    index_hints(0)
462
 
  {
463
 
  }
464
 
 
465
402
  Name_resolution_context context;
466
403
  char *db;
467
 
  /* An Item representing the WHERE clause */
468
 
  Item *where;
469
 
  /* An Item representing the HAVING clause */
470
 
  Item *having;
 
404
  Item *where, *having;                         /* WHERE & HAVING clauses */
471
405
  /* Saved values of the WHERE and HAVING clauses*/
472
 
  Item::cond_result cond_value;
473
 
  Item::cond_result having_value;
 
406
  Item::cond_result cond_value, having_value;
474
407
  /* point on lex in which it was created, used in view subquery detection */
475
408
  LEX *parent_lex;
476
409
  enum olap_type olap;
477
410
  /* FROM clause - points to the beginning of the TableList::next_local list. */
478
 
  SQL_LIST table_list;
479
 
  SQL_LIST group_list; /* GROUP BY clause. */
480
 
  List<Item> item_list;  /* list of fields & expressions */
481
 
  List<String> interval_list;
482
 
  bool is_item_list_lookup;
483
 
  Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
 
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;
 
422
  JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
484
423
  List<TableList> top_join_list; /* join list of the top level          */
485
424
  List<TableList> *join_list;    /* list for the currently parsed join  */
486
425
  TableList *embedding;          /* table embedding to the above list   */
491
430
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
492
431
  */
493
432
  TableList *leaf_tables;
494
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
433
  const char *type;               /* type of select for EXPLAIN          */
495
434
 
496
435
  SQL_LIST order_list;                /* ORDER clause */
497
436
  SQL_LIST *gorder_list;
498
437
  Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
499
 
  /* Arrays of pointers to top elements of all_fields list */
 
438
  // Arrays of pointers to top elements of all_fields list
500
439
  Item **ref_pointer_array;
501
440
 
502
441
  /*
516
455
  enum_parsing_place parsing_place; /* where we are parsing expression */
517
456
  bool with_sum_func;   /* sum function indicator */
518
457
 
 
458
  uint32_t table_join_options;
519
459
  uint32_t in_sum_expr;
520
460
  uint32_t select_number; /* number of select (used for EXPLAIN) */
521
461
  int8_t nest_level;     /* nesting level of select */
522
462
  Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
523
463
  uint32_t with_wild; /* item list contain '*' */
524
 
  bool braces;          /* SELECT ... UNION (SELECT ... ) <- this braces */
 
464
  bool  braces;         /* SELECT ... UNION (SELECT ... ) <- this braces */
525
465
  /* true when having fix field called in processing of this SELECT */
526
466
  bool having_fix_field;
527
467
  /* List of references to fields referenced from inner selects */
547
487
  /* index in the select list of the expression currently being fixed */
548
488
  int cur_pos_in_select_list;
549
489
 
 
490
  List<Function_builder>     udf_list;                  /* udf function calls stack */
550
491
  /*
551
492
    This is a copy of the original JOIN USING list that comes from
552
493
    the parser. The parser :
570
511
      1 - aggregate functions are used in this select,
571
512
          defined as SUM_FUNC_USED.
572
513
  */
573
 
  std::bitset<2> full_group_by_flag;
574
 
 
 
514
  uint8_t full_group_by_flag;
575
515
  void init_query();
576
516
  void init_select();
577
517
  Select_Lex_Unit* master_unit();
580
520
    return (Select_Lex_Unit*) slave;
581
521
  }
582
522
  Select_Lex* outer_select();
583
 
  Select_Lex* next_select()
584
 
  {
585
 
    return (Select_Lex*) next;
586
 
  }
 
523
  Select_Lex* next_select() { return (Select_Lex*) next; }
587
524
  Select_Lex* next_select_in_list()
588
525
  {
589
526
    return (Select_Lex*) link_next;
606
543
  bool add_item_to_list(Session *session, Item *item);
607
544
  bool add_group_to_list(Session *session, Item *item, bool asc);
608
545
  bool add_order_to_list(Session *session, Item *item, bool asc);
609
 
  TableList* add_table_to_list(Session *session,
610
 
                               Table_ident *table,
611
 
                               LEX_STRING *alias,
612
 
                               const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
613
 
                               thr_lock_type flags= TL_UNLOCK,
614
 
                               List<Index_hint> *hints= 0,
615
 
                               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);
616
552
  TableList* get_table_list();
617
553
  bool init_nested_join(Session *session);
618
554
  TableList *end_nested_join(Session *session);
620
556
  void add_joined_table(TableList *table);
621
557
  TableList *convert_right_join();
622
558
  List<Item>* get_item_list();
 
559
  uint32_t get_table_join_options();
623
560
  void set_lock_for_tables(thr_lock_type lock_type);
624
561
  inline void init_order()
625
562
  {
633
570
    to LEX (LEX::unit & LEX::select, for other purposes there are
634
571
    Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
635
572
  */
636
 
  void cut_subtree()
637
 
  {
638
 
    slave= 0;
639
 
  }
 
573
  void cut_subtree() { slave= 0; }
640
574
  bool test_limit();
641
575
 
642
576
  friend void lex_start(Session *session);
 
577
  Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
643
578
  void make_empty_select()
644
579
  {
645
580
    init_query();
648
583
  bool setup_ref_array(Session *session, uint32_t order_group_num);
649
584
  void print(Session *session, String *str, enum_query_type query_type);
650
585
  static void print_order(String *str,
651
 
                          Order *order,
 
586
                          order_st *order,
652
587
                          enum_query_type query_type);
653
588
  void print_limit(Session *session, String *str, enum_query_type query_type);
654
589
  void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
697
632
    first_select()->next_select()->linkage == UNION_TYPE;
698
633
}
699
634
 
700
 
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
701
664
{
702
 
  XA_NONE
703
 
, XA_JOIN
704
 
, XA_RESUME
705
 
, XA_ONE_PHASE
706
 
, XA_SUSPEND
707
 
, 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
708
707
};
709
708
 
 
709
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
 
710
                      XA_SUSPEND, XA_FOR_MIGRATE};
 
711
 
710
712
extern const LEX_STRING null_lex_str;
711
713
 
 
714
 
712
715
/*
713
716
  Class representing list of all tables used by statement.
714
717
  It also contains information about stored functions used by statement
719
722
  Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
720
723
  methods to save and restore this information.
721
724
*/
 
725
 
722
726
class Query_tables_list
723
727
{
724
728
public:
739
743
    of Query_tables_list instances which are used as backup storage.
740
744
  */
741
745
  Query_tables_list() {}
742
 
  virtual ~Query_tables_list() {}
 
746
  ~Query_tables_list() {}
743
747
 
744
748
  /* Initializes (or resets) Query_tables_list object for "real" use. */
745
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
  }
746
755
 
747
756
  /*
748
757
    Direct addition to the list of query tables.
770
779
  }
771
780
};
772
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
 
773
797
/**
774
798
  The state of the lexical parser, when parsing comments.
775
799
*/
793
817
  DISCARD_COMMENT
794
818
};
795
819
 
796
 
} /* namespace drizzled */
797
 
 
798
 
#include "drizzled/lex_input_stream.h"
799
 
 
800
 
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
801
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
 
802
1197
 
803
1198
/* The state of the lex parsing. This is saved in the Session struct */
 
1199
 
804
1200
class LEX : public Query_tables_list
805
1201
{
806
1202
public:
811
1207
  /* list of all Select_Lex */
812
1208
  Select_Lex *all_selects_list;
813
1209
 
814
 
  /* This is the "scale" for DECIMAL (S,P) notation */ 
815
 
  char *length;
816
 
  /* This is the decimal precision in DECIMAL(S,P) notation */
817
 
  char *dec;
818
 
  
819
 
  /**
820
 
   * This is used kind of like the "ident" member variable below, as 
821
 
   * a place to store certain names of identifiers.  Unfortunately, it
822
 
   * is used differently depending on the Command (SELECT on a derived
823
 
   * table vs CREATE)
824
 
   */
 
1210
  char *length,*dec,*change;
825
1211
  LEX_STRING name;
826
 
  /* The string literal used in a LIKE expression */
827
1212
  String *wild;
828
1213
  file_exchange *exchange;
829
1214
  select_result *result;
830
 
 
831
 
  /**
832
 
   * This is current used to store the name of a named key cache
833
 
   * or a named savepoint.  It should probably be refactored out into
834
 
   * the eventual Command class built for the Keycache and Savepoint
835
 
   * commands.
836
 
   */ 
837
 
  LEX_STRING ident;
838
 
 
 
1215
  Item *default_value, *on_update_value;
 
1216
  LEX_STRING comment, ident;
 
1217
  XID *xid;
839
1218
  unsigned char* yacc_yyss, *yacc_yyvs;
840
 
  /* The owning Session of this LEX */
841
1219
  Session *session;
 
1220
  virtual_column_info *vcol_info;
 
1221
 
842
1222
  const CHARSET_INFO *charset;
843
1223
  bool text_string_is_7bit;
844
1224
  /* store original leaf_tables for INSERT SELECT and PS/SP */
851
1231
  List<Item>          *insert_list,field_list,value_list,update_list;
852
1232
  List<List_item>     many_values;
853
1233
  List<set_var_base>  var_list;
 
1234
  List<Item_param>    param_list;
854
1235
  /*
855
1236
    A stack of name resolution contexts for the query. This stack is used
856
1237
    at parse time to set local name resolution contexts for various parts
865
1246
    required a local context, the parser pops the top-most context.
866
1247
  */
867
1248
  List<Name_resolution_context> context_stack;
 
1249
  List<LEX_STRING>     db_list;
868
1250
 
869
 
  SQL_LIST auxiliary_table_list;
870
 
  SQL_LIST save_list;
871
 
  CreateField *last_field;
 
1251
  SQL_LIST            auxiliary_table_list, save_list;
 
1252
  Create_field        *last_field;
872
1253
  Item_sum *in_sum_func;
873
 
  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;
874
1258
  uint32_t type;
875
1259
  /*
876
1260
    This variable is used in post-parse stage to declare that sum-functions,
883
1267
  */
884
1268
  nesting_map allow_sum_func;
885
1269
  enum_sql_command sql_command;
886
 
  statement::Statement *statement;
887
1270
  /*
888
1271
    Usually `expr` rule of yacc is quite reused but some commands better
889
1272
    not support subqueries which comes standard with this rule, like
891
1274
    syntax error back.
892
1275
  */
893
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;
894
1285
 
895
1286
  thr_lock_type lock_option;
896
1287
  enum enum_duplicates duplicates;
 
1288
  enum enum_tx_isolation tx_isolation;
 
1289
  enum enum_ha_read_modes ha_read_mode;
897
1290
  union {
898
1291
    enum ha_rkey_function ha_rkey_mode;
899
1292
    enum xa_option_words xa_opt;
 
1293
    bool lock_transactional;            /* For LOCK Table ... IN ... MODE */
900
1294
  };
901
 
  sql_var_t option_type;
 
1295
  enum enum_var_type option_type;
902
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;
903
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;
904
1312
  uint8_t describe;
905
1313
  /*
906
1314
    A flag that indicates what kinds of derived tables are present in the
907
1315
    query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
908
1316
  */
909
1317
  uint8_t derived_tables;
910
 
 
911
 
  /* Was the IGNORE symbol found in statement */
912
 
  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;
913
1333
 
914
1334
  /**
915
1335
    During name resolution search only in the table list given by
919
1339
  */
920
1340
  bool use_only_table_context;
921
1341
 
922
 
  /* Was the ESCAPE keyword used? */
923
1342
  bool escape_used;
924
1343
  bool is_lex_started; /* If lex_start() did run. For debugging. */
925
1344
 
926
1345
  LEX();
927
1346
 
928
 
  /* Note that init and de-init mostly happen in lex_start and lex_end
929
 
     and not here. This is because LEX isn't delete/new for each new
930
 
     statement in a session. It's re-used by doing lex_end, lex_start
931
 
     in sql_lex.cc
932
 
  */
933
1347
  virtual ~LEX()
934
1348
  {
 
1349
    destroy_query_tables_list();
935
1350
  }
936
1351
 
937
1352
  TableList *unlink_first_table(bool *link_to_local);
938
1353
  void link_first_table_back(TableList *first, bool link_to_local);
939
1354
  void first_lists_tables_same();
940
1355
 
 
1356
  bool only_view_structure();
 
1357
  bool need_correct_ident();
 
1358
 
941
1359
  void cleanup_after_one_table_open();
942
1360
 
943
1361
  bool push_context(Name_resolution_context *context)
982
1400
    }
983
1401
    return false;
984
1402
  }
985
 
  bool is_cross; // CROSS keyword was used
986
 
  bool isCacheable()
987
 
  {
988
 
    return cacheable;
989
 
  }
990
 
  void setCacheable(bool val)
991
 
  {
992
 
    cacheable= val;
993
 
  }
994
 
 
995
 
  void reset()
996
 
  {
997
 
    sum_expr_used= false;
998
 
  }
999
 
 
1000
 
  void setSumExprUsed()
1001
 
  {
1002
 
    sum_expr_used= true;
1003
 
  }
1004
 
 
1005
 
  bool isSumExprUsed()
1006
 
  {
1007
 
    return sum_expr_used;
1008
 
  }
1009
 
 
1010
 
  void start(Session *session);
1011
 
  void end();
1012
 
 
1013
 
private: 
1014
 
  bool cacheable;
1015
 
  bool sum_expr_used;
 
1403
};
 
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 */ }
1016
1419
};
1017
1420
 
1018
1421
extern void lex_start(Session *session);
 
1422
extern void lex_end(LEX *lex);
 
1423
 
1019
1424
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
 
1425
 
1020
1426
extern bool is_lex_native_function(const LEX_STRING *name);
1021
1427
 
1022
1428
/**
1023
1429
  @} (End of group Semantic_Analysis)
1024
1430
*/
1025
1431
 
1026
 
} /* namespace drizzled */
1027
 
 
1028
1432
#endif /* DRIZZLE_SERVER */
1029
 
#endif /* DRIZZLED_SQL_LEX_H */
 
1433
#endif /* DRIZZLE_SERVER_SQL_LEX_H */