~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:14:39 UTC
  • mfrom: (1130.2.18 plugin-base-class)
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006191439-fd1vvlp22654l3k3
Merged latest plugin-base-class.

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
 
#include "drizzled/visibility.h"
31
 
 
32
 
namespace drizzled
33
 
{
34
 
 
35
28
/**
36
29
 * Class representing a BLOB data type column
37
30
 */
38
 
class DRIZZLED_API Field_blob :
39
 
  public Field_str
40
 
{
 
31
class Field_blob :public Field_str {
41
32
protected:
 
33
  uint32_t packlength;
42
34
  String value;                         // For temporaries
43
35
public:
44
36
 
54
46
             unsigned char null_bit_arg,
55
47
             const char *field_name_arg,
56
48
             TableShare *share,
 
49
             uint32_t blob_pack_length,
57
50
             const CHARSET_INFO * const cs);
58
51
  Field_blob(uint32_t len_arg,
59
52
             bool maybe_null_arg,
64
57
               maybe_null_arg ? (unsigned char *) "": 0,
65
58
               0,
66
59
               field_name_arg,
67
 
               cs)
68
 
  {
69
 
    flags|= BLOB_FLAG;
70
 
  }
71
 
 
 
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
  {}
72
96
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
73
97
  enum ha_base_keytype key_type() const
74
98
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
80
104
  double val_real(void);
81
105
  int64_t val_int(void);
82
106
  String *val_str(String*,String *);
83
 
  type::Decimal *val_decimal(type::Decimal *);
 
107
  my_decimal *val_decimal(my_decimal *);
84
108
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
85
109
  int cmp(const unsigned char *a,const unsigned char *b)
86
110
    { return cmp_max(a, b, UINT32_MAX); }
102
126
     @returns The length of the raw data itself without the pointer.
103
127
  */
104
128
  uint32_t pack_length_no_ptr() const
105
 
  { return (uint32_t) (sizeof(uint32_t)); }
106
 
 
 
129
  { return (uint32_t) (packlength); }
 
130
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
107
131
  uint32_t sort_length() const;
108
132
  virtual uint32_t max_data_length() const
109
133
  {
110
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
134
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
111
135
  }
112
 
  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; }
113
137
  void reset_fields() { memset(&value, 0, sizeof(value)); }
114
138
#ifndef WORDS_BIGENDIAN
115
139
  static
116
140
#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);
 
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);
119
145
 
120
146
  inline void store_length(uint32_t number)
121
147
  {
122
 
    store_length(ptr, number);
 
148
    store_length(ptr, packlength, number);
123
149
  }
124
150
 
125
151
  /**
132
158
  */
133
159
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
134
160
 
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);
 
161
  uint32_t get_length(uint32_t row_offset= 0);
 
162
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
 
163
                      bool low_byte_first);
 
164
  uint32_t get_length(const unsigned char *ptr_arg);
138
165
  void put_length(unsigned char *pos, uint32_t length);
139
166
  inline void get_ptr(unsigned char **str)
140
167
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
 
168
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
142
169
    }
143
170
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
144
171
    {
145
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
 
172
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
146
173
    }
147
174
  inline void set_ptr(unsigned char *length, unsigned char *data)
148
175
    {
149
 
      memcpy(ptr,length,sizeof(uint32_t));
150
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
 
176
      memcpy(ptr,length,packlength);
 
177
      memcpy(ptr+packlength,&data,sizeof(char*));
151
178
    }
152
179
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
153
180
    {
154
181
      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*));
 
182
      store_length(ptr_ofs, packlength, length);
 
183
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
157
184
    }
158
185
  inline void set_ptr(uint32_t length, unsigned char *data)
159
186
    {
173
200
      return 1;
174
201
    }
175
202
    tmp=(unsigned char*) value.ptr();
176
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
203
    memcpy(ptr+packlength,&tmp,sizeof(char*));
177
204
    return 0;
178
205
  }
179
206
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
181
208
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
182
209
                  uint32_t max_length, bool low_byte_first);
183
210
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
184
 
                              uint32_t , bool low_byte_first);
 
211
                              uint32_t param_data, bool low_byte_first);
185
212
  void free() { value.free(); }
186
213
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
187
214
  friend int field_conv(Field *to,Field *from);
189
216
  bool has_charset(void) const
190
217
  { return charset() == &my_charset_bin ? false : true; }
191
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);
192
223
};
193
224
 
194
 
} /* namespace drizzled */
195
 
 
196
225
#endif /* DRIZZLED_FIELD_BLOB_H */
197
226