Skip to content

Commit f8b80e8

Browse files
committed
[CSV-168] CsvFormat.nullString should not be escaped. [CSV-170]
CSVFormat.MYSQL nullString should be "\N". git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1725407 13f79535-47bb-0310-9956-ffa450edef68
1 parent 913e4a8 commit f8b80e8

4 files changed

Lines changed: 258 additions & 61 deletions

File tree

src/changes/changes.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<action issue="CSV-153" type="update" dev="britter" due-to="Wren">CSVPrinter doesn't skip creation of header record if skipHeaderRecord is set to true</action>
4343
<action issue="CSV-159" type="add" dev="ggregory" due-to="Yamil Medina">Add IgnoreCase option for accessing header names</action>
4444
<action issue="CSV-169" type="add" dev="ggregory" due-to="Gary Gregory">The null string should be case-sensitive when reading records</action>
45+
<action issue="CSV-168" type="fix" dev="ggregory" due-to="Gary Gregory, cornel creanga">CsvFormat.nullString should not be escaped</action>
46+
<action issue="CSV-170" type="fix" dev="ggregory" due-to="Gary Gregory, cornel creanga">CSVFormat.MYSQL nullString should be "\N"</action>
4547
</release>
4648
<release version="1.2" date="2015-08-24" description="Feature and bug fix release">
4749
<action issue="CSV-145" type="fix" dev="ggregory" due-to="Frank Ulbricht">CSVFormat.with* methods clear the header comments</action>

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public CSVFormat getFormat() {
296296
*
297297
* <p>
298298
* This is a tab-delimited format with a LF character as the line separator. Values are not quoted and special
299-
* characters are escaped with '\'.
299+
* characters are escaped with {@code '\'}. The default NULL string is {@code "\\N"}.
300300
* </p>
301301
*
302302
* <p>
@@ -308,14 +308,15 @@ public CSVFormat getFormat() {
308308
* <li>withRecordSeparator('\n')</li>
309309
* <li>withIgnoreEmptyLines(false)</li>
310310
* <li>withEscape('\\')</li>
311+
* <li>withNullString("\\N")</li>
311312
* </ul>
312313
*
313314
* @see Predefined#MySQL
314315
* @see <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html">
315316
* http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
316317
*/
317318
public static final CSVFormat MYSQL = DEFAULT.withDelimiter(TAB).withEscape(BACKSLASH).withIgnoreEmptyLines(false)
318-
.withQuote(null).withRecordSeparator(LF);
319+
.withQuote(null).withRecordSeparator(LF).withNullString("\\N");
319320

320321
/**
321322
* Returns true if the given character is a line break character.

src/main/java/org/apache/commons/csv/CSVPrinter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ private void print(final Object object, final CharSequence value, final int offs
136136
if (!newRecord) {
137137
out.append(format.getDelimiter());
138138
}
139-
if (format.isQuoteCharacterSet()) {
139+
if (object == null) {
140+
out.append(value);
141+
} else if (format.isQuoteCharacterSet()) {
140142
// the original object is needed so can check for Number
141143
printAndQuote(object, value, offset, len);
142144
} else if (format.isEscapeCharacterSet()) {

0 commit comments

Comments
 (0)