Mailing List Archive

Need someone to try some rarely used bsddb methods
I noticed today that there is apparently still no documentation for the bsddb
module, so I started working on some. While trying out the bsddb hash object
methods, I noticed a few didn't seem to work. I tested this under Red Hat
Linux 5.0 (PC hardware) and Python 1.5.1. I used Berkeley DB v 2.3.16 with
the backwards compatibility interface, so that might be causing my problems.
I see no functional changes in the 1.5.2 version of the bsddb module, so I
doubt it's causing problems.

If you have the time, please try executing the following Python statements
and let me know what methods, if any, generate tracebacks. I will need to
know what version of Python you used, what version of Berkeley DB you used,
and for completeness, what OS platform and version you used. (If you use
version 2 of the DB library you will have to modify the bsddbmodule.c source
to include db_185.h instead of db.h.)

import bsddb
db = bsddb.hashopen("/tmp/spam.db", "c")
for i in range(10): db["%d"%i] = "%d"% (i*i)
db.keys()
db.first()
db.next()
db.last()
db.set_location('2')
db.previous()
db.sync()

The btree object (the one I use regularly) didn't have any problems. The keys
returned with the record object seem to be screwed up:

>>> db = bsddb.rnopen("/tmp/spamr.db", "c")
>>> for i in range(10): db["%d"%i] = "%d"% (i*i)
...
>>> db.keys()
['0\000\000\000', '1\000\000\000', '2\000\000\000', '3\000\000\000',
'4\000\000\000', '5\000\000\000', '6\000\000\000', '7\000\000\000',
'8\000\000\000', '9\000\000\000']

Can anyone confirm this rather odd behavior as well?

Private replies appreciated.

Thanks,

--
Skip Montanaro (skip@mojam.com, 518-372-5583)
Mojam: "Uniting the World of Music" http://www.mojam.com/
Musi-Cal: http://www.musi-cal.com/

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Need someone to try some rarely used bsddb methods [ In reply to ]
A few days ago I asked for input about how the various bsddb object
methods work with different storage types (btree, hash, recno). I got
responses from several people whose findings were consistent with mine.
The "last" and "previous" methods seemed to fail for hash databases.

It turns out they aren't supported. A little digging around in the
Berkeley DB code demonstrated that quite clearly. I will work on some
patches to the bsddb module that catch the mistake and return a more
meaningful error message along with the exception. I have yet to figure
out what is happening with the recno format databases. My
recommendation is that you only use the btree format for large
databases. (Unfortunately, anydbm.open calls bsddb.hashopen when it's
available.)

I wound up writing the section for the library reference as well. I
believe it's in the CVS repository now.

Thanks to all who replied.

--
Skip Montanaro | Mojam: "Uniting the World of Music"
http://www.mojam.com/
skip@mojam.com | Musi-Cal: http://www.musi-cal.com/
518-372-5583
Need someone to try some rarely used bsddb methods [ In reply to ]
Skip Montanaro writes:
> I wound up writing the section for the library reference as well. I
> believe it's in the CVS repository now.

It's there, along with modifications I just added to indicate the
lack of support for last() and previous() on hashtable databases.
Thanks for supporting the Python documentation efforts!


-Fred

--
Fred L. Drake, Jr. <fdrake@acm.org>
Corporation for National Research Initiatives