14
14
>>> from canonical.database.sqlbase import ZopelessTransactionManager
15
>>> ztm = ZopelessTransactionManager.initZopeless(
16
... dbuser='launchpad_main')
18
The returned transaction manager happens to be the same as the
19
ZopelessTransactionManager class:
21
>>> ztm is ZopelessTransactionManager
15
>>> ZopelessTransactionManager.initZopeless(dbuser='launchpad_main')
24
17
After initZopeless() has been called, the '_installed' attribute of
25
18
ZopelessTransactionManager will be set to the transaction manager:
27
>>> ZopelessTransactionManager._installed is ztm
20
>>> ZopelessTransactionManager._installed is ZopelessTransactionManager
30
23
The initZopeless() call defaults to read committed isolation:
35
28
>>> print c.fetchone()[0]
38
We can commit transactions:
40
>>> c.execute("UPDATE person SET name = 'something' WHERE id = 1")
43
We can also explicitly start transactions with begin(), and abort
48
>>> c.execute("UPDATE person SET name = 'blah' WHERE id = 1")
51
>>> c.execute("SELECT name FROM person WHERE id = 1")
52
>>> print c.fetchone()[0]
55
31
The uninstall() method can be used to uninstall the transaction
34
>>> ZopelessTransactionManager.uninstall()
59
35
>>> print ZopelessTransactionManager._installed
62
38
We can log in as alternative users with initZopeless():
64
>>> ztm = ZopelessTransactionManager.initZopeless(dbuser='testadmin')
40
>>> ZopelessTransactionManager.initZopeless(dbuser='testadmin')
66
42
>>> c.execute("SELECT current_user")
67
43
>>> print c.fetchone()[0]
45
>>> ZopelessTransactionManager.uninstall()
71
47
Or we can specify other transaction isolation modes:
73
49
>>> from canonical.database.sqlbase import (
74
50
... ISOLATION_LEVEL_SERIALIZABLE)
75
>>> ztm = ZopelessTransactionManager.initZopeless(
51
>>> ZopelessTransactionManager.initZopeless(
76
52
... dbuser='librarian', isolation=ISOLATION_LEVEL_SERIALIZABLE)
78
54
>>> c.execute("SHOW transaction_isolation")
79
55
>>> print c.fetchone()[0]
57
>>> ZopelessTransactionManager.uninstall()