[pybsddb] Using transactions

Albert Chin pybsddb at mlists.thewrittenword.com
Tue May 13 20:28:52 CEST 2014


I've built pybsddb-6.0.1 against db-4.7.25. I tried the following
program expecting the transaction around d.put() to work, but it
failed:

$ cat t.py
  #!/usr/bin/python

  from bsddb3 import db

  e = db.DBEnv ()
  e.set_get_returns_none (0)

  e.open (None, db.DB_CREATE | db.DB_PRIVATE | db.DB_RECOVER | \
          db.DB_INIT_LOCK | db.DB_INIT_LOG | db.DB_INIT_MPOOL | \
          db.DB_INIT_TXN)
  d = db.DB (e)
  d.set_get_returns_none (0)
  d.open ('files.db', dbtype = db.DB_BTREE,
          flags = db.DB_CREATE, mode = 0664)

  t = e.txn_begin (None, db.DB_TXN_NOWAIT)
  d.put ('foo', 'bar', t)
  t.commit ()

  d.close ()
  e.close ()

$ ./t.py
Traceback (most recent call last):
  File "./t.py", line 17, in <module>
    d.put ('foo', 'bar', t)
bsddb3.db.DBInvalidArgError: (22, 'Invalid argument -- Transaction specified for a non-transactional database')

The fix was to open the database with db.DB_AUTO_COMMIT. Is this what
is required to get transaction support to work?

-- 
albert chin (china at thewrittenword.com)


More information about the pybsddb mailing list