提交 dda602ab authored 作者: christian.peter.io's avatar christian.peter.io

The functions isBeforeFirst() and isAfterLast() were not compliant to the JDBC…

The functions isBeforeFirst() and isAfterLast() were not compliant to the JDBC spec. If the ResultSet contains no rows, they must return false. Fixed.
上级 56fe07ac
......@@ -20,6 +20,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul><li>The experimental LOB storage mechanism now supports all features of the
old one. To use it, set the system property "h2.lobInDatabase" to "true".
</li><li>The functions isBeforeFirst() and isAfterLast() were not compliant to the
JDBC spec. If the ResultSet contains no rows, they must return false. Fixed.
</li><li>Filesystem parameters like "split:" didn't work in server mode with baseDir set.
</li></ul>
......
......@@ -2429,14 +2429,16 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* Checks if the current position is before the first row, that means next()
* was not called yet.
*
* @return if the current position is before the first row
* @return if there are results and the current position is before the first row
* @throws SQLException if the result set is closed
*/
public boolean isBeforeFirst() throws SQLException {
try {
debugCodeCall("isBeforeFirst");
checkClosed();
return result.getRowId() < 0;
int row = result.getRowId();
int count = result.getRowCount();
return count > 0 && row < 0;
} catch (Exception e) {
throw logAndConvert(e);
}
......@@ -2446,7 +2448,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* Checks if the current position is after the last row, that means next()
* was called and returned false.
*
* @return if the current position is after the last row
* @return if there are results and the current position is after the last row
* @throws SQLException if the result set is closed
*/
public boolean isAfterLast() throws SQLException {
......@@ -2455,7 +2457,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
checkClosed();
int row = result.getRowId();
int count = result.getRowCount();
return row >= count || count == 0;
return count > 0 && row >= count;
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -54,6 +54,7 @@ public class TestResultSet extends TestBase {
stat = conn.createStatement();
testBeforeFirstAfterLast();
testParseSpecialValues();
testSpecialLocale();
testSubstringPrecision();
......@@ -87,6 +88,31 @@ public class TestResultSet extends TestBase {
deleteDb("resultSet");
}
private void testBeforeFirstAfterLast() throws SQLException {
stat.executeUpdate("create table test(id int)");
stat.executeUpdate("insert into test values(1)");
// With a result
ResultSet rs = stat.executeQuery("select * from test");
assertTrue(rs.isBeforeFirst());
assertFalse(rs.isAfterLast());
rs.next();
assertFalse(rs.isBeforeFirst());
assertFalse(rs.isAfterLast());
rs.next();
assertFalse(rs.isBeforeFirst());
assertTrue(rs.isAfterLast());
rs.close();
// With no result
rs = stat.executeQuery("select * from test where 1 = 2");
assertFalse(rs.isBeforeFirst());
assertFalse(rs.isAfterLast());
rs.next();
assertFalse(rs.isBeforeFirst());
assertFalse(rs.isAfterLast());
rs.close();
stat.execute("drop table test");
}
private void testParseSpecialValues() throws SQLException {
for (int i = -10; i < 10; i++) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论