mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 21:44:21 +01:00
feat(java): implement isBeforeFirst(), isAfterLast() in JDBC4ResultSet
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user