From: Date: October 17 2007 4:30am Subject: bk commit into 5.1 tree (antony:1.2574) BUG#31473 List-Archive: http://lists.mysql.com/commits/35719 X-Bug: 31473 Message-Id: <20071017023026.11998171D584@pcg5ppc.xiphis.org> Below is the list of changes that have just been committed into a local 5.1 repository of antony. When antony does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-10-16 19:30:15-07:00, antony@stripped +3 -0 Bug#31473 "CSV does not work with NULL value in datetime fields" Attempting to insert a row with a NULL value for a DATETIME field results in a CSV file which the storage engine cannot read. Don't blindly assume that "0" is acceptable for all field types, Since CSV does not support NULL, we find out from the field the default non-null value. Handle ENUM as a special case because Field_enum::val_str() can emit a value which Field_enum::store() will flag as erronous mysql-test/r/csv.result@stripped, 2007-10-16 19:30:11-07:00, antony@stripped +42 -0 test for bug 31473 mysql-test/t/csv.test@stripped, 2007-10-16 19:30:11-07:00, antony@stripped +32 -0 test for bug 31473 storage/csv/ha_tina.cc@stripped, 2007-10-16 19:30:11-07:00, antony@stripped +14 -3 bug31473 Don't blindly assume that "0" is acceptable for all field types, Since CSV does not support NULL, we find out from the field the default non-null value. Handle ENUM as a special case because Field_enum::val_str() can emit a value which Field_enum::store() will flag as erronous diff -Nrup a/mysql-test/r/csv.result b/mysql-test/r/csv.result --- a/mysql-test/r/csv.result 2007-07-10 01:09:05 -07:00 +++ b/mysql-test/r/csv.result 2007-10-16 19:30:11 -07:00 @@ -5315,4 +5315,46 @@ test.t1 check status OK select * from t1; a drop table t1; +create table t1(a datetime default null) engine=csv; +insert into t1 values(); +select * from t1; +a +0000-00-00 00:00:00 +drop table t1; +create table t1(a enum('foo','bar') default null) engine=csv; +insert into t1 values(); +select * from t1; +a +NULL +drop table t1; +create table t1(a set('foo','bar') default null) engine=csv; +insert into t1 values(); +select * from t1; +a + +drop table t1; +create table t1(a varchar(32) default null) engine=csv; +insert into t1 values(); +select * from t1; +a + +drop table t1; +create table t1(a int default null) engine=csv; +insert into t1 values(); +select * from t1; +a +0 +drop table t1; +create table t1(a blob default null) engine=csv; +insert into t1 values(); +select * from t1; +a + +drop table t1; +create table t1(a bit(1) default null) engine=csv; +insert into t1 values(); +select BIN(a) from t1; +BIN(a) +0 +drop table t1; End of 5.1 tests diff -Nrup a/mysql-test/t/csv.test b/mysql-test/t/csv.test --- a/mysql-test/t/csv.test 2007-08-08 07:39:12 -07:00 +++ b/mysql-test/t/csv.test 2007-10-16 19:30:11 -07:00 @@ -1727,4 +1727,36 @@ check table t1; select * from t1; drop table t1; +# +# Bug #31473: does not work with NULL value in datetime field +# +create table t1(a datetime default null) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a enum('foo','bar') default null) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a set('foo','bar') default null) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a varchar(32) default null) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a int default null) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a blob default null) engine=csv; +insert into t1 values(); +select * from t1; +drop table t1; +create table t1(a bit(1) default null) engine=csv; +insert into t1 values(); +select BIN(a) from t1; +drop table t1; + --echo End of 5.1 tests diff -Nrup a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc --- a/storage/csv/ha_tina.cc 2007-08-13 06:11:15 -07:00 +++ b/storage/csv/ha_tina.cc 2007-10-16 19:30:11 -07:00 @@ -471,6 +471,7 @@ int ha_tina::encode_quote(uchar *buf) { const char *ptr; const char *end_ptr; + const bool was_null= (*field)->is_null(); /* CSV does not support nulls. Write quoted 0 to the buffer. In fact, @@ -480,14 +481,17 @@ int ha_tina::encode_quote(uchar *buf) field content is cleaned up every time we use Field::set_null() in the code. */ - if ((*field)->is_null()) + if (was_null) { - buffer.append(STRING_WITH_LEN("\"0\",")); - continue; + (*field)->set_default(); + (*field)->set_notnull(); } (*field)->val_str(&attribute,&attribute); + if (was_null) + (*field)->set_null(); + if ((*field)->str_needs_quotes()) { ptr= attribute.ptr(); @@ -681,6 +685,13 @@ int ha_tina::find_current_row(uchar *buf if (read_all || bitmap_is_set(table->read_set, (*field)->field_index)) { + /* + Special case for ENUMs because Field_enum::val_str can emit + a value which Field_enum::store() will reject as erronous + */ + if (((*field)->flags & ENUM_FLAG) && !buffer.length()) + (*field)->set_default(); + else if ((*field)->store(buffer.ptr(), buffer.length(), buffer.charset(), CHECK_FIELD_WARN)) goto err;