Skip to content

Commit

Permalink
Fix #1325, return correct sql state when connection is closed (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
anilkbachola authored May 7, 2020
1 parent 2323091 commit a2fc81e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
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

0 comments on commit a2fc81e

Please sign in to comment.