Skip to content

Commit

Permalink
11.2.2 backport 1943 Check for error in DONE token when fetching resu…
Browse files Browse the repository at this point in the history
…lt sets (#2001)
  • Loading branch information
tkyc committed Dec 14, 2022
1 parent 1b43d24 commit 3e52136
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ protected Object[][] getContents() {
{"R_serverCertError", "Error validating Server Certificate: {0}: {1}."},
{"R_SecureStringInitFailed", "Failed to initialize SecureStringUtil to store secure strings"},
{"R_ALPNFailed", "Failed to negotiate Application-Layer Protocol {0}. Server returned: {1}."},
{"R_serverError", "An error occurred during the current command (Done status {0})."},
{"R_serverError", "An error occurred during the current command (Done status {0}). {1}"},
};
}
// @formatter:on
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
}
SQLServerError databaseError = this.getDatabaseError();
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_serverError"));
Object[] msgArgs = {status};
Object[] msgArgs = {status, (databaseError != null) ? databaseError.getErrorMessage() : ""};
SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), null, false);
}

Expand Down Expand Up @@ -1794,8 +1794,9 @@ final boolean fetchBufferNext() throws SQLServerException {
RowType fetchBufferCurrentRowType = RowType.UNKNOWN;
try {
fetchBufferCurrentRowType = fetchBuffer.nextRow();
if (fetchBufferCurrentRowType.equals(RowType.UNKNOWN))
if (fetchBufferCurrentRowType.equals(RowType.UNKNOWN)) {
return false;
}
} catch (SQLServerException e) {
currentRow = AFTER_LAST_ROW;
rowErrorException = e;
Expand Down Expand Up @@ -5489,8 +5490,7 @@ final RowType nextRow() throws SQLServerException {
while (null != tdsReader && !done && fetchBufferCurrentRowType.equals(RowType.UNKNOWN))
TDSParser.parse(tdsReader, fetchBufferTokenHandler);

if (fetchBufferCurrentRowType.equals(RowType.UNKNOWN)
&& null != fetchBufferTokenHandler.getDatabaseError()) {
if (null != fetchBufferTokenHandler.getDatabaseError()) {
SQLServerException.makeFromDatabaseError(stmt.connection, null,
fetchBufferTokenHandler.getDatabaseError().getErrorMessage(),
fetchBufferTokenHandler.getDatabaseError(), false);
Expand Down Expand Up @@ -5550,6 +5550,7 @@ final void processResponse(TDSReader responseTDSReader) throws SQLServerExceptio
tdsReader = responseTDSReader;
discardFetchBuffer();
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/StreamDone.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void setFromTDS(TDSReader tdsReader) throws SQLServerException {
* @return true if error
*/
/* L0 */ final boolean isError() {
return (status & TDS.DONE_ERROR) != 0;
return (((status & TDS.DONE_ERROR) != 0) || ((status & TDS.DONE_SRVERROR) != 0));
}

/**
Expand Down

0 comments on commit 3e52136

Please sign in to comment.