Skip to content

Commit 9ed3fdc

Browse files
committed
Extended empty array test method
1 parent 4785167 commit 9ed3fdc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/types/ArrayResultSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public boolean isFirst() throws SQLException {
458458

459459
@Override
460460
public boolean isLast() throws SQLException {
461-
return pos == length - 1;
461+
return length > 0 && pos == length - 1;
462462
}
463463

464464
@Override

jdbc-v2/src/test/java/com/clickhouse/jdbc/types/ArrayResultSetTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,22 @@ void testStringValues() throws SQLException {
283283
@Test
284284
void testEmptyArray() throws SQLException {
285285
ArrayResultSet rs = new ArrayResultSet(new Object[0], ClickHouseColumn.parse("v Array(Int32)").get(0));
286+
287+
Assert.assertTrue(rs.isBeforeFirst());
288+
Assert.assertFalse(rs.isAfterLast());
289+
Assert.assertFalse(rs.isLast());
290+
Assert.assertFalse(rs.isFirst());
291+
286292
assertFalse(rs.next());
293+
294+
Assert.assertTrue(rs.isBeforeFirst());
295+
Assert.assertFalse(rs.isAfterLast());
296+
Assert.assertFalse(rs.isLast());
297+
Assert.assertFalse(rs.isFirst());
298+
299+
Assert.assertThrows(SQLException.class, () -> rs.getString("col1"));
300+
Assert.assertThrows(SQLException.class, () -> rs.getObject("col1"));
301+
Assert.assertThrows(SQLException.class, () -> rs.getInt("col1"));
287302
}
288303

289304
@Test

0 commit comments

Comments
 (0)