~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.h

MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
  /* Store functions returns 1 on overflow and -1 on fatal error */
104
104
  virtual int  store(const char *to, uint length,CHARSET_INFO *cs)=0;
105
105
  virtual int  store(double nr)=0;
106
 
  virtual int  store(longlong nr, bool unsigned_val)=0;
 
106
  virtual int  store(int64_t nr, bool unsigned_val)=0;
107
107
  virtual int  store_decimal(const my_decimal *d)=0;
108
108
  virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
109
109
  int store(const char *to, uint length, CHARSET_INFO *cs,
110
110
            enum_check_fields check_level);
111
111
  virtual double val_real(void)=0;
112
 
  virtual longlong val_int(void)=0;
 
112
  virtual int64_t val_int(void)=0;
113
113
  virtual my_decimal *val_decimal(my_decimal *);
114
114
  inline String *val_str(String *str) { return val_str(str, str); }
115
115
  /*
292
292
  virtual bool optimize_range(uint idx, uint part);
293
293
  /*
294
294
    This should be true for fields which, when compared with constant
295
 
    items, can be casted to longlong. In this case we will at 'fix_fields'
296
 
    stage cast the constant items to longlongs and at the execution stage
 
295
    items, can be casted to int64_t. In this case we will at 'fix_fields'
 
296
    stage cast the constant items to int64_ts and at the execution stage
297
297
    use field->val_int() for comparison.  Used to optimize clauses like
298
298
    'a_column BETWEEN date_const, date_const'.
299
299
  */
300
 
  virtual bool can_be_compared_as_longlong() const { return false; }
 
300
  virtual bool can_be_compared_as_int64_t() const { return false; }
301
301
  virtual void free() {}
302
302
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
303
303
                           bool keep_type);
358
358
  }
359
359
  virtual void set_key_image(const uchar *buff,uint length)
360
360
    { set_image(buff,length, &my_charset_bin); }
361
 
  inline longlong val_int_offset(uint row_offset)
 
361
  inline int64_t val_int_offset(uint row_offset)
362
362
    {
363
363
      ptr+=row_offset;
364
 
      longlong tmp=val_int();
 
364
      int64_t tmp=val_int();
365
365
      ptr-=row_offset;
366
366
      return tmp;
367
367
    }
368
 
  inline longlong val_int(const uchar *new_ptr)
 
368
  inline int64_t val_int(const uchar *new_ptr)
369
369
  {
370
370
    uchar *old_ptr= ptr;
371
 
    longlong return_value;
 
371
    int64_t return_value;
372
372
    ptr= (uchar*) new_ptr;
373
373
    return_value= val_int();
374
374
    ptr= old_ptr;
458
458
                            const char *str, uint str_len,
459
459
                            timestamp_type ts_type, int cuted_increment);
460
460
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
461
 
                            longlong nr, timestamp_type ts_type,
 
461
                            int64_t nr, timestamp_type ts_type,
462
462
                            int cuted_increment);
463
463
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, 
464
464
                            double nr, timestamp_type ts_type);
477
477
  virtual uint32 max_display_length()= 0;
478
478
 
479
479
  virtual uint is_equal(Create_field *new_field);
480
 
  /* convert decimal to longlong with overflow check */
481
 
  longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
 
480
  /* convert decimal to int64_t with overflow check */
 
481
  int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
482
482
                                    int *err);
483
483
  /* The max. number of characters */
484
484
  inline uint32 char_length() const
561
561
  int check_int(CHARSET_INFO *cs, const char *str, int length,
562
562
                const char *int_end, int error);
563
563
  bool get_int(CHARSET_INFO *cs, const char *from, uint len, 
564
 
               longlong *rnd, uint64_t unsigned_max, 
565
 
               longlong signed_min, longlong signed_max);
 
564
               int64_t *rnd, uint64_t unsigned_max, 
 
565
               int64_t signed_min, int64_t signed_max);
566
566
};
567
567
 
568
568
 
577
577
  Item_result result_type () const { return STRING_RESULT; }
578
578
  uint decimals() const { return NOT_FIXED_DEC; }
579
579
  int  store(double nr);
580
 
  int  store(longlong nr, bool unsigned_val)=0;
 
580
  int  store(int64_t nr, bool unsigned_val)=0;
581
581
  int  store_decimal(const my_decimal *);
582
582
  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
583
583
  uint size_of() const { return sizeof(*this); }
668
668
  void set_value_on_overflow(my_decimal *decimal_value, bool sign);
669
669
  int  store(const char *to, uint length, CHARSET_INFO *charset);
670
670
  int  store(double nr);
671
 
  int  store(longlong nr, bool unsigned_val);
 
671
  int  store(int64_t nr, bool unsigned_val);
672
672
  int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
673
673
  int  store_decimal(const my_decimal *);
674
674
  double val_real(void);
675
 
  longlong val_int(void);
 
675
  int64_t val_int(void);
676
676
  my_decimal *val_decimal(my_decimal *);
677
677
  String *val_str(String*, String *);
678
678
  int cmp(const uchar *, const uchar *);
707
707
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
708
708
  int store(const char *to,uint length,CHARSET_INFO *charset);
709
709
  int store(double nr);
710
 
  int store(longlong nr, bool unsigned_val);
 
710
  int store(int64_t nr, bool unsigned_val);
711
711
  int reset(void) { ptr[0]=0; return 0; }
712
712
  double val_real(void);
713
 
  longlong val_int(void);
 
713
  int64_t val_int(void);
714
714
  String *val_str(String*,String *);
715
715
  bool send_binary(Protocol *protocol);
716
716
  int cmp(const uchar *,const uchar *);
758
758
    { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
759
759
  int store(const char *to,uint length,CHARSET_INFO *charset);
760
760
  int store(double nr);
761
 
  int store(longlong nr, bool unsigned_val);
 
761
  int store(int64_t nr, bool unsigned_val);
762
762
  int reset(void) { ptr[0]=ptr[1]=0; return 0; }
763
763
  double val_real(void);
764
 
  longlong val_int(void);
 
764
  int64_t val_int(void);
765
765
  String *val_str(String*,String *);
766
766
  bool send_binary(Protocol *protocol);
767
767
  int cmp(const uchar *,const uchar *);
834
834
    { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
835
835
  int store(const char *to,uint length,CHARSET_INFO *charset);
836
836
  int store(double nr);
837
 
  int store(longlong nr, bool unsigned_val);
 
837
  int store(int64_t nr, bool unsigned_val);
838
838
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
839
839
  double val_real(void);
840
 
  longlong val_int(void);
 
840
  int64_t val_int(void);
841
841
  bool send_binary(Protocol *protocol);
842
842
  String *val_str(String*,String *);
843
843
  int cmp(const uchar *,const uchar *);
889
889
};
890
890
 
891
891
 
892
 
class Field_longlong :public Field_num {
 
892
class Field_int64_t :public Field_num {
893
893
public:
894
 
  Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
894
  Field_int64_t(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
895
895
              uchar null_bit_arg,
896
896
              enum utype unireg_check_arg, const char *field_name_arg,
897
897
              bool zero_arg, bool unsigned_arg)
899
899
               unireg_check_arg, field_name_arg,
900
900
               0, zero_arg,unsigned_arg)
901
901
    {}
902
 
  Field_longlong(uint32 len_arg,bool maybe_null_arg,
 
902
  Field_int64_t(uint32 len_arg,bool maybe_null_arg,
903
903
                 const char *field_name_arg,
904
904
                  bool unsigned_arg)
905
905
    :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
911
911
    { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
912
912
  int store(const char *to,uint length,CHARSET_INFO *charset);
913
913
  int store(double nr);
914
 
  int store(longlong nr, bool unsigned_val);
 
914
  int store(int64_t nr, bool unsigned_val);
915
915
  int reset(void)
916
916
  {
917
917
    ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
918
918
    return 0;
919
919
  }
920
920
  double val_real(void);
921
 
  longlong val_int(void);
 
921
  int64_t val_int(void);
922
922
  String *val_str(String*,String *);
923
923
  bool send_binary(Protocol *protocol);
924
924
  int cmp(const uchar *,const uchar *);
925
925
  void sort_string(uchar *buff,uint length);
926
926
  uint32 pack_length() const { return 8; }
927
927
  void sql_type(String &str) const;
928
 
  bool can_be_compared_as_longlong() const { return true; }
 
928
  bool can_be_compared_as_int64_t() const { return true; }
929
929
  uint32 max_display_length() { return 20; }
930
930
  virtual uchar *pack(uchar* to, const uchar *from,
931
931
                      uint max_length __attribute__((__unused__)),
932
932
                      bool low_byte_first __attribute__((__unused__)))
933
933
  {
934
 
    int64 val;
 
934
    int64_t val;
935
935
#ifdef WORDS_BIGENDIAN
936
936
    if (table->s->db_low_byte_first)
937
937
      val = sint8korr(from);
938
938
    else
939
939
#endif
940
 
      longlongget(val, from);
 
940
      int64_tget(val, from);
941
941
 
942
942
#ifdef WORDS_BIGENDIAN
943
943
    if (low_byte_first)
944
944
      int8store(to, val);
945
945
    else
946
946
#endif
947
 
      longlongstore(to, val);
 
947
      int64_tstore(to, val);
948
948
    return to + sizeof(val);
949
949
  }
950
950
 
952
952
                              uint param_data __attribute__((__unused__)),
953
953
                              bool low_byte_first __attribute__((__unused__)))
954
954
  {
955
 
    int64 val;
 
955
    int64_t val;
956
956
#ifdef WORDS_BIGENDIAN
957
957
    if (low_byte_first)
958
958
      val = sint8korr(from);
959
959
    else
960
960
#endif
961
 
      longlongget(val, from);
 
961
      int64_tget(val, from);
962
962
 
963
963
#ifdef WORDS_BIGENDIAN
964
964
    if (table->s->db_low_byte_first)
965
965
      int8store(to, val);
966
966
    else
967
967
#endif
968
 
      longlongstore(to, val);
 
968
      int64_tstore(to, val);
969
969
    return from + sizeof(val);
970
970
  }
971
971
};
972
972
 
973
 
class Field_float :public Field_real {
974
 
public:
975
 
  Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
976
 
              uchar null_bit_arg,
977
 
              enum utype unireg_check_arg, const char *field_name_arg,
978
 
              uint8 dec_arg,bool zero_arg,bool unsigned_arg)
979
 
    :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
980
 
                unireg_check_arg, field_name_arg,
981
 
                dec_arg, zero_arg, unsigned_arg)
982
 
    {}
983
 
  Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
984
 
              uint8 dec_arg)
985
 
    :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
986
 
                NONE, field_name_arg, dec_arg, 0, 0)
987
 
    {}
988
 
  enum_field_types type() const { return MYSQL_TYPE_FLOAT;}
989
 
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
990
 
  int store(const char *to,uint length,CHARSET_INFO *charset);
991
 
  int store(double nr);
992
 
  int store(longlong nr, bool unsigned_val);
993
 
  int reset(void) { bzero(ptr,sizeof(float)); return 0; }
994
 
  double val_real(void);
995
 
  longlong val_int(void);
996
 
  String *val_str(String*,String *);
997
 
  bool send_binary(Protocol *protocol);
998
 
  int cmp(const uchar *,const uchar *);
999
 
  void sort_string(uchar *buff,uint length);
1000
 
  uint32 pack_length() const { return sizeof(float); }
1001
 
  uint row_pack_length() { return pack_length(); }
1002
 
  void sql_type(String &str) const;
1003
 
private:
1004
 
  int do_save_field_metadata(uchar *first_byte);
1005
 
};
1006
 
 
1007
 
 
1008
973
class Field_double :public Field_real {
1009
974
public:
1010
975
  Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1029
994
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
1030
995
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1031
996
  int  store(double nr);
1032
 
  int  store(longlong nr, bool unsigned_val);
 
997
  int  store(int64_t nr, bool unsigned_val);
1033
998
  int reset(void) { bzero(ptr,sizeof(double)); return 0; }
1034
999
  double val_real(void);
1035
 
  longlong val_int(void);
 
1000
  int64_t val_int(void);
1036
1001
  String *val_str(String*,String *);
1037
1002
  bool send_binary(Protocol *protocol);
1038
1003
  int cmp(const uchar *,const uchar *);
1063
1028
  { null[0]=1; return 0; }
1064
1029
  int store(double nr __attribute__((__unused__)))
1065
1030
  { null[0]=1; return 0; }
1066
 
  int store(longlong nr __attribute__((__unused__)),
 
1031
  int store(int64_t nr __attribute__((__unused__)),
1067
1032
            bool unsigned_val __attribute__((__unused__)))
1068
1033
  { null[0]=1; return 0; }
1069
1034
  int store_decimal(const my_decimal *d __attribute__((__unused__)))
1072
1037
  { return 0; }
1073
1038
  double val_real(void)
1074
1039
  { return 0.0;}
1075
 
  longlong val_int(void)
 
1040
  int64_t val_int(void)
1076
1041
  { return 0;}
1077
1042
  my_decimal *val_decimal(my_decimal *) { return 0; }
1078
1043
  String *val_str(String *value __attribute__((__unused__)),
1102
1067
  enum Item_result cmp_type () const { return INT_RESULT; }
1103
1068
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1104
1069
  int  store(double nr);
1105
 
  int  store(longlong nr, bool unsigned_val);
 
1070
  int  store(int64_t nr, bool unsigned_val);
1106
1071
  int  reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
1107
1072
  double val_real(void);
1108
 
  longlong val_int(void);
 
1073
  int64_t val_int(void);
1109
1074
  String *val_str(String*,String *);
1110
1075
  bool send_binary(Protocol *protocol);
1111
1076
  int cmp(const uchar *,const uchar *);
1112
1077
  void sort_string(uchar *buff,uint length);
1113
1078
  uint32 pack_length() const { return 4; }
1114
1079
  void sql_type(String &str) const;
1115
 
  bool can_be_compared_as_longlong() const { return true; }
 
1080
  bool can_be_compared_as_int64_t() const { return true; }
1116
1081
  bool zero_pack() const { return 0; }
1117
1082
  void set_time();
1118
1083
  virtual void set_default()
1164
1129
  enum_field_types type() const { return MYSQL_TYPE_YEAR;}
1165
1130
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1166
1131
  int  store(double nr);
1167
 
  int  store(longlong nr, bool unsigned_val);
 
1132
  int  store(int64_t nr, bool unsigned_val);
1168
1133
  double val_real(void);
1169
 
  longlong val_int(void);
 
1134
  int64_t val_int(void);
1170
1135
  String *val_str(String*,String *);
1171
1136
  bool send_binary(Protocol *protocol);
1172
1137
  void sql_type(String &str) const;
1173
 
  bool can_be_compared_as_longlong() const { return true; }
 
1138
  bool can_be_compared_as_int64_t() const { return true; }
1174
1139
};
1175
1140
 
1176
1141
 
1192
1157
  enum Item_result cmp_type () const { return INT_RESULT; }
1193
1158
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1194
1159
  int  store(double nr);
1195
 
  int  store(longlong nr, bool unsigned_val);
 
1160
  int  store(int64_t nr, bool unsigned_val);
1196
1161
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
1197
1162
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1198
1163
  double val_real(void);
1199
 
  longlong val_int(void);
 
1164
  int64_t val_int(void);
1200
1165
  String *val_str(String*,String *);
1201
1166
  bool send_binary(Protocol *protocol);
1202
1167
  int cmp(const uchar *,const uchar *);
1203
1168
  void sort_string(uchar *buff,uint length);
1204
1169
  uint32 pack_length() const { return 3; }
1205
1170
  void sql_type(String &str) const;
1206
 
  bool can_be_compared_as_longlong() const { return true; }
 
1171
  bool can_be_compared_as_int64_t() const { return true; }
1207
1172
  bool zero_pack() const { return 1; }
1208
1173
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1209
1174
  bool get_time(MYSQL_TIME *ltime);
1228
1193
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
1229
1194
  int store(const char *to,uint length,CHARSET_INFO *charset);
1230
1195
  int store(double nr);
1231
 
  int store(longlong nr, bool unsigned_val);
 
1196
  int store(int64_t nr, bool unsigned_val);
1232
1197
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
1233
1198
  double val_real(void);
1234
 
  longlong val_int(void);
 
1199
  int64_t val_int(void);
1235
1200
  String *val_str(String*,String *);
1236
1201
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
1237
1202
  bool send_binary(Protocol *protocol);
1240
1205
  void sort_string(uchar *buff,uint length);
1241
1206
  uint32 pack_length() const { return 3; }
1242
1207
  void sql_type(String &str) const;
1243
 
  bool can_be_compared_as_longlong() const { return true; }
 
1208
  bool can_be_compared_as_int64_t() const { return true; }
1244
1209
  bool zero_pack() const { return 1; }
1245
1210
};
1246
1211
 
1263
1228
  uint decimals() const { return DATETIME_DEC; }
1264
1229
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1265
1230
  int  store(double nr);
1266
 
  int  store(longlong nr, bool unsigned_val);
 
1231
  int  store(int64_t nr, bool unsigned_val);
1267
1232
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
1268
1233
  int reset(void)
1269
1234
  {
1271
1236
    return 0;
1272
1237
  }
1273
1238
  double val_real(void);
1274
 
  longlong val_int(void);
 
1239
  int64_t val_int(void);
1275
1240
  String *val_str(String*,String *);
1276
1241
  bool send_binary(Protocol *protocol);
1277
1242
  int cmp(const uchar *,const uchar *);
1278
1243
  void sort_string(uchar *buff,uint length);
1279
1244
  uint32 pack_length() const { return 8; }
1280
1245
  void sql_type(String &str) const;
1281
 
  bool can_be_compared_as_longlong() const { return true; }
 
1246
  bool can_be_compared_as_int64_t() const { return true; }
1282
1247
  bool zero_pack() const { return 1; }
1283
1248
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1284
1249
  bool get_time(MYSQL_TIME *ltime);
1315
1280
    return 0;
1316
1281
  }
1317
1282
  int store(const char *to,uint length,CHARSET_INFO *charset);
1318
 
  int store(longlong nr, bool unsigned_val);
 
1283
  int store(int64_t nr, bool unsigned_val);
1319
1284
  int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1320
1285
  double val_real(void);
1321
 
  longlong val_int(void);
 
1286
  int64_t val_int(void);
1322
1287
  String *val_str(String*,String *);
1323
1288
  my_decimal *val_decimal(my_decimal *);
1324
1289
  int cmp(const uchar *,const uchar *);
1390
1355
                                    length_bytes : 0);
1391
1356
  }
1392
1357
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1393
 
  int  store(longlong nr, bool unsigned_val);
 
1358
  int  store(int64_t nr, bool unsigned_val);
1394
1359
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
1395
1360
  double val_real(void);
1396
 
  longlong val_int(void);
 
1361
  int64_t val_int(void);
1397
1362
  String *val_str(String*,String *);
1398
1363
  my_decimal *val_decimal(my_decimal *);
1399
1364
  int cmp_max(const uchar *, const uchar *, uint max_length);
1478
1443
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
1479
1444
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1480
1445
  int  store(double nr);
1481
 
  int  store(longlong nr, bool unsigned_val);
 
1446
  int  store(int64_t nr, bool unsigned_val);
1482
1447
  double val_real(void);
1483
 
  longlong val_int(void);
 
1448
  int64_t val_int(void);
1484
1449
  String *val_str(String*,String *);
1485
1450
  my_decimal *val_decimal(my_decimal *);
1486
1451
  int cmp_max(const uchar *, const uchar *, uint max_length);
1636
1601
  enum ha_base_keytype key_type() const;
1637
1602
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1638
1603
  int  store(double nr);
1639
 
  int  store(longlong nr, bool unsigned_val);
 
1604
  int  store(int64_t nr, bool unsigned_val);
1640
1605
  double val_real(void);
1641
 
  longlong val_int(void);
 
1606
  int64_t val_int(void);
1642
1607
  String *val_str(String*,String *);
1643
1608
  int cmp(const uchar *,const uchar *);
1644
1609
  void sort_string(uchar *buff,uint length);
1678
1643
      flags=(flags & ~ENUM_FLAG) | SET_FLAG;
1679
1644
    }
1680
1645
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1681
 
  int  store(double nr) { return Field_set::store((longlong) nr, false); }
1682
 
  int  store(longlong nr, bool unsigned_val);
 
1646
  int  store(double nr) { return Field_set::store((int64_t) nr, false); }
 
1647
  int  store(int64_t nr, bool unsigned_val);
1683
1648
 
1684
1649
  virtual bool zero_pack() const { return 1; }
1685
1650
  String *val_str(String*,String *);