21
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
22
22
#define DRIZZLE_SERVER_FIELD_BLOB
24
#include <drizzled/field/longstr.h>
24
28
class Field_blob :public Field_longstr {
27
31
String value; // For temporaries
29
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
42
Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
30
43
enum utype unireg_check_arg, const char *field_name_arg,
31
TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO * const cs);
32
Field_blob(uint32_t len_arg,bool maybe_null_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,
33
46
const CHARSET_INFO * const cs)
34
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
47
:Field_longstr((unsigned char*) 0, len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
35
48
NONE, field_name_arg, cs),
40
Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
53
Field_blob(uint32_t len_arg, bool maybe_null_arg, const char *field_name_arg,
41
54
const CHARSET_INFO * const cs, bool set_packlength)
42
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
55
:Field_longstr((unsigned char*) 0,len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
43
56
NONE, field_name_arg, cs)
55
68
Field_blob(uint32_t packlength_arg)
56
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
69
:Field_longstr((unsigned char*) 0, 0, (unsigned char*) "", 0, NONE, "temp", system_charset_info),
57
70
packlength(packlength_arg) {}
58
71
enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
59
72
enum ha_base_keytype key_type() const
60
73
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
61
int store(const char *to,uint length, const CHARSET_INFO * const charset);
74
int store(const char *to,uint32_t length,
75
const CHARSET_INFO * const charset);
62
76
int store(double nr);
63
77
int store(int64_t nr, bool unsigned_val);
64
79
double val_real(void);
65
80
int64_t val_int(void);
66
81
String *val_str(String*,String *);
67
82
my_decimal *val_decimal(my_decimal *);
68
int cmp_max(const uchar *, const uchar *, uint max_length);
69
int cmp(const uchar *a,const uchar *b)
70
{ return cmp_max(a, b, ~0L); }
71
int cmp(const uchar *a, uint32_t a_length, const uchar *b, uint32_t b_length);
72
int cmp_binary(const uchar *a,const uchar *b, uint32_t max_length=~0L);
73
int key_cmp(const uchar *,const uchar*);
74
int key_cmp(const uchar *str, uint length);
83
int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
84
int cmp(const unsigned char *a,const unsigned char *b)
85
{ return cmp_max(a, b, UINT32_MAX); }
86
int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
87
int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
88
int key_cmp(const unsigned char *,const unsigned char*);
89
int key_cmp(const unsigned char *str, uint32_t length);
75
90
uint32_t key_length() const { return 0; }
76
void sort_string(uchar *buff,uint length);
77
uint32_t pack_length() const
78
{ return (uint32_t) (packlength+table->s->blob_ptr_size); }
91
void sort_string(unsigned char *buff,uint32_t length);
92
uint32_t pack_length() const;
81
Return the packed length without the pointer size added.
96
Return the packed length without the pointer size added.
83
98
This is used to determine the size of the actual data in the row
88
103
uint32_t pack_length_no_ptr() const
89
104
{ return (uint32_t) (packlength); }
90
uint row_pack_length() { return pack_length_no_ptr(); }
105
uint32_t row_pack_length() { return pack_length_no_ptr(); }
91
106
uint32_t sort_length() const;
92
107
virtual uint32_t max_data_length() const
94
109
return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
96
int reset(void) { memset(ptr, 0, packlength+sizeof(uchar*)); return 0; }
111
int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
97
112
void reset_fields() { memset(&value, 0, sizeof(value)); }
98
113
#ifndef WORDS_BIGENDIAN
101
void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number, bool low_byte_first);
102
void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number)
104
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
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,
106
121
inline void store_length(uint32_t number)
108
123
store_length(ptr, packlength, number);
112
Return the packed length plus the length of the data.
127
Return the packed length plus the length of the data.
114
This is used to determine the size of the data plus the
129
This is used to determine the size of the data plus the
115
130
packed length portion in the row data.
117
132
@returns The length in the row plus the size of the data.
119
uint32_t get_packed_size(const uchar *ptr_arg, bool low_byte_first)
120
{return packlength + get_length(ptr_arg, packlength, low_byte_first);}
134
uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
122
inline uint32_t get_length(uint row_offset= 0)
123
{ return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
124
uint32_t get_length(const uchar *ptr, uint packlength, bool low_byte_first);
125
uint32_t get_length(const uchar *ptr_arg)
126
{ return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
127
void put_length(uchar *pos, uint32_t length);
128
inline void get_ptr(uchar **str)
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);
140
void put_length(unsigned char *pos, uint32_t length);
141
inline void get_ptr(unsigned char **str)
130
memcpy(str,ptr+packlength,sizeof(uchar*));
143
memcpy(str,ptr+packlength,sizeof(unsigned char*));
132
inline void get_ptr(uchar **str, uint row_offset)
145
inline void get_ptr(unsigned char **str, uint32_t row_offset)
134
147
memcpy(str,ptr+packlength+row_offset,sizeof(char*));
136
inline void set_ptr(uchar *length, uchar *data)
149
inline void set_ptr(unsigned char *length, unsigned char *data)
138
151
memcpy(ptr,length,packlength);
139
152
memcpy(ptr+packlength,&data,sizeof(char*));
141
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, uchar *data)
154
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
143
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
156
unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
144
157
store_length(ptr_ofs, packlength, length);
145
158
memcpy(ptr_ofs+packlength,&data,sizeof(char*));
147
inline void set_ptr(uint32_t length, uchar *data)
160
inline void set_ptr(uint32_t length, unsigned char *data)
149
162
set_ptr_offset(0, length, data);
151
uint get_key_image(uchar *buff,uint length, imagetype type);
152
void set_key_image(const uchar *buff,uint 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);
167
void set_key_image(const unsigned char *buff,uint32_t length);
153
168
void sql_type(String &str) const;
154
169
inline bool copy()
158
173
if (value.copy((char*) tmp, get_length(), charset()))
160
175
Field_blob::reset();
163
tmp=(uchar*) value.ptr();
178
tmp=(unsigned char*) value.ptr();
164
179
memcpy(ptr+packlength,&tmp,sizeof(char*));
167
virtual uchar *pack(uchar *to, const uchar *from,
168
uint max_length, bool low_byte_first);
169
uchar *pack_key(uchar *to, const uchar *from,
170
uint max_length, bool low_byte_first);
171
uchar *pack_key_from_key_image(uchar* to, const uchar *from,
172
uint max_length, bool low_byte_first);
173
virtual const uchar *unpack(uchar *to, const uchar *from,
174
uint param_data, bool low_byte_first);
175
const uchar *unpack_key(uchar* to, const uchar *from,
176
uint max_length, bool low_byte_first);
177
int pack_cmp(const uchar *a, const uchar *b, uint key_length,
182
virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
183
uint32_t max_length, bool low_byte_first);
184
unsigned char *pack_key(unsigned char *to, const unsigned char *from,
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);
188
virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
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,
178
193
bool insert_or_update);
179
int pack_cmp(const uchar *b, uint key_length,bool insert_or_update);
180
uint packed_col_length(const uchar *col_ptr, uint length);
181
uint max_packed_col_length(uint max_length);
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);
182
197
void free() { value.free(); }
183
198
inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
184
199
friend int field_conv(Field *to,Field *from);
185
uint size_of() const { return sizeof(*this); }
200
uint32_t size_of() const { return sizeof(*this); }
186
201
bool has_charset(void) const
187
202
{ return charset() == &my_charset_bin ? false : true; }
188
203
uint32_t max_display_length();
189
uint 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); }
204
uint32_t is_equal(Create_field *new_field);
193
int do_save_field_metadata(uchar *first_byte);
208
int do_save_field_metadata(unsigned char *first_byte);