Skip to content

Commit 3d1616a

Browse files
author
Erlend E. Aasland
committed
Address review
1 parent 68010fe commit 3d1616a

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

Modules/_sqlite/clinic/cursor.c.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,16 @@ PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
141141
"fetchmany($self, /, size=<unrepresentable>)\n"
142142
"--\n"
143143
"\n"
144-
"Fetches several rows from the resultset.");
144+
"Fetches several rows from the resultset.\n"
145+
"\n"
146+
" size\n"
147+
" The number of rows to fetch. Defaults to the cursor\'s arraysize.");
145148

146149
#define PYSQLITE_CURSOR_FETCHMANY_METHODDEF \
147150
{"fetchmany", (PyCFunction)(void(*)(void))pysqlite_cursor_fetchmany, METH_FASTCALL|METH_KEYWORDS, pysqlite_cursor_fetchmany__doc__},
148151

149152
static PyObject *
150-
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
153+
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, PyObject *maxrows_obj);
151154

152155
static PyObject *
153156
pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -157,7 +160,7 @@ pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize
157160
static _PyArg_Parser _parser = {NULL, _keywords, "fetchmany", 0};
158161
PyObject *argsbuf[1];
159162
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
160-
int maxrows = self->arraysize;
163+
PyObject *maxrows_obj = NULL;
161164

162165
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
163166
if (!args) {
@@ -166,12 +169,9 @@ pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize
166169
if (!noptargs) {
167170
goto skip_optional_pos;
168171
}
169-
maxrows = _PyLong_AsInt(args[0]);
170-
if (maxrows == -1 && PyErr_Occurred()) {
171-
goto exit;
172-
}
172+
maxrows_obj = args[0];
173173
skip_optional_pos:
174-
return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
174+
return_value = pysqlite_cursor_fetchmany_impl(self, maxrows_obj);
175175

176176
exit:
177177
return return_value;
@@ -256,4 +256,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
256256
{
257257
return pysqlite_cursor_close_impl(self);
258258
}
259-
/*[clinic end generated code: output=8b5ffd9029d33cd8 input=a9049054013a1b77]*/
259+
/*[clinic end generated code: output=53cab2e724cd2ba5 input=a9049054013a1b77]*/

Modules/_sqlite/cursor.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,18 +822,26 @@ pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
822822
/*[clinic input]
823823
_sqlite3.Cursor.fetchmany as pysqlite_cursor_fetchmany
824824
825-
size as maxrows: int(c_default='self->arraysize', py_default='<unrepresentable>') = 1
825+
size as maxrows_obj: object = NULL
826+
The number of rows to fetch. Defaults to the cursor's arraysize.
826827
827828
Fetches several rows from the resultset.
828829
[clinic start generated code]*/
829830

830831
static PyObject *
831-
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows)
832-
/*[clinic end generated code: output=a8ef31fea64d0906 input=e436f4f150e78b9b]*/
832+
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, PyObject *maxrows_obj)
833+
/*[clinic end generated code: output=91a37190dafbc2de input=d8c699ff7e0db461]*/
833834
{
834835
PyObject* row;
835836
PyObject* list;
836837
int counter = 0;
838+
int maxrows;
839+
840+
if (maxrows_obj == NULL) {
841+
maxrows = self->arraysize;
842+
} else if (PyLong_Check(maxrows_obj) < 0) {
843+
maxrows = PyLong_AsLong(maxrows_obj);
844+
}
837845

838846
list = PyList_New(0);
839847
if (!list) {

0 commit comments

Comments
 (0)