Commit 497ee338 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-21497 Make Field_time, Field_datetime, Field_timestamp abstract

- Making classes Field_time, Field_datetime, Field_timestamp abstract
- Adding instantiable Field_time0, Field_datetime0, Field_timestamp0 classes
- Removing redundant cast in field_conv.cc, item_timefunc.cc, sp.cc in calls for set_time() and get_timestamp()
- Replacing store_TIME() to store_timestamp() in log.cc and removing redundant cast
parent cc3135cf
...@@ -5026,7 +5026,7 @@ int Field_timestamp::save_in_field(Field *to) ...@@ -5026,7 +5026,7 @@ int Field_timestamp::save_in_field(Field *to)
return to->store_timestamp_dec(Timeval(ts, sec_part), decimals()); return to->store_timestamp_dec(Timeval(ts, sec_part), decimals());
} }
my_time_t Field_timestamp::get_timestamp(const uchar *pos, my_time_t Field_timestamp0::get_timestamp(const uchar *pos,
ulong *sec_part) const ulong *sec_part) const
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
...@@ -5035,7 +5035,7 @@ my_time_t Field_timestamp::get_timestamp(const uchar *pos, ...@@ -5035,7 +5035,7 @@ my_time_t Field_timestamp::get_timestamp(const uchar *pos,
} }
bool Field_timestamp::val_native(Native *to) bool Field_timestamp0::val_native(Native *to)
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
my_time_t sec= (my_time_t) sint4korr(ptr); my_time_t sec= (my_time_t) sint4korr(ptr);
...@@ -5200,12 +5200,6 @@ int Field_timestamp::store_native(const Native &value) ...@@ -5200,12 +5200,6 @@ int Field_timestamp::store_native(const Native &value)
} }
double Field_timestamp::val_real(void)
{
return (double) Field_timestamp::val_int();
}
longlong Field_timestamp::val_int(void) longlong Field_timestamp::val_int(void)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
...@@ -5309,15 +5303,15 @@ bool Field_timestamp::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) ...@@ -5309,15 +5303,15 @@ bool Field_timestamp::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate)
} }
bool Field_timestamp::send_binary(Protocol *protocol) bool Field_timestamp0::send_binary(Protocol *protocol)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
Field_timestamp::get_date(&ltime, date_mode_t(0)); Field_timestamp0::get_date(&ltime, date_mode_t(0));
return protocol->store(&ltime, 0); return protocol->store(&ltime, 0);
} }
int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr) const int Field_timestamp0::cmp(const uchar *a_ptr, const uchar *b_ptr) const
{ {
int32 a,b; int32 a,b;
a=sint4korr(a_ptr); a=sint4korr(a_ptr);
...@@ -5326,7 +5320,7 @@ int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr) const ...@@ -5326,7 +5320,7 @@ int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr) const
} }
void Field_timestamp::sort_string(uchar *to,uint length __attribute__((unused))) void Field_timestamp0::sort_string(uchar *to,uint length __attribute__((unused)))
{ {
to[0] = ptr[3]; to[0] = ptr[3];
to[1] = ptr[2]; to[1] = ptr[2];
...@@ -5348,7 +5342,7 @@ void Field_timestamp::sql_type(String &res) const ...@@ -5348,7 +5342,7 @@ void Field_timestamp::sql_type(String &res) const
} }
int Field_timestamp::set_time() int Field_timestamp0::set_time()
{ {
set_notnull(); set_notnull();
store_TIMESTAMP(Timestamp(get_thd()->query_start(), 0)); store_TIMESTAMP(Timestamp(get_thd()->query_start(), 0));
...@@ -5808,7 +5802,7 @@ int Field_time::store_TIME_with_warning(const Time *t, ...@@ -5808,7 +5802,7 @@ int Field_time::store_TIME_with_warning(const Time *t,
} }
void Field_time::store_TIME(const MYSQL_TIME *ltime) void Field_time0::store_TIME(const MYSQL_TIME *ltime)
{ {
DBUG_ASSERT(ltime->year == 0); DBUG_ASSERT(ltime->year == 0);
DBUG_ASSERT(ltime->month == 0); DBUG_ASSERT(ltime->month == 0);
...@@ -5896,14 +5890,14 @@ Field *Field_time::new_key_field(MEM_ROOT *root, TABLE *new_table, ...@@ -5896,14 +5890,14 @@ Field *Field_time::new_key_field(MEM_ROOT *root, TABLE *new_table,
} }
double Field_time::val_real(void) double Field_time0::val_real(void)
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
uint32 j= (uint32) uint3korr(ptr); uint32 j= (uint32) uint3korr(ptr);
return (double) j; return (double) j;
} }
longlong Field_time::val_int(void) longlong Field_time0::val_int(void)
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
return (longlong) sint3korr(ptr); return (longlong) sint3korr(ptr);
...@@ -5952,7 +5946,7 @@ bool Field_time::check_zero_in_date_with_warn(date_mode_t fuzzydate) ...@@ -5952,7 +5946,7 @@ bool Field_time::check_zero_in_date_with_warn(date_mode_t fuzzydate)
DATE_FORMAT(time, "%l.%i %p") DATE_FORMAT(time, "%l.%i %p")
*/ */
bool Field_time::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) bool Field_time0::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate)
{ {
if (check_zero_in_date_with_warn(fuzzydate)) if (check_zero_in_date_with_warn(fuzzydate))
return true; return true;
...@@ -5982,7 +5976,7 @@ bool Field_time::send_binary(Protocol *protocol) ...@@ -5982,7 +5976,7 @@ bool Field_time::send_binary(Protocol *protocol)
} }
int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr) const int Field_time0::cmp(const uchar *a_ptr, const uchar *b_ptr) const
{ {
int32 a,b; int32 a,b;
a=(int32) sint3korr(a_ptr); a=(int32) sint3korr(a_ptr);
...@@ -5990,7 +5984,7 @@ int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr) const ...@@ -5990,7 +5984,7 @@ int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr) const
return (a < b) ? -1 : (a > b) ? 1 : 0; return (a < b) ? -1 : (a > b) ? 1 : 0;
} }
void Field_time::sort_string(uchar *to,uint length __attribute__((unused))) void Field_time0::sort_string(uchar *to,uint length __attribute__((unused)))
{ {
to[0] = (uchar) (ptr[2] ^ 128); to[0] = (uchar) (ptr[2] ^ 128);
to[1] = ptr[1]; to[1] = ptr[1];
...@@ -6695,7 +6689,7 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, ...@@ -6695,7 +6689,7 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx,
** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int. ** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
****************************************************************************/ ****************************************************************************/
void Field_datetime::store_TIME(const MYSQL_TIME *ltime) void Field_datetime0::store_TIME(const MYSQL_TIME *ltime)
{ {
ulonglong tmp= TIME_to_ulonglong_datetime(ltime); ulonglong tmp= TIME_to_ulonglong_datetime(ltime);
int8store(ptr,tmp); int8store(ptr,tmp);
...@@ -6710,20 +6704,15 @@ Field_datetime::conversion_depends_on_sql_mode(THD *thd, Item *expr) const ...@@ -6710,20 +6704,15 @@ Field_datetime::conversion_depends_on_sql_mode(THD *thd, Item *expr) const
} }
bool Field_datetime::send_binary(Protocol *protocol) bool Field_datetime0::send_binary(Protocol *protocol)
{ {
MYSQL_TIME tm; MYSQL_TIME tm;
Field_datetime::get_date(&tm, date_mode_t(0)); Field_datetime0::get_date(&tm, date_mode_t(0));
return protocol->store(&tm, 0); return protocol->store(&tm, 0);
} }
double Field_datetime::val_real(void) longlong Field_datetime0::val_int(void)
{
return (double) Field_datetime::val_int();
}
longlong Field_datetime::val_int(void)
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
longlong j; longlong j;
...@@ -6732,7 +6721,7 @@ longlong Field_datetime::val_int(void) ...@@ -6732,7 +6721,7 @@ longlong Field_datetime::val_int(void)
} }
String *Field_datetime::val_str(String *val_buffer, String *Field_datetime0::val_str(String *val_buffer,
String *val_ptr __attribute__((unused))) String *val_ptr __attribute__((unused)))
{ {
val_buffer->alloc(field_length); val_buffer->alloc(field_length);
...@@ -6744,7 +6733,7 @@ String *Field_datetime::val_str(String *val_buffer, ...@@ -6744,7 +6733,7 @@ String *Field_datetime::val_str(String *val_buffer,
char *pos; char *pos;
int part3; int part3;
tmp= Field_datetime::val_int(); tmp= Field_datetime0::val_int();
/* /*
Avoid problem with slow longlong arithmetic and sprintf Avoid problem with slow longlong arithmetic and sprintf
...@@ -6778,7 +6767,7 @@ String *Field_datetime::val_str(String *val_buffer, ...@@ -6778,7 +6767,7 @@ String *Field_datetime::val_str(String *val_buffer,
return val_buffer; return val_buffer;
} }
bool Field_datetime::get_TIME(MYSQL_TIME *ltime, const uchar *pos, bool Field_datetime0::get_TIME(MYSQL_TIME *ltime, const uchar *pos,
date_mode_t fuzzydate) const date_mode_t fuzzydate) const
{ {
DBUG_ASSERT(marked_for_read()); DBUG_ASSERT(marked_for_read());
...@@ -6800,7 +6789,7 @@ bool Field_datetime::get_TIME(MYSQL_TIME *ltime, const uchar *pos, ...@@ -6800,7 +6789,7 @@ bool Field_datetime::get_TIME(MYSQL_TIME *ltime, const uchar *pos,
} }
int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) const int Field_datetime0::cmp(const uchar *a_ptr, const uchar *b_ptr) const
{ {
longlong a,b; longlong a,b;
a=sint8korr(a_ptr); a=sint8korr(a_ptr);
...@@ -6809,7 +6798,7 @@ int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) const ...@@ -6809,7 +6798,7 @@ int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) const
((ulonglong) a > (ulonglong) b) ? 1 : 0; ((ulonglong) a > (ulonglong) b) ? 1 : 0;
} }
void Field_datetime::sort_string(uchar *to,uint length __attribute__((unused))) void Field_datetime0::sort_string(uchar *to,uint length __attribute__((unused)))
{ {
to[0] = ptr[7]; to[0] = ptr[7];
to[1] = ptr[6]; to[1] = ptr[6];
......
...@@ -3040,10 +3040,7 @@ class Field_timestamp :public Field_temporal { ...@@ -3040,10 +3040,7 @@ class Field_timestamp :public Field_temporal {
protected: protected:
int store_TIME_with_warning(THD *, const Datetime *, int store_TIME_with_warning(THD *, const Datetime *,
const ErrConv *, int warn); const ErrConv *, int warn);
virtual void store_TIMEVAL(const timeval &tv) virtual void store_TIMEVAL(const timeval &tv)= 0;
{
int4store(ptr, tv.tv_sec);
}
void store_TIMESTAMP(const Timestamp &ts) void store_TIMESTAMP(const Timestamp &ts)
{ {
store_TIMEVAL(ts.tv()); store_TIMEVAL(ts.tv());
...@@ -3057,8 +3054,6 @@ class Field_timestamp :public Field_temporal { ...@@ -3057,8 +3054,6 @@ class Field_timestamp :public Field_temporal {
TABLE_SHARE *share); TABLE_SHARE *share);
const Type_handler *type_handler() const override const Type_handler *type_handler() const override
{ return &type_handler_timestamp; } { return &type_handler_timestamp; }
enum ha_base_keytype key_type() const override
{ return HA_KEYTYPE_ULONG_INT; }
enum_conv_type rpl_conv_type_from(const Conv_source &source, enum_conv_type rpl_conv_type_from(const Conv_source &source,
const Relay_log_info *rli, const Relay_log_info *rli,
const Conv_param &param) const override; const Conv_param &param) const override;
...@@ -3071,22 +3066,10 @@ class Field_timestamp :public Field_temporal { ...@@ -3071,22 +3066,10 @@ class Field_timestamp :public Field_temporal {
int store_decimal(const my_decimal *) override; int store_decimal(const my_decimal *) override;
int store_timestamp_dec(const timeval &ts, uint dec) override; int store_timestamp_dec(const timeval &ts, uint dec) override;
int save_in_field(Field *to) override; int save_in_field(Field *to) override;
double val_real() override;
longlong val_int() override; longlong val_int() override;
String *val_str(String *, String *) override; String *val_str(String *, String *) override;
bool send_binary(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 4; }
void sql_type(String &str) const override; void sql_type(String &str) const override;
bool zero_pack() const override { return false; } bool zero_pack() const override { return false; }
int set_time() override;
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const override;
my_time_t get_timestamp(ulong *sec_part) const
{
return get_timestamp(ptr, sec_part);
}
/* /*
This method is used by storage/perfschema and This method is used by storage/perfschema and
Item_func_now_local::save_in_field(). Item_func_now_local::save_in_field().
...@@ -3099,6 +3082,45 @@ class Field_timestamp :public Field_temporal { ...@@ -3099,6 +3082,45 @@ class Field_timestamp :public Field_temporal {
} }
bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override; bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override;
int store_native(const Native &value) override; int store_native(const Native &value) override;
bool validate_value_in_record(THD *thd, const uchar *record) const override;
Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item)
override
{
return get_equal_const_item_datetime(thd, ctx, const_item);
}
bool load_data_set_null(THD *thd) override;
bool load_data_set_no_data(THD *thd, bool fixed_format) override;
};
class Field_timestamp0 :public Field_timestamp
{
void store_TIMEVAL(const timeval &tv) override
{
int4store(ptr, tv.tv_sec);
}
public:
Field_timestamp0(uchar *ptr_arg, uint32 len_arg,
uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg,
const LEX_CSTRING *field_name_arg,
TABLE_SHARE *share)
:Field_timestamp(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, share)
{ }
enum ha_base_keytype key_type() const override
{ return HA_KEYTYPE_ULONG_INT; }
double val_real() override
{
return (double) Field_timestamp0::val_int();
}
bool send_binary(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 4; }
int set_time() override;
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const override;
bool val_native(Native *to) override; bool val_native(Native *to) override;
uchar *pack(uchar *to, const uchar *from, uint) override uchar *pack(uchar *to, const uchar *from, uint) override
{ {
...@@ -3109,14 +3131,6 @@ class Field_timestamp :public Field_temporal { ...@@ -3109,14 +3131,6 @@ class Field_timestamp :public Field_temporal {
{ {
return unpack_int32(to, from, from_end); return unpack_int32(to, from, from_end);
} }
bool validate_value_in_record(THD *thd, const uchar *record) const override;
Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item)
override
{
return get_equal_const_item_datetime(thd, ctx, const_item);
}
bool load_data_set_null(THD *thd) override;
bool load_data_set_no_data(THD *thd, bool fixed_format) override;
uint size_of() const override { return sizeof *this; } uint size_of() const override { return sizeof *this; }
}; };
...@@ -3226,10 +3240,6 @@ class Field_timestampf :public Field_timestamp_with_dec { ...@@ -3226,10 +3240,6 @@ class Field_timestampf :public Field_timestamp_with_dec {
void set_max() override; void set_max() override;
bool is_max() override; bool is_max() override;
my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const override; my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const override;
my_time_t get_timestamp(ulong *sec_part) const
{
return get_timestamp(ptr, sec_part);
}
bool val_native(Native *to) override; bool val_native(Native *to) override;
uint size_of() const override { return sizeof *this; } uint size_of() const override { return sizeof *this; }
Binlog_type_info binlog_type_info() const override; Binlog_type_info binlog_type_info() const override;
...@@ -3405,7 +3415,7 @@ class Field_time :public Field_temporal { ...@@ -3405,7 +3415,7 @@ class Field_time :public Field_temporal {
*/ */
long curdays; long curdays;
protected: protected:
virtual void store_TIME(const MYSQL_TIME *ltime); virtual void store_TIME(const MYSQL_TIME *ltime)= 0;
void store_TIME(const Time &t) { return store_TIME(t.get_mysql_time()); } void store_TIME(const Time &t) { return store_TIME(t.get_mysql_time()); }
int store_TIME_with_warning(const Time *ltime, const ErrConv *str, int warn); int store_TIME_with_warning(const Time *ltime, const ErrConv *str, int warn);
bool check_zero_in_date_with_warn(date_mode_t fuzzydate); bool check_zero_in_date_with_warn(date_mode_t fuzzydate);
...@@ -3421,7 +3431,6 @@ class Field_time :public Field_temporal { ...@@ -3421,7 +3431,6 @@ class Field_time :public Field_temporal {
const Item_equal *item_equal) override; const Item_equal *item_equal) override;
const Type_handler *type_handler() const override const Type_handler *type_handler() const override
{ return &type_handler_time; } { return &type_handler_time; }
enum ha_base_keytype key_type() const override { return HA_KEYTYPE_INT24; }
enum_conv_type rpl_conv_type_from(const Conv_source &source, enum_conv_type rpl_conv_type_from(const Conv_source &source,
const Relay_log_info *rli, const Relay_log_info *rli,
const Conv_param &param) const override; const Conv_param &param) const override;
...@@ -3444,16 +3453,9 @@ class Field_time :public Field_temporal { ...@@ -3444,16 +3453,9 @@ class Field_time :public Field_temporal {
int store(double nr) override; int store(double nr) override;
int store(longlong nr, bool unsigned_val) override; int store(longlong nr, bool unsigned_val) override;
int store_decimal(const my_decimal *) override; int store_decimal(const my_decimal *) override;
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override; String *val_str(String *, String *) override;
bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override;
bool send_binary(Protocol *protocol) override; bool send_binary(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 3; }
void sql_type(String &str) const override; void sql_type(String &str) const override;
uint size_of() const override { return sizeof *this; }
void set_curdays(THD *thd); void set_curdays(THD *thd);
Field *new_key_field(MEM_ROOT *root, TABLE *new_table, Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uint32 length, uchar *new_ptr, uint32 length,
...@@ -3463,6 +3465,28 @@ class Field_time :public Field_temporal { ...@@ -3463,6 +3465,28 @@ class Field_time :public Field_temporal {
}; };
class Field_time0: public Field_time
{
protected:
void store_TIME(const MYSQL_TIME *ltime) override;
public:
Field_time0(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg,
uchar null_bit_arg, enum utype unireg_check_arg,
const LEX_CSTRING *field_name_arg)
:Field_time(ptr_arg, length_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg)
{ }
enum ha_base_keytype key_type() const override { return HA_KEYTYPE_INT24; }
double val_real() override;
longlong val_int() override;
bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 3; }
uint size_of() const override { return sizeof *this; }
};
/** /**
Abstract class for: Abstract class for:
- TIME(1..6) - TIME(1..6)
...@@ -3567,9 +3591,6 @@ class Field_timef :public Field_time_with_dec { ...@@ -3567,9 +3591,6 @@ class Field_timef :public Field_time_with_dec {
class Field_datetime :public Field_temporal_with_date { class Field_datetime :public Field_temporal_with_date {
void store_TIME(const MYSQL_TIME *ltime) override;
bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate)
const override;
protected: protected:
int store_TIME_with_warning(const Datetime *ltime, const ErrConv *str, int store_TIME_with_warning(const Datetime *ltime, const ErrConv *str,
int was_cut); int was_cut);
...@@ -3586,8 +3607,6 @@ class Field_datetime :public Field_temporal_with_date { ...@@ -3586,8 +3607,6 @@ class Field_datetime :public Field_temporal_with_date {
} }
const Type_handler *type_handler() const override const Type_handler *type_handler() const override
{ return &type_handler_datetime; } { return &type_handler_datetime; }
enum ha_base_keytype key_type() const override
{ return HA_KEYTYPE_ULONGLONG; }
sql_mode_t conversion_depends_on_sql_mode(THD *, Item *) const override; sql_mode_t conversion_depends_on_sql_mode(THD *, Item *) const override;
enum_conv_type rpl_conv_type_from(const Conv_source &source, enum_conv_type rpl_conv_type_from(const Conv_source &source,
const Relay_log_info *rli, const Relay_log_info *rli,
...@@ -3597,17 +3616,42 @@ class Field_datetime :public Field_temporal_with_date { ...@@ -3597,17 +3616,42 @@ class Field_datetime :public Field_temporal_with_date {
int store(longlong nr, bool unsigned_val) override; int store(longlong nr, bool unsigned_val) override;
int store_time_dec(const MYSQL_TIME *ltime, uint dec) override; int store_time_dec(const MYSQL_TIME *ltime, uint dec) override;
int store_decimal(const my_decimal *) override; int store_decimal(const my_decimal *) override;
double val_real() override; void sql_type(String &str) const override;
int set_time() override;
Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item)
override
{
return get_equal_const_item_datetime(thd, ctx, const_item);
}
};
class Field_datetime0 :public Field_datetime
{
void store_TIME(const MYSQL_TIME *ltime) override;
bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate)
const override;
public:
Field_datetime0(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg,
uchar null_bit_arg, enum utype unireg_check_arg,
const LEX_CSTRING *field_name_arg)
:Field_datetime(ptr_arg, length_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg)
{}
enum ha_base_keytype key_type() const override
{ return HA_KEYTYPE_ULONGLONG; }
double val_real() override
{
return (double) Field_datetime0::val_int();
}
longlong val_int() override; longlong val_int() override;
String *val_str(String *, String *) override; String *val_str(String *, String *) override;
bool send_binary(Protocol *protocol) override; bool send_binary(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override; int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override; void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 8; } uint32 pack_length() const override { return 8; }
void sql_type(String &str) const override;
bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override
{ return Field_datetime::get_TIME(ltime, ptr, fuzzydate); } { return Field_datetime0::get_TIME(ltime, ptr, fuzzydate); }
int set_time() override;
uchar *pack(uchar* to, const uchar *from, uint) override uchar *pack(uchar* to, const uchar *from, uint) override
{ {
return pack_int64(to, from); return pack_int64(to, from);
...@@ -3617,11 +3661,6 @@ class Field_datetime :public Field_temporal_with_date { ...@@ -3617,11 +3661,6 @@ class Field_datetime :public Field_temporal_with_date {
{ {
return unpack_int64(to, from, from_end); return unpack_int64(to, from, from_end);
} }
Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item)
override
{
return get_equal_const_item_datetime(thd, ctx, const_item);
}
uint size_of() const override { return sizeof *this; } uint size_of() const override { return sizeof *this; }
}; };
...@@ -3741,7 +3780,7 @@ new_Field_timestamp(MEM_ROOT *root,uchar *ptr, uchar *null_ptr, uchar null_bit, ...@@ -3741,7 +3780,7 @@ new_Field_timestamp(MEM_ROOT *root,uchar *ptr, uchar *null_ptr, uchar null_bit,
{ {
if (dec==0) if (dec==0)
return new (root) return new (root)
Field_timestamp(ptr, MAX_DATETIME_WIDTH, null_ptr, Field_timestamp0(ptr, MAX_DATETIME_WIDTH, null_ptr,
null_bit, unireg_check, field_name, share); null_bit, unireg_check, field_name, share);
if (dec >= FLOATING_POINT_DECIMALS) if (dec >= FLOATING_POINT_DECIMALS)
dec= MAX_DATETIME_PRECISION; dec= MAX_DATETIME_PRECISION;
...@@ -3757,7 +3796,7 @@ new_Field_time(MEM_ROOT *root, uchar *ptr, uchar *null_ptr, uchar null_bit, ...@@ -3757,7 +3796,7 @@ new_Field_time(MEM_ROOT *root, uchar *ptr, uchar *null_ptr, uchar null_bit,
{ {
if (dec == 0) if (dec == 0)
return new (root) return new (root)
Field_time(ptr, MIN_TIME_WIDTH, null_ptr, null_bit, unireg_check, Field_time0(ptr, MIN_TIME_WIDTH, null_ptr, null_bit, unireg_check,
field_name); field_name);
if (dec >= FLOATING_POINT_DECIMALS) if (dec >= FLOATING_POINT_DECIMALS)
dec= MAX_DATETIME_PRECISION; dec= MAX_DATETIME_PRECISION;
...@@ -3772,7 +3811,7 @@ new_Field_datetime(MEM_ROOT *root, uchar *ptr, uchar *null_ptr, uchar null_bit, ...@@ -3772,7 +3811,7 @@ new_Field_datetime(MEM_ROOT *root, uchar *ptr, uchar *null_ptr, uchar null_bit,
{ {
if (dec == 0) if (dec == 0)
return new (root) return new (root)
Field_datetime(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit, Field_datetime0(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit,
unireg_check, field_name); unireg_check, field_name);
if (dec >= FLOATING_POINT_DECIMALS) if (dec >= FLOATING_POINT_DECIMALS)
dec= MAX_DATETIME_PRECISION; dec= MAX_DATETIME_PRECISION;
......
...@@ -168,7 +168,7 @@ int convert_null_to_field_value_or_error(Field *field) ...@@ -168,7 +168,7 @@ int convert_null_to_field_value_or_error(Field *field)
{ {
if (field->type() == MYSQL_TYPE_TIMESTAMP) if (field->type() == MYSQL_TYPE_TIMESTAMP)
{ {
((Field_timestamp*) field)->set_time(); field->set_time();
return 0; return 0;
} }
...@@ -315,7 +315,7 @@ static void do_copy_timestamp(Copy_field *copy) ...@@ -315,7 +315,7 @@ static void do_copy_timestamp(Copy_field *copy)
if (*copy->from_null_ptr & copy->from_bit) if (*copy->from_null_ptr & copy->from_bit)
{ {
/* Same as in set_field_to_null_with_conversions() */ /* Same as in set_field_to_null_with_conversions() */
((Field_timestamp*) copy->to_field)->set_time(); copy->to_field->set_time();
} }
else else
(copy->do_copy2)(copy); (copy->do_copy2)(copy);
......
...@@ -1214,7 +1214,7 @@ bool Item_func_unix_timestamp::get_timestamp_value(my_time_t *seconds, ...@@ -1214,7 +1214,7 @@ bool Item_func_unix_timestamp::get_timestamp_value(my_time_t *seconds,
{ {
if ((null_value= field->is_null())) if ((null_value= field->is_null()))
return 1; return 1;
*seconds= ((Field_timestamp*)field)->get_timestamp(second_part); *seconds= field->get_timestamp(second_part);
return 0; return 0;
} }
} }
...@@ -1270,7 +1270,7 @@ longlong Item_func_unix_timestamp::val_int_endpoint(bool left_endp, bool *incl_e ...@@ -1270,7 +1270,7 @@ longlong Item_func_unix_timestamp::val_int_endpoint(bool left_endp, bool *incl_e
DBUG_ASSERT(arg_count == 1 && DBUG_ASSERT(arg_count == 1 &&
args[0]->type() == Item::FIELD_ITEM && args[0]->type() == Item::FIELD_ITEM &&
args[0]->field_type() == MYSQL_TYPE_TIMESTAMP); args[0]->field_type() == MYSQL_TYPE_TIMESTAMP);
Field_timestamp *field=(Field_timestamp *)(((Item_field*)args[0])->field); Field *field= ((Item_field*)args[0])->field;
/* Leave the incl_endp intact */ /* Leave the incl_endp intact */
ulong unused; ulong unused;
my_time_t ts= field->get_timestamp(&unused); my_time_t ts= field->get_timestamp(&unused);
...@@ -1644,7 +1644,7 @@ int Item_func_now_local::save_in_field(Field *field, bool no_conversions) ...@@ -1644,7 +1644,7 @@ int Item_func_now_local::save_in_field(Field *field, bool no_conversions)
ulong sec_part= decimals ? thd->query_start_sec_part() : 0; ulong sec_part= decimals ? thd->query_start_sec_part() : 0;
sec_part-= my_time_fraction_remainder(sec_part, decimals); sec_part-= my_time_fraction_remainder(sec_part, decimals);
field->set_notnull(); field->set_notnull();
((Field_timestamp*)field)->store_TIME(ts, sec_part); field->store_timestamp(ts, sec_part);
return 0; return 0;
} }
else else
......
...@@ -768,7 +768,7 @@ bool Log_to_csv_event_handler:: ...@@ -768,7 +768,7 @@ bool Log_to_csv_event_handler::
DBUG_ASSERT(table->field[0]->type() == MYSQL_TYPE_TIMESTAMP); DBUG_ASSERT(table->field[0]->type() == MYSQL_TYPE_TIMESTAMP);
((Field_timestamp*) table->field[0])->store_TIME( table->field[0]->store_timestamp(
hrtime_to_my_time(event_time), hrtime_sec_part(event_time)); hrtime_to_my_time(event_time), hrtime_sec_part(event_time));
/* do a write */ /* do a write */
...@@ -909,7 +909,7 @@ bool Log_to_csv_event_handler:: ...@@ -909,7 +909,7 @@ bool Log_to_csv_event_handler::
/* store the time and user values */ /* store the time and user values */
DBUG_ASSERT(table->field[0]->type() == MYSQL_TYPE_TIMESTAMP); DBUG_ASSERT(table->field[0]->type() == MYSQL_TYPE_TIMESTAMP);
((Field_timestamp*) table->field[0])->store_TIME( table->field[0]->store_timestamp(
hrtime_to_my_time(current_time), hrtime_sec_part(current_time)); hrtime_to_my_time(current_time), hrtime_sec_part(current_time));
if (table->field[1]->store(user_host, user_host_len, client_cs)) if (table->field[1]->store(user_host, user_host_len, client_cs))
goto err; goto err;
......
...@@ -1360,8 +1360,8 @@ Sp_handler::sp_create_routine(THD *thd, const sp_head *sp) const ...@@ -1360,8 +1360,8 @@ Sp_handler::sp_create_routine(THD *thd, const sp_head *sp) const
table->field[MYSQL_PROC_FIELD_DEFINER]-> table->field[MYSQL_PROC_FIELD_DEFINER]->
store(definer, system_charset_info); store(definer, system_charset_info);
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_CREATED])->set_time(); table->field[MYSQL_PROC_FIELD_CREATED]->set_time();
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time(); table->field[MYSQL_PROC_FIELD_MODIFIED]->set_time();
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_SQL_MODE]-> table->field[MYSQL_PROC_FIELD_SQL_MODE]->
...@@ -1651,7 +1651,7 @@ Sp_handler::sp_update_routine(THD *thd, const Database_qualified_name *name, ...@@ -1651,7 +1651,7 @@ Sp_handler::sp_update_routine(THD *thd, const Database_qualified_name *name,
} }
store_record(table,record[1]); store_record(table,record[1]);
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time(); table->field[MYSQL_PROC_FIELD_MODIFIED]->set_time();
if (chistics->suid != SP_IS_DEFAULT_SUID) if (chistics->suid != SP_IS_DEFAULT_SUID)
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]-> table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
store((longlong)chistics->suid, TRUE); store((longlong)chistics->suid, TRUE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment