~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/varstring.h

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#ifndef DRIZZLE_SERVER_FIELD_VARSTRING
22
 
#define DRIZZLE_SERVER_FIELD_VARSTRING
23
 
 
24
 
class Field_varstring :public Field_longstr {
 
21
#ifndef DRIZZLED_FIELD_VARSTRING_H
 
22
#define DRIZZLED_FIELD_VARSTRING_H
 
23
 
 
24
#include <drizzled/field/str.h>
 
25
#include <string>
 
26
 
 
27
namespace drizzled
 
28
{
 
29
 
 
30
class Field_varstring :public Field_str {
25
31
public:
 
32
 
 
33
  using Field::store;
 
34
  using Field::pack;
 
35
  using Field::unpack;
 
36
  using Field::val_int;
 
37
  using Field::val_str;
 
38
 
26
39
  /*
27
40
    The maximum space available in a Field_varstring, in bytes. See
28
41
    length_bytes.
29
42
  */
30
 
  static const uint MAX_SIZE;
 
43
  static const uint32_t MAX_SIZE;
31
44
  /* Store number of bytes used to store length (1 or 2) */
32
45
  uint32_t length_bytes;
33
 
  Field_varstring(uchar *ptr_arg,
34
 
                  uint32_t len_arg, uint length_bytes_arg,
35
 
                  uchar *null_ptr_arg, uchar null_bit_arg,
36
 
                  enum utype unireg_check_arg, const char *field_name_arg,
37
 
                  TABLE_SHARE *share, const CHARSET_INFO * const cs)
38
 
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
39
 
                   unireg_check_arg, field_name_arg, cs),
40
 
     length_bytes(length_bytes_arg)
41
 
  {
42
 
    share->varchar_fields++;
43
 
  }
44
 
  Field_varstring(uint32_t len_arg,bool maybe_null_arg,
45
 
                  const char *field_name_arg,
46
 
                  TABLE_SHARE *share, const CHARSET_INFO * const cs)
47
 
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
48
 
                   NONE, field_name_arg, cs),
49
 
     length_bytes(len_arg < 256 ? 1 :2)
50
 
  {
51
 
    share->varchar_fields++;
52
 
  }
 
46
  Field_varstring(unsigned char *ptr_arg,
 
47
                  uint32_t len_arg,
 
48
                  uint32_t length_bytes_arg,
 
49
                  unsigned char *null_ptr_arg,
 
50
                  unsigned char null_bit_arg,
 
51
                  const char *field_name_arg,
 
52
                  TableShare *share,
 
53
                  const CHARSET_INFO * const cs);
 
54
  Field_varstring(uint32_t len_arg,
 
55
                  bool maybe_null_arg,
 
56
                  const char *field_name_arg,
 
57
                  TableShare *share,
 
58
                  const CHARSET_INFO * const cs);
53
59
 
54
60
  enum_field_types type() const { return DRIZZLE_TYPE_VARCHAR; }
55
61
  enum ha_base_keytype key_type() const;
56
 
  uint row_pack_length() { return field_length; }
 
62
  uint32_t row_pack_length() { return field_length; }
57
63
  bool zero_pack() const { return 0; }
58
64
  int  reset(void) { memset(ptr, 0, field_length+length_bytes); return 0; }
59
65
  uint32_t pack_length() const { return (uint32_t) field_length+length_bytes; }
63
69
    return (uint32_t) field_length + (field_charset == &my_charset_bin ?
64
70
                                    length_bytes : 0);
65
71
  }
66
 
  int  store(const char *to,uint length, const CHARSET_INFO * const charset);
 
72
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
 
73
 
 
74
 
67
75
  int  store(int64_t nr, bool unsigned_val);
68
76
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
69
77
  double val_real(void);
70
78
  int64_t val_int(void);
71
79
  String *val_str(String*,String *);
 
80
  inline String *val_str(String *str) { return val_str(str, str); }
72
81
  my_decimal *val_decimal(my_decimal *);
73
 
  int cmp_max(const uchar *, const uchar *, uint max_length);
74
 
  int cmp(const uchar *a,const uchar *b)
 
82
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
 
83
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
 
84
  int cmp(const unsigned char *a,const unsigned char *b)
75
85
  {
76
 
    return cmp_max(a, b, ~0L);
 
86
    return cmp_max(a, b, UINT32_MAX);
77
87
  }
78
 
  void sort_string(uchar *buff,uint length);
79
 
  uint get_key_image(uchar *buff,uint length, imagetype type);
80
 
  void set_key_image(const uchar *buff,uint length);
 
88
  void sort_string(unsigned char *buff,uint32_t length);
 
89
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
 
90
  uint32_t get_key_image(std::basic_string <unsigned char> &buff, uint32_t length);
 
91
  void set_key_image(const unsigned char *buff,uint32_t length);
81
92
  void sql_type(String &str) const;
82
 
  virtual uchar *pack(uchar *to, const uchar *from,
83
 
                      uint max_length, bool low_byte_first);
84
 
  uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first);
85
 
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
86
 
                                 uint max_length, bool low_byte_first);
87
 
  virtual const uchar *unpack(uchar* to, const uchar *from,
88
 
                              uint param_data, bool low_byte_first);
89
 
  const uchar *unpack_key(uchar* to, const uchar *from,
90
 
                          uint max_length, bool low_byte_first);
91
 
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
92
 
               bool insert_or_update);
93
 
  int pack_cmp(const uchar *b, uint key_length,bool insert_or_update);
94
 
  int cmp_binary(const uchar *a,const uchar *b, uint32_t max_length=~0L);
95
 
  int key_cmp(const uchar *,const uchar*);
96
 
  int key_cmp(const uchar *str, uint length);
97
 
  uint packed_col_length(const uchar *to, uint length);
98
 
  uint max_packed_col_length(uint max_length);
99
 
  uint32_t data_length();
 
93
  virtual unsigned char *pack(unsigned char *to,
 
94
                              const unsigned char *from,
 
95
                              uint32_t max_length,
 
96
                              bool low_byte_first);
 
97
 
 
98
  virtual const unsigned char *unpack(unsigned char* to,
 
99
                                      const unsigned char *from,
 
100
                                      uint32_t param_data,
 
101
                                      bool low_byte_first);
 
102
 
 
103
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
 
104
  int key_cmp(const unsigned char *,const unsigned char*);
 
105
  int key_cmp(const unsigned char *str, uint32_t length);
 
106
  uint32_t max_packed_col_length(uint32_t max_length);
100
107
  uint32_t used_length();
101
 
  uint size_of() const { return sizeof(*this); }
 
108
  uint32_t size_of() const { return sizeof(*this); }
102
109
  enum_field_types real_type() const { return DRIZZLE_TYPE_VARCHAR; }
103
110
  bool has_charset(void) const
104
111
  { return charset() == &my_charset_bin ? false : true; }
105
 
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
106
 
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
107
 
                       uchar *new_ptr, uchar *new_null_ptr,
108
 
                       uint new_null_bit);
109
 
  uint is_equal(Create_field *new_field);
110
 
  void hash(uint32_t *nr, uint32_t *nr2);
111
 
private:
112
 
  int do_save_field_metadata(uchar *first_byte);
 
112
  Field *new_field(memory::Root *root, Table *new_table, bool keep_type);
 
113
  Field *new_key_field(memory::Root *root, Table *new_table,
 
114
                       unsigned char *new_ptr, unsigned char *new_null_ptr,
 
115
                       uint32_t new_null_bit);
113
116
};
114
117
 
115
 
#endif
 
118
} /* namespace drizzled */
 
119
 
 
120
#endif /* DRIZZLED_FIELD_VARSTRING_H */
116
121