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-17 23:03:43-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.
Do not permit the creation of a table with a nullable ENUM.
mysql-test/r/csv.result@stripped, 2007-10-17 23:03:35-07:00, antony@stripped +46
-0
test for bug 31473
mysql-test/t/csv.test@stripped, 2007-10-17 23:03:35-07:00, antony@stripped +39 -0
test for bug 31473
storage/csv/ha_tina.cc@stripped, 2007-10-17 23:03:36-07:00, antony@stripped +22 -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.
Do not permit the creation of a table with a nullable ENUM.
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-17 23:03:35 -07:00
@@ -5315,4 +5315,50 @@ 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 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;
+create table t1(a enum('foo','bar') default null) engine=csv;
+ERROR HY000: Can't create table 'test.t1' (errno: -1)
+create table t1(a enum('foo','bar') default 'foo') engine=csv;
+ERROR HY000: Can't create table 'test.t1' (errno: -1)
+create table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
+insert into t1 values();
+select * from t1;
+a
+foo
+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-17 23:03:35 -07:00
@@ -1727,4 +1727,43 @@ 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 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;
+# We prevent creation of table with nullable ENUM
+--error ER_CANT_CREATE_TABLE
+create table t1(a enum('foo','bar') default null) engine=csv;
+--error ER_CANT_CREATE_TABLE
+create table t1(a enum('foo','bar') default 'foo') engine=csv;
+# Enum columns must be specified as NOT NULL
+create table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
+insert into t1 values();
+select * 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-17 23:03:36 -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();
@@ -1479,6 +1483,21 @@ int ha_tina::create(const char *name, TA
char name_buff[FN_REFLEN];
File create_file;
DBUG_ENTER("ha_tina::create");
+
+ /*
+ check columns
+ */
+ for (Field **field= table_arg->s->field; *field; field++)
+ {
+ /*
+ If there is an ENUM column which is NULLable, we abort
+ creation of the table because Field_enum::val_str() is able
+ to emit strings which Field_enum::store() cannot parse;
+ */
+ if (((*field)->flags & ENUM_FLAG) && (*field)->real_maybe_null())
+ DBUG_RETURN(-1);
+ }
+
if ((create_file= my_create(fn_format(name_buff, name, "", CSM_EXT,
MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0,
| Thread |
|---|
| • bk commit into 5.1 tree (antony:1.2574) BUG#31473 | antony | 18 Oct |