MyDDAS: Nuno Fonseca notice an error on db_import/3 and db_view/3. The asserted predicates didn't consider the Bind Value of the variables. Bug fixed ;)

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1510 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares 2006-01-10 15:36:35 +00:00
parent 4de4b4d76c
commit 3f7a2c730d

View File

@ -90,7 +90,7 @@ db_import(Connection,RelationName,PredName) :-
'$make_list_of_args'(1,Arity,P,LA), '$make_list_of_args'(1,Arity,P,LA),
%Optimization %Optimization
'$copy_term_nv'(P,[],G,_), %'$copy_term_nv'(P,[],G,_),
%generate the SQL query %generate the SQL query
%translate(G,G,Code), %translate(G,G,Code),
@ -100,12 +100,13 @@ db_import(Connection,RelationName,PredName) :-
%build PredName clause %build PredName clause
( ConType == mysql -> ( ConType == mysql ->
Assert =..[':-',P,','(M:translate(G,G,Code), Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
','(M:translate(G,G,Code),
','(M:queries_atom(Code,FinalSQL), ','(M:queries_atom(Code,FinalSQL),
','(M:db_my_result_set(Mode), ','(M:db_my_result_set(Mode),
','(M:'$write_or_not'(FinalSQL), ','(M:'$write_or_not'(FinalSQL),
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode), ','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
','(!,M:c_db_my_row(ResultSet,Arity,LA)))))))] ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))]
% Assert =..[':-',P,','(M:'$build_query'(0,SQL,Code,LA,FinalSQL), % Assert =..[':-',P,','(M:'$build_query'(0,SQL,Code,LA,FinalSQL),
% ','(M:db_my_result_set(Mode), % ','(M:db_my_result_set(Mode),
@ -126,11 +127,12 @@ db_import(Connection,RelationName,PredName) :-
% ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))))))] % ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))))))]
; ;
'$make_a_list'(Arity,BindList), '$make_a_list'(Arity,BindList),
Assert =..[':-',P,','(M:translate(G,G,Code), Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
','(M:translate(G,G,Code),
','(M:queries_atom(Code,FinalSQL), ','(M:queries_atom(Code,FinalSQL),
','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Connection), ','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Connection),
','(M:'$write_or_not'(FinalSQL), ','(M:'$write_or_not'(FinalSQL),
','(!,M:c_db_odbc_row(ResultSet,BindList,LA))))))] ','(!,M:c_db_odbc_row(ResultSet,BindList,LA)))))))]
), ),
assert(Module:Assert), assert(Module:Assert),
@ -149,28 +151,29 @@ db_view(Connection,PredName,DbGoal) :-
% get arity of projection term % get arity of projection term
functor(PredName,ViewName,Arity), functor(PredName,ViewName,Arity),
functor(NewName,ViewName,Arity),
db_module(Module), db_module(Module),
not c_db_check_if_exists_pred(ViewName,Arity,Module), %not c_db_check_if_exists_pred(ViewName,Arity,Module),
% This copy_term is done to prevent the unification % This copy_term is done to prevent the unification
% with top-level variables A='var('A')' error % with top-level variables A='var('A')' error
copy_term((PredName,DbGoal),(CopyView,CopyGoal)), copy_term((PredName,DbGoal),(CopyView,CopyGoal)),
'$make_list_of_args'(1,Arity,NewName,LA), '$make_list_of_args'(1,Arity,CopyView,LA),
M=myddas_assert_predicates, M=myddas_assert_predicates,
c_db_connection_type(Con,ConType), c_db_connection_type(Con,ConType),
% build view clause % build view clause
( ConType == mysql -> ( ConType == mysql ->
Assert =..[':-',NewName, Assert =..[':-',CopyView,
','(M:translate(CopyView,CopyGoal,Code), ','(M:'$copy_term_nv'(CopyView,[],ProjT,Dic),
','(M:'$copy_term_nv'(CopyGoal,Dic,NG,_),
','(M:translate(ProjT,NG,Code),
','(M:queries_atom(Code,FinalSQL), ','(M:queries_atom(Code,FinalSQL),
','(M:db_my_result_set(Mode), ','(M:db_my_result_set(Mode),
','(M:'$write_or_not'(FinalSQL), ','(M:'$write_or_not'(FinalSQL),
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode), ','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
','(!,M:c_db_my_row(ResultSet,Arity,LA)))))))] ','(!,M:c_db_my_row(ResultSet,Arity,LA)))))))))]
; ;
Assert =..[':-',NewName, Assert =..[':-',NewName,
','(M:translate(CopyView,CopyGoal,Code), ','(M:translate(CopyView,CopyGoal,Code),