Skip to content

Commit b4ff2e7

Browse files
committed
fixed isLast for an empty set
1 parent 03638bd commit b4ff2e7

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public boolean isFirst() throws SQLException {
545545
@Override
546546
public boolean isLast() throws SQLException {
547547
checkClosed();
548-
return !reader.hasNext() && rowPos != AFTER_LAST;
548+
return !reader.hasNext() && rowPos != AFTER_LAST && rowPos != BEFORE_FIRST;
549549
}
550550

551551
@Override

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ protected ResultSetImpl executeQueryImpl(String sql, QuerySettings settings) thr
131131
// release before this one completes.
132132
if (resultSetAutoClose) {
133133
closeCurrentResultSet();
134-
// There is a feature `closeOnComplete` that dictate closing statement when all
134+
// There is a feature `closeOnComplete` that dictates closing the statement when all
135135
// result sets are closed. Call to `closeCurrentResultSet` will trigger this statement
136-
// closure. But it should not happen because this was introduces instead of spec and will be remove in future/
137-
// So we need make this statement open again because we going to create a new result set.
136+
// closure. But it should not happen because this was introduces instead of spec and will be removed in the future.
137+
// So we need to make this statement open again because we're going to create a new result set.
138138
this.closed = false;
139139
}
140140

@@ -370,7 +370,7 @@ public int getFetchDirection() throws SQLException {
370370
public void setFetchSize(int rows) throws SQLException {
371371
ensureOpen();
372372
if (rows < 0) {
373-
throw new SQLException("rows should be greater than 0.");
373+
throw new SQLException("rows should be greater or equal to 0.");
374374
}
375375
this.fetchSize = rows;
376376
}

jdbc-v2/src/test/java/com/clickhouse/jdbc/ResultSetImplTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,22 @@ public void testCursorPosition() throws SQLException {
241241
Assert.assertFalse(rs.isFirst());
242242
Assert.assertFalse(rs.isLast());
243243
Assert.assertEquals(rs.getRow(), 0);
244+
}
244245

246+
try (ResultSet rs = stmt.executeQuery("select 1 LIMIT 0")) {
247+
Assert.assertTrue(rs.isBeforeFirst());
248+
Assert.assertFalse(rs.isAfterLast());
249+
Assert.assertFalse(rs.isFirst());
250+
Assert.assertFalse(rs.isLast());
251+
Assert.assertEquals(rs.getRow(), 0);
252+
253+
Assert.assertFalse(rs.next());
254+
255+
Assert.assertFalse(rs.isBeforeFirst()); // we stepped over the end
256+
Assert.assertTrue(rs.isAfterLast()); // we stepped over the end
257+
Assert.assertFalse(rs.isFirst());
258+
Assert.assertFalse(rs.isLast());
259+
Assert.assertEquals(rs.getRow(), 0);
245260
}
246261
}
247262
}

0 commit comments

Comments
 (0)