diff --git a/mysql-test/main/type_enum.result b/mysql-test/main/type_enum.result index 311875d4aa692..8eabab22997b6 100644 --- a/mysql-test/main/type_enum.result +++ b/mysql-test/main/type_enum.result @@ -2570,3 +2570,17 @@ Note 1105 Cannot use key parts with `test`.`t1`.`indexed_col` in the rewritten c DROP TABLE t2; DROP TABLE t1; SET note_verbosity=DEFAULT; +# +# MDEV-39043 ENUM can be set to empty string by giving an index value as string "0" +# +set sql_mode=STRICT_ALL_TABLES; +create table t1 (a enum('Value1', 'Value2') NOT NULL DEFAULT 'Value1'); +insert into t1 values ('0'); +ERROR 01000: Data truncated for column 'a' at row 1 +select * from t1; +a +drop table t1; +set sql_mode=default; +# +# End of 10.6 tests +# diff --git a/mysql-test/main/type_enum.test b/mysql-test/main/type_enum.test index 5276c6ff04c73..01c3f52cc7149 100644 --- a/mysql-test/main/type_enum.test +++ b/mysql-test/main/type_enum.test @@ -580,3 +580,18 @@ DELIMITER ;$$ --source unusable_keys_joins.inc DROP TABLE t1; SET note_verbosity=DEFAULT; + +--echo # +--echo # MDEV-39043 ENUM can be set to empty string by giving an index value as string "0" +--echo # +set sql_mode=STRICT_ALL_TABLES; +create table t1 (a enum('Value1', 'Value2') NOT NULL DEFAULT 'Value1'); +--error WARN_DATA_TRUNCATED +insert into t1 values ('0'); +select * from t1; +drop table t1; +set sql_mode=default; + +--echo # +--echo # End of 10.6 tests +--echo # diff --git a/sql/field.cc b/sql/field.cc index 6b4c089e830c6..2d43604d4da7f 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -9401,7 +9401,7 @@ int Field_enum::store(const char *from,size_t length,CHARSET_INFO *cs) /* This is for reading numbers with LOAD DATA INFILE */ char *end; tmp=(uint) cs->strntoul(from,length,10,&end,&err); - if (err || end != from+length || tmp > typelib->count) + if (err || end != from+length || !tmp || tmp > typelib->count) { tmp=0; set_warning(WARN_DATA_TRUNCATED, 1);