~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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"
27
 
 
28
 
#include <string>
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
/**
34
 
 * Class representing a BLOB data type column
35
 
 */
36
 
class Field_blob :public Field_str {
 
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
 
22
#define DRIZZLE_SERVER_FIELD_BLOB
 
23
 
 
24
class Field_blob :public Field_longstr {
37
25
protected:
38
26
  uint32_t packlength;
39
27
  String value;                         // For temporaries
40
28
public:
41
 
 
42
 
  using Field::store;
43
 
  using Field::cmp;
44
 
  using Field::pack;
45
 
  using Field::unpack;
46
 
  using Field::val_int;
47
 
  using Field::val_str;
48
 
 
49
 
  Field_blob(unsigned char *ptr_arg,
50
 
             unsigned char *null_ptr_arg,
51
 
             unsigned char null_bit_arg,
52
 
             const char *field_name_arg,
53
 
             TableShare *share,
54
 
             uint32_t blob_pack_length,
55
 
             const CHARSET_INFO * const cs);
56
 
  Field_blob(uint32_t len_arg,
57
 
             bool maybe_null_arg,
58
 
             const char *field_name_arg,
 
29
  Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
 
30
             enum utype unireg_check_arg, const char *field_name_arg,
 
31
             TABLE_SHARE *share, uint32_t blob_pack_length, const CHARSET_INFO * const cs);
 
32
  Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
59
33
             const CHARSET_INFO * const cs)
60
 
    :Field_str((unsigned char*) NULL,
61
 
               len_arg,
62
 
               maybe_null_arg ? (unsigned char *) "": 0,
63
 
               0,
64
 
               field_name_arg,
65
 
               cs),
 
34
    :Field_longstr((unsigned char*) 0, len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
 
35
                   NONE, field_name_arg, cs),
66
36
    packlength(4)
67
37
  {
68
38
    flags|= BLOB_FLAG;
69
39
  }
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)
 
40
  Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
 
41
             const CHARSET_INFO * const cs, bool set_packlength)
 
42
    :Field_longstr((unsigned char*) 0,len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
 
43
                   NONE, field_name_arg, cs)
82
44
  {
83
45
    flags|= BLOB_FLAG;
 
46
    packlength= 4;
84
47
    if (set_packlength)
85
48
    {
86
49
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
90
53
    }
91
54
  }
92
55
  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
 
  {}
 
56
    :Field_longstr((unsigned char*) 0, 0, (unsigned char*) "", 0, NONE, "temp", system_charset_info),
 
57
    packlength(packlength_arg) {}
101
58
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
102
59
  enum ha_base_keytype key_type() const
103
60
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
104
 
  int  store(const char *to,uint32_t length,
105
 
             const CHARSET_INFO * const charset);
 
61
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
106
62
  int  store(double nr);
107
63
  int  store(int64_t nr, bool unsigned_val);
108
 
 
109
64
  double val_real(void);
110
65
  int64_t val_int(void);
111
66
  String *val_str(String*,String *);
119
74
  int key_cmp(const unsigned char *str, uint32_t length);
120
75
  uint32_t key_length() const { return 0; }
121
76
  void sort_string(unsigned char *buff,uint32_t length);
122
 
  uint32_t pack_length() const;
123
 
 
 
77
  uint32_t pack_length() const
 
78
  { return (uint32_t) (packlength+table->s->blob_ptr_size); }
124
79
 
125
80
  /**
126
 
     Return the packed length without the pointer size added.
 
81
     Return the packed length without the pointer size added. 
127
82
 
128
83
     This is used to determine the size of the actual data in the row
129
84
     buffer.
132
87
  */
133
88
  uint32_t pack_length_no_ptr() const
134
89
  { return (uint32_t) (packlength); }
 
90
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
135
91
  uint32_t sort_length() const;
136
92
  virtual uint32_t max_data_length() const
137
93
  {
142
98
#ifndef WORDS_BIGENDIAN
143
99
  static
144
100
#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);
149
 
 
 
101
  void store_length(unsigned char *i_ptr, uint32_t i_packlength, uint32_t i_number, bool low_byte_first);
 
102
  void store_length(unsigned char *i_ptr, uint32_t i_packlength, uint32_t i_number)
 
103
  {
 
104
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
 
105
  }
150
106
  inline void store_length(uint32_t number)
151
107
  {
152
108
    store_length(ptr, packlength, number);
153
109
  }
154
110
 
155
111
  /**
156
 
     Return the packed length plus the length of the data.
 
112
     Return the packed length plus the length of the data. 
157
113
 
158
 
     This is used to determine the size of the data plus the
 
114
     This is used to determine the size of the data plus the 
159
115
     packed length portion in the row data.
160
116
 
161
117
     @returns The length in the row plus the size of the data.
162
118
  */
163
 
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
 
119
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first)
 
120
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
164
121
 
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);
 
122
  inline uint32_t get_length(uint32_t row_offset= 0)
 
123
  { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
 
124
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength, bool low_byte_first);
 
125
  uint32_t get_length(const unsigned char *ptr_arg)
 
126
  { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
169
127
  void put_length(unsigned char *pos, uint32_t length);
170
128
  inline void get_ptr(unsigned char **str)
171
129
    {
180
138
      memcpy(ptr,length,packlength);
181
139
      memcpy(ptr+packlength,&data,sizeof(char*));
182
140
    }
183
 
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
 
141
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
184
142
    {
185
143
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
186
144
      store_length(ptr_ofs, packlength, length);
190
148
    {
191
149
      set_ptr_offset(0, length, data);
192
150
    }
193
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
194
 
  uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
 
151
  uint32_t get_key_image(unsigned char *buff,uint32_t length, imagetype type);
195
152
  void set_key_image(const unsigned char *buff,uint32_t length);
196
153
  void sql_type(String &str) const;
197
154
  inline bool copy()
211
168
                      uint32_t max_length, bool low_byte_first);
212
169
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
213
170
                  uint32_t max_length, bool low_byte_first);
 
171
  unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
 
172
                                 uint32_t max_length, bool low_byte_first);
214
173
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
215
174
                              uint32_t param_data, bool low_byte_first);
 
175
  const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
 
176
                          uint32_t max_length, bool low_byte_first);
 
177
  int pack_cmp(const unsigned char *a, const unsigned char *b, uint32_t key_length,
 
178
               bool insert_or_update);
 
179
  int pack_cmp(const unsigned char *b, uint32_t key_length,bool insert_or_update);
 
180
  uint32_t packed_col_length(const unsigned char *col_ptr, uint32_t length);
 
181
  uint32_t max_packed_col_length(uint32_t max_length);
216
182
  void free() { value.free(); }
217
183
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
218
184
  friend int field_conv(Field *to,Field *from);
220
186
  bool has_charset(void) const
221
187
  { return charset() == &my_charset_bin ? false : true; }
222
188
  uint32_t max_display_length();
 
189
  uint32_t is_equal(Create_field *new_field);
 
190
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
 
191
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
 
192
private:
 
193
  int do_save_field_metadata(unsigned char *first_byte);
223
194
};
224
195
 
225
 
} /* namespace drizzled */
226
 
 
227
 
#endif /* DRIZZLED_FIELD_BLOB_H */
 
196
#endif
228
197