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