mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 18:33:44 +03:00
DictRow items can be updated. Patch by Alex Aster.
This commit is contained in:
parent
6f2d40405e
commit
0ad7483a2b
|
@ -1,3 +1,7 @@
|
|||
2010-12-01 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||
|
||||
* lib/extras.py: DictRow items can be updated. Patch by Alex Aster.
|
||||
|
||||
2010-11-28 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||
|
||||
* Cancel patch from Jan integrated.
|
||||
|
|
|
@ -144,6 +144,11 @@ class DictRow(list):
|
|||
x = self._index[x]
|
||||
return list.__getitem__(self, x)
|
||||
|
||||
def __setitem__(self, x, v):
|
||||
if type(x) != int:
|
||||
x = self._index[x]
|
||||
list.__setitem__(self, x, v)
|
||||
|
||||
def items(self):
|
||||
res = []
|
||||
for n, v in self._index.items():
|
||||
|
|
|
@ -85,6 +85,7 @@ class ExtrasDictCursorTests(unittest.TestCase):
|
|||
row = getter(curs)
|
||||
self.failUnless(row['foo'] == 'bar')
|
||||
self.failUnless(row[0] == 'bar')
|
||||
return row
|
||||
|
||||
def _testWithNamedCursor(self, getter):
|
||||
curs = self.conn.cursor('aname', cursor_factory=psycopg2.extras.DictCursor)
|
||||
|
@ -105,6 +106,12 @@ class ExtrasDictCursorTests(unittest.TestCase):
|
|||
row = getter(curs)
|
||||
self.failUnless(row['foo'] == 'bar')
|
||||
|
||||
def testUpdateRow(self):
|
||||
row = self._testWithPlainCursor(lambda curs: curs.fetchone())
|
||||
row['foo'] = 'qux'
|
||||
self.failUnless(row['foo'] == 'qux')
|
||||
self.failUnless(row[0] == 'qux')
|
||||
|
||||
|
||||
def if_has_namedtuple(f):
|
||||
def if_has_namedtuple_(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user