21
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
22
22
#define DRIZZLE_SERVER_FIELD_BLOB
24
#include <drizzled/field/longstr.h>
26
24
class Field_blob :public Field_longstr {
29
27
String value; // For temporaries
31
Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
29
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
32
30
enum utype unireg_check_arg, const char *field_name_arg,
33
TABLE_SHARE *share, uint32_t blob_pack_length, const CHARSET_INFO * const cs);
31
TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO * const cs);
34
32
Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
35
33
const CHARSET_INFO * const cs)
36
:Field_longstr((unsigned char*) 0, len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
34
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
37
35
NONE, field_name_arg, cs),
57
55
Field_blob(uint32_t packlength_arg)
58
:Field_longstr((unsigned char*) 0, 0, (unsigned char*) "", 0, NONE, "temp", system_charset_info),
56
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
59
57
packlength(packlength_arg) {}
60
58
enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
61
59
enum ha_base_keytype key_type() const
62
60
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
63
int store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
61
int store(const char *to,uint length, const CHARSET_INFO * const charset);
64
62
int store(double nr);
65
63
int store(int64_t nr, bool unsigned_val);
66
64
double val_real(void);
67
65
int64_t val_int(void);
68
66
String *val_str(String*,String *);
69
67
my_decimal *val_decimal(my_decimal *);
70
int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
71
int cmp(const unsigned char *a,const unsigned char *b)
68
int cmp_max(const uchar *, const uchar *, uint32_t max_length);
69
int cmp(const uchar *a,const uchar *b)
72
70
{ return cmp_max(a, b, UINT32_MAX); }
73
int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
74
int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
75
int key_cmp(const unsigned char *,const unsigned char*);
76
int key_cmp(const unsigned char *str, uint32_t length);
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=UINT32_MAX);
73
int key_cmp(const uchar *,const uchar*);
74
int key_cmp(const uchar *str, uint length);
77
75
uint32_t key_length() const { return 0; }
78
void sort_string(unsigned char *buff,uint32_t length);
79
uint32_t pack_length() const;
76
void sort_string(uchar *buff,uint length);
77
uint32_t pack_length() const
78
{ return (uint32_t) (packlength+table->s->blob_ptr_size); }
83
81
Return the packed length without the pointer size added.
90
88
uint32_t pack_length_no_ptr() const
91
89
{ return (uint32_t) (packlength); }
92
uint32_t row_pack_length() { return pack_length_no_ptr(); }
90
uint row_pack_length() { return pack_length_no_ptr(); }
93
91
uint32_t sort_length() const;
94
92
virtual uint32_t max_data_length() const
96
94
return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
98
int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
96
int reset(void) { memset(ptr, 0, packlength+sizeof(uchar*)); return 0; }
99
97
void reset_fields() { memset(&value, 0, sizeof(value)); }
100
98
#ifndef WORDS_BIGENDIAN
103
void store_length(unsigned char *i_ptr, uint32_t i_packlength,
104
uint32_t i_number, bool low_byte_first);
105
void store_length(unsigned char *i_ptr, uint32_t i_packlength,
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);
108
106
inline void store_length(uint32_t number)
110
108
store_length(ptr, packlength, number);
119
117
@returns The length in the row plus the size of the data.
121
uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
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);}
123
uint32_t get_length(uint32_t row_offset= 0);
124
uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
125
bool low_byte_first);
126
uint32_t get_length(const unsigned char *ptr_arg);
127
void put_length(unsigned char *pos, uint32_t length);
128
inline void get_ptr(unsigned char **str)
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)
130
memcpy(str,ptr+packlength,sizeof(unsigned char*));
130
memcpy(str,ptr+packlength,sizeof(uchar*));
132
inline void get_ptr(unsigned char **str, uint32_t row_offset)
132
inline void get_ptr(uchar **str, uint row_offset)
134
134
memcpy(str,ptr+packlength+row_offset,sizeof(char*));
136
inline void set_ptr(unsigned char *length, unsigned char *data)
136
inline void set_ptr(uchar *length, uchar *data)
138
138
memcpy(ptr,length,packlength);
139
139
memcpy(ptr+packlength,&data,sizeof(char*));
141
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
141
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, uchar *data)
143
unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
143
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
144
144
store_length(ptr_ofs, packlength, length);
145
145
memcpy(ptr_ofs+packlength,&data,sizeof(char*));
147
inline void set_ptr(uint32_t length, unsigned char *data)
147
inline void set_ptr(uint32_t length, uchar *data)
149
149
set_ptr_offset(0, length, data);
151
uint32_t get_key_image(unsigned char *buff,uint32_t length, imagetype type);
152
void set_key_image(const unsigned char *buff,uint32_t length);
151
uint get_key_image(uchar *buff,uint length, imagetype type);
152
void set_key_image(const uchar *buff,uint length);
153
153
void sql_type(String &str) const;
154
154
inline bool copy()
158
158
if (value.copy((char*) tmp, get_length(), charset()))
160
160
Field_blob::reset();
163
tmp=(unsigned char*) value.ptr();
163
tmp=(uchar*) value.ptr();
164
164
memcpy(ptr+packlength,&tmp,sizeof(char*));
167
virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
168
uint32_t max_length, bool low_byte_first);
169
unsigned char *pack_key(unsigned char *to, const unsigned char *from,
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);
173
virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
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,
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,
178
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);
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);
182
182
void free() { value.free(); }
183
183
inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
184
184
friend int field_conv(Field *to,Field *from);
185
uint32_t size_of() const { return sizeof(*this); }
185
uint size_of() const { return sizeof(*this); }
186
186
bool has_charset(void) const
187
187
{ return charset() == &my_charset_bin ? false : true; }
188
188
uint32_t max_display_length();
189
uint32_t is_equal(Create_field *new_field);
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); }
193
int do_save_field_metadata(unsigned char *first_byte);
193
int do_save_field_metadata(uchar *first_byte);