src/Pure/General/postgresql.scala
changeset 65006 632bdf7b8bab
parent 65005 3278831c226d
child 65007 b6a1a1d42f5d
equal deleted inserted replaced
65005:3278831c226d 65006:632bdf7b8bab
     1 /*  Title:      Pure/General/postgresql.scala
       
     2     Author:     Makarius
       
     3 
       
     4 Support for PostgreSQL databases.
       
     5 */
       
     6 
       
     7 package isabelle
       
     8 
       
     9 
       
    10 import java.sql.{DriverManager, Connection}
       
    11 
       
    12 
       
    13 object PostgreSQL
       
    14 {
       
    15   val default_port = 5432
       
    16 
       
    17   def open_database(
       
    18     user: String,
       
    19     password: String,
       
    20     database: String = "",
       
    21     host: String = "",
       
    22     port: Int = default_port): Database =
       
    23   {
       
    24     require(user != "")
       
    25 
       
    26     val spec =
       
    27       (if (host != "") host else "localhost") +
       
    28       (if (port != default_port) ":" + port else "") + "/" +
       
    29       (if (database != "") database else user)
       
    30     val connection = DriverManager.getConnection("jdbc:postgresql://" + spec, user, password)
       
    31     new Database(spec, connection)
       
    32   }
       
    33 
       
    34   class Database private[PostgreSQL](spec: String, val connection: Connection) extends SQL_Database
       
    35   {
       
    36     override def toString: String = spec
       
    37   }
       
    38 }