summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Glukhov <Sergey.Glukhov@sun.com>2010-02-17 16:13:42 +0400
committerSergey Glukhov <Sergey.Glukhov@sun.com>2010-02-17 16:13:42 +0400
commit4b260b668d66cfd6f7e8c2612461c66d2914219d (patch)
treebdbc73dd4f1984bcdae9fc74b5711cd70d3f2b34
parent6cb7abe667533084e09f3df6951591332138ae0e (diff)
downloadmariadb-git-4b260b668d66cfd6f7e8c2612461c66d2914219d.tar.gz
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. The fix: added special case for enum type which correctly processes 0 value. Additional fix: INSERT...(default) and INSERT...() have the same behaviour now for enum type. mysql-test/r/csv.result: test result mysql-test/r/default.result: result fix mysql-test/t/csv.test: test case sql/item.cc: Changes: do not print warning for 'enum' type if there is no default value. set default value. storage/csv/ha_tina.cc: Table corruption happens during table reading in ha_tina::find_current_row() func. Field::store() method returns error(true) if stored value is 0. The fix: added special case for enum type which correctly processes 0 value.
-rw-r--r--mysql-test/r/csv.result31
-rw-r--r--mysql-test/r/default.result3
-rw-r--r--mysql-test/t/csv.test20
-rw-r--r--sql/item.cc3
-rw-r--r--storage/csv/ha_tina.cc16
5 files changed, 46 insertions, 27 deletions
diff --git a/mysql-test/r/csv.result b/mysql-test/r/csv.result
index 4b96f5a5ed0..e2eebdfc992 100644
--- a/mysql-test/r/csv.result
+++ b/mysql-test/r/csv.result
@@ -5394,17 +5394,24 @@ select * from t1;
ERROR HY000: File 'MYSQLD_DATADIR/test/t1.CSV' not found (Errcode: 2)
unlock tables;
drop table t1;
-create table t1(a enum ('a') not null) engine=csv;
-insert into t1 values (2);
+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);
Warnings:
-Warning 1265 Data truncated for column 'a' at row 1
-select * from t1 limit 1;
-ERROR HY000: Table 't1' is marked as crashed and should be repaired
-repair table t1;
-Table Op Msg_type Msg_text
-test.t1 repair Warning Data truncated for column 'a' at row 1
-test.t1 repair status OK
-select * from t1 limit 1;
-a
-drop table t1;
+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
diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result
index 5b0d82407a2..9afffe4c3bc 100644
--- a/mysql-test/r/default.result
+++ b/mysql-test/r/default.result
@@ -180,7 +180,6 @@ insert into bug20691 values (2, 3, 5, '0007-01-01', 11, 13, 17, '0019-01-01 00:0
insert into bug20691 values (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, 4);
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 +192,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);
diff --git a/mysql-test/t/csv.test b/mysql-test/t/csv.test
index cdf274190dd..b31fa83588b 100644
--- a/mysql-test/t/csv.test
+++ b/mysql-test/t/csv.test
@@ -1807,16 +1807,16 @@ unlock tables;
drop table t1;
#
-# Bug#41441 repair csv table crashes debug server
-#
-# Note: The test should be removed after Bug#33717 is fixed
+# 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;
-create table t1(a enum ('a') not null) engine=csv;
-insert into t1 values (2);
---error ER_CRASHED_ON_USAGE
-select * from t1 limit 1;
-repair table t1;
-select * from t1 limit 1;
-drop table t1;
--echo End of 5.1 tests
diff --git a/sql/item.cc b/sql/item.cc
index df266434f72..f8cca3a0667 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -6488,7 +6488,8 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
{
if (!arg)
{
- if (field_arg->flags & NO_DEFAULT_VALUE_FLAG)
+ if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
+ field_arg->real_type() != MYSQL_TYPE_ENUM)
{
if (field_arg->reset())
{
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc
index ca9d5215310..e3bc7f55dd2 100644
--- a/storage/csv/ha_tina.cc
+++ b/storage/csv/ha_tina.cc
@@ -679,9 +679,21 @@ int ha_tina::find_current_row(uchar *buf)
if (read_all || bitmap_is_set(table->read_set, (*field)->field_index))
{
+ bool is_enum= ((*field)->real_type() == MYSQL_TYPE_ENUM);
+ /*
+ Here CHECK_FIELD_WARN checks that all values in the csv file are valid
+ which is normally the case, if they were written by
+ INSERT -> ha_tina::write_row. '0' values on ENUM fields are considered
+ invalid by Field_enum::store() but it can store them on INSERT anyway.
+ Thus, for enums we silence the warning, as it doesn't really mean
+ an invalid value.
+ */
if ((*field)->store(buffer.ptr(), buffer.length(), buffer.charset(),
- CHECK_FIELD_WARN))
- goto err;
+ is_enum ? CHECK_FIELD_IGNORE : CHECK_FIELD_WARN))
+ {
+ if (!is_enum)
+ goto err;
+ }
if ((*field)->flags & BLOB_FLAG)
{
Field_blob *blob= *(Field_blob**) field;