Trouble creating bsddb database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brainstaurm
    New Member
    • May 2007
    • 7

    #1

    Trouble creating bsddb database

    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:

    Code:
    from bsddb import db
    from os import mkdir
    from os.path import exists
    
    homeDir = 'pidgindb'
    db_env = db.DBEnv()
    db_env.set_cachesize(0, 1024*1024*50)
    if not exists(homeDir):
        homeDir = mkdir(homeDir)
    db_env.open(homeDir, db.DB_INIT_MPOOL|db.DB_CREATE)
    
    pidgin = db.DB(db_env)
    pidgin.open('pidgin',None,db.DB_BTREE,db.DB_CREATE,0660)
    pidgin['apple'] = 'fruit'
    pidgin['carrot'] = 'vegetable'
    pidgin.close()
    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!
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by brainstaurm
    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:

    Code:
    from bsddb import db
    from os import mkdir
    from os.path import exists
    
    homeDir = 'pidgindb'
    db_env = db.DBEnv()
    db_env.set_cachesize(0, 1024*1024*50)
    if not exists(homeDir):
        homeDir = mkdir(homeDir)
    db_env.open(homeDir, db.DB_INIT_MPOOL|db.DB_CREATE)
    
    pidgin = db.DB(db_env)
    pidgin.open('pidgin',None,db.DB_BTREE,db.DB_CREATE,0660)
    pidgin['apple'] = 'fruit'
    pidgin['carrot'] = 'vegetable'
    pidgin.close()
    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:
    Code:
    if not exists(homeDir):
        homeDir = mkdir(homeDir)
        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.

    Comment

    • brainstaurm
      New Member
      • May 2007
      • 7

      #3
      Originally posted by bartonc
      I'd throw a print statement in here:
      Code:
      if not exists(homeDir):
          homeDir = mkdir(homeDir)
          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.

      Comment

      Working...