~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

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_BLOB_H
22
 
#define DRIZZLED_FIELD_BLOB_H
23
 
 
24
 
#include <drizzled/field/str.h>
25
 
 
26
 
#include "drizzled/global_charset_info.h"
27
 
 
28
 
#include <string>
29
 
 
30
 
#include "drizzled/visibility.h"
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
/**
36
 
 * Class representing a BLOB data type column
37
 
 */
38
 
class DRIZZLED_API Field_blob :
39
 
  public Field_str
40
 
{
 
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
 
22
#define DRIZZLE_SERVER_FIELD_BLOB
 
23
 
 
24
class Field_blob :public Field_longstr {
41
25
protected:
 
26
  uint packlength;
42
27
  String value;                         // For temporaries
43
28
public:
44
 
 
45
 
  using Field::store;
46
 
  using Field::cmp;
47
 
  using Field::pack;
48
 
  using Field::unpack;
49
 
  using Field::val_int;
50
 
  using Field::val_str;
51
 
 
52
 
  Field_blob(unsigned char *ptr_arg,
53
 
             unsigned char *null_ptr_arg,
54
 
             unsigned char null_bit_arg,
55
 
             const char *field_name_arg,
56
 
             TableShare *share,
57
 
             const CHARSET_INFO * const cs);
58
 
  Field_blob(uint32_t len_arg,
59
 
             bool maybe_null_arg,
60
 
             const char *field_name_arg,
 
29
  Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
30
             enum utype unireg_check_arg, const char *field_name_arg,
 
31
             TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO * const cs);
 
32
  Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
61
33
             const CHARSET_INFO * const cs)
62
 
    :Field_str((unsigned char*) NULL,
63
 
               len_arg,
64
 
               maybe_null_arg ? (unsigned char *) "": 0,
65
 
               0,
66
 
               field_name_arg,
67
 
               cs)
68
 
  {
69
 
    flags|= BLOB_FLAG;
70
 
  }
71
 
 
 
34
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
35
                   NONE, field_name_arg, cs),
 
36
    packlength(4)
 
37
  {
 
38
    flags|= BLOB_FLAG;
 
39
  }
 
40
  Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
 
41
             const CHARSET_INFO * const cs, bool set_packlength)
 
42
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
43
                   NONE, field_name_arg, cs)
 
44
  {
 
45
    flags|= BLOB_FLAG;
 
46
    packlength= 4;
 
47
    if (set_packlength)
 
48
    {
 
49
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
 
50
      packlength= l_char_length <= 255 ? 1 :
 
51
                  l_char_length <= 65535 ? 2 :
 
52
                  l_char_length <= 16777215 ? 3 : 4;
 
53
    }
 
54
  }
 
55
  Field_blob(uint32_t packlength_arg)
 
56
    :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
 
57
    packlength(packlength_arg) {}
72
58
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
73
59
  enum ha_base_keytype key_type() const
74
60
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
75
 
  int  store(const char *to,uint32_t length,
76
 
             const CHARSET_INFO * const charset);
 
61
  int  store(const char *to,uint length, const CHARSET_INFO * const charset);
77
62
  int  store(double nr);
78
63
  int  store(int64_t nr, bool unsigned_val);
79
 
 
80
64
  double val_real(void);
81
65
  int64_t val_int(void);
82
66
  String *val_str(String*,String *);
83
 
  type::Decimal *val_decimal(type::Decimal *);
84
 
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
85
 
  int cmp(const unsigned char *a,const unsigned char *b)
 
67
  my_decimal *val_decimal(my_decimal *);
 
68
  int cmp_max(const uchar *, const uchar *, uint32_t max_length);
 
69
  int cmp(const uchar *a,const uchar *b)
86
70
    { return cmp_max(a, b, UINT32_MAX); }
87
 
  int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
88
 
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
89
 
  int key_cmp(const unsigned char *,const unsigned char*);
90
 
  int key_cmp(const unsigned char *str, uint32_t length);
 
71
  int cmp(const uchar *a, uint32_t a_length, const uchar *b, uint32_t b_length);
 
72
  int cmp_binary(const uchar *a,const uchar *b, uint32_t max_length=UINT32_MAX);
 
73
  int key_cmp(const uchar *,const uchar*);
 
74
  int key_cmp(const uchar *str, uint length);
91
75
  uint32_t key_length() const { return 0; }
92
 
  void sort_string(unsigned char *buff,uint32_t length);
93
 
  uint32_t pack_length() const;
94
 
 
 
76
  void sort_string(uchar *buff,uint length);
 
77
  uint32_t pack_length() const
 
78
  { return (uint32_t) (packlength+table->s->blob_ptr_size); }
95
79
 
96
80
  /**
97
 
     Return the packed length without the pointer size added.
 
81
     Return the packed length without the pointer size added. 
98
82
 
99
83
     This is used to determine the size of the actual data in the row
100
84
     buffer.
102
86
     @returns The length of the raw data itself without the pointer.
103
87
  */
104
88
  uint32_t pack_length_no_ptr() const
105
 
  { return (uint32_t) (sizeof(uint32_t)); }
106
 
 
 
89
  { return (uint32_t) (packlength); }
 
90
  uint row_pack_length() { return pack_length_no_ptr(); }
107
91
  uint32_t sort_length() const;
108
92
  virtual uint32_t max_data_length() const
109
93
  {
110
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
94
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
111
95
  }
112
 
  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
 
96
  int reset(void) { memset(ptr, 0, packlength+sizeof(uchar*)); return 0; }
113
97
  void reset_fields() { memset(&value, 0, sizeof(value)); }
114
98
#ifndef WORDS_BIGENDIAN
115
99
  static
116
100
#endif
117
 
  void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
118
 
  void store_length(unsigned char *i_ptr, uint32_t i_number);
119
 
 
 
101
  void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number, bool low_byte_first);
 
102
  void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number)
 
103
  {
 
104
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
 
105
  }
120
106
  inline void store_length(uint32_t number)
121
107
  {
122
 
    store_length(ptr, number);
 
108
    store_length(ptr, packlength, number);
123
109
  }
124
110
 
125
111
  /**
126
 
     Return the packed length plus the length of the data.
 
112
     Return the packed length plus the length of the data. 
127
113
 
128
 
     This is used to determine the size of the data plus the
 
114
     This is used to determine the size of the data plus the 
129
115
     packed length portion in the row data.
130
116
 
131
117
     @returns The length in the row plus the size of the data.
132
118
  */
133
 
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
 
119
  uint32_t get_packed_size(const uchar *ptr_arg, bool low_byte_first)
 
120
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
134
121
 
135
 
  DRIZZLED_API uint32_t get_length(uint32_t row_offset= 0);
136
 
  DRIZZLED_API uint32_t get_length(const unsigned char *ptr, bool low_byte_first);
137
 
  DRIZZLED_API uint32_t get_length(const unsigned char *ptr_arg);
138
 
  void put_length(unsigned char *pos, uint32_t length);
139
 
  inline void get_ptr(unsigned char **str)
140
 
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
142
 
    }
143
 
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
144
 
    {
145
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
146
 
    }
147
 
  inline void set_ptr(unsigned char *length, unsigned char *data)
148
 
    {
149
 
      memcpy(ptr,length,sizeof(uint32_t));
150
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
151
 
    }
152
 
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
153
 
    {
154
 
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
155
 
      store_length(ptr_ofs, length);
156
 
      memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
157
 
    }
158
 
  inline void set_ptr(uint32_t length, unsigned char *data)
 
122
  inline uint32_t get_length(uint row_offset= 0)
 
123
  { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
 
124
  uint32_t get_length(const uchar *ptr, uint packlength, bool low_byte_first);
 
125
  uint32_t get_length(const uchar *ptr_arg)
 
126
  { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
 
127
  void put_length(uchar *pos, uint32_t length);
 
128
  inline void get_ptr(uchar **str)
 
129
    {
 
130
      memcpy(str,ptr+packlength,sizeof(uchar*));
 
131
    }
 
132
  inline void get_ptr(uchar **str, uint row_offset)
 
133
    {
 
134
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
 
135
    }
 
136
  inline void set_ptr(uchar *length, uchar *data)
 
137
    {
 
138
      memcpy(ptr,length,packlength);
 
139
      memcpy(ptr+packlength,&data,sizeof(char*));
 
140
    }
 
141
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, uchar *data)
 
142
    {
 
143
      uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
 
144
      store_length(ptr_ofs, packlength, length);
 
145
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
 
146
    }
 
147
  inline void set_ptr(uint32_t length, uchar *data)
159
148
    {
160
149
      set_ptr_offset(0, length, data);
161
150
    }
162
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
163
 
  uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
164
 
  void set_key_image(const unsigned char *buff,uint32_t length);
 
151
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
152
  void set_key_image(const uchar *buff,uint length);
165
153
  void sql_type(String &str) const;
166
154
  inline bool copy()
167
155
  {
168
 
    unsigned char *tmp;
 
156
    uchar *tmp;
169
157
    get_ptr(&tmp);
170
158
    if (value.copy((char*) tmp, get_length(), charset()))
171
159
    {
172
160
      Field_blob::reset();
173
161
      return 1;
174
162
    }
175
 
    tmp=(unsigned char*) value.ptr();
176
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
163
    tmp=(uchar*) value.ptr();
 
164
    memcpy(ptr+packlength,&tmp,sizeof(char*));
177
165
    return 0;
178
166
  }
179
 
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
180
 
                      uint32_t max_length, bool low_byte_first);
181
 
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
182
 
                  uint32_t max_length, bool low_byte_first);
183
 
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
184
 
                              uint32_t , bool low_byte_first);
 
167
  virtual uchar *pack(uchar *to, const uchar *from,
 
168
                      uint max_length, bool low_byte_first);
 
169
  uchar *pack_key(uchar *to, const uchar *from,
 
170
                  uint max_length, bool low_byte_first);
 
171
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
172
                                 uint max_length, bool low_byte_first);
 
173
  virtual const uchar *unpack(uchar *to, const uchar *from,
 
174
                              uint param_data, bool low_byte_first);
 
175
  const uchar *unpack_key(uchar* to, const uchar *from,
 
176
                          uint max_length, bool low_byte_first);
 
177
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
178
               bool insert_or_update);
 
179
  int pack_cmp(const uchar *b, uint key_length,bool insert_or_update);
 
180
  uint packed_col_length(const uchar *col_ptr, uint length);
 
181
  uint max_packed_col_length(uint max_length);
185
182
  void free() { value.free(); }
186
183
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
187
184
  friend int field_conv(Field *to,Field *from);
188
 
  uint32_t size_of() const { return sizeof(*this); }
 
185
  uint size_of() const { return sizeof(*this); }
189
186
  bool has_charset(void) const
190
187
  { return charset() == &my_charset_bin ? false : true; }
191
188
  uint32_t max_display_length();
 
189
  uint is_equal(Create_field *new_field);
 
190
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
 
191
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
 
192
private:
 
193
  int do_save_field_metadata(uchar *first_byte);
192
194
};
193
195
 
194
 
} /* namespace drizzled */
195
 
 
196
 
#endif /* DRIZZLED_FIELD_BLOB_H */
 
196
#endif
197
197