summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/cextension
diff options
context:
space:
mode:
authorGaëtan de Menten <gdementen@gmail.com>2010-04-02 20:29:37 +0200
committerGaëtan de Menten <gdementen@gmail.com>2010-04-02 20:29:37 +0200
commit7e25d8218bee860e043a73ed1c9d887ed9920855 (patch)
tree87c991af509d1f363f776ae8e26d59296d46c1a9 /lib/sqlalchemy/cextension
parentdf1b86bc1774420d240daac494be333d5c85905e (diff)
downloadsqlalchemy-7e25d8218bee860e043a73ed1c9d887ed9920855.tar.gz
- made the C version of RowProxy accept any sequence for the row, instead of
only tuples
Diffstat (limited to 'lib/sqlalchemy/cextension')
-rw-r--r--lib/sqlalchemy/cextension/resultproxy.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c
index b530b65f7..45149bebd 100644
--- a/lib/sqlalchemy/cextension/resultproxy.c
+++ b/lib/sqlalchemy/cextension/resultproxy.c
@@ -69,8 +69,8 @@ BaseRowProxy_init(BaseRowProxy *self, PyObject *args, PyObject *kwds)
Py_INCREF(parent);
self->parent = parent;
- if (!PyTuple_CheckExact(row)) {
- PyErr_SetString(PyExc_TypeError, "row must be a tuple");
+ if (!PySequence_Check(row)) {
+ PyErr_SetString(PyExc_TypeError, "row must be a sequence");
return -1;
}
Py_INCREF(row);
@@ -148,13 +148,15 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
{
Py_ssize_t num_values, num_processors;
PyObject **valueptr, **funcptr, **resultptr;
- PyObject *func, *result, *processed_value;
+ PyObject *func, *result, *processed_value, *values_fastseq;
num_values = Py_SIZE(values);
num_processors = Py_SIZE(processors);
if (num_values != num_processors) {
- PyErr_SetString(PyExc_RuntimeError,
- "number of values in row differ from number of column processors");
+ PyErr_Format(PyExc_RuntimeError,
+ "number of values in row (%d) differ from number of column "
+ "processors (%d)",
+ num_values, num_processors);
return NULL;
}
@@ -166,9 +168,11 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
if (result == NULL)
return NULL;
- /* we don't need to use PySequence_Fast as long as values, processors and
- * result are simple tuple or lists. */
- valueptr = PySequence_Fast_ITEMS(values);
+ values_fastseq = PySequence_Fast(values, "row must be a sequence");
+ if (values_fastseq == NULL)
+ return NULL;
+
+ valueptr = PySequence_Fast_ITEMS(values_fastseq);
funcptr = PySequence_Fast_ITEMS(processors);
resultptr = PySequence_Fast_ITEMS(result);
while (--num_values >= 0) {
@@ -177,6 +181,7 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
processed_value = PyObject_CallFunctionObjArgs(func, *valueptr,
NULL);
if (processed_value == NULL) {
+ Py_DECREF(values_fastseq);
Py_DECREF(result);
return NULL;
}
@@ -189,6 +194,7 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
funcptr++;
resultptr++;
}
+ Py_DECREF(values_fastseq);
return result;
}
@@ -199,19 +205,12 @@ BaseRowProxy_values(BaseRowProxy *self)
self->processors, 0);
}
-static PyTupleObject *
-BaseRowProxy_tuplevalues(BaseRowProxy *self)
-{
- return (PyTupleObject *)BaseRowProxy_processvalues(self->row,
- self->processors, 1);
-}
-
static PyObject *
BaseRowProxy_iter(BaseRowProxy *self)
{
PyObject *values, *result;
- values = (PyObject *)BaseRowProxy_tuplevalues(self);
+ values = BaseRowProxy_processvalues(self->row, self->processors, 1);
if (values == NULL)
return NULL;
@@ -395,7 +394,7 @@ BaseRowProxy_setrow(BaseRowProxy *self, PyObject *value, void *closure)
if (!PyTuple_CheckExact(value)) {
PyErr_SetString(PyExc_TypeError,
- "The 'row' attribute value must be a tuple");
+ "The 'row' attribute value must be a sequence");
return -1;
}