~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

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