mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-02 16:04:20 +01:00
Implement close on LimboStatement and JDBC4Statement independently
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package org.github.tursodatabase.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Properties;
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
import org.github.tursodatabase.jdbc4.JDBC4Connection;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class LimboStatementTest {
|
||||
|
||||
private JDBC4Connection connection;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
String filePath = TestUtils.createTempFile();
|
||||
String url = "jdbc:sqlite:" + filePath;
|
||||
connection = new JDBC4Connection(url, filePath, new Properties());
|
||||
}
|
||||
|
||||
@Test
|
||||
void closing_statement_closes_related_resources() throws Exception {
|
||||
LimboStatement stmt = connection.prepare("SELECT 1");
|
||||
stmt.execute();
|
||||
|
||||
stmt.close();
|
||||
assertTrue(stmt.isClosed());
|
||||
assertFalse(stmt.getResultSet().isOpen());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.github.tursodatabase.jdbc4;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
@@ -51,4 +52,22 @@ class JDBC4StatementTest {
|
||||
stmt.execute("INSERT INTO users VALUES (1, 'limbo');");
|
||||
assertTrue(stmt.execute("SELECT * FROM users;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void close_statement_test() throws Exception {
|
||||
stmt.close();
|
||||
assertTrue(stmt.isClosed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void double_close_is_no_op() throws SQLException {
|
||||
stmt.close();
|
||||
assertDoesNotThrow(() -> stmt.close());
|
||||
}
|
||||
|
||||
@Test
|
||||
void operations_on_closed_statement_should_throw_exception() throws Exception {
|
||||
stmt.close();
|
||||
assertThrows(SQLException.class, () -> stmt.execute("SELECT 1"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user