Skip to content

Commit

Permalink
Added SQLState 22005 to driver conversion exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc committed Aug 4, 2023
1 parent 0080cc4 commit a2f389a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ private DataTypes() {
static final void throwConversionError(String fromType, String toType) throws SQLServerException {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedConversionFromTo"));
Object[] msgArgs = {fromType, toType};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true);
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), SQLState.ERROR_IN_ASSIGNMENT.getSQLStateCode(), true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ enum SQLState {
DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW("22008"),
NUMERIC_DATA_OUT_OF_RANGE("22003"),
DATA_EXCEPTION_LENGTH_MISMATCH("22026"),
COL_NOT_FOUND("42S22");
COL_NOT_FOUND("42S22"),
ERROR_IN_ASSIGNMENT("22005");

private final String sqlStateCode;

Expand Down Expand Up @@ -59,6 +60,7 @@ public final class SQLServerException extends java.sql.SQLException {
static final String EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH = "08001";
static final String EXCEPTION_XOPEN_CONNECTION_DOES_NOT_EXIST = "08003";
static final String EXCEPTION_XOPEN_CONNECTION_FAILURE = "08006"; // After connection was connected OK
static final String EXCEPTION_XOPEN_ERROR_IN_ASSIGNMENT = "22005"; // Error code is the same in both SQL-99 and X/Open

static final String LOG_CLIENT_CONNECTION_ID_PREFIX = " ClientConnectionId:";

Expand Down Expand Up @@ -302,6 +304,8 @@ static String mapFromXopen(String state) {
return "08S01";
case SQLServerException.EXCEPTION_XOPEN_CONNECTION_FAILURE:
return "08S01";
case SQLServerException.EXCEPTION_XOPEN_ERROR_IN_ASSIGNMENT:
return "22005";
default:
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,20 @@ public void testUpdateMisc() throws Exception {
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
}

// Verify SQLState 22005 is in exception for conversion errors
try {
Timestamp timestamp = Timestamp.valueOf("9999-12-31 23:59:59.998");
rs.updateTimestamp(1, timestamp);
rs.updateRow();
rs.getLong(1);
} catch (SQLServerException e) {
assertEquals("22005", e.getSQLState());
}

if (!exceptionThrown) {
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
}

// Update time(5) from Timestamp with nanos more precise than 100ns
Timestamp ts = Timestamp.valueOf("2010-01-12 11:05:23");
ts.setNanos(987659999);
Expand Down

0 comments on commit a2f389a

Please sign in to comment.