~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include <string>
29
29
 
30
 
#include "drizzled/visibility.h"
31
 
 
32
30
namespace drizzled
33
31
{
34
32
 
35
33
/**
36
34
 * Class representing a BLOB data type column
37
35
 */
38
 
class DRIZZLED_API Field_blob :
39
 
  public Field_str
40
 
{
 
36
class Field_blob :public Field_str {
41
37
protected:
 
38
  uint32_t packlength;
42
39
  String value;                         // For temporaries
43
40
public:
44
41
 
54
51
             unsigned char null_bit_arg,
55
52
             const char *field_name_arg,
56
53
             TableShare *share,
 
54
             uint32_t blob_pack_length,
57
55
             const CHARSET_INFO * const cs);
58
56
  Field_blob(uint32_t len_arg,
59
57
             bool maybe_null_arg,
64
62
               maybe_null_arg ? (unsigned char *) "": 0,
65
63
               0,
66
64
               field_name_arg,
67
 
               cs)
68
 
  {
69
 
    flags|= BLOB_FLAG;
70
 
  }
71
 
 
 
65
               cs),
 
66
    packlength(4)
 
67
  {
 
68
    flags|= BLOB_FLAG;
 
69
  }
 
70
  Field_blob(uint32_t len_arg,
 
71
             bool maybe_null_arg,
 
72
             const char *field_name_arg,
 
73
             const CHARSET_INFO * const cs,
 
74
             bool set_packlength)
 
75
    :Field_str((unsigned char*) NULL,
 
76
               len_arg,
 
77
               maybe_null_arg ? (unsigned char*) "": 0,
 
78
               0,
 
79
               field_name_arg,
 
80
               cs),
 
81
    packlength(4)
 
82
  {
 
83
    flags|= BLOB_FLAG;
 
84
    if (set_packlength)
 
85
    {
 
86
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
 
87
      packlength= l_char_length <= 255 ? 1 :
 
88
                  l_char_length <= 65535 ? 2 :
 
89
                  l_char_length <= 16777215 ? 3 : 4;
 
90
    }
 
91
  }
 
92
  Field_blob(uint32_t packlength_arg)
 
93
    :Field_str((unsigned char*) 0,
 
94
               0,
 
95
               (unsigned char*) "",
 
96
               0,
 
97
               "temp",
 
98
               system_charset_info),
 
99
    packlength(packlength_arg) 
 
100
  {}
72
101
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
73
102
  enum ha_base_keytype key_type() const
74
103
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
80
109
  double val_real(void);
81
110
  int64_t val_int(void);
82
111
  String *val_str(String*,String *);
83
 
  type::Decimal *val_decimal(type::Decimal *);
 
112
  my_decimal *val_decimal(my_decimal *);
84
113
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
85
114
  int cmp(const unsigned char *a,const unsigned char *b)
86
115
    { return cmp_max(a, b, UINT32_MAX); }
102
131
     @returns The length of the raw data itself without the pointer.
103
132
  */
104
133
  uint32_t pack_length_no_ptr() const
105
 
  { return (uint32_t) (sizeof(uint32_t)); }
106
 
 
 
134
  { return (uint32_t) (packlength); }
107
135
  uint32_t sort_length() const;
108
136
  virtual uint32_t max_data_length() const
109
137
  {
110
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
138
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
111
139
  }
112
 
  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
 
140
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
113
141
  void reset_fields() { memset(&value, 0, sizeof(value)); }
114
142
#ifndef WORDS_BIGENDIAN
115
143
  static
116
144
#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);
 
145
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
146
                    uint32_t i_number, bool low_byte_first);
 
147
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
148
                    uint32_t i_number);
119
149
 
120
150
  inline void store_length(uint32_t number)
121
151
  {
122
 
    store_length(ptr, number);
 
152
    store_length(ptr, packlength, number);
123
153
  }
124
154
 
125
155
  /**
132
162
  */
133
163
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
134
164
 
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);
 
165
  uint32_t get_length(uint32_t row_offset= 0);
 
166
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
 
167
                      bool low_byte_first);
 
168
  uint32_t get_length(const unsigned char *ptr_arg);
138
169
  void put_length(unsigned char *pos, uint32_t length);
139
170
  inline void get_ptr(unsigned char **str)
140
171
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
 
172
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
142
173
    }
143
174
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
144
175
    {
145
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
 
176
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
146
177
    }
147
178
  inline void set_ptr(unsigned char *length, unsigned char *data)
148
179
    {
149
 
      memcpy(ptr,length,sizeof(uint32_t));
150
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
 
180
      memcpy(ptr,length,packlength);
 
181
      memcpy(ptr+packlength,&data,sizeof(char*));
151
182
    }
152
183
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
153
184
    {
154
185
      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*));
 
186
      store_length(ptr_ofs, packlength, length);
 
187
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
157
188
    }
158
189
  inline void set_ptr(uint32_t length, unsigned char *data)
159
190
    {
173
204
      return 1;
174
205
    }
175
206
    tmp=(unsigned char*) value.ptr();
176
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
207
    memcpy(ptr+packlength,&tmp,sizeof(char*));
177
208
    return 0;
178
209
  }
179
210
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
181
212
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
182
213
                  uint32_t max_length, bool low_byte_first);
183
214
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
184
 
                              uint32_t , bool low_byte_first);
 
215
                              uint32_t param_data, bool low_byte_first);
185
216
  void free() { value.free(); }
186
217
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
187
218
  friend int field_conv(Field *to,Field *from);