From e555df648c5c81f51be2e574627f6327099516ba Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 8 Aug 2019 13:47:50 +0400 Subject: MDEV-20285 Wrong result on INSERT..SELECT when converting from SIGNED to UNSIGNED --- sql/field.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'sql/field.h') diff --git a/sql/field.h b/sql/field.h index 3e5b84f9249..330523f5864 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1708,13 +1708,6 @@ public: { return to->store(val_int(), MY_TEST(flags & UNSIGNED_FLAG)); } - bool memcpy_field_possible(const Field *from) const - { - return real_type() == from->real_type() && - pack_length() == from->pack_length() && - !((flags & UNSIGNED_FLAG) && !(from->flags & UNSIGNED_FLAG)) && - decimals() == from->decimals(); - } uint is_equal(Create_field *new_field); uint row_pack_length() const { return pack_length(); } uint32 pack_length_from_metadata(uint field_metadata) { @@ -1892,7 +1885,10 @@ public: e.g. a DOUBLE(53,10) into a DOUBLE(10,10). But it should be OK the other way around. */ - return Field_num::memcpy_field_possible(from) && + return real_type() == from->real_type() && + pack_length() == from->pack_length() && + is_unsigned() <= from->is_unsigned() && + decimals() == from->decimals() && field_length >= from->field_length; } int store_decimal(const my_decimal *); @@ -1983,7 +1979,10 @@ public: } bool memcpy_field_possible(const Field *from) const { - return Field_num::memcpy_field_possible(from) && + return real_type() == from->real_type() && + pack_length() == from->pack_length() && + is_unsigned() <= from->is_unsigned() && + decimals() == from->decimals() && field_length == from->field_length; } int reset(void); @@ -2041,6 +2040,12 @@ public: :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, 0, zero_arg, unsigned_arg) {} + bool memcpy_field_possible(const Field *from) const + { + return real_type() == from->real_type() && + pack_length() == from->pack_length() && + is_unsigned() == from->is_unsigned(); + } int store_decimal(const my_decimal *); my_decimal *val_decimal(my_decimal *); bool val_bool() { return val_int() != 0; } -- cgit v1.2.1