Change dbhash values in place using next() loop?

Martin von Loewis loewis at informatik.hu-berlin.de
Sun May 27 11:37:20 EDT 2001


Carsten Gaebler <cg at schlund.de> writes:

> This works for about half of the items, but the others remain unchanged.
> Does changing the values change the ordering of the file?

I've tried to answer these questions with the Sleepycat manuals
(http://www.sleepycat.com/docs/), and it turns out that it is not easy
to answer.

Python's bsddb uses the 1.85 seq() operation to iterate over the
sequence, which is undocumented in the current version. It turns out
that DB 3.x (and probably 2.x as well) uses a fresh cursor for each
DB185 database, and translates all seq() calls to corresponding
DBC->c_get calls.

Now, when you modify the database, Python uses put(), which translates
to DB->put if no flag is specified (and Python uses indeed 0 as the flag).

Then, the question is whether the cursor is stable across puts. It
turns out that in a hash database, it isn't:

http://www.sleepycat.com/docs/ref/am/stability.html

So it seems that you have two options:

a) convert your database into a RECNO or BTREE database, instead of a
hash database, as that will provide you with stable cursors.

b) use the DB2+ cursor API to perform the updates. That requires a
Python wrapper around DB2/DB3 interfaces, as available from

http://pybsddb.sourceforge.net/

My guess is that modifications of the data of the current cursor
guarantee some stability, although you also might need to activate
locking.

Hope this helps,
Martin



More information about the Python-list mailing list