173.1.2
by Toru Maesaka
forgot to bzr-add new files in the previous push |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 MySQL
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
#ifndef DRIZZLE_SERVER_FIELD_BLOB
|
|
22 |
#define DRIZZLE_SERVER_FIELD_BLOB
|
|
23 |
||
24 |
#include "mysql_priv.h" |
|
25 |
||
26 |
class Field_blob :public Field_longstr { |
|
27 |
protected: |
|
28 |
uint packlength; |
|
29 |
String value; // For temporaries |
|
30 |
public: |
|
31 |
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
|
32 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
33 |
TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs); |
|
34 |
Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
35 |
CHARSET_INFO *cs) |
|
36 |
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, |
|
37 |
NONE, field_name_arg, cs), |
|
38 |
packlength(4) |
|
39 |
{
|
|
40 |
flags|= BLOB_FLAG; |
|
41 |
}
|
|
42 |
Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
43 |
CHARSET_INFO *cs, bool set_packlength) |
|
44 |
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, |
|
45 |
NONE, field_name_arg, cs) |
|
46 |
{
|
|
47 |
flags|= BLOB_FLAG; |
|
48 |
packlength= 4; |
|
49 |
if (set_packlength) |
|
50 |
{
|
|
51 |
uint32_t l_char_length= len_arg/cs->mbmaxlen; |
|
52 |
packlength= l_char_length <= 255 ? 1 : |
|
53 |
l_char_length <= 65535 ? 2 : |
|
54 |
l_char_length <= 16777215 ? 3 : 4; |
|
55 |
}
|
|
56 |
}
|
|
57 |
Field_blob(uint32_t packlength_arg) |
|
58 |
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info), |
|
59 |
packlength(packlength_arg) {} |
|
60 |
enum_field_types type() const { return MYSQL_TYPE_BLOB;} |
|
61 |
enum ha_base_keytype key_type() const |
|
62 |
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } |
|
63 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
64 |
int store(double nr); |
|
65 |
int store(int64_t nr, bool unsigned_val); |
|
66 |
double val_real(void); |
|
67 |
int64_t val_int(void); |
|
68 |
String *val_str(String*,String *); |
|
69 |
my_decimal *val_decimal(my_decimal *); |
|
70 |
int cmp_max(const uchar *, const uchar *, uint max_length); |
|
71 |
int cmp(const uchar *a,const uchar *b) |
|
72 |
{ return cmp_max(a, b, ~0L); } |
|
73 |
int cmp(const uchar *a, uint32_t a_length, const uchar *b, uint32_t b_length); |
|
74 |
int cmp_binary(const uchar *a,const uchar *b, uint32_t max_length=~0L); |
|
75 |
int key_cmp(const uchar *,const uchar*); |
|
76 |
int key_cmp(const uchar *str, uint length); |
|
77 |
uint32_t key_length() const { return 0; } |
|
78 |
void sort_string(uchar *buff,uint length); |
|
79 |
uint32_t pack_length() const |
|
80 |
{ return (uint32_t) (packlength+table->s->blob_ptr_size); } |
|
81 |
||
82 |
/**
|
|
83 |
Return the packed length without the pointer size added.
|
|
84 |
||
85 |
This is used to determine the size of the actual data in the row
|
|
86 |
buffer.
|
|
87 |
||
88 |
@returns The length of the raw data itself without the pointer.
|
|
89 |
*/
|
|
90 |
uint32_t pack_length_no_ptr() const |
|
91 |
{ return (uint32_t) (packlength); } |
|
92 |
uint row_pack_length() { return pack_length_no_ptr(); } |
|
93 |
uint32_t sort_length() const; |
|
94 |
virtual uint32_t max_data_length() const |
|
95 |
{
|
|
96 |
return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1); |
|
97 |
}
|
|
98 |
int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; } |
|
99 |
void reset_fields() { bzero((uchar*) &value,sizeof(value)); } |
|
100 |
#ifndef WORDS_BIGENDIAN
|
|
101 |
static
|
|
102 |
#endif
|
|
103 |
void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number, bool low_byte_first); |
|
104 |
void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number) |
|
105 |
{
|
|
106 |
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first); |
|
107 |
}
|
|
108 |
inline void store_length(uint32_t number) |
|
109 |
{
|
|
110 |
store_length(ptr, packlength, number); |
|
111 |
}
|
|
112 |
||
113 |
/**
|
|
114 |
Return the packed length plus the length of the data.
|
|
115 |
||
116 |
This is used to determine the size of the data plus the
|
|
117 |
packed length portion in the row data.
|
|
118 |
||
119 |
@returns The length in the row plus the size of the data.
|
|
120 |
*/
|
|
121 |
uint32_t get_packed_size(const uchar *ptr_arg, bool low_byte_first) |
|
122 |
{return packlength + get_length(ptr_arg, packlength, low_byte_first);} |
|
123 |
||
124 |
inline uint32_t get_length(uint row_offset= 0) |
|
125 |
{ return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); } |
|
126 |
uint32_t get_length(const uchar *ptr, uint packlength, bool low_byte_first); |
|
127 |
uint32_t get_length(const uchar *ptr_arg) |
|
128 |
{ return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); } |
|
129 |
void put_length(uchar *pos, uint32_t length); |
|
130 |
inline void get_ptr(uchar **str) |
|
131 |
{
|
|
132 |
memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*)); |
|
133 |
}
|
|
134 |
inline void get_ptr(uchar **str, uint row_offset) |
|
135 |
{
|
|
136 |
memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*)); |
|
137 |
}
|
|
138 |
inline void set_ptr(uchar *length, uchar *data) |
|
139 |
{
|
|
140 |
memcpy(ptr,length,packlength); |
|
141 |
memcpy_fixed(ptr+packlength,&data,sizeof(char*)); |
|
142 |
}
|
|
143 |
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, uchar *data) |
|
144 |
{
|
|
145 |
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*); |
|
146 |
store_length(ptr_ofs, packlength, length); |
|
147 |
memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*)); |
|
148 |
}
|
|
149 |
inline void set_ptr(uint32_t length, uchar *data) |
|
150 |
{
|
|
151 |
set_ptr_offset(0, length, data); |
|
152 |
}
|
|
153 |
uint get_key_image(uchar *buff,uint length, imagetype type); |
|
154 |
void set_key_image(const uchar *buff,uint length); |
|
155 |
void sql_type(String &str) const; |
|
156 |
inline bool copy() |
|
157 |
{
|
|
158 |
uchar *tmp; |
|
159 |
get_ptr(&tmp); |
|
160 |
if (value.copy((char*) tmp, get_length(), charset())) |
|
161 |
{
|
|
162 |
Field_blob::reset(); |
|
163 |
return 1; |
|
164 |
}
|
|
165 |
tmp=(uchar*) value.ptr(); |
|
166 |
memcpy_fixed(ptr+packlength,&tmp,sizeof(char*)); |
|
167 |
return 0; |
|
168 |
}
|
|
169 |
virtual uchar *pack(uchar *to, const uchar *from, |
|
170 |
uint max_length, bool low_byte_first); |
|
171 |
uchar *pack_key(uchar *to, const uchar *from, |
|
172 |
uint max_length, bool low_byte_first); |
|
173 |
uchar *pack_key_from_key_image(uchar* to, const uchar *from, |
|
174 |
uint max_length, bool low_byte_first); |
|
175 |
virtual const uchar *unpack(uchar *to, const uchar *from, |
|
176 |
uint param_data, bool low_byte_first); |
|
177 |
const uchar *unpack_key(uchar* to, const uchar *from, |
|
178 |
uint max_length, bool low_byte_first); |
|
179 |
int pack_cmp(const uchar *a, const uchar *b, uint key_length, |
|
180 |
my_bool insert_or_update); |
|
181 |
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update); |
|
182 |
uint packed_col_length(const uchar *col_ptr, uint length); |
|
183 |
uint max_packed_col_length(uint max_length); |
|
184 |
void free() { value.free(); } |
|
185 |
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); } |
|
186 |
friend int field_conv(Field *to,Field *from); |
|
187 |
uint size_of() const { return sizeof(*this); } |
|
188 |
bool has_charset(void) const |
|
189 |
{ return charset() == &my_charset_bin ? false : true; } |
|
190 |
uint32_t max_display_length(); |
|
191 |
uint is_equal(Create_field *new_field); |
|
192 |
inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); } |
|
193 |
inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); } |
|
194 |
private: |
|
195 |
int do_save_field_metadata(uchar *first_byte); |
|
196 |
};
|
|
197 |
||
198 |
#endif
|
|
199 |