~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field/varstring.h

Merge/fix in FAQ.

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