From e48d7aa763dc995b920bbacb68c7902551b504a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=A0=EC=9A=B0?= Date: Mon, 27 Jan 2025 20:31:37 +0900 Subject: [PATCH] Add `consumeAll` method in LimboResultSet and let JDBC4Statement to use it --- .../tursodatabase/core/LimboResultSet.java | 16 +++++++++++++--- .../tursodatabase/jdbc4/JDBC4Statement.java | 4 +--- .../tursodatabase/jdbc4/JDBC4ResultSetTest.java | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/bindings/java/src/main/java/org/github/tursodatabase/core/LimboResultSet.java b/bindings/java/src/main/java/org/github/tursodatabase/core/LimboResultSet.java index 6633dbd33..598ef22c4 100644 --- a/bindings/java/src/main/java/org/github/tursodatabase/core/LimboResultSet.java +++ b/bindings/java/src/main/java/org/github/tursodatabase/core/LimboResultSet.java @@ -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 next makes @@ -74,9 +87,6 @@ public class LimboResultSet { } pastLastRow = lastStepResult.isDone(); - if (pastLastRow) { - open = false; - } return !pastLastRow; } diff --git a/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java b/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java index eee4c95a3..1005d2e27 100644 --- a/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java +++ b/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java @@ -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; diff --git a/bindings/java/src/test/java/org/github/tursodatabase/jdbc4/JDBC4ResultSetTest.java b/bindings/java/src/test/java/org/github/tursodatabase/jdbc4/JDBC4ResultSetTest.java index 20f002733..7d62a245b 100644 --- a/bindings/java/src/test/java/org/github/tursodatabase/jdbc4/JDBC4ResultSetTest.java +++ b/bindings/java/src/test/java/org/github/tursodatabase/jdbc4/JDBC4ResultSetTest.java @@ -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); } }