155
102
bool is_created_from_null_item;
157
/* Virtual column data */
158
virtual_column_info *vcol_info;
160
Indication that the field is phycically stored in tables
161
rather than just generated on SQL queries.
162
As of now, false can only be set for generated-only virtual columns.
166
Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
167
unsigned char null_bit_arg, utype unireg_check_arg,
104
Field(uchar *ptr_arg,uint32_t length_arg,uchar *null_ptr_arg,
105
uchar null_bit_arg, utype unireg_check_arg,
168
106
const char *field_name_arg);
169
107
virtual ~Field() {}
170
108
/* Store functions returns 1 on overflow and -1 on fatal error */
171
virtual int store(const char *to, uint32_t length, const CHARSET_INFO * const cs)=0;
109
virtual int store(const char *to, uint length, const CHARSET_INFO * const cs)=0;
172
110
virtual int store(double nr)=0;
173
111
virtual int store(int64_t nr, bool unsigned_val)=0;
174
112
virtual int store_decimal(const my_decimal *d)=0;
175
virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
176
int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
113
virtual int store_time(DRIZZLE_TIME *ltime, timestamp_type t_type);
114
int store(const char *to, uint length, const CHARSET_INFO * const cs,
177
115
enum_check_fields check_level);
178
116
virtual double val_real(void)=0;
179
117
virtual int64_t val_int(void)=0;
281
219
virtual uint32_t key_length() const { return pack_length(); }
282
220
virtual enum_field_types type() const =0;
283
221
virtual enum_field_types real_type() const { return type(); }
284
inline int cmp(const unsigned char *str) { return cmp(ptr,str); }
285
virtual int cmp_max(const unsigned char *a, const unsigned char *b,
286
uint32_t max_len __attribute__((unused)))
222
inline int cmp(const uchar *str) { return cmp(ptr,str); }
223
virtual int cmp_max(const uchar *a, const uchar *b,
224
uint max_len __attribute__((unused)))
287
225
{ return cmp(a, b); }
288
virtual int cmp(const unsigned char *,const unsigned char *)=0;
289
virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
226
virtual int cmp(const uchar *,const uchar *)=0;
227
virtual int cmp_binary(const uchar *a,const uchar *b,
290
228
uint32_t __attribute__((unused)) max_length=UINT32_MAX)
291
229
{ return memcmp(a,b,pack_length()); }
292
virtual int cmp_offset(uint32_t row_offset)
230
virtual int cmp_offset(uint row_offset)
293
231
{ return cmp(ptr,ptr+row_offset); }
294
virtual int cmp_binary_offset(uint32_t row_offset)
232
virtual int cmp_binary_offset(uint row_offset)
295
233
{ return cmp_binary(ptr, ptr+row_offset); };
296
virtual int key_cmp(const unsigned char *a,const unsigned char *b)
234
virtual int key_cmp(const uchar *a,const uchar *b)
297
235
{ return cmp(a, b); }
298
virtual int key_cmp(const unsigned char *str, uint32_t length __attribute__((unused)))
236
virtual int key_cmp(const uchar *str, uint length __attribute__((unused)))
299
237
{ return cmp(ptr,str); }
300
virtual uint32_t decimals() const { return 0; }
238
virtual uint decimals() const { return 0; }
302
240
Caller beware: sql_type can change str.Ptr, so check
303
241
ptr() to see if it changed if you are using your own buffer
304
242
in str and restore it with set() if needed
306
244
virtual void sql_type(String &str) const =0;
307
virtual uint32_t size_of() const =0; // For new field
245
virtual uint size_of() const =0; // For new field
308
246
inline bool is_null(my_ptrdiff_t row_offset= 0)
309
247
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
310
248
inline bool is_real_null(my_ptrdiff_t row_offset= 0)
311
249
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
312
inline bool is_null_in_record(const unsigned char *record)
250
inline bool is_null_in_record(const uchar *record)
316
return test(record[(uint32_t) (null_ptr -table->record[0])] &
254
return test(record[(uint) (null_ptr -table->record[0])] &
319
257
inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
369
307
virtual Field *new_field(MEM_ROOT *root, Table *new_table,
371
309
virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
372
unsigned char *new_ptr, unsigned char *new_null_ptr,
373
uint32_t new_null_bit);
310
uchar *new_ptr, uchar *new_null_ptr,
374
312
Field *clone(MEM_ROOT *mem_root, Table *new_table);
375
inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
313
inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
377
315
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
379
inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
317
inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
380
318
virtual void move_field_offset(my_ptrdiff_t ptr_diff)
382
ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
320
ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
384
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
322
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
386
virtual void get_image(unsigned char *buff, uint32_t length,
324
virtual void get_image(uchar *buff, uint length,
387
325
const CHARSET_INFO * const cs __attribute__((unused)))
388
326
{ memcpy(buff,ptr,length); }
389
virtual void set_image(const unsigned char *buff,uint32_t length,
327
virtual void set_image(const uchar *buff,uint length,
390
328
const CHARSET_INFO * const cs __attribute__((unused)))
391
329
{ memcpy(ptr,buff,length); }
417
355
Number of copied bytes (excluding padded zero bytes -- see above).
420
virtual uint32_t get_key_image(unsigned char *buff, uint32_t length,
358
virtual uint get_key_image(uchar *buff, uint length,
421
359
imagetype type __attribute__((unused)))
423
361
get_image(buff, length, &my_charset_bin);
426
virtual void set_key_image(const unsigned char *buff,uint32_t length)
364
virtual void set_key_image(const uchar *buff,uint length)
427
365
{ set_image(buff,length, &my_charset_bin); }
428
inline int64_t val_int_offset(uint32_t row_offset)
366
inline int64_t val_int_offset(uint row_offset)
431
369
int64_t tmp=val_int();
435
inline int64_t val_int(const unsigned char *new_ptr)
373
inline int64_t val_int(const uchar *new_ptr)
437
unsigned char *old_ptr= ptr;
438
376
int64_t return_value;
439
ptr= (unsigned char*) new_ptr;
377
ptr= (uchar*) new_ptr;
440
378
return_value= val_int();
442
380
return return_value;
444
inline String *val_str(String *str, const unsigned char *new_ptr)
382
inline String *val_str(String *str, const uchar *new_ptr)
446
unsigned char *old_ptr= ptr;
447
ptr= (unsigned char*) new_ptr;
385
ptr= (uchar*) new_ptr;
452
390
virtual bool send_binary(Protocol *protocol);
454
virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
455
uint32_t max_length, bool low_byte_first);
457
@overload Field::pack(unsigned char*, const unsigned char*, uint32_t, bool)
459
unsigned char *pack(unsigned char *to, const unsigned char *from)
461
unsigned char *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
465
virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
466
uint32_t param_data, bool low_byte_first);
468
@overload Field::unpack(unsigned char*, const unsigned char*, uint32_t, bool)
470
const unsigned char *unpack(unsigned char* to, const unsigned char *from)
472
const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
476
virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
477
uint32_t max_length, bool low_byte_first)
479
return pack(to, from, max_length, low_byte_first);
481
virtual unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
482
uint32_t max_length, bool low_byte_first)
484
return pack(to, from, max_length, low_byte_first);
486
virtual const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
487
uint32_t max_length, bool low_byte_first)
392
virtual uchar *pack(uchar *to, const uchar *from,
393
uint max_length, bool low_byte_first);
395
@overload Field::pack(uchar*, const uchar*, uint, bool)
397
uchar *pack(uchar *to, const uchar *from)
399
uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
403
virtual const uchar *unpack(uchar* to, const uchar *from,
404
uint param_data, bool low_byte_first);
406
@overload Field::unpack(uchar*, const uchar*, uint, bool)
408
const uchar *unpack(uchar* to, const uchar *from)
410
const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first);
414
virtual uchar *pack_key(uchar* to, const uchar *from,
415
uint max_length, bool low_byte_first)
417
return pack(to, from, max_length, low_byte_first);
419
virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from,
420
uint max_length, bool low_byte_first)
422
return pack(to, from, max_length, low_byte_first);
424
virtual const uchar *unpack_key(uchar* to, const uchar *from,
425
uint max_length, bool low_byte_first)
489
427
return unpack(to, from, max_length, low_byte_first);
491
virtual uint32_t packed_col_length(const unsigned char *to __attribute__((unused)),
429
virtual uint packed_col_length(const uchar *to __attribute__((unused)),
493
431
{ return length;}
494
virtual uint32_t max_packed_col_length(uint32_t max_length)
432
virtual uint max_packed_col_length(uint max_length)
495
433
{ return max_length;}
497
virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
498
uint32_t key_length_arg __attribute__((unused)),
435
virtual int pack_cmp(const uchar *a,const uchar *b,
436
uint key_length_arg __attribute__((unused)),
499
437
bool insert_or_update __attribute__((unused)))
500
438
{ return cmp(a,b); }
501
virtual int pack_cmp(const unsigned char *b,
502
uint32_t key_length_arg __attribute__((unused)),
439
virtual int pack_cmp(const uchar *b,
440
uint key_length_arg __attribute__((unused)),
503
441
bool insert_or_update __attribute__((unused)))
504
442
{ return cmp(ptr,b); }
505
uint32_t offset(unsigned char *record)
443
uint offset(uchar *record)
507
return (uint32_t) (ptr - record);
445
return (uint) (ptr - record);
509
447
void copy_from_tmp(int offset);
510
uint32_t fill_cache_field(struct st_cache_field *copy);
511
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
448
uint fill_cache_field(struct st_cache_field *copy);
449
virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
512
450
virtual bool get_time(DRIZZLE_TIME *ltime);
513
451
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
514
452
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
602
540
@returns 0 no bytes written.
604
virtual int do_save_field_metadata(unsigned char *metadata_ptr __attribute__((unused)))
542
virtual int do_save_field_metadata(uchar *metadata_ptr __attribute__((unused)))
547
class Field_num :public Field {
550
bool decimal_precision; // Purify cannot handle bit fields & only for decimal type
551
bool unsigned_flag; // Purify cannot handle bit fields
552
Field_num(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
553
uchar null_bit_arg, utype unireg_check_arg,
554
const char *field_name_arg,
555
uint8_t dec_arg, bool zero_arg, bool unsigned_arg);
556
Item_result result_type () const { return REAL_RESULT; }
557
void add_unsigned(String &res) const;
558
friend class Create_field;
559
void make_field(Send_field *);
560
uint decimals() const { return (uint) dec; }
561
uint size_of() const { return sizeof(*this); }
562
bool eq_def(Field *field);
563
int store_decimal(const my_decimal *);
564
my_decimal *val_decimal(my_decimal *);
565
uint is_equal(Create_field *new_field);
566
int check_int(const CHARSET_INFO * const cs, const char *str, int length,
567
const char *int_end, int error);
568
bool get_int(const CHARSET_INFO * const cs, const char *from, uint len,
569
int64_t *rnd, uint64_t unsigned_max,
570
int64_t signed_min, int64_t signed_max);
573
/* base class for all string related classes */
575
class Field_str :public Field {
577
const CHARSET_INFO *field_charset;
578
enum Derivation field_derivation;
580
Field_str(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
581
uchar null_bit_arg, utype unireg_check_arg,
582
const char *field_name_arg, const CHARSET_INFO * const charset);
583
Item_result result_type () const { return STRING_RESULT; }
584
uint decimals() const { return NOT_FIXED_DEC; }
585
int store(double nr);
586
int store(int64_t nr, bool unsigned_val)=0;
587
int store_decimal(const my_decimal *);
588
int store(const char *to,uint length, const CHARSET_INFO * const cs)=0;
589
uint size_of() const { return sizeof(*this); }
590
const CHARSET_INFO *charset(void) const { return field_charset; }
591
void set_charset(const CHARSET_INFO * const charset_arg) { field_charset= charset_arg; }
592
enum Derivation derivation(void) const { return field_derivation; }
593
virtual void set_derivation(enum Derivation derivation_arg)
594
{ field_derivation= derivation_arg; }
595
bool binary() const { return field_charset == &my_charset_bin; }
596
uint32_t max_display_length() { return field_length; }
597
friend class Create_field;
598
my_decimal *val_decimal(my_decimal *);
599
virtual bool str_needs_quotes() { return true; }
600
bool compare_str_field_flags(Create_field *new_field, uint32_t flags);
601
uint is_equal(Create_field *new_field);
605
/* base class for Field_varstring and Field_blob */
607
class Field_longstr :public Field_str
610
int report_if_important_data(const char *ptr, const char *end);
612
Field_longstr(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
613
uchar null_bit_arg, utype unireg_check_arg,
614
const char *field_name_arg, const CHARSET_INFO * const charset_arg)
615
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
616
field_name_arg, charset_arg)
619
int store_decimal(const my_decimal *d);
620
uint32_t max_data_length() const;
623
/* base class for float and double and decimal (old one) */
624
class Field_real :public Field_num {
628
Field_real(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
629
uchar null_bit_arg, utype unireg_check_arg,
630
const char *field_name_arg,
631
uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
632
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
633
field_name_arg, dec_arg, zero_arg, unsigned_arg),
634
not_fixed(dec_arg >= NOT_FIXED_DEC)
636
int store_decimal(const my_decimal *);
637
my_decimal *val_decimal(my_decimal *);
638
int truncate(double *nr, double max_length);
639
uint32_t max_display_length() { return field_length; }
640
uint size_of() const { return sizeof(*this); }
641
virtual const uchar *unpack(uchar* to, const uchar *from,
642
uint param_data, bool low_byte_first);
643
virtual uchar *pack(uchar* to, const uchar *from,
644
uint max_length, bool low_byte_first);
648
class Field_tiny :public Field_num {
650
Field_tiny(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
652
enum utype unireg_check_arg, const char *field_name_arg,
653
bool zero_arg, bool unsigned_arg)
654
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
655
unireg_check_arg, field_name_arg,
656
0, zero_arg,unsigned_arg)
658
enum Item_result result_type () const { return INT_RESULT; }
659
enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
660
enum ha_base_keytype key_type() const
661
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
662
int store(const char *to,uint length, const CHARSET_INFO * const charset);
663
int store(double nr);
664
int store(int64_t nr, bool unsigned_val);
665
int reset(void) { ptr[0]=0; return 0; }
666
double val_real(void);
667
int64_t val_int(void);
668
String *val_str(String*,String *);
669
bool send_binary(Protocol *protocol);
670
int cmp(const uchar *,const uchar *);
671
void sort_string(uchar *buff,uint length);
672
uint32_t pack_length() const { return 1; }
673
void sql_type(String &str) const;
674
uint32_t max_display_length() { return 4; }
676
virtual uchar *pack(uchar* to, const uchar *from,
677
uint max_length __attribute__((unused)),
678
bool low_byte_first __attribute__((unused)))
684
virtual const uchar *unpack(uchar* to, const uchar *from,
685
uint param_data __attribute__((unused)),
686
bool low_byte_first __attribute__((unused)))
694
class Field_enum :public Field_str {
699
Field_enum(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
701
enum utype unireg_check_arg, const char *field_name_arg,
703
TYPELIB *typelib_arg,
704
const CHARSET_INFO * const charset_arg)
705
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
706
unireg_check_arg, field_name_arg, charset_arg),
707
packlength(packlength_arg),typelib(typelib_arg)
711
Field *new_field(MEM_ROOT *root, Table *new_table, bool keep_type);
712
enum_field_types type() const { return DRIZZLE_TYPE_ENUM; }
713
enum Item_result cmp_type () const { return INT_RESULT; }
714
enum Item_result cast_to_int_type () const { return INT_RESULT; }
715
enum ha_base_keytype key_type() const;
716
int store(const char *to,uint length, const CHARSET_INFO * const charset);
717
int store(double nr);
718
int store(int64_t nr, bool unsigned_val);
719
double val_real(void);
720
int64_t val_int(void);
721
String *val_str(String*,String *);
722
int cmp(const uchar *,const uchar *);
723
void sort_string(uchar *buff,uint length);
724
uint32_t pack_length() const { return (uint32_t) packlength; }
725
void store_type(uint64_t value);
726
void sql_type(String &str) const;
727
uint size_of() const { return sizeof(*this); }
728
enum_field_types real_type() const { return DRIZZLE_TYPE_ENUM; }
729
uint pack_length_from_metadata(uint field_metadata)
730
{ return (field_metadata & 0x00ff); }
731
uint row_pack_length() { return pack_length(); }
732
virtual bool zero_pack() const { return 0; }
733
bool optimize_range(uint idx __attribute__((unused)),
734
uint part __attribute__((unused)))
736
bool eq_def(Field *field);
737
bool has_charset(void) const { return true; }
738
/* enum and set are sorted as integers */
739
const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
741
int do_save_field_metadata(uchar *first_byte);
705
830
typedef void Copy_func(Copy_field*);
706
831
Copy_func *get_copy_func(Field *to, Field *from);
708
unsigned char *from_ptr,*to_ptr;
709
unsigned char *from_null_ptr,*to_null_ptr;
833
uchar *from_ptr,*to_ptr;
834
uchar *from_null_ptr,*to_null_ptr;
711
uint32_t from_bit,to_bit;
712
uint32_t from_length,to_length;
836
uint from_bit,to_bit;
837
uint from_length,to_length;
713
838
Field *from_field,*to_field;
714
839
String tmp; // For items
718
843
void set(Field *to,Field *from,bool save); // Field to field
719
void set(unsigned char *to,Field *from); // Field to string
844
void set(uchar *to,Field *from); // Field to string
720
845
void (*do_copy)(Copy_field *);
721
846
void (*do_copy2)(Copy_field *); // Used to handle null values
725
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
726
unsigned char *null_pos, unsigned char null_bit,
727
uint32_t pack_flag, enum_field_types field_type,
850
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
851
uchar *null_pos, uchar null_bit,
852
uint pack_flag, enum_field_types field_type,
728
853
const CHARSET_INFO * cs,
729
854
Field::utype unireg_check,
730
855
TYPELIB *interval, const char *field_name);
731
uint32_t pack_length_to_packflag(uint32_t type);
856
uint pack_length_to_packflag(uint type);
732
857
enum_field_types get_blob_type_from_length(uint32_t length);
733
858
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
734
859
int set_field_to_null(Field *field);
735
860
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
739
test_if_important_data(const CHARSET_INFO * const cs,
863
check_string_copy_error(Field_str *field,
864
const char *well_formed_error_pos,
865
const char *cannot_convert_error_pos,
867
const CHARSET_INFO * const cs);
746
#include <drizzled/field/str.h>
747
#include <drizzled/field/longstr.h>
748
#include <drizzled/field/num.h>
749
872
#include <drizzled/field/blob.h>
750
#include <drizzled/field/enum.h>
751
873
#include <drizzled/field/null.h>
752
874
#include <drizzled/field/date.h>
753
875
#include <drizzled/field/fdecimal.h>
754
#include <drizzled/field/real.h>
755
876
#include <drizzled/field/double.h>
877
#include <drizzled/field/short.h>
756
878
#include <drizzled/field/long.h>
757
879
#include <drizzled/field/int64_t.h>
758
#include <drizzled/field/num.h>
759
880
#include <drizzled/field/timetype.h>
760
881
#include <drizzled/field/timestamp.h>
761
882
#include <drizzled/field/datetime.h>