1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2006 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
17 |
/*
|
|
18 |
Because of the function new_field() all field classes that have static
|
|
19 |
variables must declare the size_of() member function.
|
|
20 |
*/
|
|
21 |
||
22 |
#ifdef USE_PRAGMA_INTERFACE
|
|
23 |
#pragma interface /* gcc class implementation */ |
|
24 |
#endif
|
|
25 |
||
26 |
#define DATETIME_DEC 6
|
|
27 |
const uint32 max_field_size= (uint32) 4294967295U; |
|
28 |
||
29 |
class Send_field; |
|
30 |
class Protocol; |
|
31 |
class Create_field; |
|
32 |
struct st_cache_field; |
|
33 |
int field_conv(Field *to,Field *from); |
|
34 |
||
35 |
inline uint get_enum_pack_length(int elements) |
|
36 |
{
|
|
37 |
return elements < 256 ? 1 : 2; |
|
38 |
}
|
|
39 |
||
40 |
inline uint get_set_pack_length(int elements) |
|
41 |
{
|
|
42 |
uint len= (elements + 7) / 8; |
|
43 |
return len > 4 ? 8 : len; |
|
44 |
}
|
|
45 |
||
46 |
class Field |
|
47 |
{
|
|
48 |
Field(const Item &); /* Prevent use of these */ |
|
49 |
void operator=(Field &); |
|
50 |
public: |
|
51 |
static void *operator new(size_t size) {return sql_alloc(size); } |
|
52 |
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); } |
|
53 |
||
54 |
uchar *ptr; // Position to field in record |
|
55 |
uchar *null_ptr; // Byte where null_bit is |
|
56 |
/*
|
|
57 |
Note that you can use table->in_use as replacement for current_thd member
|
|
58 |
only inside of val_*() and store() members (e.g. you can't use it in cons)
|
|
59 |
*/
|
|
60 |
struct st_table *table; // Pointer for table |
|
61 |
struct st_table *orig_table; // Pointer to original table |
|
62 |
const char **table_name, *field_name; |
|
63 |
LEX_STRING comment; |
|
64 |
/* Field is part of the following keys */
|
|
65 |
key_map key_start, part_of_key, part_of_key_not_clustered; |
|
66 |
key_map part_of_sortkey; |
|
67 |
/*
|
|
68 |
We use three additional unireg types for TIMESTAMP to overcome limitation
|
|
69 |
of current binary format of .frm file. We'd like to be able to support
|
|
70 |
NOW() as default and on update value for such fields but unable to hold
|
|
71 |
this info anywhere except unireg_check field. This issue will be resolved
|
|
72 |
in more clean way with transition to new text based .frm format.
|
|
73 |
See also comment for Field_timestamp::Field_timestamp().
|
|
74 |
*/
|
|
75 |
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL, |
|
76 |
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD, |
|
77 |
BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD, |
|
78 |
TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD}; |
|
79 |
enum imagetype { itRAW, itMBR}; |
|
80 |
||
81 |
utype unireg_check; |
|
82 |
uint32 field_length; // Length of field |
|
83 |
uint32 flags; |
|
84 |
uint16 field_index; // field number in fields array |
|
85 |
uchar null_bit; // Bit used to test null bit |
|
86 |
/**
|
|
87 |
If true, this field was created in create_tmp_field_from_item from a NULL
|
|
88 |
value. This means that the type of the field is just a guess, and the type
|
|
89 |
may be freely coerced to another type.
|
|
90 |
||
91 |
@see create_tmp_field_from_item
|
|
92 |
@see Item_type_holder::get_real_type
|
|
93 |
||
94 |
*/
|
|
95 |
bool is_created_from_null_item; |
|
96 |
||
97 |
Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg, |
|
98 |
uchar null_bit_arg, utype unireg_check_arg, |
|
99 |
const char *field_name_arg); |
|
100 |
virtual ~Field() {} |
|
101 |
/* Store functions returns 1 on overflow and -1 on fatal error */
|
|
102 |
virtual int store(const char *to, uint length,CHARSET_INFO *cs)=0; |
|
103 |
virtual int store(double nr)=0; |
|
104 |
virtual int store(longlong nr, bool unsigned_val)=0; |
|
105 |
virtual int store_decimal(const my_decimal *d)=0; |
|
106 |
virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type); |
|
107 |
int store(const char *to, uint length, CHARSET_INFO *cs, |
|
108 |
enum_check_fields check_level); |
|
109 |
virtual double val_real(void)=0; |
|
110 |
virtual longlong val_int(void)=0; |
|
111 |
virtual my_decimal *val_decimal(my_decimal *); |
|
112 |
inline String *val_str(String *str) { return val_str(str, str); } |
|
113 |
/*
|
|
114 |
val_str(buf1, buf2) gets two buffers and should use them as follows:
|
|
115 |
if it needs a temp buffer to convert result to string - use buf1
|
|
116 |
example Field_tiny::val_str()
|
|
117 |
if the value exists as a string already - use buf2
|
|
118 |
example Field_string::val_str()
|
|
119 |
consequently, buf2 may be created as 'String buf;' - no memory
|
|
120 |
will be allocated for it. buf1 will be allocated to hold a
|
|
121 |
value if it's too small. Using allocated buffer for buf2 may result in
|
|
122 |
an unnecessary free (and later, may be an alloc).
|
|
123 |
This trickery is used to decrease a number of malloc calls.
|
|
124 |
*/
|
|
125 |
virtual String *val_str(String*,String *)=0; |
|
126 |
String *val_int_as_str(String *val_buffer, my_bool unsigned_flag); |
|
127 |
/*
|
|
128 |
str_needs_quotes() returns TRUE if the value returned by val_str() needs
|
|
129 |
to be quoted when used in constructing an SQL query.
|
|
130 |
*/
|
|
131 |
virtual bool str_needs_quotes() { return FALSE; } |
|
132 |
virtual Item_result result_type () const=0; |
|
133 |
virtual Item_result cmp_type () const { return result_type(); } |
|
134 |
virtual Item_result cast_to_int_type () const { return result_type(); } |
|
135 |
static bool type_can_have_key_part(enum_field_types); |
|
136 |
static enum_field_types field_type_merge(enum_field_types, enum_field_types); |
|
137 |
static Item_result result_merge_type(enum_field_types); |
|
138 |
virtual bool eq(Field *field) |
|
139 |
{
|
|
140 |
return (ptr == field->ptr && null_ptr == field->null_ptr && |
|
141 |
null_bit == field->null_bit); |
|
142 |
}
|
|
143 |
virtual bool eq_def(Field *field); |
|
144 |
||
145 |
/*
|
|
146 |
pack_length() returns size (in bytes) used to store field data in memory
|
|
147 |
(i.e. it returns the maximum size of the field in a row of the table,
|
|
148 |
which is located in RAM).
|
|
149 |
*/
|
|
150 |
virtual uint32 pack_length() const { return (uint32) field_length; } |
|
151 |
||
152 |
/*
|
|
153 |
pack_length_in_rec() returns size (in bytes) used to store field data on
|
|
154 |
storage (i.e. it returns the maximal size of the field in a row of the
|
|
155 |
table, which is located on disk).
|
|
156 |
*/
|
|
157 |
virtual uint32 pack_length_in_rec() const { return pack_length(); } |
|
158 |
virtual int compatible_field_size(uint field_metadata); |
|
159 |
virtual uint pack_length_from_metadata(uint field_metadata) |
|
160 |
{ return field_metadata; } |
|
161 |
/*
|
|
162 |
This method is used to return the size of the data in a row-based
|
|
163 |
replication row record. The default implementation of returning 0 is
|
|
164 |
designed to allow fields that do not use metadata to return TRUE (1)
|
|
165 |
from compatible_field_size() which uses this function in the comparison.
|
|
166 |
The default value for field metadata for fields that do not have
|
|
167 |
metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
|
|
168 |
||
169 |
Note: While most classes that override this method return pack_length(),
|
|
170 |
the classes Field_string, Field_varstring, and Field_blob return
|
|
171 |
field_length + 1, field_length, and pack_length_no_ptr() respectfully.
|
|
172 |
*/
|
|
173 |
virtual uint row_pack_length() { return 0; } |
|
174 |
virtual int save_field_metadata(uchar *first_byte) |
|
175 |
{ return do_save_field_metadata(first_byte); } |
|
176 |
||
177 |
/*
|
|
178 |
data_length() return the "real size" of the data in memory.
|
|
179 |
For varstrings, this does _not_ include the length bytes.
|
|
180 |
*/
|
|
181 |
virtual uint32 data_length() { return pack_length(); } |
|
182 |
/*
|
|
183 |
used_length() returns the number of bytes actually used to store the data
|
|
184 |
of the field. So for a varstring it includes both lenght byte(s) and
|
|
185 |
string data, and anything after data_length() bytes are unused.
|
|
186 |
*/
|
|
187 |
virtual uint32 used_length() { return pack_length(); } |
|
188 |
virtual uint32 sort_length() const { return pack_length(); } |
|
189 |
||
190 |
/**
|
|
191 |
Get the maximum size of the data in packed format.
|
|
192 |
||
193 |
@return Maximum data length of the field when packed using the
|
|
194 |
Field::pack() function.
|
|
195 |
*/
|
|
196 |
virtual uint32 max_data_length() const { |
|
197 |
return pack_length(); |
|
198 |
};
|
|
199 |
||
200 |
virtual int reset(void) { bzero(ptr,pack_length()); return 0; } |
|
201 |
virtual void reset_fields() {} |
|
202 |
virtual void set_default() |
|
203 |
{
|
|
204 |
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values - table->record[0]); |
|
205 |
memcpy(ptr, ptr + l_offset, pack_length()); |
|
206 |
if (null_ptr) |
|
207 |
*null_ptr= ((*null_ptr & (uchar) ~null_bit) | (null_ptr[l_offset] & null_bit)); |
|
208 |
}
|
|
209 |
virtual bool binary() const { return 1; } |
|
210 |
virtual bool zero_pack() const { return 1; } |
|
211 |
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
|
212 |
virtual uint32 key_length() const { return pack_length(); } |
|
213 |
virtual enum_field_types type() const =0; |
|
214 |
virtual enum_field_types real_type() const { return type(); } |
|
215 |
inline int cmp(const uchar *str) { return cmp(ptr,str); } |
|
216 |
virtual int cmp_max(const uchar *a, const uchar *b, uint max_len) |
|
217 |
{ return cmp(a, b); } |
|
218 |
virtual int cmp(const uchar *,const uchar *)=0; |
|
219 |
virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L) |
|
220 |
{ return memcmp(a,b,pack_length()); } |
|
221 |
virtual int cmp_offset(uint row_offset) |
|
222 |
{ return cmp(ptr,ptr+row_offset); } |
|
223 |
virtual int cmp_binary_offset(uint row_offset) |
|
224 |
{ return cmp_binary(ptr, ptr+row_offset); }; |
|
225 |
virtual int key_cmp(const uchar *a,const uchar *b) |
|
226 |
{ return cmp(a, b); } |
|
227 |
virtual int key_cmp(const uchar *str, uint length) |
|
228 |
{ return cmp(ptr,str); } |
|
229 |
virtual uint decimals() const { return 0; } |
|
230 |
/*
|
|
231 |
Caller beware: sql_type can change str.Ptr, so check
|
|
232 |
ptr() to see if it changed if you are using your own buffer
|
|
233 |
in str and restore it with set() if needed
|
|
234 |
*/
|
|
235 |
virtual void sql_type(String &str) const =0; |
|
236 |
virtual uint size_of() const =0; // For new field |
|
237 |
inline bool is_null(my_ptrdiff_t row_offset= 0) |
|
238 |
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; } |
|
239 |
inline bool is_real_null(my_ptrdiff_t row_offset= 0) |
|
240 |
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; } |
|
241 |
inline bool is_null_in_record(const uchar *record) |
|
242 |
{
|
|
243 |
if (!null_ptr) |
|
244 |
return 0; |
|
245 |
return test(record[(uint) (null_ptr -table->record[0])] & |
|
246 |
null_bit); |
|
247 |
}
|
|
248 |
inline bool is_null_in_record_with_offset(my_ptrdiff_t offset) |
|
249 |
{
|
|
250 |
if (!null_ptr) |
|
251 |
return 0; |
|
252 |
return test(null_ptr[offset] & null_bit); |
|
253 |
}
|
|
254 |
inline void set_null(my_ptrdiff_t row_offset= 0) |
|
255 |
{ if (null_ptr) null_ptr[row_offset]|= null_bit; } |
|
256 |
inline void set_notnull(my_ptrdiff_t row_offset= 0) |
|
257 |
{ if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; } |
|
258 |
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; } |
|
259 |
inline bool real_maybe_null(void) { return null_ptr != 0; } |
|
260 |
||
261 |
enum { |
|
262 |
LAST_NULL_BYTE_UNDEF= 0 |
|
263 |
};
|
|
264 |
||
265 |
/*
|
|
266 |
Find the position of the last null byte for the field.
|
|
267 |
||
268 |
SYNOPSIS
|
|
269 |
last_null_byte()
|
|
270 |
||
271 |
DESCRIPTION
|
|
272 |
Return a pointer to the last byte of the null bytes where the
|
|
273 |
field conceptually is placed.
|
|
274 |
||
275 |
RETURN VALUE
|
|
276 |
The position of the last null byte relative to the beginning of
|
|
277 |
the record. If the field does not use any bits of the null
|
|
278 |
bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
|
|
279 |
*/
|
|
280 |
size_t last_null_byte() const { |
|
281 |
size_t bytes= do_last_null_byte(); |
|
282 |
DBUG_PRINT("debug", ("last_null_byte() ==> %ld", (long) bytes)); |
|
283 |
DBUG_ASSERT(bytes <= table->s->null_bytes); |
|
284 |
return bytes; |
|
285 |
}
|
|
286 |
||
287 |
virtual void make_field(Send_field *); |
|
288 |
virtual void sort_string(uchar *buff,uint length)=0; |
|
289 |
virtual bool optimize_range(uint idx, uint part); |
|
290 |
/*
|
|
291 |
This should be true for fields which, when compared with constant
|
|
292 |
items, can be casted to longlong. In this case we will at 'fix_fields'
|
|
293 |
stage cast the constant items to longlongs and at the execution stage
|
|
294 |
use field->val_int() for comparison. Used to optimize clauses like
|
|
295 |
'a_column BETWEEN date_const, date_const'.
|
|
296 |
*/
|
|
297 |
virtual bool can_be_compared_as_longlong() const { return FALSE; } |
|
298 |
virtual void free() {} |
|
299 |
virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table, |
|
300 |
bool keep_type); |
|
301 |
virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, |
|
302 |
uchar *new_ptr, uchar *new_null_ptr, |
|
303 |
uint new_null_bit); |
|
304 |
Field *clone(MEM_ROOT *mem_root, struct st_table *new_table); |
|
305 |
inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg) |
|
306 |
{
|
|
307 |
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg; |
|
308 |
}
|
|
309 |
inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; } |
|
310 |
virtual void move_field_offset(my_ptrdiff_t ptr_diff) |
|
311 |
{
|
|
312 |
ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*); |
|
313 |
if (null_ptr) |
|
314 |
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*); |
|
315 |
}
|
|
316 |
virtual void get_image(uchar *buff, uint length, CHARSET_INFO *cs) |
|
317 |
{ memcpy(buff,ptr,length); } |
|
318 |
virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) |
|
319 |
{ memcpy(ptr,buff,length); } |
|
320 |
||
321 |
||
322 |
/*
|
|
323 |
Copy a field part into an output buffer.
|
|
324 |
||
325 |
SYNOPSIS
|
|
326 |
Field::get_key_image()
|
|
327 |
buff [out] output buffer
|
|
328 |
length output buffer size
|
|
329 |
type itMBR for geometry blobs, otherwise itRAW
|
|
330 |
||
331 |
DESCRIPTION
|
|
332 |
This function makes a copy of field part of size equal to or
|
|
333 |
less than "length" parameter value.
|
|
334 |
For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
|
|
335 |
is padded by zero byte.
|
|
336 |
||
337 |
NOTES
|
|
338 |
For variable length character fields (i.e. UTF-8) the "length"
|
|
339 |
parameter means a number of output buffer bytes as if all field
|
|
340 |
characters have maximal possible size (mbmaxlen). In the other words,
|
|
341 |
"length" parameter is a number of characters multiplied by
|
|
342 |
field_charset->mbmaxlen.
|
|
343 |
||
344 |
RETURN
|
|
345 |
Number of copied bytes (excluding padded zero bytes -- see above).
|
|
346 |
*/
|
|
347 |
||
348 |
virtual uint get_key_image(uchar *buff, uint length, imagetype type) |
|
349 |
{
|
|
350 |
get_image(buff, length, &my_charset_bin); |
|
351 |
return length; |
|
352 |
}
|
|
353 |
virtual void set_key_image(const uchar *buff,uint length) |
|
354 |
{ set_image(buff,length, &my_charset_bin); } |
|
355 |
inline longlong val_int_offset(uint row_offset) |
|
356 |
{
|
|
357 |
ptr+=row_offset; |
|
358 |
longlong tmp=val_int(); |
|
359 |
ptr-=row_offset; |
|
360 |
return tmp; |
|
361 |
}
|
|
362 |
inline longlong val_int(const uchar *new_ptr) |
|
363 |
{
|
|
364 |
uchar *old_ptr= ptr; |
|
365 |
longlong return_value; |
|
366 |
ptr= (uchar*) new_ptr; |
|
367 |
return_value= val_int(); |
|
368 |
ptr= old_ptr; |
|
369 |
return return_value; |
|
370 |
}
|
|
371 |
inline String *val_str(String *str, const uchar *new_ptr) |
|
372 |
{
|
|
373 |
uchar *old_ptr= ptr; |
|
374 |
ptr= (uchar*) new_ptr; |
|
375 |
val_str(str); |
|
376 |
ptr= old_ptr; |
|
377 |
return str; |
|
378 |
}
|
|
379 |
virtual bool send_binary(Protocol *protocol); |
|
380 |
||
381 |
virtual uchar *pack(uchar *to, const uchar *from, |
|
382 |
uint max_length, bool low_byte_first); |
|
383 |
/**
|
|
384 |
@overload Field::pack(uchar*, const uchar*, uint, bool)
|
|
385 |
*/
|
|
386 |
uchar *pack(uchar *to, const uchar *from) |
|
387 |
{
|
|
388 |
DBUG_ENTER("Field::pack"); |
|
389 |
uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first); |
|
390 |
DBUG_RETURN(result); |
|
391 |
}
|
|
392 |
||
393 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
394 |
uint param_data, bool low_byte_first); |
|
395 |
/**
|
|
396 |
@overload Field::unpack(uchar*, const uchar*, uint, bool)
|
|
397 |
*/
|
|
398 |
const uchar *unpack(uchar* to, const uchar *from) |
|
399 |
{
|
|
400 |
DBUG_ENTER("Field::unpack"); |
|
401 |
const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first); |
|
402 |
DBUG_RETURN(result); |
|
403 |
}
|
|
404 |
||
405 |
virtual uchar *pack_key(uchar* to, const uchar *from, |
|
406 |
uint max_length, bool low_byte_first) |
|
407 |
{
|
|
408 |
return pack(to, from, max_length, low_byte_first); |
|
409 |
}
|
|
410 |
virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from, |
|
411 |
uint max_length, bool low_byte_first) |
|
412 |
{
|
|
413 |
return pack(to, from, max_length, low_byte_first); |
|
414 |
}
|
|
415 |
virtual const uchar *unpack_key(uchar* to, const uchar *from, |
|
416 |
uint max_length, bool low_byte_first) |
|
417 |
{
|
|
418 |
return unpack(to, from, max_length, low_byte_first); |
|
419 |
}
|
|
420 |
virtual uint packed_col_length(const uchar *to, uint length) |
|
421 |
{ return length;} |
|
422 |
virtual uint max_packed_col_length(uint max_length) |
|
423 |
{ return max_length;} |
|
424 |
||
425 |
virtual int pack_cmp(const uchar *a,const uchar *b, uint key_length_arg, |
|
426 |
my_bool insert_or_update) |
|
427 |
{ return cmp(a,b); } |
|
428 |
virtual int pack_cmp(const uchar *b, uint key_length_arg, |
|
429 |
my_bool insert_or_update) |
|
430 |
{ return cmp(ptr,b); } |
|
431 |
uint offset(uchar *record) |
|
432 |
{
|
|
433 |
return (uint) (ptr - record); |
|
434 |
}
|
|
435 |
void copy_from_tmp(int offset); |
|
436 |
uint fill_cache_field(struct st_cache_field *copy); |
|
437 |
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
438 |
virtual bool get_time(MYSQL_TIME *ltime); |
|
439 |
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } |
|
440 |
virtual CHARSET_INFO *sort_charset(void) const { return charset(); } |
|
441 |
virtual bool has_charset(void) const { return FALSE; } |
|
442 |
virtual void set_charset(CHARSET_INFO *charset_arg) { } |
|
443 |
virtual enum Derivation derivation(void) const |
|
444 |
{ return DERIVATION_IMPLICIT; } |
|
445 |
virtual void set_derivation(enum Derivation derivation_arg) { } |
|
446 |
bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code, |
|
447 |
int cuted_increment); |
|
448 |
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, |
|
449 |
const char *str, uint str_len, |
|
450 |
timestamp_type ts_type, int cuted_increment); |
|
451 |
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, |
|
452 |
longlong nr, timestamp_type ts_type, |
|
453 |
int cuted_increment); |
|
454 |
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, |
|
455 |
double nr, timestamp_type ts_type); |
|
456 |
inline bool check_overflow(int op_result) |
|
457 |
{
|
|
458 |
return (op_result == E_DEC_OVERFLOW); |
|
459 |
}
|
|
460 |
int warn_if_overflow(int op_result); |
|
461 |
void init(TABLE *table_arg) |
|
462 |
{
|
|
463 |
orig_table= table= table_arg; |
|
464 |
table_name= &table_arg->alias; |
|
465 |
}
|
|
466 |
||
467 |
/* maximum possible display length */
|
|
468 |
virtual uint32 max_display_length()= 0; |
|
469 |
||
470 |
virtual uint is_equal(Create_field *new_field); |
|
471 |
/* convert decimal to longlong with overflow check */
|
|
472 |
longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag, |
|
473 |
int *err); |
|
474 |
/* The max. number of characters */
|
|
475 |
inline uint32 char_length() const |
|
476 |
{
|
|
477 |
return field_length / charset()->mbmaxlen; |
|
478 |
}
|
|
479 |
||
480 |
inline enum ha_storage_media field_storage_type() const |
|
481 |
{
|
|
482 |
return (enum ha_storage_media) |
|
483 |
((flags >> FIELD_STORAGE_FLAGS) & STORAGE_TYPE_MASK); |
|
484 |
}
|
|
485 |
||
486 |
inline enum column_format_type column_format() const |
|
487 |
{
|
|
488 |
return (enum column_format_type) |
|
489 |
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK); |
|
490 |
}
|
|
491 |
||
492 |
#ifndef DBUG_OFF
|
|
493 |
/* Print field value into debug trace, in NULL-aware way. */
|
|
494 |
void dbug_print() |
|
495 |
{
|
|
496 |
if (is_real_null()) |
|
497 |
fprintf(DBUG_FILE, "NULL"); |
|
498 |
else
|
|
499 |
{
|
|
500 |
char buf[256]; |
|
501 |
String str(buf, sizeof(buf), &my_charset_bin); |
|
502 |
str.length(0); |
|
503 |
String *pstr; |
|
504 |
pstr= val_str(&str); |
|
505 |
fprintf(DBUG_FILE, "'%s'", pstr->c_ptr_safe()); |
|
506 |
}
|
|
507 |
}
|
|
508 |
#endif
|
|
509 |
||
510 |
/* Hash value */
|
|
511 |
virtual void hash(ulong *nr, ulong *nr2); |
|
512 |
friend bool reopen_table(THD *,struct st_table *,bool); |
|
513 |
friend int cre_myisam(char * name, register TABLE *form, uint options, |
|
514 |
uint64_t auto_increment_value); |
|
515 |
friend class Copy_field; |
|
516 |
friend class Item_avg_field; |
|
517 |
friend class Item_std_field; |
|
518 |
friend class Item_sum_num; |
|
519 |
friend class Item_sum_sum; |
|
520 |
friend class Item_sum_str; |
|
521 |
friend class Item_sum_count; |
|
522 |
friend class Item_sum_avg; |
|
523 |
friend class Item_sum_std; |
|
524 |
friend class Item_sum_min; |
|
525 |
friend class Item_sum_max; |
|
526 |
friend class Item_func_group_concat; |
|
527 |
||
528 |
private: |
|
529 |
/*
|
|
530 |
Primitive for implementing last_null_byte().
|
|
531 |
||
532 |
SYNOPSIS
|
|
533 |
do_last_null_byte()
|
|
534 |
||
535 |
DESCRIPTION
|
|
536 |
Primitive for the implementation of the last_null_byte()
|
|
537 |
function. This represents the inheritance interface and can be
|
|
538 |
overridden by subclasses.
|
|
539 |
*/
|
|
540 |
virtual size_t do_last_null_byte() const; |
|
541 |
||
542 |
/**
|
|
543 |
Retrieve the field metadata for fields.
|
|
544 |
||
545 |
This default implementation returns 0 and saves 0 in the metadata_ptr
|
|
546 |
value.
|
|
547 |
||
548 |
@param metadata_ptr First byte of field metadata
|
|
549 |
||
550 |
@returns 0 no bytes written.
|
|
551 |
*/
|
|
552 |
virtual int do_save_field_metadata(uchar *metadata_ptr) |
|
553 |
{ return 0; } |
|
554 |
};
|
|
555 |
||
556 |
||
557 |
class Field_num :public Field { |
|
558 |
public: |
|
559 |
const uint8 dec; |
|
560 |
bool zerofill,unsigned_flag; // Purify cannot handle bit fields |
|
561 |
Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, |
|
562 |
uchar null_bit_arg, utype unireg_check_arg, |
|
563 |
const char *field_name_arg, |
|
564 |
uint8 dec_arg, bool zero_arg, bool unsigned_arg); |
|
565 |
Item_result result_type () const { return REAL_RESULT; } |
|
566 |
void prepend_zeros(String *value); |
|
567 |
void add_zerofill_and_unsigned(String &res) const; |
|
568 |
friend class Create_field; |
|
569 |
void make_field(Send_field *); |
|
570 |
uint decimals() const { return (uint) dec; } |
|
571 |
uint size_of() const { return sizeof(*this); } |
|
572 |
bool eq_def(Field *field); |
|
573 |
int store_decimal(const my_decimal *); |
|
574 |
my_decimal *val_decimal(my_decimal *); |
|
575 |
uint is_equal(Create_field *new_field); |
|
576 |
int check_int(CHARSET_INFO *cs, const char *str, int length, |
|
577 |
const char *int_end, int error); |
|
578 |
bool get_int(CHARSET_INFO *cs, const char *from, uint len, |
|
579 |
longlong *rnd, uint64_t unsigned_max, |
|
580 |
longlong signed_min, longlong signed_max); |
|
581 |
};
|
|
582 |
||
583 |
||
584 |
class Field_str :public Field { |
|
585 |
protected: |
|
586 |
CHARSET_INFO *field_charset; |
|
587 |
enum Derivation field_derivation; |
|
588 |
public: |
|
589 |
Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, |
|
590 |
uchar null_bit_arg, utype unireg_check_arg, |
|
591 |
const char *field_name_arg, CHARSET_INFO *charset); |
|
592 |
Item_result result_type () const { return STRING_RESULT; } |
|
593 |
uint decimals() const { return NOT_FIXED_DEC; } |
|
594 |
int store(double nr); |
|
595 |
int store(longlong nr, bool unsigned_val)=0; |
|
596 |
int store_decimal(const my_decimal *); |
|
597 |
int store(const char *to,uint length,CHARSET_INFO *cs)=0; |
|
598 |
uint size_of() const { return sizeof(*this); } |
|
599 |
CHARSET_INFO *charset(void) const { return field_charset; } |
|
600 |
void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; } |
|
601 |
enum Derivation derivation(void) const { return field_derivation; } |
|
602 |
virtual void set_derivation(enum Derivation derivation_arg) |
|
603 |
{ field_derivation= derivation_arg; } |
|
604 |
bool binary() const { return field_charset == &my_charset_bin; } |
|
605 |
uint32 max_display_length() { return field_length; } |
|
606 |
friend class Create_field; |
|
607 |
my_decimal *val_decimal(my_decimal *); |
|
608 |
virtual bool str_needs_quotes() { return TRUE; } |
|
609 |
bool compare_str_field_flags(Create_field *new_field, uint32 flags); |
|
610 |
uint is_equal(Create_field *new_field); |
|
611 |
};
|
|
612 |
||
613 |
||
614 |
/* base class for Field_string, Field_varstring and Field_blob */
|
|
615 |
||
616 |
class Field_longstr :public Field_str |
|
617 |
{
|
|
618 |
protected: |
|
619 |
int report_if_important_data(const char *ptr, const char *end); |
|
620 |
public: |
|
621 |
Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
622 |
uchar null_bit_arg, utype unireg_check_arg, |
|
623 |
const char *field_name_arg, CHARSET_INFO *charset_arg) |
|
624 |
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
|
625 |
field_name_arg, charset_arg) |
|
626 |
{}
|
|
627 |
||
628 |
int store_decimal(const my_decimal *d); |
|
629 |
uint32 max_data_length() const; |
|
630 |
};
|
|
631 |
||
632 |
/* base class for float and double and decimal (old one) */
|
|
633 |
class Field_real :public Field_num { |
|
634 |
public: |
|
635 |
my_bool not_fixed; |
|
636 |
||
637 |
Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
638 |
uchar null_bit_arg, utype unireg_check_arg, |
|
639 |
const char *field_name_arg, |
|
640 |
uint8 dec_arg, bool zero_arg, bool unsigned_arg) |
|
641 |
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
|
642 |
field_name_arg, dec_arg, zero_arg, unsigned_arg), |
|
643 |
not_fixed(dec_arg >= NOT_FIXED_DEC) |
|
644 |
{}
|
|
645 |
int store_decimal(const my_decimal *); |
|
646 |
my_decimal *val_decimal(my_decimal *); |
|
647 |
int truncate(double *nr, double max_length); |
|
648 |
uint32 max_display_length() { return field_length; } |
|
649 |
uint size_of() const { return sizeof(*this); } |
|
650 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
651 |
uint param_data, bool low_byte_first); |
|
652 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
653 |
uint max_length, bool low_byte_first); |
|
654 |
};
|
|
655 |
||
656 |
||
657 |
class Field_decimal :public Field_real { |
|
658 |
public: |
|
659 |
Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
660 |
uchar null_bit_arg, |
|
661 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
662 |
uint8 dec_arg,bool zero_arg,bool unsigned_arg) |
|
663 |
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
664 |
unireg_check_arg, field_name_arg, |
|
665 |
dec_arg, zero_arg, unsigned_arg) |
|
666 |
{}
|
|
667 |
enum_field_types type() const { return MYSQL_TYPE_DECIMAL;} |
|
668 |
enum ha_base_keytype key_type() const |
|
669 |
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; } |
|
670 |
int reset(void); |
|
671 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
672 |
int store(double nr); |
|
673 |
int store(longlong nr, bool unsigned_val); |
|
674 |
double val_real(void); |
|
675 |
longlong val_int(void); |
|
676 |
String *val_str(String*,String *); |
|
677 |
int cmp(const uchar *,const uchar *); |
|
678 |
void sort_string(uchar *buff,uint length); |
|
679 |
void overflow(bool negative); |
|
680 |
bool zero_pack() const { return 0; } |
|
681 |
void sql_type(String &str) const; |
|
682 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
683 |
uint param_data, bool low_byte_first) |
|
684 |
{
|
|
685 |
return Field::unpack(to, from, param_data, low_byte_first); |
|
686 |
}
|
|
687 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
688 |
uint max_length, bool low_byte_first) |
|
689 |
{
|
|
690 |
return Field::pack(to, from, max_length, low_byte_first); |
|
691 |
}
|
|
692 |
};
|
|
693 |
||
694 |
||
695 |
/* New decimal/numeric field which use fixed point arithmetic */
|
|
696 |
class Field_new_decimal :public Field_num { |
|
697 |
private: |
|
698 |
int do_save_field_metadata(uchar *first_byte); |
|
699 |
public: |
|
700 |
/* The maximum number of decimal digits can be stored */
|
|
701 |
uint precision; |
|
702 |
uint bin_size; |
|
703 |
/*
|
|
704 |
Constructors take max_length of the field as a parameter - not the
|
|
705 |
precision as the number of decimal digits allowed.
|
|
706 |
So for example we need to count length from precision handling
|
|
707 |
CREATE TABLE ( DECIMAL(x,y))
|
|
708 |
*/
|
|
709 |
Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
710 |
uchar null_bit_arg, |
|
711 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
712 |
uint8 dec_arg, bool zero_arg, bool unsigned_arg); |
|
713 |
Field_new_decimal(uint32 len_arg, bool maybe_null_arg, |
|
714 |
const char *field_name_arg, uint8 dec_arg, |
|
715 |
bool unsigned_arg); |
|
716 |
enum_field_types type() const { return MYSQL_TYPE_NEWDECIMAL;} |
|
717 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
|
718 |
Item_result result_type () const { return DECIMAL_RESULT; } |
|
719 |
int reset(void); |
|
720 |
bool store_value(const my_decimal *decimal_value); |
|
721 |
void set_value_on_overflow(my_decimal *decimal_value, bool sign); |
|
722 |
int store(const char *to, uint length, CHARSET_INFO *charset); |
|
723 |
int store(double nr); |
|
724 |
int store(longlong nr, bool unsigned_val); |
|
725 |
int store_time(MYSQL_TIME *ltime, timestamp_type t_type); |
|
726 |
int store_decimal(const my_decimal *); |
|
727 |
double val_real(void); |
|
728 |
longlong val_int(void); |
|
729 |
my_decimal *val_decimal(my_decimal *); |
|
730 |
String *val_str(String*, String *); |
|
731 |
int cmp(const uchar *, const uchar *); |
|
732 |
void sort_string(uchar *buff, uint length); |
|
733 |
bool zero_pack() const { return 0; } |
|
734 |
void sql_type(String &str) const; |
|
735 |
uint32 max_display_length() { return field_length; } |
|
736 |
uint size_of() const { return sizeof(*this); } |
|
737 |
uint32 pack_length() const { return (uint32) bin_size; } |
|
738 |
uint pack_length_from_metadata(uint field_metadata); |
|
739 |
uint row_pack_length() { return pack_length(); } |
|
740 |
int compatible_field_size(uint field_metadata); |
|
741 |
uint is_equal(Create_field *new_field); |
|
742 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
743 |
uint param_data, bool low_byte_first); |
|
744 |
};
|
|
745 |
||
746 |
||
747 |
class Field_tiny :public Field_num { |
|
748 |
public: |
|
749 |
Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
750 |
uchar null_bit_arg, |
|
751 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
752 |
bool zero_arg, bool unsigned_arg) |
|
753 |
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
754 |
unireg_check_arg, field_name_arg, |
|
755 |
0, zero_arg,unsigned_arg) |
|
756 |
{}
|
|
757 |
enum Item_result result_type () const { return INT_RESULT; } |
|
758 |
enum_field_types type() const { return MYSQL_TYPE_TINY;} |
|
759 |
enum ha_base_keytype key_type() const |
|
760 |
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; } |
|
761 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
762 |
int store(double nr); |
|
763 |
int store(longlong nr, bool unsigned_val); |
|
764 |
int reset(void) { ptr[0]=0; return 0; } |
|
765 |
double val_real(void); |
|
766 |
longlong val_int(void); |
|
767 |
String *val_str(String*,String *); |
|
768 |
bool send_binary(Protocol *protocol); |
|
769 |
int cmp(const uchar *,const uchar *); |
|
770 |
void sort_string(uchar *buff,uint length); |
|
771 |
uint32 pack_length() const { return 1; } |
|
772 |
void sql_type(String &str) const; |
|
773 |
uint32 max_display_length() { return 4; } |
|
774 |
||
775 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
776 |
uint max_length, bool low_byte_first) |
|
777 |
{
|
|
778 |
*to= *from; |
|
779 |
return to + 1; |
|
780 |
}
|
|
781 |
||
782 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
783 |
uint param_data, bool low_byte_first) |
|
784 |
{
|
|
785 |
*to= *from; |
|
786 |
return from + 1; |
|
787 |
}
|
|
788 |
};
|
|
789 |
||
790 |
||
791 |
class Field_short :public Field_num { |
|
792 |
public: |
|
793 |
Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
794 |
uchar null_bit_arg, |
|
795 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
796 |
bool zero_arg, bool unsigned_arg) |
|
797 |
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
798 |
unireg_check_arg, field_name_arg, |
|
799 |
0, zero_arg,unsigned_arg) |
|
800 |
{}
|
|
801 |
Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
802 |
bool unsigned_arg) |
|
803 |
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, |
|
804 |
NONE, field_name_arg, 0, 0, unsigned_arg) |
|
805 |
{}
|
|
806 |
enum Item_result result_type () const { return INT_RESULT; } |
|
807 |
enum_field_types type() const { return MYSQL_TYPE_SHORT;} |
|
808 |
enum ha_base_keytype key_type() const |
|
809 |
{ return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;} |
|
810 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
811 |
int store(double nr); |
|
812 |
int store(longlong nr, bool unsigned_val); |
|
813 |
int reset(void) { ptr[0]=ptr[1]=0; return 0; } |
|
814 |
double val_real(void); |
|
815 |
longlong val_int(void); |
|
816 |
String *val_str(String*,String *); |
|
817 |
bool send_binary(Protocol *protocol); |
|
818 |
int cmp(const uchar *,const uchar *); |
|
819 |
void sort_string(uchar *buff,uint length); |
|
820 |
uint32 pack_length() const { return 2; } |
|
821 |
void sql_type(String &str) const; |
|
822 |
uint32 max_display_length() { return 6; } |
|
823 |
||
824 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
825 |
uint max_length, bool low_byte_first) |
|
826 |
{
|
|
827 |
int16 val; |
|
828 |
#ifdef WORDS_BIGENDIAN
|
|
829 |
if (table->s->db_low_byte_first) |
|
830 |
val = sint2korr(from); |
|
831 |
else
|
|
832 |
#endif
|
|
833 |
shortget(val, from); |
|
834 |
||
835 |
#ifdef WORDS_BIGENDIAN
|
|
836 |
if (low_byte_first) |
|
837 |
int2store(to, val); |
|
838 |
else
|
|
839 |
#endif
|
|
840 |
shortstore(to, val); |
|
841 |
return to + sizeof(val); |
|
842 |
}
|
|
843 |
||
844 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
845 |
uint param_data, bool low_byte_first) |
|
846 |
{
|
|
847 |
int16 val; |
|
848 |
#ifdef WORDS_BIGENDIAN
|
|
849 |
if (low_byte_first) |
|
850 |
val = sint2korr(from); |
|
851 |
else
|
|
852 |
#endif
|
|
853 |
shortget(val, from); |
|
854 |
||
855 |
#ifdef WORDS_BIGENDIAN
|
|
856 |
if (table->s->db_low_byte_first) |
|
857 |
int2store(to, val); |
|
858 |
else
|
|
859 |
#endif
|
|
860 |
shortstore(to, val); |
|
861 |
return from + sizeof(val); |
|
862 |
}
|
|
863 |
};
|
|
864 |
||
865 |
class Field_medium :public Field_num { |
|
866 |
public: |
|
867 |
Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
868 |
uchar null_bit_arg, |
|
869 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
870 |
bool zero_arg, bool unsigned_arg) |
|
871 |
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
872 |
unireg_check_arg, field_name_arg, |
|
873 |
0, zero_arg,unsigned_arg) |
|
874 |
{}
|
|
875 |
enum Item_result result_type () const { return INT_RESULT; } |
|
876 |
enum_field_types type() const { return MYSQL_TYPE_INT24;} |
|
877 |
enum ha_base_keytype key_type() const |
|
878 |
{ return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; } |
|
879 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
880 |
int store(double nr); |
|
881 |
int store(longlong nr, bool unsigned_val); |
|
882 |
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } |
|
883 |
double val_real(void); |
|
884 |
longlong val_int(void); |
|
885 |
String *val_str(String*,String *); |
|
886 |
bool send_binary(Protocol *protocol); |
|
887 |
int cmp(const uchar *,const uchar *); |
|
888 |
void sort_string(uchar *buff,uint length); |
|
889 |
uint32 pack_length() const { return 3; } |
|
890 |
void sql_type(String &str) const; |
|
891 |
uint32 max_display_length() { return 8; } |
|
892 |
||
893 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
894 |
uint max_length, bool low_byte_first) |
|
895 |
{
|
|
896 |
return Field::pack(to, from, max_length, low_byte_first); |
|
897 |
}
|
|
898 |
||
899 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
900 |
uint param_data, bool low_byte_first) |
|
901 |
{
|
|
902 |
return Field::unpack(to, from, param_data, low_byte_first); |
|
903 |
}
|
|
904 |
};
|
|
905 |
||
906 |
||
907 |
class Field_long :public Field_num { |
|
908 |
public: |
|
909 |
Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
910 |
uchar null_bit_arg, |
|
911 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
912 |
bool zero_arg, bool unsigned_arg) |
|
913 |
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
914 |
unireg_check_arg, field_name_arg, |
|
915 |
0, zero_arg,unsigned_arg) |
|
916 |
{}
|
|
917 |
Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
918 |
bool unsigned_arg) |
|
919 |
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, |
|
920 |
NONE, field_name_arg,0,0,unsigned_arg) |
|
921 |
{}
|
|
922 |
enum Item_result result_type () const { return INT_RESULT; } |
|
923 |
enum_field_types type() const { return MYSQL_TYPE_LONG;} |
|
924 |
enum ha_base_keytype key_type() const |
|
925 |
{ return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; } |
|
926 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
927 |
int store(double nr); |
|
928 |
int store(longlong nr, bool unsigned_val); |
|
929 |
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } |
|
930 |
double val_real(void); |
|
931 |
longlong val_int(void); |
|
932 |
bool send_binary(Protocol *protocol); |
|
933 |
String *val_str(String*,String *); |
|
934 |
int cmp(const uchar *,const uchar *); |
|
935 |
void sort_string(uchar *buff,uint length); |
|
936 |
uint32 pack_length() const { return 4; } |
|
937 |
void sql_type(String &str) const; |
|
938 |
uint32 max_display_length() { return MY_INT32_NUM_DECIMAL_DIGITS; } |
|
939 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
940 |
uint max_length, bool low_byte_first) |
|
941 |
{
|
|
942 |
int32 val; |
|
943 |
#ifdef WORDS_BIGENDIAN
|
|
944 |
if (table->s->db_low_byte_first) |
|
945 |
val = sint4korr(from); |
|
946 |
else
|
|
947 |
#endif
|
|
948 |
longget(val, from); |
|
949 |
||
950 |
#ifdef WORDS_BIGENDIAN
|
|
951 |
if (low_byte_first) |
|
952 |
int4store(to, val); |
|
953 |
else
|
|
954 |
#endif
|
|
955 |
longstore(to, val); |
|
956 |
return to + sizeof(val); |
|
957 |
}
|
|
958 |
||
959 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
960 |
uint param_data, bool low_byte_first) |
|
961 |
{
|
|
962 |
int32 val; |
|
963 |
#ifdef WORDS_BIGENDIAN
|
|
964 |
if (low_byte_first) |
|
965 |
val = sint4korr(from); |
|
966 |
else
|
|
967 |
#endif
|
|
968 |
longget(val, from); |
|
969 |
||
970 |
#ifdef WORDS_BIGENDIAN
|
|
971 |
if (table->s->db_low_byte_first) |
|
972 |
int4store(to, val); |
|
973 |
else
|
|
974 |
#endif
|
|
975 |
longstore(to, val); |
|
976 |
return from + sizeof(val); |
|
977 |
}
|
|
978 |
};
|
|
979 |
||
980 |
||
981 |
#ifdef HAVE_LONG_LONG
|
|
982 |
class Field_longlong :public Field_num { |
|
983 |
public: |
|
984 |
Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
985 |
uchar null_bit_arg, |
|
986 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
987 |
bool zero_arg, bool unsigned_arg) |
|
988 |
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
989 |
unireg_check_arg, field_name_arg, |
|
990 |
0, zero_arg,unsigned_arg) |
|
991 |
{}
|
|
992 |
Field_longlong(uint32 len_arg,bool maybe_null_arg, |
|
993 |
const char *field_name_arg, |
|
994 |
bool unsigned_arg) |
|
995 |
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, |
|
996 |
NONE, field_name_arg,0,0,unsigned_arg) |
|
997 |
{}
|
|
998 |
enum Item_result result_type () const { return INT_RESULT; } |
|
999 |
enum_field_types type() const { return MYSQL_TYPE_LONGLONG;} |
|
1000 |
enum ha_base_keytype key_type() const |
|
1001 |
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; } |
|
1002 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1003 |
int store(double nr); |
|
1004 |
int store(longlong nr, bool unsigned_val); |
|
1005 |
int reset(void) |
|
1006 |
{
|
|
1007 |
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; |
|
1008 |
return 0; |
|
1009 |
}
|
|
1010 |
double val_real(void); |
|
1011 |
longlong val_int(void); |
|
1012 |
String *val_str(String*,String *); |
|
1013 |
bool send_binary(Protocol *protocol); |
|
1014 |
int cmp(const uchar *,const uchar *); |
|
1015 |
void sort_string(uchar *buff,uint length); |
|
1016 |
uint32 pack_length() const { return 8; } |
|
1017 |
void sql_type(String &str) const; |
|
1018 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1019 |
uint32 max_display_length() { return 20; } |
|
1020 |
virtual uchar *pack(uchar* to, const uchar *from, |
|
1021 |
uint max_length, bool low_byte_first) |
|
1022 |
{
|
|
1023 |
int64 val; |
|
1024 |
#ifdef WORDS_BIGENDIAN
|
|
1025 |
if (table->s->db_low_byte_first) |
|
1026 |
val = sint8korr(from); |
|
1027 |
else
|
|
1028 |
#endif
|
|
1029 |
longlongget(val, from); |
|
1030 |
||
1031 |
#ifdef WORDS_BIGENDIAN
|
|
1032 |
if (low_byte_first) |
|
1033 |
int8store(to, val); |
|
1034 |
else
|
|
1035 |
#endif
|
|
1036 |
longlongstore(to, val); |
|
1037 |
return to + sizeof(val); |
|
1038 |
}
|
|
1039 |
||
1040 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
1041 |
uint param_data, bool low_byte_first) |
|
1042 |
{
|
|
1043 |
int64 val; |
|
1044 |
#ifdef WORDS_BIGENDIAN
|
|
1045 |
if (low_byte_first) |
|
1046 |
val = sint8korr(from); |
|
1047 |
else
|
|
1048 |
#endif
|
|
1049 |
longlongget(val, from); |
|
1050 |
||
1051 |
#ifdef WORDS_BIGENDIAN
|
|
1052 |
if (table->s->db_low_byte_first) |
|
1053 |
int8store(to, val); |
|
1054 |
else
|
|
1055 |
#endif
|
|
1056 |
longlongstore(to, val); |
|
1057 |
return from + sizeof(val); |
|
1058 |
}
|
|
1059 |
};
|
|
1060 |
#endif
|
|
1061 |
||
1062 |
||
1063 |
class Field_float :public Field_real { |
|
1064 |
public: |
|
1065 |
Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1066 |
uchar null_bit_arg, |
|
1067 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1068 |
uint8 dec_arg,bool zero_arg,bool unsigned_arg) |
|
1069 |
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1070 |
unireg_check_arg, field_name_arg, |
|
1071 |
dec_arg, zero_arg, unsigned_arg) |
|
1072 |
{}
|
|
1073 |
Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, |
|
1074 |
uint8 dec_arg) |
|
1075 |
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0, |
|
1076 |
NONE, field_name_arg, dec_arg, 0, 0) |
|
1077 |
{}
|
|
1078 |
enum_field_types type() const { return MYSQL_TYPE_FLOAT;} |
|
1079 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; } |
|
1080 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1081 |
int store(double nr); |
|
1082 |
int store(longlong nr, bool unsigned_val); |
|
1083 |
int reset(void) { bzero(ptr,sizeof(float)); return 0; } |
|
1084 |
double val_real(void); |
|
1085 |
longlong val_int(void); |
|
1086 |
String *val_str(String*,String *); |
|
1087 |
bool send_binary(Protocol *protocol); |
|
1088 |
int cmp(const uchar *,const uchar *); |
|
1089 |
void sort_string(uchar *buff,uint length); |
|
1090 |
uint32 pack_length() const { return sizeof(float); } |
|
1091 |
uint row_pack_length() { return pack_length(); } |
|
1092 |
void sql_type(String &str) const; |
|
1093 |
private: |
|
1094 |
int do_save_field_metadata(uchar *first_byte); |
|
1095 |
};
|
|
1096 |
||
1097 |
||
1098 |
class Field_double :public Field_real { |
|
1099 |
public: |
|
1100 |
Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1101 |
uchar null_bit_arg, |
|
1102 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1103 |
uint8 dec_arg,bool zero_arg,bool unsigned_arg) |
|
1104 |
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1105 |
unireg_check_arg, field_name_arg, |
|
1106 |
dec_arg, zero_arg, unsigned_arg) |
|
1107 |
{}
|
|
1108 |
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, |
|
1109 |
uint8 dec_arg) |
|
1110 |
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, |
|
1111 |
NONE, field_name_arg, dec_arg, 0, 0) |
|
1112 |
{}
|
|
1113 |
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, |
|
1114 |
uint8 dec_arg, my_bool not_fixed_arg) |
|
1115 |
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, |
|
1116 |
NONE, field_name_arg, dec_arg, 0, 0) |
|
1117 |
{not_fixed= not_fixed_arg; } |
|
1118 |
enum_field_types type() const { return MYSQL_TYPE_DOUBLE;} |
|
1119 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; } |
|
1120 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1121 |
int store(double nr); |
|
1122 |
int store(longlong nr, bool unsigned_val); |
|
1123 |
int reset(void) { bzero(ptr,sizeof(double)); return 0; } |
|
1124 |
double val_real(void); |
|
1125 |
longlong val_int(void); |
|
1126 |
String *val_str(String*,String *); |
|
1127 |
bool send_binary(Protocol *protocol); |
|
1128 |
int cmp(const uchar *,const uchar *); |
|
1129 |
void sort_string(uchar *buff,uint length); |
|
1130 |
uint32 pack_length() const { return sizeof(double); } |
|
1131 |
uint row_pack_length() { return pack_length(); } |
|
1132 |
void sql_type(String &str) const; |
|
1133 |
private: |
|
1134 |
int do_save_field_metadata(uchar *first_byte); |
|
1135 |
};
|
|
1136 |
||
1137 |
||
1138 |
/* Everything saved in this will disappear. It will always return NULL */
|
|
1139 |
||
1140 |
class Field_null :public Field_str { |
|
1141 |
static uchar null[1]; |
|
1142 |
public: |
|
1143 |
Field_null(uchar *ptr_arg, uint32 len_arg, |
|
1144 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1145 |
CHARSET_INFO *cs) |
|
1146 |
:Field_str(ptr_arg, len_arg, null, 1, |
|
1147 |
unireg_check_arg, field_name_arg, cs) |
|
1148 |
{}
|
|
1149 |
enum_field_types type() const { return MYSQL_TYPE_NULL;} |
|
1150 |
int store(const char *to, uint length, CHARSET_INFO *cs) |
|
1151 |
{ null[0]=1; return 0; } |
|
1152 |
int store(double nr) { null[0]=1; return 0; } |
|
1153 |
int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; } |
|
1154 |
int store_decimal(const my_decimal *d) { null[0]=1; return 0; } |
|
1155 |
int reset(void) { return 0; } |
|
1156 |
double val_real(void) { return 0.0;} |
|
1157 |
longlong val_int(void) { return 0;} |
|
1158 |
my_decimal *val_decimal(my_decimal *) { return 0; } |
|
1159 |
String *val_str(String *value,String *value2) |
|
1160 |
{ value2->length(0); return value2;} |
|
1161 |
int cmp(const uchar *a, const uchar *b) { return 0;} |
|
1162 |
void sort_string(uchar *buff, uint length) {} |
|
1163 |
uint32 pack_length() const { return 0; } |
|
1164 |
void sql_type(String &str) const; |
|
1165 |
uint size_of() const { return sizeof(*this); } |
|
1166 |
uint32 max_display_length() { return 4; } |
|
1167 |
};
|
|
1168 |
||
1169 |
||
1170 |
class Field_timestamp :public Field_str { |
|
1171 |
public: |
|
1172 |
Field_timestamp(uchar *ptr_arg, uint32 len_arg, |
|
1173 |
uchar *null_ptr_arg, uchar null_bit_arg, |
|
1174 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1175 |
TABLE_SHARE *share, CHARSET_INFO *cs); |
|
1176 |
Field_timestamp(bool maybe_null_arg, const char *field_name_arg, |
|
1177 |
CHARSET_INFO *cs); |
|
1178 |
enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;} |
|
1179 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } |
|
1180 |
enum Item_result cmp_type () const { return INT_RESULT; } |
|
1181 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1182 |
int store(double nr); |
|
1183 |
int store(longlong nr, bool unsigned_val); |
|
1184 |
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } |
|
1185 |
double val_real(void); |
|
1186 |
longlong val_int(void); |
|
1187 |
String *val_str(String*,String *); |
|
1188 |
bool send_binary(Protocol *protocol); |
|
1189 |
int cmp(const uchar *,const uchar *); |
|
1190 |
void sort_string(uchar *buff,uint length); |
|
1191 |
uint32 pack_length() const { return 4; } |
|
1192 |
void sql_type(String &str) const; |
|
1193 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1194 |
bool zero_pack() const { return 0; } |
|
1195 |
void set_time(); |
|
1196 |
virtual void set_default() |
|
1197 |
{
|
|
1198 |
if (table->timestamp_field == this && |
|
1199 |
unireg_check != TIMESTAMP_UN_FIELD) |
|
1200 |
set_time(); |
|
1201 |
else
|
|
1202 |
Field::set_default(); |
|
1203 |
}
|
|
1204 |
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
|
|
1205 |
inline long get_timestamp(my_bool *null_value) |
|
1206 |
{
|
|
1207 |
if ((*null_value= is_null())) |
|
1208 |
return 0; |
|
1209 |
#ifdef WORDS_BIGENDIAN
|
|
1210 |
if (table && table->s->db_low_byte_first) |
|
1211 |
return sint4korr(ptr); |
|
1212 |
#endif
|
|
1213 |
long tmp; |
|
1214 |
longget(tmp,ptr); |
|
1215 |
return tmp; |
|
1216 |
}
|
|
1217 |
inline void store_timestamp(my_time_t timestamp) |
|
1218 |
{
|
|
1219 |
#ifdef WORDS_BIGENDIAN
|
|
1220 |
if (table && table->s->db_low_byte_first) |
|
1221 |
{
|
|
1222 |
int4store(ptr,timestamp); |
|
1223 |
}
|
|
1224 |
else
|
|
1225 |
#endif
|
|
1226 |
longstore(ptr,(uint32) timestamp); |
|
1227 |
}
|
|
1228 |
bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
1229 |
bool get_time(MYSQL_TIME *ltime); |
|
1230 |
timestamp_auto_set_type get_auto_set_type() const; |
|
1231 |
};
|
|
1232 |
||
1233 |
||
1234 |
class Field_year :public Field_tiny { |
|
1235 |
public: |
|
1236 |
Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1237 |
uchar null_bit_arg, |
|
1238 |
enum utype unireg_check_arg, const char *field_name_arg) |
|
1239 |
:Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1240 |
unireg_check_arg, field_name_arg, 1, 1) |
|
1241 |
{}
|
|
1242 |
enum_field_types type() const { return MYSQL_TYPE_YEAR;} |
|
1243 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1244 |
int store(double nr); |
|
1245 |
int store(longlong nr, bool unsigned_val); |
|
1246 |
double val_real(void); |
|
1247 |
longlong val_int(void); |
|
1248 |
String *val_str(String*,String *); |
|
1249 |
bool send_binary(Protocol *protocol); |
|
1250 |
void sql_type(String &str) const; |
|
1251 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1252 |
};
|
|
1253 |
||
1254 |
||
1255 |
class Field_date :public Field_str { |
|
1256 |
public: |
|
1257 |
Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
|
1258 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1259 |
CHARSET_INFO *cs) |
|
1260 |
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg, |
|
1261 |
unireg_check_arg, field_name_arg, cs) |
|
1262 |
{}
|
|
1263 |
Field_date(bool maybe_null_arg, const char *field_name_arg, |
|
1264 |
CHARSET_INFO *cs) |
|
1265 |
:Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0, |
|
1266 |
NONE, field_name_arg, cs) {} |
|
1267 |
enum_field_types type() const { return MYSQL_TYPE_DATE;} |
|
1268 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } |
|
1269 |
enum Item_result cmp_type () const { return INT_RESULT; } |
|
1270 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1271 |
int store(double nr); |
|
1272 |
int store(longlong nr, bool unsigned_val); |
|
1273 |
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } |
|
1274 |
double val_real(void); |
|
1275 |
longlong val_int(void); |
|
1276 |
String *val_str(String*,String *); |
|
1277 |
bool get_time(MYSQL_TIME *ltime); |
|
1278 |
bool send_binary(Protocol *protocol); |
|
1279 |
int cmp(const uchar *,const uchar *); |
|
1280 |
void sort_string(uchar *buff,uint length); |
|
1281 |
uint32 pack_length() const { return 4; } |
|
1282 |
void sql_type(String &str) const; |
|
1283 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1284 |
bool zero_pack() const { return 1; } |
|
1285 |
};
|
|
1286 |
||
1287 |
||
1288 |
class Field_newdate :public Field_str { |
|
1289 |
public: |
|
1290 |
Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
|
1291 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1292 |
CHARSET_INFO *cs) |
|
1293 |
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg, |
|
1294 |
unireg_check_arg, field_name_arg, cs) |
|
1295 |
{}
|
|
1296 |
Field_newdate(bool maybe_null_arg, const char *field_name_arg, |
|
1297 |
CHARSET_INFO *cs) |
|
1298 |
:Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0, |
|
1299 |
NONE, field_name_arg, cs) {} |
|
1300 |
enum_field_types type() const { return MYSQL_TYPE_DATE;} |
|
1301 |
enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; } |
|
1302 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; } |
|
1303 |
enum Item_result cmp_type () const { return INT_RESULT; } |
|
1304 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1305 |
int store(double nr); |
|
1306 |
int store(longlong nr, bool unsigned_val); |
|
1307 |
int store_time(MYSQL_TIME *ltime, timestamp_type type); |
|
1308 |
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } |
|
1309 |
double val_real(void); |
|
1310 |
longlong val_int(void); |
|
1311 |
String *val_str(String*,String *); |
|
1312 |
bool send_binary(Protocol *protocol); |
|
1313 |
int cmp(const uchar *,const uchar *); |
|
1314 |
void sort_string(uchar *buff,uint length); |
|
1315 |
uint32 pack_length() const { return 3; } |
|
1316 |
void sql_type(String &str) const; |
|
1317 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1318 |
bool zero_pack() const { return 1; } |
|
1319 |
bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
1320 |
bool get_time(MYSQL_TIME *ltime); |
|
1321 |
};
|
|
1322 |
||
1323 |
||
1324 |
class Field_time :public Field_str { |
|
1325 |
public: |
|
1326 |
Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
|
1327 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1328 |
CHARSET_INFO *cs) |
|
1329 |
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg, |
|
1330 |
unireg_check_arg, field_name_arg, cs) |
|
1331 |
{}
|
|
1332 |
Field_time(bool maybe_null_arg, const char *field_name_arg, |
|
1333 |
CHARSET_INFO *cs) |
|
1334 |
:Field_str((uchar*) 0,8, maybe_null_arg ? (uchar*) "": 0,0, |
|
1335 |
NONE, field_name_arg, cs) {} |
|
1336 |
enum_field_types type() const { return MYSQL_TYPE_TIME;} |
|
1337 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } |
|
1338 |
enum Item_result cmp_type () const { return INT_RESULT; } |
|
1339 |
int store_time(MYSQL_TIME *ltime, timestamp_type type); |
|
1340 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1341 |
int store(double nr); |
|
1342 |
int store(longlong nr, bool unsigned_val); |
|
1343 |
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } |
|
1344 |
double val_real(void); |
|
1345 |
longlong val_int(void); |
|
1346 |
String *val_str(String*,String *); |
|
1347 |
bool get_date(MYSQL_TIME *ltime, uint fuzzydate); |
|
1348 |
bool send_binary(Protocol *protocol); |
|
1349 |
bool get_time(MYSQL_TIME *ltime); |
|
1350 |
int cmp(const uchar *,const uchar *); |
|
1351 |
void sort_string(uchar *buff,uint length); |
|
1352 |
uint32 pack_length() const { return 3; } |
|
1353 |
void sql_type(String &str) const; |
|
1354 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1355 |
bool zero_pack() const { return 1; } |
|
1356 |
};
|
|
1357 |
||
1358 |
||
1359 |
class Field_datetime :public Field_str { |
|
1360 |
public: |
|
1361 |
Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
|
1362 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1363 |
CHARSET_INFO *cs) |
|
1364 |
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg, |
|
1365 |
unireg_check_arg, field_name_arg, cs) |
|
1366 |
{}
|
|
1367 |
Field_datetime(bool maybe_null_arg, const char *field_name_arg, |
|
1368 |
CHARSET_INFO *cs) |
|
1369 |
:Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0, |
|
1370 |
NONE, field_name_arg, cs) {} |
|
1371 |
enum_field_types type() const { return MYSQL_TYPE_DATETIME;} |
|
1372 |
#ifdef HAVE_LONG_LONG
|
|
1373 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } |
|
1374 |
#endif
|
|
1375 |
enum Item_result cmp_type () const { return INT_RESULT; } |
|
1376 |
uint decimals() const { return DATETIME_DEC; } |
|
1377 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1378 |
int store(double nr); |
|
1379 |
int store(longlong nr, bool unsigned_val); |
|
1380 |
int store_time(MYSQL_TIME *ltime, timestamp_type type); |
|
1381 |
int reset(void) |
|
1382 |
{
|
|
1383 |
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; |
|
1384 |
return 0; |
|
1385 |
}
|
|
1386 |
double val_real(void); |
|
1387 |
longlong val_int(void); |
|
1388 |
String *val_str(String*,String *); |
|
1389 |
bool send_binary(Protocol *protocol); |
|
1390 |
int cmp(const uchar *,const uchar *); |
|
1391 |
void sort_string(uchar *buff,uint length); |
|
1392 |
uint32 pack_length() const { return 8; } |
|
1393 |
void sql_type(String &str) const; |
|
1394 |
bool can_be_compared_as_longlong() const { return TRUE; } |
|
1395 |
bool zero_pack() const { return 1; } |
|
1396 |
bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
1397 |
bool get_time(MYSQL_TIME *ltime); |
|
1398 |
};
|
|
1399 |
||
1400 |
||
1401 |
class Field_string :public Field_longstr { |
|
1402 |
public: |
|
1403 |
bool can_alter_field_type; |
|
1404 |
Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg, |
|
1405 |
uchar null_bit_arg, |
|
1406 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1407 |
CHARSET_INFO *cs) |
|
1408 |
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1409 |
unireg_check_arg, field_name_arg, cs), |
|
1410 |
can_alter_field_type(1) {}; |
|
1411 |
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
1412 |
CHARSET_INFO *cs) |
|
1413 |
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, |
|
1414 |
NONE, field_name_arg, cs), |
|
1415 |
can_alter_field_type(1) {}; |
|
1416 |
||
1417 |
enum_field_types type() const |
|
1418 |
{
|
|
1419 |
return ((can_alter_field_type && orig_table && |
|
1420 |
orig_table->s->db_create_options & HA_OPTION_PACK_RECORD && |
|
1421 |
field_length >= 4) && |
|
1422 |
orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ? |
|
1423 |
MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING); |
|
1424 |
}
|
|
1425 |
enum ha_base_keytype key_type() const |
|
1426 |
{ return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; } |
|
1427 |
bool zero_pack() const { return 0; } |
|
1428 |
int reset(void) |
|
1429 |
{
|
|
1430 |
charset()->cset->fill(charset(),(char*) ptr, field_length, |
|
1431 |
(has_charset() ? ' ' : 0)); |
|
1432 |
return 0; |
|
1433 |
}
|
|
1434 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1435 |
int store(longlong nr, bool unsigned_val); |
|
1436 |
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */ |
|
1437 |
double val_real(void); |
|
1438 |
longlong val_int(void); |
|
1439 |
String *val_str(String*,String *); |
|
1440 |
my_decimal *val_decimal(my_decimal *); |
|
1441 |
int cmp(const uchar *,const uchar *); |
|
1442 |
void sort_string(uchar *buff,uint length); |
|
1443 |
void sql_type(String &str) const; |
|
1444 |
virtual uchar *pack(uchar *to, const uchar *from, |
|
1445 |
uint max_length, bool low_byte_first); |
|
1446 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
1447 |
uint param_data, bool low_byte_first); |
|
1448 |
uint pack_length_from_metadata(uint field_metadata) |
|
1449 |
{ return (field_metadata & 0x00ff); } |
|
1450 |
uint row_pack_length() { return (field_length + 1); } |
|
1451 |
int pack_cmp(const uchar *a,const uchar *b,uint key_length, |
|
1452 |
my_bool insert_or_update); |
|
1453 |
int pack_cmp(const uchar *b,uint key_length,my_bool insert_or_update); |
|
1454 |
uint packed_col_length(const uchar *to, uint length); |
|
1455 |
uint max_packed_col_length(uint max_length); |
|
1456 |
uint size_of() const { return sizeof(*this); } |
|
1457 |
enum_field_types real_type() const { return MYSQL_TYPE_STRING; } |
|
1458 |
bool has_charset(void) const |
|
1459 |
{ return charset() == &my_charset_bin ? FALSE : TRUE; } |
|
1460 |
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type); |
|
1461 |
virtual uint get_key_image(uchar *buff,uint length, imagetype type); |
|
1462 |
private: |
|
1463 |
int do_save_field_metadata(uchar *first_byte); |
|
1464 |
};
|
|
1465 |
||
1466 |
||
1467 |
class Field_varstring :public Field_longstr { |
|
1468 |
public: |
|
1469 |
/*
|
|
1470 |
The maximum space available in a Field_varstring, in bytes. See
|
|
1471 |
length_bytes.
|
|
1472 |
*/
|
|
1473 |
static const uint MAX_SIZE; |
|
1474 |
/* Store number of bytes used to store length (1 or 2) */
|
|
1475 |
uint32 length_bytes; |
|
1476 |
Field_varstring(uchar *ptr_arg, |
|
1477 |
uint32 len_arg, uint length_bytes_arg, |
|
1478 |
uchar *null_ptr_arg, uchar null_bit_arg, |
|
1479 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1480 |
TABLE_SHARE *share, CHARSET_INFO *cs) |
|
1481 |
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1482 |
unireg_check_arg, field_name_arg, cs), |
|
1483 |
length_bytes(length_bytes_arg) |
|
1484 |
{
|
|
1485 |
share->varchar_fields++; |
|
1486 |
}
|
|
1487 |
Field_varstring(uint32 len_arg,bool maybe_null_arg, |
|
1488 |
const char *field_name_arg, |
|
1489 |
TABLE_SHARE *share, CHARSET_INFO *cs) |
|
1490 |
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, |
|
1491 |
NONE, field_name_arg, cs), |
|
1492 |
length_bytes(len_arg < 256 ? 1 :2) |
|
1493 |
{
|
|
1494 |
share->varchar_fields++; |
|
1495 |
}
|
|
1496 |
||
1497 |
enum_field_types type() const { return MYSQL_TYPE_VARCHAR; } |
|
1498 |
enum ha_base_keytype key_type() const; |
|
1499 |
uint row_pack_length() { return field_length; } |
|
1500 |
bool zero_pack() const { return 0; } |
|
1501 |
int reset(void) { bzero(ptr,field_length+length_bytes); return 0; } |
|
1502 |
uint32 pack_length() const { return (uint32) field_length+length_bytes; } |
|
1503 |
uint32 key_length() const { return (uint32) field_length; } |
|
1504 |
uint32 sort_length() const |
|
1505 |
{
|
|
1506 |
return (uint32) field_length + (field_charset == &my_charset_bin ? |
|
1507 |
length_bytes : 0); |
|
1508 |
}
|
|
1509 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1510 |
int store(longlong nr, bool unsigned_val); |
|
1511 |
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */ |
|
1512 |
double val_real(void); |
|
1513 |
longlong val_int(void); |
|
1514 |
String *val_str(String*,String *); |
|
1515 |
my_decimal *val_decimal(my_decimal *); |
|
1516 |
int cmp_max(const uchar *, const uchar *, uint max_length); |
|
1517 |
int cmp(const uchar *a,const uchar *b) |
|
1518 |
{
|
|
1519 |
return cmp_max(a, b, ~0L); |
|
1520 |
}
|
|
1521 |
void sort_string(uchar *buff,uint length); |
|
1522 |
uint get_key_image(uchar *buff,uint length, imagetype type); |
|
1523 |
void set_key_image(const uchar *buff,uint length); |
|
1524 |
void sql_type(String &str) const; |
|
1525 |
virtual uchar *pack(uchar *to, const uchar *from, |
|
1526 |
uint max_length, bool low_byte_first); |
|
1527 |
uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first); |
|
1528 |
uchar *pack_key_from_key_image(uchar* to, const uchar *from, |
|
1529 |
uint max_length, bool low_byte_first); |
|
1530 |
virtual const uchar *unpack(uchar* to, const uchar *from, |
|
1531 |
uint param_data, bool low_byte_first); |
|
1532 |
const uchar *unpack_key(uchar* to, const uchar *from, |
|
1533 |
uint max_length, bool low_byte_first); |
|
1534 |
int pack_cmp(const uchar *a, const uchar *b, uint key_length, |
|
1535 |
my_bool insert_or_update); |
|
1536 |
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update); |
|
1537 |
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L); |
|
1538 |
int key_cmp(const uchar *,const uchar*); |
|
1539 |
int key_cmp(const uchar *str, uint length); |
|
1540 |
uint packed_col_length(const uchar *to, uint length); |
|
1541 |
uint max_packed_col_length(uint max_length); |
|
1542 |
uint32 data_length(); |
|
1543 |
uint32 used_length(); |
|
1544 |
uint size_of() const { return sizeof(*this); } |
|
1545 |
enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; } |
|
1546 |
bool has_charset(void) const |
|
1547 |
{ return charset() == &my_charset_bin ? FALSE : TRUE; } |
|
1548 |
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type); |
|
1549 |
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, |
|
1550 |
uchar *new_ptr, uchar *new_null_ptr, |
|
1551 |
uint new_null_bit); |
|
1552 |
uint is_equal(Create_field *new_field); |
|
1553 |
void hash(ulong *nr, ulong *nr2); |
|
1554 |
private: |
|
1555 |
int do_save_field_metadata(uchar *first_byte); |
|
1556 |
};
|
|
1557 |
||
1558 |
||
1559 |
class Field_blob :public Field_longstr { |
|
1560 |
protected: |
|
1561 |
uint packlength; |
|
1562 |
String value; // For temporaries |
|
1563 |
public: |
|
1564 |
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
|
1565 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1566 |
TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs); |
|
1567 |
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
1568 |
CHARSET_INFO *cs) |
|
1569 |
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, |
|
1570 |
NONE, field_name_arg, cs), |
|
1571 |
packlength(4) |
|
1572 |
{
|
|
1573 |
flags|= BLOB_FLAG; |
|
1574 |
}
|
|
1575 |
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, |
|
1576 |
CHARSET_INFO *cs, bool set_packlength) |
|
1577 |
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, |
|
1578 |
NONE, field_name_arg, cs) |
|
1579 |
{
|
|
1580 |
flags|= BLOB_FLAG; |
|
1581 |
packlength= 4; |
|
1582 |
if (set_packlength) |
|
1583 |
{
|
|
1584 |
uint32 l_char_length= len_arg/cs->mbmaxlen; |
|
1585 |
packlength= l_char_length <= 255 ? 1 : |
|
1586 |
l_char_length <= 65535 ? 2 : |
|
1587 |
l_char_length <= 16777215 ? 3 : 4; |
|
1588 |
}
|
|
1589 |
}
|
|
1590 |
Field_blob(uint32 packlength_arg) |
|
1591 |
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info), |
|
1592 |
packlength(packlength_arg) {} |
|
1593 |
enum_field_types type() const { return MYSQL_TYPE_BLOB;} |
|
1594 |
enum ha_base_keytype key_type() const |
|
1595 |
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } |
|
1596 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1597 |
int store(double nr); |
|
1598 |
int store(longlong nr, bool unsigned_val); |
|
1599 |
double val_real(void); |
|
1600 |
longlong val_int(void); |
|
1601 |
String *val_str(String*,String *); |
|
1602 |
my_decimal *val_decimal(my_decimal *); |
|
1603 |
int cmp_max(const uchar *, const uchar *, uint max_length); |
|
1604 |
int cmp(const uchar *a,const uchar *b) |
|
1605 |
{ return cmp_max(a, b, ~0L); } |
|
1606 |
int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length); |
|
1607 |
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L); |
|
1608 |
int key_cmp(const uchar *,const uchar*); |
|
1609 |
int key_cmp(const uchar *str, uint length); |
|
1610 |
uint32 key_length() const { return 0; } |
|
1611 |
void sort_string(uchar *buff,uint length); |
|
1612 |
uint32 pack_length() const |
|
1613 |
{ return (uint32) (packlength+table->s->blob_ptr_size); } |
|
1614 |
||
1615 |
/**
|
|
1616 |
Return the packed length without the pointer size added.
|
|
1617 |
||
1618 |
This is used to determine the size of the actual data in the row
|
|
1619 |
buffer.
|
|
1620 |
||
1621 |
@returns The length of the raw data itself without the pointer.
|
|
1622 |
*/
|
|
1623 |
uint32 pack_length_no_ptr() const |
|
1624 |
{ return (uint32) (packlength); } |
|
1625 |
uint row_pack_length() { return pack_length_no_ptr(); } |
|
1626 |
uint32 sort_length() const; |
|
1627 |
virtual uint32 max_data_length() const |
|
1628 |
{
|
|
1629 |
return (uint32) (((uint64_t) 1 << (packlength*8)) -1); |
|
1630 |
}
|
|
1631 |
int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; } |
|
1632 |
void reset_fields() { bzero((uchar*) &value,sizeof(value)); } |
|
1633 |
#ifndef WORDS_BIGENDIAN
|
|
1634 |
static
|
|
1635 |
#endif
|
|
1636 |
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, bool low_byte_first); |
|
1637 |
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number) |
|
1638 |
{
|
|
1639 |
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first); |
|
1640 |
}
|
|
1641 |
inline void store_length(uint32 number) |
|
1642 |
{
|
|
1643 |
store_length(ptr, packlength, number); |
|
1644 |
}
|
|
1645 |
||
1646 |
/**
|
|
1647 |
Return the packed length plus the length of the data.
|
|
1648 |
||
1649 |
This is used to determine the size of the data plus the
|
|
1650 |
packed length portion in the row data.
|
|
1651 |
||
1652 |
@returns The length in the row plus the size of the data.
|
|
1653 |
*/
|
|
1654 |
uint32 get_packed_size(const uchar *ptr_arg, bool low_byte_first) |
|
1655 |
{return packlength + get_length(ptr_arg, packlength, low_byte_first);} |
|
1656 |
||
1657 |
inline uint32 get_length(uint row_offset= 0) |
|
1658 |
{ return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); } |
|
1659 |
uint32 get_length(const uchar *ptr, uint packlength, bool low_byte_first); |
|
1660 |
uint32 get_length(const uchar *ptr_arg) |
|
1661 |
{ return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); } |
|
1662 |
void put_length(uchar *pos, uint32 length); |
|
1663 |
inline void get_ptr(uchar **str) |
|
1664 |
{
|
|
1665 |
memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*)); |
|
1666 |
}
|
|
1667 |
inline void get_ptr(uchar **str, uint row_offset) |
|
1668 |
{
|
|
1669 |
memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*)); |
|
1670 |
}
|
|
1671 |
inline void set_ptr(uchar *length, uchar *data) |
|
1672 |
{
|
|
1673 |
memcpy(ptr,length,packlength); |
|
1674 |
memcpy_fixed(ptr+packlength,&data,sizeof(char*)); |
|
1675 |
}
|
|
1676 |
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data) |
|
1677 |
{
|
|
1678 |
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*); |
|
1679 |
store_length(ptr_ofs, packlength, length); |
|
1680 |
memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*)); |
|
1681 |
}
|
|
1682 |
inline void set_ptr(uint32 length, uchar *data) |
|
1683 |
{
|
|
1684 |
set_ptr_offset(0, length, data); |
|
1685 |
}
|
|
1686 |
uint get_key_image(uchar *buff,uint length, imagetype type); |
|
1687 |
void set_key_image(const uchar *buff,uint length); |
|
1688 |
void sql_type(String &str) const; |
|
1689 |
inline bool copy() |
|
1690 |
{
|
|
1691 |
uchar *tmp; |
|
1692 |
get_ptr(&tmp); |
|
1693 |
if (value.copy((char*) tmp, get_length(), charset())) |
|
1694 |
{
|
|
1695 |
Field_blob::reset(); |
|
1696 |
return 1; |
|
1697 |
}
|
|
1698 |
tmp=(uchar*) value.ptr(); |
|
1699 |
memcpy_fixed(ptr+packlength,&tmp,sizeof(char*)); |
|
1700 |
return 0; |
|
1701 |
}
|
|
1702 |
virtual uchar *pack(uchar *to, const uchar *from, |
|
1703 |
uint max_length, bool low_byte_first); |
|
1704 |
uchar *pack_key(uchar *to, const uchar *from, |
|
1705 |
uint max_length, bool low_byte_first); |
|
1706 |
uchar *pack_key_from_key_image(uchar* to, const uchar *from, |
|
1707 |
uint max_length, bool low_byte_first); |
|
1708 |
virtual const uchar *unpack(uchar *to, const uchar *from, |
|
1709 |
uint param_data, bool low_byte_first); |
|
1710 |
const uchar *unpack_key(uchar* to, const uchar *from, |
|
1711 |
uint max_length, bool low_byte_first); |
|
1712 |
int pack_cmp(const uchar *a, const uchar *b, uint key_length, |
|
1713 |
my_bool insert_or_update); |
|
1714 |
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update); |
|
1715 |
uint packed_col_length(const uchar *col_ptr, uint length); |
|
1716 |
uint max_packed_col_length(uint max_length); |
|
1717 |
void free() { value.free(); } |
|
1718 |
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); } |
|
1719 |
friend int field_conv(Field *to,Field *from); |
|
1720 |
uint size_of() const { return sizeof(*this); } |
|
1721 |
bool has_charset(void) const |
|
1722 |
{ return charset() == &my_charset_bin ? FALSE : TRUE; } |
|
1723 |
uint32 max_display_length(); |
|
1724 |
uint is_equal(Create_field *new_field); |
|
1725 |
inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); } |
|
1726 |
inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); } |
|
1727 |
private: |
|
1728 |
int do_save_field_metadata(uchar *first_byte); |
|
1729 |
};
|
|
1730 |
||
1731 |
||
1732 |
class Field_enum :public Field_str { |
|
1733 |
protected: |
|
1734 |
uint packlength; |
|
1735 |
public: |
|
1736 |
TYPELIB *typelib; |
|
1737 |
Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1738 |
uchar null_bit_arg, |
|
1739 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1740 |
uint packlength_arg, |
|
1741 |
TYPELIB *typelib_arg, |
|
1742 |
CHARSET_INFO *charset_arg) |
|
1743 |
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1744 |
unireg_check_arg, field_name_arg, charset_arg), |
|
1745 |
packlength(packlength_arg),typelib(typelib_arg) |
|
1746 |
{
|
|
1747 |
flags|=ENUM_FLAG; |
|
1748 |
}
|
|
1749 |
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type); |
|
1750 |
enum_field_types type() const { return MYSQL_TYPE_STRING; } |
|
1751 |
enum Item_result cmp_type () const { return INT_RESULT; } |
|
1752 |
enum Item_result cast_to_int_type () const { return INT_RESULT; } |
|
1753 |
enum ha_base_keytype key_type() const; |
|
1754 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1755 |
int store(double nr); |
|
1756 |
int store(longlong nr, bool unsigned_val); |
|
1757 |
double val_real(void); |
|
1758 |
longlong val_int(void); |
|
1759 |
String *val_str(String*,String *); |
|
1760 |
int cmp(const uchar *,const uchar *); |
|
1761 |
void sort_string(uchar *buff,uint length); |
|
1762 |
uint32 pack_length() const { return (uint32) packlength; } |
|
1763 |
void store_type(uint64_t value); |
|
1764 |
void sql_type(String &str) const; |
|
1765 |
uint size_of() const { return sizeof(*this); } |
|
1766 |
enum_field_types real_type() const { return MYSQL_TYPE_ENUM; } |
|
1767 |
uint pack_length_from_metadata(uint field_metadata) |
|
1768 |
{ return (field_metadata & 0x00ff); } |
|
1769 |
uint row_pack_length() { return pack_length(); } |
|
1770 |
virtual bool zero_pack() const { return 0; } |
|
1771 |
bool optimize_range(uint idx, uint part) { return 0; } |
|
1772 |
bool eq_def(Field *field); |
|
1773 |
bool has_charset(void) const { return TRUE; } |
|
1774 |
/* enum and set are sorted as integers */
|
|
1775 |
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } |
|
1776 |
private: |
|
1777 |
int do_save_field_metadata(uchar *first_byte); |
|
1778 |
};
|
|
1779 |
||
1780 |
||
1781 |
class Field_set :public Field_enum { |
|
1782 |
public: |
|
1783 |
Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1784 |
uchar null_bit_arg, |
|
1785 |
enum utype unireg_check_arg, const char *field_name_arg, |
|
1786 |
uint32 packlength_arg, |
|
1787 |
TYPELIB *typelib_arg, CHARSET_INFO *charset_arg) |
|
1788 |
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
|
1789 |
unireg_check_arg, field_name_arg, |
|
1790 |
packlength_arg, |
|
1791 |
typelib_arg,charset_arg) |
|
1792 |
{
|
|
1793 |
flags=(flags & ~ENUM_FLAG) | SET_FLAG; |
|
1794 |
}
|
|
1795 |
int store(const char *to,uint length,CHARSET_INFO *charset); |
|
1796 |
int store(double nr) { return Field_set::store((longlong) nr, FALSE); } |
|
1797 |
int store(longlong nr, bool unsigned_val); |
|
1798 |
||
1799 |
virtual bool zero_pack() const { return 1; } |
|
1800 |
String *val_str(String*,String *); |
|
1801 |
void sql_type(String &str) const; |
|
1802 |
enum_field_types real_type() const { return MYSQL_TYPE_SET; } |
|
1803 |
bool has_charset(void) const { return TRUE; } |
|
1804 |
};
|
|
1805 |
||
1806 |
||
1807 |
/*
|
|
1808 |
Note:
|
|
1809 |
To use Field_bit::cmp_binary() you need to copy the bits stored in
|
|
1810 |
the beginning of the record (the NULL bytes) to each memory you
|
|
1811 |
want to compare (where the arguments point).
|
|
1812 |
||
1813 |
This is the reason:
|
|
1814 |
- Field_bit::cmp_binary() is only implemented in the base class
|
|
1815 |
(Field::cmp_binary()).
|
|
1816 |
- Field::cmp_binary() currenly use pack_length() to calculate how
|
|
1817 |
long the data is.
|
|
1818 |
- pack_length() includes size of the bits stored in the NULL bytes
|
|
1819 |
of the record.
|
|
1820 |
*/
|
|
1821 |
class Field_bit :public Field { |
|
1822 |
public: |
|
1823 |
uchar *bit_ptr; // position in record where 'uneven' bits store |
|
1824 |
uchar bit_ofs; // offset to 'uneven' high bits |
|
1825 |
uint bit_len; // number of 'uneven' high bits |
|
1826 |
uint bytes_in_rec; |
|
1827 |
Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1828 |
uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg, |
|
1829 |
enum utype unireg_check_arg, const char *field_name_arg); |
|
1830 |
enum_field_types type() const { return MYSQL_TYPE_BIT; } |
|
1831 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; } |
|
1832 |
uint32 key_length() const { return (uint32) (field_length + 7) / 8; } |
|
1833 |
uint32 max_data_length() const { return (field_length + 7) / 8; } |
|
1834 |
uint32 max_display_length() { return field_length; } |
|
1835 |
uint size_of() const { return sizeof(*this); } |
|
1836 |
Item_result result_type () const { return INT_RESULT; } |
|
1837 |
int reset(void) { bzero(ptr, bytes_in_rec); return 0; } |
|
1838 |
int store(const char *to, uint length, CHARSET_INFO *charset); |
|
1839 |
int store(double nr); |
|
1840 |
int store(longlong nr, bool unsigned_val); |
|
1841 |
int store_decimal(const my_decimal *); |
|
1842 |
double val_real(void); |
|
1843 |
longlong val_int(void); |
|
1844 |
String *val_str(String*, String *); |
|
1845 |
virtual bool str_needs_quotes() { return TRUE; } |
|
1846 |
my_decimal *val_decimal(my_decimal *); |
|
1847 |
int cmp(const uchar *a, const uchar *b) |
|
1848 |
{
|
|
1849 |
DBUG_ASSERT(ptr == a); |
|
1850 |
return Field_bit::key_cmp(b, bytes_in_rec+test(bit_len)); |
|
1851 |
}
|
|
1852 |
int cmp_binary_offset(uint row_offset) |
|
1853 |
{ return cmp_offset(row_offset); } |
|
1854 |
int cmp_max(const uchar *a, const uchar *b, uint max_length); |
|
1855 |
int key_cmp(const uchar *a, const uchar *b) |
|
1856 |
{ return cmp_binary((uchar *) a, (uchar *) b); } |
|
1857 |
int key_cmp(const uchar *str, uint length); |
|
1858 |
int cmp_offset(uint row_offset); |
|
1859 |
void get_image(uchar *buff, uint length, CHARSET_INFO *cs) |
|
1860 |
{ get_key_image(buff, length, itRAW); } |
|
1861 |
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) |
|
1862 |
{ Field_bit::store((char *) buff, length, cs); } |
|
1863 |
uint get_key_image(uchar *buff, uint length, imagetype type); |
|
1864 |
void set_key_image(const uchar *buff, uint length) |
|
1865 |
{ Field_bit::store((char*) buff, length, &my_charset_bin); } |
|
1866 |
void sort_string(uchar *buff, uint length) |
|
1867 |
{ get_key_image(buff, length, itRAW); } |
|
1868 |
uint32 pack_length() const { return (uint32) (field_length + 7) / 8; } |
|
1869 |
uint32 pack_length_in_rec() const { return bytes_in_rec; } |
|
1870 |
uint pack_length_from_metadata(uint field_metadata); |
|
1871 |
uint row_pack_length() |
|
1872 |
{ return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); } |
|
1873 |
int compatible_field_size(uint field_metadata); |
|
1874 |
void sql_type(String &str) const; |
|
1875 |
virtual uchar *pack(uchar *to, const uchar *from, |
|
1876 |
uint max_length, bool low_byte_first); |
|
1877 |
virtual const uchar *unpack(uchar *to, const uchar *from, |
|
1878 |
uint param_data, bool low_byte_first); |
|
1879 |
virtual void set_default(); |
|
1880 |
||
1881 |
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, |
|
1882 |
uchar *new_ptr, uchar *new_null_ptr, |
|
1883 |
uint new_null_bit); |
|
1884 |
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg) |
|
1885 |
{
|
|
1886 |
bit_ptr= bit_ptr_arg; |
|
1887 |
bit_ofs= bit_ofs_arg; |
|
1888 |
}
|
|
1889 |
bool eq(Field *field) |
|
1890 |
{
|
|
1891 |
return (Field::eq(field) && |
|
1892 |
field->type() == type() && |
|
1893 |
bit_ptr == ((Field_bit *)field)->bit_ptr && |
|
1894 |
bit_ofs == ((Field_bit *)field)->bit_ofs); |
|
1895 |
}
|
|
1896 |
uint is_equal(Create_field *new_field); |
|
1897 |
void move_field_offset(my_ptrdiff_t ptr_diff) |
|
1898 |
{
|
|
1899 |
Field::move_field_offset(ptr_diff); |
|
1900 |
bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*); |
|
1901 |
}
|
|
1902 |
void hash(ulong *nr, ulong *nr2); |
|
1903 |
||
1904 |
private: |
|
1905 |
virtual size_t do_last_null_byte() const; |
|
1906 |
int do_save_field_metadata(uchar *first_byte); |
|
1907 |
};
|
|
1908 |
||
1909 |
||
1910 |
/**
|
|
1911 |
BIT field represented as chars for non-MyISAM tables.
|
|
1912 |
||
1913 |
@todo The inheritance relationship is backwards since Field_bit is
|
|
1914 |
an extended version of Field_bit_as_char and not the other way
|
|
1915 |
around. Hence, we should refactor it to fix the hierarchy order.
|
|
1916 |
*/
|
|
1917 |
class Field_bit_as_char: public Field_bit { |
|
1918 |
public: |
|
1919 |
Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
|
1920 |
uchar null_bit_arg, |
|
1921 |
enum utype unireg_check_arg, const char *field_name_arg); |
|
1922 |
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
|
1923 |
uint size_of() const { return sizeof(*this); } |
|
1924 |
int store(const char *to, uint length, CHARSET_INFO *charset); |
|
1925 |
int store(double nr) { return Field_bit::store(nr); } |
|
1926 |
int store(longlong nr, bool unsigned_val) |
|
1927 |
{ return Field_bit::store(nr, unsigned_val); } |
|
1928 |
void sql_type(String &str) const; |
|
1929 |
};
|
|
1930 |
||
1931 |
||
1932 |
/*
|
|
1933 |
Create field class for CREATE TABLE
|
|
1934 |
*/
|
|
1935 |
||
1936 |
class Create_field :public Sql_alloc |
|
1937 |
{
|
|
1938 |
public: |
|
1939 |
const char *field_name; |
|
1940 |
const char *change; // If done with alter table |
|
1941 |
const char *after; // Put column after this one |
|
1942 |
LEX_STRING comment; // Comment for field |
|
1943 |
Item *def; // Default value |
|
1944 |
enum enum_field_types sql_type; |
|
1945 |
/*
|
|
1946 |
At various stages in execution this can be length of field in bytes or
|
|
1947 |
max number of characters.
|
|
1948 |
*/
|
|
1949 |
ulong length; |
|
1950 |
/*
|
|
1951 |
The value of `length' as set by parser: is the number of characters
|
|
1952 |
for most of the types, or of bytes for BLOBs or numeric types.
|
|
1953 |
*/
|
|
1954 |
uint32 char_length; |
|
1955 |
uint decimals, flags, pack_length, key_length; |
|
1956 |
Field::utype unireg_check; |
|
1957 |
TYPELIB *interval; // Which interval to use |
|
1958 |
TYPELIB *save_interval; // Temporary copy for the above |
|
1959 |
// Used only for UCS2 intervals
|
|
1960 |
List<String> interval_list; |
|
1961 |
CHARSET_INFO *charset; |
|
1962 |
Field *field; // For alter table |
|
1963 |
||
1964 |
uint8 row,col,sc_length,interval_id; // For rea_create_table |
|
1965 |
uint offset,pack_flag; |
|
1966 |
Create_field() :after(0) {} |
|
1967 |
Create_field(Field *field, Field *orig_field); |
|
1968 |
/* Used to make a clone of this object for ALTER/CREATE TABLE */
|
|
1969 |
Create_field *clone(MEM_ROOT *mem_root) const |
|
1970 |
{ return new (mem_root) Create_field(*this); } |
|
1971 |
void create_length_to_internal_length(void); |
|
1972 |
||
1973 |
inline enum ha_storage_media field_storage_type() const |
|
1974 |
{
|
|
1975 |
return (enum ha_storage_media) |
|
1976 |
((flags >> FIELD_STORAGE_FLAGS) & STORAGE_TYPE_MASK); |
|
1977 |
}
|
|
1978 |
||
1979 |
inline enum column_format_type column_format() const |
|
1980 |
{
|
|
1981 |
return (enum column_format_type) |
|
1982 |
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK); |
|
1983 |
}
|
|
1984 |
||
1985 |
/* Init for a tmp table field. To be extended if need be. */
|
|
1986 |
void init_for_tmp_table(enum_field_types sql_type_arg, |
|
1987 |
uint32 max_length, uint32 decimals, |
|
1988 |
bool maybe_null, bool is_unsigned); |
|
1989 |
||
1990 |
bool init(THD *thd, char *field_name, enum_field_types type, char *length, |
|
1991 |
char *decimals, uint type_modifier, Item *default_value, |
|
1992 |
Item *on_update_value, LEX_STRING *comment, char *change, |
|
1993 |
List<String> *interval_list, CHARSET_INFO *cs, |
|
1994 |
uint uint_geom_type, |
|
1995 |
enum ha_storage_media storage_type, |
|
1996 |
enum column_format_type column_format); |
|
1997 |
};
|
|
1998 |
||
1999 |
||
2000 |
/*
|
|
2001 |
A class for sending info to the client
|
|
2002 |
*/
|
|
2003 |
||
2004 |
class Send_field { |
|
2005 |
public: |
|
2006 |
const char *db_name; |
|
2007 |
const char *table_name,*org_table_name; |
|
2008 |
const char *col_name,*org_col_name; |
|
2009 |
ulong length; |
|
2010 |
uint charsetnr, flags, decimals; |
|
2011 |
enum_field_types type; |
|
2012 |
Send_field() {} |
|
2013 |
};
|
|
2014 |
||
2015 |
||
2016 |
/*
|
|
2017 |
A class for quick copying data to fields
|
|
2018 |
*/
|
|
2019 |
||
2020 |
class Copy_field :public Sql_alloc { |
|
2021 |
/**
|
|
2022 |
Convenience definition of a copy function returned by
|
|
2023 |
get_copy_func.
|
|
2024 |
*/
|
|
2025 |
typedef void Copy_func(Copy_field*); |
|
2026 |
Copy_func *get_copy_func(Field *to, Field *from); |
|
2027 |
public: |
|
2028 |
uchar *from_ptr,*to_ptr; |
|
2029 |
uchar *from_null_ptr,*to_null_ptr; |
|
2030 |
my_bool *null_row; |
|
2031 |
uint from_bit,to_bit; |
|
2032 |
uint from_length,to_length; |
|
2033 |
Field *from_field,*to_field; |
|
2034 |
String tmp; // For items |
|
2035 |
||
2036 |
Copy_field() {} |
|
2037 |
~Copy_field() {} |
|
2038 |
void set(Field *to,Field *from,bool save); // Field to field |
|
2039 |
void set(uchar *to,Field *from); // Field to string |
|
2040 |
void (*do_copy)(Copy_field *); |
|
2041 |
void (*do_copy2)(Copy_field *); // Used to handle null values |
|
2042 |
};
|
|
2043 |
||
2044 |
||
2045 |
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length, |
|
2046 |
uchar *null_pos, uchar null_bit, |
|
2047 |
uint pack_flag, enum_field_types field_type, |
|
2048 |
CHARSET_INFO *cs, |
|
2049 |
Field::utype unireg_check, |
|
2050 |
TYPELIB *interval, const char *field_name); |
|
2051 |
uint pack_length_to_packflag(uint type); |
|
2052 |
enum_field_types get_blob_type_from_length(ulong length); |
|
2053 |
uint32 calc_pack_length(enum_field_types type,uint32 length); |
|
2054 |
int set_field_to_null(Field *field); |
|
2055 |
int set_field_to_null_with_conversions(Field *field, bool no_conversions); |
|
2056 |
||
2057 |
/*
|
|
2058 |
The following are for the interface with the .frm file
|
|
2059 |
*/
|
|
2060 |
||
2061 |
#define FIELDFLAG_DECIMAL 1
|
|
2062 |
#define FIELDFLAG_BINARY 1 // Shares same flag |
|
2063 |
#define FIELDFLAG_NUMBER 2
|
|
2064 |
#define FIELDFLAG_ZEROFILL 4
|
|
2065 |
#define FIELDFLAG_PACK 120 // Bits used for packing |
|
2066 |
#define FIELDFLAG_INTERVAL 256 // mangled with decimals! |
|
2067 |
#define FIELDFLAG_BITFIELD 512 // mangled with decimals! |
|
2068 |
#define FIELDFLAG_BLOB 1024 // mangled with decimals! |
|
2069 |
#define FIELDFLAG_GEOM 2048 // mangled with decimals! |
|
2070 |
||
2071 |
#define FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */ |
|
2072 |
||
2073 |
#define FIELDFLAG_LEFT_FULLSCREEN 8192
|
|
2074 |
#define FIELDFLAG_RIGHT_FULLSCREEN 16384
|
|
2075 |
#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output |
|
2076 |
#define FIELDFLAG_NO_DEFAULT 16384 /* sql */ |
|
2077 |
#define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag |
|
2078 |
#define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql |
|
2079 |
#define FIELDFLAG_HEX_ESCAPE ((uint) 0x10000)
|
|
2080 |
#define FIELDFLAG_PACK_SHIFT 3
|
|
2081 |
#define FIELDFLAG_DEC_SHIFT 8
|
|
2082 |
#define FIELDFLAG_MAX_DEC 31
|
|
2083 |
#define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01
|
|
2084 |
#define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800
|
|
2085 |
||
2086 |
#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */ |
|
2087 |
||
2088 |
#define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL)
|
|
2089 |
#define f_is_num(x) ((x) & FIELDFLAG_NUMBER)
|
|
2090 |
#define f_is_zerofill(x) ((x) & FIELDFLAG_ZEROFILL)
|
|
2091 |
#define f_is_packed(x) ((x) & FIELDFLAG_PACK)
|
|
2092 |
#define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
|
|
2093 |
#define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
|
|
2094 |
#define f_is_alpha(x) (!f_is_num(x))
|
|
2095 |
#define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility |
|
2096 |
#define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
|
|
2097 |
#define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
|
|
2098 |
#define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
|
|
2099 |
#define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256))
|
|
2100 |
#define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
|
|
2101 |
#define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL)
|
|
2102 |
#define f_no_default(x) (x & FIELDFLAG_NO_DEFAULT)
|
|
2103 |
#define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
|
|
2104 |
#define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE)
|