src/Pure/General/sql.scala
changeset 77037 164a21e5d568
parent 76870 c6cdf2a641f4
child 77039 2f09dc0e6dda
--- a/src/Pure/General/sql.scala	Fri Jan 20 22:47:55 2023 +0100
+++ b/src/Pure/General/sql.scala	Sun Jan 22 20:40:51 2023 +0100
@@ -10,6 +10,9 @@
 import java.time.OffsetDateTime
 import java.sql.{DriverManager, Connection, PreparedStatement, ResultSet}
 
+import org.sqlite.jdbc4.JDBC4Connection
+import org.postgresql.PGConnection
+
 import scala.collection.mutable
 
 
@@ -302,6 +305,20 @@
 
     def connection: Connection
 
+    def sqlite_connection: Option[JDBC4Connection] =
+      connection match { case conn: JDBC4Connection => Some(conn) case _ => None }
+
+    def postgresql_connection: Option[PGConnection] =
+      connection match { case conn: PGConnection => Some(conn) case _ => None }
+
+    def the_sqlite_connection: JDBC4Connection =
+      sqlite_connection getOrElse
+        error("SQLite connection expected, but found " + connection.getClass.getName)
+
+    def the_postgresql_connection: PGConnection =
+      postgresql_connection getOrElse
+        error("PostgreSQL connection expected, but found " + connection.getClass.getName)
+
     def close(): Unit = connection.close()
 
     def transaction[A](body: => A): A = {