3
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates.
4
Copyright (c) 2008, 2011, Monty Program Ab
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
20
Because of the function new_field() all field classes that have static
21
variables must declare the size_of() member function.
24
#ifdef USE_PRAGMA_INTERFACE
25
#pragma interface /* gcc class implementation */
28
#include "mysqld.h" /* system_charset_info */
29
#include "table.h" /* TABLE */
30
#include "sql_string.h" /* String */
31
#include "my_decimal.h" /* my_decimal */
32
#include "sql_error.h" /* MYSQL_ERROR */
40
enum enum_check_fields
44
CHECK_FIELD_ERROR_FOR_NULL
50
DERIVATION_IGNORABLE= 6,
51
DERIVATION_NUMERIC= 5,
52
DERIVATION_COERCIBLE= 4,
53
DERIVATION_SYSCONST= 3,
54
DERIVATION_IMPLICIT= 2,
56
DERIVATION_EXPLICIT= 0
59
#define STORAGE_TYPE_MASK 7
60
#define COLUMN_FORMAT_MASK 7
61
#define COLUMN_FORMAT_SHIFT 3
63
#define my_charset_numeric my_charset_latin1
64
#define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII
66
/* The length of the header part for each virtual column in the .frm file */
67
#define FRM_VCOL_HEADER_SIZE(b) (3 + test(b))
69
struct ha_field_option_struct;
71
struct st_cache_field;
72
int field_conv(Field *to,Field *from);
73
int truncate_double(double *nr, uint field_length, uint dec,
74
bool unsigned_flag, double max_value);
75
longlong double_to_longlong(double nr, bool unsigned_flag, bool *error);
77
inline uint get_enum_pack_length(int elements)
79
return elements < 256 ? 1 : 2;
82
inline uint get_set_pack_length(int elements)
84
uint len= (elements + 7) / 8;
85
return len > 4 ? 8 : len;
89
Virtual_column_info is the class to contain additional
90
characteristics that is specific for a virtual/computed
92
- the defining expression that is evaluated to compute the value
94
- whether the field is to be stored in the database
95
- whether the field is used in a partitioning expression
98
class Virtual_column_info: public Sql_alloc
102
The following data is only updated by the parser and read
103
when a Create_field object is created/initialized.
105
enum_field_types field_type; /* Real field type*/
106
/* Flag indicating that the field is physically stored in the database */
108
/* Flag indicating that the field used in a partitioning expression */
109
bool in_partitioning_expr;
112
/* The expression to compute the value of the virtual column */
114
/* Text representation of the defining expression */
117
Virtual_column_info()
118
: field_type((enum enum_field_types)MYSQL_TYPE_VIRTUAL),
119
stored_in_db(FALSE), in_partitioning_expr(FALSE),
125
~Virtual_column_info() {}
126
enum_field_types get_real_type()
130
void set_field_type(enum_field_types fld_type)
132
/* Calling this function can only be done once. */
133
field_type= fld_type;
139
void set_stored_in_db_flag(bool stored)
141
stored_in_db= stored;
143
bool is_in_partitioning_expr()
145
return in_partitioning_expr;
147
void mark_as_in_partitioning_expr()
149
in_partitioning_expr= TRUE;
155
Field(const Item &); /* Prevent use of these */
156
void operator=(Field &);
158
static void *operator new(size_t size) throw ()
159
{ return sql_alloc(size); }
160
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
162
uchar *ptr; // Position to field in record
164
Byte where the @c NULL bit is stored inside a record. If this Field is a
165
@c NOT @c NULL field, this member is @c NULL.
169
Note that you can use table->in_use as replacement for current_thd member
170
only inside of val_*() and store() members (e.g. you can't use it in cons)
172
TABLE *table; // Pointer for table
173
TABLE *orig_table; // Pointer to original table
174
const char * const *table_name;
175
const char *field_name;
176
/** reference to the list of options or NULL */
177
engine_option_value *option_list;
178
ha_field_option_struct *option_struct; /* structure with parsed options */
180
/* Field is part of the following keys */
181
key_map key_start, part_of_key, part_of_key_not_clustered;
182
key_map part_of_sortkey;
184
We use three additional unireg types for TIMESTAMP to overcome limitation
185
of current binary format of .frm file. We'd like to be able to support
186
NOW() as default and on update value for such fields but unable to hold
187
this info anywhere except unireg_check field. This issue will be resolved
188
in more clean way with transition to new text based .frm format.
189
See also comment for Field_timestamp::Field_timestamp().
191
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
192
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
193
BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
194
TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
197
GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
198
GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6,
199
GEOM_GEOMETRYCOLLECTION = 7
201
enum imagetype { itRAW, itMBR};
204
uint32 field_length; // Length of field
206
uint16 field_index; // field number in fields array
207
uchar null_bit; // Bit used to test null bit
209
If true, this field was created in create_tmp_field_from_item from a NULL
210
value. This means that the type of the field is just a guess, and the type
211
may be freely coerced to another type.
213
@see create_tmp_field_from_item
214
@see Item_type_holder::get_real_type
217
bool is_created_from_null_item;
220
This is additional data provided for any computed(virtual) field.
221
In particular it includes a pointer to the item by which this field
222
can be computed from other fields.
224
Virtual_column_info *vcol_info;
226
Flag indicating that the field is physically stored in tables
227
rather than just computed from other fields.
228
As of now, FALSE can be set only for computed virtual columns.
232
Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
233
uchar null_bit_arg, utype unireg_check_arg,
234
const char *field_name_arg);
236
/* Store functions returns 1 on overflow and -1 on fatal error */
237
virtual int store(const char *to, uint length,CHARSET_INFO *cs)=0;
238
virtual int store(double nr)=0;
239
virtual int store(longlong nr, bool unsigned_val)=0;
240
virtual int store_decimal(const my_decimal *d)=0;
241
virtual int store_time_dec(MYSQL_TIME *ltime, uint dec);
242
int store_time(MYSQL_TIME *ltime)
243
{ return store_time_dec(ltime, TIME_SECOND_PART_DIGITS); }
244
int store(const char *to, uint length, CHARSET_INFO *cs,
245
enum_check_fields check_level);
246
virtual double val_real(void)=0;
247
virtual longlong val_int(void)=0;
248
virtual my_decimal *val_decimal(my_decimal *);
249
inline String *val_str(String *str) { return val_str(str, str); }
251
val_str(buf1, buf2) gets two buffers and should use them as follows:
252
if it needs a temp buffer to convert result to string - use buf1
253
example Field_tiny::val_str()
254
if the value exists as a string already - use buf2
255
example Field_string::val_str()
256
consequently, buf2 may be created as 'String buf;' - no memory
257
will be allocated for it. buf1 will be allocated to hold a
258
value if it's too small. Using allocated buffer for buf2 may result in
259
an unnecessary free (and later, may be an alloc).
260
This trickery is used to decrease a number of malloc calls.
262
virtual String *val_str(String*,String *)=0;
263
String *val_int_as_str(String *val_buffer, bool unsigned_flag);
265
str_needs_quotes() returns TRUE if the value returned by val_str() needs
266
to be quoted when used in constructing an SQL query.
268
virtual bool str_needs_quotes() { return FALSE; }
269
virtual Item_result result_type () const=0;
270
virtual Item_result cmp_type () const { return result_type(); }
271
static bool type_can_have_key_part(enum_field_types);
272
static enum_field_types field_type_merge(enum_field_types, enum_field_types);
273
static Item_result result_merge_type(enum_field_types);
274
virtual bool eq(Field *field)
276
return (ptr == field->ptr && null_ptr == field->null_ptr &&
277
null_bit == field->null_bit && field->type() == type());
279
virtual bool eq_def(Field *field);
282
pack_length() returns size (in bytes) used to store field data in memory
283
(i.e. it returns the maximum size of the field in a row of the table,
284
which is located in RAM).
286
virtual uint32 pack_length() const { return (uint32) field_length; }
289
pack_length_in_rec() returns size (in bytes) used to store field data on
290
storage (i.e. it returns the maximal size of the field in a row of the
291
table, which is located on disk).
293
virtual uint32 pack_length_in_rec() const { return pack_length(); }
294
virtual bool compatible_field_size(uint metadata, Relay_log_info *rli,
295
uint16 mflags, int *order);
296
virtual uint pack_length_from_metadata(uint field_metadata)
298
DBUG_ENTER("Field::pack_length_from_metadata");
299
DBUG_RETURN(field_metadata);
301
virtual uint row_pack_length() { return 0; }
302
virtual int save_field_metadata(uchar *first_byte)
303
{ return do_save_field_metadata(first_byte); }
306
data_length() return the "real size" of the data in memory.
308
virtual uint32 data_length() { return pack_length(); }
309
virtual uint32 sort_length() const { return pack_length(); }
312
Get the maximum size of the data in packed format.
314
@return Maximum data length of the field when packed using the
315
Field::pack() function.
317
virtual uint32 max_data_length() const {
318
return pack_length();
321
virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
322
virtual void reset_fields() {}
323
virtual void set_default()
325
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
327
memcpy(ptr, ptr + l_offset, pack_length());
329
*null_ptr= ((*null_ptr & (uchar) ~null_bit) |
330
(null_ptr[l_offset] & null_bit));
332
virtual bool binary() const { return 1; }
333
virtual bool zero_pack() const { return 1; }
334
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
335
virtual uint32 key_length() const { return pack_length(); }
336
virtual enum_field_types type() const =0;
337
virtual enum_field_types real_type() const { return type(); }
338
inline int cmp(const uchar *str) { return cmp(ptr,str); }
339
virtual int cmp_max(const uchar *a, const uchar *b, uint max_len)
340
{ return cmp(a, b); }
341
virtual int cmp(const uchar *,const uchar *)=0;
342
virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L)
343
{ return memcmp(a,b,pack_length()); }
344
virtual int cmp_offset(uint row_offset)
345
{ return cmp(ptr,ptr+row_offset); }
346
virtual int cmp_binary_offset(uint row_offset)
347
{ return cmp_binary(ptr, ptr+row_offset); };
348
virtual int key_cmp(const uchar *a,const uchar *b)
349
{ return cmp(a, b); }
350
virtual int key_cmp(const uchar *str, uint length)
351
{ return cmp(ptr,str); }
352
virtual uint decimals() const { return 0; }
354
Caller beware: sql_type can change str.Ptr, so check
355
ptr() to see if it changed if you are using your own buffer
356
in str and restore it with set() if needed
358
virtual void sql_type(String &str) const =0;
359
virtual uint size_of() const =0; // For new field
360
inline bool is_null(my_ptrdiff_t row_offset= 0)
361
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
362
inline bool is_real_null(my_ptrdiff_t row_offset= 0)
363
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
364
inline bool is_null_in_record(const uchar *record)
368
return test(record[(uint) (null_ptr -table->record[0])] &
371
inline bool is_null_in_record_with_offset(my_ptrdiff_t col_offset)
375
return test(null_ptr[col_offset] & null_bit);
377
inline void set_null(my_ptrdiff_t row_offset= 0)
378
{ if (null_ptr) null_ptr[row_offset]|= null_bit; }
379
inline void set_notnull(my_ptrdiff_t row_offset= 0)
380
{ if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
381
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
383
Signals that this field is NULL-able.
385
inline bool real_maybe_null(void) { return null_ptr != 0; }
388
LAST_NULL_BYTE_UNDEF= 0
392
Find the position of the last null byte for the field.
398
Return a pointer to the last byte of the null bytes where the
399
field conceptually is placed.
402
The position of the last null byte relative to the beginning of
403
the record. If the field does not use any bits of the null
404
bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
406
size_t last_null_byte() const {
407
size_t bytes= do_last_null_byte();
408
DBUG_PRINT("debug", ("last_null_byte() ==> %ld", (long) bytes));
409
DBUG_ASSERT(bytes <= table->s->null_bytes);
413
void make_sort_key(uchar *buff, uint length);
414
virtual void make_field(Send_field *);
415
virtual void sort_string(uchar *buff,uint length)=0;
416
virtual bool optimize_range(uint idx, uint part);
417
virtual void free() {}
418
virtual Field *new_field(MEM_ROOT *root, TABLE *new_table,
420
virtual Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
421
uchar *new_ptr, uchar *new_null_ptr,
423
Field *clone(MEM_ROOT *mem_root, TABLE *new_table);
424
inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
426
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
428
inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
429
virtual void move_field_offset(my_ptrdiff_t ptr_diff)
431
ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
433
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
435
virtual void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
436
{ memcpy(buff,ptr,length); }
437
virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
438
{ memcpy(ptr,buff,length); }
442
Copy a field part into an output buffer.
445
Field::get_key_image()
446
buff [out] output buffer
447
length output buffer size
448
type itMBR for geometry blobs, otherwise itRAW
451
This function makes a copy of field part of size equal to or
452
less than "length" parameter value.
453
For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
454
is padded by zero byte.
457
For variable length character fields (i.e. UTF-8) the "length"
458
parameter means a number of output buffer bytes as if all field
459
characters have maximal possible size (mbmaxlen). In the other words,
460
"length" parameter is a number of characters multiplied by
461
field_charset->mbmaxlen.
464
Number of copied bytes (excluding padded zero bytes -- see above).
467
virtual uint get_key_image(uchar *buff, uint length, imagetype type_arg)
469
get_image(buff, length, &my_charset_bin);
472
virtual void set_key_image(const uchar *buff,uint length)
473
{ set_image(buff,length, &my_charset_bin); }
474
inline longlong val_int_offset(uint row_offset)
477
longlong tmp=val_int();
481
inline longlong val_int(const uchar *new_ptr)
484
longlong return_value;
485
ptr= (uchar*) new_ptr;
486
return_value= val_int();
490
inline String *val_str(String *str, const uchar *new_ptr)
493
ptr= (uchar*) new_ptr;
498
virtual bool send_binary(Protocol *protocol);
500
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
502
@overload Field::pack(uchar*, const uchar*, uint, bool)
504
uchar *pack(uchar *to, const uchar *from)
506
DBUG_ENTER("Field::pack");
507
uchar *result= this->pack(to, from, UINT_MAX);
511
virtual const uchar *unpack(uchar* to, const uchar *from,
512
const uchar *from_end, uint param_data=0);
514
virtual uint packed_col_length(const uchar *to, uint length)
516
virtual uint max_packed_col_length(uint max_length)
517
{ return max_length;}
519
uint offset(uchar *record)
521
return (uint) (ptr - record);
523
void copy_from_tmp(int offset);
524
uint fill_cache_field(struct st_cache_field *copy);
525
virtual bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
526
bool get_time(MYSQL_TIME *ltime) { return get_date(ltime, TIME_TIME_ONLY); }
527
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
528
virtual CHARSET_INFO *charset_for_protocol(void) const
529
{ return binary() ? &my_charset_bin : charset(); }
530
virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
531
virtual bool has_charset(void) const { return FALSE; }
532
virtual void set_charset(CHARSET_INFO *charset_arg) { }
533
virtual enum Derivation derivation(void) const
534
{ return DERIVATION_IMPLICIT; }
535
virtual uint repertoire(void) const { return MY_REPERTOIRE_UNICODE30; }
536
virtual void set_derivation(enum Derivation derivation_arg) { }
537
virtual int set_time() { return 1; }
538
void set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
539
int cuted_increment);
540
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
541
const ErrConv *str, timestamp_type ts_type,
542
int cuted_increment);
543
inline bool check_overflow(int op_result)
545
return (op_result == E_DEC_OVERFLOW);
547
int warn_if_overflow(int op_result);
548
void set_table_name(String *alias)
550
table_name= &alias->Ptr;
552
void init(TABLE *table_arg)
554
orig_table= table= table_arg;
555
set_table_name(&table_arg->alias);
558
/* maximum possible display length */
559
virtual uint32 max_display_length()= 0;
562
Whether a field being created is compatible with a existing one.
564
Used by the ALTER TABLE code to evaluate whether the new definition
565
of a table is compatible with the old definition so that it can
566
determine if data needs to be copied over (table data change).
568
virtual uint is_equal(Create_field *new_field);
569
/* convert decimal to longlong with overflow check */
570
longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
572
/* The max. number of characters */
573
virtual uint32 char_length()
575
return field_length / charset()->mbmaxlen;
578
virtual geometry_type get_geometry_type()
580
/* shouldn't get here. */
582
return GEOM_GEOMETRY;
585
key_map get_possible_keys();
588
virtual void hash(ulong *nr, ulong *nr2);
590
/* Check whether the field can be used as a join attribute in hash join */
591
virtual bool hash_join_is_possible() { return TRUE; }
592
virtual bool eq_cmp_as_binary() { return TRUE; }
594
friend int cre_myisam(char * name, register TABLE *form, uint options,
595
ulonglong auto_increment_value);
596
friend class Copy_field;
597
friend class Item_avg_field;
598
friend class Item_std_field;
599
friend class Item_sum_num;
600
friend class Item_sum_sum;
601
friend class Item_sum_str;
602
friend class Item_sum_count;
603
friend class Item_sum_avg;
604
friend class Item_sum_std;
605
friend class Item_sum_min;
606
friend class Item_sum_max;
607
friend class Item_func_group_concat;
611
Primitive for implementing last_null_byte().
617
Primitive for the implementation of the last_null_byte()
618
function. This represents the inheritance interface and can be
619
overridden by subclasses.
621
virtual size_t do_last_null_byte() const;
624
Retrieve the field metadata for fields.
626
This default implementation returns 0 and saves 0 in the metadata_ptr
629
@param metadata_ptr First byte of field metadata
631
@returns 0 no bytes written.
633
virtual int do_save_field_metadata(uchar *metadata_ptr)
637
uchar *pack_int(uchar *to, const uchar *from, size_t size)
639
memcpy(to, from, size);
643
const uchar *unpack_int(uchar* to, const uchar *from,
644
const uchar *from_end, size_t size)
646
if (from + size > from_end)
648
memcpy(to, from, size);
652
uchar *pack_int16(uchar *to, const uchar *from)
653
{ return pack_int(to, from, 2); }
654
const uchar *unpack_int16(uchar* to, const uchar *from, const uchar *from_end)
655
{ return unpack_int(to, from, from_end, 2); }
656
uchar *pack_int24(uchar *to, const uchar *from)
657
{ return pack_int(to, from, 3); }
658
const uchar *unpack_int24(uchar* to, const uchar *from, const uchar *from_end)
659
{ return unpack_int(to, from, from_end, 3); }
660
uchar *pack_int32(uchar *to, const uchar *from)
661
{ return pack_int(to, from, 4); }
662
const uchar *unpack_int32(uchar* to, const uchar *from, const uchar *from_end)
663
{ return unpack_int(to, from, from_end, 4); }
664
uchar *pack_int64(uchar* to, const uchar *from)
665
{ return pack_int(to, from, 8); }
666
const uchar *unpack_int64(uchar* to, const uchar *from, const uchar *from_end)
667
{ return unpack_int(to, from, from_end, 8); }
669
bool field_flags_are_binary()
671
return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0;
677
class Field_num :public Field {
680
bool zerofill,unsigned_flag; // Purify cannot handle bit fields
681
Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
682
uchar null_bit_arg, utype unireg_check_arg,
683
const char *field_name_arg,
684
uint8 dec_arg, bool zero_arg, bool unsigned_arg);
685
enum Item_result result_type () const { return INT_RESULT; }
686
enum Derivation derivation(void) const { return DERIVATION_NUMERIC; }
687
uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; }
688
CHARSET_INFO *charset(void) const { return &my_charset_numeric; }
689
void prepend_zeros(String *value);
690
void add_zerofill_and_unsigned(String &res) const;
691
friend class Create_field;
692
void make_field(Send_field *);
693
uint decimals() const { return (uint) dec; }
694
uint size_of() const { return sizeof(*this); }
695
bool eq_def(Field *field);
696
int store_decimal(const my_decimal *);
697
my_decimal *val_decimal(my_decimal *);
698
uint is_equal(Create_field *new_field);
699
uint row_pack_length() { return pack_length(); }
700
uint32 pack_length_from_metadata(uint field_metadata) {
701
uint32 length= pack_length();
702
DBUG_PRINT("result", ("pack_length_from_metadata(%d): %u",
703
field_metadata, length));
706
int store_time_dec(MYSQL_TIME *ltime, uint dec);
707
int check_int(CHARSET_INFO *cs, const char *str, int length,
708
const char *int_end, int error);
709
bool get_int(CHARSET_INFO *cs, const char *from, uint len,
710
longlong *rnd, ulonglong unsigned_max,
711
longlong signed_min, longlong signed_max);
715
class Field_str :public Field {
717
CHARSET_INFO *field_charset;
718
enum Derivation field_derivation;
720
Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
721
uchar null_bit_arg, utype unireg_check_arg,
722
const char *field_name_arg, CHARSET_INFO *charset);
723
Item_result result_type () const { return STRING_RESULT; }
725
match_collation_to_optimize_range() is to distinguish in
726
range optimizer (see opt_range.cc) between real string types:
728
and the other string-alike types with result_type() == STRING_RESULT:
729
DATE, TIME, DATETIME, TIMESTAMP
730
We need it to decide whether to test if collation of the operation
731
matches collation of the field (needed only for real string types).
732
QQ: shouldn't DATE/TIME types have their own XXX_RESULT types eventually?
734
virtual bool match_collation_to_optimize_range() const=0;
735
uint decimals() const { return NOT_FIXED_DEC; }
736
int store(double nr);
737
int store(longlong nr, bool unsigned_val)=0;
738
int store_decimal(const my_decimal *);
739
int store(const char *to,uint length,CHARSET_INFO *cs)=0;
740
uint size_of() const { return sizeof(*this); }
741
uint repertoire(void) const
743
return my_charset_repertoire(field_charset);
745
CHARSET_INFO *charset(void) const { return field_charset; }
746
void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
747
enum Derivation derivation(void) const { return field_derivation; }
748
virtual void set_derivation(enum Derivation derivation_arg)
749
{ field_derivation= derivation_arg; }
750
bool binary() const { return field_charset == &my_charset_bin; }
751
uint32 max_display_length() { return field_length; }
752
friend class Create_field;
753
my_decimal *val_decimal(my_decimal *);
754
virtual bool str_needs_quotes() { return TRUE; }
755
uint is_equal(Create_field *new_field);
756
bool eq_cmp_as_binary() { return test(flags & BINARY_FLAG); }
759
/* base class for Field_string, Field_varstring and Field_blob */
761
class Field_longstr :public Field_str
764
int report_if_important_data(const char *ptr, const char *end,
767
Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
768
uchar null_bit_arg, utype unireg_check_arg,
769
const char *field_name_arg, CHARSET_INFO *charset_arg)
770
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
771
field_name_arg, charset_arg)
774
int store_decimal(const my_decimal *d);
775
uint32 max_data_length() const;
778
/* base class for float and double and decimal (old one) */
779
class Field_real :public Field_num {
783
Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
784
uchar null_bit_arg, utype unireg_check_arg,
785
const char *field_name_arg,
786
uint8 dec_arg, bool zero_arg, bool unsigned_arg)
787
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
788
field_name_arg, dec_arg, zero_arg, unsigned_arg),
789
not_fixed(dec_arg >= NOT_FIXED_DEC)
791
Item_result result_type () const { return REAL_RESULT; }
792
int store_decimal(const my_decimal *);
793
int store_time_dec(MYSQL_TIME *ltime, uint dec);
794
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
795
my_decimal *val_decimal(my_decimal *);
796
uint32 max_display_length() { return field_length; }
797
uint size_of() const { return sizeof(*this); }
801
class Field_decimal :public Field_real {
803
Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
805
enum utype unireg_check_arg, const char *field_name_arg,
806
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
807
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
808
unireg_check_arg, field_name_arg,
809
dec_arg, zero_arg, unsigned_arg)
811
enum_field_types type() const { return MYSQL_TYPE_DECIMAL;}
812
enum ha_base_keytype key_type() const
813
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
815
int store(const char *to,uint length,CHARSET_INFO *charset);
816
int store(double nr);
817
int store(longlong nr, bool unsigned_val);
818
double val_real(void);
819
longlong val_int(void);
820
String *val_str(String*,String *);
821
int cmp(const uchar *,const uchar *);
822
void sort_string(uchar *buff,uint length);
823
void overflow(bool negative);
824
bool zero_pack() const { return 0; }
825
void sql_type(String &str) const;
826
virtual uchar *pack(uchar* to, const uchar *from, uint max_length)
828
return Field::pack(to, from, max_length);
833
/* New decimal/numeric field which use fixed point arithmetic */
834
class Field_new_decimal :public Field_num {
836
int do_save_field_metadata(uchar *first_byte);
838
/* The maximum number of decimal digits can be stored */
842
Constructors take max_length of the field as a parameter - not the
843
precision as the number of decimal digits allowed.
844
So for example we need to count length from precision handling
845
CREATE TABLE ( DECIMAL(x,y))
847
Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
849
enum utype unireg_check_arg, const char *field_name_arg,
850
uint8 dec_arg, bool zero_arg, bool unsigned_arg);
851
Field_new_decimal(uint32 len_arg, bool maybe_null_arg,
852
const char *field_name_arg, uint8 dec_arg,
854
enum_field_types type() const { return MYSQL_TYPE_NEWDECIMAL;}
855
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
856
Item_result result_type () const { return DECIMAL_RESULT; }
858
bool store_value(const my_decimal *decimal_value);
859
void set_value_on_overflow(my_decimal *decimal_value, bool sign);
860
int store(const char *to, uint length, CHARSET_INFO *charset);
861
int store(double nr);
862
int store(longlong nr, bool unsigned_val);
863
int store_time_dec(MYSQL_TIME *ltime, uint dec);
864
int store_decimal(const my_decimal *);
865
double val_real(void);
866
longlong val_int(void);
867
my_decimal *val_decimal(my_decimal *);
868
String *val_str(String*, String *);
869
int cmp(const uchar *, const uchar *);
870
void sort_string(uchar *buff, uint length);
871
bool zero_pack() const { return 0; }
872
void sql_type(String &str) const;
873
uint32 max_display_length() { return field_length; }
874
uint size_of() const { return sizeof(*this); }
875
uint32 pack_length() const { return (uint32) bin_size; }
876
uint pack_length_from_metadata(uint field_metadata);
877
uint row_pack_length() { return pack_length(); }
878
bool compatible_field_size(uint field_metadata, Relay_log_info *rli,
879
uint16 mflags, int *order_var);
880
uint is_equal(Create_field *new_field);
881
virtual const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, uint param_data);
882
static Field *create_from_item (Item *);
886
class Field_tiny :public Field_num {
888
Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
890
enum utype unireg_check_arg, const char *field_name_arg,
891
bool zero_arg, bool unsigned_arg)
892
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
893
unireg_check_arg, field_name_arg,
894
0, zero_arg,unsigned_arg)
896
enum_field_types type() const { return MYSQL_TYPE_TINY;}
897
enum ha_base_keytype key_type() const
898
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
899
int store(const char *to,uint length,CHARSET_INFO *charset);
900
int store(double nr);
901
int store(longlong nr, bool unsigned_val);
902
int reset(void) { ptr[0]=0; return 0; }
903
double val_real(void);
904
longlong val_int(void);
905
String *val_str(String*,String *);
906
bool send_binary(Protocol *protocol);
907
int cmp(const uchar *,const uchar *);
908
void sort_string(uchar *buff,uint length);
909
uint32 pack_length() const { return 1; }
910
void sql_type(String &str) const;
911
uint32 max_display_length() { return 4; }
913
virtual uchar *pack(uchar* to, const uchar *from, uint max_length)
919
virtual const uchar *unpack(uchar* to, const uchar *from,
920
const uchar *from_end, uint param_data)
922
if (from == from_end)
930
class Field_short :public Field_num {
932
Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
934
enum utype unireg_check_arg, const char *field_name_arg,
935
bool zero_arg, bool unsigned_arg)
936
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
937
unireg_check_arg, field_name_arg,
938
0, zero_arg,unsigned_arg)
940
Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
942
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
943
NONE, field_name_arg, 0, 0, unsigned_arg)
945
enum_field_types type() const { return MYSQL_TYPE_SHORT;}
946
enum ha_base_keytype key_type() const
947
{ return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
948
int store(const char *to,uint length,CHARSET_INFO *charset);
949
int store(double nr);
950
int store(longlong nr, bool unsigned_val);
951
int reset(void) { ptr[0]=ptr[1]=0; return 0; }
952
double val_real(void);
953
longlong val_int(void);
954
String *val_str(String*,String *);
955
bool send_binary(Protocol *protocol);
956
int cmp(const uchar *,const uchar *);
957
void sort_string(uchar *buff,uint length);
958
uint32 pack_length() const { return 2; }
959
void sql_type(String &str) const;
960
uint32 max_display_length() { return 6; }
962
virtual uchar *pack(uchar* to, const uchar *from, uint max_length)
963
{ return pack_int16(to, from); }
965
virtual const uchar *unpack(uchar* to, const uchar *from,
966
const uchar *from_end, uint param_data)
967
{ return unpack_int16(to, from, from_end); }
970
class Field_medium :public Field_num {
972
Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
974
enum utype unireg_check_arg, const char *field_name_arg,
975
bool zero_arg, bool unsigned_arg)
976
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
977
unireg_check_arg, field_name_arg,
978
0, zero_arg,unsigned_arg)
980
enum_field_types type() const { return MYSQL_TYPE_INT24;}
981
enum ha_base_keytype key_type() const
982
{ return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
983
int store(const char *to,uint length,CHARSET_INFO *charset);
984
int store(double nr);
985
int store(longlong nr, bool unsigned_val);
986
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
987
double val_real(void);
988
longlong val_int(void);
989
String *val_str(String*,String *);
990
bool send_binary(Protocol *protocol);
991
int cmp(const uchar *,const uchar *);
992
void sort_string(uchar *buff,uint length);
993
uint32 pack_length() const { return 3; }
994
void sql_type(String &str) const;
995
uint32 max_display_length() { return 8; }
997
virtual uchar *pack(uchar* to, const uchar *from, uint max_length)
999
return Field::pack(to, from, max_length);
1004
class Field_long :public Field_num {
1006
Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1008
enum utype unireg_check_arg, const char *field_name_arg,
1009
bool zero_arg, bool unsigned_arg)
1010
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1011
unireg_check_arg, field_name_arg,
1012
0, zero_arg,unsigned_arg)
1014
Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1016
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
1017
NONE, field_name_arg,0,0,unsigned_arg)
1019
enum_field_types type() const { return MYSQL_TYPE_LONG;}
1020
enum ha_base_keytype key_type() const
1021
{ return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
1022
int store(const char *to,uint length,CHARSET_INFO *charset);
1023
int store(double nr);
1024
int store(longlong nr, bool unsigned_val);
1025
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1026
double val_real(void);
1027
longlong val_int(void);
1028
bool send_binary(Protocol *protocol);
1029
String *val_str(String*,String *);
1030
int cmp(const uchar *,const uchar *);
1031
void sort_string(uchar *buff,uint length);
1032
uint32 pack_length() const { return 4; }
1033
void sql_type(String &str) const;
1034
uint32 max_display_length() { return MY_INT32_NUM_DECIMAL_DIGITS; }
1035
virtual uchar *pack(uchar* to, const uchar *from,
1036
uint max_length __attribute__((unused)))
1038
return pack_int32(to, from);
1040
virtual const uchar *unpack(uchar* to, const uchar *from,
1041
const uchar *from_end,
1042
uint param_data __attribute__((unused)))
1044
return unpack_int32(to, from, from_end);
1049
class Field_longlong :public Field_num {
1051
Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1053
enum utype unireg_check_arg, const char *field_name_arg,
1054
bool zero_arg, bool unsigned_arg)
1055
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1056
unireg_check_arg, field_name_arg,
1057
0, zero_arg,unsigned_arg)
1059
Field_longlong(uint32 len_arg,bool maybe_null_arg,
1060
const char *field_name_arg,
1062
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
1063
NONE, field_name_arg,0,0,unsigned_arg)
1065
enum_field_types type() const { return MYSQL_TYPE_LONGLONG;}
1066
enum ha_base_keytype key_type() const
1067
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
1068
int store(const char *to,uint length,CHARSET_INFO *charset);
1069
int store(double nr);
1070
int store(longlong nr, bool unsigned_val);
1073
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
1076
double val_real(void);
1077
longlong val_int(void);
1078
String *val_str(String*,String *);
1079
bool send_binary(Protocol *protocol);
1080
int cmp(const uchar *,const uchar *);
1081
void sort_string(uchar *buff,uint length);
1082
uint32 pack_length() const { return 8; }
1083
void sql_type(String &str) const;
1084
uint32 max_display_length() { return 20; }
1085
virtual uchar *pack(uchar* to, const uchar *from,
1086
uint max_length __attribute__((unused)))
1088
return pack_int64(to, from);
1090
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
1091
uint param_data __attribute__((unused)))
1093
return unpack_int64(to, from, from_end);
1098
class Field_float :public Field_real {
1100
Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_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)
1108
Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1110
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
1111
NONE, field_name_arg, dec_arg, 0, 0)
1113
enum_field_types type() const { return MYSQL_TYPE_FLOAT;}
1114
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
1115
int store(const char *to,uint length,CHARSET_INFO *charset);
1116
int store(double nr);
1117
int store(longlong nr, bool unsigned_val);
1118
int reset(void) { bzero(ptr,sizeof(float)); return 0; }
1119
double val_real(void);
1120
longlong val_int(void);
1121
String *val_str(String*,String *);
1122
bool send_binary(Protocol *protocol);
1123
int cmp(const uchar *,const uchar *);
1124
void sort_string(uchar *buff,uint length);
1125
uint32 pack_length() const { return sizeof(float); }
1126
uint row_pack_length() { return pack_length(); }
1127
void sql_type(String &str) const;
1129
int do_save_field_metadata(uchar *first_byte);
1133
class Field_double :public Field_real {
1135
Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1137
enum utype unireg_check_arg, const char *field_name_arg,
1138
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
1139
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1140
unireg_check_arg, field_name_arg,
1141
dec_arg, zero_arg, unsigned_arg)
1143
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1145
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
1146
NONE, field_name_arg, dec_arg, 0, 0)
1148
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1149
uint8 dec_arg, bool not_fixed_arg)
1150
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
1151
NONE, field_name_arg, dec_arg, 0, 0)
1152
{not_fixed= not_fixed_arg; }
1153
enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
1154
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
1155
int store(const char *to,uint length,CHARSET_INFO *charset);
1156
int store(double nr);
1157
int store(longlong nr, bool unsigned_val);
1158
int reset(void) { bzero(ptr,sizeof(double)); return 0; }
1159
double val_real(void);
1160
longlong val_int(void);
1161
String *val_str(String*,String *);
1162
bool send_binary(Protocol *protocol);
1163
int cmp(const uchar *,const uchar *);
1164
void sort_string(uchar *buff,uint length);
1165
uint32 pack_length() const { return sizeof(double); }
1166
uint row_pack_length() { return pack_length(); }
1167
void sql_type(String &str) const;
1169
int do_save_field_metadata(uchar *first_byte);
1173
/* Everything saved in this will disappear. It will always return NULL */
1175
class Field_null :public Field_str {
1176
static uchar null[1];
1178
Field_null(uchar *ptr_arg, uint32 len_arg,
1179
enum utype unireg_check_arg, const char *field_name_arg,
1181
:Field_str(ptr_arg, len_arg, null, 1,
1182
unireg_check_arg, field_name_arg, cs)
1184
enum_field_types type() const { return MYSQL_TYPE_NULL;}
1185
bool match_collation_to_optimize_range() const { return FALSE; }
1186
int store(const char *to, uint length, CHARSET_INFO *cs)
1187
{ null[0]=1; return 0; }
1188
int store(double nr) { null[0]=1; return 0; }
1189
int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; }
1190
int store_decimal(const my_decimal *d) { null[0]=1; return 0; }
1191
int reset(void) { return 0; }
1192
double val_real(void) { return 0.0;}
1193
longlong val_int(void) { return 0;}
1194
my_decimal *val_decimal(my_decimal *) { return 0; }
1195
String *val_str(String *value,String *value2)
1196
{ value2->length(0); return value2;}
1197
int cmp(const uchar *a, const uchar *b) { return 0;}
1198
void sort_string(uchar *buff, uint length) {}
1199
uint32 pack_length() const { return 0; }
1200
void sql_type(String &str) const;
1201
uint size_of() const { return sizeof(*this); }
1202
uint32 max_display_length() { return 4; }
1203
void move_field_offset(my_ptrdiff_t ptr_diff) {}
1207
class Field_timestamp :public Field_str {
1209
int store_TIME_with_warning(THD *, MYSQL_TIME *, const ErrConv *,
1212
Field_timestamp(uchar *ptr_arg, uint32 len_arg,
1213
uchar *null_ptr_arg, uchar null_bit_arg,
1214
enum utype unireg_check_arg, const char *field_name_arg,
1215
TABLE_SHARE *share, CHARSET_INFO *cs);
1216
Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
1218
enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;}
1219
bool match_collation_to_optimize_range() const { return FALSE; }
1220
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
1221
enum Item_result cmp_type () const { return TIME_RESULT; }
1222
enum Derivation derivation(void) const { return DERIVATION_NUMERIC; }
1223
uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; }
1224
CHARSET_INFO *charset(void) const { return &my_charset_numeric; }
1225
bool binary() const { return 1; }
1226
int store(const char *to,uint length,CHARSET_INFO *charset);
1227
int store(double nr);
1228
int store(longlong nr, bool unsigned_val);
1229
int store_time_dec(MYSQL_TIME *ltime, uint dec);
1230
double val_real(void);
1231
longlong val_int(void);
1232
String *val_str(String*,String *);
1233
bool send_binary(Protocol *protocol);
1234
int cmp(const uchar *,const uchar *);
1235
void sort_string(uchar *buff,uint length);
1236
uint32 pack_length() const { return 4; }
1237
void sql_type(String &str) const;
1238
bool zero_pack() const { return 0; }
1239
uint decimals() const { return 0; }
1240
virtual int set_time();
1241
virtual void set_default()
1243
if (table->timestamp_field == this &&
1244
unireg_check != TIMESTAMP_UN_FIELD)
1247
Field::set_default();
1249
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
1250
virtual my_time_t get_timestamp(ulong *sec_part) const;
1251
virtual void store_TIME(my_time_t timestamp, ulong sec_part)
1253
int4store(ptr,timestamp);
1255
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1256
timestamp_auto_set_type get_auto_set_type() const;
1257
uchar *pack(uchar *to, const uchar *from,
1258
uint max_length __attribute__((unused)))
1260
return pack_int32(to, from);
1262
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
1263
uint param_data __attribute__((unused)))
1265
return unpack_int32(to, from, from_end);
1270
class Field_timestamp_hires :public Field_timestamp {
1273
Field_timestamp_hires(uchar *ptr_arg,
1274
uchar *null_ptr_arg, uchar null_bit_arg,
1275
enum utype unireg_check_arg, const char *field_name_arg,
1276
TABLE_SHARE *share, uint dec_arg, CHARSET_INFO *cs) :
1277
Field_timestamp(ptr_arg, MAX_DATETIME_WIDTH + dec_arg + 1, null_ptr_arg,
1278
null_bit_arg, unireg_check_arg, field_name_arg, share, cs),
1282
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
1284
void sql_type(String &str) const;
1285
my_time_t get_timestamp(ulong *sec_part) const;
1286
void store_TIME(my_time_t timestamp, ulong sec_part);
1287
int store_decimal(const my_decimal *d);
1288
double val_real(void);
1289
String *val_str(String*,String *);
1290
my_decimal* val_decimal(my_decimal*);
1291
bool send_binary(Protocol *protocol);
1292
int cmp(const uchar *,const uchar *);
1293
void sort_string(uchar *buff,uint length);
1294
uint decimals() const { return dec; }
1296
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1297
void make_field(Send_field *field);
1298
uint32 pack_length() const;
1299
uchar *pack(uchar *to, const uchar *from, uint max_length)
1300
{ return Field::pack(to, from, max_length); }
1301
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
1303
{ return Field::unpack(to, from, from_end, param_data); }
1304
uint size_of() const { return sizeof(*this); }
1305
bool eq_def(Field *field)
1306
{ return Field_str::eq_def(field) && dec == field->decimals(); }
1310
class Field_year :public Field_tiny {
1312
Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1314
enum utype unireg_check_arg, const char *field_name_arg)
1315
:Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1316
unireg_check_arg, field_name_arg, 1, 1)
1318
enum_field_types type() const { return MYSQL_TYPE_YEAR;}
1319
int store(const char *to,uint length,CHARSET_INFO *charset);
1320
int store(double nr);
1321
int store(longlong nr, bool unsigned_val);
1322
int store_time_dec(MYSQL_TIME *ltime, uint dec);
1323
double val_real(void);
1324
longlong val_int(void);
1325
String *val_str(String*,String *);
1326
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1327
bool send_binary(Protocol *protocol);
1328
uint32 max_display_length() { return field_length; }
1329
void sql_type(String &str) const;
1333
class Field_temporal: public Field_str {
1335
int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str,
1336
int was_cut, int have_smth_to_conv);
1337
virtual void store_TIME(MYSQL_TIME *ltime) = 0;
1339
Field_temporal(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
1340
uchar null_bit_arg, utype unireg_check_arg,
1341
const char *field_name_arg, CHARSET_INFO *charset_arg)
1342
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
1343
field_name_arg, charset_arg)
1344
{ flags|= BINARY_FLAG; }
1345
enum Derivation derivation(void) const { return DERIVATION_NUMERIC; }
1346
uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; }
1347
CHARSET_INFO *charset(void) const { return &my_charset_numeric; }
1348
bool binary() const { return 1; }
1349
bool match_collation_to_optimize_range() const { return FALSE; }
1350
enum Item_result cmp_type () const { return TIME_RESULT; }
1351
int store(const char *to,uint length,CHARSET_INFO *charset);
1352
int store(double nr);
1353
int store(longlong nr, bool unsigned_val);
1354
int store_time_dec(MYSQL_TIME *ltime, uint dec);
1355
my_decimal *val_decimal(my_decimal*);
1356
bool eq_def(Field *field)
1358
return (Field_str::eq_def(field) && decimals() == field->decimals());
1362
class Field_date :public Field_temporal {
1363
void store_TIME(MYSQL_TIME *ltime);
1365
Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1366
enum utype unireg_check_arg, const char *field_name_arg,
1368
:Field_temporal(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg,
1369
unireg_check_arg, field_name_arg, cs) {}
1370
enum_field_types type() const { return MYSQL_TYPE_DATE;}
1371
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
1372
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1373
double val_real(void);
1374
longlong val_int(void);
1375
String *val_str(String*,String *);
1376
uint decimals() const { return 0; }
1377
bool send_binary(Protocol *protocol);
1378
int cmp(const uchar *,const uchar *);
1379
void sort_string(uchar *buff,uint length);
1380
uint32 pack_length() const { return 4; }
1381
void sql_type(String &str) const;
1382
bool zero_pack() const { return 1; }
1383
uchar *pack(uchar* to, const uchar *from,
1384
uint max_length __attribute__((unused)))
1386
return pack_int32(to, from);
1388
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
1389
uint param_data __attribute__((unused)))
1391
return unpack_int32(to, from, from_end);
1396
class Field_newdate :public Field_temporal {
1397
void store_TIME(MYSQL_TIME *ltime);
1399
Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1400
enum utype unireg_check_arg, const char *field_name_arg,
1402
:Field_temporal(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg,
1403
unireg_check_arg, field_name_arg, cs)
1405
enum_field_types type() const { return MYSQL_TYPE_DATE;}
1406
enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; }
1407
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
1408
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1409
uint decimals() const { return 0; }
1410
double val_real(void);
1411
longlong val_int(void);
1412
String *val_str(String*,String *);
1413
bool send_binary(Protocol *protocol);
1414
int cmp(const uchar *,const uchar *);
1415
void sort_string(uchar *buff,uint length);
1416
uint32 pack_length() const { return 3; }
1417
void sql_type(String &str) const;
1418
bool zero_pack() const { return 1; }
1419
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1423
class Field_time :public Field_temporal {
1424
void store_TIME(MYSQL_TIME *ltime);
1426
Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg,
1427
uchar null_bit_arg, enum utype unireg_check_arg,
1428
const char *field_name_arg, CHARSET_INFO *cs)
1429
:Field_temporal(ptr_arg, length_arg, null_ptr_arg, null_bit_arg,
1430
unireg_check_arg, field_name_arg, cs)
1432
enum_field_types type() const { return MYSQL_TYPE_TIME;}
1433
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
1434
int store_time_dec(MYSQL_TIME *ltime, uint dec);
1435
int store(const char *to,uint length,CHARSET_INFO *charset);
1436
int store(double nr);
1437
int store(longlong nr, bool unsigned_val);
1438
uint decimals() const { return 0; }
1439
double val_real(void);
1440
longlong val_int(void);
1441
String *val_str(String*,String *);
1442
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1443
bool send_binary(Protocol *protocol);
1444
int cmp(const uchar *,const uchar *);
1445
void sort_string(uchar *buff,uint length);
1446
uint32 pack_length() const { return 3; }
1447
void sql_type(String &str) const;
1448
bool zero_pack() const { return 1; }
1451
class Field_time_hires :public Field_time {
1453
longlong zero_point;
1454
void store_TIME(MYSQL_TIME *ltime);
1456
Field_time_hires(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1457
enum utype unireg_check_arg, const char *field_name_arg,
1458
uint dec_arg, CHARSET_INFO *cs)
1459
:Field_time(ptr_arg, MIN_TIME_WIDTH + dec_arg + 1, null_ptr_arg,
1460
null_bit_arg, unireg_check_arg, field_name_arg, cs),
1464
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
1465
zero_point= sec_part_shift(
1466
((TIME_MAX_VALUE_SECONDS+1LL)*TIME_SECOND_PART_FACTOR), dec);
1468
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1469
uint decimals() const { return dec; }
1470
int store_decimal(const my_decimal *d);
1471
longlong val_int(void);
1472
double val_real(void);
1473
String *val_str(String*,String *);
1475
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1476
bool send_binary(Protocol *protocol);
1477
int cmp(const uchar *,const uchar *);
1478
void sort_string(uchar *buff,uint length);
1479
uint32 pack_length() const;
1480
void sql_type(String &str) const;
1481
void make_field(Send_field *);
1482
uint size_of() const { return sizeof(*this); }
1485
class Field_datetime :public Field_temporal {
1486
void store_TIME(MYSQL_TIME *ltime);
1488
Field_datetime(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg,
1489
uchar null_bit_arg, enum utype unireg_check_arg,
1490
const char *field_name_arg, CHARSET_INFO *cs)
1491
:Field_temporal(ptr_arg, length_arg, null_ptr_arg, null_bit_arg,
1492
unireg_check_arg, field_name_arg, cs)
1494
enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
1495
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
1496
uint decimals() const { return 0; }
1497
double val_real(void);
1498
longlong val_int(void);
1499
String *val_str(String*,String *);
1500
bool send_binary(Protocol *protocol);
1501
int cmp(const uchar *,const uchar *);
1502
void sort_string(uchar *buff,uint length);
1503
uint32 pack_length() const { return 8; }
1504
void sql_type(String &str) const;
1505
bool zero_pack() const { return 1; }
1506
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1507
uchar *pack(uchar* to, const uchar *from,
1508
uint max_length __attribute__((unused)))
1510
return pack_int64(to, from);
1512
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
1513
uint param_data __attribute__((unused)))
1515
return unpack_int64(to, from, from_end);
1520
class Field_datetime_hires :public Field_datetime {
1521
void store_TIME(MYSQL_TIME *ltime);
1524
Field_datetime_hires(uchar *ptr_arg, uchar *null_ptr_arg,
1525
uchar null_bit_arg, enum utype unireg_check_arg,
1526
const char *field_name_arg, uint dec_arg,
1528
:Field_datetime(ptr_arg, MAX_DATETIME_WIDTH + dec_arg + 1,
1529
null_ptr_arg, null_bit_arg, unireg_check_arg,
1530
field_name_arg, cs), dec(dec_arg)
1533
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
1535
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1536
uint decimals() const { return dec; }
1537
void make_field(Send_field *field);
1538
int store_decimal(const my_decimal *d);
1539
double val_real(void);
1540
longlong val_int(void);
1541
String *val_str(String*,String *);
1542
bool send_binary(Protocol *protocol);
1543
int cmp(const uchar *,const uchar *);
1544
void sort_string(uchar *buff,uint length);
1545
uint32 pack_length() const;
1546
void sql_type(String &str) const;
1547
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
1548
uchar *pack(uchar *to, const uchar *from, uint max_length)
1549
{ return Field::pack(to, from, max_length); }
1550
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
1552
{ return Field::unpack(to, from, from_end, param_data); }
1553
uint size_of() const { return sizeof(*this); }
1556
static inline Field_timestamp *
1557
new_Field_timestamp(uchar *ptr, uchar *null_ptr, uchar null_bit,
1558
enum Field::utype unireg_check, const char *field_name,
1559
TABLE_SHARE *share, uint dec, CHARSET_INFO *cs)
1562
return new Field_timestamp(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit,
1563
unireg_check, field_name, share, cs);
1564
if (dec == NOT_FIXED_DEC)
1565
dec= MAX_DATETIME_PRECISION;
1566
return new Field_timestamp_hires(ptr, null_ptr, null_bit, unireg_check,
1567
field_name, share, dec, cs);
1570
static inline Field_time *
1571
new_Field_time(uchar *ptr, uchar *null_ptr, uchar null_bit,
1572
enum Field::utype unireg_check, const char *field_name,
1573
uint dec, CHARSET_INFO *cs)
1576
return new Field_time(ptr, MIN_TIME_WIDTH, null_ptr, null_bit,
1577
unireg_check, field_name, cs);
1578
if (dec == NOT_FIXED_DEC)
1579
dec= MAX_DATETIME_PRECISION;
1580
return new Field_time_hires(ptr, null_ptr, null_bit,
1581
unireg_check, field_name, dec, cs);
1584
static inline Field_datetime *
1585
new_Field_datetime(uchar *ptr, uchar *null_ptr, uchar null_bit,
1586
enum Field::utype unireg_check,
1587
const char *field_name, uint dec, CHARSET_INFO *cs)
1590
return new Field_datetime(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit,
1591
unireg_check, field_name, cs);
1592
if (dec == NOT_FIXED_DEC)
1593
dec= MAX_DATETIME_PRECISION;
1594
return new Field_datetime_hires(ptr, null_ptr, null_bit,
1595
unireg_check, field_name, dec, cs);
1598
class Field_string :public Field_longstr {
1600
bool can_alter_field_type;
1601
Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
1603
enum utype unireg_check_arg, const char *field_name_arg,
1605
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1606
unireg_check_arg, field_name_arg, cs),
1607
can_alter_field_type(1) {};
1608
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1610
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1611
NONE, field_name_arg, cs),
1612
can_alter_field_type(1) {};
1614
enum_field_types type() const
1616
return ((can_alter_field_type && orig_table &&
1617
orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
1618
field_length >= 4) &&
1619
orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
1620
MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
1622
bool match_collation_to_optimize_range() const { return TRUE; }
1623
enum ha_base_keytype key_type() const
1624
{ return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
1625
bool zero_pack() const { return 0; }
1628
charset()->cset->fill(charset(),(char*) ptr, field_length,
1629
(has_charset() ? ' ' : 0));
1632
int store(const char *to,uint length,CHARSET_INFO *charset);
1633
int store(longlong nr, bool unsigned_val);
1634
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1635
double val_real(void);
1636
longlong val_int(void);
1637
String *val_str(String*,String *);
1638
my_decimal *val_decimal(my_decimal *);
1639
int cmp(const uchar *,const uchar *);
1640
void sort_string(uchar *buff,uint length);
1641
void sql_type(String &str) const;
1642
virtual uchar *pack(uchar *to, const uchar *from,
1644
virtual const uchar *unpack(uchar* to, const uchar *from,
1645
const uchar *from_end,uint param_data);
1646
uint pack_length_from_metadata(uint field_metadata)
1648
DBUG_PRINT("debug", ("field_metadata: 0x%04x", field_metadata));
1649
if (field_metadata == 0)
1650
return row_pack_length();
1651
return (((field_metadata >> 4) & 0x300) ^ 0x300) + (field_metadata & 0x00ff);
1653
bool compatible_field_size(uint field_metadata, Relay_log_info *rli,
1654
uint16 mflags, int *order_var);
1655
uint row_pack_length() { return field_length; }
1656
int pack_cmp(const uchar *a,const uchar *b,uint key_length,
1657
bool insert_or_update);
1658
int pack_cmp(const uchar *b,uint key_length,bool insert_or_update);
1659
uint packed_col_length(const uchar *to, uint length);
1660
uint max_packed_col_length(uint max_length);
1661
uint size_of() const { return sizeof(*this); }
1662
enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
1663
bool has_charset(void) const
1664
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1665
Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type);
1666
virtual uint get_key_image(uchar *buff,uint length, imagetype type);
1668
int do_save_field_metadata(uchar *first_byte);
1672
class Field_varstring :public Field_longstr {
1675
The maximum space available in a Field_varstring, in bytes. See
1678
static const uint MAX_SIZE;
1679
/* Store number of bytes used to store length (1 or 2) */
1680
uint32 length_bytes;
1681
Field_varstring(uchar *ptr_arg,
1682
uint32 len_arg, uint length_bytes_arg,
1683
uchar *null_ptr_arg, uchar null_bit_arg,
1684
enum utype unireg_check_arg, const char *field_name_arg,
1685
TABLE_SHARE *share, CHARSET_INFO *cs)
1686
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1687
unireg_check_arg, field_name_arg, cs),
1688
length_bytes(length_bytes_arg)
1690
share->varchar_fields++;
1692
Field_varstring(uint32 len_arg,bool maybe_null_arg,
1693
const char *field_name_arg,
1694
TABLE_SHARE *share, CHARSET_INFO *cs)
1695
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1696
NONE, field_name_arg, cs),
1697
length_bytes(len_arg < 256 ? 1 :2)
1699
share->varchar_fields++;
1702
enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
1703
bool match_collation_to_optimize_range() const { return TRUE; }
1704
enum ha_base_keytype key_type() const;
1705
uint row_pack_length() { return field_length; }
1706
bool zero_pack() const { return 0; }
1707
int reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
1708
uint32 pack_length() const { return (uint32) field_length+length_bytes; }
1709
uint32 key_length() const { return (uint32) field_length; }
1710
uint32 sort_length() const
1712
return (uint32) field_length + (field_charset == &my_charset_bin ?
1715
int store(const char *to,uint length,CHARSET_INFO *charset);
1716
int store(longlong nr, bool unsigned_val);
1717
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1718
double val_real(void);
1719
longlong val_int(void);
1720
String *val_str(String*,String *);
1721
my_decimal *val_decimal(my_decimal *);
1722
int cmp_max(const uchar *, const uchar *, uint max_length);
1723
int cmp(const uchar *a,const uchar *b)
1725
return cmp_max(a, b, ~0L);
1727
void sort_string(uchar *buff,uint length);
1728
uint get_key_image(uchar *buff,uint length, imagetype type);
1729
void set_key_image(const uchar *buff,uint length);
1730
void sql_type(String &str) const;
1731
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
1732
virtual const uchar *unpack(uchar* to, const uchar *from,
1733
const uchar *from_end, uint param_data);
1734
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1735
int key_cmp(const uchar *,const uchar*);
1736
int key_cmp(const uchar *str, uint length);
1737
uint packed_col_length(const uchar *to, uint length);
1738
uint max_packed_col_length(uint max_length);
1739
uint32 data_length();
1740
uint size_of() const { return sizeof(*this); }
1741
enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
1742
bool has_charset(void) const
1743
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1744
Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type);
1745
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
1746
uchar *new_ptr, uchar *new_null_ptr,
1748
uint is_equal(Create_field *new_field);
1749
void hash(ulong *nr, ulong *nr2);
1751
int do_save_field_metadata(uchar *first_byte);
1755
class Field_blob :public Field_longstr {
1758
The number of bytes used to represent the length of the blob.
1763
The 'value'-object is a cache fronting the storage engine.
1768
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1769
enum utype unireg_check_arg, const char *field_name_arg,
1770
TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
1771
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1773
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1774
NONE, field_name_arg, cs),
1779
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1780
CHARSET_INFO *cs, bool set_packlength)
1781
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1782
NONE, field_name_arg, cs)
1788
uint32 l_char_length= len_arg/cs->mbmaxlen;
1789
packlength= l_char_length <= 255 ? 1 :
1790
l_char_length <= 65535 ? 2 :
1791
l_char_length <= 16777215 ? 3 : 4;
1794
Field_blob(uint32 packlength_arg)
1795
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
1796
packlength(packlength_arg) {}
1797
enum_field_types type() const { return MYSQL_TYPE_BLOB;}
1798
bool match_collation_to_optimize_range() const { return TRUE; }
1799
enum ha_base_keytype key_type() const
1800
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
1801
int store(const char *to,uint length,CHARSET_INFO *charset);
1802
int store(double nr);
1803
int store(longlong nr, bool unsigned_val);
1804
double val_real(void);
1805
longlong val_int(void);
1806
String *val_str(String*,String *);
1807
my_decimal *val_decimal(my_decimal *);
1808
int cmp_max(const uchar *, const uchar *, uint max_length);
1809
int cmp(const uchar *a,const uchar *b)
1810
{ return cmp_max(a, b, ~0L); }
1811
int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
1812
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1813
int key_cmp(const uchar *,const uchar*);
1814
int key_cmp(const uchar *str, uint length);
1815
uint32 key_length() const { return 0; }
1816
void sort_string(uchar *buff,uint length);
1817
uint32 pack_length() const
1818
{ return (uint32) (packlength+table->s->blob_ptr_size); }
1821
Return the packed length without the pointer size added.
1823
This is used to determine the size of the actual data in the row
1826
@returns The length of the raw data itself without the pointer.
1828
uint32 pack_length_no_ptr() const
1829
{ return (uint32) (packlength); }
1830
uint row_pack_length() { return pack_length_no_ptr(); }
1831
uint32 sort_length() const;
1832
virtual uint32 max_data_length() const
1834
return (uint32) (((ulonglong) 1 << (packlength*8)) -1);
1836
int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
1837
void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
1838
uint32 get_field_buffer_size(void) { return value.alloced_length(); }
1839
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number);
1840
inline void store_length(uint32 number)
1842
store_length(ptr, packlength, number);
1846
Return the packed length plus the length of the data.
1848
This is used to determine the size of the data plus the
1849
packed length portion in the row data.
1851
@returns The length in the row plus the size of the data.
1853
uint32 get_packed_size(const uchar *ptr_arg)
1854
{return packlength + get_length(ptr_arg, packlength);}
1856
inline uint32 get_length(uint row_offset= 0)
1857
{ return get_length(ptr+row_offset, this->packlength); }
1858
uint32 get_length(const uchar *ptr, uint packlength);
1859
uint32 get_length(const uchar *ptr_arg)
1860
{ return get_length(ptr_arg, this->packlength); }
1861
inline void get_ptr(uchar **str)
1863
memcpy(str, ptr+packlength, sizeof(uchar*));
1865
inline void get_ptr(uchar **str, uint row_offset)
1867
memcpy(str, ptr+packlength+row_offset, sizeof(char*));
1869
inline void set_ptr(uchar *length, uchar *data)
1871
memcpy(ptr,length,packlength);
1872
memcpy(ptr+packlength, &data,sizeof(char*));
1874
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
1876
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
1877
store_length(ptr_ofs, packlength, length);
1878
memcpy(ptr_ofs+packlength, &data, sizeof(char*));
1880
inline void set_ptr(uint32 length, uchar *data)
1882
set_ptr_offset(0, length, data);
1884
uint get_key_image(uchar *buff,uint length, imagetype type);
1885
void set_key_image(const uchar *buff,uint length);
1886
void sql_type(String &str) const;
1891
if (value.copy((char*) tmp, get_length(), charset()))
1893
Field_blob::reset();
1896
tmp=(uchar*) value.ptr();
1897
memcpy(ptr+packlength, &tmp, sizeof(char*));
1900
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
1901
virtual const uchar *unpack(uchar *to, const uchar *from,
1902
const uchar *from_end, uint param_data);
1903
uint packed_col_length(const uchar *col_ptr, uint length);
1904
uint max_packed_col_length(uint max_length);
1905
void free() { value.free(); }
1906
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
1907
friend int field_conv(Field *to,Field *from);
1908
uint size_of() const { return sizeof(*this); }
1909
bool has_charset(void) const
1910
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1911
uint32 max_display_length();
1912
uint32 char_length();
1913
uint is_equal(Create_field *new_field);
1914
inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
1915
inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
1917
int do_save_field_metadata(uchar *first_byte);
1922
class Field_geom :public Field_blob {
1924
enum geometry_type geom_type;
1926
Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
1927
enum utype unireg_check_arg, const char *field_name_arg,
1928
TABLE_SHARE *share, uint blob_pack_length,
1929
enum geometry_type geom_type_arg)
1930
:Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
1931
field_name_arg, share, blob_pack_length, &my_charset_bin)
1932
{ geom_type= geom_type_arg; }
1933
Field_geom(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1934
TABLE_SHARE *share, enum geometry_type geom_type_arg)
1935
:Field_blob(len_arg, maybe_null_arg, field_name_arg, &my_charset_bin)
1936
{ geom_type= geom_type_arg; }
1937
enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; }
1938
enum_field_types type() const { return MYSQL_TYPE_GEOMETRY; }
1939
bool match_collation_to_optimize_range() const { return FALSE; }
1940
void sql_type(String &str) const;
1941
int store(const char *to, uint length, CHARSET_INFO *charset);
1942
int store(double nr);
1943
int store(longlong nr, bool unsigned_val);
1944
int store_decimal(const my_decimal *);
1945
uint size_of() const { return sizeof(*this); }
1948
Non-nullable GEOMETRY types cannot have defaults,
1949
but the underlying blob must still be reset.
1951
int reset(void) { return Field_blob::reset() || !maybe_null(); }
1953
geometry_type get_geometry_type() { return geom_type; };
1955
#endif /*HAVE_SPATIAL*/
1958
class Field_enum :public Field_str {
1963
Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1965
enum utype unireg_check_arg, const char *field_name_arg,
1966
uint packlength_arg,
1967
TYPELIB *typelib_arg,
1968
CHARSET_INFO *charset_arg)
1969
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1970
unireg_check_arg, field_name_arg, charset_arg),
1971
packlength(packlength_arg),typelib(typelib_arg)
1975
Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type);
1976
enum_field_types type() const { return MYSQL_TYPE_STRING; }
1977
bool match_collation_to_optimize_range() const { return FALSE; }
1978
enum Item_result cmp_type () const { return INT_RESULT; }
1979
enum ha_base_keytype key_type() const;
1980
int store(const char *to,uint length,CHARSET_INFO *charset);
1981
int store(double nr);
1982
int store(longlong nr, bool unsigned_val);
1983
double val_real(void);
1984
longlong val_int(void);
1985
String *val_str(String*,String *);
1986
int cmp(const uchar *,const uchar *);
1987
void sort_string(uchar *buff,uint length);
1988
uint32 pack_length() const { return (uint32) packlength; }
1989
void store_type(ulonglong value);
1990
void sql_type(String &str) const;
1991
uint size_of() const { return sizeof(*this); }
1992
enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
1993
uint pack_length_from_metadata(uint field_metadata)
1994
{ return (field_metadata & 0x00ff); }
1995
uint row_pack_length() { return pack_length(); }
1996
virtual bool zero_pack() const { return 0; }
1997
bool optimize_range(uint idx, uint part) { return 0; }
1998
bool eq_def(Field *field);
1999
bool has_charset(void) const { return TRUE; }
2000
/* enum and set are sorted as integers */
2001
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
2002
uint decimals() const { return 0; }
2004
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
2005
virtual const uchar *unpack(uchar *to, const uchar *from,
2006
const uchar *from_end, uint param_data);
2009
int do_save_field_metadata(uchar *first_byte);
2010
uint is_equal(Create_field *new_field);
2014
class Field_set :public Field_enum {
2016
Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2018
enum utype unireg_check_arg, const char *field_name_arg,
2019
uint32 packlength_arg,
2020
TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
2021
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
2022
unireg_check_arg, field_name_arg,
2024
typelib_arg,charset_arg),
2025
empty_set_string("", 0, charset_arg)
2027
flags=(flags & ~ENUM_FLAG) | SET_FLAG;
2029
int store(const char *to,uint length,CHARSET_INFO *charset);
2030
int store(double nr) { return Field_set::store((longlong) nr, FALSE); }
2031
int store(longlong nr, bool unsigned_val);
2033
virtual bool zero_pack() const { return 1; }
2034
String *val_str(String*,String *);
2035
void sql_type(String &str) const;
2036
uint size_of() const { return sizeof(*this); }
2037
enum_field_types real_type() const { return MYSQL_TYPE_SET; }
2038
bool has_charset(void) const { return TRUE; }
2040
const String empty_set_string;
2046
To use Field_bit::cmp_binary() you need to copy the bits stored in
2047
the beginning of the record (the NULL bytes) to each memory you
2048
want to compare (where the arguments point).
2051
- Field_bit::cmp_binary() is only implemented in the base class
2052
(Field::cmp_binary()).
2053
- Field::cmp_binary() currenly use pack_length() to calculate how
2055
- pack_length() includes size of the bits stored in the NULL bytes
2058
class Field_bit :public Field {
2060
uchar *bit_ptr; // position in record where 'uneven' bits store
2061
uchar bit_ofs; // offset to 'uneven' high bits
2062
uint bit_len; // number of 'uneven' high bits
2064
Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2065
uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
2066
enum utype unireg_check_arg, const char *field_name_arg);
2067
enum_field_types type() const { return MYSQL_TYPE_BIT; }
2068
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
2069
uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
2070
uint32 max_data_length() const { return (field_length + 7) / 8; }
2071
uint32 max_display_length() { return field_length; }
2072
uint size_of() const { return sizeof(*this); }
2073
Item_result result_type () const { return INT_RESULT; }
2075
bzero(ptr, bytes_in_rec);
2076
if (bit_ptr && (bit_len > 0)) // reset odd bits among null bits
2077
clr_rec_bits(bit_ptr, bit_ofs, bit_len);
2080
int store(const char *to, uint length, CHARSET_INFO *charset);
2081
int store(double nr);
2082
int store(longlong nr, bool unsigned_val);
2083
int store_decimal(const my_decimal *);
2084
double val_real(void);
2085
longlong val_int(void);
2086
String *val_str(String*, String *);
2087
virtual bool str_needs_quotes() { return TRUE; }
2088
my_decimal *val_decimal(my_decimal *);
2089
int cmp(const uchar *a, const uchar *b)
2091
DBUG_ASSERT(ptr == a || ptr == b);
2093
return Field_bit::key_cmp(b, bytes_in_rec+test(bit_len));
2095
return Field_bit::key_cmp(a, bytes_in_rec+test(bit_len)) * -1;
2097
int cmp_binary_offset(uint row_offset)
2098
{ return cmp_offset(row_offset); }
2099
int cmp_max(const uchar *a, const uchar *b, uint max_length);
2100
int key_cmp(const uchar *a, const uchar *b)
2101
{ return cmp_binary((uchar *) a, (uchar *) b); }
2102
int key_cmp(const uchar *str, uint length);
2103
int cmp_offset(uint row_offset);
2104
void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
2105
{ get_key_image(buff, length, itRAW); }
2106
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
2107
{ Field_bit::store((char *) buff, length, cs); }
2108
uint get_key_image(uchar *buff, uint length, imagetype type);
2109
void set_key_image(const uchar *buff, uint length)
2110
{ Field_bit::store((char*) buff, length, &my_charset_bin); }
2111
void sort_string(uchar *buff, uint length)
2112
{ get_key_image(buff, length, itRAW); }
2113
uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
2114
uint32 pack_length_in_rec() const { return bytes_in_rec; }
2115
uint pack_length_from_metadata(uint field_metadata);
2116
uint row_pack_length()
2117
{ return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); }
2118
bool compatible_field_size(uint metadata, Relay_log_info *rli,
2119
uint16 mflags, int *order_var);
2120
void sql_type(String &str) const;
2121
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
2122
virtual const uchar *unpack(uchar *to, const uchar *from,
2123
const uchar *from_end, uint param_data);
2124
virtual void set_default();
2126
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
2127
uchar *new_ptr, uchar *new_null_ptr,
2129
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
2131
bit_ptr= bit_ptr_arg;
2132
bit_ofs= bit_ofs_arg;
2134
bool eq(Field *field)
2136
return (Field::eq(field) &&
2137
bit_ptr == ((Field_bit *)field)->bit_ptr &&
2138
bit_ofs == ((Field_bit *)field)->bit_ofs);
2140
uint is_equal(Create_field *new_field);
2141
void move_field_offset(my_ptrdiff_t ptr_diff)
2143
Field::move_field_offset(ptr_diff);
2144
bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
2146
void hash(ulong *nr, ulong *nr2);
2149
virtual size_t do_last_null_byte() const;
2150
int do_save_field_metadata(uchar *first_byte);
2155
BIT field represented as chars for non-MyISAM tables.
2157
@todo The inheritance relationship is backwards since Field_bit is
2158
an extended version of Field_bit_as_char and not the other way
2159
around. Hence, we should refactor it to fix the hierarchy order.
2161
class Field_bit_as_char: public Field_bit {
2163
Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2165
enum utype unireg_check_arg, const char *field_name_arg);
2166
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
2167
uint size_of() const { return sizeof(*this); }
2168
int store(const char *to, uint length, CHARSET_INFO *charset);
2169
int store(double nr) { return Field_bit::store(nr); }
2170
int store(longlong nr, bool unsigned_val)
2171
{ return Field_bit::store(nr, unsigned_val); }
2172
void sql_type(String &str) const;
2177
Create field class for CREATE TABLE
2180
class Create_field :public Sql_alloc
2183
const char *field_name;
2184
const char *change; // If done with alter table
2185
const char *after; // Put column after this one
2186
LEX_STRING comment; // Comment for field
2187
Item *def; // Default value
2188
enum enum_field_types sql_type;
2190
At various stages in execution this can be length of field in bytes or
2191
max number of characters.
2195
The value of `length' as set by parser: is the number of characters
2196
for most of the types, or of bytes for BLOBs or numeric types.
2199
uint decimals, flags, pack_length, key_length;
2200
Field::utype unireg_check;
2201
TYPELIB *interval; // Which interval to use
2202
TYPELIB *save_interval; // Temporary copy for the above
2203
// Used only for UCS2 intervals
2204
List<String> interval_list;
2205
CHARSET_INFO *charset;
2206
Field::geometry_type geom_type;
2207
Field *field; // For alter table
2208
engine_option_value *option_list;
2209
/** structure with parsed options (for comparing fields in ALTER TABLE) */
2210
ha_field_option_struct *option_struct;
2212
uint8 row,col,sc_length,interval_id; // For rea_create_table
2213
uint offset,pack_flag;
2216
This is additinal data provided for any computed(virtual) field.
2217
In particular it includes a pointer to the item by which this field
2218
can be computed from other fields.
2220
Virtual_column_info *vcol_info;
2222
Flag indicating that the field is physically stored in tables
2223
rather than just computed from other fields.
2224
As of now, FALSE can be set only for computed virtual columns.
2228
Create_field() :after(0), option_list(NULL), option_struct(NULL)
2230
Create_field(Field *field, Field *orig_field);
2231
/* Used to make a clone of this object for ALTER/CREATE TABLE */
2232
Create_field *clone(MEM_ROOT *mem_root) const;
2233
void create_length_to_internal_length(void);
2235
/* Init for a tmp table field. To be extended if need be. */
2236
void init_for_tmp_table(enum_field_types sql_type_arg,
2237
uint32 max_length, uint32 decimals,
2238
bool maybe_null, bool is_unsigned,
2239
uint pack_length = ~0U);
2241
bool init(THD *thd, char *field_name, enum_field_types type, char *length,
2242
char *decimals, uint type_modifier, Item *default_value,
2243
Item *on_update_value, LEX_STRING *comment, char *change,
2244
List<String> *interval_list, CHARSET_INFO *cs,
2245
uint uint_geom_type, Virtual_column_info *vcol_info,
2246
engine_option_value *option_list);
2248
bool field_flags_are_binary()
2250
return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0;
2252
uint virtual_col_expr_maxlen()
2254
return 255 - FRM_VCOL_HEADER_SIZE(interval != NULL);
2257
const String empty_set_string;
2262
A class for sending info to the client
2265
class Send_field :public Sql_alloc {
2267
const char *db_name;
2268
const char *table_name,*org_table_name;
2269
const char *col_name,*org_col_name;
2271
uint charsetnr, flags, decimals;
2272
enum_field_types type;
2278
A class for quick copying data to fields
2281
class Copy_field :public Sql_alloc {
2283
Convenience definition of a copy function returned by
2286
typedef void Copy_func(Copy_field*);
2287
Copy_func *get_copy_func(Field *to, Field *from);
2289
uchar *from_ptr,*to_ptr;
2290
uchar *from_null_ptr,*to_null_ptr;
2292
uint from_bit,to_bit;
2294
Number of bytes in the fields pointed to by 'from_ptr' and
2295
'to_ptr'. Usually this is the number of bytes that are copied from
2296
'from_ptr' to 'to_ptr'.
2298
For variable-length fields (VARCHAR), the first byte(s) describe
2299
the actual length of the text. For VARCHARs with length
2300
< 256 there is 1 length byte
2301
>= 256 there is 2 length bytes
2302
Thus, if from_field is VARCHAR(10), from_length (and in most cases
2303
to_length) is 11. For VARCHAR(1024), the length is 1026. @see
2304
Field_varstring::length_bytes
2306
Note that for VARCHARs, do_copy() will be do_varstring*() which
2307
only copies the length-bytes (1 or 2) + the actual length of the
2308
text instead of from/to_length bytes. @see get_copy_func()
2310
uint from_length,to_length;
2311
Field *from_field,*to_field;
2312
String tmp; // For items
2316
void set(Field *to,Field *from,bool save); // Field to field
2317
void set(uchar *to,Field *from); // Field to string
2318
void (*do_copy)(Copy_field *);
2319
void (*do_copy2)(Copy_field *); // Used to handle null values
2323
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length,
2324
uchar *null_pos, uchar null_bit,
2325
uint pack_flag, enum_field_types field_type,
2327
Field::geometry_type geom_type,
2328
Field::utype unireg_check,
2329
TYPELIB *interval, const char *field_name);
2330
uint pack_length_to_packflag(uint type);
2331
enum_field_types get_blob_type_from_length(ulong length);
2332
uint32 calc_pack_length(enum_field_types type,uint32 length);
2333
int set_field_to_null(Field *field);
2334
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
2337
The following are for the interface with the .frm file
2340
#define FIELDFLAG_DECIMAL 1
2341
#define FIELDFLAG_BINARY 1 // Shares same flag
2342
#define FIELDFLAG_NUMBER 2
2343
#define FIELDFLAG_ZEROFILL 4
2344
#define FIELDFLAG_PACK 120 // Bits used for packing
2345
#define FIELDFLAG_INTERVAL 256 // mangled with decimals!
2346
#define FIELDFLAG_BITFIELD 512 // mangled with decimals!
2347
#define FIELDFLAG_BLOB 1024 // mangled with decimals!
2348
#define FIELDFLAG_GEOM 2048 // mangled with decimals!
2350
#define FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */
2352
#define FIELDFLAG_LEFT_FULLSCREEN 8192
2353
#define FIELDFLAG_RIGHT_FULLSCREEN 16384
2354
#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output
2355
#define FIELDFLAG_NO_DEFAULT 16384 /* sql */
2356
#define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag
2357
#define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql
2358
#define FIELDFLAG_HEX_ESCAPE ((uint) 0x10000)
2359
#define FIELDFLAG_PACK_SHIFT 3
2360
#define FIELDFLAG_DEC_SHIFT 8
2361
#define FIELDFLAG_MAX_DEC 31
2362
#define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01
2363
#define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800
2365
#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */
2367
#define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL)
2368
#define f_is_num(x) ((x) & FIELDFLAG_NUMBER)
2369
#define f_is_zerofill(x) ((x) & FIELDFLAG_ZEROFILL)
2370
#define f_is_packed(x) ((x) & FIELDFLAG_PACK)
2371
#define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
2372
#define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
2373
#define f_is_alpha(x) (!f_is_num(x))
2374
#define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
2375
#define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
2376
#define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
2377
#define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
2378
#define f_is_geom(x) (((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM)
2379
#define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256))
2380
#define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
2381
#define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL)
2382
#define f_no_default(x) (x & FIELDFLAG_NO_DEFAULT)
2383
#define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
2384
#define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE)
2386
#endif /* FIELD_INCLUDED */