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

11.2.2 backport 1943 Check for error in DONE token when fetching result sets #2001

Merged
merged 2 commits into from
Dec 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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