src/Pure/Tools/sqlite.scala
changeset 63779 9da65bc75610
parent 63778 e06e899b78d0
child 63780 163244cefb4e
equal deleted inserted replaced
63778:e06e899b78d0 63779:9da65bc75610
    17   class Database private [SQLite](path: Path, val connection: Connection)
    17   class Database private [SQLite](path: Path, val connection: Connection)
    18   {
    18   {
    19     override def toString: String = path.toString
    19     override def toString: String = path.toString
    20 
    20 
    21     def close { connection.close }
    21     def close { connection.close }
       
    22 
       
    23     def transaction[A](body: => A): A =
       
    24     {
       
    25       val auto_commit = connection.getAutoCommit
       
    26       val savepoint = connection.setSavepoint
       
    27 
       
    28       try {
       
    29         connection.setAutoCommit(false)
       
    30         val result = body
       
    31         connection.commit
       
    32         result
       
    33       }
       
    34       catch { case exn: Throwable => connection.rollback(savepoint); throw exn }
       
    35       finally { connection.setAutoCommit(auto_commit) }
       
    36     }
    22   }
    37   }
    23 
    38 
    24   def open_database(path: Path): Database =
    39   def open_database(path: Path): Database =
    25   {
    40   {
    26     val path0 = path.expand
    41     val path0 = path.expand