feat(java): implement isBeforeFirst(), isAfterLast() in JDBC4ResultSet

This commit is contained in:
kimminseok
2025-10-07 14:15:10 +09:00
parent 80d11b75b1
commit fd61ddbd21
3 changed files with 56 additions and 2 deletions

View File

@@ -99,6 +99,16 @@ public final class TursoResultSet {
return lastStepResult != null && lastStepResult.isRow();
}
/** Checks whether the cursor is positioned after the last row. */
public boolean isPastLastRow() {
return pastLastRow;
}
/** Gets the current row number (0-based, 0 means before first row). */
public int getRow() {
return row;
}
/**
* Checks the status of the result set.
*

View File

@@ -413,12 +413,12 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
@Override
public boolean isBeforeFirst() throws SQLException {
throw new UnsupportedOperationException("not implemented");
return resultSet.isOpen() && resultSet.getRow() == 0 && !resultSet.isPastLastRow();
}
@Override
public boolean isAfterLast() throws SQLException {
throw new UnsupportedOperationException("not implemented");
return resultSet.isOpen() && resultSet.isPastLastRow();
}
@Override

View File

@@ -642,4 +642,48 @@ class JDBC4ResultSetTest {
assertEquals(BigDecimal.valueOf(12345.67), resultSet.getBigDecimal("amount"));
}
@Test
void test_isBeforeFirst_and_isAfterLast() throws Exception {
stmt.executeUpdate("CREATE TABLE test_position (id INTEGER);");
stmt.executeUpdate("INSERT INTO test_position VALUES (1);");
stmt.executeUpdate("INSERT INTO test_position VALUES (2);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_position");
// Before first row
assertTrue(resultSet.isBeforeFirst());
assertFalse(resultSet.isAfterLast());
// First row
resultSet.next();
assertFalse(resultSet.isBeforeFirst());
assertFalse(resultSet.isAfterLast());
// Second row
resultSet.next();
assertFalse(resultSet.isBeforeFirst());
assertFalse(resultSet.isAfterLast());
// After last row
resultSet.next();
assertFalse(resultSet.isBeforeFirst());
assertTrue(resultSet.isAfterLast());
}
@Test
void test_isBeforeFirst_with_empty_resultSet() throws Exception {
stmt.executeUpdate("CREATE TABLE test_empty (id INTEGER);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_empty");
// Before calling next()
assertTrue(resultSet.isBeforeFirst());
assertFalse(resultSet.isAfterLast());
// After calling next() on empty ResultSet
assertFalse(resultSet.next());
assertFalse(resultSet.isBeforeFirst());
assertTrue(resultSet.isAfterLast());
}
}