src/Pure/General/sql.scala
changeset 79724 54d0f6edfe3a
parent 79722 5938158733bb
child 79725 abb5eedfeecf
equal deleted inserted replaced
79723:aa77ebb2dc16 79724:54d0f6edfe3a
     1 /*  Title:      Pure/General/sql.scala
     1 /*  Title:      Pure/General/sql.scala
     2     Author:     Makarius
     2     Author:     Makarius
     3 
     3 
     4 Support for SQL databases: SQLite and PostgreSQL.
     4 Support for SQL databases: SQLite and PostgreSQL.
     5 
     5 
     6 See https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Connection.html
     6 See https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/Connection.html
     7 */
     7 */
     8 
     8 
     9 package isabelle
     9 package isabelle
    10 
    10 
    11 
    11 
   660 
   660 
   661 
   661 
   662 
   662 
   663 /** PostgreSQL **/
   663 /** PostgreSQL **/
   664 
   664 
   665 // see https://www.postgresql.org/docs/current/index.html
   665 // see https://www.postgresql.org/docs/14/index.html
   666 // see https://jdbc.postgresql.org/documentation
   666 // see https://jdbc.postgresql.org/documentation
   667 
   667 
   668 object PostgreSQL {
   668 object PostgreSQL {
   669   type Source = SQL.Source
   669   type Source = SQL.Source
   670 
   670 
   776     def insert_permissive(table: SQL.Table, sql: SQL.Source = ""): SQL.Source =
   776     def insert_permissive(table: SQL.Table, sql: SQL.Source = ""): SQL.Source =
   777       table.insert_cmd(sql = if_proper(sql, sql + " ") + "ON CONFLICT DO NOTHING")
   777       table.insert_cmd(sql = if_proper(sql, sql + " ") + "ON CONFLICT DO NOTHING")
   778 
   778 
   779 
   779 
   780     /* explicit locking: only applicable to PostgreSQL within transaction context */
   780     /* explicit locking: only applicable to PostgreSQL within transaction context */
   781     // see https://www.postgresql.org/docs/current/sql-lock.html
   781     // see https://www.postgresql.org/docs/14/sql-lock.html
   782     // see https://www.postgresql.org/docs/current/explicit-locking.html
   782     // see https://www.postgresql.org/docs/14/explicit-locking.html
   783 
   783 
   784     override def lock_tables(tables: List[SQL.Table]): PostgreSQL.Source =
   784     override def lock_tables(tables: List[SQL.Table]): PostgreSQL.Source =
   785       if_proper(tables, "LOCK TABLE " + tables.mkString(", ") + " IN ACCESS EXCLUSIVE MODE")
   785       if_proper(tables, "LOCK TABLE " + tables.mkString(", ") + " IN ACCESS EXCLUSIVE MODE")
   786 
   786 
   787 
   787 
   788     /* notifications: IPC via database server */
   788     /* notifications: IPC via database server */
   789     /*
   789     /*
   790       - see https://www.postgresql.org/docs/current/sql-notify.html
   790       - see https://www.postgresql.org/docs/14/sql-notify.html
   791       - self-notifications and repeated notifications are suppressed
   791       - self-notifications and repeated notifications are suppressed
   792       - notifications are sorted by local system time (nano seconds)
   792       - notifications are sorted by local system time (nano seconds)
   793     */
   793     */
   794 
   794 
   795     private var _receiver_buffer: Option[Map[SQL.Notification, Long]] = None
   795     private var _receiver_buffer: Option[Map[SQL.Notification, Long]] = None