~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.h

Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.

This fixes the buffer overflow in https://bugs.launchpad.net/drizzle/+bug/373468

It also removes a handwritten snprintf in field/datetime.cc
However... this caused us to have to change Temporal to have a way to not
"convert" the int64_t value (so 20090101 becomes 20090101000000 etc) as it
has already been converted and we just want the Temporal type to do the
to_string conversion.

This still causes a failure in 'metadata' test due to size of timestamp type. I need feedback from Jay on when the usecond code comes into play to know the correct fix for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
#include <drizzled/message/table.pb.h>
27
27
 
28
 
#include "drizzled/plugin/function.h"
 
28
#include "drizzled/sql_udf.h"
29
29
#include "drizzled/name_resolution_context.h"
30
30
#include "drizzled/item/subselect.h"
 
31
#include "drizzled/item/param.h"
 
32
#include "drizzled/item/outer_ref.h"
31
33
#include "drizzled/table_list.h"
32
34
#include "drizzled/function/math/real.h"
33
35
#include "drizzled/alter_drop.h"
34
36
#include "drizzled/alter_column.h"
35
 
#include "drizzled/alter_info.h"
36
 
#include "drizzled/key_part_spec.h"
 
37
#include "drizzled/key.h"
 
38
#include "drizzled/foreign_key.h"
 
39
#include "drizzled/item/param.h"
37
40
#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
41
 
47
42
class select_result_interceptor;
48
43
 
54
49
class Lex_Column;
55
50
class Item_outer_ref;
56
51
 
57
 
} /* namespace drizzled */
58
 
 
59
52
/*
60
53
  The following hack is needed because mysql_yacc.cc does not define
61
54
  YYSTYPE before including this file
68
61
#  define LEX_YYSTYPE void *
69
62
# else
70
63
#  if defined(DRIZZLE_LEX)
71
 
#   include <drizzled/foreign_key.h>
72
64
#   include <drizzled/lex_symbol.h>
73
65
#   include <drizzled/sql_yacc.h>
74
66
#   define LEX_YYSTYPE YYSTYPE *
87
79
#define DERIVED_NONE    0
88
80
#define DERIVED_SUBQUERY        1
89
81
 
90
 
namespace drizzled
91
 
{
92
 
 
93
82
typedef List<Item> List_item;
94
83
 
95
84
enum sub_select_type
110
99
  ROLLUP_TYPE
111
100
};
112
101
 
 
102
enum tablespace_op_type
 
103
{
 
104
  NO_TABLESPACE_OP,
 
105
  DISCARD_TABLESPACE,
 
106
  IMPORT_TABLESPACE
 
107
};
 
108
 
113
109
/*
114
110
  The state of the lex parsing for selects
115
111
 
255
251
 
256
252
  static void *operator new(size_t size)
257
253
  {
258
 
    return memory::sql_alloc(size);
 
254
    return sql_alloc(size);
259
255
  }
260
 
  static void *operator new(size_t size, memory::Root *mem_root)
 
256
  static void *operator new(size_t size, MEM_ROOT *mem_root)
261
257
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
262
258
  static void operator delete(void *, size_t)
263
 
  {  }
264
 
  static void operator delete(void *, memory::Root *)
 
259
  { TRASH(ptr, size); }
 
260
  static void operator delete(void *, MEM_ROOT *)
265
261
  {}
266
262
  Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
267
263
  virtual ~Select_Lex_Node() {}
433
429
    by TableList::next_leaf, so leaf_tables points to the left-most leaf.
434
430
  */
435
431
  TableList *leaf_tables;
436
 
  enum drizzled::optimizer::select_type type; /* type of select for EXPLAIN */
 
432
  const char *type;               /* type of select for EXPLAIN          */
437
433
 
438
434
  SQL_LIST order_list;                /* ORDER clause */
439
435
  SQL_LIST *gorder_list;
513
509
      1 - aggregate functions are used in this select,
514
510
          defined as SUM_FUNC_USED.
515
511
  */
516
 
  std::bitset<2> full_group_by_flag;
 
512
  uint8_t full_group_by_flag;
517
513
  void init_query();
518
514
  void init_select();
519
515
  Select_Lex_Unit* master_unit();
641
637
    first_select()->next_select()->linkage == UNION_TYPE;
642
638
}
643
639
 
 
640
#define ALTER_ADD_COLUMN        (1L << 0)
 
641
#define ALTER_DROP_COLUMN       (1L << 1)
 
642
#define ALTER_CHANGE_COLUMN     (1L << 2)
 
643
#define ALTER_COLUMN_STORAGE    (1L << 3)
 
644
#define ALTER_COLUMN_FORMAT     (1L << 4)
 
645
#define ALTER_COLUMN_ORDER      (1L << 5)
 
646
#define ALTER_ADD_INDEX         (1L << 6)
 
647
#define ALTER_DROP_INDEX        (1L << 7)
 
648
#define ALTER_RENAME            (1L << 8)
 
649
#define ALTER_ORDER             (1L << 9)
 
650
#define ALTER_OPTIONS           (1L << 10)
 
651
#define ALTER_COLUMN_DEFAULT    (1L << 11)
 
652
#define ALTER_KEYS_ONOFF        (1L << 12)
 
653
#define ALTER_STORAGE           (1L << 13)
 
654
#define ALTER_ROW_FORMAT        (1L << 14)
 
655
#define ALTER_CONVERT           (1L << 15)
 
656
#define ALTER_FORCE             (1L << 16)
 
657
#define ALTER_RECREATE          (1L << 17)
 
658
#define ALTER_TABLE_REORG        (1L << 24)
 
659
#define ALTER_FOREIGN_KEY         (1L << 31)
 
660
 
 
661
/**
 
662
  @brief Parsing data for CREATE or ALTER Table.
 
663
 
 
664
  This structure contains a list of columns or indexes to be created,
 
665
  altered or dropped.
 
666
*/
 
667
 
 
668
class Alter_info
 
669
{
 
670
public:
 
671
  List<Alter_drop> drop_list;
 
672
  List<Alter_column> alter_list;
 
673
  List<Key> key_list;
 
674
  List<CreateField> create_list;
 
675
  uint32_t flags;
 
676
  enum enum_enable_or_disable keys_onoff;
 
677
  enum tablespace_op_type tablespace_op;
 
678
  uint32_t no_parts;
 
679
  enum ha_build_method build_method;
 
680
  CreateField *datetime_field;
 
681
  bool error_if_not_empty;
 
682
 
 
683
  Alter_info() :
 
684
    flags(0),
 
685
    keys_onoff(LEAVE_AS_IS),
 
686
    tablespace_op(NO_TABLESPACE_OP),
 
687
    no_parts(0),
 
688
    build_method(HA_BUILD_DEFAULT),
 
689
    datetime_field(NULL),
 
690
    error_if_not_empty(false)
 
691
  {}
 
692
 
 
693
  void reset()
 
694
  {
 
695
    drop_list.empty();
 
696
    alter_list.empty();
 
697
    key_list.empty();
 
698
    create_list.empty();
 
699
    flags= 0;
 
700
    keys_onoff= LEAVE_AS_IS;
 
701
    tablespace_op= NO_TABLESPACE_OP;
 
702
    no_parts= 0;
 
703
    build_method= HA_BUILD_DEFAULT;
 
704
    datetime_field= 0;
 
705
    error_if_not_empty= false;
 
706
  }
 
707
  Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
 
708
private:
 
709
  Alter_info &operator=(const Alter_info &rhs); // not implemented
 
710
  Alter_info(const Alter_info &rhs);            // not implemented
 
711
};
 
712
 
644
713
enum xa_option_words
645
714
{
646
715
  XA_NONE
683
752
    of Query_tables_list instances which are used as backup storage.
684
753
  */
685
754
  Query_tables_list() {}
686
 
  virtual ~Query_tables_list() {}
 
755
  ~Query_tables_list() {}
687
756
 
688
757
  /* Initializes (or resets) Query_tables_list object for "real" use. */
689
758
  void reset_query_tables_list(bool init);
737
806
  DISCARD_COMMENT
738
807
};
739
808
 
740
 
} /* namespace drizzled */
741
 
 
742
809
#include "drizzled/lex_input_stream.h"
743
810
 
744
 
namespace drizzled
745
 
{
746
 
 
747
811
/* The state of the lex parsing. This is saved in the Session struct */
748
812
class LEX : public Query_tables_list
749
813
{
759
823
  char *length;
760
824
  /* This is the decimal precision in DECIMAL(S,P) notation */
761
825
  char *dec;
 
826
  /* The text in a CHANGE COLUMN clause in ALTER TABLE */
 
827
  char *change;
762
828
  
763
829
  /**
764
830
   * This is used kind of like the "ident" member variable below, as 
772
838
  file_exchange *exchange;
773
839
  select_result *result;
774
840
 
 
841
  /* An item representing the DEFAULT clause in CREATE/ALTER TABLE */
 
842
  Item *default_value;
 
843
  /* An item representing the ON UPDATE clause in CREATE/ALTER TABLE */
 
844
  Item *on_update_value;
 
845
  /* Not really sure what exactly goes in here... Comment text at beginning of statement? */
 
846
  LEX_STRING comment;
 
847
 
775
848
  /**
776
849
   * This is current used to store the name of a named key cache
777
850
   * or a named savepoint.  It should probably be refactored out into
795
868
  List<Item>          *insert_list,field_list,value_list,update_list;
796
869
  List<List_item>     many_values;
797
870
  List<set_var_base>  var_list;
 
871
  List<Item_param>    param_list;
798
872
  /*
799
873
    A stack of name resolution contexts for the query. This stack is used
800
874
    at parse time to set local name resolution contexts for various parts
814
888
  SQL_LIST save_list;
815
889
  CreateField *last_field;
816
890
  Item_sum *in_sum_func;
817
 
  plugin::Function *udf;
 
891
  Function_builder *udf;
 
892
  HA_CHECK_OPT check_opt;                       // check/repair options
 
893
  HA_CREATE_INFO create_info;
 
894
  drizzled::message::Table *create_table_proto;
 
895
  StorageEngine *show_engine;
 
896
  KEY_CREATE_INFO key_create_info;
818
897
  uint32_t type;
819
898
  /*
820
899
    This variable is used in post-parse stage to declare that sum-functions,
827
906
  */
828
907
  nesting_map allow_sum_func;
829
908
  enum_sql_command sql_command;
830
 
  statement::Statement *statement;
831
909
  /*
832
910
    Usually `expr` rule of yacc is quite reused but some commands better
833
911
    not support subqueries which comes standard with this rule, like
838
916
 
839
917
  thr_lock_type lock_option;
840
918
  enum enum_duplicates duplicates;
 
919
  enum enum_tx_isolation tx_isolation;
 
920
  enum enum_ha_read_modes ha_read_mode;
841
921
  union {
842
922
    enum ha_rkey_function ha_rkey_mode;
843
923
    enum xa_option_words xa_opt;
844
924
  };
845
 
  sql_var_t option_type;
 
925
  enum enum_var_type option_type;
846
926
 
 
927
  enum column_format_type column_format;
 
928
  enum Foreign_key::fk_match_opt fk_match_option;
 
929
  enum Foreign_key::fk_option fk_update_opt;
 
930
  enum Foreign_key::fk_option fk_delete_opt;
 
931
  /* Options used in START TRANSACTION statement */
 
932
  uint32_t start_transaction_opt;
847
933
  int nest_level;
 
934
  /*
 
935
    In LEX representing update which were transformed to multi-update
 
936
    stores total number of tables. For LEX representing multi-delete
 
937
    holds number of tables from which we will delete records.
 
938
  */
 
939
  uint32_t table_count;
848
940
  uint8_t describe;
849
941
  /*
850
942
    A flag that indicates what kinds of derived tables are present in the
852
944
  */
853
945
  uint8_t derived_tables;
854
946
 
 
947
  /* True if "IF EXISTS" used in DROP statement */
 
948
  bool drop_if_exists;
 
949
  /* True if "TEMPORARY" used in DROP/CREATE statement */
 
950
  bool drop_temporary;
 
951
  bool one_shot_set;
 
952
 
 
953
  /* Only true when FULL symbol is found (e.g. SHOW FULL PROCESSLIST) */
 
954
  bool verbose;
 
955
  
 
956
  /* Was the CHAIN option using in COMMIT/ROLLBACK? */
 
957
  bool tx_chain;
 
958
  /* Was the RELEASE option used in COMMIT/ROLLBACK? */
 
959
  bool tx_release;
855
960
  /* Was the IGNORE symbol found in statement */
856
961
  bool ignore;
 
962
  Alter_info alter_info;
 
963
 
 
964
  /*
 
965
    Pointers to part of LOAD DATA statement that should be rewritten
 
966
    during replication ("LOCAL 'filename' REPLACE INTO" part).
 
967
  */
 
968
  const char *fname_start;
 
969
  const char *fname_end;
857
970
 
858
971
  /**
859
972
    During name resolution search only in the table list given by
940
1053
  @} (End of group Semantic_Analysis)
941
1054
*/
942
1055
 
943
 
} /* namespace drizzled */
944
 
 
945
1056
#endif /* DRIZZLE_SERVER */
946
1057
#endif /* DRIZZLED_SQL_LEX_H */