diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-11-22 14:53:25 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-11-22 14:53:25 +0400 |
commit | 740ce108a52120fe6b2933ce8f3e82d8cf12ae8c (patch) | |
tree | 5ffdf0c29f4749c7cfcf67c2899edf3b1bf23820 /sql/field_conv.cc | |
parent | 2ebb110c36b2671614af26f34b35ece58a9b9f6a (diff) | |
download | mariadb-git-740ce108a52120fe6b2933ce8f3e82d8cf12ae8c.tar.gz |
MDEV-17792 New class Timestamp and cleanups in Date, Datetime, Field for rounding
Diffstat (limited to 'sql/field_conv.cc')
-rw-r--r-- | sql/field_conv.cc | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 8b3d9c04656..7a064f64570 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -425,24 +425,32 @@ void Field::do_field_timestamp(Copy_field *copy) } -void Field::do_field_temporal(Copy_field *copy) +void Field::do_field_temporal(Copy_field *copy, date_mode_t fuzzydate) { MYSQL_TIME ltime; // TODO: we now need to check result - if (copy->from_field->get_date(<ime, date_mode_t(0))) + if (copy->from_field->get_date(<ime, fuzzydate)) copy->to_field->reset(); else copy->to_field->store_time_dec(<ime, copy->from_field->decimals()); } +void Field::do_field_datetime(Copy_field *copy) +{ + return do_field_temporal(copy, date_mode_t(0)); +} + + +void Field::do_field_date(Copy_field *copy) +{ + return do_field_temporal(copy, date_mode_t(0)); +} + + void Field_time::do_field_time(Copy_field *copy) { - MYSQL_TIME ltime; - if (copy->from_field->get_date(<ime, TIME_TIME_ONLY)) - copy->to_field->reset(); - else - copy->to_field->store_time_dec(<ime, copy->from_field->decimals()); + return do_field_temporal(copy, TIME_TIME_ONLY); } @@ -720,13 +728,20 @@ void Copy_field::set(Field *to,Field *from,bool save) Field::Copy_func *Field_timestamp::get_copy_func(const Field *from) const { Field::Copy_func *copy= Field_temporal::get_copy_func(from); - if (copy == do_field_temporal && from->type() == MYSQL_TYPE_TIMESTAMP) + if (copy == do_field_datetime && from->type() == MYSQL_TYPE_TIMESTAMP) return do_field_timestamp; else return copy; } +Field::Copy_func *Field_date_common::get_copy_func(const Field *from) const +{ + Field::Copy_func *copy= Field_temporal::get_copy_func(from); + return copy == do_field_datetime ? do_field_date : copy; +} + + Field::Copy_func *Field_temporal::get_copy_func(const Field *from) const { /* If types are not 100 % identical then convert trough get_date() */ @@ -739,7 +754,7 @@ Field::Copy_func *Field_temporal::get_copy_func(const Field *from) const if (!eq_def(from) || (table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE))) - return do_field_temporal; + return do_field_datetime; return get_identical_copy_func(); } |