On my system with db4, I noticed that whichdb doesn't
know anything about more recent database types created
by the bsddb module.
Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
[GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>>
>>> from whichdb import *
>>> import bsddb
>>>
>>> dbfile= "hash"
>>> bsddb.hashopen( dbfile)
{}
>>> whichdb( dbfile)
'dbhash'
>>> # yay
...
>>> dbfile= "btree"
>>> bsddb.btopen( dbfile)
{}
>>> whichdb( dbfile)
''
>>> # bah
...
>>> dbfile= "recno"
>>> bsddb.rnopen( dbfile)
{}
>>> whichdb( dbfile)
''
>>> # humbug!
It looks like both these database types share:
#define DB_BTREEMAGIC 0x053162
So this might be a start:
--- Python-2.5c1/Lib/whichdb.py.orig 2005-02-05
22:57:08.000000000 -0800
+++ Python-2.5c1/Lib/whichdb.py 2006-08-28
13:46:57.000000000 -0700
@@ -109,6 +109,10 @@
if magic in (0x00061561, 0x61150600):
return "dbhash"
+ # Check for binary tree
+ if magic == 0x00053162:
+ return "btree"
+
# Unknown
return ""
But alas, I'm not clear on the best way to
differentiate between btree and recno.
The above example is on 2.4 but persists in 2.5.
|