2006-02-05 02:19:15 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: myddas_top_level.yap *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: MYDDAS Top Level predicates *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2006-03-09 15:52:06 +00:00
|
|
|
#ifdef MYDDAS_TOP_LEVEL
|
|
|
|
|
2006-02-05 02:19:15 +00:00
|
|
|
:- module(myddas_top_level,[
|
2006-05-31 15:35:05 +01:00
|
|
|
db_top_level/4,
|
2006-02-08 17:29:55 +00:00
|
|
|
db_top_level/5,
|
|
|
|
db_datalog_select/3
|
|
|
|
]).
|
2006-02-05 02:19:15 +00:00
|
|
|
|
|
|
|
:- use_module(myddas_mysql,[
|
|
|
|
db_my_result_set/1
|
|
|
|
]).
|
|
|
|
|
2019-04-06 10:07:54 +01:00
|
|
|
:- use_module(library(system),[
|
2006-05-31 15:35:05 +01:00
|
|
|
system/2
|
|
|
|
]).
|
|
|
|
|
2019-04-06 10:07:54 +01:00
|
|
|
:- use_module(library(charsio),[
|
2006-02-08 17:29:55 +00:00
|
|
|
read_from_chars/2
|
|
|
|
]).
|
|
|
|
|
2019-04-06 10:07:54 +01:00
|
|
|
:- use_module(library(terms),[
|
2006-02-08 17:29:55 +00:00
|
|
|
term_variables/2
|
|
|
|
]).
|
|
|
|
|
|
|
|
:- use_module(myddas_util_predicates,[
|
2006-05-31 15:35:05 +01:00
|
|
|
'$make_atom'/2,
|
2006-02-08 17:29:55 +00:00
|
|
|
'$prolog2sql'/3,
|
|
|
|
'$write_or_not'/1,
|
|
|
|
'$lenght'/2
|
|
|
|
]).
|
2006-05-31 15:35:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
% db_top_level/5
|
|
|
|
% db_top_level/4
|
|
|
|
%
|
|
|
|
db_top_level(mysql,HostDb,User,Password):-
|
|
|
|
db_top_level(mysql,myddas,HostDb,User,Password).
|
|
|
|
|
|
|
|
db_top_level(mysql,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
|
|
|
'$make_atom'(['mysql',' -h ',Host,' -P ',Port,' -S ',Socket,' -u ',User,' --password=',Password,' ',Db],Command),
|
|
|
|
system(Command,_).
|
|
|
|
db_top_level(mysql,Connection,Host/Db/Port,User,Password) :-
|
|
|
|
integer(Port),!,
|
|
|
|
'$make_atom'(['mysql',' -h ',Host,' -P ',Port,' -u ',User,' --password=',Password,' ',Db],Command),
|
|
|
|
system(Command,_).
|
|
|
|
db_top_level(mysql,Connection,Host/Db/Socket,User,Password) :- !,
|
|
|
|
db_top_level(mysql,Connection,Host/Db/0/Socket,User,Password).
|
|
|
|
db_top_level(mysql,Connection,Host/Db,User,Password):-
|
|
|
|
db_top_level(mysql,Connection,Host/Db/0,User,Password).
|
|
|
|
|
|
|
|
|
2006-02-05 02:19:15 +00:00
|
|
|
|
2006-02-08 17:29:55 +00:00
|
|
|
db_top_level(datalog,Connection,_,_,_):-
|
2006-02-05 02:19:15 +00:00
|
|
|
%'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
2006-02-08 17:29:55 +00:00
|
|
|
get_value(Connection,Con),
|
|
|
|
Con \= [],!,
|
|
|
|
c_db_connection_type(Con,mysql),
|
|
|
|
Prompt = ' datalog> ',
|
|
|
|
nl,
|
|
|
|
'$top_level_datalog_cicle'(Connection,Prompt).
|
|
|
|
% c_db_tl_readline(Prompt,Line),
|
|
|
|
% name(Line,CharsLine),
|
|
|
|
% read_from_chars(CharsLine,Query),
|
|
|
|
% term_variables(Query,VarList),
|
|
|
|
% db_datalog_select(Connection,VarList,Query).
|
|
|
|
|
|
|
|
'$top_level_datalog_cicle'(Connection,Prompt):-
|
|
|
|
c_db_tl_readline(Prompt,Line),
|
|
|
|
name(Line,CharsLine),
|
|
|
|
catch(read_from_chars(CharsLine,Query),_,'$top_level_datalog_cicle'(Connection,Prompt)),
|
|
|
|
!,'$top_level_datalog'(Connection,Prompt,Query).
|
|
|
|
|
|
|
|
|
|
|
|
'$top_level_datalog'(_,_,halt):-!.
|
|
|
|
'$top_level_datalog'(Connection,Prompt,Query):-
|
|
|
|
term_variables(Query,[]),!,
|
|
|
|
Query =..[_|Args],
|
|
|
|
db_datalog_select(Connection,Args,Query),
|
|
|
|
'$top_level_datalog_cicle'(Connection,Prompt).
|
|
|
|
'$top_level_datalog'(Connection,Prompt,Query):-
|
|
|
|
term_variables(Query,VarList),
|
|
|
|
db_datalog_select(Connection,VarList,Query),
|
|
|
|
!,'$top_level_datalog_cicle'(Connection,Prompt).
|
|
|
|
|
|
|
|
db_datalog_select(Connection,LA,DbGoal):-
|
|
|
|
|
|
|
|
'$lenght'(LA,Arity),
|
2006-04-30 11:11:25 +01:00
|
|
|
Name=viewname,
|
|
|
|
functor(ViewName,Name,Arity),
|
2006-02-08 17:29:55 +00:00
|
|
|
% build arg list for viewname/Arity
|
2006-04-30 11:11:25 +01:00
|
|
|
ViewName=..[Name|LA],
|
2006-02-08 17:29:55 +00:00
|
|
|
|
|
|
|
'$prolog2sql'(ViewName,DbGoal,SQL),
|
|
|
|
|
|
|
|
get_value(Connection,Con),
|
2006-04-30 11:11:25 +01:00
|
|
|
%c_db_connection_type(Con,ConType),
|
2006-02-08 17:29:55 +00:00
|
|
|
'$write_or_not'(SQL),
|
|
|
|
%( ConType == mysql ->
|
2006-02-05 02:19:15 +00:00
|
|
|
db_my_result_set(Mode),
|
2006-04-30 11:11:25 +01:00
|
|
|
c_db_my_query(SQL,ResultSet,Con,Mode,_),
|
2006-02-08 17:29:55 +00:00
|
|
|
c_db_my_table_write(ResultSet).
|
|
|
|
|
2006-03-09 15:52:06 +00:00
|
|
|
#endif MYDDAS_TOP_LEVEL
|