~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

Blackhole, CSV, Pool of Threads,Single Thread, Multi Thread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include <drizzled/field/str.h>
25
25
 
26
 
#include "drizzled/global_charset_info.h"
27
 
 
28
26
#include <string>
29
27
 
30
 
namespace drizzled
31
 
{
32
 
 
33
28
/**
34
29
 * Class representing a BLOB data type column
35
30
 */
36
31
class Field_blob :public Field_str {
37
32
protected:
 
33
  uint32_t packlength;
38
34
  String value;                         // For temporaries
39
35
public:
40
36
 
50
46
             unsigned char null_bit_arg,
51
47
             const char *field_name_arg,
52
48
             TableShare *share,
 
49
             uint32_t blob_pack_length,
53
50
             const CHARSET_INFO * const cs);
54
51
  Field_blob(uint32_t len_arg,
55
52
             bool maybe_null_arg,
60
57
               maybe_null_arg ? (unsigned char *) "": 0,
61
58
               0,
62
59
               field_name_arg,
63
 
               cs)
64
 
  {
65
 
    flags|= BLOB_FLAG;
66
 
  }
67
 
 
 
60
               cs),
 
61
    packlength(4)
 
62
  {
 
63
    flags|= BLOB_FLAG;
 
64
  }
 
65
  Field_blob(uint32_t len_arg,
 
66
             bool maybe_null_arg,
 
67
             const char *field_name_arg,
 
68
             const CHARSET_INFO * const cs,
 
69
             bool set_packlength)
 
70
    :Field_str((unsigned char*) NULL,
 
71
               len_arg,
 
72
               maybe_null_arg ? (unsigned char*) "": 0,
 
73
               0,
 
74
               field_name_arg,
 
75
               cs),
 
76
    packlength(4)
 
77
  {
 
78
    flags|= BLOB_FLAG;
 
79
    if (set_packlength)
 
80
    {
 
81
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
 
82
      packlength= l_char_length <= 255 ? 1 :
 
83
                  l_char_length <= 65535 ? 2 :
 
84
                  l_char_length <= 16777215 ? 3 : 4;
 
85
    }
 
86
  }
 
87
  Field_blob(uint32_t packlength_arg)
 
88
    :Field_str((unsigned char*) 0,
 
89
               0,
 
90
               (unsigned char*) "",
 
91
               0,
 
92
               "temp",
 
93
               system_charset_info),
 
94
    packlength(packlength_arg) 
 
95
  {}
68
96
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
69
97
  enum ha_base_keytype key_type() const
70
98
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
98
126
     @returns The length of the raw data itself without the pointer.
99
127
  */
100
128
  uint32_t pack_length_no_ptr() const
101
 
  { return (uint32_t) (sizeof(uint32_t)); }
102
 
 
 
129
  { return (uint32_t) (packlength); }
 
130
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
103
131
  uint32_t sort_length() const;
104
132
  virtual uint32_t max_data_length() const
105
133
  {
106
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
134
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
107
135
  }
108
 
  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
 
136
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
109
137
  void reset_fields() { memset(&value, 0, sizeof(value)); }
110
138
#ifndef WORDS_BIGENDIAN
111
139
  static
112
140
#endif
113
 
  void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
114
 
  void store_length(unsigned char *i_ptr, uint32_t i_number);
 
141
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
142
                    uint32_t i_number, bool low_byte_first);
 
143
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
144
                    uint32_t i_number);
115
145
 
116
146
  inline void store_length(uint32_t number)
117
147
  {
118
 
    store_length(ptr, number);
 
148
    store_length(ptr, packlength, number);
119
149
  }
120
150
 
121
151
  /**
129
159
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
130
160
 
131
161
  uint32_t get_length(uint32_t row_offset= 0);
132
 
  uint32_t get_length(const unsigned char *ptr, bool low_byte_first);
 
162
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
 
163
                      bool low_byte_first);
133
164
  uint32_t get_length(const unsigned char *ptr_arg);
134
165
  void put_length(unsigned char *pos, uint32_t length);
135
166
  inline void get_ptr(unsigned char **str)
136
167
    {
137
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
 
168
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
138
169
    }
139
170
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
140
171
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
 
172
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
142
173
    }
143
174
  inline void set_ptr(unsigned char *length, unsigned char *data)
144
175
    {
145
 
      memcpy(ptr,length,sizeof(uint32_t));
146
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
 
176
      memcpy(ptr,length,packlength);
 
177
      memcpy(ptr+packlength,&data,sizeof(char*));
147
178
    }
148
179
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
149
180
    {
150
181
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
151
 
      store_length(ptr_ofs, length);
152
 
      memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
 
182
      store_length(ptr_ofs, packlength, length);
 
183
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
153
184
    }
154
185
  inline void set_ptr(uint32_t length, unsigned char *data)
155
186
    {
169
200
      return 1;
170
201
    }
171
202
    tmp=(unsigned char*) value.ptr();
172
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
203
    memcpy(ptr+packlength,&tmp,sizeof(char*));
173
204
    return 0;
174
205
  }
175
206
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
177
208
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
178
209
                  uint32_t max_length, bool low_byte_first);
179
210
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
180
 
                              uint32_t , bool low_byte_first);
 
211
                              uint32_t param_data, bool low_byte_first);
181
212
  void free() { value.free(); }
182
213
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
183
214
  friend int field_conv(Field *to,Field *from);
185
216
  bool has_charset(void) const
186
217
  { return charset() == &my_charset_bin ? false : true; }
187
218
  uint32_t max_display_length();
 
219
  uint32_t is_equal(CreateField *new_field);
 
220
 
 
221
private:
 
222
  int do_save_field_metadata(unsigned char *first_byte);
188
223
};
189
224
 
190
 
} /* namespace drizzled */
191
 
 
192
225
#endif /* DRIZZLED_FIELD_BLOB_H */
193
226