提交 44649f78 authored 作者: noelgrandin's avatar noelgrandin

Fix for bug in getMoreResults(int), because it was not resetting the update count.

上级 0cc8dcfa
......@@ -34,6 +34,7 @@ Change Log
</li><li>Terrence Huang has translated the error messages to Chinese. Thanks a lot!
</li><li>TRUNC was added as an alias for TRUNCATE.
</li><li>Small optimisation for accessing result values by column name.
</li><li>Fix for bug in Statement#getMoreResults(int)
</li></ul>
<h2>Version 1.3.166 (2012-04-08)</h2>
......
......@@ -283,26 +283,6 @@ public class JdbcStatement extends TraceObject implements Statement {
}
}
/**
* Moves to the next result set - however there is always only one result
* set. This call also closes the current result set (if there is one).
* Returns true if there is a next result set (that means - it always
* returns false).
*
* @return false
* @throws SQLException if this object is closed.
*/
public boolean getMoreResults() throws SQLException {
try {
debugCodeCall("getMoreResults");
checkClosed();
closeOldResultSet();
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Sets the name of the cursor. This call is ignored.
*
......@@ -680,6 +660,26 @@ public class JdbcStatement extends TraceObject implements Statement {
}
}
/**
* Moves to the next result set - however there is always only one result
* set. This call also closes the current result set (if there is one).
* Returns true if there is a next result set (that means - it always
* returns false).
*
* @return false
* @throws SQLException if this object is closed.
*/
public boolean getMoreResults() throws SQLException {
try {
debugCodeCall("getMoreResults");
checkClosed();
closeOldResultSet();
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Move to the next result set.
* This method always returns false.
......@@ -695,9 +695,8 @@ public class JdbcStatement extends TraceObject implements Statement {
switch (current) {
case Statement.CLOSE_CURRENT_RESULT:
case Statement.CLOSE_ALL_RESULTS:
if (resultSet != null) {
resultSet.close();
}
checkClosed();
closeOldResultSet();
break;
case Statement.KEEP_CURRENT_RESULT:
// nothing to do
......
......@@ -83,6 +83,7 @@ public class TestPreparedStatement extends TestBase {
testIdentity(conn);
}
testDataTypes(conn);
testGetMoreResults(conn);
testBlob(conn);
testClob(conn);
testParameterMetaData(conn);
......@@ -863,23 +864,39 @@ public class TestPreparedStatement extends TestBase {
rs = stat.executeQuery("SELECT VALUE FROM T_DECIMAL_0 ORDER BY ID");
checkBigDecimal(rs, new String[] { "" + Long.MAX_VALUE, "" + Long.MIN_VALUE, "10", "-20", "30", "-40" });
}
// getMoreResults
private void testGetMoreResults(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
PreparedStatement prep;
ResultSet rs;
stat.execute("CREATE TABLE TEST(ID INT)");
stat.execute("INSERT INTO TEST VALUES(1)");
prep = conn.prepareStatement("SELECT * FROM TEST");
// just to check if it doesn't throw an exception - it may be null
prep.getMetaData();
assertTrue(prep.execute());
rs = prep.getResultSet();
assertFalse(prep.getMoreResults());
assertEquals(-1, prep.getUpdateCount());
// supposed to be closed now
assertThrows(ErrorCode.OBJECT_CLOSED, rs).next();
assertEquals(-1, prep.getUpdateCount());
prep = conn.prepareStatement("UPDATE TEST SET ID = 2");
assertFalse(prep.execute());
assertEquals(1, prep.getUpdateCount());
assertFalse(prep.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
assertEquals(-1, prep.getUpdateCount());
// supposed to be closed now
assertThrows(ErrorCode.OBJECT_CLOSED, rs).next();
assertTrue(prep.getUpdateCount() == -1);
assertEquals(-1, prep.getUpdateCount());
prep = conn.prepareStatement("DELETE FROM TEST");
prep.executeUpdate();
assertFalse(prep.getMoreResults());
assertTrue(prep.getUpdateCount() == -1);
assertEquals(-1, prep.getUpdateCount());
}
private void testObject(Connection conn) throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论