mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #6118 from ever0de/feat/sqlite-fetchmany-size-arg
sqlite3: Support 'size' keyword argument in `Cursor::fetchmany`
This commit is contained in:
2 files changed
+13
-6
No files matched your search
Vendored
-2
@@ -1069,8 +1069,6 @@ class CursorTests(unittest.TestCase):
|
||||
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")
|
||||
|
||||
+13
-4
@@ -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(
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user