2

I am attempting to open a *.bdb file using python package: bsddb . I have confirmed the file is a Berkeley DB (Btree, version 9) by using file command in Linux.

However, when I attempt to open using the following script in Python: db2 = bsddb.btopen('FeatureVector.bdb')

I get the error BDB0590: files containing multiple databases may only be opened read-only.

I attempted to open as read-only by adding a r flag, and it opens, but when I try to iterate through all values, only one key is returned without a value.

Any ideas?

Here is the code in full

import bsddb

db2 = bsddb.btopen('FeatureVector.bdb')

for k, v in db2.iteritems():
    print k, v

And it is returning:

FeatureVector, which is the name of the file. I guess a follow-up question is how do I view the different databases inside of the file?

Pipo
  • 101
  • 1
  • 6
  • Why do you think that getting one key with no value is incorrect? Do you have some other way of looking at the database that shows more keys? – John Gordon Mar 08 '16 at 19:55
  • Also, **show us the code** that queries the db. Maybe you're just doing it wrong, but without the code, we can't tell that. – John Gordon Mar 08 '16 at 19:56
  • Hey John, thanks for your responses I added a bit more detail to the original question based on your answers. In terms of the database only containing one key, the client that emailed the original file mentoned it should contain thousands of lines and given the fact that the file is almost 10KB, I am inclined to believe it contains more than one key. – Pipo Mar 08 '16 at 20:03
  • _thousands of lines_ in a 10KB file means each line is only a few bytes long. Are you sure the file didn't get corrupted or truncated? – John Gordon Mar 08 '16 at 20:16
  • I just tried creating a bsd database with one item, and the disk file is 32K. Are you SURE your file is intact? – John Gordon Mar 08 '16 at 20:18
  • I have just discovered a "Berkeley DB (Btree, version 9)" file and wondered what it was. I also got the "may only be opened read-only" error. I suspect this file was created while mounting an SSHFS filesystem from a Mac. The directory it's in is ~/.AppleDB. The file contains the following k,v pairs: `[('cnid2.db', '\x00\x00\x00\x02'), ('devino.db', '\x00\x00\x00\x04'), ('didname.db', '\x00\x00\x00\x06'), ('name.db', '\x00\x00\x00\x08')]` Maybe your val's just printing invisibly? But by the keys in my file and the "multiple dbs" in orig err, I think we need extra code to read multiple dbs? – Wodin May 09 '16 at 07:31

0 Answers0