Skip to content

sendStringParametersAsUnicode not considered for SQLServerBulkCopy? #1181

@pbcornelius

Description

@pbcornelius

Driver version

7.4.1

Problem description

  1. Expected behaviour:
    SQLServerBulkCopy should treat VARCHAR and LONGVARCHAR like LONGNVARCHAR and NVARCHAR if sendStringParametersAsUnicode = True; or, alternatively, provide a seperate configuration for this (if there is one, I apologise, but I could not find it here or here).

  2. Actual behaviour:
    It does not. As a result, unicode characters in VARCHAR columns are lost during transfer. This means one cannot transfer unicode from databases that do not distinguish between VARCHAR and NVARCHAR (such as H2).

  3. Error message/stack trace:
    None

  4. Any other details that can be helpful:
    A workaround is to wrap the ResultSetMetaData and manually swap VARCHAR for NVARCHAR, e.g.:

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;
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions