MYDDAS: Top Level Functionality
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1534 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
96bc3dd011
commit
8012773ae1
@ -11,8 +11,12 @@
|
||||
* File: stdpreds.c *
|
||||
* comments: General-purpose C implemented system predicates *
|
||||
* *
|
||||
* Last rev: $Date: 2005-12-17 03:25:39 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2006-02-05 02:17:54 $,$Author: tiagosoares $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.98 2005/12/17 03:25:39 vsc
|
||||
* major changes to support online event-based profiling
|
||||
* improve error discovery and restart on scanner.
|
||||
*
|
||||
* Revision 1.97 2005/11/22 11:25:59 tiagosoares
|
||||
* support for the MyDDAS interface library
|
||||
*
|
||||
@ -2964,6 +2968,9 @@ Yap_InitCPreds(void)
|
||||
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
|
||||
Yap_InitMYDDAS_SharedPreds();
|
||||
#endif
|
||||
#if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE
|
||||
Yap_InitMYDDAS_TopLevelPreds();
|
||||
#endif
|
||||
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
|
||||
Yap_InitMYDDAS_testPreds();
|
||||
#endif
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: Yap.proto *
|
||||
* mods: *
|
||||
* comments: Function declarations for YAP *
|
||||
* version: $Id: Yapproto.h,v 1.67 2005-12-19 13:52:35 tiagosoares Exp $ *
|
||||
* version: $Id: Yapproto.h,v 1.68 2006-02-05 02:17:55 tiagosoares Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
/* prototype file for Yap */
|
||||
@ -333,6 +333,9 @@ void STD_PROTO(Yap_MyDDAS_delete_all_myddas_structs,(void));
|
||||
void STD_PROTO(Yap_InitMYDDAS_SharedPreds,(void));
|
||||
void STD_PROTO(Yap_InitBackMYDDAS_SharedPreds,(void));
|
||||
#endif
|
||||
#if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL //&& defined HAVE_LIBREADLINE
|
||||
void STD_PROTO(Yap_InitMYDDAS_TopLevelPreds,(void));
|
||||
#endif
|
||||
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
|
||||
void STD_PROTO(Yap_InitMYDDAS_testPreds,(void));
|
||||
void STD_PROTO(Yap_InitBackMYDDAS_testPreds,(void));
|
||||
|
14
Makefile.in
14
Makefile.in
@ -171,8 +171,8 @@ C_SOURCES= \
|
||||
$(srcdir)/MYDDAS/myddas_odbc.c \
|
||||
$(srcdir)/MYDDAS/myddas_util.c \
|
||||
$(srcdir)/MYDDAS/myddas_shared.c \
|
||||
$(srcdir)/MYDDAS/myddas_test_predicates.c \
|
||||
$(srcdir)/MYDDAS/myddas_statistics.c
|
||||
$(srcdir)/MYDDAS/myddas_statistics.c \
|
||||
$(srcdir)/MYDDAS/myddas_top_level.c
|
||||
|
||||
PL_SOURCES= \
|
||||
$(srcdir)/pl/arith.yap $(srcdir)/pl/arrays.yap $(srcdir)/pl/boot.yap \
|
||||
@ -207,8 +207,8 @@ ENGINE_OBJECTS = \
|
||||
exec.o gprof.o grow.o \
|
||||
heapgc.o index.o init.o inlines.o \
|
||||
iopreds.o depth_bound.o mavar.o \
|
||||
myddas_mysql.o myddas_odbc.o myddas_shared.o myddas_test_predicates.o \
|
||||
myddas_util.o myddas_statistics.o modules.o other.o \
|
||||
myddas_mysql.o myddas_odbc.o myddas_shared.o \
|
||||
myddas_util.o myddas_statistics.o myddas_top_level.o modules.o other.o \
|
||||
parser.o save.o scanner.o sort.o stdpreds.o sysbits.o threads.o \
|
||||
tracer.o \
|
||||
unify.o userpreds.o utilpreds.o write.o ypsocks.o ypstdio.o @MPI_OBJS@
|
||||
@ -429,12 +429,12 @@ myddas_odbc.o: $(srcdir)/MYDDAS/myddas_odbc.c
|
||||
myddas_shared.o: $(srcdir)/MYDDAS/myddas_shared.c
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_shared.c -o $@
|
||||
|
||||
myddas_test_predicates.o: $(srcdir)/MYDDAS/myddas_test_predicates.c
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_test_predicates.c -o $@
|
||||
|
||||
myddas_util.o: $(srcdir)/MYDDAS/myddas_util.c
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_util.c -o $@
|
||||
|
||||
myddas_top_level.o: $(srcdir)/MYDDAS/myddas_top_level.c
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_top_level.c -o $@
|
||||
|
||||
myddas_statistics.o: $(srcdir)/MYDDAS/myddas_statistics.c
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_statistics.c -o $@
|
||||
|
||||
|
44
configure
vendored
44
configure
vendored
@ -848,6 +848,7 @@ Optional Features:
|
||||
--enable-cut-c support for executing c code when a cut occurs
|
||||
--enable-myddas enable the MYDDAS library
|
||||
--enable-myddas-stats enable the MYDDAS library statistics support
|
||||
--enable-myddas-top-level enable the MYDDAS top-level support to MySQL
|
||||
--enable-tabling support tabling
|
||||
--enable-or-parallelism support or-parallelism as: env-copy,sba,a-cow
|
||||
--enable-depth-limit support depth-bound computation
|
||||
@ -2426,7 +2427,16 @@ _ACEOF
|
||||
myddas_stats="$enableval"
|
||||
else
|
||||
myddas_stats=no
|
||||
fi;
|
||||
fi;
|
||||
|
||||
# Check whether --enable-myddas-top-level was given.
|
||||
if test "${enable_myddas_top_level+set}" = set; then
|
||||
enableval="$enable_myddas_top_level"
|
||||
myddas_top_level="$enableval"
|
||||
else
|
||||
myddas_top_level=no
|
||||
fi;
|
||||
|
||||
fi
|
||||
|
||||
# Check whether --enable-tabling or --disable-tabling was given.
|
||||
@ -6404,6 +6414,12 @@ case "$orparallelism" in
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
if test "$cut_c" = "yes"
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DCUT_C=1"
|
||||
fi
|
||||
|
||||
if test "$ac_cv_lib_mysql_myddas" = "yes"
|
||||
then
|
||||
if test "$cut_c" = "no"
|
||||
@ -6455,10 +6471,28 @@ if test "$myddas_stats" = "yes"
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_STATS"
|
||||
fi
|
||||
|
||||
if test "$cut_c" = "yes"
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DCUT_C=1"
|
||||
fi
|
||||
if test "$myddas_top_level" = "yes"
|
||||
then
|
||||
if test "$ac_cv_lib_mysql_myddas" = "no"
|
||||
then
|
||||
echo
|
||||
echo
|
||||
echo "********************************************************"
|
||||
echo
|
||||
echo
|
||||
echo "!!!!!! WARNING !!!!!!"
|
||||
echo "The MYDDAS Top Level makes no sense without the mysql devel libraries"
|
||||
echo "Please contact tiagosoares@ncc.up.pt for help"
|
||||
echo
|
||||
echo "Disabling MYDDAS Top Level"
|
||||
echo
|
||||
echo "********************************************************"
|
||||
echo
|
||||
echo
|
||||
else
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL"
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$tabling" = "yes"
|
||||
then
|
||||
|
@ -37,6 +37,9 @@
|
||||
db_number_of_fields/3,
|
||||
|
||||
db_multi_queries_number/2,
|
||||
|
||||
% myddas_top_level.yap
|
||||
db_top_level/4,
|
||||
|
||||
% myddas_assert_predicates.yap
|
||||
db_import/3,
|
||||
@ -56,11 +59,19 @@
|
||||
db_my_describe/3,
|
||||
db_my_show_tables/1,
|
||||
db_my_show_tables/2,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_my_sql_select/3,
|
||||
db_my_number_of_fields/3,
|
||||
db_my_get_attributes_types/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas_top_level,[
|
||||
db_top_level/4
|
||||
]).
|
||||
|
||||
:- use_module(myddas_assert_predicates,[
|
||||
db_import/3,
|
||||
db_view/3,
|
||||
@ -80,6 +91,10 @@
|
||||
db_my_describe/3,
|
||||
db_my_show_tables/1,
|
||||
db_my_show_tables/2,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_my_sql_select/3,
|
||||
db_my_number_of_fields/3,
|
||||
db_my_get_attributes_types/3
|
||||
@ -121,11 +136,12 @@
|
||||
% db_open/5
|
||||
%
|
||||
%
|
||||
db_open(mysql,Connection,Host/Db,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),
|
||||
set_value(Connection,Con).
|
||||
db_open(odbc,Connection,ODBCEntry,User,Password) :-!,
|
||||
|
||||
db_open(odbc,Connection,ODBCEntry,User,Password) :-
|
||||
'$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)),
|
||||
c_db_odbc_connect(ODBCEntry,User,Password,Con),
|
||||
set_value(Connection,Con).
|
||||
|
@ -28,6 +28,11 @@
|
||||
is_list/1
|
||||
]).
|
||||
|
||||
'$error_checks'(db_show_database(Connection,_)):- !,
|
||||
atom(Connection).
|
||||
'$error_checks'(db_change_database(Connection,Database)):- !,
|
||||
atom(Connection),
|
||||
atom(Database).
|
||||
'$error_checks'(db_prolog_select_multi(Connection,DbGoalsList,_)):- !,
|
||||
atom(Connection),
|
||||
is_list(DbGoalsList).
|
||||
|
@ -27,6 +27,10 @@
|
||||
db_my_describe/3,
|
||||
db_my_show_tables/1,
|
||||
db_my_show_tables/2,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_my_sql_select/3,
|
||||
db_my_number_of_fields/3,
|
||||
db_my_get_attributes_types/3
|
||||
@ -198,6 +202,59 @@ db_my_show_tables(Connection,table(Table)) :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_database/2
|
||||
%
|
||||
%
|
||||
db_show_database(Connection,Database) :-
|
||||
'$error_checks'(db_show_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
c_db_my_get_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_databases/2
|
||||
%
|
||||
%
|
||||
db_show_databases(Connection,database(Databases)) :-
|
||||
%'$error_checks'(db_show_databases(Connection,Database)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_db_my_query('SHOW DATABASES',ResultSet,Conn,Mode),
|
||||
!,c_db_my_row(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_databases/1
|
||||
% TODO Error Checks
|
||||
%
|
||||
db_show_databases(Connection) :-
|
||||
%'$error_checks'(db_my_show_databases(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_db_my_query('SHOW DATABASES',ResultSet,Conn,Mode),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_change_database/2
|
||||
%
|
||||
%
|
||||
db_change_database(Connection,Database) :-
|
||||
'$error_checks'(db_change_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
'$make_atom'(['USE ',Database],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
c_db_my_change_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_sql_select/3
|
||||
|
@ -1018,9 +1018,9 @@ query_atom(query(Select,From,Where),QueryList,Diff):-
|
||||
query_atom(agg_query(Function,Select,From,Where,Group),QueryList,Diff):-
|
||||
clause_atom('SELECT',Function,Select,',',QueryList,X1),
|
||||
clause_atom('FROM',From,',',X1,X2),
|
||||
clause_atom('WHERE',Where,'AND',X2,Diff).
|
||||
clause_atom('WHERE',Where,'AND',X2,X3),
|
||||
%ILP : PARA NAO POR OS GROUP BYS. FAZER FLAG PARA ISTO
|
||||
%clause_atom('GROUP BY',Group,',',X3,Diff).
|
||||
clause_atom('GROUP BY',Group,',',X3,Diff).
|
||||
|
||||
|
||||
query_atom(negated_existential_subquery(Select,From,Where),QueryList,Diff):-
|
||||
|
@ -1,290 +0,0 @@
|
||||
:- module(myddas_test_predicates,[
|
||||
% Tests or Debug Predicates
|
||||
%db_my_delete/2,
|
||||
db_assert_view/4,
|
||||
db_my_insert_test/2,
|
||||
db_my_import_michel/3,
|
||||
db_view_original/3, % DEBUG ONLY
|
||||
db_ilpview/4
|
||||
]).
|
||||
|
||||
|
||||
:- use_module(myddas).
|
||||
:- use_module(myddas_mysql).
|
||||
:- use_module(myddas_util_predicates).
|
||||
:- use_module(myddas_prolog2sql,[translate/3,queries_atom/2]).
|
||||
:- use_module(myddas_errors).
|
||||
:- use_module(lists).
|
||||
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_assert_view/4
|
||||
% TODO Test with ODBC
|
||||
% TODO error checks
|
||||
db_assert_view(ViewName,SQLorDbGoal,FieldsInf,Connection):-
|
||||
'$get_value'(Connection,Con),
|
||||
%'$error_checks'(),
|
||||
( var(ViewName) ->
|
||||
c_db_get_new_table_name(Con,ViewName),
|
||||
TableName = ViewName
|
||||
),
|
||||
'$process_sql_goal'(ViewName,SQLorDbGoal,TableName,SQL),
|
||||
|
||||
% Case there's some information about the
|
||||
% attribute fields of the relation given
|
||||
% by the user
|
||||
'$generate_final_sql'(FieldsInf,TableName,SQL,FinalSQL),
|
||||
'$run_query'(Con,FinalSQL),
|
||||
|
||||
% TODO: Optimize this
|
||||
db_my_import(TableName,TableName,Connection).
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_insert/2
|
||||
%
|
||||
%
|
||||
db_my_insert_test(PredName,Connection):-
|
||||
'$get_value'(Connection,Conn),
|
||||
translate(PredName,PredName,Code),
|
||||
'$error_checks'(db_my_insert2(PredName,Conn,Code)),
|
||||
'$get_values_for_insert'(Code,ValuesList,RelName),
|
||||
'$make_atom'(['INSERT INTO ',RelName,' VALUES'|ValuesList],SQL),
|
||||
c_db_my_query_no_result(SQL,Conn).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_delete/2
|
||||
%
|
||||
%
|
||||
% db_my_delete(PredName,Connection):-
|
||||
% '$get_value'(Connection,Conn),
|
||||
% translate(PredName,PredName,Code),
|
||||
% %'$error_checks'(db_my_delete(PredName,Conn,Code)),
|
||||
% queries_atom(Code,SQL),
|
||||
% c_db_my_query('SELECT 46 , "ola" , "Adeus" FROM estrada A WHERE A.id_estrada = 46 , "ola" , "Adeus" FROM estrada A WHERE A.id_estrada = 46 AND A.nome = "ola" AND A.nome_alternativo = "Adeus"',_,Conn).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_import_michel/3
|
||||
%
|
||||
%
|
||||
db_my_import_michel(RelationName,PredName,Connection) :-
|
||||
'$error_checks'(db_my_import(RelationName,PredName,Connection)),
|
||||
% get connection id based on given atom
|
||||
'$get_value'(Connection,Conn),
|
||||
% assert information needed for translate/3 and PredName clause
|
||||
'$assert_relation_info_and_pred_clause_michel_query'(RelationName,PredName,Conn).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
% --- '$assert_relation_info_and_pred_clause'(RelationName,PredName,Connection)
|
||||
% Asserts information needed for translate/3 and the clause of the
|
||||
% PredName predicate
|
||||
% ---
|
||||
'$assert_relation_info_and_pred_clause_michel_query'(RelationName,PredName,Connection) :-
|
||||
% get relation arity
|
||||
% C Predicate
|
||||
c_db_my_number_of_fields(RelationName,Connection,Arity),
|
||||
db_module(Module),
|
||||
not c_db_my_check_if_exists_pred(PredName,Arity,Module),
|
||||
R=..[relation,PredName,Arity,RelationName],
|
||||
% assert relation fact
|
||||
'$assert_facts'(myddas_prolog2sql,R),
|
||||
%assert(myddas_prolog2sql:R),
|
||||
Size is 2*Arity,
|
||||
'$make_a_list'(Size,TypesList),
|
||||
% get attributes types in TypesList [field0,type0,field1,type1...]
|
||||
c_db_my_get_attributes_types(RelationName,Connection,TypesList),
|
||||
% assert attributes facts
|
||||
'$assert_attribute_information'(0,Arity,RelationName,TypesList),
|
||||
% build PredName functor
|
||||
functor(P,PredName,Arity),
|
||||
% build PredName clause
|
||||
Assert =..[':-',P,','(myddas_test_predicates:'$generate_optimized_SQL'(P,SQL,LA,ArityProj),
|
||||
','(myddas_test_predicates:db_my_result_set(Mode),
|
||||
','(myddas_test_predicates:'$write_or_not'(SQL),
|
||||
','(myddas_test_predicates:c_db_my_query(SQL,ResultSet,Connection,Mode),
|
||||
','(!,myddas_test_predicates:c_db_my_row_unify(ResultSet,ArityProj,LA))))))],
|
||||
% we are assuming that all the predicates will be inserted in
|
||||
% the user module
|
||||
assert(Module:Assert),
|
||||
% ALTERACAO
|
||||
% Adds PredName and Arity to this Connection List
|
||||
% C Predicate
|
||||
c_db_add_preds(PredName,Arity,Module,Connection).
|
||||
|
||||
|
||||
% Beginning of new predicates for optimized translate
|
||||
|
||||
'$generate_optimized_SQL'(Pred,SQL,DbRowList,Arity) :-
|
||||
Pred =..[F|Args],
|
||||
functor(Pred,_,A),
|
||||
myddas_prolog2sql:relation(F,A,Relation),
|
||||
'$divide_args_in_proj_and_where'(1,Relation,Args,[],Proj,Where),
|
||||
'$generate_SQL'(Relation,Proj,Where,SQL),
|
||||
'$generate_dbrow_list'(Proj,DbRowList,Arity).
|
||||
|
||||
|
||||
'$divide_args_in_proj_and_where'(_, _, [], _, [], []) :- !.
|
||||
|
||||
'$divide_args_in_proj_and_where'(I, Relation, [H|T], Dict, Proj, [v(Att,Att1)|Where]) :-
|
||||
var(H),
|
||||
'$member_var'(H,Dict,Att),!,
|
||||
myddas_prolog2sql:attribute(I,Relation,Att1,_),
|
||||
I1 is I+1,
|
||||
'$divide_args_in_proj_and_where'(I1, Relation, T, Dict, Proj, Where).
|
||||
|
||||
'$divide_args_in_proj_and_where'(I, Relation, [H|T], Dict, [(Att,H)|Proj], Where) :-
|
||||
var(H),!,
|
||||
myddas_prolog2sql:attribute(I,Relation,Att,_),
|
||||
I1 is I+1,
|
||||
'$divide_args_in_proj_and_where'( I1, Relation, T, [(H,Att)|Dict], Proj, Where).
|
||||
|
||||
'$divide_args_in_proj_and_where'(I, Relation, [H|T], Dict, Proj, [g(Att,H)|Where]) :-
|
||||
myddas_prolog2sql:attribute(I,Relation,Att,_),
|
||||
I1 is I+1,
|
||||
'$divide_args_in_proj_and_where'(I1,Relation,T,Dict,Proj,Where).
|
||||
|
||||
|
||||
'$generate_SQL'(Relation,_,[],SQL) :-
|
||||
!,
|
||||
atom_concat('SELECT * FROM ',Relation, SQL).
|
||||
|
||||
|
||||
'$generate_SQL'(Relation,Proj,Where,SQL) :-
|
||||
'$make_proj_atom'(Proj,Proj_Atom),
|
||||
atom_concat('SELECT ',Proj_Atom,R),
|
||||
atom_concat(R, ' FROM ',R1),
|
||||
atom_concat(R1, Relation, R2),
|
||||
atom_concat(R2, ' WHERE ', R3),
|
||||
'$make_where_atom'(Where,Where_Atom),
|
||||
atom_concat(R3,Where_Atom,SQL).
|
||||
|
||||
|
||||
'$generate_dbrow_list'([],[_],0) :- !. % important for empty projection terms.
|
||||
|
||||
'$generate_dbrow_list'([(_,V)],[V],1) :- !.
|
||||
|
||||
'$generate_dbrow_list'([(_,V)|T],[V|R],I1) :-
|
||||
'$generate_dbrow_list'(T,R,I), I1 is I+1.
|
||||
|
||||
|
||||
'$make_proj_atom'([],'1') :- !. % important for empty projection terms.
|
||||
|
||||
'$make_proj_atom'([(A,_)],A) :- !.
|
||||
|
||||
'$make_proj_atom'([(A,_)|T],Atom) :-
|
||||
'$make_proj_atom'(T,Atom1),
|
||||
atom_concat(A,',',Atom2),
|
||||
atom_concat(Atom2,Atom1,Atom).
|
||||
|
||||
|
||||
'$make_where_atom'([v(Att,H)],Atom) :-
|
||||
!,
|
||||
atom_concat(Att,' = ',R),
|
||||
atom_concat(R,H,Atom).
|
||||
|
||||
'$make_where_atom'([v(Att,H)|T],Atom) :-
|
||||
'$make_where_atom'(T,Atom1),
|
||||
atom_concat(Att,' = ',R),
|
||||
atom_concat(R,H,Atom2),
|
||||
atom_concat(Atom2, ' AND ', Atom3),
|
||||
atom_concat(Atom3,Atom1,Atom).
|
||||
|
||||
|
||||
'$make_where_atom'([g(Att,H)],Atom) :-
|
||||
number(H),
|
||||
!,
|
||||
number_atom(H,H1),
|
||||
atom_concat(Att,' = \'',R),
|
||||
atom_concat(R,H1,R1),
|
||||
atom_concat(R1,'\'',Atom).
|
||||
|
||||
'$make_where_atom'([g(Att,H)],Atom) :-
|
||||
!,
|
||||
atom_concat(Att,' = \'',R),
|
||||
atom_concat(R,H,R1),
|
||||
atom_concat(R1,'\'',Atom).
|
||||
|
||||
'$make_where_atom'([g(Att,H)|T],Atom) :-
|
||||
number(H),
|
||||
!,
|
||||
number_atom(H,H1),
|
||||
'$make_where_atom'(T,Atom1),
|
||||
atom_concat(Att,' = \'',R),
|
||||
atom_concat(R,H1,R1),
|
||||
atom_concat(R1,'\'',Atom2),
|
||||
atom_concat(Atom2, ' AND ', Atom3),
|
||||
atom_concat(Atom3,Atom1,Atom).
|
||||
|
||||
'$make_where_atom'([g(Att,H)|T],Atom) :-
|
||||
'$make_where_atom'(T,Atom1),
|
||||
atom_concat(Att,' = \'',R),
|
||||
atom_concat(R,H,R1),
|
||||
atom_concat(R1,'\'',Atom2),
|
||||
atom_concat(Atom2, ' AND ', Atom3),
|
||||
atom_concat(Atom3,Atom1,Atom).
|
||||
|
||||
|
||||
'$member_var'(H,[(V,Att)|_],Att) :-
|
||||
H == V,!.
|
||||
|
||||
'$member_var'(H,[_|T],Att) :-
|
||||
'$member_var'(H,T,Att).
|
||||
|
||||
% End of predicates for optimized translate
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_view_original/3
|
||||
%
|
||||
%
|
||||
db_view_original(PredName,DbGoal,Connection) :-
|
||||
'$error_checks'(db_my_view(PredName,DbGoal,Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$assert_view_clause2'(PredName,DbGoal,Conn).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
'$assert_view_clause2'(ViewName,DbGoal,Connection) :-
|
||||
% here we can add some error control, like checking DBgoals include
|
||||
% only DB relations
|
||||
% get arity of projection term
|
||||
% PredName necessary for c_db_add_preds
|
||||
functor(ViewName,PredName,Arity),
|
||||
functor(NewName,PredName,Arity),
|
||||
db_module(Module),
|
||||
not c_db_my_check_if_exists_pred(PredName,Arity,Module),
|
||||
%'$copy_term_nv'(NewName,[],G,_),
|
||||
%translate(ViewName,DbGoal,Code),
|
||||
%queries_atom(Code,SQL),
|
||||
% build arg list for db_my_row/2
|
||||
'$make_list_of_args'(1,Arity,NewName,LA),
|
||||
% checks if the WHERE commend of SQL exists in the string
|
||||
%'$where_exists'(SQL,Flag),
|
||||
% build view clause
|
||||
Assert =..[':-',NewName,
|
||||
','(myddas_test_predicates:translate(ViewName,DbGoal,Code),
|
||||
','(myddas_test_predicates:queries_atom(Code,FinalSQL),
|
||||
','(myddas_test_predicates:db_my_result_set(Mode),
|
||||
','(myddas_test_predicates:c_db_my_query(FinalSQL,ResultSet,Connection,Mode),
|
||||
','(myddas_test_predicates:'$write_or_not'(FinalSQL),
|
||||
','(!,myddas_test_predicates:c_db_my_row(ResultSet,Arity,LA)))))))],
|
||||
assert(Module:Assert),
|
||||
% ALTERACAO
|
||||
% Adds PredName and Arity to this Connection List
|
||||
% C Predicate
|
||||
c_db_add_preds(PredName,Arity,Module,Connection).
|
||||
|
||||
|
||||
|
||||
|
||||
|
39
library/MYDDAS/myddas_top_level.yap
Normal file
39
library/MYDDAS/myddas_top_level.yap
Normal file
@ -0,0 +1,39 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
:- module(myddas_top_level,[
|
||||
db_top_level/4
|
||||
]).
|
||||
|
||||
:- use_module(myddas_mysql,[
|
||||
db_my_result_set/1
|
||||
]).
|
||||
|
||||
db_top_level(Connection,_,_,_):-
|
||||
%'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
||||
get_value(Connection,Con),
|
||||
Con \= [],!,
|
||||
c_db_connection_type(Con,mysql),
|
||||
db_my_result_set(Mode),
|
||||
c_db_top_level(Con,Mode).
|
||||
|
||||
db_top_level(Connection,Host/Db,User,Password):-
|
||||
%'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
||||
c_db_my_connect(Host,User,Password,Db,Con),
|
||||
set_value(Connection,Con),
|
||||
db_my_result_set(Mode),
|
||||
c_db_top_level(Con,Mode).
|
@ -52,10 +52,10 @@ PROGRAMS= $(srcdir)/apply_macros.yap \
|
||||
$(srcdir)/MYDDAS/myddas.yap \
|
||||
$(srcdir)/MYDDAS/myddas_assert_predicates.yap \
|
||||
$(srcdir)/MYDDAS/myddas_mysql.yap \
|
||||
$(srcdir)/MYDDAS/myddas_top_level.yap \
|
||||
$(srcdir)/MYDDAS/myddas_errors.yap \
|
||||
$(srcdir)/MYDDAS/myddas_prolog2sql.yap \
|
||||
$(srcdir)/MYDDAS/myddas_util_predicates.yap \
|
||||
$(srcdir)/MYDDAS/myddas_test_predicates.yap
|
||||
$(srcdir)/MYDDAS/myddas_util_predicates.yap
|
||||
|
||||
LOGTALK_PROGRAMS= \
|
||||
$(srcdir)/logtalk/logtalk.pl \
|
||||
|
Reference in New Issue
Block a user