[Python-bugs-list] [ python-Bugs-491888 ] whichdb lies about db type

noreply@sourceforge.net noreply@sourceforge.net
Wed, 12 Dec 2001 23:05:53 -0800


Bugs item #491888, was opened at 2001-12-11 19:22
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=491888&group_id=5470

Category: Python Library
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Richard Jones (richard)
Assigned to: Nobody/Anonymous (nobody)
Summary: whichdb lies about db type

Initial Comment:
>>> import dbm
>>> d = dbm.open('foo', 'n')
>>> d['a'] = 'b'
>>> d.close()
>>> import whichdb
>>> whichdb.whichdb('foo.db')
'dbhash'

I'm currently testing for the existence of "foo.db" 
instead of "foo" and hard-code my routines to use dbm 
if there is a "foo.db" file (since all other db 
modules that I've tested do no append ".db")

Might it also be possible to have anydbm perform a 
whichdb check in its open function, so that older 
databases are usable with newer, more feature-full 
installations that might include "better" dbm 
backends?



----------------------------------------------------------------------

>Comment By: Richard Jones (richard)
Date: 2001-12-12 23:05

Message:
Logged In: YES 
user_id=6405

Sorry about the anydbm/whichdb confusion - reading the 
source a little closer would have avoided my confusion.

Regardless, there is still a problem that on my system, 
dbm files are reported as dbhash, and dbhash can't open 
the dbm files...

[richard@co3044991-a tmp]$ python
Python 2.1.1 (#1, Aug 30 2001, 17:36:05) 
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.61mdk)] on 
linux-i386
Type "copyright", "credits" or "license" for more 
information.
>>> import dbm
>>> dbm.open('foo','n')
<dbm object at 0x812a0f0>
>>> import dbhash
>>> dbhash.open('bar', 'n')
<bsddb object at 0x812b870>
>>> 
>>> import whichdb
>>> whichdb.whichdb('foo.db')
'dbhash'
>>> whichdb.whichdb('bar')
'dbhash'
>>> dbhash.open('foo.db', 'r')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.1/dbhash.py", line 16, in open
    return bsddb.hashopen(file, flag, mode)
bsddb.error: (-30990, 'Unknown error 4294936306')
>>> dbhash.open('bar', 'r')
<bsddb object at 0x812ef48>
>>> 
[richard@co3044991-a tmp]$ file foo.db
foo.db: Berkeley DB (Hash, version 5, native byte-order)
[richard@co3044991-a tmp]$ file bar
bar: Berkeley DB (Hash, version 7, native byte-order)



----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-12-12 15:28

Message:
Logged In: YES 
user_id=21627

I fail to see the problem altogether. What system are you
on? Why do you think dbm does not create dbhash files? It is
not just that the magic says they are BSDDB DB_HASH files,
they really are of that kind?

Also, which of the APIs (dbm, dbhash) do you consider
"better"? I'd say that dbhash is better, since it builds
upon bsddb. So whichdbm, and anydbm, do use the "better" dbm
backend already?

Where is the bug?

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-11 20:28

Message:
Logged In: YES 
user_id=6380

Hm. anydmb *does* use whichdb. The problem seems to be that
the dbm file really *does* look like a BSD hash -- the Unix
file(1) command has the same problem.

But I'm not sure I understand your question. Do you have a
particular patch in mind?

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=491888&group_id=5470