Skip to content

Commit

Permalink
Initial changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc committed Jan 4, 2024
1 parent 41c1f8a commit c309aae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,22 @@ void setValue(JDBCType jdbcType, Object value, JavaType javaType, StreamSetterAr
// the value with the appropriate corresponding Unicode type.
// JavaType.OBJECT == javaType when calling setNull()
if (con.sendStringParametersAsUnicode() && (JavaType.STRING == javaType || JavaType.READER == javaType
|| JavaType.CLOB == javaType || JavaType.OBJECT == javaType)) {
|| JavaType.CLOB == javaType || JavaType.OBJECT == javaType) && jdbcType != JDBCType.VARCHAR) {
jdbcType = getSSPAUJDBCType(jdbcType);
}

DTV newDTV = new DTV();
newDTV.setValue(con.getDatabaseCollation(), jdbcType, value, javaType, streamSetterArgs, calendar, scale, con,
forceEncrypt);

if (!con.sendStringParametersAsUnicode()) {
if (!con.sendStringParametersAsUnicode() || (con.sendStringParametersAsUnicode() && jdbcType == JDBCType.VARCHAR)) {
newDTV.sendStringParametersAsUnicode = false;
}

if (con.sendStringParametersAsUnicode() && jdbcType == JDBCType.VARCHAR && (!con.getDatabaseCollation().isUtf8Encoding() || con.getServerMajorVersion() < 15)) {
throw new SQLServerException(SQLServerException.getErrString("R_possibleColumnDataCorruption"), null);
}

inputDTV = setterDTV = newDTV;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ final boolean hasAsciiCompatibleSBCS() {
return encoding.hasAsciiCompatibleSBCS();
}

boolean isUtf8Encoding() {
return encoding.equals(Encoding.UTF8);
}

static final int tdsLength() {
return TDS_LENGTH;
} // Length of collation in TDS (in bytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ protected Object[][] getContents() {
{"R_invalidDatetimeType", "The datetimeType connection property {0} is not valid."},
{"R_dataAlreadyAccessed", "The data has been accessed and is not available for this column or parameter."},
{"R_outParamsNotPermittedinBatch", "The OUT and INOUT parameters are not permitted in a batch."},
{"R_possibleColumnDataCorruption", "Attempted to insert encrypted unicode data into non-unicode column. Data corruption may occur."},
{"R_colNotMatchTable", "Number of provided columns {0} does not match the table definition {1}."},
{"R_invalidSQL", "Invalid SQL query {0}."},
{"R_multipleQueriesNotAllowed", "Multiple queries are not allowed."},
Expand Down

0 comments on commit c309aae

Please sign in to comment.