summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-03-30 17:05:30 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-03-30 17:05:30 -0400
commit4df1e07bb9c43ed8d1927a90c75f3142beaa403a (patch)
tree49e11f239390c653e2d2b60c743f37395584f004 /lib/sqlalchemy
parent4a3205df84b737f5fe55914fe22eef7264f20764 (diff)
parentf84ef1f83cc64a5ea3a910b8d1bdf00b05e9ceab (diff)
downloadsqlalchemy-4df1e07bb9c43ed8d1927a90c75f3142beaa403a.tar.gz
Merge remote-tracking branch 'origin/pr/231' into pr231
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/cextension/resultproxy.c4
-rw-r--r--lib/sqlalchemy/engine/result.py9
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c
index f5593f60d..170278cff 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 f09b0b40b..afa6b4dca 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