提交 07236a50 authored 作者: Thomas Mueller's avatar Thomas Mueller

CSVREAD did not process NULL correctly when using a whitespace field separator.

上级 cc29aa7f
...@@ -19,6 +19,7 @@ Change Log ...@@ -19,6 +19,7 @@ Change Log
<ul><li>Multi version concurrency (MVCC): when a row was updated or deleted, but this change was rolled back, <ul><li>Multi version concurrency (MVCC): when a row was updated or deleted, but this change was rolled back,
the row was not visible by other sessions if no index was used to access it. Fixed. the row was not visible by other sessions if no index was used to access it. Fixed.
</li><li>Views with multiple joined tables (where one was an outer join) couldn't be used in some cases. Fixed. </li><li>Views with multiple joined tables (where one was an outer join) couldn't be used in some cases. Fixed.
</li><li>The CSVREAD method did not process NULL correctly when using a whitespace field separator.
</li><li>Fixed the Oracle mode: Oracle allows multiple rows with NULL in a unique index. </li><li>Fixed the Oracle mode: Oracle allows multiple rows with NULL in a unique index.
</li><li>Running out of memory could result in incomplete transactions or corrupted databases. Fixed. </li><li>Running out of memory could result in incomplete transactions or corrupted databases. Fixed.
</li><li>When using order by in a query that uses the same table multiple times, the order could </li><li>When using order by in a query that uses the same table multiple times, the order could
......
...@@ -345,12 +345,12 @@ public class Csv implements SimpleRowSource { ...@@ -345,12 +345,12 @@ public class Csv implements SimpleRowSource {
if (ch < 0 || ch == '\r' || ch == '\n') { if (ch < 0 || ch == '\r' || ch == '\n') {
endOfLine = true; endOfLine = true;
break; break;
} else if (ch <= ' ') {
// ignore spaces
continue;
} else if (ch == fieldSeparatorRead) { } else if (ch == fieldSeparatorRead) {
// null // null
break; break;
} else if (ch <= ' ') {
// ignore spaces
continue;
} else if (ch == fieldDelimiter) { } else if (ch == fieldDelimiter) {
// delimited value // delimited value
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
...@@ -388,10 +388,10 @@ public class Csv implements SimpleRowSource { ...@@ -388,10 +388,10 @@ public class Csv implements SimpleRowSource {
ch = readChar(); ch = readChar();
if (ch < 0) { if (ch < 0) {
break; break;
} else if (ch == ' ' || ch == '\t') {
// ignore
} else if (ch == fieldSeparatorRead) { } else if (ch == fieldSeparatorRead) {
break; break;
} else if (ch == ' ' || ch == '\t') {
// ignore
} else if (ch == '\r' || ch == '\n') { } else if (ch == '\r' || ch == '\n') {
pushBack(ch); pushBack(ch);
endOfLine = true; endOfLine = true;
......
...@@ -25,6 +25,7 @@ $$A new version of H2 is available for <a href="http://www.h2database.com">downl ...@@ -25,6 +25,7 @@ $$A new version of H2 is available for <a href="http://www.h2database.com">downl
</li></ul> </li></ul>
<b>Bugfixes:</b> <b>Bugfixes:</b>
<ul><li>Running out of memory could result in incomplete transactions or corrupted databases. Fixed. <ul><li>Running out of memory could result in incomplete transactions or corrupted databases. Fixed.
</li><li>CSVREAD did not process NULL correctly when using a whitespace field separator.
</li><li>Stopping a WebServer didn't always work. Fixed. </li><li>Stopping a WebServer didn't always work. Fixed.
</li><li>Sometimes, order by in a query that uses the same table multiple times didn't work. </li><li>Sometimes, order by in a query that uses the same table multiple times didn't work.
</li><li>A multi version concurrency (MVCC) problem has been fixed. </li><li>A multi version concurrency (MVCC) problem has been fixed.
......
...@@ -33,6 +33,7 @@ import org.h2.util.StringUtils; ...@@ -33,6 +33,7 @@ import org.h2.util.StringUtils;
public class TestCsv extends TestBase { public class TestCsv extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testSpaceSeparated();
testNull(); testNull();
testRandomData(); testRandomData();
testEmptyFieldDelimiter(); testEmptyFieldDelimiter();
...@@ -42,6 +43,25 @@ public class TestCsv extends TestBase { ...@@ -42,6 +43,25 @@ public class TestCsv extends TestBase {
testRead(); testRead();
testPipe(); testPipe();
} }
private void testSpaceSeparated() throws Exception {
deleteDb("csv");
File f = new File(baseDir + "/testSpace.csv");
FileUtils.delete(f.getAbsolutePath());
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
stat.execute("create temporary table test (a int, b int, c int)");
stat.execute("insert into test values(1,2,3)");
stat.execute("insert into test values(4,null,5)");
stat.execute("call csvwrite('test.tsv','select * from test',null,' ')");
ResultSet rs1 = stat.executeQuery("select * from test");
assertResultSetOrdered(rs1, new String[][]{new String[]{"1", "2", "3"}, new String[]{"4", null, "5"}});
ResultSet rs2 = stat.executeQuery("select * from csvread('test.tsv',null,null,' ')");
assertResultSetOrdered(rs2, new String[][]{new String[]{"1", "2", "3"}, new String[]{"4", null, "5"}});
conn.close();
FileUtils.delete(f.getAbsolutePath());
}
/** /**
* Test custom NULL string. * Test custom NULL string.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论