Mischiefblog
I make apps for other people

Got transactions working in BDB 4.7 and Python

Posted by Chris Jones
On September 26th, 2008 at 07:44

Permalink | Trackback | Links In |

Comments Off on Got transactions working in BDB 4.7 and Python
Posted in Python

I’ve been working on a personal, side-project for about a week. This morning, I finally got transactions working. I need to learn a little more about BDB tuning and I’m not planning on releasing my code until I’m happier with it and it’s been tested more thoroughly.

Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Configure
>>> cfg = Configure.Configure()
>>> class Alpha:
... def __init__(self):
... self.field = 'alpha'
...
>>> cfg.databases['objects'][1].get('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RefCache.py", line 110, in get
value = self.repository.get(key)
File "Repository.py", line 104, in get
raise KeyError, key
KeyError: 'a'
>>> txn = cfg.databases['objects'][1].beginTransaction()
>>> a = Alpha()
>>> cfg.databases['objects'][1].put('a', a, txn)
>>> cfg.databases['objects'][1].commitTransaction(txn)
>>> a.field
'alpha'
>>> a = None
>>> a
>>> a = cfg.databases['objects'][1].get('a')
>>> a.field
'alpha'
>>> b = Alpha()
>>> b.field = 'beta'
>>> txn = cfg.databases['objects'][1].beginTransaction()
>>> cfg.databases['objects'][1].put('b', b, txn)
>>> cfg.databases['objects'][1].rollbackTransaction(txn)
>>> cfg.shutdown()
>>> ^D
 
$ python
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Configure
>>> cfg = Configure.Configure()
>>> class Alpha:
... def __init__(self):
... self.field = 'alpha'
...
>>> b = cfg.databases['objects'][1].get('b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RefCache.py", line 110, in get
value = self.repository.get(key)
File "Repository.py", line 104, in get
raise KeyError, key
KeyError: 'b'
>>> a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> a = cfg.databases['objects'][1].get('a')
>>> a.field
'alpha'
>>> a = None
>>> a
>>> cfg.shutdown()
>>> ^D
 
$ db_stat -e -h db
Fri Sep 26 07:35:53 2008 Local time
0x120897 Magic number
0 Panic value
4.7.25 Environment version
...trimmed...

Comments are closed.