I have a csv file with unix style line endings. When I read that in with the TextDriver in Windows, it reads the first record incorrectly. The first character of the first column is missing.
My csv file contains: (With just line feeds as end of line)
COLUMN
value
My code:
Class.forName("com.hxtt.sql.text.TextDriver");
String url = "jdbc:csv:/.?delayedClose=0;_CSV_Header=true";
String query = "select * from \"linux-eol.csv\"";
try(Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query)) {
resultSet.next();
System.out.println(resultSet.getString("COLUMN"));
}
The output is 'alue' in Windows.
In Linux, it outputs 'value'.
Notes:
- Removing delayedClose=0 solves the problem. However, this property seems unrelated to me, and should not influence the line ending detection.
- We previously used version 5.1.032, where this issue did not occur. We are now testing version 5.2.177, where this issue popped up.
|
_CSV_EOL connection property: To specify 1~2 character sequence to terminate one line. An end-of-line line sequence is any one of a line feed ('\n', 0x0A), a carriage return ('\r', 0x0D), or a carriage return followed immediately by a linefeed. In most occasions, you needn't to care that connection property, since HXTT CSV supports even to mix three styles in one file. For data update, HXTT CSV can detect automatically OS version and choose the suitable EOL style in UNIX-style, DOS-style, and Mac-style. If you wish to create unix-style file on Windows, then you need to assign that connection porperty. It supports escape processing so that you can use \t, \r, \u001A, \x32, and so on. For instance, your data file is using $ as EOL, HXTT CSV can support that file.
_CSV_EOL=\n
|
I cannot add the _CSV_EOL property to the url, since I don't know the line ending.
The csv file is supplied by the user of our software at a later date and can have either of the line endings. We need to have the automatic detection.
In our previous version of the TextDriver this detection worked; in the latest version it does not.
|
|
Fixed. Please download it.
|