MYDDAS: New functionalitys to the MYDDAS system
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1541 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -17,13 +17,17 @@
|
||||
|
||||
:- module(myddas,[
|
||||
db_open/5,
|
||||
db_open/4,
|
||||
db_close/1,
|
||||
db_close/0,
|
||||
|
||||
db_verbose/1,
|
||||
db_module/1,
|
||||
db_is_database_predicate/3,
|
||||
db_stats/2,
|
||||
|
||||
db_sql/2,
|
||||
db_sql/3,
|
||||
db_sql_select/3,
|
||||
db_prolog_select/3,
|
||||
db_prolog_select_multi/3,
|
||||
@@ -43,11 +47,15 @@
|
||||
db_datalog_select/3,
|
||||
|
||||
% myddas_assert_predicates.yap
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/3,
|
||||
db_abolish/2,
|
||||
|
||||
db_listing/0,
|
||||
db_listing/1,
|
||||
|
||||
% myddas_mysql.yap
|
||||
db_my_open/5,
|
||||
db_my_close/1,
|
||||
@@ -75,10 +83,14 @@
|
||||
]).
|
||||
|
||||
:- use_module(myddas_assert_predicates,[
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/3,
|
||||
db_abolish/2
|
||||
db_abolish/2,
|
||||
db_listing/0,
|
||||
db_listing/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_mysql,[
|
||||
@@ -135,9 +147,11 @@
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_open/5
|
||||
%
|
||||
% db_open/5
|
||||
% db_open/4
|
||||
%
|
||||
db_open(Interface,HostDb,User,Password):-
|
||||
db_open(Interface,myddas,HostDb,User,Password).
|
||||
db_open(mysql,Connection,Host/Db,User,Password) :-
|
||||
'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
||||
c_db_my_connect(Host,User,Password,Db,Con),
|
||||
@@ -153,8 +167,10 @@ db_open(odbc,Connection,ODBCEntry,User,Password) :-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_close/1
|
||||
% db_close/0
|
||||
%
|
||||
%
|
||||
db_close:-
|
||||
db_close(myddas).
|
||||
db_close(Connection):-
|
||||
'$error_checks'(db_close(Connection)),
|
||||
get_value(Connection,Con),
|
||||
@@ -232,12 +248,18 @@ db_stats(Connection,List):-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
db_sql_select(_,_,_):-
|
||||
nl,write('Know use db_sql/3 insted of db_sql_select/3'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_sql_select(+,+,-)
|
||||
% db_sql(+,+,-)
|
||||
%
|
||||
%
|
||||
db_sql_select(Connection,SQL,LA):-
|
||||
'$error_checks'(db_sql_select(Connection,SQL,LA)),
|
||||
db_sql(SQL,LA):-
|
||||
db_sql(myddas,SQL,LA).
|
||||
db_sql(Connection,SQL,LA):-
|
||||
'$error_checks'(db_sql(Connection,SQL,LA)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
|
@@ -16,10 +16,14 @@
|
||||
*************************************************************************/
|
||||
|
||||
:- module(myddas_assert_predicates,[
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/3,
|
||||
db_abolish/2
|
||||
db_abolish/2,
|
||||
db_listing/0,
|
||||
db_listing/1
|
||||
]).
|
||||
|
||||
|
||||
@@ -54,8 +58,10 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_import/3
|
||||
% db_import/2
|
||||
%
|
||||
%
|
||||
db_import(RelationName,PredName):-
|
||||
db_import(myddas,Relation,PredName).
|
||||
db_import(Connection,RelationName,PredName) :-
|
||||
'$error_checks'(db_import(Connection,RelationName,PredName)),
|
||||
get_value(Connection,Con),
|
||||
@@ -90,13 +96,6 @@ db_import(Connection,RelationName,PredName) :-
|
||||
functor(P,PredName,Arity),
|
||||
'$make_list_of_args'(1,Arity,P,LA),
|
||||
|
||||
%Optimization
|
||||
%'$copy_term_nv'(P,[],G,_),
|
||||
|
||||
%generate the SQL query
|
||||
% translate(G,G,Code),
|
||||
%queries_atom(Code,SQL),
|
||||
|
||||
M=myddas_assert_predicates,
|
||||
%build PredName clause
|
||||
( ConType == mysql ->
|
||||
@@ -109,27 +108,10 @@ db_import(Connection,RelationName,PredName) :-
|
||||
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
||||
','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))]
|
||||
|
||||
% Assert =..[':-',P,','(M:'$build_query'(0,SQL,Code,LA,FinalSQL),
|
||||
% ','(M:db_my_result_set(Mode),
|
||||
% ','(M:'$write_or_not'(FinalSQL),
|
||||
% ','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
||||
% ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))]
|
||||
|
||||
% Assert =..[':-',P,','(get_value(db_myddas_stats_count,Number),
|
||||
% ','(statistics(cputime,TimeI),
|
||||
% ','(M:'$build_query'(0,SQL,Code,LA,FinalSQL),
|
||||
% ','(M:db_my_result_set(Mode),
|
||||
% ','(M:'$write_or_not'(FinalSQL),
|
||||
% ','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
||||
% ','(statistics(cputime,TimeF),
|
||||
% ','(Temp is TimeF - TimeI,
|
||||
% ','(Temp2 is Temp + Number,
|
||||
% ','(set_value(db_myddas_stats_count,Temp2),
|
||||
% ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))))))]
|
||||
;
|
||||
'$make_a_list'(Arity,BindList),
|
||||
Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
|
||||
','(M:translate(G,G,Code),
|
||||
','(M:translate(G,G,Code),
|
||||
','(M:queries_atom(Code,FinalSQL),
|
||||
','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Connection),
|
||||
','(M:'$write_or_not'(FinalSQL),
|
||||
@@ -144,8 +126,10 @@ db_import(Connection,RelationName,PredName) :-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_view/3
|
||||
% db_view/2
|
||||
%
|
||||
%
|
||||
db_view(PredName,DbGoal) :-
|
||||
db_view(myddas,PredName,DbGoal).
|
||||
db_view(Connection,PredName,DbGoal) :-
|
||||
'$error_checks'(db_view(Connection,PredName,DbGoal)),
|
||||
get_value(Connection,Con),
|
||||
@@ -247,13 +231,61 @@ db_insert(Connection,RelationName,PredName) :-
|
||||
%
|
||||
%
|
||||
db_abolish(Module:PredName,Arity):-!,
|
||||
%'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||
'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
db_abolish(PredName,Arity):-
|
||||
%'$error_checks'(db_abolish(PredName,Arity)),
|
||||
'$error_checks'(db_abolish(PredName,Arity)),
|
||||
db_module(Module),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_abolish(+,+)
|
||||
%
|
||||
%
|
||||
db_abolish(Module:PredName,Arity):-!,
|
||||
'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
db_abolish(PredName,Arity):-
|
||||
'$error_checks'(db_abolish(PredName,Arity)),
|
||||
db_module(Module),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_listing.
|
||||
%
|
||||
%
|
||||
db_listing:-
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity),
|
||||
fail.
|
||||
db_listing.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_listing.
|
||||
%
|
||||
%
|
||||
db_listing(Module:Name/Arity):-!,
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity).
|
||||
db_listing(Name/Arity):-!,
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity).
|
||||
db_listing(Name):-
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
@@ -28,6 +28,15 @@
|
||||
is_list/1
|
||||
]).
|
||||
|
||||
|
||||
'$error_checks'(db_abolish(ModulePredName,Arity)):-!,
|
||||
(ModulePredName = Module:PredName ->
|
||||
atom(Module),
|
||||
atom(PredName)
|
||||
;
|
||||
atom(ModulePredName)
|
||||
),
|
||||
number(Arity).
|
||||
'$error_checks'(db_show_database(Connection,_)):- !,
|
||||
atom(Connection).
|
||||
'$error_checks'(db_change_database(Connection,Database)):- !,
|
||||
@@ -106,7 +115,7 @@
|
||||
'$error_checks'(db_get_attributes_types(Connection,RelationName,_)) :- !,
|
||||
atom(Connection),
|
||||
nonvar(RelationName).
|
||||
'$error_checks'(db_sql_select(Connection,SQL,LA)):- !,
|
||||
'$error_checks'(db_sql(Connection,SQL,LA)):- !,
|
||||
atom(Connection),
|
||||
nonvar(SQL),
|
||||
not ground(LA).
|
||||
|
Reference in New Issue
Block a user