Skip to content

Commit 1df8f0e

Browse files
committed
Undo invalid code optimization
It's a common mistake, but optimizing the condition breaks the contract. The code must invoke getUpdateCount() Added a stronger comment. Related to #1095
1 parent 1ff4a86 commit 1df8f0e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,18 @@ private ResultSetWrapper getFirstResultSet(Statement stmt) throws SQLException {
259259
private ResultSetWrapper getNextResultSet(Statement stmt) {
260260
// Making this method tolerant of bad JDBC drivers
261261
try {
262-
// Crazy Standard JDBC way of determining if there are more results
263-
if (stmt.getConnection().getMetaData().supportsMultipleResultSets()
264-
&& (stmt.getMoreResults() || (stmt.getUpdateCount() != -1))) {
265-
ResultSet rs = stmt.getResultSet();
266-
if (rs == null) {
267-
return getNextResultSet(stmt);
262+
if (stmt.getConnection().getMetaData().supportsMultipleResultSets()) {
263+
// Crazy Standard JDBC way of determining if there are more results
264+
// DO NOT try to 'imporove' the condition even if IDE tells you to!
265+
// It's important that getUpdateCount() is called here.
266+
if (!(!stmt.getMoreResults() && stmt.getUpdateCount() == -1)) {
267+
ResultSet rs = stmt.getResultSet();
268+
if (rs == null) {
269+
return getNextResultSet(stmt);
270+
} else {
271+
return new ResultSetWrapper(rs, configuration);
272+
}
268273
}
269-
return new ResultSetWrapper(rs, configuration);
270274
}
271275
} catch (Exception e) {
272276
// Intentionally ignored.

0 commit comments

Comments
 (0)