mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Applied .executemany() iterator patch.
This commit is contained in:
parent
431a2aec6c
commit
b5b5cc71a7
|
@ -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>
|
2005-04-18 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
* MANIFEST.in: included debian directory.
|
* MANIFEST.in: included debian directory.
|
||||||
|
|
|
@ -395,9 +395,8 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
|
psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
PyObject *operation = NULL, *vars = NULL;
|
PyObject *operation = NULL, *vars = NULL;
|
||||||
|
PyObject *v, *iter = NULL;
|
||||||
|
|
||||||
static char *kwlist[] = {"query", "vars", 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);
|
EXC_IF_CURS_CLOSED(self);
|
||||||
|
|
||||||
for (i = 0; i < PySequence_Size(vars); i++) {
|
if (!PyIter_Check(vars)) {
|
||||||
PyObject *v = PySequence_GetItem(vars, i);
|
vars = iter = PyObject_GetIter(vars);
|
||||||
if (!v || _psyco_curs_execute(self, operation, v, 0) == 0) {
|
if (iter == NULL) return NULL;
|
||||||
Py_XDECREF(v);
|
}
|
||||||
|
|
||||||
|
while ((v = PyIter_Next(vars)) != NULL) {
|
||||||
|
if (_psyco_curs_execute(self, operation, v, 0) == 0) {
|
||||||
|
Py_DECREF(v);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Py_XDECREF(iter);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef PSYCOPG_EXTENSIONS
|
#ifdef PSYCOPG_EXTENSIONS
|
||||||
#define psyco_curs_mogrify_doc \
|
#define psyco_curs_mogrify_doc \
|
||||||
"mogrify(query, vars=None) -> return query after binding vars"
|
"mogrify(query, vars=None) -> return query after binding vars"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user