◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
37 changes: 25 additions & 12 deletions crates/stdlib/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ mod _sqlite {
name: PyStrRef,
}

struct CallbackData {
obj: NonNull<PyObject>,
vm: *const VirtualMachine,
Expand Down Expand Up @@ -1023,22 +1029,29 @@ mod _sqlite {
#[pymethod]
fn cursor(
zelf: PyRef<Self>,
factory: OptionalArg<ArgCallable>,
vm: &VirtualMachine,
) -> PyResult<PyRef<Cursor>> {
zelf.db_lock(vm).map(drop)?;

let cursor = if let OptionalArg::Present(factory) = factory {
let cursor = factory.invoke((zelf.clone(),), vm)?;
let cursor = cursor.downcast::<Cursor>().map_err(|x| {
vm.new_type_error(format!("factory must return a cursor, not {}", x.class()))
})?;
let _ = unsafe { cursor.row_factory.swap(zelf.row_factory.to_owned()) };
cursor
} else {
let row_factory = zelf.row_factory.to_owned();
Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx)
};
Ok(cursor)
}

Expand Down
Loading
Toggle all file notes Toggle all file annotations