By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

Trouble creating bsddb database

P: 7
I am trying to create a bsddb database where I would like to store all the relevant database files created by my application under one directory.

My code looks as follows:

Expand|Select|Wrap|Line Numbers
  1. from bsddb import db
  2. from os import mkdir
  3. from os.path import exists
  4.  
  5. homeDir = 'pidgindb'
  6. db_env = db.DBEnv()
  7. db_env.set_cachesize(0, 1024*1024*50)
  8. if not exists(homeDir):
  9.     homeDir = mkdir(homeDir)
  10. db_env.open(homeDir, db.DB_INIT_MPOOL|db.DB_CREATE)
  11.  
  12. pidgin = db.DB(db_env)
  13. pidgin.open('pidgin',None,db.DB_BTREE,db.DB_CREATE,0660)
  14. pidgin['apple'] = 'fruit'
  15. pidgin['carrot'] = 'vegetable'
  16. pidgin.close()
  17.  
When I run the script for the first time, it creates all the database files (__db.001
, __db.002, pidgin) in the current directory. When I run it for the second time, it behaves correctly and creates the database files in the dir specified while opening DBEnv. Is this a bug, or am I doing something wrong?

My environment: Windows, Python 2.4.3, bsddb 4.3.0.1

Thanks!
May 14 '07 #1
Share this Question
Share on Google+
2 Replies


bartonc
Expert 5K+
P: 6,596
I am trying to create a bsddb database where I would like to store all the relevant database files created by my application under one directory.

My code looks as follows:

Expand|Select|Wrap|Line Numbers
  1. from bsddb import db
  2. from os import mkdir
  3. from os.path import exists
  4.  
  5. homeDir = 'pidgindb'
  6. db_env = db.DBEnv()
  7. db_env.set_cachesize(0, 1024*1024*50)
  8. if not exists(homeDir):
  9.     homeDir = mkdir(homeDir)
  10. db_env.open(homeDir, db.DB_INIT_MPOOL|db.DB_CREATE)
  11.  
  12. pidgin = db.DB(db_env)
  13. pidgin.open('pidgin',None,db.DB_BTREE,db.DB_CREATE,0660)
  14. pidgin['apple'] = 'fruit'
  15. pidgin['carrot'] = 'vegetable'
  16. pidgin.close()
  17.  
When I run the script for the first time, it creates all the database files (__db.001
, __db.002, pidgin) in the current directory. When I run it for the second time, it behaves correctly and creates the database files in the dir specified while opening DBEnv. Is this a bug, or am I doing something wrong?

My environment: Windows, Python 2.4.3, bsddb 4.3.0.1

Thanks!
I'd throw a print statement in here:
Expand|Select|Wrap|Line Numbers
  1. if not exists(homeDir):
  2.     homeDir = mkdir(homeDir)
  3.     print homeDir
I'm guessing that you are getting a fully qualified path that has spaces in it. You'll want to us some os.path functions to strip or otherwise convert to a valid db_env.open() path.
May 14 '07 #2

P: 7
I'd throw a print statement in here:
Expand|Select|Wrap|Line Numbers
  1. if not exists(homeDir):
  2.     homeDir = mkdir(homeDir)
  3.     print homeDir
I'm guessing that you are getting a fully qualified path that has spaces in it. You'll want to us some os.path functions to strip or otherwise convert to a valid db_env.open() path.
Thanks, printing that out did solve the problem! homeDir was getting set to None when running the script for the first time.
May 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.