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

Retain error information in SQLServerPreparedStatement.getMetaData exceptions #1430

Merged
merged 1 commit into from
Oct 13, 2020
Merged
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 @@ -1050,7 +1050,7 @@ else if (needsPrepare)
}

@Override
public final java.sql.ResultSetMetaData getMetaData() throws SQLServerException {
public final java.sql.ResultSetMetaData getMetaData() throws SQLServerException, SQLTimeoutException {
Copy link
Contributor

@ulvii ulvii Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adding SQLTimeoutException necessary here? Could you explain this a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. buildExecuteMetaData() previously caught and wrapped the SQLTimeoutException in another exception with less info. That's been changed so that it's no longer caught, and it gets thrown directly. The JDBC API allows for throwing this exception type, so it shouldn't be rethrown with less info.

loggerExternal.entering(getClassNameLogging(), "getMetaData");
checkClosed();
boolean rsclosed = false;
Expand All @@ -1063,7 +1063,7 @@ public final java.sql.ResultSetMetaData getMetaData() throws SQLServerException
rsclosed = true;
}
if (resultSet == null || rsclosed) {
SQLServerResultSet emptyResultSet = (SQLServerResultSet) buildExecuteMetaData();
SQLServerResultSet emptyResultSet = buildExecuteMetaData();
if (null != emptyResultSet)
rsmd = emptyResultSet.getMetaData();
} else if (resultSet != null) {
Expand All @@ -1080,21 +1080,18 @@ public final java.sql.ResultSetMetaData getMetaData() throws SQLServerException
* @throws SQLServerException
* @return the result set containing the meta data
*/
private ResultSet buildExecuteMetaData() throws SQLServerException {
private SQLServerResultSet buildExecuteMetaData() throws SQLServerException, SQLTimeoutException {
String fmtSQL = userSQL;

ResultSet emptyResultSet = null;
SQLServerResultSet emptyResultSet = null;
try {
fmtSQL = replaceMarkerWithNull(fmtSQL);
internalStmt = (SQLServerStatement) connection.createStatement();
emptyResultSet = internalStmt.executeQueryInternal("set fmtonly on " + fmtSQL + "\nset fmtonly off");
} catch (SQLException sqle) {
} catch (SQLServerException sqle) {
// Ignore empty result set errors, otherwise propagate the server error.
if (!sqle.getMessage().equals(SQLServerException.getErrString("R_noResultset"))) {
// if the error is not no resultset then throw a processings error.
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_processingError"));
Object[] msgArgs = {sqle.getMessage()};

SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), null, true);
throw sqle;
}
}
return emptyResultSet;
Expand Down