fixes in module flow
also: - user is everyone's parent; - system predicate <=> prolog:predicate
This commit is contained in:
parent
2af4dae017
commit
3f9e57fc48
@ -75,8 +75,6 @@ extern void Yap_InitBackMYDDAS_PostgresPreds(void);
|
||||
/* myddas_sqlite3.c */
|
||||
#if defined MYDDAS_SQLITE3
|
||||
extern void init_sqlite3( void );
|
||||
extern void Yap_InitMYDDAS_SQLITE3Preds(void);
|
||||
extern void Yap_InitBackMYDDAS_SQLITE3Preds(void);
|
||||
#endif
|
||||
|
||||
/* Myddas_shared.c */
|
||||
|
@ -17,9 +17,6 @@
|
||||
typedef struct myddas_global *MYDDAS_GLOBAL;
|
||||
#include "myddas_util.h"
|
||||
|
||||
// extern void Yap_InitMYDDAS_SQLITE3Preds(void);
|
||||
// extern void Yap_InitBackMYDDAS_SQLITE3Preds(void);
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
typedef struct myddas_stats_time_struct *MYDDAS_STATS_TIME;
|
||||
typedef struct myddas_global_stats *MYDDAS_GLOBAL_STATS;
|
||||
|
@ -51,6 +51,8 @@ static Int c_db_check(USES_REGS1);
|
||||
#endif
|
||||
|
||||
void Yap_InitMYDDAS_SharedPreds(void) {
|
||||
Term cm = CurrentModule;
|
||||
CurrentModule = MkAtomTerm(Yap_LookupAtom("myddas"));
|
||||
/* c_db_initialize_myddas */
|
||||
Yap_InitCPred("c_db_initialize_myddas", 0, c_db_initialize_myddas, 0);
|
||||
|
||||
@ -86,15 +88,19 @@ void Yap_InitMYDDAS_SharedPreds(void) {
|
||||
#ifdef DEBUG
|
||||
Yap_InitCPred("c_db_check", 0, c_db_check, 0);
|
||||
#endif
|
||||
CurrentModule = cm;
|
||||
}
|
||||
|
||||
void Yap_InitBackMYDDAS_SharedPreds(void) {
|
||||
Term cm = CurrentModule;
|
||||
CurrentModule = MkAtomTerm(Yap_LookupAtom("myddas"));
|
||||
/* Gives all the predicates associated to a given connection */
|
||||
Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(Int), c_db_preds_conn_start,
|
||||
c_db_preds_conn_continue, 0);
|
||||
/* Gives all the connections stored on the MYDDAS Structure*/
|
||||
Yap_InitCPredBack("c_db_connection", 1, sizeof(Int), c_db_connection_start,
|
||||
c_db_connection_continue, 0);
|
||||
CurrentModule = cm;
|
||||
}
|
||||
|
||||
static bool myddas_initialised;
|
||||
|
@ -97,15 +97,6 @@
|
||||
#endif
|
||||
% myddas_assert_predicates.ypp
|
||||
,
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/2,
|
||||
db_insert/3,
|
||||
db_abolish/2,
|
||||
db_listing/0,
|
||||
db_listing/1
|
||||
% myddas_mysql.ypp
|
||||
]).
|
||||
|
||||
@ -123,7 +114,7 @@
|
||||
]).
|
||||
#endif
|
||||
|
||||
:- use_module(myddas_assert_predicates,[
|
||||
:- reexport(myddas_assert_predicates,[
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
@ -140,12 +131,12 @@
|
||||
|
||||
:- use_module(myddas_sqlite3,[
|
||||
% myddas_mysql.ypp
|
||||
%c_sqlite3_connect/4,
|
||||
%c_sqlite3_disconnect/1,
|
||||
%c_sqlite3_query/5,
|
||||
c_sqlite3_connect/4,
|
||||
c_sqlite3_disconnect/1,
|
||||
c_sqlite3_query/5,
|
||||
c_sqlite3_number_of_fields/3,
|
||||
c_sqlite3_get_attributes_types/3,
|
||||
sqlite3_result_set/1,
|
||||
%c_sqlite3_number_of_fields/3,
|
||||
%c_sqlite3_get_attributes_types/3,
|
||||
sqlite3_describe/3,
|
||||
sqlite3_show_tables/2,
|
||||
sqlite3_row/3
|
||||
|
@ -29,7 +29,8 @@
|
||||
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_module/1
|
||||
db_module/1,
|
||||
c_db_connection_type/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
|
@ -19,28 +19,27 @@
|
||||
#define DBMS(x) sqlite3_##x
|
||||
#define c_DBMS(x) c_sqlite3_##x
|
||||
#define NAME() 'YAPsqlite3'
|
||||
#define MODULE() user
|
||||
#define MODULE() myddas_sqlite3
|
||||
#define INIT() init_sqlite3
|
||||
#elif defined( odbc )
|
||||
#undef odbc
|
||||
#define DBMS(x) odbc_##x
|
||||
#define c_DBMS(x) c_odbc_##x
|
||||
#define NAME() 'YAPodbc'
|
||||
#define MODULE() user
|
||||
#define MODULE() myddas_odbc
|
||||
#define INIT() init_odbc
|
||||
#elif defined( postgres )
|
||||
#undef postgres
|
||||
#define DBMS(x) postgres_##x
|
||||
#define c_DBMS(x) c_postgres_##x
|
||||
#define NAME() 'YAPpostgres'
|
||||
#define MODULE() user
|
||||
#define MODULE() myddas_postgres
|
||||
#define INIT() init_postgres
|
||||
#endif
|
||||
|
||||
#if defined(DBMS)
|
||||
|
||||
:- module(MODULE(),[
|
||||
/*
|
||||
c_DBMS(change_database)/2,
|
||||
c_DBMS(connect)/4,
|
||||
c_DBMS(disconnect)/1,
|
||||
@ -50,8 +49,8 @@
|
||||
c_DBMS(get_next_result_set)/3,
|
||||
c_DBMS(query)/5,
|
||||
c_DBMS(number_of_fields)/3,
|
||||
*/
|
||||
DBMS(describe)/3,
|
||||
DBMS(result_set)/1,
|
||||
DBMS(show_tables)/2,
|
||||
DBMS(row)/3
|
||||
]).
|
||||
@ -61,9 +60,7 @@
|
||||
:- use_module(library(maplist)).
|
||||
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_sql/3
|
||||
]).
|
||||
:- use_module(myddas).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
@ -154,7 +151,7 @@ DBMS(datalog_show_tables)(Connection) :-
|
||||
% DBMS(show_tables)/2
|
||||
% gives the results of the SHOW TABLES statement
|
||||
% by backtracking
|
||||
DBMS(show_tables)(Connection,table(Table)) :-
|
||||
DBMS(showq_tables)(Connection,table(Table)) :-
|
||||
'$get_value'(Connection,Conn),
|
||||
SQL = 'SELECT name FROM sqlite_master WHERE type=\'table\' ORDER BY name',
|
||||
DBMS(result_set)(Mode),
|
||||
|
@ -630,6 +630,8 @@ static Int c_sqlite3_row(USES_REGS1) {
|
||||
}
|
||||
|
||||
static void Yap_InitMYDDAS_SQLITE3Preds(void) {
|
||||
Term cm = CurrentModule;
|
||||
CurrentModule = MkAtomTerm(Yap_LookupAtom("myddas_sqlite3"));
|
||||
/* db_dbect: Host x User x Passwd x Database x dbection x ERROR_CODE */
|
||||
Yap_InitCPred("c_sqlite3_connect", 4, c_sqlite3_connect, 0);
|
||||
|
||||
@ -661,23 +663,24 @@ static void Yap_InitMYDDAS_SQLITE3Preds(void) {
|
||||
|
||||
/* c_sqlite3_change_database: connection x DataBaseName */
|
||||
Yap_InitCPred("c_sqlite3_change_database", 2, c_sqlite3_change_database, 0);
|
||||
CurrentModule = cm;
|
||||
}
|
||||
static void Yap_InitBackMYDDAS_SQLITE3Preds(void) {
|
||||
Term cm = CurrentModule;
|
||||
CurrentModule = MkAtomTerm(Yap_LookupAtom("myddas_sqlite3"));
|
||||
/* db_row: ResultSet x Arity x ListOfArgs */
|
||||
// Yap_InitCPredBack("c_sqlite3_row", 3, 0, c_sqlite3_row_initialise,
|
||||
// c_sqlite3_row, c_sqlite3_row_terminate);
|
||||
Yap_InitCPred("c_sqlite3_row_initialise", 2, c_sqlite3_row_initialise, 0);
|
||||
Yap_InitCPred("c_sqlite3_row_terminate", 2, c_sqlite3_row_terminate, 0);
|
||||
Yap_InitCPredBack("c_sqlite3_row_get", 4, 0, c_sqlite3_row, c_sqlite3_row, 0);
|
||||
CurrentModule = cm;
|
||||
}
|
||||
|
||||
X_API void init_sqlite3(void) {
|
||||
Term cm = CurrentModule;
|
||||
|
||||
Yap_InitMYDDAS_SQLITE3Preds();
|
||||
|
||||
Yap_InitBackMYDDAS_SQLITE3Preds();
|
||||
CurrentModule = cm;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
:- use_module(library(plunit)).
|
||||
|
||||
:- begin_tests(sqlite3).
|
||||
@ -13,7 +12,7 @@ test(db_open) :-
|
||||
db_open(sqlite3, '/data/user/0/pt.up.yap/files/chinook.db', _, _).
|
||||
:- else.
|
||||
test(db_open) :-
|
||||
db_open(sqlite3,myddas,dataset('chinook.db'),_,_).
|
||||
db_open(sqlite3,myddas,dataset('chinook.db'),_,_).
|
||||
:-endif.
|
||||
|
||||
test(schema0, all((Desc ==[(table albums),
|
||||
@ -98,3 +97,4 @@ test(close) :-
|
||||
:- end_tests(sqlite3).
|
||||
|
||||
:- run_tests.
|
||||
|
||||
|
@ -46,10 +46,9 @@ fail.
|
||||
recorded('$import','$import'(ExportingMod,ImportingMod,G0,G,_,_),_).
|
||||
%% parent/user
|
||||
'$get_predicate_definition'(ImportingMod:G,ExportingMod:G0) :-
|
||||
( '$parent_module'(ImportingMod, PMod) ), %; PMod = user),
|
||||
(nonvar(G0),'$pred_exists'(G0,PMod), PMod:G0 = ExportingMod:G;
|
||||
recorded('$import','$import'(ExportingMod,PMod,G0,G,_,_),_)
|
||||
).
|
||||
( '$parent_module'(ImportingMod, PMod) ; PMod = user ),
|
||||
ImportingMod \= PMod,
|
||||
'$get_predicate_definition'(PMod:G, ExportingMod:G0).
|
||||
%% autoload`
|
||||
%'$get_predicate_definition'(ImportingMod:G,ExportingMod:G) :-
|
||||
% current_prolog_flag(autoload, true),
|
||||
|
@ -485,8 +485,9 @@ current_predicate(A0,T0) :-
|
||||
'$all_current_modules'(M)
|
||||
),
|
||||
% M is bound
|
||||
M \= prolog,
|
||||
(
|
||||
'$current_predicate'(A,M,T,user),
|
||||
'$current_predicate'(A,M,T,_),
|
||||
functor(T, A, _)
|
||||
;
|
||||
'$get_predicate_definition'(M:T,M1:_T1),
|
||||
|
Reference in New Issue
Block a user