~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Jay Pipes
  • Date: 2009-03-13 23:35:46 UTC
  • mto: This revision was merged to the branch mainline in revision 937.
  • Revision ID: jpipes@serialcoder-20090313233546-n12t6xpf71um75fo
Split index hints out into their own file, removal from sql_lex.h and sql_select.cc

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
 
namespace drizzled
31
 
{
32
 
 
33
 
/**
34
 
 * Class representing a BLOB data type column
35
 
 */
36
 
class Field_blob :public Field_str {
 
28
class Field_blob :public Field_longstr {
37
29
protected:
 
30
  uint32_t packlength;
38
31
  String value;                         // For temporaries
39
32
public:
40
33
 
45
38
  using Field::val_int;
46
39
  using Field::val_str;
47
40
 
48
 
  Field_blob(unsigned char *ptr_arg,
49
 
             unsigned char *null_ptr_arg,
50
 
             unsigned char null_bit_arg,
51
 
             const char *field_name_arg,
52
 
             TableShare *share,
53
 
             const CHARSET_INFO * const cs);
54
 
  Field_blob(uint32_t len_arg,
55
 
             bool maybe_null_arg,
56
 
             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,
57
46
             const CHARSET_INFO * const cs)
58
 
    :Field_str((unsigned char*) NULL,
59
 
               len_arg,
60
 
               maybe_null_arg ? (unsigned char *) "": 0,
61
 
               0,
62
 
               field_name_arg,
63
 
               cs)
64
 
  {
65
 
    flags|= BLOB_FLAG;
66
 
  }
67
 
 
 
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) {}
68
71
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
69
72
  enum ha_base_keytype key_type() const
70
73
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
98
101
     @returns The length of the raw data itself without the pointer.
99
102
  */
100
103
  uint32_t pack_length_no_ptr() const
101
 
  { return (uint32_t) (sizeof(uint32_t)); }
102
 
 
 
104
  { return (uint32_t) (packlength); }
 
105
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
103
106
  uint32_t sort_length() const;
104
107
  virtual uint32_t max_data_length() const
105
108
  {
106
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
109
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
107
110
  }
108
 
  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; }
109
112
  void reset_fields() { memset(&value, 0, sizeof(value)); }
110
113
#ifndef WORDS_BIGENDIAN
111
114
  static
112
115
#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);
 
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);
115
120
 
116
121
  inline void store_length(uint32_t number)
117
122
  {
118
 
    store_length(ptr, number);
 
123
    store_length(ptr, packlength, number);
119
124
  }
120
125
 
121
126
  /**
129
134
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
130
135
 
131
136
  uint32_t get_length(uint32_t row_offset= 0);
132
 
  uint32_t get_length(const unsigned char *ptr, bool low_byte_first);
 
137
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
 
138
                      bool low_byte_first);
133
139
  uint32_t get_length(const unsigned char *ptr_arg);
134
140
  void put_length(unsigned char *pos, uint32_t length);
135
141
  inline void get_ptr(unsigned char **str)
136
142
    {
137
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
 
143
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
138
144
    }
139
145
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
140
146
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
 
147
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
142
148
    }
143
149
  inline void set_ptr(unsigned char *length, unsigned char *data)
144
150
    {
145
 
      memcpy(ptr,length,sizeof(uint32_t));
146
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
 
151
      memcpy(ptr,length,packlength);
 
152
      memcpy(ptr+packlength,&data,sizeof(char*));
147
153
    }
148
 
  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)
149
155
    {
150
156
      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*));
 
157
      store_length(ptr_ofs, packlength, length);
 
158
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
153
159
    }
154
160
  inline void set_ptr(uint32_t length, unsigned char *data)
155
161
    {
156
162
      set_ptr_offset(0, length, data);
157
163
    }
158
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
159
 
  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);
160
167
  void set_key_image(const unsigned char *buff,uint32_t length);
161
168
  void sql_type(String &str) const;
162
169
  inline bool copy()
169
176
      return 1;
170
177
    }
171
178
    tmp=(unsigned char*) value.ptr();
172
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
179
    memcpy(ptr+packlength,&tmp,sizeof(char*));
173
180
    return 0;
174
181
  }
175
182
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
176
183
                      uint32_t max_length, bool low_byte_first);
177
184
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
178
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);
179
188
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
180
 
                              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);
181
197
  void free() { value.free(); }
182
198
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
183
199
  friend int field_conv(Field *to,Field *from);
185
201
  bool has_charset(void) const
186
202
  { return charset() == &my_charset_bin ? false : true; }
187
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);
188
209
};
189
210
 
190
 
} /* namespace drizzled */
191
 
 
192
 
#endif /* DRIZZLED_FIELD_BLOB_H */
 
211
#endif
193
212