mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 12:34:22 +01:00
Implement executeQuery and executeUpdate
This commit is contained in:
@@ -12,6 +12,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.github.tursodatabase.annotations.Nullable;
|
||||
import org.github.tursodatabase.annotations.SkipNullableCheck;
|
||||
import org.github.tursodatabase.core.LimboConnection;
|
||||
import org.github.tursodatabase.core.LimboResultSet;
|
||||
import org.github.tursodatabase.core.LimboStatement;
|
||||
|
||||
public class JDBC4Statement implements Statement {
|
||||
@@ -47,15 +48,24 @@ public class JDBC4Statement implements Statement {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SkipNullableCheck
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
// TODO
|
||||
return null;
|
||||
execute(sql);
|
||||
|
||||
requireNonNull(statement, "statement should not be null after running execute method");
|
||||
return new JDBC4ResultSet(statement.getResultSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
// TODO
|
||||
execute(sql);
|
||||
|
||||
requireNonNull(statement, "statement should not be null after running execute method");
|
||||
final LimboResultSet resultSet = statement.getResultSet();
|
||||
while (resultSet.isOpen()) {
|
||||
resultSet.next();
|
||||
}
|
||||
|
||||
// TODO: return update count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Properties;
|
||||
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JDBC4ResultSetTest {
|
||||
@@ -28,26 +27,25 @@ class JDBC4ResultSetTest {
|
||||
|
||||
@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');");
|
||||
stmt.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
|
||||
stmt.executeUpdate("INSERT INTO users VALUES (1, 'sinwoo');");
|
||||
stmt.executeUpdate("INSERT INTO users VALUES (2, 'seonwoo');");
|
||||
|
||||
// first call to next occur internally
|
||||
stmt.execute("SELECT * FROM users");
|
||||
stmt.executeQuery("SELECT * FROM users");
|
||||
ResultSet resultSet = stmt.getResultSet();
|
||||
|
||||
assertTrue(resultSet.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Disabled("https://github.com/tursodatabase/limbo/pull/743#issuecomment-2600746904")
|
||||
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');");
|
||||
stmt.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
|
||||
stmt.executeUpdate("INSERT INTO users VALUES (1, 'sinwoo');");
|
||||
stmt.executeUpdate("INSERT INTO users VALUES (2, 'seonwoo');");
|
||||
|
||||
// first call to next occur internally
|
||||
stmt.execute("SELECT * FROM users");
|
||||
stmt.executeQuery("SELECT * FROM users");
|
||||
ResultSet resultSet = stmt.getResultSet();
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
Reference in New Issue
Block a user