If an exception occurs when going through a database,
the cursors will not be correctly reset.
If I manually set the cursor to None (by doing db.dbc =
None) it will work fine.
>>> db = bsddb.btopen('/tmp/test.db', 'c')
>>> db.first()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/bsddb/__init__.py", line
264, in first
rv = self.dbc.first()
_bsddb.DBNotFoundError: (-30990, 'DB_NOTFOUND: No
matching key/data pair found')
>>> db['foo'] = 'bar'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/bsddb/__init__.py", line
217, in __setitem__
self._closeCursors()
File "/usr/lib/python2.4/bsddb/__init__.py", line
192, in _closeCursors
self.saved_dbc_key = c.current(0,0,0)[0]
bsddb._db.DBInvalidArgError: (22, 'Invalid argument --
Cursor position must be set before performing this
operation')
Here, I first open a new database. Since it is empty,
db.first() will fail. When I after that try to add a
key/value pair to the database it fails, since it tries
to close an invalid cursor.
>>> db = bsddb.btopen('/tmp/test.db', 'c')
>>> db.first()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/bsddb/__init__.py", line
264, in first
rv = self.dbc.first()
_bsddb.DBNotFoundError: (-30990, 'DB_NOTFOUND: No
matching key/data pair found')
>>> db.dbc = None
>>> db['foo'] = 'bar'
>>> db
{'foo': 'bar'}
Here I do "db.dbc = None" after the exception and now
it works just fine.
|