Applied .executemany() iterator patch.

This commit is contained in:
Federico Di Gregorio 2005-05-09 06:52:30 +00:00
parent 431a2aec6c
commit b5b5cc71a7
2 changed files with 15 additions and 7 deletions

View File

@ -1,3 +1,8 @@
2005-05-09 Federico Di Gregorio <fog@debian.org>
* psycopg/cursor_type.c (psyco_curs_executemany): applied slightly
fixed patch from wrobell to allow iterators in .executemany().
2005-04-18 Federico Di Gregorio <fog@debian.org>
* MANIFEST.in: included debian directory.

View File

@ -395,9 +395,8 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
static PyObject *
psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
{
int i;
PyObject *operation = NULL, *vars = NULL;
PyObject *v, *iter = NULL;
static char *kwlist[] = {"query", "vars", NULL};
@ -408,23 +407,27 @@ psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
EXC_IF_CURS_CLOSED(self);
for (i = 0; i < PySequence_Size(vars); i++) {
PyObject *v = PySequence_GetItem(vars, i);
if (!v || _psyco_curs_execute(self, operation, v, 0) == 0) {
Py_XDECREF(v);
if (!PyIter_Check(vars)) {
vars = iter = PyObject_GetIter(vars);
if (iter == NULL) return NULL;
}
while ((v = PyIter_Next(vars)) != NULL) {
if (_psyco_curs_execute(self, operation, v, 0) == 0) {
Py_DECREF(v);
return NULL;
}
else {
Py_DECREF(v);
}
}
Py_XDECREF(iter);
Py_INCREF(Py_None);
return Py_None;
}
#ifdef PSYCOPG_EXTENSIONS
#define psyco_curs_mogrify_doc \
"mogrify(query, vars=None) -> return query after binding vars"