diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-09-19 23:50:32 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-09-21 22:03:28 +0200 |
commit | f8a800bec81983910a96a5dc38f3aeb9b7528bce (patch) | |
tree | 7da12c2d4f832cbf6bf9774a6dbbab88feada0c1 /sql/field_conv.cc | |
parent | f4f48e06215fe6717865ccbe27ddc388a2cb86b8 (diff) | |
download | mariadb-git-f8a800bec81983910a96a5dc38f3aeb9b7528bce.tar.gz |
bugfix: copy timestamps correctly in INSERT...SELECT
don't do it via MYSQL_TIME, that conversion is lossy
around DST change dates.
Diffstat (limited to 'sql/field_conv.cc')
-rw-r--r-- | sql/field_conv.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 74c5fb5b502..850403afb97 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -219,6 +219,13 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions) } +static int copy_timestamp_fields(Field *from, Field *to) +{ + DBUG_ASSERT(from->type() == MYSQL_TYPE_TIMESTAMP); + DBUG_ASSERT(to->type() == MYSQL_TYPE_TIMESTAMP); + return ((Field_timestamp*)to)->store_timestamp((Field_timestamp*)from); +} + static void do_skip(Copy_field *copy __attribute__((unused))) { } @@ -419,13 +426,7 @@ static void do_field_decimal(Copy_field *copy) static void do_field_timestamp(Copy_field *copy) { - DBUG_ASSERT(copy->from_field->type() == MYSQL_TYPE_TIMESTAMP); - DBUG_ASSERT(copy->to_field->type() == MYSQL_TYPE_TIMESTAMP); - ulong sec_part; - Field_timestamp *f= static_cast<Field_timestamp*>(copy->from_field); - Field_timestamp *t= static_cast<Field_timestamp*>(copy->to_field); - my_time_t ts= f->get_timestamp(&sec_part); - t->store_TIME(ts, sec_part); + copy_timestamp_fields(copy->from_field, copy->to_field); } @@ -938,6 +939,10 @@ int field_conv_incompatible(Field *to, Field *from) my_decimal buff; return to->store_decimal(from->val_decimal(&buff)); } + if (from->type() == MYSQL_TYPE_TIMESTAMP && to->type() == MYSQL_TYPE_TIMESTAMP) + { + return copy_timestamp_fields(from, to); + } if (from->cmp_type() == TIME_RESULT) { MYSQL_TIME ltime; |