diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/cextension/resultproxy.c | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/result.py | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index a87fe7b56..331fae2b2 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -263,6 +263,8 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) #if PY_MAJOR_VERSION < 3 if (PyInt_CheckExact(key)) { index = PyInt_AS_LONG(key); + if (index < 0) + index += BaseRowProxy_length(self); } else #endif @@ -271,6 +273,8 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) if ((index == -1) && PyErr_Occurred()) /* -1 can be either the actual value, or an error flag. */ return NULL; + if (index < 0) + index += BaseRowProxy_length(self); } else if (PySlice_Check(key)) { values = PyObject_GetItem(self->row, key); if (values == NULL) diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 39f4fc50c..9208686e1 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -215,10 +215,17 @@ class ResultMetaData(object): self._keymap = {} if not _baserowproxy_usecext: - # keymap indexes by integer index... + # keymap indexes by integer index: this is only used + # in the pure Python BaseRowProxy.__getitem__ + # implementation to avoid an expensive + # isinstance(key, util.int_types) in the most common + # case path self._keymap.update([ (elem[0], (elem[3], elem[4], elem[0])) for elem in raw + ] + [ + (elem[0] - num_ctx_cols, (elem[3], elem[4], elem[0])) + for elem in raw ]) # processors in key order for certain per-row |