#if PY_MAJOR_VERSION < 3
if (PyInt_CheckExact(key)) {
index = PyInt_AS_LONG(key);
+ if (index < 0)
+ index += BaseRowProxy_length(self);
} else
#endif
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)
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
{'key': (None, None, 0), 0: (None, None, 0)})
assert isinstance(row, collections.Sequence)
+ def test_rowproxy_getitem(self):
+ metadata = MetaData()
+ metadata.bind = 'sqlite://'
+ values = Table('users', metadata,
+ Column('key', String(10), primary_key=True),
+ Column('value', String(10)))
+ values.create()
+
+ values.insert().execute(key='One', value='Uno')
+ row = values.select().execute().fetchone()
+
+ assert row['key'] == 'One'
+ assert row['value'] == 'Uno'
+ assert row[0] == 'One'
+ assert row[1] == 'Uno'
+ assert row[-2] == 'One'
+ assert row[-1] == 'Uno'
+ assert row[1:0:-1] == ('Uno',)
+
@testing.requires.cextensions
def test_row_c_sequence_check(self):
import csv