| 1020 | |
| 1021 | #[pymethod] |
| 1022 | fn cursor( |
| 1023 | zelf: PyRef<Self>, |
| 1024 | args: CursorArgs, |
| 1025 | vm: &VirtualMachine, |
| 1026 | ) -> PyResult<PyObjectRef> { |
| 1027 | zelf.db_lock(vm).map(drop)?; |
| 1028 | |
| 1029 | let factory = match args.factory { |
| 1030 | OptionalArg::Present(f) => f, |
| 1031 | OptionalArg::Missing => Cursor::class(&vm.ctx).to_owned().into(), |
| 1032 | }; |
| 1033 | |
| 1034 | let cursor = factory.call((zelf.clone(),), vm)?; |
| 1035 | |
| 1036 | if !cursor.class().fast_issubclass(Cursor::class(&vm.ctx)) { |
| 1037 | return Err(vm.new_type_error(format!( |
| 1038 | "factory must return a cursor, not {}", |
| 1039 | cursor.class() |
| 1040 | ))); |
| 1041 | } |
| 1042 | |
| 1043 | if let Some(cursor_ref) = cursor.downcast_ref::<Cursor>() |
| 1044 | && let Some(factory) = zelf.row_factory.to_owned() |
| 1045 | { |
| 1046 | let _ = unsafe { cursor_ref.row_factory.swap(Some(factory)) }; |
| 1047 | } |
| 1048 | |
| 1049 | Ok(cursor) |
| 1050 | } |
| 1051 | |
| 1052 | #[pymethod] |
| 1053 | fn blobopen( |