fetchmany accepts None as size, meaning the default arraysize

without this care, extending fetchmany in subclasses becomes tricky.

Closes ticket #84.
This commit is contained in:
Daniele Varrazzo 2012-01-10 01:32:45 +00:00
parent 09a8e7bf1f
commit dcc60131a9
2 changed files with 18 additions and 1 deletions

7
NEWS
View File

@ -1,3 +1,10 @@
What's new in psycopg 2.4.5
---------------------------
- Fixed fetchmany() with no argument in cursor subclasses
(ticket #84).
What's new in psycopg 2.4.4
---------------------------

View File

@ -850,13 +850,23 @@ psyco_curs_fetchmany(cursorObject *self, PyObject *args, PyObject *kwords)
int i;
PyObject *list, *res;
PyObject *pysize = NULL;
long int size = self->arraysize;
static char *kwlist[] = {"size", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwords, "|l", kwlist, &size)) {
/* allow passing None instead of omitting the *size* argument,
* or using the method from subclasses would be a problem */
if (!PyArg_ParseTupleAndKeywords(args, kwords, "|O", kwlist, &pysize)) {
return NULL;
}
if (pysize && pysize != Py_None) {
size = PyInt_AsLong(pysize);
if (size == -1 && PyErr_Occurred()) {
return NULL;
}
}
EXC_IF_CURS_CLOSED(self);
if (_psyco_curs_prefetch(self) < 0) return NULL;
EXC_IF_NO_TUPLES(self);