droid vs myddas

This commit is contained in:
Vitor Santos Costa 2019-04-07 00:25:10 +01:00
parent 0f1eaa827a
commit cab11f5205
14 changed files with 144 additions and 94 deletions

View File

@ -620,7 +620,6 @@ add_definitions(-DMYDDAS=1 -DEMBEDDED_MYDDAS=1 -DMYDDAS_SQLITE3=1 -DEMBEDDED_SQL
else()
add_definitions(-DMYDDAS=1 -DEMBEDDED_MYDDAS=1 -DMYDDAS_SQLITE3=1 )
endif()
if (MYSQL_FOUND)
add_definitions( -DMYDDAS_MYSQL=1)
endif ()
@ -636,6 +635,7 @@ endif()
# we use the nice UTF-8 package
#available at the Julia project
endif()
add_subDIRECTORY( packages/myddas )
add_subDIRECTORY( packages/clpqr )

View File

@ -31,10 +31,15 @@ set(MYDDAS_UTIL_SOURCES
add_subdirectory(sqlite3)
if(MYSQL_FOUND)
add_subdirectory(mysql)
endif()
if (ODBC_FOUND)
add_subdirectory(odbc)
endif()
if (POSTGRES_FOUND)
add_subdirectory(postgres)
endif()
set(CXX_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/packages/swig/android)
add_component(myddas
@ -57,3 +62,5 @@ MY_set_target_properties(myddas PROPERTIES
cmake_dependent_option(USE_MYDDAS_Stats
"enable the MYDDAS library statistics support" OFF
USE_MYDDAS OFF)
add_dependencies(myddas MYDDAS_PL)

View File

@ -130,22 +130,32 @@ static Int c_db_connection_type(USES_REGS1) {
Int *con = (Int *)IntegerOfTerm(arg_con);
MYDDAS_API type = myddas_util_connection_type(con);
switch (type) {
#if MYDDAS_MYSQL
case API_MYSQL:
/* MYSQL Connection */
return Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("mysql")));
#endif
#if MYDDAS_ODBC
case API_ODBC:
/* ODBC Connection */
return Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("odbc")));
#endif
#if USE_MYDDAS_SQLITE3
case API_SQLITE3:
/* SQLITE3 Connection */
return Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("sqlite3")));
case API_POSTGRES:
#endif
#if MYDDAS_POSTGRES
case API_POSTGRES:
/* SQLITE3 Connection */
return Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("postgres")));
#endif
default:
return FALSE;
}
return FALSE;
}
/* db_add_preds: PredName * Arity * Module * Connection*/

View File

@ -1,17 +1,35 @@
set(MYDDAS_YPP
myddas.ypp
myddas_core.ypp
myddas_assert_predicates.ypp
myddas_top_level.ypp
myddas_errors.ypp
myddas_prolog2sql.ypp
myddas_mysql.ypp
myddas_util_predicates.ypp
myddas_prolog2sql_optimizer.ypp)
if (FOUND_MYSQL)
list(APPEND MYDDAS_YPP myddas_assert_predicates.ypp)
endif()
get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS)
set(MYDDAS_DRIVERS
myddas_driver.ypp
)
set(MYDDAS_DBMS sqlite3 postgres odbc)
set(MYDDAS_DBMS sqlite3)
set(MYDDAS_FLAGS ${MYDDAS_FLAGS};-DMYDDAS_SQLITE3=1)
if (POSTGRES_FOUND)
list(APPEND MYDDAS_DBMS postgres)
set(MYDDAS_FLAGS ${MYDDAS_FLAGS};-DMYDDAS_POSTGRES=1)
endif()
if (ODBC_FOUND)
set(MYDDAS_FLAGS ${MYDDAS_FLAGS};-DMYDDAS_ODBC=1)
list(APPEND MYDDAS_DBMS odbc)
endif()
if (MYSQL_FOUND)
set(MYDDAS_FLAGS ${MYDDAS_FLAGS};-DMYDDAS_MYSQL=1)
list(APPEND MYDDAS_DBMS mysql)
endif()
if (ANDROID)
set (MYDDAS_PL_OUTDIR ${CMAKE_SOURCE_DIR}/../yaplib/src/generated/assets/Yap/myddas )
@ -20,23 +38,24 @@ if (ANDROID)
else()
set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS)
foreach (filename ${MYDDAS_YPP})
get_filename_component(base ${filename} NAME_WE)
set(base_abs ${MYDDAS_PL_OUTDIR}/${base})
set(outfile ${base_abs}.yap)
list(APPEND MYDDAS_YAP_FILES ${outfile})
execute_process(
add_custom_command(OUTPUT ${outfile}
COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile}
)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
)
set_source_files_properties(outfile PROPERTIES GENERATED TRUE)
endforeach ()
foreach (dbms ${MYDDAS_DBMS} )
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
list(APPEND MYDDAS_YAP_FILES ${outfile})
execute_process(
add_custom_command(OUTPUT ${outfile}
COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp -o ${outfile}
)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp
)
set_source_files_properties(outfile PROPERTIES GENERATED TRUE)
@ -46,3 +65,7 @@ endforeach()
install(FILES ${MYDDAS_YAP_FILES} DESTINATION ${YAP_INSTALL_DATADIR}/myddas)
install(FILES myddas.yap DESTINATION ${YAP_INSTALL_DATADIR})
add_custom_target(MYDDAS_PL
ALL
DEPENDS ${MYDDAS_YAP_FILES})

View File

@ -1 +1 @@
:- include( myddas/myddas ).
:- include( myddas/myddas_core ).

View File

@ -24,11 +24,12 @@
db_insert/3,
db_abolish/2,
db_listing/0,
db_listing/1
db_listing/1,
relation/3
]).
:- use_module(myddas,[
:- use_module(myddas_core,[
db_module/1,
c_db_check_if_exists_pred/3,
c_db_preds_conn/4,
@ -59,10 +60,12 @@
translate/3,
queries_atom/2
]).
#if MYDDAS_MYSQL
:- use_module(myddas_mysql,[
db_my_result_set/1
]).
#endif
#if MYDDAS_SQLITE3
:- use_module(myddas_sqlite3,[
sqlite3_result_set/1,
sqlite3_show_tables/1,
@ -77,6 +80,8 @@
c_sqlite3_number_of_fields/3,
sqlite3_row/3
]).
#endif
#if MYDDAS_ODBC
:- use_module(myddas_odbc,[
odbc_result_set/1,
c_odbc_change_database/2,
@ -90,7 +95,9 @@
c_odbc_number_of_fields/3,
c_odbc_row/3
]).
#endif
#if MYDDAS_POSTGRES
#endif
:- use_module( library(lists)).
@ -104,7 +111,7 @@ db_import(RelationName,PredName0):-
db_import(myddas,RelationName,PredName0).
db_import(Connection,RelationName,PredName0) :-
'$error_checks'(db_import(Connection,RelationName,PredName0)),
get_value(Connection,Con),
get_value(Connection,Con),
table_arity( Con, ConType, RelationName, Arity ),
strip_module(PredName0, Module, PredName),
\+ c_db_check_if_exists_pred(PredName,Arity,Module),
@ -124,8 +131,9 @@ db_import(Connection,RelationName,PredName0) :-
functor(P,PredName,Arity),
P=..[PredName|LA],
%build PredName clause
table_access_predicate( ConType, Con, Arity, P, LA, Module, Assert ),
assert_static(Module:Assert),
table_access_predicate( ConType, Con, Arity, P, LA, Module, Assert0 ),
strip_module(Assert0,_,Assert),
assert_static(user:Assert),
c_db_add_preds(PredName,Arity,Module,Con).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -217,22 +225,6 @@ db_abolish(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.
%
@ -282,14 +274,15 @@ table_arity( Con, ConType, RelationName, Arity ) :-
.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#if MYDDAS_MYSQL
% major attributes types.
table_attributes( mysql, Con, RelationName, TypesList ) :-
c_db_my_get_attributes_types(RelationName,Con,TypesList).
#endif
#if MYDDAS_POSTGRES
table_attributes( postgres, Con, RelationName, TypesList ) :-
c_postgres_get_attributes_types(RelationName,Con,TypesList).
#endif
table_attributes( odbc, Con, RelationName, TypesList ) :-
c_odbc_get_attributes_types(RelationName,Con,TypesList).
@ -298,7 +291,7 @@ table_attributes( sqlite3, Con, RelationName, TypesList ) :-
% predicate for DB-> query
#if MYDDAS_MYSQL
table_access_predicate( mysql, Con, Arity, P, LA, M,
M:( P :- myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(G,G,Code),
@ -309,7 +302,8 @@ table_access_predicate( mysql, Con, Arity, P, LA, M,
!,
user:c_db_my_row(ResultSet,Arity,LA)
)).
#endif
#if MYDDAS_POSTGRES
table_access_predicate( postgres, Con, Arity, P, LA, M,
M:( P :- myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(M:G,M:G,Code),
@ -320,7 +314,8 @@ table_access_predicate( postgres, Con, Arity, P, LA, M,
!,
c_postgres_row(ResultSet,Arity,LA) )
).
#endif
#if MYDDAS_SQLITE3
table_access_predicate( sqlite3, Con, Arity, P, LA, M,
M:( P :- (myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(G,G,Code),
@ -331,7 +326,8 @@ table_access_predicate( sqlite3, Con, Arity, P, LA, M,
!,
myddas_sqlite3:sqlite3_row(ResultSet,Arity,LA)
) )).
#endif
#if MYDDAS_ODBC
table_access_predicate( odbc, Con, Arity, P, LA, M,
M:( P :- (myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(G,G,Code),
@ -342,9 +338,9 @@ table_access_predicate( odbc, Con, Arity, P, LA, M,
!,
myddas_odbc:c_odbc_row(ResultSet,Arity,LA)
) )).
#endif
#if MYDDAS_MYSQL
table_insert( mysql, Con, RelationName, TypesList, Predicate, LA,
( Predicate :- myddas_assert_predicates:
( '$get_values_for_insert'(TypesList,LA,ValuesList),
@ -353,7 +349,8 @@ table_insert( mysql, Con, RelationName, TypesList, Predicate, LA,
'$write_or_not'(SQL),
c_db_my_query(SQL,_,Con,Mode,_)))
).
#endif
#if MYDDAS_POSTGRES
table_insert( postgres, Con, RelationName, TypesList, Predicate, LA,
( Predicate :- myddas_assert_predicates:
( '$get_values_for_insert'(TypesList,LA,ValuesList),
@ -362,7 +359,8 @@ table_insert( postgres, Con, RelationName, TypesList, Predicate, LA,
'$write_or_not'(SQL),
c_postgres_query(SQL,_,Con,Mode,_)))
).
#endif
#if MYDDAS_SQLITE3
table_insert( sqlite3, Con, RelationName, TypesList, Predicate, LA,
( Predicate :- myddas_assert_predicates:
( '$get_values_for_insert'(TypesList,LA,ValuesList),
@ -371,7 +369,8 @@ table_insert( sqlite3, Con, RelationName, TypesList, Predicate, LA,
'$write_or_not'(SQL),
c_sqlite3_query(SQL,_,Con,Mode,_)))
).
#endif
#if MYDDAS_ODBC
table_insert( odbc, Con, RelationName, TypesList, Predicate, LA,
( Predicate :- myddas_assert_predicates:
( '$get_values_for_insert'(TypesList,LA,ValuesList),
@ -379,8 +378,8 @@ table_insert( odbc, Con, RelationName, TypesList, Predicate, LA,
'$write_or_not'(SQL),
c_odbc_my_query(SQL,_,_,_,Con)))
).
#endif
#if MYDDAS_MYSQL
table_view( mysql, Con, CopyView, CopyGoal, Arity, LA, M,
( CopyView :-
M:( '$copy_term_nv'(CopyView,[],ProjT,Dic),
@ -392,7 +391,8 @@ table_view( mysql, Con, CopyView, CopyGoal, Arity, LA, M,
c_db_my_query(FinalSQL,ResultSet,Con,Mode,_),
!,
c_db_my_row(ResultSet,Arity,LA) ))).
#endif
#if MYDDAS_POSTGRES
table_view( postgres, Con, CopyView, CopyGoal, Arity, LA, M,
( CopyView :-
M:( '$copy_term_nv'(CopyView,[],ProjT,Dic),
@ -404,7 +404,8 @@ table_view( postgres, Con, CopyView, CopyGoal, Arity, LA, M,
c_postgres_query(FinalSQL,ResultSet,Con,Mode,_),
!,
c_postgres_row(ResultSet,Arity,LA) ))).
#endif
#if MYDDAS_ODBC
table_view( odbc, Con, CopyView, CopyGoal, Arity, LA, M,
( CopyView :-
M:( '$copy_term_nv'(CopyView,[],ProjT,Dic),
@ -416,7 +417,8 @@ table_view( odbc, Con, CopyView, CopyGoal, Arity, LA, M,
c_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
!,
c_odbc_row(ResultSet,Arity,LA) ))).
#endif
#if MYDDAS_SQLITE3
table_view( sqlite3, Con, CopyView, CopyGoal, Arity, LA, M,
( CopyView :-
M:( '$copy_term_nv'(CopyView,[],ProjT,Dic),
@ -427,3 +429,4 @@ table_view( sqlite3, Con, CopyView, CopyGoal, Arity, LA, M,
myddas_sqlite3:c_sqlite3_query(FinalSQL,ResultSet,Con,_,_),
!,
myddas_sqlite3:sqlite3_row(ResultSet,Arity,LA) ))).
#endif

View File

@ -158,7 +158,7 @@
:- meta_predicate db_import(+,+,:), db_import(+,:).
#ifdef MYDDAS_SQLITE3
:- use_module(myddas_sqlite3,[
% myddas_mysql.ypp
c_sqlite3_connect/4,
@ -171,7 +171,7 @@
sqlite3_show_tables/2,
sqlite3_row/3
]).
#endif
:- use_module(myddas_util_predicates,[
'$prolog2sql'/3,
'$create_multi_query'/3,
@ -248,8 +248,6 @@ user:prolog_file_type( db, dataset ).
%
%
%
db_open(Interface,HostDb,User,Password):-
db_open(Interface,myddas,HostDb,User,Password).
#ifdef MYDDAS_MYSQL
db_open(mysql,Connection,Host/Db/Port/Socket,User,Password) :- !,
@ -286,12 +284,18 @@ db_open(odbc,Connection,ODBCEntry,User,Password) :-
set_value(Connection,Con).
#endif
%% sqlite3
#ifdef MYDDAS_SQLITE3
db_open(sqlite3,Connection,File,User,Password) :-
absolute_file_name(File,Db,[access(write),file_type(myddas),expand(true)]),
'$error_checks'(db_open(sqlite3,Connection,Db,User,Password)),
c_sqlite3_connect(Db,User,Password,Con),
set_value(Connection,Con).
db_open(sqlite3,File,User,Password) :-
absolute_file_name(File,Db,[access(write),file_type(myddas),expand(true)]),
'$error_checks'(db_open(sqlite3,Connection,Db,User,Password)),
c_sqlite3_connect(Db,User,Password,Con),
set_value(myddas,Con).
#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -60,7 +60,7 @@
:- use_module(library(maplist)).
:- use_module(myddas).
:- use_module(myddas_core).
:- use_module(myddas_errors,[
'$error_checks'/1

View File

@ -38,7 +38,7 @@
db_sql_mode/2
]).
:- use_module(myddas,[
:- use_module(myddas_core,[
db_sql/3
]).

View File

@ -49,6 +49,10 @@
member/2
]).
:- use_module(library(myddas_assert_predicates),[
relation/3
]).
:- use_module(library(gensym)).

View File

@ -45,7 +45,7 @@
'$check_list_on_list'/2
]).
:- use_module(myddas,[
:- use_module(myddas_core,[
db_verbose/1,
c_db_preds_conn/4
]).

View File

@ -2,7 +2,7 @@
:- use_module(library(lists)).
:- use_module(library(maplist)).
:- use_module(library(myddas)).
:- use_module(myddas_core).
main :-
init,
@ -14,17 +14,17 @@ main_ :-
main_ .
init :-
catch(db_open(sqlite3,data('chinook.db'),_,_), _, fail),
catch(db_open(sqlite3,con,('chinook.db'),_,_), _, fail),
% db_open(sqlite3, 'chinook.db', _, _),
writeln('chinook has landed').
go :-
writeln(('db_import')),
db_import('artists', artists),
db_import(con,'artists', artists),
writeln(('artist -> artists')),
db_import('albums', albums),
db_import(con,'albums', albums),
writeln(('albums -> albums')),
db_import('tracks', tracks),
db_import(con,'tracks', tracks),
writeln(('tracks -> tracks')).
@ -34,31 +34,31 @@ go :-
writeln(X:Y).
go :-
writeln(db_get_attributes_types),
db_get_attributes_types(albums,Als),
db_get_attributes_types(con,albums,Als),
format('~w -> ~w~n',[albums,Als]),
db_get_attributes_types(tracks,Ts),
db_get_attributes_types(con,tracks,Ts),
format('~w -> ~w~n',[tracks,Ts]),
db_get_attributes_types(artists,As),
db_get_attributes_types(con,artists,As),
format('~w -> ~w~n',[artists,As]).
go :-
writeln(db_number_of_fields),
db_number_of_fields(albums,Als),
db_number_of_fields(tracks,Ts),
db_number_of_fields(artists,As),
db_number_of_fields(con,albums,Als),
db_number_of_fields(con,tracks,Ts),
db_number_of_fields(con,artists,As),
writeln(As:Als:Ts).
go :-
db_describe(albums, Desc), writeln(albums:Desc).
db_describe(con,albums, Desc), writeln(albums:Desc).
go :-
db_describe(tracks, Desc), writeln(tracks:Desc).
db_describe(con,tracks, Desc), writeln(tracks:Desc).
go :-
db_describe(artists, Desc), writeln(artists:Desc).
db_describe(con,artists, Desc), writeln(artists:Desc).
go :-
db_show_tables(Desc), writeln(tables:Desc).
db_show_tables(con,Desc), writeln(tables:Desc).
go :-
db_show_tables(table(T)),
db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')),
db_show_tables(con,table(T)),
db_describe(con,T,tableinfo(FieldID,Type,Null,Primary,Default,'')),
writeln(T:tableinfo(FieldID,Type,Null,Primary,Default,'')).
@ -91,8 +91,7 @@ go_cut1 :-
!.
close :-
db_close.
db_close(con).
:- initialization(main).
:- initialization(main, now).

View File

@ -1,20 +1,20 @@
:- module(android,
[text_to_query/2]).
%:- module(android,
% [text_to_query/2]).
:- initialization(yap_flag(verbose,_,normal)).
:- meta_predicate( text_to_query( :, - ) ).
text_to_query( MString, Status ) :-
strip_module( MString, Mod, String ),
strip_module( user:MString, Mod, String ),
top_query(android:query_( Mod:String, Status ) ).
top_query(query_( MString, Mod, Status ) ).
query_( Mtring, Mod, Status ) :-
query_( Mod:String, Status ) :-
atomic_to_term( String, Goal, VarNames ),
(
is_list(Goal) -> G = ensure_loaded( Goal ) ; G = Goal ),
catch(query_to_answer( Mod:G, VarNames, Status, Bindings).
is_list(Goal) -> G = consult( Goal ) ; G = Goal ),
query_to_answer( Mod:G, VarNames, Status, Bindings).
user:file_search_path(data, '/data/data/pt.up.yap/files/Yap/myddas').

View File

@ -225,13 +225,14 @@
'$extend_file_search_path'(P).
'$init_path_extensions'.
/**
* @pred top_query(?0 Goal).
*
* run _Goal_ as f it had been called from the Prolog
* top-level.
*/
top_quer(G) :-
top_query(G) :-
'$init_step'(2), % consult
'$init_step'(3), % globals
'$init_step'(4), % check if a saved state,
@ -248,12 +249,11 @@ top_quer(G) :-
nb_setval('$debug_jump',off),
'__NB_setval__'('$trace',off),
nb_setval('$debug_status', state(zip, 0, stop,off)),
set_prolog_flag(break_level, 0).
call(user:G, Error, '$Errors'(Error)).
set_prolog_flag(break_level, 0),
catch(user:G, Error, '$Error'(Error)).
/**
*
* @}
*/