support specific connection types, for additional operations;
authorwenzelm
Sun, 22 Jan 2023 20:40:51 +0100
changeset 77037 164a21e5d568
parent 77036 d0151eb9ecb0
child 77038 7b5b1789a34c
support specific connection types, for additional operations;
src/Pure/General/sql.scala
--- 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 = {