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

Fix #1325, return correct sql state when connection is closed #1326

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
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial
SharedTimer getSharedTimer() throws SQLServerException {
if (state == State.Closed) {
SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"),
null, false);
SQLServerException.EXCEPTION_XOPEN_CONNECTION_FAILURE, false);
}
if (null == sharedTimer) {
this.sharedTimer = SharedTimer.getTimer();
Expand Down Expand Up @@ -1167,7 +1167,7 @@ public String toString() {
void checkClosed() throws SQLServerException {
if (isSessionUnAvailable()) {
SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"),
null, false);
SQLServerException.EXCEPTION_XOPEN_CONNECTION_FAILURE, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ SQLServerConnection getWrappedConnection() {
void checkClosed() throws SQLServerException {
if (!bIsOpen) {
SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"),
null, false);
SQLServerException.EXCEPTION_XOPEN_CONNECTION_FAILURE, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public void testClosedConnection() throws SQLException {
} catch (SQLServerException e) {
assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"),
TestResource.getResource("R_wrongExceptionMessage"));
assertEquals("08S01", e.getSQLState(), TestResource.getResource("R_wrongSqlState"));
}
try (Connection conn = getConnection()) {
conn.close();
Expand All @@ -433,6 +434,7 @@ public void testClosedConnection() throws SQLException {
} catch (SQLServerException e) {
assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"),
TestResource.getResource("R_wrongExceptionMessage"));
assertEquals("08S01", e.getSQLState(), TestResource.getResource("R_wrongSqlState"));
}
}

Expand Down Expand Up @@ -567,6 +569,7 @@ public void testClientConnectionId() throws Exception {
} catch (SQLException e) {
assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"),
TestResource.getResource("R_wrongExceptionMessage"));
assertEquals("08S01", e.getSQLState(), TestResource.getResource("R_wrongSqlState"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected Object[][] getContents() {
{"R_connectionReset", "Connection reset"}, {"R_unknownException", "Unknown exception"},
{"R_deadConnection", "Dead connection should be invalid"},
{"R_wrongExceptionMessage", "Wrong exception message"},
{"R_wrongSqlState", "Wrong sql state"},
{"R_parameterNotDefined", "Parameter {0} was not defined"},
{"R_unexpectedExceptionContent", "Unexpected content in exception message"},
{"R_connectionClosed", "The connection has been closed"},
Expand Down