Did you know ... Search Documentation:
Pack sql_compiler -- prolog/sql_compiler.pl
PublicShow source

Description

This module rewrites prolog goals as SQL goals. It assumes the details of the schema are given using the following predicates:

relation/2
attribute/4
unique/2
Some example schemas are bundled with blipkit:
sql_schema/schema_go.pro
sql_schema/schema_enscore44.pro
There are also sqlmap modules that bridge between the schema and blipkit models. See for example
genomic/genome_sqlmap_enscore.pro
ontol/ontol_sqlmap_go.pro

TODO

problem with existentials being in the projection

works:

blip-sql -debug sql_compiler  -u seqfeature_sqlmap_chado_exposed_ids -u genome_bridge_from_seqfeature -r rdb/flybase prolog-to-sql -proj T "feature(G),seqfeature_db:feature_relationship(G,T,Type,Rank)"

misses join:

== blip-sql -debug sql_compiler -u seqfeature_sqlmap_chado_exposed_ids -u genome_bridge_from_seqfeature -r rdb/flybase prolog-to-sql "feature(G),seqfeature_db:feature_relationship(G,T,Type,Rank)" ==

Recursive SQL

PostgreSQL8.4 allows WITH RECURSIVE; e.g.

tree(?ID,?Parent)

struct(ID,Parent) :- struct(ID,Parent).
struct(ID,A) :- struct(ID,Parent),struct(Parent,A).

should translate to:

WITH RECURSIVE struct AS (
SELECT t.* FROM tree t WHERE id = 890
UNION ALL
SELECT t.* FROM tree t, struct s WHERE t.id = s.parent_id
)
SELECT * FROM struct;

Author

This modules is an extension of version 1.1 (Dec 21st 1992) of the Prolog to SQL compiler written by Christoph Draxler of the Univeristy of Munich.

Christoph Draxler CIS Centre for Information and Speech Processing Ludwig-Maximilians-University Munich Wagmuellerstr. 23 D 80538 Munich Tel : ++49 / +89 / 211 06 64 (-60) Fax : ++49 / +89 / 211 06 74 Mail: draxler@cis.uni-muenchen.de

It was modified by Chris Mungall to be compatible with SWI-Prolog and extended to support:

MySQL specific column types SELECT DISTINCT query rewriting for optimization additional comparison operators

Permission has been granted by the original author to distribute this software using the same license as SWI-Prolog.

RELEASE INFORMATION Current version is v. 1.1 of Dec. 21st 1992. Version 1.0 Sept. 3 1992 CJM mods 2005

 view(?Head, ?Body)[multifile]
SQL rewrite - Head is rewritten as Body. Can also be written as Head <- Body
 load_schema_defs(+SchemaFileSpec)
loads a schema into memory, allowing sql_compiler to make use of it for plterm_to_sqlterm/3

Example: load_schema_defs(bio('sql_schema/schema_enscore44'))

 plterm_to_sqlterm(+ProjectionTerm, +DatabaseGoal, ?SQLQueryTerm)
rewrite a prolog goal as a SQL Term. The SQL term can then be translated via sqlterm2atom/2
Arguments:
ProjectionTerm-
DatabaseGoal-
SQLQueryTerm-
 rewrite_query(+GoalIn, ?GoalOut) is det
 sqlterm2atom(+SQLQueryTerm, ?SQLQueryAtom) is det
translates an SQL Term to an atom that conforms to SQL syntax. see plterm_to_sqlterm/3 [Ciao: sqlterm2string]
 relation(+PrologFunctor, +Arity, SQLTableName)[multifile]
 get_type(+Constant, ?Type)
Prolog implementation specific definition of type retrieval sepia Prolog version given here

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 print_sqlterm(Arg1)