Skip to content

Commit 430eb5f

Browse files
authored
Fix sqlite3 Cursor.fetchmany to not fetch rows when size=0 (#7425)
1 parent e7d2b57 commit 430eb5f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,6 @@ def test_invalid_array_size(self):
10961096
self.assertRaises(ValueError, setter, -3)
10971097
self.assertRaises(OverflowError, setter, UINT32_MAX + 1)
10981098

1099-
@unittest.expectedFailure # TODO: RUSTPYTHON fetchmany behavior with exhausted cursor differs
11001099
def test_fetchmany(self):
11011100
# no active SQL statement
11021101
res = self.cu.fetchmany()

crates/stdlib/src/_sqlite3.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,10 +1900,14 @@ mod _sqlite3 {
19001900
};
19011901

19021902
let mut list = vec![];
1903-
while let PyIterReturn::Return(row) = Cursor::next(zelf, vm)? {
1904-
list.push(row);
1905-
if max_rows > 0 && list.len() as c_int >= max_rows {
1906-
break;
1903+
let mut remaining = max_rows;
1904+
while remaining > 0 {
1905+
match Cursor::next(zelf, vm)? {
1906+
PyIterReturn::Return(row) => {
1907+
list.push(row);
1908+
remaining -= 1;
1909+
}
1910+
PyIterReturn::StopIteration(_) => break,
19071911
}
19081912
}
19091913
Ok(list)

0 commit comments

Comments
 (0)