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
class Field_longlong :public Field_num {
983
Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
985
enum utype unireg_check_arg, const char *field_name_arg,
986
bool zero_arg, bool unsigned_arg)
987
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
988
unireg_check_arg, field_name_arg,
989
0, zero_arg,unsigned_arg)
991
Field_longlong(uint32 len_arg,bool maybe_null_arg,
992
const char *field_name_arg,
994
:Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
995
NONE, field_name_arg,0,0,unsigned_arg)
997
enum Item_result result_type () const { return INT_RESULT; }
998
enum_field_types type() const { return MYSQL_TYPE_LONGLONG;}
999
enum ha_base_keytype key_type() const
1000
{ return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
1001
int store(const char *to,uint length,CHARSET_INFO *charset);
1002
int store(double nr);
1003
int store(longlong nr, bool unsigned_val);
1006
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
1009
double val_real(void);
1010
longlong val_int(void);
1011
String *val_str(String*,String *);
1012
bool send_binary(Protocol *protocol);
1013
int cmp(const uchar *,const uchar *);
1014
void sort_string(uchar *buff,uint length);
1015
uint32 pack_length() const { return 8; }
1016
void sql_type(String &str) const;
1017
bool can_be_compared_as_longlong() const { return TRUE; }
1018
uint32 max_display_length() { return 20; }
1019
virtual uchar *pack(uchar* to, const uchar *from,
1020
uint max_length, bool low_byte_first)
1023
#ifdef WORDS_BIGENDIAN
1024
if (table->s->db_low_byte_first)
1025
val = sint8korr(from);
1028
longlongget(val, from);
1030
#ifdef WORDS_BIGENDIAN
1035
longlongstore(to, val);
1036
return to + sizeof(val);
1039
virtual const uchar *unpack(uchar* to, const uchar *from,
1040
uint param_data, bool low_byte_first)
1043
#ifdef WORDS_BIGENDIAN
1045
val = sint8korr(from);
1048
longlongget(val, from);
1050
#ifdef WORDS_BIGENDIAN
1051
if (table->s->db_low_byte_first)
1055
longlongstore(to, val);
1056
return from + sizeof(val);
1060
class Field_float :public Field_real {
1062
Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1064
enum utype unireg_check_arg, const char *field_name_arg,
1065
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
1066
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1067
unireg_check_arg, field_name_arg,
1068
dec_arg, zero_arg, unsigned_arg)
1070
Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1072
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
1073
NONE, field_name_arg, dec_arg, 0, 0)
1075
enum_field_types type() const { return MYSQL_TYPE_FLOAT;}
1076
enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
1077
int store(const char *to,uint length,CHARSET_INFO *charset);
1078
int store(double nr);
1079
int store(longlong nr, bool unsigned_val);
1080
int reset(void) { bzero(ptr,sizeof(float)); return 0; }
1081
double val_real(void);
1082
longlong val_int(void);
1083
String *val_str(String*,String *);
1084
bool send_binary(Protocol *protocol);
1085
int cmp(const uchar *,const uchar *);
1086
void sort_string(uchar *buff,uint length);
1087
uint32 pack_length() const { return sizeof(float); }
1088
uint row_pack_length() { return pack_length(); }
1089
void sql_type(String &str) const;
1091
int do_save_field_metadata(uchar *first_byte);
1095
class Field_double :public Field_real {
1097
Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1099
enum utype unireg_check_arg, const char *field_name_arg,
1100
uint8 dec_arg,bool zero_arg,bool unsigned_arg)
1101
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1102
unireg_check_arg, field_name_arg,
1103
dec_arg, zero_arg, unsigned_arg)
1105
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1107
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
1108
NONE, field_name_arg, dec_arg, 0, 0)
1110
Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
1111
uint8 dec_arg, my_bool not_fixed_arg)
1112
:Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
1113
NONE, field_name_arg, dec_arg, 0, 0)
1114
{not_fixed= not_fixed_arg; }
1115
enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
1116
enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
1117
int store(const char *to,uint length,CHARSET_INFO *charset);
1118
int store(double nr);
1119
int store(longlong nr, bool unsigned_val);
1120
int reset(void) { bzero(ptr,sizeof(double)); return 0; }
1121
double val_real(void);
1122
longlong val_int(void);
1123
String *val_str(String*,String *);
1124
bool send_binary(Protocol *protocol);
1125
int cmp(const uchar *,const uchar *);
1126
void sort_string(uchar *buff,uint length);
1127
uint32 pack_length() const { return sizeof(double); }
1128
uint row_pack_length() { return pack_length(); }
1129
void sql_type(String &str) const;
1131
int do_save_field_metadata(uchar *first_byte);
1135
/* Everything saved in this will disappear. It will always return NULL */
1137
class Field_null :public Field_str {
1138
static uchar null[1];
1140
Field_null(uchar *ptr_arg, uint32 len_arg,
1141
enum utype unireg_check_arg, const char *field_name_arg,
1143
:Field_str(ptr_arg, len_arg, null, 1,
1144
unireg_check_arg, field_name_arg, cs)
1146
enum_field_types type() const { return MYSQL_TYPE_NULL;}
1147
int store(const char *to, uint length, CHARSET_INFO *cs)
1148
{ null[0]=1; return 0; }
1149
int store(double nr) { null[0]=1; return 0; }
1150
int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; }
1151
int store_decimal(const my_decimal *d) { null[0]=1; return 0; }
1152
int reset(void) { return 0; }
1153
double val_real(void) { return 0.0;}
1154
longlong val_int(void) { return 0;}
1155
my_decimal *val_decimal(my_decimal *) { return 0; }
1156
String *val_str(String *value,String *value2)
1157
{ value2->length(0); return value2;}
1158
int cmp(const uchar *a, const uchar *b) { return 0;}
1159
void sort_string(uchar *buff, uint length) {}
1160
uint32 pack_length() const { return 0; }
1161
void sql_type(String &str) const;
1162
uint size_of() const { return sizeof(*this); }
1163
uint32 max_display_length() { return 4; }
1167
class Field_timestamp :public Field_str {
1169
Field_timestamp(uchar *ptr_arg, uint32 len_arg,
1170
uchar *null_ptr_arg, uchar null_bit_arg,
1171
enum utype unireg_check_arg, const char *field_name_arg,
1172
TABLE_SHARE *share, CHARSET_INFO *cs);
1173
Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
1175
enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;}
1176
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
1177
enum Item_result cmp_type () const { return INT_RESULT; }
1178
int store(const char *to,uint length,CHARSET_INFO *charset);
1179
int store(double nr);
1180
int store(longlong nr, bool unsigned_val);
1181
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1182
double val_real(void);
1183
longlong val_int(void);
1184
String *val_str(String*,String *);
1185
bool send_binary(Protocol *protocol);
1186
int cmp(const uchar *,const uchar *);
1187
void sort_string(uchar *buff,uint length);
1188
uint32 pack_length() const { return 4; }
1189
void sql_type(String &str) const;
1190
bool can_be_compared_as_longlong() const { return TRUE; }
1191
bool zero_pack() const { return 0; }
1193
virtual void set_default()
1195
if (table->timestamp_field == this &&
1196
unireg_check != TIMESTAMP_UN_FIELD)
1199
Field::set_default();
1201
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
1202
inline long get_timestamp(my_bool *null_value)
1204
if ((*null_value= is_null()))
1206
#ifdef WORDS_BIGENDIAN
1207
if (table && table->s->db_low_byte_first)
1208
return sint4korr(ptr);
1214
inline void store_timestamp(my_time_t timestamp)
1216
#ifdef WORDS_BIGENDIAN
1217
if (table && table->s->db_low_byte_first)
1219
int4store(ptr,timestamp);
1223
longstore(ptr,(uint32) timestamp);
1225
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1226
bool get_time(MYSQL_TIME *ltime);
1227
timestamp_auto_set_type get_auto_set_type() const;
1231
class Field_year :public Field_tiny {
1233
Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1235
enum utype unireg_check_arg, const char *field_name_arg)
1236
:Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1237
unireg_check_arg, field_name_arg, 1, 1)
1239
enum_field_types type() const { return MYSQL_TYPE_YEAR;}
1240
int store(const char *to,uint length,CHARSET_INFO *charset);
1241
int store(double nr);
1242
int store(longlong nr, bool unsigned_val);
1243
double val_real(void);
1244
longlong val_int(void);
1245
String *val_str(String*,String *);
1246
bool send_binary(Protocol *protocol);
1247
void sql_type(String &str) const;
1248
bool can_be_compared_as_longlong() const { return TRUE; }
1252
class Field_date :public Field_str {
1254
Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1255
enum utype unireg_check_arg, const char *field_name_arg,
1257
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
1258
unireg_check_arg, field_name_arg, cs)
1260
Field_date(bool maybe_null_arg, const char *field_name_arg,
1262
:Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
1263
NONE, field_name_arg, cs) {}
1264
enum_field_types type() const { return MYSQL_TYPE_DATE;}
1265
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
1266
enum Item_result cmp_type () const { return INT_RESULT; }
1267
int store(const char *to,uint length,CHARSET_INFO *charset);
1268
int store(double nr);
1269
int store(longlong nr, bool unsigned_val);
1270
int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1271
double val_real(void);
1272
longlong val_int(void);
1273
String *val_str(String*,String *);
1274
bool get_time(MYSQL_TIME *ltime);
1275
bool send_binary(Protocol *protocol);
1276
int cmp(const uchar *,const uchar *);
1277
void sort_string(uchar *buff,uint length);
1278
uint32 pack_length() const { return 4; }
1279
void sql_type(String &str) const;
1280
bool can_be_compared_as_longlong() const { return TRUE; }
1281
bool zero_pack() const { return 1; }
1285
class Field_newdate :public Field_str {
1287
Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1288
enum utype unireg_check_arg, const char *field_name_arg,
1290
:Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
1291
unireg_check_arg, field_name_arg, cs)
1293
Field_newdate(bool maybe_null_arg, const char *field_name_arg,
1295
:Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
1296
NONE, field_name_arg, cs) {}
1297
enum_field_types type() const { return MYSQL_TYPE_DATE;}
1298
enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; }
1299
enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
1300
enum Item_result cmp_type () const { return INT_RESULT; }
1301
int store(const char *to,uint length,CHARSET_INFO *charset);
1302
int store(double nr);
1303
int store(longlong nr, bool unsigned_val);
1304
int store_time(MYSQL_TIME *ltime, timestamp_type type);
1305
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1306
double val_real(void);
1307
longlong val_int(void);
1308
String *val_str(String*,String *);
1309
bool send_binary(Protocol *protocol);
1310
int cmp(const uchar *,const uchar *);
1311
void sort_string(uchar *buff,uint length);
1312
uint32 pack_length() const { return 3; }
1313
void sql_type(String &str) const;
1314
bool can_be_compared_as_longlong() const { return TRUE; }
1315
bool zero_pack() const { return 1; }
1316
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1317
bool get_time(MYSQL_TIME *ltime);
1321
class Field_time :public Field_str {
1323
Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1324
enum utype unireg_check_arg, const char *field_name_arg,
1326
:Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
1327
unireg_check_arg, field_name_arg, cs)
1329
Field_time(bool maybe_null_arg, const char *field_name_arg,
1331
:Field_str((uchar*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
1332
NONE, field_name_arg, cs) {}
1333
enum_field_types type() const { return MYSQL_TYPE_TIME;}
1334
enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
1335
enum Item_result cmp_type () const { return INT_RESULT; }
1336
int store_time(MYSQL_TIME *ltime, timestamp_type type);
1337
int store(const char *to,uint length,CHARSET_INFO *charset);
1338
int store(double nr);
1339
int store(longlong nr, bool unsigned_val);
1340
int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1341
double val_real(void);
1342
longlong val_int(void);
1343
String *val_str(String*,String *);
1344
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
1345
bool send_binary(Protocol *protocol);
1346
bool get_time(MYSQL_TIME *ltime);
1347
int cmp(const uchar *,const uchar *);
1348
void sort_string(uchar *buff,uint length);
1349
uint32 pack_length() const { return 3; }
1350
void sql_type(String &str) const;
1351
bool can_be_compared_as_longlong() const { return TRUE; }
1352
bool zero_pack() const { return 1; }
1356
class Field_datetime :public Field_str {
1358
Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1359
enum utype unireg_check_arg, const char *field_name_arg,
1361
:Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
1362
unireg_check_arg, field_name_arg, cs)
1364
Field_datetime(bool maybe_null_arg, const char *field_name_arg,
1366
:Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
1367
NONE, field_name_arg, cs) {}
1368
enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
1369
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
1370
enum Item_result cmp_type () const { return INT_RESULT; }
1371
uint decimals() const { return DATETIME_DEC; }
1372
int store(const char *to,uint length,CHARSET_INFO *charset);
1373
int store(double nr);
1374
int store(longlong nr, bool unsigned_val);
1375
int store_time(MYSQL_TIME *ltime, timestamp_type type);
1378
ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
1381
double val_real(void);
1382
longlong val_int(void);
1383
String *val_str(String*,String *);
1384
bool send_binary(Protocol *protocol);
1385
int cmp(const uchar *,const uchar *);
1386
void sort_string(uchar *buff,uint length);
1387
uint32 pack_length() const { return 8; }
1388
void sql_type(String &str) const;
1389
bool can_be_compared_as_longlong() const { return TRUE; }
1390
bool zero_pack() const { return 1; }
1391
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1392
bool get_time(MYSQL_TIME *ltime);
1396
class Field_string :public Field_longstr {
1398
bool can_alter_field_type;
1399
Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
1401
enum utype unireg_check_arg, const char *field_name_arg,
1403
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1404
unireg_check_arg, field_name_arg, cs),
1405
can_alter_field_type(1) {};
1406
Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1408
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1409
NONE, field_name_arg, cs),
1410
can_alter_field_type(1) {};
1412
enum_field_types type() const
1414
return ((can_alter_field_type && orig_table &&
1415
orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
1416
field_length >= 4) &&
1417
orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
1418
MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
1420
enum ha_base_keytype key_type() const
1421
{ return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
1422
bool zero_pack() const { return 0; }
1425
charset()->cset->fill(charset(),(char*) ptr, field_length,
1426
(has_charset() ? ' ' : 0));
1429
int store(const char *to,uint length,CHARSET_INFO *charset);
1430
int store(longlong nr, bool unsigned_val);
1431
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1432
double val_real(void);
1433
longlong val_int(void);
1434
String *val_str(String*,String *);
1435
my_decimal *val_decimal(my_decimal *);
1436
int cmp(const uchar *,const uchar *);
1437
void sort_string(uchar *buff,uint length);
1438
void sql_type(String &str) const;
1439
virtual uchar *pack(uchar *to, const uchar *from,
1440
uint max_length, bool low_byte_first);
1441
virtual const uchar *unpack(uchar* to, const uchar *from,
1442
uint param_data, bool low_byte_first);
1443
uint pack_length_from_metadata(uint field_metadata)
1444
{ return (field_metadata & 0x00ff); }
1445
uint row_pack_length() { return (field_length + 1); }
1446
int pack_cmp(const uchar *a,const uchar *b,uint key_length,
1447
my_bool insert_or_update);
1448
int pack_cmp(const uchar *b,uint key_length,my_bool insert_or_update);
1449
uint packed_col_length(const uchar *to, uint length);
1450
uint max_packed_col_length(uint max_length);
1451
uint size_of() const { return sizeof(*this); }
1452
enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
1453
bool has_charset(void) const
1454
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1455
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1456
virtual uint get_key_image(uchar *buff,uint length, imagetype type);
1458
int do_save_field_metadata(uchar *first_byte);
1462
class Field_varstring :public Field_longstr {
1465
The maximum space available in a Field_varstring, in bytes. See
1468
static const uint MAX_SIZE;
1469
/* Store number of bytes used to store length (1 or 2) */
1470
uint32 length_bytes;
1471
Field_varstring(uchar *ptr_arg,
1472
uint32 len_arg, uint length_bytes_arg,
1473
uchar *null_ptr_arg, uchar null_bit_arg,
1474
enum utype unireg_check_arg, const char *field_name_arg,
1475
TABLE_SHARE *share, CHARSET_INFO *cs)
1476
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1477
unireg_check_arg, field_name_arg, cs),
1478
length_bytes(length_bytes_arg)
1480
share->varchar_fields++;
1482
Field_varstring(uint32 len_arg,bool maybe_null_arg,
1483
const char *field_name_arg,
1484
TABLE_SHARE *share, CHARSET_INFO *cs)
1485
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1486
NONE, field_name_arg, cs),
1487
length_bytes(len_arg < 256 ? 1 :2)
1489
share->varchar_fields++;
1492
enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
1493
enum ha_base_keytype key_type() const;
1494
uint row_pack_length() { return field_length; }
1495
bool zero_pack() const { return 0; }
1496
int reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
1497
uint32 pack_length() const { return (uint32) field_length+length_bytes; }
1498
uint32 key_length() const { return (uint32) field_length; }
1499
uint32 sort_length() const
1501
return (uint32) field_length + (field_charset == &my_charset_bin ?
1504
int store(const char *to,uint length,CHARSET_INFO *charset);
1505
int store(longlong nr, bool unsigned_val);
1506
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1507
double val_real(void);
1508
longlong val_int(void);
1509
String *val_str(String*,String *);
1510
my_decimal *val_decimal(my_decimal *);
1511
int cmp_max(const uchar *, const uchar *, uint max_length);
1512
int cmp(const uchar *a,const uchar *b)
1514
return cmp_max(a, b, ~0L);
1516
void sort_string(uchar *buff,uint length);
1517
uint get_key_image(uchar *buff,uint length, imagetype type);
1518
void set_key_image(const uchar *buff,uint length);
1519
void sql_type(String &str) const;
1520
virtual uchar *pack(uchar *to, const uchar *from,
1521
uint max_length, bool low_byte_first);
1522
uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first);
1523
uchar *pack_key_from_key_image(uchar* to, const uchar *from,
1524
uint max_length, bool low_byte_first);
1525
virtual const uchar *unpack(uchar* to, const uchar *from,
1526
uint param_data, bool low_byte_first);
1527
const uchar *unpack_key(uchar* to, const uchar *from,
1528
uint max_length, bool low_byte_first);
1529
int pack_cmp(const uchar *a, const uchar *b, uint key_length,
1530
my_bool insert_or_update);
1531
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
1532
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1533
int key_cmp(const uchar *,const uchar*);
1534
int key_cmp(const uchar *str, uint length);
1535
uint packed_col_length(const uchar *to, uint length);
1536
uint max_packed_col_length(uint max_length);
1537
uint32 data_length();
1538
uint32 used_length();
1539
uint size_of() const { return sizeof(*this); }
1540
enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
1541
bool has_charset(void) const
1542
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1543
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1544
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
1545
uchar *new_ptr, uchar *new_null_ptr,
1547
uint is_equal(Create_field *new_field);
1548
void hash(ulong *nr, ulong *nr2);
1550
int do_save_field_metadata(uchar *first_byte);
1554
class Field_blob :public Field_longstr {
1557
String value; // For temporaries
1559
Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1560
enum utype unireg_check_arg, const char *field_name_arg,
1561
TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
1562
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1564
:Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1565
NONE, field_name_arg, cs),
1570
Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1571
CHARSET_INFO *cs, bool set_packlength)
1572
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1573
NONE, field_name_arg, cs)
1579
uint32 l_char_length= len_arg/cs->mbmaxlen;
1580
packlength= l_char_length <= 255 ? 1 :
1581
l_char_length <= 65535 ? 2 :
1582
l_char_length <= 16777215 ? 3 : 4;
1585
Field_blob(uint32 packlength_arg)
1586
:Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
1587
packlength(packlength_arg) {}
1588
enum_field_types type() const { return MYSQL_TYPE_BLOB;}
1589
enum ha_base_keytype key_type() const
1590
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
1591
int store(const char *to,uint length,CHARSET_INFO *charset);
1592
int store(double nr);
1593
int store(longlong nr, bool unsigned_val);
1594
double val_real(void);
1595
longlong val_int(void);
1596
String *val_str(String*,String *);
1597
my_decimal *val_decimal(my_decimal *);
1598
int cmp_max(const uchar *, const uchar *, uint max_length);
1599
int cmp(const uchar *a,const uchar *b)
1600
{ return cmp_max(a, b, ~0L); }
1601
int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
1602
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1603
int key_cmp(const uchar *,const uchar*);
1604
int key_cmp(const uchar *str, uint length);
1605
uint32 key_length() const { return 0; }
1606
void sort_string(uchar *buff,uint length);
1607
uint32 pack_length() const
1608
{ return (uint32) (packlength+table->s->blob_ptr_size); }
1611
Return the packed length without the pointer size added.
1613
This is used to determine the size of the actual data in the row
1616
@returns The length of the raw data itself without the pointer.
1618
uint32 pack_length_no_ptr() const
1619
{ return (uint32) (packlength); }
1620
uint row_pack_length() { return pack_length_no_ptr(); }
1621
uint32 sort_length() const;
1622
virtual uint32 max_data_length() const
1624
return (uint32) (((uint64_t) 1 << (packlength*8)) -1);
1626
int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
1627
void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
1628
#ifndef WORDS_BIGENDIAN
1631
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, bool low_byte_first);
1632
void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
1634
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
1636
inline void store_length(uint32 number)
1638
store_length(ptr, packlength, number);
1642
Return the packed length plus the length of the data.
1644
This is used to determine the size of the data plus the
1645
packed length portion in the row data.
1647
@returns The length in the row plus the size of the data.
1649
uint32 get_packed_size(const uchar *ptr_arg, bool low_byte_first)
1650
{return packlength + get_length(ptr_arg, packlength, low_byte_first);}
1652
inline uint32 get_length(uint row_offset= 0)
1653
{ return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
1654
uint32 get_length(const uchar *ptr, uint packlength, bool low_byte_first);
1655
uint32 get_length(const uchar *ptr_arg)
1656
{ return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
1657
void put_length(uchar *pos, uint32 length);
1658
inline void get_ptr(uchar **str)
1660
memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*));
1662
inline void get_ptr(uchar **str, uint row_offset)
1664
memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*));
1666
inline void set_ptr(uchar *length, uchar *data)
1668
memcpy(ptr,length,packlength);
1669
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
1671
void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
1673
uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
1674
store_length(ptr_ofs, packlength, length);
1675
memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
1677
inline void set_ptr(uint32 length, uchar *data)
1679
set_ptr_offset(0, length, data);
1681
uint get_key_image(uchar *buff,uint length, imagetype type);
1682
void set_key_image(const uchar *buff,uint length);
1683
void sql_type(String &str) const;
1688
if (value.copy((char*) tmp, get_length(), charset()))
1690
Field_blob::reset();
1693
tmp=(uchar*) value.ptr();
1694
memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
1697
virtual uchar *pack(uchar *to, const uchar *from,
1698
uint max_length, bool low_byte_first);
1699
uchar *pack_key(uchar *to, const uchar *from,
1700
uint max_length, bool low_byte_first);
1701
uchar *pack_key_from_key_image(uchar* to, const uchar *from,
1702
uint max_length, bool low_byte_first);
1703
virtual const uchar *unpack(uchar *to, const uchar *from,
1704
uint param_data, bool low_byte_first);
1705
const uchar *unpack_key(uchar* to, const uchar *from,
1706
uint max_length, bool low_byte_first);
1707
int pack_cmp(const uchar *a, const uchar *b, uint key_length,
1708
my_bool insert_or_update);
1709
int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
1710
uint packed_col_length(const uchar *col_ptr, uint length);
1711
uint max_packed_col_length(uint max_length);
1712
void free() { value.free(); }
1713
inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
1714
friend int field_conv(Field *to,Field *from);
1715
uint size_of() const { return sizeof(*this); }
1716
bool has_charset(void) const
1717
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
1718
uint32 max_display_length();
1719
uint is_equal(Create_field *new_field);
1720
inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
1721
inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
1723
int do_save_field_metadata(uchar *first_byte);
1727
class Field_enum :public Field_str {
1732
Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1734
enum utype unireg_check_arg, const char *field_name_arg,
1735
uint packlength_arg,
1736
TYPELIB *typelib_arg,
1737
CHARSET_INFO *charset_arg)
1738
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1739
unireg_check_arg, field_name_arg, charset_arg),
1740
packlength(packlength_arg),typelib(typelib_arg)
1744
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1745
enum_field_types type() const { return MYSQL_TYPE_STRING; }
1746
enum Item_result cmp_type () const { return INT_RESULT; }
1747
enum Item_result cast_to_int_type () const { return INT_RESULT; }
1748
enum ha_base_keytype key_type() const;
1749
int store(const char *to,uint length,CHARSET_INFO *charset);
1750
int store(double nr);
1751
int store(longlong nr, bool unsigned_val);
1752
double val_real(void);
1753
longlong val_int(void);
1754
String *val_str(String*,String *);
1755
int cmp(const uchar *,const uchar *);
1756
void sort_string(uchar *buff,uint length);
1757
uint32 pack_length() const { return (uint32) packlength; }
1758
void store_type(uint64_t value);
1759
void sql_type(String &str) const;
1760
uint size_of() const { return sizeof(*this); }
1761
enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
1762
uint pack_length_from_metadata(uint field_metadata)
1763
{ return (field_metadata & 0x00ff); }
1764
uint row_pack_length() { return pack_length(); }
1765
virtual bool zero_pack() const { return 0; }
1766
bool optimize_range(uint idx, uint part) { return 0; }
1767
bool eq_def(Field *field);
1768
bool has_charset(void) const { return TRUE; }
1769
/* enum and set are sorted as integers */
1770
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
1772
int do_save_field_metadata(uchar *first_byte);
1776
class Field_set :public Field_enum {
1778
Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1780
enum utype unireg_check_arg, const char *field_name_arg,
1781
uint32 packlength_arg,
1782
TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
1783
:Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1784
unireg_check_arg, field_name_arg,
1786
typelib_arg,charset_arg)
1788
flags=(flags & ~ENUM_FLAG) | SET_FLAG;
1790
int store(const char *to,uint length,CHARSET_INFO *charset);
1791
int store(double nr) { return Field_set::store((longlong) nr, FALSE); }
1792
int store(longlong nr, bool unsigned_val);
1794
virtual bool zero_pack() const { return 1; }
1795
String *val_str(String*,String *);
1796
void sql_type(String &str) const;
1797
enum_field_types real_type() const { return MYSQL_TYPE_SET; }
1798
bool has_charset(void) const { return TRUE; }
1804
To use Field_bit::cmp_binary() you need to copy the bits stored in
1805
the beginning of the record (the NULL bytes) to each memory you
1806
want to compare (where the arguments point).
1809
- Field_bit::cmp_binary() is only implemented in the base class
1810
(Field::cmp_binary()).
1811
- Field::cmp_binary() currenly use pack_length() to calculate how
1813
- pack_length() includes size of the bits stored in the NULL bytes
1816
class Field_bit :public Field {
1818
uchar *bit_ptr; // position in record where 'uneven' bits store
1819
uchar bit_ofs; // offset to 'uneven' high bits
1820
uint bit_len; // number of 'uneven' high bits
1822
Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1823
uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
1824
enum utype unireg_check_arg, const char *field_name_arg);
1825
enum_field_types type() const { return MYSQL_TYPE_BIT; }
1826
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
1827
uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
1828
uint32 max_data_length() const { return (field_length + 7) / 8; }
1829
uint32 max_display_length() { return field_length; }
1830
uint size_of() const { return sizeof(*this); }
1831
Item_result result_type () const { return INT_RESULT; }
1832
int reset(void) { bzero(ptr, bytes_in_rec); return 0; }
1833
int store(const char *to, uint length, CHARSET_INFO *charset);
1834
int store(double nr);
1835
int store(longlong nr, bool unsigned_val);
1836
int store_decimal(const my_decimal *);
1837
double val_real(void);
1838
longlong val_int(void);
1839
String *val_str(String*, String *);
1840
virtual bool str_needs_quotes() { return TRUE; }
1841
my_decimal *val_decimal(my_decimal *);
1842
int cmp(const uchar *a, const uchar *b)
1844
DBUG_ASSERT(ptr == a);
1845
return Field_bit::key_cmp(b, bytes_in_rec+test(bit_len));
1847
int cmp_binary_offset(uint row_offset)
1848
{ return cmp_offset(row_offset); }
1849
int cmp_max(const uchar *a, const uchar *b, uint max_length);
1850
int key_cmp(const uchar *a, const uchar *b)
1851
{ return cmp_binary((uchar *) a, (uchar *) b); }
1852
int key_cmp(const uchar *str, uint length);
1853
int cmp_offset(uint row_offset);
1854
void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
1855
{ get_key_image(buff, length, itRAW); }
1856
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
1857
{ Field_bit::store((char *) buff, length, cs); }
1858
uint get_key_image(uchar *buff, uint length, imagetype type);
1859
void set_key_image(const uchar *buff, uint length)
1860
{ Field_bit::store((char*) buff, length, &my_charset_bin); }
1861
void sort_string(uchar *buff, uint length)
1862
{ get_key_image(buff, length, itRAW); }
1863
uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
1864
uint32 pack_length_in_rec() const { return bytes_in_rec; }
1865
uint pack_length_from_metadata(uint field_metadata);
1866
uint row_pack_length()
1867
{ return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); }
1868
int compatible_field_size(uint field_metadata);
1869
void sql_type(String &str) const;
1870
virtual uchar *pack(uchar *to, const uchar *from,
1871
uint max_length, bool low_byte_first);
1872
virtual const uchar *unpack(uchar *to, const uchar *from,
1873
uint param_data, bool low_byte_first);
1874
virtual void set_default();
1876
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
1877
uchar *new_ptr, uchar *new_null_ptr,
1879
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
1881
bit_ptr= bit_ptr_arg;
1882
bit_ofs= bit_ofs_arg;
1884
bool eq(Field *field)
1886
return (Field::eq(field) &&
1887
field->type() == type() &&
1888
bit_ptr == ((Field_bit *)field)->bit_ptr &&
1889
bit_ofs == ((Field_bit *)field)->bit_ofs);
1891
uint is_equal(Create_field *new_field);
1892
void move_field_offset(my_ptrdiff_t ptr_diff)
1894
Field::move_field_offset(ptr_diff);
1895
bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
1897
void hash(ulong *nr, ulong *nr2);
1900
virtual size_t do_last_null_byte() const;
1901
int do_save_field_metadata(uchar *first_byte);
1906
BIT field represented as chars for non-MyISAM tables.
1908
@todo The inheritance relationship is backwards since Field_bit is
1909
an extended version of Field_bit_as_char and not the other way
1910
around. Hence, we should refactor it to fix the hierarchy order.
1912
class Field_bit_as_char: public Field_bit {
1914
Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1916
enum utype unireg_check_arg, const char *field_name_arg);
1917
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1918
uint size_of() const { return sizeof(*this); }
1919
int store(const char *to, uint length, CHARSET_INFO *charset);
1920
int store(double nr) { return Field_bit::store(nr); }
1921
int store(longlong nr, bool unsigned_val)
1922
{ return Field_bit::store(nr, unsigned_val); }
1923
void sql_type(String &str) const;
604
1928
Create field class for CREATE TABLE