Fix isBeforeFirst to return false for empty ResultSet

This commit is contained in:
kimminseok
2025-10-08 00:40:15 +09:00
parent 043a9fc7b8
commit 104c2ffc5e
3 changed files with 11 additions and 1 deletions

View File

@@ -104,6 +104,11 @@ public final class TursoResultSet {
return pastLastRow;
}
/** Checks whether the result set is empty (has no rows). */
public boolean isEmpty() {
return isEmptyResultSet;
}
/** Gets the current row number (0-based, 0 means before first row). */
public int getRow() {
return row;

View File

@@ -413,6 +413,10 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
@Override
public boolean isBeforeFirst() throws SQLException {
// Empty ResultSet should return false per JDBC spec
if (resultSet.isEmpty()) {
return false;
}
return resultSet.isOpen() && resultSet.getRow() == 0 && !resultSet.isPastLastRow();
}

View File

@@ -675,7 +675,8 @@ class JDBC4ResultSetTest {
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_empty");
// Before calling next()
assertTrue(resultSet.isBeforeFirst());
// Empty ResultSet should return false for isBeforeFirst()
assertFalse(resultSet.isBeforeFirst());
assertFalse(resultSet.isAfterLast());
// After calling next() on empty ResultSet