Implement JDBC4ResultSEt.java's next() method

This commit is contained in:
김선우
2025-01-19 13:15:15 +09:00
parent 73f8eab651
commit 33effdbfd4
8 changed files with 140 additions and 27 deletions

View File

@@ -22,7 +22,6 @@ public class IntegrationTest {
}
@Test
@Disabled("Doesn't work on workflow. Need investigation.")
void create_table_multi_inserts_select() throws Exception {
Statement stmt = createDefaultStatement();
stmt.execute("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");

View File

@@ -0,0 +1,58 @@
package org.github.tursodatabase.jdbc4;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import org.github.tursodatabase.TestUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class JDBC4ResultSetTest {
private Statement stmt;
@BeforeEach
void setUp() throws Exception {
String filePath = TestUtils.createTempFile();
String url = "jdbc:sqlite:" + filePath;
final JDBC4Connection connection = new JDBC4Connection(url, filePath, new Properties());
stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.CLOSE_CURSORS_AT_COMMIT);
}
@Test
void invoking_next_before_the_last_row_should_return_true() throws Exception {
stmt.execute("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
stmt.execute("INSERT INTO users VALUES (1, 'sinwoo');");
stmt.execute("INSERT INTO users VALUES (2, 'seonwoo');");
// first call to next occur internally
stmt.execute("SELECT * FROM users");
ResultSet resultSet = stmt.getResultSet();
assertTrue(resultSet.next());
}
@Test
void invoking_next_after_the_last_row_should_return_false() throws Exception {
stmt.execute("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
stmt.execute("INSERT INTO users VALUES (1, 'sinwoo');");
stmt.execute("INSERT INTO users VALUES (2, 'seonwoo');");
// first call to next occur internally
stmt.execute("SELECT * FROM users");
ResultSet resultSet = stmt.getResultSet();
while (resultSet.next()) {
// this loop will break when resultSet returns false
}
// if the previous call to next() returned false, consecutive call to next() should return false as well
assertFalse(resultSet.next());
}
}