提交 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 ...@@ -20,6 +20,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>The experimental LOB storage mechanism now supports all features of the <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". 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><li>Filesystem parameters like "split:" didn't work in server mode with baseDir set.
</li></ul> </li></ul>
......
...@@ -2429,14 +2429,16 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2429,14 +2429,16 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* Checks if the current position is before the first row, that means next() * Checks if the current position is before the first row, that means next()
* was not called yet. * 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 * @throws SQLException if the result set is closed
*/ */
public boolean isBeforeFirst() throws SQLException { public boolean isBeforeFirst() throws SQLException {
try { try {
debugCodeCall("isBeforeFirst"); debugCodeCall("isBeforeFirst");
checkClosed(); checkClosed();
return result.getRowId() < 0; int row = result.getRowId();
int count = result.getRowCount();
return count > 0 && row < 0;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -2446,7 +2448,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2446,7 +2448,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* Checks if the current position is after the last row, that means next() * Checks if the current position is after the last row, that means next()
* was called and returned false. * 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 * @throws SQLException if the result set is closed
*/ */
public boolean isAfterLast() throws SQLException { public boolean isAfterLast() throws SQLException {
...@@ -2455,7 +2457,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -2455,7 +2457,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
checkClosed(); checkClosed();
int row = result.getRowId(); int row = result.getRowId();
int count = result.getRowCount(); int count = result.getRowCount();
return row >= count || count == 0; return count > 0 && row >= count;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
...@@ -54,6 +54,7 @@ public class TestResultSet extends TestBase { ...@@ -54,6 +54,7 @@ public class TestResultSet extends TestBase {
stat = conn.createStatement(); stat = conn.createStatement();
testBeforeFirstAfterLast();
testParseSpecialValues(); testParseSpecialValues();
testSpecialLocale(); testSpecialLocale();
testSubstringPrecision(); testSubstringPrecision();
...@@ -88,6 +89,31 @@ public class TestResultSet extends TestBase { ...@@ -88,6 +89,31 @@ public class TestResultSet extends TestBase {
} }
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 { private void testParseSpecialValues() throws SQLException {
for (int i = -10; i < 10; i++) { for (int i = -10; i < 10; i++) {
testParseSpecialValue("" + ((long) Integer.MIN_VALUE + i)); testParseSpecialValue("" + ((long) Integer.MIN_VALUE + i));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论