db_facts.pl -- a term based interface to the ODBC and SQLite libaries.

This library serves two purposes. First, term structures can be used to interact with SQL databases and second, to provide a common abstraction layer for ODBC and proSQLite libraries of SWI-Prolog.

This library is debug/1 aware: call debug(db_facts) to see what is sent to the SQL engine.

author
- Nicos Angelopoulos,
version
- 0.5 2018/3/18, fix single quote in db_holds/3, added db_max/4 and db_min/4 and examples/exam1.pl
- 0.4 + 0.3, 2016/12/22, fix code-list and enable strings as db fact arguments (and wrap of back-end loading)
- 0.2, 2016/9/18, allow mass asserts in prosqlite interface
- 0.1.0, 2013/11/1
See also
- http://stoics.org.uk/~nicos/sware/db_facts/
- files in examples/ directory
- also available as a SWI pack http://www.swi-prolog.org/pack/list
- doc/Releases.txt
license
- Perl Artistic License
To be done
- build data structures so we don't interrogate the dbs about column names and the such all the time
 db_enabled_library(-Lib)
Lib is a db backend library enabled in this run. Lib is in {odbc,sqlite}.
 db_version(-Version, -Date)
The current version. Version is a Mj:Mn:Fx term, and date is a date(Y,M,D) term.
?- db_version( 0:5:0, date(2018,3,18) ).
true.
 db_create(+Conn, +Goal)
Very simple interface for creating tables via a term representation (Goal). Goal should share functor name and arity with the table to be creating at the database identified by Conn. Arguments of Goal should be either - or + pairs. First term of the pair should be the table name and second should be its type. The column of a + pair is taken to be part of the primary key.
     db_create( phones_db, phones(name+text,telephone-text,address-text) )
 db_assert(+Goal)
Call db_assert( Conn, Goal, _Aff ) for the implied connection Conn for table that corresponds to the supplied Goal.
 db_assert(+Goal, -Affected)
Call db_assert( Conn, Goal, Affected ) for the implied connection Conn for table that corresponds to the supplied Goal.
 db_assert(+Conn, +Goal, -Affected)
Assert a table row to table matching Goal of db connection Conn. Affected is the number of rows affected by the operation.

As of db_facts v0.2 Goal can be a list of Goals with all goals asserted in a single Instert operation.

 db_holds(+Goal)
Call db_holds( Conn, Goal ) for the implied connection Conn for table that corresponds to the supplied Goal.
 db_holds(+Conn, +Goal)
Goal is partially instantiated at call, returning at backtracing all matching rows from corresponding table belonging to connection Conn.
 db_retractall(+Goal)
Call db_retractall(Conn,Goal,_Aff) for the implied connection Conn for table that corresponds to the supplied Goal.
 db_retractall(+Goal, -Affected)
Call db_retractall(Conn,Goal,Affected) for the implied connection Conn for table that corresponds to the supplied Goal.
 db_retractall(+Conn, +Goal, -Affected)
Remove all rows that correspond to the table from SQLite database identified by Conn and is named by Goal's name. The arity of Goal should also match the arity of the table to be deleted. Ground arguments are added to the Where part of the DELETE SQL statement at their respective column locations. Affected is the number of rows affected by the operation.
     db_retractall( uniprot, secondary_accessions(_,'P64943'), A ).
 db_goal_connection(+Goal, -Conn)
Locate connection serving table matching to Goal.
 db_table(+Conn, -Table) is nondet
 db_table(+Conn, ?Table, -Facet) is nondet
Table is a table of database Conn. Facet is a property of table.
 db_table_column(+Conn, -Table, -Column)
 db_table_column(+Conn, -Table, -Column, -Facet)
Table is a table in connection. Column is a column of Table and Facet is an aspect of this Column as supported by the underlying connection manager.
 db_max(+Conn, +Table, +ArgOrClm, -Max)
Find the max value for a Table, at column ArgOrClm (see db_table_column_name/4).
 db_min(+Conn, +Table, +ArgOrClm, -Min)
Find the min value for a Table, at column ArgOrClm (see db_table_column_name/4).
 db_query(+Conn, +Sql, -Row)
Get Row at a time from quering database handle Conn, with Sql statement.
 db_current_connection(?Conn)
Conn is a currently open db connection.
 db_current_connection(?Conn, -Type)
True iff Conn is a current db connection of (db_facts) Type.
 db_disconnect(+Conn)
Disconnect from an ODBC or proSQLite connection.
 db_date_sql_atom(Date, Sql)
Convert between a Prolog date/3 term and an Sql atom. The conversion is bidirectional.