[Tutor] PYBSDDB help
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Fri Oct 21 01:10:30 CEST 2005
Hi Toren,
Ok, I see that you've asked your question on the pybsddb mailing list as
well a few weeks ago, which is fine.
http://lists.sourceforge.net/lists/listinfo/pybsddb-users
Unfortunately, it looks like spammers have attacked that mailing list
badly enough that it appears they've done severe damage to that community
there
We'll do what we can to help. Your call to open():
self.cadmvinfo.open(self.filename, db.DB_HASH,
db.DB_CREATE,db.DB_DUP)
appears to be the culprit.
I see that you're trying to db.DB_CREATE and db.DB_DUP as flags. I would
have expected to see something like:
db.DB_CREATE | db.DB_DUP
because flags are traditionally combined by using bitwise arithmetic.
However, DB_DUP is not a flag that should be passed off to the open()
function anyway. I suspect that your problems stem from this, since if we
don't call open() with the right arguments, then pybsddb won't do what you
want.
Let's ignore the DB_DUP stuff for the moment. According to:
http://pybsddb.sourceforge.net/bsddb3.html
the method signature for open() is:
open(filename, dbname=None, dbtype=DB_UNKNOWN, flags=0, mode=0660)
so if we're going to provide arguments that override the defaults, we'll
want to be explicit in which arguments we'ere overriding. Rather than:
self.cadmvinfo.open(self.filename, db.DB_HASH,
db.DB_CREATE)
Try:
self.cadmvinfo.open(self.filename,
dbtype=db.DB_HASH,
flags=db.DB_CREATE)
where we explictely say which arguments go where. That way, we have no
possiblity of accidently putting db.DB_HASH into the place where open()
expects a database name.
According to:
http://pybsddb.sourceforge.net/api_c/db_open.html
I don't see DB_DUP being a flag option that we pass into open(). Instead,
I see it as an option to set_flags() instead:
http://pybsddb.sourceforge.net/api_c/db_set_flags.html
So the following will probably do what you want:
self.cadmvinfo.set_flags(db.DB_DUP)
self.cadmvinfo.open(self.filename,
dbtype=db.DB_HASH,
flags=db.DB_CREATE)
This matches the usage in the test case examples in
bsddb/test/test_basics.py in the pybsddb source distribution.
Do you have any questions on this so far?
More information about the Tutor
mailing list