EXEC ( 'SPARQL || ' CREATE SPIN LIBRARY <{library-IRI}> { CLASS {} { RULE <{rule-iri}> { CONSTRUCT { ?this <{magic-predicate-iri}> ?area } WHERE { { Query-Body } } UNION STORAGE } } } ASK WHERE { }' ) ; -- Note: -- UNION STORAGE clause ensures fusion of calcuated and existing values when inferring objects of the -- relation identified by the variable ?area. Thus, if excluded inferred -- objects of the relation would only comprise calculated values. -- Note: -- The query at the end is validation one, it's purpose is to flag the presence of failed preconditions if it's ASK or return the -- list of failed preconditions if it's a SELECT. -- The query with CREATE MACRO LIBRARY/CREATE SPIN LIBRARY is compiled into call of function DB.DBA.RDF_SML_CREATE(). The function -- can be redefined if one want to shoot his leg in an unusual way, but its default version is pretty short. First it is making a -- "dry run" of the whole statement without creating or storing the library and executes the query at its end (e.g.,, this ASK WHERE -- { }. If the query at the end signals an error then the error is resignalled and the library is not -- created. if the query returns any non-empty result-set then an "Assertion failed: the validation query of macro library should -- return nothing" error is signalled. If no data rows returned by the query, the DB.DBA.RDF_SML_CREATE() alters the system metadata -- to store the library. -- Usage -- Pragma DEFINE input:macro-lib <{library-IRI}> ; -- Storage Attachment SPARQL ALTER QUAD STORAGE <{storage-iri}> { ATTACH MACRO LIBRARY <{library-IRI}> };