diff options
-rw-r--r-- | mysql-test/r/type_enum.result | 20 | ||||
-rw-r--r-- | mysql-test/r/type_ranges.result | 4 | ||||
-rw-r--r-- | mysql-test/t/type_enum.test | 18 | ||||
-rw-r--r-- | sql/field_conv.cc | 16 |
4 files changed, 49 insertions, 9 deletions
diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result index f537b7140ba..ca516f027ba 100644 --- a/mysql-test/r/type_enum.result +++ b/mysql-test/r/type_enum.result @@ -1809,3 +1809,23 @@ f1 drop table t1; +CREATE TABLE t1 (c1 ENUM('a', '', 'b')); +INSERT INTO t1 (c1) VALUES ('b'); +INSERT INTO t1 (c1) VALUES (''); +INSERT INTO t1 (c1) VALUES (0); +Warnings: +Warning 1265 Data truncated for column 'c1' at row 1 +INSERT INTO t1 (c1) VALUES (''); +SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1; +c1 + 0 COUNT(c1) +0 1 +2 2 +3 1 +CREATE TABLE t2 SELECT * FROM t1; +SELECT c1 + 0 FROM t2; +c1 + 0 +3 +2 +0 +2 +DROP TABLE t1,t2; diff --git a/mysql-test/r/type_ranges.result b/mysql-test/r/type_ranges.result index e949d734944..5c2d3b84d89 100644 --- a/mysql-test/r/type_ranges.result +++ b/mysql-test/r/type_ranges.result @@ -208,10 +208,6 @@ options flags one one drop table t2; create table t2 select * from t1; -Warnings: -Warning 1265 Data truncated for column 'options' at row 4 -Warning 1265 Data truncated for column 'options' at row 5 -Warning 1265 Data truncated for column 'options' at row 6 update t2 set string="changed" where auto=16; show full columns from t1; Field Type Collation Null Key Default Extra Privileges Comment diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test index ecc945a3157..fbba38f926d 100644 --- a/mysql-test/t/type_enum.test +++ b/mysql-test/t/type_enum.test @@ -182,3 +182,21 @@ create table t1(f1 set('a','b'), index(f1)); insert into t1 values(''),(''),('a'),('b'); select * from t1 where f1=''; drop table t1; + +# +# Bug#29360: Confluence of the special 0 enum value with the normal empty string +# value during field to field copy. +# + +CREATE TABLE t1 (c1 ENUM('a', '', 'b')); +INSERT INTO t1 (c1) VALUES ('b'); +INSERT INTO t1 (c1) VALUES (''); +INSERT INTO t1 (c1) VALUES (0); +INSERT INTO t1 (c1) VALUES (''); + +SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1; + +CREATE TABLE t2 SELECT * FROM t1; +SELECT c1 + 0 FROM t2; + +DROP TABLE t1,t2; diff --git a/sql/field_conv.cc b/sql/field_conv.cc index a286255ec23..2df65b62de6 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -790,11 +790,17 @@ int field_conv(Field *to,Field *from) blob->value.copy(); return blob->store(blob->value.ptr(),blob->value.length(),from->charset()); } - if ((from->result_type() == STRING_RESULT && - (to->result_type() == STRING_RESULT || - (from->real_type() != FIELD_TYPE_ENUM && - from->real_type() != FIELD_TYPE_SET))) || - to->type() == FIELD_TYPE_DECIMAL) + if (from->real_type() == FIELD_TYPE_ENUM && + to->real_type() == FIELD_TYPE_ENUM && + from->val_int() == 0) + { + ((Field_enum *)(to))->store_type(0); + } + else if ((from->result_type() == STRING_RESULT && + (to->result_type() == STRING_RESULT || + (from->real_type() != FIELD_TYPE_ENUM && + from->real_type() != FIELD_TYPE_SET))) || + to->type() == FIELD_TYPE_DECIMAL) { char buff[MAX_FIELD_WIDTH]; String result(buff,sizeof(buff),from->charset()); |