8000 Fix Cursor.close() to drop statement and rows · tursodatabase/libsql-python@e9f9f59 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9f9f59

Browse files
committed
Fix Cursor.close() to drop statement and rows
1 parent 52e5213 commit e9f9f59

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,24 @@ pub struct Curs 8000 or {
330330
// SAFETY: The libsql crate guarantees that `Connection` is thread-safe.
331331
unsafe impl Send for Cursor {}
332332

333+
impl Drop for Cursor {
334+
fn drop(&mut self) {
335+
self.stmt.replace(None);
336+
self.rows.replace(None);
337+
}
338+
}
339+
333340
#[pymethods]
334341
impl Cursor {
342+
fn close(self_: PyRef<'_, Self>) -> PyResult<()> {
343+
rt().block_on(async {
344+
let cursor: &Cursor = &self_;
345+
cursor.stmt.replace(None);
346+
cursor.rows.replace(None);
347+
});
348+
Ok(())
349+
}
350+
335351
fn execute<'a>(
336352
self_: PyRef<'a, Self>,
337353
sql: String,
@@ -474,11 +490,6 @@ impl Cursor {
474490
fn rowcount(self_: PyRef<'_, Self>) -> PyResult<i64> {
475491
Ok(*self_.rowcount.borrow())
476492
}
477-
478-
fn close(_self: PyRef<'_, Self>) -> PyResult<()> {
479-
// TODO
480-
Ok(())
481-
}
482493
}
483494

484495
async fn begin_transaction(conn: &libsql_core::Connection) -> PyResult<()> {

0 commit comments

Comments
 (0)
0