MyDDAS: Professor Michel Ferreira extended the prolog2sql interface with some new capabilities, including the support for ...WHERE EXISTS... querys

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1503 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares 2006-01-08 16:36:17 +00:00
parent c0a9fa5cab
commit d1fc8bc59c
1 changed files with 36 additions and 4 deletions

View File

@ -250,6 +250,8 @@ query_generation([Conjunction|Conjunctions],ProjectionTerm,[Query|Queries]):-
%
% --------------------------------------------------------------------------------------
translate_goal(SimpleGoal,[SQLFrom],SQLWhere,Dict,NewDict):-
% --- positive goal binds variables - these bindings are held in the dictionary -----
functor(SimpleGoal,Functor,Arity),
@ -274,6 +276,13 @@ translate_goal(not ComparisonGoal,[],SQLCompOp,Dict,Dict):-
negated_comparison(SQLOperator,SQLNegOperator),
translate_comparison(LeftArg,RightArg,SQLNegOperator,Dict,SQLCompOp).
translate_goal(exists(ExistsGoals),[],SQLExistsSubquery,Dict,Dict):-
% --- exists goals do not bind variables - hence Dict is returned unchanged --------
functor(ExistsGoals,Functor,_),
not comparison(Functor,_),
translate_conjunction(ExistsGoals,SQLFrom,SQLWhere,Dict,_),
SQLExistsSubquery = [existential_subquery([*],SQLFrom,SQLWhere)].
translate_goal(ComparisonGoal,[],SQLCompOp,Dict,Dict):-
% --- comparison operations do not bind variables - Dict is returned unchanged ------
ComparisonGoal =.. [ComparisonOperator,LeftArg,RightArg],
@ -794,7 +803,7 @@ printqueries([Query|Queries]):-
nl,
print_query(Query),
nl,
write('UNION'),
write('UNION '),
nl,
printqueries(Queries).
@ -836,6 +845,18 @@ print_query(negated_existential_subquery(Select,From,Where)):-
nl,
write(')').
print_query(existential_subquery(Select,From,Where)):-
write('EXISTS'),
nl,
write('('),
print_clause('SELECT',Select,','),
nl,
print_clause('FROM',From,','),
nl,
print_clause('WHERE',Where,'AND'),
nl,
write(')').
@ -947,6 +968,9 @@ print_column(agg_query(Function,Select,From,Where,Group)):-
print_column(negated_existential_subquery(Select,From,Where)):-
print_query(negated_existential_subquery(Select,From,Where)).
print_column(existential_subquery(Select,From,Where)):-
print_query(existential_subquery(Select,From,Where)).
@ -972,7 +996,7 @@ queries_atom([Query],QueryList,Diff):-
queries_atom([Query|Queries],QueryList,Diff):-
Queries \= [],
query_atom(Query,QueryList,X1),
column_atom('UNION',X1,X2),
column_atom('UNION ',X1,X2),
queries_atom(Queries,X2,Diff).
@ -1002,6 +1026,13 @@ query_atom(negated_existential_subquery(Select,From,Where),QueryList,Diff):-
clause_atom('WHERE',Where,'AND',X3,X4),
column_atom(')',X4,Diff).
query_atom(existential_subquery(Select,From,Where),QueryList,Diff):-
column_atom('EXISTS(',QueryList,X1),
clause_atom('SELECT',Select,',',X1,X2),
clause_atom('FROM',From,',',X2,X3),
clause_atom('WHERE',Where,'AND',X3,X4),
column_atom(')',X4,Diff).
@ -1059,8 +1090,6 @@ clause_atom([Item,NextItem|RestItems],Junctor,QueryList,Diff):-
column_atom(att(RangeVar,Attribute),QueryList,Diff):-
column_atom(RangeVar,QueryList,X1),
column_atom('.',X1,X2),
@ -1117,6 +1146,9 @@ column_atom(agg_query(Function,Select,From,Where,Group),QueryList,Diff):-
column_atom(negated_existential_subquery(Select,From,Where),QueryList,Diff):-
query_atom(negated_existential_subquery(Select,From,Where),QueryList,Diff).
column_atom(existential_subquery(Select,From,Where),QueryList,Diff):-
query_atom(existential_subquery(Select,From,Where),QueryList,Diff).
column_atom(Atom,List,Diff):-
atom(Atom),