Skip to content

Commit

Permalink
Fixes support of empty string in CSVs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Tabin committed Jul 6, 2023
1 parent 2a921a7 commit 8fc369e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion h2/src/main/org/h2/tools/Csv.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ public Object[] readRow() throws SQLException {
if (input == null) {
return null;
}

boolean nullStringIsEmpty = nullString==null || nullString.isEmpty();
String[] row = new String[columnNames.length];
try {
int i = 0;
Expand All @@ -558,7 +560,7 @@ public Object[] readRow() throws SQLException {
// Empty Strings should be NULL
// in order to prevent conversion of zero-length String
// to Number
row[i++] = v!=null && v.length() > 0
row[i++] = v!=null && (v.length()>0 || !nullStringIsEmpty)
? v
: null;
}
Expand Down
2 changes: 1 addition & 1 deletion h2/src/test/org/h2/test/db/TestCsv.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private void testNull() throws Exception {
assertEquals("D", meta.getColumnLabel(4));
assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(null, rs.getString(2));
assertEquals("", rs.getString(2));
// null is never quoted
assertEquals("\\N", rs.getString(3));
// an empty string is always parsed as null
Expand Down

0 comments on commit 8fc369e

Please sign in to comment.