From: Date: December 26 2008 5:46pm Subject: bzr commit into mysql-5.1-bugteam branch (Sergey.Glukhov:2746) Bug#33717 List-Archive: http://lists.mysql.com/commits/62353 X-Bug: 33717 Message-Id: <0KCH00ISFTA7N130@fe-emea-09.sun.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7BIT #At file:///home/gluh/MySQL/mysql-5.1-bug-41131/ based on revid:sergey.glukhov@stripped 2746 Sergey Glukhov 2008-12-26 Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for MyISAM Table corruption happens during table reading in ha_tina::find_current_row() func. Field::store() method returns error(true) if stored value is 0, but 0 is legal value. The fix is to return false if the value is 0. Additional fix: INSERT...(default) and INSERT...() have the same behaviour now. modified: mysql-test/r/csv.result mysql-test/r/default.result mysql-test/r/key.result mysql-test/r/sp.result mysql-test/r/strict.result mysql-test/r/type_enum.result mysql-test/r/type_ranges.result mysql-test/t/csv.test mysql-test/t/strict.test sql/field.cc sql/item.cc sql/sql_insert.cc per-file messages: mysql-test/r/csv.result test result mysql-test/r/default.result result fix mysql-test/r/key.result result fix mysql-test/r/sp.result result fix mysql-test/r/strict.result result fix mysql-test/r/type_enum.result result fix mysql-test/r/type_ranges.result result fix mysql-test/t/csv.test test case mysql-test/t/strict.test test fix sql/field.cc 0 is legal value for ENUM type, so there is no need to return error in this case. sql/item.cc set default value sql/sql_insert.cc removed check for ENUM field. The reason is that ENUM field behavoir should be the same as other fileds have. === modified file 'mysql-test/r/csv.result' --- a/mysql-test/r/csv.result 2008-12-10 09:05:18 +0000 +++ b/mysql-test/r/csv.result 2008-12-26 17:48:08 +0000 @@ -5394,4 +5394,28 @@ select * from t1; ERROR HY000: File './test/t1.CSV' not found (Errcode: 2) unlock tables; drop table t1; +CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV; +INSERT INTO t1 VALUES(); +Warnings: +Warning 1364 Field 'e' doesn't have a default value +INSERT INTO t1 VALUES(default); +Warnings: +Warning 1364 Field 'e' doesn't have a default value +INSERT INTO t1 VALUES(0); +Warnings: +Warning 1265 Data truncated for column 'e' at row 1 +INSERT INTO t1 VALUES(3); +Warnings: +Warning 1265 Data truncated for column 'e' at row 1 +INSERT INTO t1 VALUES(-1); +Warnings: +Warning 1265 Data truncated for column 'e' at row 1 +SELECT * FROM t1; +e +foo +foo + + + +DROP TABLE t1; End of 5.1 tests === modified file 'mysql-test/r/default.result' --- a/mysql-test/r/default.result 2008-09-03 08:06:03 +0000 +++ b/mysql-test/r/default.result 2008-12-26 17:48:08 +0000 @@ -169,6 +169,7 @@ insert into bug20691 values (2, 3, 5, '0 insert into bug20691 (x) values (2); Warnings: Warning 1364 Field 'a' doesn't have a default value +Warning 1364 Field 'b' doesn't have a default value Warning 1364 Field 'c' doesn't have a default value Warning 1364 Field 'd' doesn't have a default value Warning 1364 Field 'e' doesn't have a default value @@ -193,7 +194,7 @@ a b c d e f g h i x two large 00:00:05 0007-01-01 11 13 17 0019-01-01 00:00:00 23 1 small 00:00:00 0000-00-00 0 0000-00-00 00:00:00 0 2 two large 00:00:05 0007-01-01 11 13 17 0019-01-01 00:00:00 23 3 - 00:00:00 0000-00-00 0 0000-00-00 00:00:00 0 4 + small 00:00:00 0000-00-00 0 0000-00-00 00:00:00 0 4 drop table bug20691; create table t1 (id int not null); insert into t1 values(default); === modified file 'mysql-test/r/key.result' --- a/mysql-test/r/key.result 2007-12-05 19:33:36 +0000 +++ b/mysql-test/r/key.result 2008-12-26 17:48:08 +0000 @@ -33,11 +33,6 @@ KEY price (price,area,type,transityes,sh INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','N','N','N','N'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','N','N','N','N'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','','','',''); -Warnings: -Warning 1265 Data truncated for column 'transityes' at row 1 -Warning 1265 Data truncated for column 'shopsyes' at row 1 -Warning 1265 Data truncated for column 'schoolsyes' at row 1 -Warning 1265 Data truncated for column 'petsyes' at row 1 INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y'); === modified file 'mysql-test/r/sp.result' --- a/mysql-test/r/sp.result 2008-11-03 10:40:58 +0000 +++ b/mysql-test/r/sp.result 2008-12-26 17:48:08 +0000 @@ -3426,8 +3426,6 @@ drop procedure bug9538| drop procedure if exists bug8692| create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| insert into t3 values ('', '', '', '', '', '', NULL)| -Warnings: -Warning 1265 Data truncated for column 'c3' at row 1 create procedure bug8692() begin declare v1 VARCHAR(10); === modified file 'mysql-test/r/strict.result' --- a/mysql-test/r/strict.result 2008-05-13 12:01:02 +0000 +++ b/mysql-test/r/strict.result 2008-12-26 17:48:08 +0000 @@ -966,7 +966,6 @@ ERROR 01000: Data truncated for column ' INSERT INTO t1 (col1) VALUES ('redd'); ERROR 01000: Data truncated for column 'col1' at row 1 INSERT INTO t1 VALUES (''); -ERROR 01000: Data truncated for column 'col1' at row 1 UPDATE t1 SET col1 ='yellow' WHERE col1 ='green'; ERROR 01000: Data truncated for column 'col1' at row 3 INSERT IGNORE INTO t1 VALUES ('yellow'); @@ -981,6 +980,7 @@ red green + DROP TABLE t1; CREATE TABLE t1 (col1 INT NOT NULL, col2 CHAR(5) NOT NULL, col3 DATE NOT NULL); INSERT INTO t1 VALUES (100, 'hello', '2004-08-20'); === modified file 'mysql-test/r/type_enum.result' --- a/mysql-test/r/type_enum.result 2007-09-20 09:10:05 +0000 +++ b/mysql-test/r/type_enum.result 2008-12-26 17:48:08 +0000 @@ -1644,8 +1644,6 @@ select * from t1; a update t1 set a = replace(a,'x','y'); -Warnings: -Warning 1265 Data truncated for column 'a' at row 1 select * from t1; a === modified file 'mysql-test/r/type_ranges.result' --- a/mysql-test/r/type_ranges.result 2007-11-13 13:24:48 +0000 +++ b/mysql-test/r/type_ranges.result 2008-12-26 17:48:08 +0000 @@ -125,6 +125,8 @@ Warning 1264 Out of range value for colu Warning 1264 Out of range value for column 'umedium' at row 1 Warning 1265 Data truncated for column 'options' at row 1 insert into t1 (tiny) values (1); +Warnings: +Warning 1364 Field 'options' doesn't have a default value select auto,string,tiny,short,medium,long_int,longlong,real_float,real_double,utiny,ushort,umedium,ulong,ulonglong,mod(floor(time_stamp/1000000),1000000)-mod(curdate(),1000000),date_field,time_field,date_time,blob_col,tinyblob_col,mediumblob_col,longblob_col from t1; auto string tiny short medium long_int longlong real_float real_double utiny ushort umedium ulong ulonglong mod(floor(time_stamp/1000000),1000000)-mod(curdate(),1000000) date_field time_field date_time blob_col tinyblob_col mediumblob_col longblob_col 10 1 1 1 1 1 1 1.0 1.0000 1 00001 1 1 1 0 0000-00-00 00:00:00 0000-00-00 00:00:00 1 1 1 1 === modified file 'mysql-test/t/csv.test' --- a/mysql-test/t/csv.test 2008-12-10 09:05:18 +0000 +++ b/mysql-test/t/csv.test 2008-12-26 17:48:08 +0000 @@ -1804,4 +1804,16 @@ unlock tables; drop table t1; --disconnect con1 +# +# Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for MyISAM +# +CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV; +INSERT INTO t1 VALUES(); +INSERT INTO t1 VALUES(default); +INSERT INTO t1 VALUES(0); +INSERT INTO t1 VALUES(3); +INSERT INTO t1 VALUES(-1); +SELECT * FROM t1; +DROP TABLE t1; + --echo End of 5.1 tests === modified file 'mysql-test/t/strict.test' --- a/mysql-test/t/strict.test 2008-02-19 21:33:43 +0000 +++ b/mysql-test/t/strict.test 2008-12-26 17:48:08 +0000 @@ -869,7 +869,6 @@ INSERT INTO t1 VALUES ('red'),('blue'),( INSERT INTO t1 (col1) VALUES ('yellow'); --error 1265 INSERT INTO t1 (col1) VALUES ('redd'); ---error 1265 INSERT INTO t1 VALUES (''); --error 1265 UPDATE t1 SET col1 ='yellow' WHERE col1 ='green'; === modified file 'sql/field.cc' --- a/sql/field.cc 2008-12-09 10:56:46 +0000 +++ b/sql/field.cc 2008-12-26 17:48:08 +0000 @@ -8469,7 +8469,7 @@ int Field_enum::store(const char *from,u uint tmp=find_type2(typelib, from, length, field_charset); if (!tmp) { - if (length < 6) // Can't be more than 99999 enums + if (length > 0 && length < 6) // Can't be more than 99999 enums { /* This is for reading numbers with LOAD DATA INFILE */ char *end; @@ -8482,7 +8482,7 @@ int Field_enum::store(const char *from,u if (!table->in_use->count_cuted_fields) err= 0; } - else + else if (length >= 6) set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1); } store_type((ulonglong) tmp); === modified file 'sql/item.cc' --- a/sql/item.cc 2008-12-16 12:12:22 +0000 +++ b/sql/item.cc 2008-12-26 17:48:08 +0000 @@ -6181,6 +6181,7 @@ void Item_default_value::print(String *s int Item_default_value::save_in_field(Field *field_arg, bool no_conversions) { + int err= 0; if (!arg) { if (field_arg->flags & NO_DEFAULT_VALUE_FLAG) @@ -6210,10 +6211,10 @@ int Item_default_value::save_in_field(Fi ER(ER_NO_DEFAULT_FOR_FIELD), field_arg->field_name); } - return 1; + err= 1; } field_arg->set_default(); - return 0; + return err; } return Item_field::save_in_field(field_arg, no_conversions); } === modified file 'sql/sql_insert.cc' --- a/sql/sql_insert.cc 2008-10-21 07:55:03 +0000 +++ b/sql/sql_insert.cc 2008-12-26 17:48:08 +0000 @@ -1616,8 +1616,7 @@ int check_that_all_fields_are_given_valu for (Field **field=entry->field ; *field ; field++) { if (!bitmap_is_set(write_set, (*field)->field_index) && - ((*field)->flags & NO_DEFAULT_VALUE_FLAG) && - ((*field)->real_type() != MYSQL_TYPE_ENUM)) + ((*field)->flags & NO_DEFAULT_VALUE_FLAG)) { bool view= FALSE; if (table_list)