~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Lee
  • Date: 2009-01-01 03:07:33 UTC
  • mto: (758.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: lbieber@lbieber-desktop-20090101030733-fb411b55f07vij8q
more header file cleanup

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