prepare() won't raise if no transaction is in progress;
this was a regression introduced in 0.6. [ticket:1998]
+ - Threadlocal engine returns itself upon begin(),
+ begin_nested(); engine then implements contextmanager
+ methods to allow the "with" statement. [ticket:2004]
+
- postgresql
- Single element tuple expressions inside an IN clause
parenthesize correctly, also from [ticket:1984]
self.__opencount = 0
base.Connection.close(self)
-
class TLEngine(base.Engine):
"""An Engine that includes support for thread-local managed transactions."""
if not hasattr(self._connections, 'trans'):
self._connections.trans = []
self._connections.trans.append(self.contextual_connect().begin_twophase(xid=xid))
+ return self
def begin_nested(self):
if not hasattr(self._connections, 'trans'):
self._connections.trans = []
self._connections.trans.append(self.contextual_connect().begin_nested())
+ return self
def begin(self):
if not hasattr(self._connections, 'trans'):
self._connections.trans = []
self._connections.trans.append(self.contextual_connect().begin())
+ return self
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ if type is None:
+ self.commit()
+ else:
+ self.rollback()
def prepare(self):
if not hasattr(self._connections, 'trans') or \
finally:
external_connection.close()
+ def test_with_interface(self):
+ trans = tlengine.begin()
+ tlengine.execute(users.insert(), user_id=1, user_name='user1')
+ tlengine.execute(users.insert(), user_id=2, user_name='user2')
+ trans.commit()
+
+ trans = tlengine.begin()
+ tlengine.execute(users.insert(), user_id=3, user_name='user3')
+ trans.__exit__(Exception, "fake", None)
+ trans = tlengine.begin()
+ tlengine.execute(users.insert(), user_id=4, user_name='user4')
+ trans.__exit__(None, None, None)
+ eq_(
+ tlengine.execute(users.select().order_by(users.c.user_id)).fetchall(),
+ [
+ (1, 'user1'),
+ (2, 'user2'),
+ (4, 'user4'),
+ ]
+ )
+
def test_commits(self):
connection = tlengine.connect()
assert connection.execute('select count(*) from query_users'
})
mapper(Address, addresses)
-
-
class FixtureDataTest(TransactionTest):
run_inserts = 'each'