src/Pure/Tools/sqlite.scala
changeset 63779 9da65bc75610
parent 63778 e06e899b78d0
child 63780 163244cefb4e
--- a/src/Pure/Tools/sqlite.scala	Sun Sep 04 15:44:20 2016 +0200
+++ b/src/Pure/Tools/sqlite.scala	Sun Sep 04 17:38:22 2016 +0200
@@ -19,6 +19,21 @@
     override def toString: String = path.toString
 
     def close { connection.close }
+
+    def transaction[A](body: => A): A =
+    {
+      val auto_commit = connection.getAutoCommit
+      val savepoint = connection.setSavepoint
+
+      try {
+        connection.setAutoCommit(false)
+        val result = body
+        connection.commit
+        result
+      }
+      catch { case exn: Throwable => connection.rollback(savepoint); throw exn }
+      finally { connection.setAutoCommit(auto_commit) }
+    }
   }
 
   def open_database(path: Path): Database =