Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SQLState 22005 to driver conversion exceptions #2185

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,23 @@ public void testUpdateMisc() throws Exception {
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
}


exceptionThrown = true;
// 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);
exceptionThrown = false;
} 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
Loading