From: Gaƫtan de Menten Date: Sun, 11 Apr 2010 18:56:39 +0000 (+0200) Subject: - engines X-Git-Tag: rel_0_6_0~23^2~15^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa9506a0da35b78b2c4b1c62b1700fe33f5bea2e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - engines - The C extension now also works with DBAPIs which use custom sequences as row (and not only tuples). [ticket:1757] --- diff --git a/CHANGES b/CHANGES index 4831295913..99b8ffa815 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,10 @@ CHANGES as the sorting functions now require hashable objects only. [ticket:1756] +- engines + - The C extension now also works with DBAPIs which use custom + sequences as row (and not only tuples). [ticket:1757] + - sql - Restored some bind-labeling logic from 0.5 which ensures that tables with column names that overlap another column diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index 5d9100469e..50830b660f 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -150,8 +150,8 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple) PyObject **valueptr, **funcptr, **resultptr; PyObject *func, *result, *processed_value, *values_fastseq; - num_values = Py_SIZE(values); - num_processors = Py_SIZE(processors); + num_values = PySequence_Length(values); + num_processors = PyList_Size(processors); if (num_values != num_processors) { PyErr_Format(PyExc_RuntimeError, "number of values in row (%d) differ from number of column " @@ -225,7 +225,7 @@ BaseRowProxy_iter(BaseRowProxy *self) static Py_ssize_t BaseRowProxy_length(BaseRowProxy *self) { - return Py_SIZE(self->row); + return PySequence_Length(self->row); } static PyObject * @@ -233,7 +233,7 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) { PyObject *processors, *values; PyObject *processor, *value; - PyObject *record, *result, *indexobject; + PyObject *row, *record, *result, *indexobject; PyObject *exc_module, *exception; char *cstr_key; long index; @@ -303,7 +303,11 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) if (processor == NULL) return NULL; - value = PyTuple_GetItem(self->row, index); + row = self->row; + if (PyTuple_CheckExact(row)) + value = PyTuple_GetItem(row, index); + else + value = PySequence_GetItem(row, index); if (value == NULL) return NULL;