dbapi.py
branchstable
changeset 5100 04c71ebf38a5
parent 5032 e3fa27fc0d9a
child 5174 78438ad513ca
child 5307 228932b4f8c5
--- a/dbapi.py	Wed Mar 31 11:41:20 2010 +0200
+++ b/dbapi.py	Wed Mar 31 11:52:15 2010 +0200
@@ -367,6 +367,16 @@
             return '<Connection %s (anonymous)>' % self.sessionid
         return '<Connection %s>' % self.sessionid
 
+    def __enter__(self):
+        return self.cursor()
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        if exc_type is None:
+            self.commit()
+        else:
+            self.rollback()
+            return False #propagate the exception
+
     def request(self):
         return DBAPIRequest(self.vreg, self)