Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,6 @@ def test_fetchmany(self):
res = self.cu.fetchmany(100)
self.assertEqual(res, [])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_fetchmany_kw_arg(self):
"""Checks if fetchmany works with keyword arguments"""
self.cu.execute("select name from test")
Expand Down
17 changes: 13 additions & 4 deletions stdlib/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,12 @@ mod _sqlite {
statement: Option<PyRef<Statement>>,
}

#[derive(FromArgs)]
struct FetchManyArgs {
#[pyarg(any, name = "size", optional)]
size: Option<c_int>,
}

#[pyclass(with(Constructor, IterNext, Iterable), flags(BASETYPE))]
impl Cursor {
fn new(
Expand Down Expand Up @@ -1684,14 +1690,17 @@ mod _sqlite {
#[pymethod]
fn fetchmany(
zelf: &Py<Self>,
max_rows: OptionalArg<c_int>,
args: FetchManyArgs,
vm: &VirtualMachine,
) -> PyResult<Vec<PyObjectRef>> {
let max_rows = max_rows.unwrap_or_else(|| zelf.arraysize.load(Ordering::Relaxed));
let max_rows = args
.size
.unwrap_or_else(|| zelf.arraysize.load(Ordering::Relaxed));

let mut list = vec![];
while let PyIterReturn::Return(row) = Self::next(zelf, vm)? {
while let PyIterReturn::Return(row) = Cursor::next(zelf, vm)? {
list.push(row);
if list.len() as c_int >= max_rows {
if max_rows > 0 && list.len() as c_int >= max_rows {
break;
}
}
Expand Down
Loading