597
550
@returns 0 no bytes written.
599
virtual int do_save_field_metadata(unsigned char *metadata_ptr __attribute__((unused)))
552
virtual int do_save_field_metadata(uchar *metadata_ptr)
557
class Field_num :public Field {
560
bool zerofill,unsigned_flag; // Purify cannot handle bit fields
561
Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
562
uchar null_bit_arg, utype unireg_check_arg,
563
const char *field_name_arg,
564
uint8 dec_arg, bool zero_arg, bool unsigned_arg);
565
Item_result result_type () const { return REAL_RESULT; }
566
void prepend_zeros(String *value);
567
void add_zerofill_and_unsigned(String &res) const;
568
friend class Create_field;
569
void make_field(Send_field *);
570
uint decimals() const { return (uint) dec; }
571
uint size_of() const { return sizeof(*this); }
572
bool eq_def(Field *field);
573
int store_decimal(const my_decimal *);
574
my_decimal *val_decimal(my_decimal *);
575
uint is_equal(Create_field *new_field);
576
int check_int(CHARSET_INFO *cs, const char *str, int length,
577
const char *int_end, int error);
578
bool get_int(CHARSET_INFO *cs, const char *from, uint len,
579
longlong *rnd, uint64_t unsigned_max,
580
longlong signed_min, longlong signed_max);
584
class Field_str :public Field {
586
CHARSET_INFO *field_charset;
587
enum Derivation field_derivation;
589
Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
590
uchar null_bit_arg, utype unireg_check_arg,
591
const char *field_name_arg, CHARSET_INFO *charset);
592
Item_result result_type () const { return STRING_RESULT; }
593
uint decimals() const { return NOT_FIXED_DEC; }
594
int store(double nr);
595
int store(longlong nr, bool unsigned_val)=0;
596
int store_decimal(const my_decimal *);
597
int store(const char *to,uint length,CHARSET_INFO *cs)=0;
598
uint size_of() const { return sizeof(*this); }
599
CHARSET_INFO *charset(void) const { return field_charset; }
600
void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
601
enum Derivation derivation(void) const { return field_derivation; }
602
virtual void set_derivation(enum Derivation derivation_arg)
603
{ field_derivation= derivation_arg; }
604
bool binary() const { return field_charset == &my_charset_bin; }
605
uint32 max_display_length() { return field_length; }
606
friend class Create_field;
607
my_decimal *val_decimal(my_decimal *);
608
virtual bool str_needs_quotes() { return TRUE; }
609
bool compare_str_field_flags(Create_field *new_field, uint32 flags);
610
uint is_equal(Create_field *new_field);
614
/* base class for Field_string, Field_varstring and Field_blob */
616
class Field_longstr :public Field_str
619
int report_if_important_data(const char *ptr, const char *end);
621
Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
622
uchar null_bit_arg, utype unireg_check_arg,
623
const char *field_name_arg, CHARSET_INFO *charset_arg)
624
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
625
field_name_arg, charset_arg)
628
int store_decimal(const my_decimal *d);
629
uint32 max_data_length() const;
632
/* base class for float and double and decimal (old one) */
633
class Field_real :public Field_num {
637
Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
638
uchar null_bit_arg, utype unireg_check_arg,
639
const char *field_name_arg,
640
uint8 dec_arg, bool zero_arg, bool unsigned_arg)
641
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
642
field_name_arg, dec_arg, zero_arg, unsigned_arg),
643
not_fixed(dec_arg >= NOT_FIXED_DEC)
645
int store_decimal(const my_decimal *);
646
my_decimal *val_decimal(my_decimal *);
647
int truncate(double *nr, double max_length);
648
uint32 max_display_length() { return field_length; }
649
uint size_of() const { return sizeof(*this); }
650
virtual const uchar *unpack(uchar* to, const uchar *from,
651
uint param_data, bool low_byte_first);
652
virtual uchar *pack(uchar* to, const uchar *from,
653
uint max_length, bool low_byte_first);
657
class Field_decimal :public Field_real {
659
Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
661
enum utype unireg_check_arg, const char *field_name_arg,
662
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
663
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
664
unireg_check_arg, field_name_arg,
665
dec_arg, zero_arg, unsigned_arg)
667
enum_field_types type() const { return MYSQL_TYPE_DECIMAL;}
668
enum ha_base_keytype key_type() const
669
{ return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
671
int store(const char *to,uint length,CHARSET_INFO *charset);
672
int store(double nr);
673
int store(longlong nr, bool unsigned_val);
674
double val_real(void);
675
longlong val_int(void);
676
String *val_str(String*,String *);
677
int cmp(const uchar *,const uchar *);
678
void sort_string(uchar *buff,uint length);
679
void overflow(bool negative);
680
bool zero_pack() const { return 0; }
681
void sql_type(String &str) const;
682
virtual const uchar *unpack(uchar* to, const uchar *from,
683
uint param_data, bool low_byte_first)
685
return Field::unpack(to, from, param_data, low_byte_first);
687
virtual uchar *pack(uchar* to, const uchar *from,
688
uint max_length, bool low_byte_first)
690
return Field::pack(to, from, max_length, low_byte_first);
695
/* New decimal/numeric field which use fixed point arithmetic */
696
class Field_new_decimal :public Field_num {
698
int do_save_field_metadata(uchar *first_byte);
700
/* The maximum number of decimal digits can be stored */
704
Constructors take max_length of the field as a parameter - not the
705
precision as the number of decimal digits allowed.
706
So for example we need to count length from precision handling
707
CREATE TABLE ( DECIMAL(x,y))
709
Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
711
enum utype unireg_check_arg, const char *field_name_arg,
712
uint8 dec_arg, bool zero_arg, bool unsigned_arg);
713
Field_new_decimal(uint32 len_arg, bool maybe_null_arg,
714
const char *field_name_arg, uint8 dec_arg,
716
enum_field_types type() const { return MYSQL_TYPE_NEWDECIMAL;}
717
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
718
Item_result result_type () const { return DECIMAL_RESULT; }
720
bool store_value(const my_decimal *decimal_value);
721
void set_value_on_overflow(my_decimal *decimal_value, bool sign);
722
int store(const char *to, uint length, CHARSET_INFO *charset);
723
int store(double nr);
724
int store(longlong nr, bool unsigned_val);
725
int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
726
int store_decimal(const my_decimal *);
727
double val_real(void);
728
longlong val_int(void);
729
my_decimal *val_decimal(my_decimal *);
730
String *val_str(String*, String *);
731
int cmp(const uchar *, const uchar *);
732
void sort_string(uchar *buff, uint length);
733
bool zero_pack() const { return 0; }
734
void sql_type(String &str) const;
735
uint32 max_display_length() { return field_length; }
736
uint size_of() const { return sizeof(*this); }
737
uint32 pack_length() const { return (uint32) bin_size; }
738
uint pack_length_from_metadata(uint field_metadata);
739
uint row_pack_length() { return pack_length(); }
740
int compatible_field_size(uint field_metadata);
741
uint is_equal(Create_field *new_field);
742
virtual const uchar *unpack(uchar* to, const uchar *from,
743
uint param_data, bool low_byte_first);
747
class Field_tiny :public Field_num {
749
Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
751
enum utype unireg_check_arg, const char *field_name_arg,
752
bool zero_arg, bool unsigned_arg)
753
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
754
unireg_check_arg, field_name_arg,
755
0, zero_arg,unsigned_arg)
757
enum Item_result result_type () const { return INT_RESULT; }
758
enum_field_types type() const { return MYSQL_TYPE_TINY;}
759
enum ha_base_keytype key_type() const
760
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
761
int store(const char *to,uint length,CHARSET_INFO *charset);
762
int store(double nr);
763
int store(longlong nr, bool unsigned_val);
764
int reset(void) { ptr[0]=0; return 0; }
765
double val_real(void);
766
longlong val_int(void);
767
String *val_str(String*,String *);
768
bool send_binary(Protocol *protocol);
769
int cmp(const uchar *,const uchar *);
770
void sort_string(uchar *buff,uint length);
771
uint32 pack_length() const { return 1; }
772
void sql_type(String &str) const;
773
uint32 max_display_length() { return 4; }
775
virtual uchar *pack(uchar* to, const uchar *from,
776
uint max_length, bool low_byte_first)
782
virtual const uchar *unpack(uchar* to, const uchar *from,
783
uint param_data, bool low_byte_first)
791
class Field_short :public Field_num {
793
Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
795
enum utype unireg_check_arg, const char *field_name_arg,
796
bool zero_arg, bool unsigned_arg)
797
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
798
unireg_check_arg, field_name_arg,
799
0, zero_arg,unsigned_arg)
801
Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
803
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
804
NONE, field_name_arg, 0, 0, unsigned_arg)
806
enum Item_result result_type () const { return INT_RESULT; }
807
enum_field_types type() const { return MYSQL_TYPE_SHORT;}
808
enum ha_base_keytype key_type() const
809
{ return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
810
int store(const char *to,uint length,CHARSET_INFO *charset);
811
int store(double nr);
812
int store(longlong nr, bool unsigned_val);
813
int reset(void) { ptr[0]=ptr[1]=0; return 0; }
814
double val_real(void);
815
longlong val_int(void);
816
String *val_str(String*,String *);
817
bool send_binary(Protocol *protocol);
818
int cmp(const uchar *,const uchar *);
819
void sort_string(uchar *buff,uint length);
820
uint32 pack_length() const { return 2; }
821
void sql_type(String &str) const;
822
uint32 max_display_length() { return 6; }
824
virtual uchar *pack(uchar* to, const uchar *from,
825
uint max_length, bool low_byte_first)
828
#ifdef WORDS_BIGENDIAN
829
if (table->s->db_low_byte_first)
830
val = sint2korr(from);
835
#ifdef WORDS_BIGENDIAN
841
return to + sizeof(val);
844
virtual const uchar *unpack(uchar* to, const uchar *from,
845
uint param_data, bool low_byte_first)
848
#ifdef WORDS_BIGENDIAN
850
val = sint2korr(from);
855
#ifdef WORDS_BIGENDIAN
856
if (table->s->db_low_byte_first)
861
return from + sizeof(val);
865
class Field_medium :public Field_num {
867
Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
869
enum utype unireg_check_arg, const char *field_name_arg,
870
bool zero_arg, bool unsigned_arg)
871
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
872
unireg_check_arg, field_name_arg,
873
0, zero_arg,unsigned_arg)
875
enum Item_result result_type () const { return INT_RESULT; }
876
enum_field_types type() const { return MYSQL_TYPE_INT24;}
877
enum ha_base_keytype key_type() const
878
{ return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
879
int store(const char *to,uint length,CHARSET_INFO *charset);
880
int store(double nr);
881
int store(longlong nr, bool unsigned_val);
882
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
883
double val_real(void);
884
longlong val_int(void);
885
String *val_str(String*,String *);
886
bool send_binary(Protocol *protocol);
887
int cmp(const uchar *,const uchar *);
888
void sort_string(uchar *buff,uint length);
889
uint32 pack_length() const { return 3; }
890
void sql_type(String &str) const;
891
uint32 max_display_length() { return 8; }
893
virtual uchar *pack(uchar* to, const uchar *from,
894
uint max_length, bool low_byte_first)
896
return Field::pack(to, from, max_length, low_byte_first);
899
virtual const uchar *unpack(uchar* to, const uchar *from,
900
uint param_data, bool low_byte_first)
902
return Field::unpack(to, from, param_data, low_byte_first);
907
class Field_long :public Field_num {
909
Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
911
enum utype unireg_check_arg, const char *field_name_arg,
912
bool zero_arg, bool unsigned_arg)
913
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
914
unireg_check_arg, field_name_arg,
915
0, zero_arg,unsigned_arg)
917
Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
919
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
920
NONE, field_name_arg,0,0,unsigned_arg)
922
enum Item_result result_type () const { return INT_RESULT; }
923
enum_field_types type() const { return MYSQL_TYPE_LONG;}
924
enum ha_base_keytype key_type() const
925
{ return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
926
int store(const char *to,uint length,CHARSET_INFO *charset);
927
int store(double nr);
928
int store(longlong nr, bool unsigned_val);
929
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
930
double val_real(void);
931
longlong val_int(void);
932
bool send_binary(Protocol *protocol);
933
String *val_str(String*,String *);
934
int cmp(const uchar *,const uchar *);
935
void sort_string(uchar *buff,uint length);
936
uint32 pack_length() const { return 4; }
937
void sql_type(String &str) const;
938
uint32 max_display_length() { return MY_INT32_NUM_DECIMAL_DIGITS; }
939
virtual uchar *pack(uchar* to, const uchar *from,
940
uint max_length, bool low_byte_first)
943
#ifdef WORDS_BIGENDIAN
944
if (table->s->db_low_byte_first)
945
val = sint4korr(from);
950
#ifdef WORDS_BIGENDIAN
956
return to + sizeof(val);
959
virtual const uchar *unpack(uchar* to, const uchar *from,
960
uint param_data, bool low_byte_first)
963
#ifdef WORDS_BIGENDIAN
965
val = sint4korr(from);
970
#ifdef WORDS_BIGENDIAN
971
if (table->s->db_low_byte_first)
976
return from + sizeof(val);
981
#ifdef HAVE_LONG_LONG
982
class Field_longlong :public Field_num {
984
Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
986
enum utype unireg_check_arg, const char *field_name_arg,
987
bool zero_arg, bool unsigned_arg)
988
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
989
unireg_check_arg, field_name_arg,
990
0, zero_arg,unsigned_arg)
992
Field_longlong(uint32 len_arg,bool maybe_null_arg,
993
const char *field_name_arg,
995
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
996
NONE, field_name_arg,0,0,unsigned_arg)
998
enum Item_result result_type () const { return INT_RESULT; }
999
enum_field_types type() const { return MYSQL_TYPE_LONGLONG;}
1000
enum ha_base_keytype key_type() const
1001
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
1002
int store(const char *to,uint length,CHARSET_INFO *charset);
1003
int store(double nr);
1004
int store(longlong nr, bool unsigned_val);
1007
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
1010
double val_real(void);
1011
longlong val_int(void);
1012
String *val_str(String*,String *);
1013
bool send_binary(Protocol *protocol);
1014
int cmp(const uchar *,const uchar *);
1015
void sort_string(uchar *buff,uint length);
1016
uint32 pack_length() const { return 8; }
1017
void sql_type(String &str) const;
1018
bool can_be_compared_as_longlong() const { return TRUE; }
1019
uint32 max_display_length() { return 20; }
1020
virtual uchar *pack(uchar* to, const uchar *from,
1021
uint max_length, bool low_byte_first)
1024
#ifdef WORDS_BIGENDIAN
1025
if (table->s->db_low_byte_first)
1026
val = sint8korr(from);
1029
longlongget(val, from);
1031
#ifdef WORDS_BIGENDIAN
1036
longlongstore(to, val);
1037
return to + sizeof(val);
1040
virtual const uchar *unpack(uchar* to, const uchar *from,
1041
uint param_data, bool low_byte_first)
1044
#ifdef WORDS_BIGENDIAN
1046
val = sint8korr(from);
1049
longlongget(val, from);
1051
#ifdef WORDS_BIGENDIAN
1052
if (table->s->db_low_byte_first)
1056
longlongstore(to, val);
1057
return from + sizeof(val);
1063
class Field_float :public Field_real {
1065
Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1067
enum utype unireg_check_arg, const char *field_name_arg,
1068
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
1069
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1070
unireg_check_arg, field_name_arg,
1071
dec_arg, zero_arg, unsigned_arg)
1073
Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1075
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
1076
NONE, field_name_arg, dec_arg, 0, 0)
1078
enum_field_types type() const { return MYSQL_TYPE_FLOAT;}
1079
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
1080
int store(const char *to,uint length,CHARSET_INFO *charset);
1081
int store(double nr);
1082
int store(longlong nr, bool unsigned_val);
1083
int reset(void) { bzero(ptr,sizeof(float)); return 0; }
1084
double val_real(void);
1085
longlong val_int(void);
1086
String *val_str(String*,String *);
1087
bool send_binary(Protocol *protocol);
1088
int cmp(const uchar *,const uchar *);
1089
void sort_string(uchar *buff,uint length);
1090
uint32 pack_length() const { return sizeof(float); }
1091
uint row_pack_length() { return pack_length(); }
1092
void sql_type(String &str) const;
1094
int do_save_field_metadata(uchar *first_byte);
1098
class Field_double :public Field_real {
1100
Field_double(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_double(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
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1114
uint8 dec_arg, my_bool not_fixed_arg)
1115
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
1116
NONE, field_name_arg, dec_arg, 0, 0)
1117
{not_fixed= not_fixed_arg; }
1118
enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
1119
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
1120
int store(const char *to,uint length,CHARSET_INFO *charset);
1121
int store(double nr);
1122
int store(longlong nr, bool unsigned_val);
1123
int reset(void) { bzero(ptr,sizeof(double)); return 0; }
1124
double val_real(void);
1125
longlong val_int(void);
1126
String *val_str(String*,String *);
1127
bool send_binary(Protocol *protocol);
1128
int cmp(const uchar *,const uchar *);
1129
void sort_string(uchar *buff,uint length);
1130
uint32 pack_length() const { return sizeof(double); }
1131
uint row_pack_length() { return pack_length(); }
1132
void sql_type(String &str) const;
1134
int do_save_field_metadata(uchar *first_byte);
1138
/* Everything saved in this will disappear. It will always return NULL */
1140
class Field_null :public Field_str {
1141
static uchar null[1];
1143
Field_null(uchar *ptr_arg, uint32 len_arg,
1144
enum utype unireg_check_arg, const char *field_name_arg,
1146
:Field_str(ptr_arg, len_arg, null, 1,
1147
unireg_check_arg, field_name_arg, cs)
1149
enum_field_types type() const { return MYSQL_TYPE_NULL;}
1150
int store(const char *to, uint length, CHARSET_INFO *cs)
1151
{ null[0]=1; return 0; }
1152
int store(double nr) { null[0]=1; return 0; }
1153
int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; }
1154
int store_decimal(const my_decimal *d) { null[0]=1; return 0; }
1155
int reset(void) { return 0; }
1156
double val_real(void) { return 0.0;}
1157
longlong val_int(void) { return 0;}
1158
my_decimal *val_decimal(my_decimal *) { return 0; }
1159
String *val_str(String *value,String *value2)
1160
{ value2->length(0); return value2;}
1161
int cmp(const uchar *a, const uchar *b) { return 0;}
1162
void sort_string(uchar *buff, uint length) {}
1163
uint32 pack_length() const { return 0; }
1164
void sql_type(String &str) const;
1165
uint size_of() const { return sizeof(*this); }
1166
uint32 max_display_length() { return 4; }
1170
class Field_timestamp :public Field_str {
1172
Field_timestamp(uchar *ptr_arg, uint32 len_arg,
1173
uchar *null_ptr_arg, uchar null_bit_arg,
1174
enum utype unireg_check_arg, const char *field_name_arg,
1175
TABLE_SHARE *share, CHARSET_INFO *cs);
1176
Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
1178
enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;}
1179
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
1180
enum Item_result cmp_type () const { return INT_RESULT; }
1181
int store(const char *to,uint length,CHARSET_INFO *charset);
1182
int store(double nr);
1183
int store(longlong nr, bool unsigned_val);
1184
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1185
double val_real(void);
1186
longlong val_int(void);
1187
String *val_str(String*,String *);
1188
bool send_binary(Protocol *protocol);
1189
int cmp(const uchar *,const uchar *);
1190
void sort_string(uchar *buff,uint length);
1191
uint32 pack_length() const { return 4; }
1192
void sql_type(String &str) const;
1193
bool can_be_compared_as_longlong() const { return TRUE; }
1194
bool zero_pack() const { return 0; }
1196
virtual void set_default()
1198
if (table->timestamp_field == this &&
1199
unireg_check != TIMESTAMP_UN_FIELD)
1202
Field::set_default();
1204
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
1205
inline long get_timestamp(my_bool *null_value)
1207
if ((*null_value= is_null()))
1209
#ifdef WORDS_BIGENDIAN
1210
if (table && table->s->db_low_byte_first)
1211
return sint4korr(ptr);
1217
inline void store_timestamp(my_time_t timestamp)
1219
#ifdef WORDS_BIGENDIAN
1220
if (table && table->s->db_low_byte_first)
1222
int4store(ptr,timestamp);
1226
longstore(ptr,(uint32) timestamp);
1228
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1229
bool get_time(MYSQL_TIME *ltime);
1230
timestamp_auto_set_type get_auto_set_type() const;
1234
class Field_year :public Field_tiny {
1236
Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1238
enum utype unireg_check_arg, const char *field_name_arg)
1239
:Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1240
unireg_check_arg, field_name_arg, 1, 1)
1242
enum_field_types type() const { return MYSQL_TYPE_YEAR;}
1243
int store(const char *to,uint length,CHARSET_INFO *charset);
1244
int store(double nr);
1245
int store(longlong nr, bool unsigned_val);
1246
double val_real(void);
1247
longlong val_int(void);
1248
String *val_str(String*,String *);
1249
bool send_binary(Protocol *protocol);
1250
void sql_type(String &str) const;
1251
bool can_be_compared_as_longlong() const { return TRUE; }
1255
class Field_date :public Field_str {
1257
Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1258
enum utype unireg_check_arg, const char *field_name_arg,
1260
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
1261
unireg_check_arg, field_name_arg, cs)
1263
Field_date(bool maybe_null_arg, const char *field_name_arg,
1265
:Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
1266
NONE, field_name_arg, cs) {}
1267
enum_field_types type() const { return MYSQL_TYPE_DATE;}
1268
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
1269
enum Item_result cmp_type () const { return INT_RESULT; }
1270
int store(const char *to,uint length,CHARSET_INFO *charset);
1271
int store(double nr);
1272
int store(longlong nr, bool unsigned_val);
1273
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1274
double val_real(void);
1275
longlong val_int(void);
1276
String *val_str(String*,String *);
1277
bool get_time(MYSQL_TIME *ltime);
1278
bool send_binary(Protocol *protocol);
1279
int cmp(const uchar *,const uchar *);
1280
void sort_string(uchar *buff,uint length);
1281
uint32 pack_length() const { return 4; }
1282
void sql_type(String &str) const;
1283
bool can_be_compared_as_longlong() const { return TRUE; }
1284
bool zero_pack() const { return 1; }
1288
class Field_newdate :public Field_str {
1290
Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1291
enum utype unireg_check_arg, const char *field_name_arg,
1293
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
1294
unireg_check_arg, field_name_arg, cs)
1296
Field_newdate(bool maybe_null_arg, const char *field_name_arg,
1298
:Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
1299
NONE, field_name_arg, cs) {}
1300
enum_field_types type() const { return MYSQL_TYPE_DATE;}
1301
enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; }
1302
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
1303
enum Item_result cmp_type () const { return INT_RESULT; }
1304
int store(const char *to,uint length,CHARSET_INFO *charset);
1305
int store(double nr);
1306
int store(longlong nr, bool unsigned_val);
1307
int store_time(MYSQL_TIME *ltime, timestamp_type type);
1308
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1309
double val_real(void);
1310
longlong val_int(void);
1311
String *val_str(String*,String *);
1312
bool send_binary(Protocol *protocol);
1313
int cmp(const uchar *,const uchar *);
1314
void sort_string(uchar *buff,uint length);
1315
uint32 pack_length() const { return 3; }
1316
void sql_type(String &str) const;
1317
bool can_be_compared_as_longlong() const { return TRUE; }
1318
bool zero_pack() const { return 1; }
1319
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1320
bool get_time(MYSQL_TIME *ltime);
1324
class Field_time :public Field_str {
1326
Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1327
enum utype unireg_check_arg, const char *field_name_arg,
1329
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
1330
unireg_check_arg, field_name_arg, cs)
1332
Field_time(bool maybe_null_arg, const char *field_name_arg,
1334
:Field_str((uchar*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
1335
NONE, field_name_arg, cs) {}
1336
enum_field_types type() const { return MYSQL_TYPE_TIME;}
1337
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
1338
enum Item_result cmp_type () const { return INT_RESULT; }
1339
int store_time(MYSQL_TIME *ltime, timestamp_type type);
1340
int store(const char *to,uint length,CHARSET_INFO *charset);
1341
int store(double nr);
1342
int store(longlong nr, bool unsigned_val);
1343
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1344
double val_real(void);
1345
longlong val_int(void);
1346
String *val_str(String*,String *);
1347
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
1348
bool send_binary(Protocol *protocol);
1349
bool get_time(MYSQL_TIME *ltime);
1350
int cmp(const uchar *,const uchar *);
1351
void sort_string(uchar *buff,uint length);
1352
uint32 pack_length() const { return 3; }
1353
void sql_type(String &str) const;
1354
bool can_be_compared_as_longlong() const { return TRUE; }
1355
bool zero_pack() const { return 1; }
1359
class Field_datetime :public Field_str {
1361
Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1362
enum utype unireg_check_arg, const char *field_name_arg,
1364
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
1365
unireg_check_arg, field_name_arg, cs)
1367
Field_datetime(bool maybe_null_arg, const char *field_name_arg,
1369
:Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
1370
NONE, field_name_arg, cs) {}
1371
enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
1372
#ifdef HAVE_LONG_LONG
1373
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
1375
enum Item_result cmp_type () const { return INT_RESULT; }
1376
uint decimals() const { return DATETIME_DEC; }
1377
int store(const char *to,uint length,CHARSET_INFO *charset);
1378
int store(double nr);
1379
int store(longlong nr, bool unsigned_val);
1380
int store_time(MYSQL_TIME *ltime, timestamp_type type);
1383
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
1386
double val_real(void);
1387
longlong val_int(void);
1388
String *val_str(String*,String *);
1389
bool send_binary(Protocol *protocol);
1390
int cmp(const uchar *,const uchar *);
1391
void sort_string(uchar *buff,uint length);
1392
uint32 pack_length() const { return 8; }
1393
void sql_type(String &str) const;
1394
bool can_be_compared_as_longlong() const { return TRUE; }
1395
bool zero_pack() const { return 1; }
1396
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1397
bool get_time(MYSQL_TIME *ltime);
1401
class Field_string :public Field_longstr {
1403
bool can_alter_field_type;
1404
Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
1406
enum utype unireg_check_arg, const char *field_name_arg,
1408
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1409
unireg_check_arg, field_name_arg, cs),
1410
can_alter_field_type(1) {};
1411
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1413
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1414
NONE, field_name_arg, cs),
1415
can_alter_field_type(1) {};
1417
enum_field_types type() const
1419
return ((can_alter_field_type && orig_table &&
1420
orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
1421
field_length >= 4) &&
1422
orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
1423
MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
1425
enum ha_base_keytype key_type() const
1426
{ return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
1427
bool zero_pack() const { return 0; }
1430
charset()->cset->fill(charset(),(char*) ptr, field_length,
1431
(has_charset() ? ' ' : 0));
1434
int store(const char *to,uint length,CHARSET_INFO *charset);
1435
int store(longlong nr, bool unsigned_val);
1436
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1437
double val_real(void);
1438
longlong val_int(void);
1439
String *val_str(String*,String *);
1440
my_decimal *val_decimal(my_decimal *);
1441
int cmp(const uchar *,const uchar *);
1442
void sort_string(uchar *buff,uint length);
1443
void sql_type(String &str) const;
1444
virtual uchar *pack(uchar *to, const uchar *from,
1445
uint max_length, bool low_byte_first);
1446
virtual const uchar *unpack(uchar* to, const uchar *from,
1447
uint param_data, bool low_byte_first);
1448
uint pack_length_from_metadata(uint field_metadata)
1449
{ return (field_metadata & 0x00ff); }
1450
uint row_pack_length() { return (field_length + 1); }
1451
int pack_cmp(const uchar *a,const uchar *b,uint key_length,
1452
my_bool insert_or_update);
1453
int pack_cmp(const uchar *b,uint key_length,my_bool insert_or_update);
1454
uint packed_col_length(const uchar *to, uint length);
1455
uint max_packed_col_length(uint max_length);
1456
uint size_of() const { return sizeof(*this); }
1457
enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
1458
bool has_charset(void) const
1459
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1460
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1461
virtual uint get_key_image(uchar *buff,uint length, imagetype type);
1463
int do_save_field_metadata(uchar *first_byte);
1467
class Field_varstring :public Field_longstr {
1470
The maximum space available in a Field_varstring, in bytes. See
1473
static const uint MAX_SIZE;
1474
/* Store number of bytes used to store length (1 or 2) */
1475
uint32 length_bytes;
1476
Field_varstring(uchar *ptr_arg,
1477
uint32 len_arg, uint length_bytes_arg,
1478
uchar *null_ptr_arg, uchar null_bit_arg,
1479
enum utype unireg_check_arg, const char *field_name_arg,
1480
TABLE_SHARE *share, CHARSET_INFO *cs)
1481
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1482
unireg_check_arg, field_name_arg, cs),
1483
length_bytes(length_bytes_arg)
1485
share->varchar_fields++;
1487
Field_varstring(uint32 len_arg,bool maybe_null_arg,
1488
const char *field_name_arg,
1489
TABLE_SHARE *share, CHARSET_INFO *cs)
1490
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1491
NONE, field_name_arg, cs),
1492
length_bytes(len_arg < 256 ? 1 :2)
1494
share->varchar_fields++;
1497
enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
1498
enum ha_base_keytype key_type() const;
1499
uint row_pack_length() { return field_length; }
1500
bool zero_pack() const { return 0; }
1501
int reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
1502
uint32 pack_length() const { return (uint32) field_length+length_bytes; }
1503
uint32 key_length() const { return (uint32) field_length; }
1504
uint32 sort_length() const
1506
return (uint32) field_length + (field_charset == &my_charset_bin ?
1509
int store(const char *to,uint length,CHARSET_INFO *charset);
1510
int store(longlong nr, bool unsigned_val);
1511
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1512
double val_real(void);
1513
longlong val_int(void);
1514
String *val_str(String*,String *);
1515
my_decimal *val_decimal(my_decimal *);
1516
int cmp_max(const uchar *, const uchar *, uint max_length);
1517
int cmp(const uchar *a,const uchar *b)
1519
return cmp_max(a, b, ~0L);
1521
void sort_string(uchar *buff,uint length);
1522
uint get_key_image(uchar *buff,uint length, imagetype type);
1523
void set_key_image(const uchar *buff,uint length);
1524
void sql_type(String &str) const;
1525
virtual uchar *pack(uchar *to, const uchar *from,
1526
uint max_length, bool low_byte_first);
1527
uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first);
1528
uchar *pack_key_from_key_image(uchar* to, const uchar *from,
1529
uint max_length, bool low_byte_first);
1530
virtual const uchar *unpack(uchar* to, const uchar *from,
1531
uint param_data, bool low_byte_first);
1532
const uchar *unpack_key(uchar* to, const uchar *from,
1533
uint max_length, bool low_byte_first);
1534
int pack_cmp(const uchar *a, const uchar *b, uint key_length,
1535
my_bool insert_or_update);
1536
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
1537
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1538
int key_cmp(const uchar *,const uchar*);
1539
int key_cmp(const uchar *str, uint length);
1540
uint packed_col_length(const uchar *to, uint length);
1541
uint max_packed_col_length(uint max_length);
1542
uint32 data_length();
1543
uint32 used_length();
1544
uint size_of() const { return sizeof(*this); }
1545
enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
1546
bool has_charset(void) const
1547
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1548
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1549
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
1550
uchar *new_ptr, uchar *new_null_ptr,
1552
uint is_equal(Create_field *new_field);
1553
void hash(ulong *nr, ulong *nr2);
1555
int do_save_field_metadata(uchar *first_byte);
1559
class Field_blob :public Field_longstr {
1562
String value; // For temporaries
1564
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1565
enum utype unireg_check_arg, const char *field_name_arg,
1566
TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
1567
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1569
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1570
NONE, field_name_arg, cs),
1575
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1576
CHARSET_INFO *cs, bool set_packlength)
1577
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1578
NONE, field_name_arg, cs)
1584
uint32 l_char_length= len_arg/cs->mbmaxlen;
1585
packlength= l_char_length <= 255 ? 1 :
1586
l_char_length <= 65535 ? 2 :
1587
l_char_length <= 16777215 ? 3 : 4;
1590
Field_blob(uint32 packlength_arg)
1591
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
1592
packlength(packlength_arg) {}
1593
enum_field_types type() const { return MYSQL_TYPE_BLOB;}
1594
enum ha_base_keytype key_type() const
1595
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
1596
int store(const char *to,uint length,CHARSET_INFO *charset);
1597
int store(double nr);
1598
int store(longlong nr, bool unsigned_val);
1599
double val_real(void);
1600
longlong val_int(void);
1601
String *val_str(String*,String *);
1602
my_decimal *val_decimal(my_decimal *);
1603
int cmp_max(const uchar *, const uchar *, uint max_length);
1604
int cmp(const uchar *a,const uchar *b)
1605
{ return cmp_max(a, b, ~0L); }
1606
int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
1607
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1608
int key_cmp(const uchar *,const uchar*);
1609
int key_cmp(const uchar *str, uint length);
1610
uint32 key_length() const { return 0; }
1611
void sort_string(uchar *buff,uint length);
1612
uint32 pack_length() const
1613
{ return (uint32) (packlength+table->s->blob_ptr_size); }
1616
Return the packed length without the pointer size added.
1618
This is used to determine the size of the actual data in the row
1621
@returns The length of the raw data itself without the pointer.
1623
uint32 pack_length_no_ptr() const
1624
{ return (uint32) (packlength); }
1625
uint row_pack_length() { return pack_length_no_ptr(); }
1626
uint32 sort_length() const;
1627
virtual uint32 max_data_length() const
1629
return (uint32) (((uint64_t) 1 << (packlength*8)) -1);
1631
int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
1632
void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
1633
#ifndef WORDS_BIGENDIAN
1636
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, bool low_byte_first);
1637
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
1639
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
1641
inline void store_length(uint32 number)
1643
store_length(ptr, packlength, number);
1647
Return the packed length plus the length of the data.
1649
This is used to determine the size of the data plus the
1650
packed length portion in the row data.
1652
@returns The length in the row plus the size of the data.
1654
uint32 get_packed_size(const uchar *ptr_arg, bool low_byte_first)
1655
{return packlength + get_length(ptr_arg, packlength, low_byte_first);}
1657
inline uint32 get_length(uint row_offset= 0)
1658
{ return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
1659
uint32 get_length(const uchar *ptr, uint packlength, bool low_byte_first);
1660
uint32 get_length(const uchar *ptr_arg)
1661
{ return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
1662
void put_length(uchar *pos, uint32 length);
1663
inline void get_ptr(uchar **str)
1665
memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*));
1667
inline void get_ptr(uchar **str, uint row_offset)
1669
memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*));
1671
inline void set_ptr(uchar *length, uchar *data)
1673
memcpy(ptr,length,packlength);
1674
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
1676
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
1678
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
1679
store_length(ptr_ofs, packlength, length);
1680
memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
1682
inline void set_ptr(uint32 length, uchar *data)
1684
set_ptr_offset(0, length, data);
1686
uint get_key_image(uchar *buff,uint length, imagetype type);
1687
void set_key_image(const uchar *buff,uint length);
1688
void sql_type(String &str) const;
1693
if (value.copy((char*) tmp, get_length(), charset()))
1695
Field_blob::reset();
1698
tmp=(uchar*) value.ptr();
1699
memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
1702
virtual uchar *pack(uchar *to, const uchar *from,
1703
uint max_length, bool low_byte_first);
1704
uchar *pack_key(uchar *to, const uchar *from,
1705
uint max_length, bool low_byte_first);
1706
uchar *pack_key_from_key_image(uchar* to, const uchar *from,
1707
uint max_length, bool low_byte_first);
1708
virtual const uchar *unpack(uchar *to, const uchar *from,
1709
uint param_data, bool low_byte_first);
1710
const uchar *unpack_key(uchar* to, const uchar *from,
1711
uint max_length, bool low_byte_first);
1712
int pack_cmp(const uchar *a, const uchar *b, uint key_length,
1713
my_bool insert_or_update);
1714
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
1715
uint packed_col_length(const uchar *col_ptr, uint length);
1716
uint max_packed_col_length(uint max_length);
1717
void free() { value.free(); }
1718
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
1719
friend int field_conv(Field *to,Field *from);
1720
uint size_of() const { return sizeof(*this); }
1721
bool has_charset(void) const
1722
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1723
uint32 max_display_length();
1724
uint is_equal(Create_field *new_field);
1725
inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
1726
inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
1728
int do_save_field_metadata(uchar *first_byte);
1732
class Field_enum :public Field_str {
1737
Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1739
enum utype unireg_check_arg, const char *field_name_arg,
1740
uint packlength_arg,
1741
TYPELIB *typelib_arg,
1742
CHARSET_INFO *charset_arg)
1743
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1744
unireg_check_arg, field_name_arg, charset_arg),
1745
packlength(packlength_arg),typelib(typelib_arg)
1749
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1750
enum_field_types type() const { return MYSQL_TYPE_STRING; }
1751
enum Item_result cmp_type () const { return INT_RESULT; }
1752
enum Item_result cast_to_int_type () const { return INT_RESULT; }
1753
enum ha_base_keytype key_type() const;
1754
int store(const char *to,uint length,CHARSET_INFO *charset);
1755
int store(double nr);
1756
int store(longlong nr, bool unsigned_val);
1757
double val_real(void);
1758
longlong val_int(void);
1759
String *val_str(String*,String *);
1760
int cmp(const uchar *,const uchar *);
1761
void sort_string(uchar *buff,uint length);
1762
uint32 pack_length() const { return (uint32) packlength; }
1763
void store_type(uint64_t value);
1764
void sql_type(String &str) const;
1765
uint size_of() const { return sizeof(*this); }
1766
enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
1767
uint pack_length_from_metadata(uint field_metadata)
1768
{ return (field_metadata & 0x00ff); }
1769
uint row_pack_length() { return pack_length(); }
1770
virtual bool zero_pack() const { return 0; }
1771
bool optimize_range(uint idx, uint part) { return 0; }
1772
bool eq_def(Field *field);
1773
bool has_charset(void) const { return TRUE; }
1774
/* enum and set are sorted as integers */
1775
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
1777
int do_save_field_metadata(uchar *first_byte);
1781
class Field_set :public Field_enum {
1783
Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1785
enum utype unireg_check_arg, const char *field_name_arg,
1786
uint32 packlength_arg,
1787
TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
1788
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1789
unireg_check_arg, field_name_arg,
1791
typelib_arg,charset_arg)
1793
flags=(flags & ~ENUM_FLAG) | SET_FLAG;
1795
int store(const char *to,uint length,CHARSET_INFO *charset);
1796
int store(double nr) { return Field_set::store((longlong) nr, FALSE); }
1797
int store(longlong nr, bool unsigned_val);
1799
virtual bool zero_pack() const { return 1; }
1800
String *val_str(String*,String *);
1801
void sql_type(String &str) const;
1802
enum_field_types real_type() const { return MYSQL_TYPE_SET; }
1803
bool has_charset(void) const { return TRUE; }
1809
To use Field_bit::cmp_binary() you need to copy the bits stored in
1810
the beginning of the record (the NULL bytes) to each memory you
1811
want to compare (where the arguments point).
1814
- Field_bit::cmp_binary() is only implemented in the base class
1815
(Field::cmp_binary()).
1816
- Field::cmp_binary() currenly use pack_length() to calculate how
1818
- pack_length() includes size of the bits stored in the NULL bytes
1821
class Field_bit :public Field {
1823
uchar *bit_ptr; // position in record where 'uneven' bits store
1824
uchar bit_ofs; // offset to 'uneven' high bits
1825
uint bit_len; // number of 'uneven' high bits
1827
Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1828
uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
1829
enum utype unireg_check_arg, const char *field_name_arg);
1830
enum_field_types type() const { return MYSQL_TYPE_BIT; }
1831
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
1832
uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
1833
uint32 max_data_length() const { return (field_length + 7) / 8; }
1834
uint32 max_display_length() { return field_length; }
1835
uint size_of() const { return sizeof(*this); }
1836
Item_result result_type () const { return INT_RESULT; }
1837
int reset(void) { bzero(ptr, bytes_in_rec); return 0; }
1838
int store(const char *to, uint length, CHARSET_INFO *charset);
1839
int store(double nr);
1840
int store(longlong nr, bool unsigned_val);
1841
int store_decimal(const my_decimal *);
1842
double val_real(void);
1843
longlong val_int(void);
1844
String *val_str(String*, String *);
1845
virtual bool str_needs_quotes() { return TRUE; }
1846
my_decimal *val_decimal(my_decimal *);
1847
int cmp(const uchar *a, const uchar *b)
1849
DBUG_ASSERT(ptr == a);
1850
return Field_bit::key_cmp(b, bytes_in_rec+test(bit_len));
1852
int cmp_binary_offset(uint row_offset)
1853
{ return cmp_offset(row_offset); }
1854
int cmp_max(const uchar *a, const uchar *b, uint max_length);
1855
int key_cmp(const uchar *a, const uchar *b)
1856
{ return cmp_binary((uchar *) a, (uchar *) b); }
1857
int key_cmp(const uchar *str, uint length);
1858
int cmp_offset(uint row_offset);
1859
void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
1860
{ get_key_image(buff, length, itRAW); }
1861
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
1862
{ Field_bit::store((char *) buff, length, cs); }
1863
uint get_key_image(uchar *buff, uint length, imagetype type);
1864
void set_key_image(const uchar *buff, uint length)
1865
{ Field_bit::store((char*) buff, length, &my_charset_bin); }
1866
void sort_string(uchar *buff, uint length)
1867
{ get_key_image(buff, length, itRAW); }
1868
uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
1869
uint32 pack_length_in_rec() const { return bytes_in_rec; }
1870
uint pack_length_from_metadata(uint field_metadata);
1871
uint row_pack_length()
1872
{ return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); }
1873
int compatible_field_size(uint field_metadata);
1874
void sql_type(String &str) const;
1875
virtual uchar *pack(uchar *to, const uchar *from,
1876
uint max_length, bool low_byte_first);
1877
virtual const uchar *unpack(uchar *to, const uchar *from,
1878
uint param_data, bool low_byte_first);
1879
virtual void set_default();
1881
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
1882
uchar *new_ptr, uchar *new_null_ptr,
1884
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
1886
bit_ptr= bit_ptr_arg;
1887
bit_ofs= bit_ofs_arg;
1889
bool eq(Field *field)
1891
return (Field::eq(field) &&
1892
field->type() == type() &&
1893
bit_ptr == ((Field_bit *)field)->bit_ptr &&
1894
bit_ofs == ((Field_bit *)field)->bit_ofs);
1896
uint is_equal(Create_field *new_field);
1897
void move_field_offset(my_ptrdiff_t ptr_diff)
1899
Field::move_field_offset(ptr_diff);
1900
bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
1902
void hash(ulong *nr, ulong *nr2);
1905
virtual size_t do_last_null_byte() const;
1906
int do_save_field_metadata(uchar *first_byte);
1911
BIT field represented as chars for non-MyISAM tables.
1913
@todo The inheritance relationship is backwards since Field_bit is
1914
an extended version of Field_bit_as_char and not the other way
1915
around. Hence, we should refactor it to fix the hierarchy order.
1917
class Field_bit_as_char: public Field_bit {
1919
Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1921
enum utype unireg_check_arg, const char *field_name_arg);
1922
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1923
uint size_of() const { return sizeof(*this); }
1924
int store(const char *to, uint length, CHARSET_INFO *charset);
1925
int store(double nr) { return Field_bit::store(nr); }
1926
int store(longlong nr, bool unsigned_val)
1927
{ return Field_bit::store(nr, unsigned_val); }
1928
void sql_type(String &str) const;
604
1933
Create field class for CREATE TABLE