~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

Merge in security refactor.

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); }
 
135
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
107
136
  uint32_t sort_length() const;
108
137
  virtual uint32_t max_data_length() const
109
138
  {
110
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
139
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
111
140
  }
112
 
  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
 
141
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
113
142
  void reset_fields() { memset(&value, 0, sizeof(value)); }
114
143
#ifndef WORDS_BIGENDIAN
115
144
  static
116
145
#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);
 
146
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
147
                    uint32_t i_number, bool low_byte_first);
 
148
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
149
                    uint32_t i_number);
119
150
 
120
151
  inline void store_length(uint32_t number)
121
152
  {
122
 
    store_length(ptr, number);
 
153
    store_length(ptr, packlength, number);
123
154
  }
124
155
 
125
156
  /**
132
163
  */
133
164
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
134
165
 
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);
 
166
  uint32_t get_length(uint32_t row_offset= 0);
 
167
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
 
168
                      bool low_byte_first);
 
169
  uint32_t get_length(const unsigned char *ptr_arg);
138
170
  void put_length(unsigned char *pos, uint32_t length);
139
171
  inline void get_ptr(unsigned char **str)
140
172
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
 
173
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
142
174
    }
143
175
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
144
176
    {
145
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
 
177
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
146
178
    }
147
179
  inline void set_ptr(unsigned char *length, unsigned char *data)
148
180
    {
149
 
      memcpy(ptr,length,sizeof(uint32_t));
150
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
 
181
      memcpy(ptr,length,packlength);
 
182
      memcpy(ptr+packlength,&data,sizeof(char*));
151
183
    }
152
184
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
153
185
    {
154
186
      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*));
 
187
      store_length(ptr_ofs, packlength, length);
 
188
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
157
189
    }
158
190
  inline void set_ptr(uint32_t length, unsigned char *data)
159
191
    {
173
205
      return 1;
174
206
    }
175
207
    tmp=(unsigned char*) value.ptr();
176
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
208
    memcpy(ptr+packlength,&tmp,sizeof(char*));
177
209
    return 0;
178
210
  }
179
211
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
181
213
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
182
214
                  uint32_t max_length, bool low_byte_first);
183
215
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
184
 
                              uint32_t , bool low_byte_first);
 
216
                              uint32_t param_data, bool low_byte_first);
185
217
  void free() { value.free(); }
186
218
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
187
219
  friend int field_conv(Field *to,Field *from);