Driver version
9.2.1.jre15
JAVA/JVM version
JDK 15
Problem description
Expected behaviour: Importing data from a csv file with a delimiter containing a special regex character (for example ("|") should work
I have a csv file where the delimiter is the pipe character (|):
FOO1 | BAR1 | 1
FOO2 | BAR2 | 2
When trying to import the data using SQLServerBulkCSVFileRecord, import fails because the lines are not split correctly:
try (
var connection = DriverManager.getConnection(connectionUrl);
var bulkCopy = new SQLServerBulkCopy(connection)
) {
# delimiter = |
var fileRecord = new SQLServerBulkCSVFileRecord(csvSourcePath, null, "|",false);
...
bulkCopy.setDestinationTableName(destinationTable);
bulkCopy.writeToServer(fileRecord);
}
I looked into SQLServerBulkCSVFileRecord::getRowData and this clearly happens because the method String::split is used to split the line. However special regex characters are not treated as delimiters if not escaped, so the line is not split correctly.
This can be fixed by one of the following:
- Implementing special handling for delimiters passed to the constructor of
SQLServerBulkCSVFileRecord
- Passing the responsibility to the user, and explicitly state in the javadoc that special regex chars should be escaped.
I think the second approach is better, but I would be happy to provide a pull request for either approach.
Driver version
9.2.1.jre15
JAVA/JVM version
JDK 15
Problem description
Expected behaviour: Importing data from a csv file with a delimiter containing a special regex character (for example ("|") should work
I have a csv file where the delimiter is the pipe character (
|):FOO1 | BAR1 | 1 FOO2 | BAR2 | 2When trying to import the data using
SQLServerBulkCSVFileRecord, import fails because the lines are not split correctly:I looked into
SQLServerBulkCSVFileRecord::getRowDataand this clearly happens because the methodString::splitis used to split the line. However special regex characters are not treated as delimiters if not escaped, so the line is not split correctly.This can be fixed by one of the following:
SQLServerBulkCSVFileRecordI think the second approach is better, but I would be happy to provide a pull request for either approach.