public class UnicodeResultSetMetaData implements ResultSetMetaData {
...
private static List<Integer> UNICODE_EQUIVALENT = List.of(Types.VARCHAR, Types.LONGVARCHAR);
private static List<String> UNICODE_EQUIVALENT_NAMES = List.of("VARCHAR",
"CHARACTER VARYING",
"LONGVARCHAR",
"VARCHAR2",
"VARCHAR_CASESENSITIVE");
public int getColumnType(int column) throws SQLException {
int type = meta.getColumnType(column);
if (UNICODE_EQUIVALENT.contains(type)) {
return Types.NVARCHAR;
} else {
return type;
}
}
public String getColumnTypeName(int column) throws SQLException {
String type = meta.getColumnTypeName(column);
if (UNICODE_EQUIVALENT_NAMES.contains(type)) {
return "NVARCHAR";
} else {
return type;
}
}
Driver version
7.4.1
Problem description
Expected behaviour:
SQLServerBulkCopyshould treatVARCHARandLONGVARCHARlikeLONGNVARCHARandNVARCHARifsendStringParametersAsUnicode = True; or, alternatively, provide a seperate configuration for this (if there is one, I apologise, but I could not find it here or here).Actual behaviour:
It does not. As a result, unicode characters in
VARCHARcolumns are lost during transfer. This means one cannot transfer unicode from databases that do not distinguish betweenVARCHARandNVARCHAR(such as H2).Error message/stack trace:
None
Any other details that can be helpful:
A workaround is to wrap the ResultSetMetaData and manually swap
VARCHARforNVARCHAR, e.g.: