%
% given a list of dbq/2, generate the DB queries in CIF
% (Note: CIF to ICode conversion will be done by the DB-wrapper.)
%

:- module(dbq_gen,[	generate_dbq/2,
			dump_dbq/1
		]).

:- use_module('../../prolog/util/prolog_detect').
:-	prolog_detect:prolog(Prolog),
	(	(	Prolog=sicstus,
			use_module(library(lists))
		);
		Prolog=swi;
		(	write('*** unsupported Prolog system ***'),
			nl,
			fail
		)
	).
:- use_module('../../prolog/util/cif_util').

generate_dbq([],[]).

generate_dbq([D|Ds],[Q|Qs]) :-
	generate_dbq(D,Q),
	generate_dbq(Ds,Qs).

generate_dbq(dbq(Vars:Types,Zf),Q) :-
	filter_generate2(Zf,Filtered_zf),
	Q=[Vars:Types,Filtered_zf].
%	Q=[[Vars:Types,Filtered_zf]].


dump_dbq([]).
dump_dbq([Q|Qs]) :-
	write(Q),
	nl,
	dump_dbq(Qs).


%
% filter out generate/2 involving integer/float/boolean/string
%

filter_generate2([],[]).

filter_generate2([G|Gs],Filtered) :-
	G=generate(Class,_),
	member(Class,[integer,string,float,boolean]),
	!,
	filter_generate2(Gs,Filtered).

filter_generate2([C|Gs],[C|Filtered]) :-
%	G=generate(Class,_),
	filter_generate2(Gs,Filtered).


