Add consumeAll method in LimboResultSet and let JDBC4Statement to use it

This commit is contained in:
김선우
2025-01-27 20:31:37 +09:00
parent 4dd2d1c64a
commit e48d7aa763
3 changed files with 17 additions and 7 deletions

View File

@@ -39,6 +39,19 @@ public class LimboResultSet {
this.statement = statement;
}
/**
* Consumes all the rows in this result set until the {@link #next()} method returns `false`.
*
* @throws SQLException if the result set is not open or if an error occurs while iterating.
*/
public void consumeAll() throws SQLException {
if (!open) {
throw new SQLException("The result set is not open");
}
while (next()) {}
}
/**
* Moves the cursor forward one row from its current position. A {@link LimboResultSet} cursor is
* initially positioned before the first fow; the first call to the method <code>next</code> makes
@@ -74,9 +87,6 @@ public class LimboResultSet {
}
pastLastRow = lastStepResult.isDone();
if (pastLastRow) {
open = false;
}
return !pastLastRow;
}

View File

@@ -65,9 +65,7 @@ public class JDBC4Statement implements Statement {
requireNonNull(statement, "statement should not be null after running execute method");
final LimboResultSet resultSet = statement.getResultSet();
while (resultSet.isOpen()) {
resultSet.next();
}
resultSet.consumeAll();
// TODO: return update count;
return 0;

View File

@@ -1,9 +1,11 @@
package org.github.tursodatabase.jdbc4;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import org.github.tursodatabase.TestUtils;
@@ -79,6 +81,6 @@ class JDBC4ResultSetTest {
resultSet.close();
assertTrue(resultSet.isClosed());
resultSet.next();
assertThrows(SQLException.class, resultSet::next);
}
}