~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Monty Taylor
  • Date: 2009-03-16 16:56:48 UTC
  • mto: This revision was merged to the branch mainline in revision 938.
  • Revision ID: mordred@inaugust.com-20090316165648-0dsce73jne0qikk0
Addd -Wshadow to PROTOSKIP warnings and turned -Wstrict-aliasing off. Jumped the gun...

Show diffs side-by-side

added added

removed removed

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