from the default. [ticket:2209]
- engine
+ - Context manager provided by Connection.begin()
+ will issue rollback() if the commit() fails,
+ not just if an exception occurs.
+
- Use urllib.parse_qsl() in Python 2.6 and above,
no deprecation warning about cgi.parse_qsl()
[ticket:1682]
def __exit__(self, type, value, traceback):
if type is None and self.is_active:
- self.commit()
+ try:
+ self.commit()
+ except:
+ self.rollback()
+ raise
else:
self.rollback()
-
class RootTransaction(Transaction):
def __init__(self, connection):
super(RootTransaction, self).__init__(connection, None)
assert len(result.fetchall()) == 0
connection.close()
+ def test_with_interface(self):
+ connection = testing.db.connect()
+ trans = connection.begin()
+ connection.execute(users.insert(), user_id=1, user_name='user1')
+ connection.execute(users.insert(), user_id=2, user_name='user2')
+ try:
+ connection.execute(users.insert(), user_id=2, user_name='user2.5')
+ except Exception, e:
+ trans.__exit__(*sys.exc_info())
+
+ assert not trans.is_active
+ self.assert_(connection.scalar('select count(*) from '
+ 'query_users') == 0)
+
+ trans = connection.begin()
+ connection.execute(users.insert(), user_id=1, user_name='user1')
+ trans.__exit__(None, None, None)
+ assert not trans.is_active
+ self.assert_(connection.scalar('select count(*) from '
+ 'query_users') == 1)
+ connection.close()
+
def test_close(self):
connection = testing.db.connect()
transaction = connection.begin()