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];
......
This diff is collapsed.
...@@ -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