mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-19 17:34:19 +01:00
Implement close() on LimboStatement
This commit is contained in:
@@ -88,6 +88,15 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboStatement_step<'l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_org_github_tursodatabase_core_LimboStatement__1close<'local>(
|
||||||
|
_env: JNIEnv<'local>,
|
||||||
|
_obj: JObject<'local>,
|
||||||
|
stmt_ptr: jlong
|
||||||
|
) {
|
||||||
|
LimboStatement::drop(stmt_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
fn row_to_obj_array<'local>(
|
fn row_to_obj_array<'local>(
|
||||||
env: &mut JNIEnv<'local>,
|
env: &mut JNIEnv<'local>,
|
||||||
row: &limbo_core::Row,
|
row: &limbo_core::Row,
|
||||||
|
|||||||
@@ -50,7 +50,11 @@ public class LimboResultSet {
|
|||||||
* cursor can only move forward.
|
* cursor can only move forward.
|
||||||
*/
|
*/
|
||||||
public boolean next() throws SQLException {
|
public boolean next() throws SQLException {
|
||||||
if (!open || isEmptyResultSet || pastLastRow) {
|
if (!open) {
|
||||||
|
throw new SQLException("The resultSet is not open");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEmptyResultSet || pastLastRow) {
|
||||||
return false; // completed ResultSet
|
return false; // completed ResultSet
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +101,11 @@ public class LimboResultSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws SQLException {
|
||||||
|
this.statement.close();
|
||||||
|
this.open = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LimboResultSet{"
|
return "LimboResultSet{"
|
||||||
|
|||||||
@@ -67,6 +67,16 @@ public class LimboStatement {
|
|||||||
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes);
|
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the current statement and releases any resources associated with it. This method calls
|
||||||
|
* the native `_close` method to perform the actual closing operation.
|
||||||
|
*/
|
||||||
|
public void close() {
|
||||||
|
_close(statementPointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private native void _close(long statementPointer);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LimboStatement{"
|
return "LimboStatement{"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class JDBC4ResultSet implements ResultSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
// TODO
|
resultSet.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -866,8 +866,7 @@ public class JDBC4ResultSet implements ResultSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClosed() throws SQLException {
|
public boolean isClosed() throws SQLException {
|
||||||
// TODO
|
return !resultSet.isOpen();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -57,4 +57,28 @@ class JDBC4ResultSetTest {
|
|||||||
// as well
|
// as well
|
||||||
assertFalse(resultSet.next());
|
assertFalse(resultSet.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resultSet_close_test() throws Exception {
|
||||||
|
stmt.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
|
||||||
|
stmt.executeUpdate("INSERT INTO users VALUES (2, 'seonwoo');");
|
||||||
|
stmt.executeQuery("SELECT * FROM users");
|
||||||
|
ResultSet resultSet = stmt.getResultSet();
|
||||||
|
|
||||||
|
assertFalse(resultSet.isClosed());
|
||||||
|
resultSet.close();
|
||||||
|
assertTrue(resultSet.isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void calling_methods_on_closed_resultSet_should_throw_exception() throws Exception {
|
||||||
|
stmt.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
|
||||||
|
stmt.executeUpdate("INSERT INTO users VALUES (2, 'seonwoo');");
|
||||||
|
stmt.executeQuery("SELECT * FROM users");
|
||||||
|
ResultSet resultSet = stmt.getResultSet();
|
||||||
|
resultSet.close();
|
||||||
|
assertTrue(resultSet.isClosed());
|
||||||
|
|
||||||
|
resultSet.next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user