Menu

#113 Filename parts appended to last column when using indexedFiles with multi-line records

open
nobody
None
5
2015-04-14
2015-04-14
No

I have the CSV file test-001-002.txt with STATION column values containing newlines:

Datum,Station
1,"first part
second part"
2,"before CRLF
after"

I use the following logic to connect to the database and run an SQL query:

props.put("fileExtension", ".txt");
props.put("indexedFiles", "true");
props.put("fileTailPattern", "-(\\d+)-(\\d+)");
props.put("fileTailParts", "Seqnr,Logdatum");
Connection conn = DriverManager.getConnection("jdbc:relique:csv:/tmp", props);
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT Datum, Station, Seqnr, Logdatum FROM test");
CsvDriver.writeToCsv(results, System.out, true);

In the output of this SQL statement, the values ,001,002 generated from the filename have been added in the middle of the STATION column value, just before the newline:

DATUM,STATION,SEQNR,LOGDATUM
1,"first part,001,002
second part",001,002
2,"before CRLF,001,002
after",001,002

Discussion

  • Simon Chenery

    Simon Chenery - 2015-04-14

    Correct output is:

    DATUM,STATION,SEQNR,LOGDATUM
    1,"first part
    second part",001,002
    2,"before CRLF
    after",001,002
    
     
  • Simon Chenery

    Simon Chenery - 2015-04-14

    Originally reported in csvjdbc-develop mailing list, "field with CRLF corrupted when indexedFiles=true" on 07.04.2015

     
MongoDB Logo MongoDB