This commit is contained in:
Vitor Santos Costa 2018-07-02 16:48:00 +01:00
parent 71aed8b870
commit fd492b5b16
8 changed files with 37 additions and 32 deletions

View File

@ -2129,20 +2129,17 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
char *d = Malloc(strlen(fl)+1);
strcpy(d,fl);
bool consulted = (mode == YAP_CONSULT_MODE);
sno = Yap_OpenStream(MkStringTerm(fl), "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding);
Term tat = MkAtomTerm(Yap_LookupAtom(d));
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), LOCAL_encoding);
if (sno < 0 ||
!Yap_ChDir(dirname((char *)d))) {
pop_text_stack(lvl);
*full = NULL;
return -1;
}
LOCAL_PrologMode = UserMode;
} LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, fl);
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
*full = pop_output_text_stack(lvl, fl);
pop_text_stack(lvl);
RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno;

View File

@ -161,8 +161,7 @@ static bool consult(const char *b_file USES_REGS) {
/* consult in C */
int lvl = push_text_stack();
char *full = Malloc(YAP_FILENAME_MAX + 1);
full[0] = '\0';
char *full;
/* the consult mode does not matter here, really */
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) {
osno = 0;
@ -213,8 +212,12 @@ static bool consult(const char *b_file USES_REGS) {
}
BACKUP_MACHINE_REGS();
YAP_EndConsult(c_stream, &osno, full);
pop_text_stack(lvl);
return true;
if (!Yap_AddAlias(AtomLoopStream, osno)) {
pop_text_stack(lvl);
return false;
}
pop_text_stack(lvl);
return true;
}
///

View File

@ -57,6 +57,7 @@
with the `use_module(library(lists))` command.
*/
:- include(pl/bootlists).
/** @pred list_concat(+ _Lists_,? _List_)

View File

@ -101,7 +101,7 @@ db_import(Connection,RelationName,PredName0) :-
not c_db_check_if_exists_pred(PredName,Arity,Module),
R=..[relation,PredName,Arity,RelationName],
% assert relation fact
assert(user:R),
assert(Module:R),
Size is 2*Arity,
length(TypesList, Size),
@ -114,15 +114,15 @@ db_import(Connection,RelationName,PredName0) :-
% build PredName functor
functor(P,PredName,Arity),
P=..[PredName|LA],
M=myddas_assert_predicates,
%build PredName clause
table_access_predicate( ConType, Con, Arity, P, LA, M, Assert ),
assert(Module:Assert),
table_access_predicate( ConType, Con, Arity, P, LA, Modulelisting, Assert ),
assert_static(Module:Assert),
c_db_add_preds(PredName,Arity,Module,Con).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- meta_predicate db_view(:,0).
:- meta_predicate db_view(+,:,0).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_view/3
@ -289,8 +289,9 @@ table_attributes( sqlite3, Con, RelationName, TypesList ) :-
% predicate for DB-> query
table_access_predicate( mysql, Con, Arity, P, LA, M,
( P :- M:('$copy_term_nv'(P,[],G,_),
( P :- user:('$copy_term_nv'(P,[],G,_),
translate(G,G,Code),
queries_atom(Code,FinalSQL),
db_my_result_set(Mode),
@ -299,9 +300,9 @@ table_access_predicate( mysql, Con, Arity, P, LA, M,
!,
c_db_my_row(ResultSet,Arity,LA) ))).
table_access_predicate( postgres, Con, Arity, P, LA, M,
( P :- M:('$copy_term_nv'(P,[],G,_),
translate(G,G,Code),
table_access_predicate( postgres, Con, Arity, P, LA, _M,
( P :- '$copy_term_nv'(P,[],G,_),
translate(M:G,M:G,Code),
queries_atom(Code,FinalSQL),
db_my_result_set(Mode),
'$write_or_not'(FinalSQL),
@ -310,8 +311,8 @@ table_access_predicate( postgres, Con, Arity, P, LA, M,
c_postgsres_row(ResultSet,Arity,LA) ))).
table_access_predicate( sqlite3, Con, Arity, P, LA, M,
( P :- M:('$copy_term_nv'(P,[],G,_),
translate(G,G,Code),
( P :- ('$copy_term_nv'(P,[],G,_),
translate(M:G,M:G,Code),
queries_atom(Code,FinalSQL),
sqlite3_result_set(Mode),
'$write_or_not'(FinalSQL),

View File

@ -56,6 +56,11 @@
DBMS(row)/3
]).
:- use_module(library(lists)).
:- use_module(library(maplist)).
:- use_module(myddas,[
db_sql/3
]).

View File

@ -2,7 +2,7 @@
:- use_module(library(lists)).
:- use_module(library(maplist)).
:- use_module(library(maplist)).
:- use_module(library(myddas)).
main :-
@ -10,7 +10,7 @@ main :-
main_,
close.
main_ :-
go,
catch(go,E,writeln(E)),
fail.
main_ .
@ -28,6 +28,11 @@ go :-
db_import('tracks', tracks),
writeln(('tracks -> tracks')).
go :-
% X=1,
artists(X,Y),
writeln(X:Y).
go :-
writeln(db_get_attributes_types),
db_get_attributes_types(albums,Als),
@ -57,6 +62,7 @@ go :-
db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')),
writeln(T:tableinfo(FieldID,Type,Null,Primary,Default,'')).
go :-
writeln(access),
go_cut0.
@ -73,11 +79,6 @@ go :-
go :-
go_cut1.
go :-
% X=1,
artists(X,Y),
writeln(X:Y).
go_cut0 :-
artists(X,Y),
writeln(X:Y),

View File

@ -7,8 +7,6 @@
* @{
*/
:- system_module( '$_lists', [], []).
:- set_prolog_flag(source, true). % source.
% memberchk(+Element, +Set)

View File

@ -1033,7 +1033,6 @@ prolog:print_message(Severity, Term) :-
!.
prolog:print_message(Severity, Term) :-
translate_message( Term, Severity, Lines0, [ end(Id)]),
writeln(Lines0),
Lines = [begin(Severity, Id)| Lines0],
(
user:message_hook(Term, Severity, Lines)