diff --git a/C/fli_absmi_insts.h b/C/fli_absmi_insts.h
index a0d3e9dd6..abbf83629 100644
--- a/C/fli_absmi_insts.h
+++ b/C/fli_absmi_insts.h
@@ -10,6 +10,18 @@
#endif /* INDENT_CODE */
BOp(call_cpred, Osbpp);
+#if __ANDROID__
+ char *s; Atom name;
+ if (PREG->y_u.Osbpp.p->ArityOfPE) {
+ Functor f = PREG->y_u.Osbpp.p->FunctorOfPred;
+ name = f->NameOfFE;
+ } else {
+ name = (Atom)(PREG->y_u.Osbpp.p->FunctorOfPred);
+ }
+ s = name->StrOfAE;
+
+ __android_log_print(ANDROID_LOG_INFO, "YAP", " %s ", s);
+#endif
check_trail(TR);
if (!(PREG->y_u.Osbpp.p->PredFlags & (SafePredFlag|NoTracePredFlag|HiddenPredFlag))) {
CACHE_Y_AS_ENV(YREG);
diff --git a/C/pl-yap.c b/C/pl-yap.c
index 97beb5b9d..e6e0e5621 100755
--- a/C/pl-yap.c
+++ b/C/pl-yap.c
@@ -929,33 +929,39 @@ char *
Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags)
{
- char *r, buf[4096];
+ char *buf;
- int64_t size;
- IOSTREAM *fd;
+ size_t size = 4096, total = size;
+ IOSTREAM *fd;
- r = buf;
- fd = Sopenmem(&r, &sz, "w");
- fd->encoding = ENC_UTF8;
- if ( PL_write_term(fd, l, 1200, flags) &&
- Sputcode(EOS, fd) >= 0 &&
- Sflush(fd) >= 0 )
- {
- size = Stell64(fd);
- *length = size-1;
- char *bf = malloc(*length+1);
- if (!bf)
- return NULL;
- strncpy(bf,buf,*length+1);
- Sclose(fd);
- r = bf;
- return r;
- }
- /* failed */
- if ( r != buf ) {
- Sfree(r);
+ total = size;
+ buf = malloc(total);
+ while ( (fd = Sopenmem(&buf, &size, "w")) == NULL ||
+ (( fd->encoding = ENC_UTF8) && FALSE) ||
+ (PL_write_term(fd, l, 1200, flags) == 0) ||
+ Sputcode(EOS, fd) < 0 ||
+ Sflush(fd) < 0 ) /* failure */
+ {
+#ifdef DEBUG
+ {CACHE_REGS
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);}
+#endif
+ Sclose(fd);
+ if (!fd)
+ return NULL;
+ total += size;
+ buf = realloc(buf, total);
+ if (!buf)
+ return NULL;
+ Sclose(fd);
}
- return NULL;
+#ifdef DEBUG
+ {CACHE_REGS
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text done %s", buf);}
+#endif
+ Sclose(fd);
+ /* success */
+ return buf;
}
diff --git a/C/stdpreds.c b/C/stdpreds.c
index ac4d638a2..200e8f0f0 100644
--- a/C/stdpreds.c
+++ b/C/stdpreds.c
@@ -931,6 +931,7 @@ static Int cont_current_predicate(USES_REGS1) {
if (!is_det) {
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p);
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q);
+ B->cp_h = HR;
}
} else if (IsNonVarTerm(t2)) {
// operating within the same module.
@@ -943,6 +944,7 @@ static Int cont_current_predicate(USES_REGS1) {
npp = pp->NextPredOfModule;
if (npp) {
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(npp);
+ B->cp_h = HR;
} else {
is_det = true;
}
@@ -957,12 +959,14 @@ static Int cont_current_predicate(USES_REGS1) {
else {
pp = m->PredForME;
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m);
+ B->cp_h = HR;
}
} // we found a new answer
if (!pp)
cut_fail();
else
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp->NextPredOfModule);
+ B->cp_h = HR;
}
if (pp->ModuleOfPred != IDB_MODULE) {
f = pp->FunctorOfPred;
@@ -1081,6 +1085,7 @@ static Int init_current_predicate(USES_REGS1) {
cut_fail();
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p);
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q);
+ B->cp_h = HR;
}
}
// check module
@@ -1102,6 +1107,7 @@ static Int init_current_predicate(USES_REGS1) {
}
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m);
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp);
+ B->cp_h = HR;
}
// ensure deref access to choice-point fields.
return cont_current_predicate(PASS_REGS1);
@@ -1124,7 +1130,7 @@ int Yap_IsOpMaxPrio(Atom at) {
CACHE_REGS
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
int max;
-
+
if (EndOfPAEntr(op))
return 0;
max = (op->Prefix & 0xfff);
@@ -1156,6 +1162,7 @@ static Int cont_current_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock);
if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
+ B->cp_h = HR;
return TRUE;
} else {
cut_succeed();
@@ -1164,6 +1171,7 @@ static Int cont_current_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock);
if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
+ B->cp_h = HR;
return FALSE;
} else {
cut_fail();
@@ -1171,21 +1179,22 @@ static Int cont_current_op(USES_REGS1) {
}
}
-static Int init_current_op(
- USES_REGS1) { /* current_op(-Precedence,-Type,-Atom) */
+static Int init_current_op(USES_REGS1) { /* current_op(-Precedence,-Type,-Atom) */
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)OpList);
+ B->cp_h = HR;
return cont_current_op(PASS_REGS1);
}
static Int cont_current_atom_op(USES_REGS1) {
OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)), *next;
-
+
READ_LOCK(op->OpRWLock);
next = NextOp(RepOpProp(op->NextOfPE) PASS_REGS);
if (unify_op(op PASS_REGS)) {
READ_UNLOCK(op->OpRWLock);
if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
+ B->cp_h = HR;
return TRUE;
} else {
cut_succeed();
@@ -1194,6 +1203,7 @@ static Int cont_current_atom_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock);
if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
+ B->cp_h = HR;
return FALSE;
} else {
cut_fail();
@@ -1216,6 +1226,7 @@ static Int init_current_atom_op(
cut_fail();
}
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
+ B->cp_h = HR;
return cont_current_atom_op(PASS_REGS1);
}
diff --git a/C/write.c b/C/write.c
index 669eaff81..1dcf46053 100644
--- a/C/write.c
+++ b/C/write.c
@@ -1189,19 +1189,18 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
}
}
+struct write_globs wglb;
+struct rewind_term rwt;
+
void Yap_plwrite(Term t, void *mywrite, int max_depth, int flags, int priority)
/* term to be written */
/* consumer */
/* write options */
{
- struct write_globs wglb;
- struct rewind_term rwt;
-
if (!mywrite)
wglb.stream = Serror;
else
wglb.stream = mywrite;
-
wglb.lw = separator;
wglb.last_atom_minus = FALSE;
wglb.Quote_illegal = flags & Quote_illegal_f;
diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp
index 944950593..90cc1b055 100644
--- a/CXX/yapi.cpp
+++ b/CXX/yapi.cpp
@@ -88,6 +88,7 @@ YAPStringTerm::YAPStringTerm(char *s, size_t len) { // build string
BACKUP_H();
CACHE_REGS
+
seq_tv_t inp, out;
inp.val.c = s;
inp.type = YAP_STRING_CHARS;
@@ -104,6 +105,7 @@ YAPStringTerm::YAPStringTerm(wchar_t *s): YAPTerm() { // build string
BACKUP_H();
CACHE_REGS
+
seq_tv_t inp, out;
inp.val.w = s;
inp.type = YAP_STRING_WCHARS;
@@ -119,6 +121,7 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build stri
BACKUP_H();
CACHE_REGS
+
seq_tv_t inp, out;
inp.val.w = s;
inp.type = YAP_STRING_WCHARS;
@@ -133,17 +136,24 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build stri
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
+ BACKUP_MACHINE_REGS();
UInt arity = ArityOfFunctor(f.f);
mk ( Yap_MkApplTerm( f.f, arity, (Term *)ts) );
+ RECOVER_MACHINE_REGS();
}
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() {
+ BACKUP_MACHINE_REGS();
UInt arity = ArityOfFunctor(f.f);
mk ( Yap_MkNewApplTerm( f.f, arity) );
+ RECOVER_MACHINE_REGS();
}
YAPTerm YAPApplTerm::getArg(int arg) {
- return YAPTerm( ArgOfTerm(arg, gt() ) );
+ BACKUP_MACHINE_REGS();
+ YAPTerm to = YAPTerm( ArgOfTerm(arg, gt() ) );
+ RECOVER_MACHINE_REGS();
+ return to;
}
YAPFunctor YAPApplTerm::getFunctor() {
@@ -152,11 +162,15 @@ YAPFunctor YAPApplTerm::getFunctor() {
YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() {
CACHE_REGS
+ BACKUP_MACHINE_REGS();
mk ( MkPairTerm( th.term(), tl.term() ) );
+ RECOVER_MACHINE_REGS();
}
YAPPairTerm::YAPPairTerm() : YAPTerm() {
+ BACKUP_MACHINE_REGS();
t = Yap_MkNewPairTerm( );
+ RECOVER_MACHINE_REGS();
}
void YAPTerm::mk(Term t0) { CACHE_REGS t = Yap_InitSlot( t0 PASS_REGS); }
@@ -268,16 +282,24 @@ intptr_t YAPTerm::hashTerm(size_t sz, size_t depth, bool variant) {
return out;
}
-char *YAPTerm::text() {
+const char *YAPTerm::text() {
size_t sze = 4096, length;
char *os;
int enc;
BACKUP_MACHINE_REGS();
+#ifdef DEBUG
+ {CACHE_REGS
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x \n", t, LOCAL_SlotBase[t]);}
+#endif
if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) {
RECOVER_MACHINE_REGS();
return (char *)NULL;
}
+#ifdef DEBUG
+ {CACHE_REGS
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x %p\n", t, LOCAL_SlotBase[t], os);}
+#endif
RECOVER_MACHINE_REGS();
return os;
}
@@ -287,21 +309,19 @@ char *YAPQuery::text() {
char *os;
int enc;
- { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I LCL0+%p/t=(%d) %x", LCL0, *q_g, LCL0[-15]) ; }
+ { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I t=(%d) %lx", *q_g) ; }
BACKUP_MACHINE_REGS();
if (!(os = Yap_HandleToString(*q_g, sze, &length, &enc, 0))) {
- { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "IIa LCL0+t=(%p) %x oz=%p %s", LCL0, LCL0[-15], os, os) ; }
- RECOVER_MACHINE_REGS();
+ RECOVER_MACHINE_REGS();
return (char *)NULL;
}
- { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II LCL0+t=(%p) %x", LCL0, LCL0[-15]) ; }
+ { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II ") ; }
RECOVER_MACHINE_REGS();
return os;
}
bool YAPListTerm::nil() {
CACHE_REGS
- __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d LCL0+t=(%p)", t, LCL0+t) ;
return gt() == TermNil;
}
@@ -327,15 +347,15 @@ YAPTerm::YAPTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn )
YAPTerm YAPListTerm::car()
{
- { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d LCL0+t=(%p)", t, LCL0+t) ; }
Term to = gt();
+ { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%d", to) ; }
if (IsPairTerm(to))
return YAPTerm(HeadOfTerm(to));
else
return MkIntTerm(-1);
}
-YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
+ YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
char *YAPAtom::getName(void) {
@@ -602,8 +622,8 @@ YAPPredicate::YAPPredicate(YAPAtom at, arity_t arity) {
PredEntry *YAPPredicate::getPred( Term t, Term* &outp ) {
CACHE_REGS
Term m = CurrentModule ;
- { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "H= %p, outp=%p", HR, outp) ; }
- t = Yap_StripModule(t, &m);
+ { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "H= %p, outp=%p", HR, outp) ; }
+t = Yap_StripModule(t, &m);
if (IsVarTerm(t) || IsNumTerm(t)) {
ap = (PredEntry *)NULL;
outp = (Term *)NULL;
diff --git a/CXX/yapt.hh b/CXX/yapt.hh
index 2fd869782..223ea67d6 100644
--- a/CXX/yapt.hh
+++ b/CXX/yapt.hh
@@ -1,6 +1,8 @@
#ifndef YAPT_HH
#define YAPT_HH 1
+class YAPAtomTerm;
+
/**
* @brief Generic Prolog Term
*/
@@ -9,7 +11,8 @@ class YAPTerm {
friend class YAPPrologPredicate;
friend class YAPQuery;
friend class YAPModule;
- friend class YAPModuleProp;
+ friend class YAPModuleProp;
+ friend class YAPApplTerm;
protected:
yhandle_t t; /// handle to term, equivalent to term_t
void mk(Term t0); /// internal method to convert from term to handle
@@ -37,33 +40,39 @@ public:
bool unifiable(YAPTerm t1); /// we can unify t and t1
bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash,
- bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound
- bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom
- bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer
- bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point
- bool isString() { return IsStringTerm( gt() ); } /// type check for a string " ... "
- bool isCompound() { return !(IsVarTerm( gt() ) || IsNumTerm( gt() )); } /// is a primitive term
- bool isAppl() { return IsApplTerm( gt() ); } /// is a structured term
- bool isPair() { return IsPairTerm( gt() ); } /// is a pair term
- bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground
- bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list
+ virtual bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound
+ virtual bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom
+ virtual bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer
+ virtual bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point
+ virtual bool isString() { return IsStringTerm( gt() ); } /// type check for a string " ... "
+ virtual bool isCompound() { return !(IsVarTerm( gt() ) || IsNumTerm( gt() )); } /// is a primitive term
+ virtual bool isAppl() { return IsApplTerm( gt() ); } /// is a structured term
+ virtual bool isPair() { return IsPairTerm( gt() ); } /// is a pair term
+ virtual bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground
+ virtual bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list
/// extract the argument i of the term, where i in 1...arity
inline YAPTerm getArg(int i) {
+ BACKUP_MACHINE_REGS();
Term t0 = gt();
+ YAPTerm tf;
if (IsApplTerm(t0))
- return YAPTerm(ArgOfTerm(i, t0));
+ tf = YAPTerm(ArgOfTerm(i, t0));
else if (IsPairTerm(t0)) {
if (i==1)
- return YAPTerm(HeadOfTerm(t0));
- if (i==2)
- return YAPTerm(TailOfTerm(t0));
+ tf = YAPTerm(HeadOfTerm(t0));
+ else if (i==2)
+ tf = YAPTerm(TailOfTerm(t0));
+ } else {
+ tf = YAPTerm((Term)0);
}
- return YAPTerm((Term)0);
+ RECOVER_MACHINE_REGS();
+ //{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "after getArg H= %p, i=%d", HR, tf.gt()) ; }
+ return tf;
}
/// return a string with a textual representation of the term
- char *text();
+ virtual const char *text();
};
/**
@@ -78,6 +87,44 @@ public:
CELL *getVar() { return VarOfTerm( gt() ); }
/// is the variable bound to another one
bool unbound() { return IsUnboundVar(VarOfTerm( gt() )); }
+ virtual bool isVar() { return true; } /// type check for unbound
+ virtual bool isAtom() { return false; } /// type check for atom
+ virtual bool isInteger() { return false; } /// type check for integer
+ virtual bool isFloat() { return false; } /// type check for floating-point
+ virtual bool isString() { return false; } /// type check for a string " ... "
+ virtual bool isCompound() { return false; } /// is a primitive term
+ virtual bool isAppl() { return false; } /// is a structured term
+ virtual bool isPair() { return false; } /// is a pair term
+ virtual bool isGround() { return false; } /// term is ground
+ virtual bool isList() { return false; } /// term is a list
+};
+
+/**
+ * @brief Atom Term
+ * Term Representation of an Atom
+ */
+class YAPAtomTerm: YAPTerm {
+ friend class YAPModule;
+ // Constructor: receives a C-atom;
+ YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
+ YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
+ // Getter for Prolog atom
+ Term getTerm() { return t; }
+public:
+ // Constructor: receives an atom;
+ YAPAtomTerm(YAPAtom a): YAPTerm() { mk( MkAtomTerm(a.a) ); }
+ // Constructor: receives a sequence of ISO-LATIN1 codes;
+ YAPAtomTerm(char *s) ;
+ // Constructor: receives a sequence of up to n ISO-LATIN1 codes;
+ YAPAtomTerm(char *s, size_t len);
+ // Constructor: receives a sequence of wchar_ts, whatever they may be;
+ YAPAtomTerm(wchar_t *s) ;
+ // Constructor: receives a sequence of n wchar_ts, whatever they may be;
+ YAPAtomTerm(wchar_t *s, size_t len);
+ // Getter: outputs the atom;
+ YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); }
+ // Getter: outputs the name as a sequence of ISO-LATIN1 codes;
+ const char *getName() { return AtomOfTerm( gt() )->StrOfAE; }
};
/**
@@ -123,6 +170,10 @@ public:
/// Create a list term out of a standard term. Check if a valid operation.
///
/// @param[in] the term
+ YAPListTerm() { mk(TermNil); /* else type_error */ }
+ /// Create an empty list term.
+ ///
+ /// @param[in] the term
YAPListTerm(Term t0) { mk(t0); /* else type_error */ }
/* /// Create a list term out of an array of terms.
///
@@ -145,8 +196,9 @@ public:
Term to = gt();
if (IsPairTerm( to ))
return YAPListTerm(TailOfTerm( to ));
- else
- return MkIntTerm(-1);
+ else if ( to == TermNil)
+ return YAPListTerm( );
+ /* error */;
}
/// Check if the list is empty.
@@ -171,32 +223,4 @@ public:
const char *getString() { return StringOfTerm( gt() ); }
};
-/**
- * @brief Atom Term
- * Term Representation of an Atom
- */
-class YAPAtomTerm: YAPTerm {
- friend class YAPModule;
- // Constructor: receives a C-atom;
- YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
- YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
- // Getter for Prolog atom
- Term getTerm() { return t; }
-public:
- // Constructor: receives an atom;
- YAPAtomTerm(YAPAtom a): YAPTerm() { mk( MkAtomTerm(a.a) ); }
- // Constructor: receives a sequence of ISO-LATIN1 codes;
- YAPAtomTerm(char *s) ;
- // Constructor: receives a sequence of up to n ISO-LATIN1 codes;
- YAPAtomTerm(char *s, size_t len);
- // Constructor: receives a sequence of wchar_ts, whatever they may be;
- YAPAtomTerm(wchar_t *s) ;
- // Constructor: receives a sequence of n wchar_ts, whatever they may be;
- YAPAtomTerm(wchar_t *s, size_t len);
- // Getter: outputs the atom;
- YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); }
- // Getter: outputs the name as a sequence of ISO-LATIN1 codes;
- const char *getName() { return AtomOfTerm( gt() )->StrOfAE; }
-};
-
#endif /* YAPT_HH */
diff --git a/library/parameters.yap b/library/parameters.yap
index ffd9b7cda..1876f3812 100644
--- a/library/parameters.yap
+++ b/library/parameters.yap
@@ -72,7 +72,7 @@
:- use_module( library(bdd) ).
-:- dynamic extension/4, init/2, frame/2.
+:- dynamic extension/4, init/2, frame/2, exclusive/0.
user:term_expansion(Term,Clauses) :-
Term = ( Spec :- Body),
@@ -92,50 +92,61 @@ find_name( [_|UnsortedCurrentNames] , V, Name) :-
expand( Skel, Names, GoalVars, Body, Tests, Out) :-
Skel =.. [N|As], %
%pick(Vs, As, Os),
- trace,
append(As, GoalVars, Os),
- Head =.. [N|Os],
+ Head =.. [N|Os],
maplist(original_name(GoalVars), Names, Ts),
LinkGoal =.. [access|Ts],
+ trace,
formula( Tests, Fs, Dic),
bdd_new(Fs , BDD),
bdd_print( BDD, '/Users/vsc/bdd.dot', Names),
- bdd_tree(BDD, Tree),
+ bdd_tree(BDD, Tree),
ptree(Tree, Names, Dic),
% portray_clause((Head:-GExtBody)),
unnumbervars((Head:- LinkGoal,Body), Out).
-ptree( bdd(_,L,_Vs) , Names, Dic) :-
-% term_variables(L, LVs),
+swap_f(Key-V, Key=V).
+
+ptree( bdd(Root,L,_Vs) , Names, File, Dic) :-
+ % term_variables(L, LVs),
% Vs =.. [_|LVs],
-% trace,
-maplist( bindv,Names),
+ maplist( bindv,Names),
rb_visit(Dic, Pairs),
maplist( bindv,Pairs),
- open('bdd.dot', write, S) ,
+ absolute_file_name( File, [], AbsFile ),
+ open(AbsFile, write, S) ,
format(S,'digraph "DD" {
size = "7.5,10"
center = true;~n', []),
+ format(S,' "~w" [label = "~w"];~n', [1, Root]),
maplist( print_node(S), L),
format(S, '}~n', []),
close(S),
fail.
ptree(_, _, _).
-bindv( X = '$VAR'(X) ).
-bindv( X - '$VAR'(X) ).
+bindv( X = '$VAR'(X) ) :- !.
+bindv( X - '$VAR'(X) ) :- !.
+bindv(_).
print_node(S,pp( Val, Name, Left, Right )) :-
+ %writeln(Name),
simplify(Name, N),
format(S,' "~w" [label = "~w"];~n', [Val, N]),
- format(S,' "~w" -> "~w";~n', [Val, Right]),
- format(S,' "~w" -> "~w" [style = dashed];~n', [Val, Left]).
+ format(S,' "~w" -> "~w" [arrowType="none" color="red"] ;~n', [Val, Left]),
+ format(S,' "~w" -> "~w" [style = dashed arrowType="none"];~n', [Val, Right]).
print_node(S,pn( Val, Name, Left, Right )) :-
simplify(Name, N),
+ %writeln(Name),
format(S,' "~w" [label = "~w"];~n', [Val, N]),
- format(S,' "~w" -> "~w";~n', [Val, Right]),
- format(S,' "~w" -> "~w" [style = dashed];~n', [Val, Left]).
+ format(S,' "~w" -> "~w" [arrowType="none" color="red"];~n', [Val,Left]),
+ ( Right == 1 ->
+ format(S,' "~w" -> "0" [dir=none style = dotted];~n', [Val])
+ ;
+ format(S,' "~w" -> "~w" [style = dotted type="odot"];~n', [Val, Right])
+ ).
+simplify(V,V) :- var(V),!.
simplify('$VAR'(X),Y) :- !, simplify(X,Y).
simplify(c^(X),Y) :- !, simplify(X,Y).
simplify(G, X:M) :- G=.. [X,N], !, simplify(N,M).
@@ -145,7 +156,7 @@ simplify(X, X).
/*
pick([LastV,LastV1|More], As, OVs) :-
nonvar(LastV),
- LastV = (ID:_Name=V),
+ LastV = (ID:_Name=V),
nonvar(LastV1),
LastV1 = (ID: _Name1=_V1), !,
(
@@ -428,16 +439,16 @@ ensure((X in D)) :-
formula( Axioms, FormulaE, Dic) :-
rb_new( Dic0 ),
- partition( is_init, Axioms, _Inits, OGoals),
- partition( is_frame, OGoals, _Frames, Goals),
+ partition( is_frame, Axioms, _, Goals),
foldl2( eq, Goals, Formula, Dic0, Dic, [], Extras),
append(Formula, Extras, FormulaL),
- maplist(writeln,FormulaL),
list2prod( FormulaL, FormulaE).
-is_init( A ?= B ) :- assert(init(A, B)).
-
is_frame( A =:= B ) :- assert( frame(A, B)).
+is_frame( level(N, [H|L]) ) :- !, maplist( assertn(level, N), [H|L] ).
+is_frame( level(N, L ) ) :- assert( level( N, L) ).
+
+assertn(level, N, L) :- assert( level( N, L) ).
list2prod( [], true).
list2prod( [F], F).
@@ -445,17 +456,20 @@ list2prod( [F1,F2|Fs], F1*NF) :-
list2prod( [F2|Fs], NF).
%eq(G,_,_,_,_,_) :- writeln(a:G), fail.
+eq(1, 1, Dic, Dic, I, I) :- !.
+eq(X, VX, Dic0, Dic, I0, I) :- var(X), !,
+ add(X, VX, Dic0, Dic, I0, I).
eq(X == Exp, (-TA + TY)*(-TY + TA), Dic0, Dic, I0, I) :- !,
eq(X, TA, Dic0, Dic1, I0, I1),
eq(Exp, TY, Dic1, Dic, I1, I).
- eq((X ==> Y), (-TX + TY), Dic0, Dic, I0, I) :- !,
- eq( X, TX, Dic0, Dic1, I0, I1),
- eq( Y, TY, Dic1, Dic, I1, I).
+eq((X ==> Y), (-TX + TY), Dic0, Dic, I0, I) :- !,
+ eq( X, TX, Dic0, Dic1, I0, I1),
+ eq( Y, TY, Dic1, Dic, I1, I).
- eq((X :- Y), (TX + -TY), Dic0, Dic, I0, I) :- !,
- eq( X, TX, Dic0, Dic1, I0, I1),
- eq( Y, TY, Dic1, Dic, I1, I).
+eq((X :- Y), (TX + -TY), Dic0, Dic, I0, I) :- !,
+eq( X, TX, Dic0, Dic1, I0, I1),
+eq( Y, TY, Dic1, Dic, I1, I).
eq((X + Y), (TX + TY), Dic0, Dic, I0, I) :- !,
eq( X, TX, Dic0, Dic1, I0, I1),
@@ -483,7 +497,29 @@ eq(one_of(D), Ds, Dic0, Dic, I0, I) :-
t_domain0( D, Ds, Dic0, Dic, I0, I).
eq(G, NG, Dic0, Dic, I0, I) :-
- add( G, NG, Dic0, Dic, I0, I).
+ add( G, NG, Dic0, Dic, I0, I).
+
+add_xors(L, V, I0, I) :-
+ foldl(add_xor(V), L, I0, I).
+
+add_xor(V, V0, I, I) :- V == V0, !.
+add_xor(V, V0, I, [(V-V0)|I]).
+
+xor( VX, DV0s, DV , Disj0, Disj0+Conj) :- !,
+ foldl( add_all2(VX, DV), DV0s, 1,Conj).
+
+add_all2(VX, G, GD, C, C*(VX=G)
+ ) :- G == GD, ! .
+add_all2(VX, _, G, C, C*(-(VX=G))).
+
+list2prod(X, P, X *P).
+list2sum(X, P, X +P).
+
+t_domain0( [D], DX, Dic0, Dic, I0, I) :- !,
+ eq(D , DX , Dic0, Dic, I0, I).
+t_domain0( [D1|D2s], (DX1+ (-DX1*D2Xs)), Dic0, Dic, I0, I) :-
+ eq(D1, DX1, Dic0, Dic1, I0, I1),
+ t_domain0(D2s, D2Xs, Dic1, Dic, I1, I).
t_domain( [D], X, _VX, VDX, Dic0, Dic, I0, I) :- !,
add( X=D, VDX, Dic0, Dic, I0, I).
@@ -507,6 +543,7 @@ add( AG, V, Dic0, Dic, I0, IF) :-
add( AG, V, Dic0, Dic, I, I) :-
rb_insert( Dic0, AG, V, Dic).
+simp_key(G , G) :- var(G), !.
simp_key(_^_:error(_^G) , G) :- !.
simp_key(_^_:G , G) :- !.
simp_key('$VAR'(S):A, SAG) :-
diff --git a/os/pl-write.c b/os/pl-write.c
index eec18e0c5..f979d9efd 100644
--- a/os/pl-write.c
+++ b/os/pl-write.c
@@ -262,8 +262,20 @@ writeTopTerm(term_t t, int prec, write_options *options)
if (flags & PL_WRT_BLOB_PORTRAY)
yap_flag |= Blob_Portray_f;
old_module = CurrentModule;
+ char * buf[1024];
+ size_t length;
+ int encode; Term tn;
+
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "Yap_REGS=%p\n", Yap_REGS);
CurrentModule = Yap_GetModuleFromEntry(options->module);
- Yap_plwrite(Yap_GetFromSlot(t PASS_REGS), options->out, options->max_depth, yap_flag, prec);
+
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d\n", t) ;
+
+__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "LOCAl_SlotBase[t]=%ld\n", LOCAL_SlotBase[t]);
+ __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "LOCAl_SlotBase=%ld\n", Deref(LOCAL_SlotBase[t]));
+
+
+Yap_plwrite(Yap_GetFromSlot(t PASS_REGS), options->out, options->max_depth, yap_flag, prec);
CurrentModule = old_module;
return TRUE;
}
@@ -554,7 +566,7 @@ pl_write_term(term_t term, term_t options)
/** @pred write_term(+ _T_, + _Opts_) is iso
-Displays term _T_ on the current output stream, according to the
+ Displays term _T_ on the current output stream, according to the
following options:
+ quoted(+ _Bool_) is iso
@@ -609,7 +621,6 @@ PL_write_term(IOSTREAM *s, term_t term, int precedence, int flags)
options.flags = flags;
options.out = s;
options.module = MODULE_user;
-
PutOpenToken(EOF, s); /* reset this */
return writeTopTerm(term, precedence, &options);
}
diff --git a/packages/bdd/bdd.yap b/packages/bdd/bdd.yap
index 56d5abe77..faaed0f85 100644
--- a/packages/bdd/bdd.yap
+++ b/packages/bdd/bdd.yap
@@ -31,8 +31,9 @@ The following predicates construct a BDD:
bdd_print/2,
bdd_print/3,
bdd_to_probability_sum_product/2,
- bdd_to_probability_sum_product/3,
- bdd_close/1,
+ bdd_to_probability_sum_product/3,
+ bdd_reorder/2,
+ bdd_close/1,
mtbdd_close/1]).
:- use_module(library(lists)).
@@ -338,6 +339,14 @@ bdd_close(cudd(M,_,_Vars, _)) :-
bdd_close(add(M,_,_Vars, _)) :-
cudd_die(M).
+/** @pred bdd_close( _BDDHandle_)
+
+ close the BDD and release any resources it holds.
+
+*/
+bdd_reorder(cudd(M,Top,_Vars, _), How) :-
+ cudd_reorder(M, Top,How).
+
/** @pred bdd_size(+ _BDDHandle_, - _Size_)
Unify _Size_ with the number of nodes in _BDDHandle_.
@@ -356,19 +365,23 @@ Output bdd _BDDHandle_ as a dot file to _File_.
*/
bdd_print(cudd(M,Top,_Vars, _), File) :-
- cudd_print(M, Top, File).
+ absolute_file_name(File, AFile, []),
+ cudd_print(M, Top, AFile).
bdd_print(add(M,Top,_Vars, _), File) :-
- cudd_print(M, Top, File).
+ absolute_file_name(File, AFile, []),
+ cudd_print(M, Top, AFile).
bdd_print(cudd(M,Top, Vars, _), File, Names) :-
Vars =.. [_|LVars],
%trace,
maplist( fetch_name(Names), LVars, Ss),
- cudd_print(M, Top, File, Ss).
+ absolute_file_name(File, AFile, []),
+ cudd_print(M, Top, AFile, Ss).
bdd_print(add(M,Top, Vars, _), File, Names) :-
Vars =.. [_|LVars],
maplist( fetch_name(Names), LVars, Ss),
- cudd_print(M, Top, File, Ss).
+ absolute_file_name(File, AFile, []),
+ cudd_print(M, Top, AFile, Ss).
fetch_name([S=V1|_], V2, SN) :- V1 == V2, !,
( atom(S) -> SN = S ; format(atom(SN), '~w', [S]) ).
diff --git a/packages/bdd/cudd.c b/packages/bdd/cudd.c
index 96f701a2e..531c130af 100644
--- a/packages/bdd/cudd.c
+++ b/packages/bdd/cudd.c
@@ -633,6 +633,13 @@ get_vars(YAP_Term t3)
}
static YAP_Bool
+p_cudd_reorder(void)
+{
+ DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
+ return Cudd_ReduceHeap( manager, CUDD_REORDER_EXACT, 1);
+}
+
+ static YAP_Bool
p_cudd_to_term(void)
{
DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
@@ -870,10 +877,12 @@ p_cudd_print_with_names(void)
DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
DdNode *n0 = (DdNode *)YAP_IntOfTerm(YAP_ARG2);
const char *s = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3));
- const char **namesp;
+ char **namesp;
YAP_Term names = YAP_ARG4;
FILE *f;
YAP_Int len;
+ YAP_Int i = 0;
+
if (!strcmp(s, "user_output")) f = stdout;
else if (!strcmp(s, "user_error")) f = stderr;
else if (!strcmp(s, "user")) f = stdout;
@@ -883,18 +892,34 @@ p_cudd_print_with_names(void)
if ((namesp = malloc(sizeof(const char *)*len)) == NULL)
return FALSE;
while (YAP_IsPairTerm(names)) {
- YAP_Int i = 0;
YAP_Term hd = YAP_HeadOfTerm( names);
- char * s = YAP_AtomName(YAP_AtomOfTerm(hd));
- const char *ns = malloc(strlen(s)+1);
- strncpy(ns, s, strlen(s)+1);
- namesp[i++] = ns;
+ const char *f;
+
+ if (YAP_IsAtomTerm(hd)) {
+ const char * s = YAP_AtomName(YAP_AtomOfTerm(hd));
+ char *ns = malloc(strlen(s)+1);
+ strncpy(ns, s, strlen(s)+1);
+ f = ns;
+ } else {
+ size_t sz =256;
+ char *s = malloc(sz+256);
+ while( !YAP_WriteBuffer(hd, s, sz-1, 0) ) {
+ sz+=1024;
+ s = realloc(s, sz);
+ }
+ f = s;
+ }
names = YAP_TailOfTerm( names);
+ namesp[i++] = f;
}
- Cudd_DumpDot(manager, 1, &n0, (char **)namesp, NULL, f);
- free( namesp );
+ Cudd_DumpDot(manager, 1, &n0, namesp, NULL, f);
if (f != stdout && f != stderr)
fclose(f);
+ while (i > 0) {
+ i--;
+ free(namesp[i]);
+ }
+ free( namesp );
return TRUE;
}
@@ -942,7 +967,8 @@ init_cudd(void)
FunctorOutAdd = YAP_MkFunctor(YAP_LookupAtom("add"), 4);
FunctorCudd = YAP_MkFunctor(YAP_LookupAtom("cudd"), 1);
TermMinusOne = YAP_MkIntTerm(-1);
- TermPlusOne = YAP_MkIntTerm(+1);
+ TermPlusOne = YAP_MkIntTerm(+1);
+ TermZero = YAP_MkIntTerm(0);
TermFalse = YAP_MkAtomTerm(YAP_LookupAtom("false"));
TermTrue = YAP_MkAtomTerm(YAP_LookupAtom("true"));
YAP_UserCPredicate("term_to_cudd", p_term_to_cudd, 3);
@@ -953,7 +979,8 @@ init_cudd(void)
YAP_UserCPredicate("add_to_term", p_add_to_term, 4);
YAP_UserCPredicate("cudd_to_probability_sum_product", p_cudd_to_p, 4);
YAP_UserCPredicate("cudd_size", p_cudd_size, 3);
- YAP_UserCPredicate("cudd_die", p_cudd_die, 1);
+ YAP_UserCPredicate("cudd_die", p_cudd_die, 1);
+ YAP_UserCPredicate("cudd_reorder", p_cudd_reorder, 2);
YAP_UserCPredicate("cudd_release_node", p_cudd_release_node, 2);
YAP_UserCPredicate("cudd_print", p_cudd_print, 3);
YAP_UserCPredicate("cudd_print", p_cudd_print_with_names, 4);
diff --git a/packages/myddas/Makefile.in b/packages/myddas/Makefile.in
index 88756b6d5..ca4d602d1 100644
--- a/packages/myddas/Makefile.in
+++ b/packages/myddas/Makefile.in
@@ -57,31 +57,36 @@ MYDDAS_SOURCES= \
myddas_wkb2prolog.c
MYDDAS_PROLOG= \
- $(srcdir)/pl/myddas.ypp \
- $(srcdir)/pl/myddas_assert_predicates.ypp \
- $(srcdir)/pl/myddas_mysql.ypp \
- $(srcdir)/pl/myddas_sqlite3.ypp \
- $(srcdir)/pl/myddas_top_level.ypp \
- $(srcdir)/pl/myddas_errors.ypp \
- $(srcdir)/pl/myddas_postgres.ypp \
- $(srcdir)/pl/myddas_prolog2sql.ypp \
- $(srcdir)/pl/myddas_util_predicates.ypp \
- $(srcdir)/pl/myddas_prolog2sql_optimizer.ypp
+ myddas.ypp \
+ myddas_assert_predicates.ypp \
+ myddas_mysql.ypp \
+ myddas_sqlite3.ypp \
+ myddas_top_level.ypp \
+ myddas_errors.ypp \
+ myddas_postgres.ypp \
+ myddas_prolog2sql.ypp \
+ myddas_util_predicates.ypp \
+ myddas_prolog2sql_optimizer.ypp
+
OBJS= $(MYDDAS_SOURCES:.c=.o)
+MYDDAS_YAP= $(MYDDAS_PROLOG:.ypp=.yap)
SOBJS= myddas.@SO@
#in some systems we just create a single object, in others we need to
# create a libray
-all: $(SOBJS)
+all: $(SOBJS) $(MYDDAS_YAP)
-.PRECIOUS: %.o
+.PRECIOUS: %.o %.yap
%.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) $< -o $@
+%.yap: $(srcdir)/pl/%.ypp
+ cpp $(YAP_EXTRAS) -P -E -w $< -o $@
+
@DO_SECOND_LD@%.@SO@: $(OBJS)
@DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o $@ $(OBJS) @EXTRA_LIBS_FOR_DLLS@ @MYDDAS_LIBS@
@@ -97,7 +102,7 @@ install_myddas:
mkdir -p $(DESTDIR)$(SHAREDIR); \
for p in $(MYDDAS_PROLOG); \
do name=`basename $$p .ypp`; echo $$name;\
- cpp $(YAP_EXTRAS) -P -E -w $$p > $(DESTDIR)$(SHAREDIR)/$$name.yap; \
+ $(INSTALL_DATA) $$name.yap $(DESTDIR)$(SHAREDIR); \
done; \
fi
diff --git a/packages/myddas/pl/myddas.ypp b/packages/myddas/pl/myddas.ypp
index 3327db4f1..917c4d65d 100644
--- a/packages/myddas/pl/myddas.ypp
+++ b/packages/myddas/pl/myddas.ypp
@@ -1,21 +1,21 @@
- /*************************************************************************
-* *
-* 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.yap *
-* Last rev: *
-* mods: *
-* comments: Global predicates for the MyDDAS Interface *
-* *
-*************************************************************************/
+/*************************************************************************
+ * *
+ * 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.yap *
+ * Last rev: *
+ * mods: *
+ * comments: Global predicates for the MyDDAS Interface *
+ * *
+ *************************************************************************/
-#if USE_MYDDAS
+#if 1 //USE_MYDDAS
:- load_foreign_files([myddas], [], init_myddas).
@@ -27,181 +27,181 @@
#endif
:- module(myddas,[
- db_open/5,
- db_open/4,
- db_close/1,
- db_close/0,
+ db_open/5,
+ db_open/4,
+ db_close/1,
+ db_close/0,
- db_verbose/1,
- db_module/1,
- db_is_database_predicate/3,
-#ifdef MYDDAS_STATS
- db_stats/1,
- db_stats/2,
- db_stats_time/2,
-#endif
- db_sql/2,
- db_sql/3,
- db_sql_select/3,
- db_prolog_select/2,
- db_prolog_select/3,
- db_prolog_select_multi/3,
- db_command/2,
- db_assert/2,
- db_assert/1,
- db_create_table/3,
- db_export_view/4,
- db_update/2,
+ db_verbose/1,
+ db_module/1,
+ db_is_database_predicate/3,
+ #ifdef MYDDAS_STATS
+ db_stats/1,
+ db_stats/2,
+ db_stats_time/2,
+ #endif
+ db_sql/2,
+ db_sql/3,
+ db_sql_select/3,
+ db_prolog_select/2,
+ db_prolog_select/3,
+ db_prolog_select_multi/3,
+ db_command/2,
+ db_assert/2,
+ db_assert/1,
+ db_create_table/3,
+ db_export_view/4,
+ db_update/2,
- db_get_attributes_types/2,
- db_get_attributes_types/3,
- db_number_of_fields/2,
- db_number_of_fields/3,
+ db_get_attributes_types/2,
+ db_get_attributes_types/3,
+ db_number_of_fields/2,
+ db_number_of_fields/3,
- db_multi_queries_number/2,
+ db_multi_queries_number/2,
- % myddas_top_level.ypp
-#ifdef MYDDAS_TOP_LEVEL
- db_top_level/4,
- db_top_level/5,
- db_datalog_select/3,
-#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
-#ifdef MYDDAS_MYSQL
- % myddas_mysql.ypp
- ,
- db_my_result_set/1,
- db_datalog_describe/1,
- db_datalog_describe/2,
- db_describe/3,
- db_describe/2,
- db_datalog_show_tables/1,
- db_datalog_show_tables/0,
- db_show_tables/2,
- db_show_tables/1,
- db_show_database/2,
- db_show_databases/2,
- db_show_databases/1,
- db_change_database/2,
- db_call_procedure/4,
- db_call_procedure/3,
- db_my_sql_mode/1,
- db_my_sql_mode/2,
- db_sql_mode/1,
- db_sql_mode/2
-#endif
- ]).
+ % myddas_top_level.ypp
+ #ifdef MYDDAS_TOP_LEVEL
+ db_top_level/4,
+ db_top_level/5,
+ db_datalog_select/3,
+ #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
+ #ifdef MYDDAS_MYSQL
+ % myddas_mysql.ypp
+ ,
+ db_my_result_set/1,
+ db_datalog_describe/1,
+ db_datalog_describe/2,
+ db_describe/3,
+ db_describe/2,
+ db_datalog_show_tables/1,
+ db_datalog_show_tables/0,
+ db_show_tables/2,
+ db_show_tables/1,
+ db_show_database/2,
+ db_show_databases/2,
+ db_show_databases/1,
+ db_change_database/2,
+ db_call_procedure/4,
+ db_call_procedure/3,
+ db_my_sql_mode/1,
+ db_my_sql_mode/2,
+ db_sql_mode/1,
+ db_sql_mode/2
+ #endif
+ ]).
/**
-@defgroup MYDDAS The MYDDAS Data-base interface.
-@ingroup YAPPackages
-@{
+ @defgroup MYDDAS The MYDDAS Data-base interface.
+ @ingroup YAPPackages
+ @{
-The MYDDAS database project was developed within a FCT project aiming at
-the development of a highly efficient deductive database system, based
-on the coupling of the MySQL relational database system with the YAP
-Prolog system. MYDDAS was later expanded to support the ODBC interface.
+ The MYDDAS database project was developed within a FCT project aiming at
+ the development of a highly efficient deductive database system, based
+ on the coupling of the MySQL relational database system with the YAP
+ Prolog system. MYDDAS was later expanded to support the ODBC interface.
*/
/** @defgroup Requirements_and_Installation_Guide Requirements and Installation Guide
-ee
-Next, we describe how to usen of the YAP with the MYDDAS System. The
-use of this system is entirely depend of the MySQL development libraries
-or the ODBC development libraries. At least one of the this development
-libraries must be installed on the computer system, otherwise MYDDAS
-will not compile. The MySQL development libraries from MySQL 3.23 an
-above are know to work. We recommend the usage of MySQL versus ODBC,
-but it is possible to have both options installed
+ ee
+ Next, we describe how to usen of the YAP with the MYDDAS System. The
+ use of this system is entirely depend of the MySQL development libraries
+ or the ODBC development libraries. At least one of the this development
+ libraries must be installed on the computer system, otherwise MYDDAS
+ will not compile. The MySQL development libraries from MySQL 3.23 an
+ above are know to work. We recommend the usage of MySQL versus ODBC,
+ but it is possible to have both options installed
-At the same time, without any problem. The MYDDAS system automatically
-controls the two options. Currently, MYDDAS is know to compile without
-problems in Linux. The usage of this system on Windows has not been
-tested yet. MYDDAS must be enabled at configure time. This can be done
-with the following options:
+ At the same time, without any problem. The MYDDAS system automatically
+ controls the two options. Currently, MYDDAS is know to compile without
+ problems in Linux. The usage of this system on Windows has not been
+ tested yet. MYDDAS must be enabled at configure time. This can be done
+ with the following options:
-+ --enable-myddas
+ + --enable-myddas
-This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects;
+ This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects;
-+ --enable-myddas-stats
+ + --enable-myddas-stats
-This option is only available in MySQL. It includes code to get
-statistics from the MYDDAS system;
+ This option is only available in MySQL. It includes code to get
+ statistics from the MYDDAS system;
-+ --enable-top-level
+ + --enable-top-level
-This option is only available in MySQL. It enables the option to interact with the MySQL server in
-two different ways. As if we were on the MySQL Client Shell, and as if
-we were using Datalog.
+ This option is only available in MySQL. It enables the option to interact with the MySQL server in
+ two different ways. As if we were on the MySQL Client Shell, and as if
+ we were using Datalog.
*/
%% @}
/** @defgroup MYDDAS_Architecture MYDDAS Architecture
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
-The system includes four main blocks that are put together through the
-MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an
-ODBC layer and a Prolog to SQL compiler. Current effort is put on the
-MySQL interface rather than on the ODBC interface. If you want to use
-the full power of the MYDDAS interface we recommend you to use a MySQL
-database. Other databases, such as Oracle, PostGres or Microsoft SQL
-Server, can be interfaced through the ODBC layer, but with limited
-performance and features support.
+ The system includes four main blocks that are put together through the
+ MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an
+ ODBC level and a Prolog to SQL compiler. Current effort is put on the
+ MySQL interface rather than on the ODBC interface. If you want to use
+ the full power of the MYDDAS interface we recommend you to use a MySQL
+ database. Other databases, such as Oracle, PostGres or Microsoft SQL
+ Server, can be interfaced through the ODBC layer, but with limited
+ performance and features support.
-The main structure of the MYDDAS interface is simple. Prolog queries
-involving database goals are translated to SQL using the Prolog to SQL
-compiler; then the SQL expression is sent to the database system, which
-returns the set of tuples satisfying the query; and finally those tuples
-are made available to the Prolog engine as terms. For recursive queries
-involving database goals, the YapTab tabling engine provides the
-necessary support for an efficient evaluation of such queries.
+ The main structure of the MYDDAS interface is simple. Prolog queries
+ involving database goals are translated to SQL using the Prolog to SQL
+ compiler; then the SQL expression is sent to the database system, which
+ returns the set of tuples satisfying the query; and finally those tuples
+ are made available to the Prolog engine as terms. For recursive queries
+ involving database goals, the YapTab tabling engine provides the
+ necessary support for an efficient evaluation of such queries.
-An important aspect of the MYDDAS interface is that for the programmer
-the use of predicates which are defined in database relations is
-completely transparent. An example of this transparent support is the
-Prolog cut operator, which has exactly the same behaviour from
-predicates defined in the Prolog program source code, or from predicates
-defined in database as relations.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ An important aspect of the MYDDAS interface is that for the programmer
+ the use of predicates which are defined in database relations is
+ completely transparent. An example of this transparent support is the
+ Prolog cut operator, which has exactly the same behaviour from
+ predicates defined in the Prolog program source code, or from predicates
+ defined in database as relations.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Name = 'John Doe',
-Number = 123456789 ?
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Backtracking can then be used to retrieve the next row
-of the relation phonebook. Records with particular field values may be
-selected in the same way as in Prolog. (In particular, no mode
-specification for database predicates is required). For instance:
+ Name = 'John Doe',
+ Number = 123456789 ?
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ Backtracking can then be used to retrieve the next row
+ of the relation phonebook. Records with particular field values may be
+ selected in the same way as in Prolog. (In particular, no mode
+ specification for database predicates is required). For instance:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- phonebook(Letter,'John Doe',Letter).
-Letter = 'D',
-Number = 123456789 ?
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-generates the query
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- phonebook(Letter,'John Doe',Letter).
+ Letter = 'D',
+ Number = 123456789 ?
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generates the query
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-SELECT A.Letter , 'John Doe' , A.Number
-FROM 'phonebook' A
-WHERE A.Name = 'John Doe';
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ SELECT A.Letter , 'John Doe' , A.Number
+ FROM 'phonebook' A
+ WHERE A.Name = 'John Doe';
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
@@ -209,110 +209,110 @@ WHERE A.Name = 'John Doe';
/** @defgroup View_Level_Interface View Level Interface
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/**
-@pred db view(+,+,+).
+ @pred db view(+,+,+).
-@pred db view(+,+).
+ @pred db view(+,+).
-If we import a database relation, such as an edge relation representing the edges of a directed graph, through
+ If we import a database relation, such as an edge relation representing the edges of a directed graph, through
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_import('Edge',edge).
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-sqliand we then write a query to retrieve all the direct cycles in the
-graph, such as
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_import('Edge',edge).
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ sqliand we then write a query to retrieve all the direct cycles in the
+ graph, such as
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- edge(A,B), edge(B,A).
-A = 10,
-B = 20 ?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-this is clearly inefficient [3], because of relation-level
-access. Relation-level access means that a separate SQL query will be
-generated for every goal in the body of the clause. For the second
-`edge/2` goal, a SQL query is generated using the variable bindings that
-result from the first `edge/2` goal execution. If the second
-`edge/2` goal
-fails, or if alternative solutions are demanded, backtracking access the
-next tuple for the first `edge/2` goal and another SQL query will be
-generated for the second `edge/2` goal. The generation of this large
-number of queries and the communication overhead with the database
-system for each of them, makes the relation-level approach inefficient.
-To solve this problem the view level interface can be used for the
-definition of rules whose bodies includes only imported database
-predicates. One can use the view level interface through the predicates
-db_view/3 and `db_view/2`:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- edge(A,B), edge(B,A).
+ A = 10,
+ B = 20 ?
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ this is clearly inefficient [3], because of relation-level
+ access. Relation-level access means that a separate SQL query will be
+ generated for every goal in the body of the clause. For the second
+ `edge/2` goal, a SQL query is generated using the variable bindings that
+ result from the first `edge/2` goal execution. If the second
+ `edge/2` goal
+ fails, or if alternative solutions are demanded, backtracking access the
+ next tuple for the first `edge/2` goal and another SQL query will be
+ generated for the second `edge/2` goal. The generation of this large
+ number of queries and the communication overhead with the database
+ system for each of them, makes the relation-level approach inefficient.
+ To solve this problem the view level interface can be used for the
+ definition of rules whose bodies includes only imported database
+ predicates. One can use the view level interface through the predicates
+ db_view/3 and `db_view/2`:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_view(Conn,PredName(Arg_1,...,Arg_n),DbGoal).
-?- db_view(PredName(Arg_1,...,Arg_n),DbGoal).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-All arguments are standard Prolog terms. _Arg1_ through _Argn_
-define the attributes to be retrieved from the database, while
-_DbGoal_ defines the selection restrictions and join
-conditions. _Conn_ is the connection identifier, which again can be
-dropped. Calling predicate `PredName/n` will retrieve database
-tuples using a single SQL query generated for the _DbGoal_. We next show
-an example of a view definition for the direct cycles discussed
-above. Assuming the declaration:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_view(Conn,PredName(Arg_1,...,Arg_n),DbGoal).
+ ?- db_view(PredName(Arg_1,...,Arg_n),DbGoal).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ All arguments are standard Prolog terms. _Arg1_ through _Argn_
+ define the attributes to be retrieved from the database, while
+ _DbGoal_ defines the selection restrictions and join
+ conditions. _Conn_ is the connection identifier, which again can be
+ dropped. Calling predicate `PredName/n` will retrieve database
+ tuples using a single SQL query generated for the _DbGoal_. We next show
+ an example of a view definition for the direct cycles discussed
+ above. Assuming the declaration:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_import('Edge',edge).
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-we
-write:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_import('Edge',edge).
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ we
+ write:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_view(direct_cycle(A,B),(edge(A,B), edge(B,A))).
-yes
-?- direct_cycle(A,B)).
-A = 10,
-B = 20 ?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-This call generates the SQL
-statement:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_view(direct_cycle(A,B),(edge(A,B), edge(B,A))).
+ yes
+ ?- direct_cycle(A,B)).
+ A = 10,
+ B = 20 ?
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ This call generates the SQL
+ statement:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-SELECT A.attr1 , A.attr2
-FROM Edge A , Edge B
-WHERE B.attr1 = A.attr2 AND B.attr2 = A.attr1;
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ SELECT A.attr1 , A.attr2
+ FROM Edge A , Edge B
+ WHERE B.attr1 = A.attr2 AND B.attr2 = A.attr1;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Backtracking, as in relational level interface, can be used to retrieve the next row of the view.
-The view interface also supports aggregate function predicates such as
-`sum`, `avg`, `count`, `min` and `max`. For
-instance:
+ Backtracking, as in relational level interface, can be used to retrieve the next row of the view.
+ The view interface also supports aggregate function predicates such as
+ `sum`, `avg`, `count`, `min` and `max`. For
+ instance:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_view(count(X),(X is count(B, B^edge(10,B)))).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-generates the query :
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_view(count(X),(X is count(B, B^edge(10,B)))).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ generates the query :
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-SELECT COUNT(A.attr2)
-FROM Edge A WHERE A.attr1 = 10;
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ SELECT COUNT(A.attr2)
+ FROM Edge A WHERE A.attr1 = 10;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-To know how to use db `view/3`, please refer to Draxler's Prolog to
-SQL Compiler Manual.
+ To know how to use db `view/3`, please refer to Draxler's Prolog to
+ SQL Compiler Manual.
*/
%% @}
/** @defgroup Accessing_Tables_in_Data_Sources_Using_SQL Accessing Tables in Data Sources Using SQL
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
@@ -320,114 +320,114 @@ SQL Compiler Manual.
-@pred db_sql(+,?).
+ @pred db_sql(+,?).
-It is also possible to explicitly send a SQL query to the database server using
+ It is also possible to explicitly send a SQL query to the database server using
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_sql(Conn,SQL,List).
-?- db_sql(SQL,List).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-where _SQL_ is an arbitrary SQL expression, and _List_ is a list
-holding the first tuple of result set returned by the server. The result
-set can also be navigated through backtracking.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_sql(Conn,SQL,List).
+ ?- db_sql(SQL,List).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ where _SQL_ is an arbitrary SQL expression, and _List_ is a list
+ holding the first tuple of result set returned by the server. The result
+ set can also be navigated through backtracking.
-Example:
+ Example:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_sql('SELECT * FROM phonebook',LA).
-LA = ['D','John Doe',123456789] ?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_sql('SELECT * FROM phonebook',LA).
+ LA = ['D','John Doe',123456789] ?
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
%% @}
/** @defgroup Insertion_of_Rows Insertion of Rows
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/** @pred db_assert(+,+).
-@pred db_assert(+).
+ @pred db_assert(+).
-Assuming you have imported the related base table using
-`db_import/2` or db_import/3, you can insert to that table
-by using db_assert/2 predicate any given fact.
+ Assuming you have imported the related base table using
+ `db_import/2` or db_import/3, you can insert to that table
+ by using db_assert/2 predicate any given fact.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_assert(Conn,Fact).
-?- db_assert(Fact).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The second argument must be declared with all of its arguments bound to
-constants. For example assuming `helloWorld` is imported through
-`db_import/2`:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_assert(Conn,Fact).
+ ?- db_assert(Fact).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ The second argument must be declared with all of its arguments bound to
+ constants. For example assuming `helloWorld` is imported through
+ `db_import/2`:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_import('Hello World',helloWorld).
-yes
-?- db_assert(helloWorld('A' ,'Ana',31)).
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-This, would generate the following query
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_import('Hello World',helloWorld).
+ yes
+ ?- db_assert(helloWorld('A' ,'Ana',31)).
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ This, would generate the following query
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-INSERT INTO helloWorld
-VALUES ('A','Ana',3)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-which would insert into the helloWorld, the following row:
-`A,Ana,31`. If we want to insert `NULL` values into the
-relation, we call db_assert/2 with a uninstantiated variable in
-the data base imported predicate. For example, the following query on
-the YAP-prolog system:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ INSERT INTO helloWorld
+ VALUES ('A','Ana',3)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ which would insert into the helloWorld, the following row:
+ `A,Ana,31`. If we want to insert `NULL` values into the
+ relation, we call db_assert/2 with a uninstantiated variable in
+ the data base imported predicate. For example, the following query on
+ the YAP-prolog system:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_assert(helloWorld('A',NULL,31)).
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_assert(helloWorld('A',NULL,31)).
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Would insert the row: `A,null value,31` into the relation
-`Hello World`, assuming that the second row allows null values.
+ Would insert the row: `A,null value,31` into the relation
+ `Hello World`, assuming that the second row allows null values.
*/
/** @pred db insert(+,+,+).
-@pred db insert(+,+).
+ @pred db insert(+,+).
-This predicate would create a new database predicate, which will insert
-any given tuple into the database.
+ This predicate would create a new database predicate, which will insert
+ any given tuple into the database.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_insert(Conn,RelationName,PredName).
-?- db_insert(RelationName,PredName).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-This would create a new predicate with name _PredName_, that will
-insert tuples into the relation _RelationName_. is the connection
-identifier. For example, if we wanted to insert the new tuple
-`('A',null,31)` into the relation `Hello World`, we do:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_insert(Conn,RelationName,PredName).
+ ?- db_insert(RelationName,PredName).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ This would create a new predicate with name _PredName_, that will
+ insert tuples into the relation _RelationName_. is the connection
+ identifier. For example, if we wanted to insert the new tuple
+ `('A',null,31)` into the relation `Hello World`, we do:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_insert('Hello World',helloWorldInsert).
-yes
-?- helloWorldInsert('A',NULL,31).
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_insert('Hello World',helloWorldInsert).
+ yes
+ ?- helloWorldInsert('A',NULL,31).
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
%% @}
/** @defgroup Types_of_Attributes Types of AttributesL
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
@@ -435,64 +435,64 @@ yes
-@pred db_get_attributes_types(+,?).
+ @pred db_get_attributes_types(+,?).
-The prototype for this predicate is the following:
+ The prototype for this predicate is the following:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_get_attributes_types(Conn,RelationName,ListOfFields).
-?- db_get_attributes_types(RelationName,ListOfFields).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_get_attributes_types(Conn,RelationName,ListOfFields).
+ ?- db_get_attributes_types(RelationName,ListOfFields).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-You can use the
-predicate `db_get_attributes types/2` or db_get_attributes_types/3, to
-know what are the names and attributes types of the fields of a given
-relation. For example:
+ You can use the
+ predicate `db_get_attributes types/2` or db_get_attributes_types/3, to
+ know what are the names and attributes types of the fields of a given
+ relation. For example:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_get_attributes_types(myddas,'Hello World',LA).
-LA = ['Number',integer,'Name',string,'Letter',string] ?
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-where Hello World is the name of the relation and myddas is the
-connection identifier.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_get_attributes_types(myddas,'Hello World',LA).
+ LA = ['Number',integer,'Name',string,'Letter',string] ?
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ where Hello World is the name of the relation and myddas is the
+ connection identifier.
*/
%% @}
/** @defgroup Number_of_Fields Number of Fields
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/** @pred db_number_of_fields(+,?).
-@pred db_number_of_fields(+,+,?).
+ @pred db_number_of_fields(+,+,?).
-The prototype for this
-predicate is the following:
+ The prototype for this
+ predicate is the following:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_number_of_fields(Conn,RelationName,Arity).
-?- db_number_of_fields(RelationName,Arity).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-You can use the predicate db_number_of_fields/2 or
-`db_number_of_fields/3` to know what is the arity of a given
-relation. Example:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_number_of_fields(Conn,RelationName,Arity).
+ ?- db_number_of_fields(RelationName,Arity).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ You can use the predicate db_number_of_fields/2 or
+ `db_number_of_fields/3` to know what is the arity of a given
+ relation. Example:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_number_of_fields(myddas,'Hello World',Arity).
-Arity = 3 ?
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-where `Hello World` is the name of the
-relation and `myddas` is the connection identifier.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_number_of_fields(myddas,'Hello World',Arity).
+ Arity = 3 ?
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ where `Hello World` is the name of the
+ relation and `myddas` is the connection identifier.
*/
@@ -501,31 +501,31 @@ relation and `myddas` is the connection identifier.
/** @defgroup Describing_a_Relation Describing a Relation
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/** @pred db_datalog_describe(+,+).
-@pred db_datalog_describe(+).
+ @pred db_datalog_describe(+).
-The db `datalog_describe/2` predicate does not really returns any
-value. It simply prints to the screen the result of the MySQL describe
-command, the same way as `DESCRIBE` in the MySQL prompt would.
+ The db `datalog_describe/2` predicate does not really returns any
+ value. It simply prints to the screen the result of the MySQL describe
+ command, the same way as `DESCRIBE` in the MySQL prompt would.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_datalog_describe(myddas,'Hello World').
-+----------+----------+------+-----+---------+-------+
-| Field | Type | Null | Key | Default | Extra |
-+----------+----------+------+-----+---------+-------+
-+ Number | int(11) | YES | | NULL | |
-+ Name | char(10) | YES | | NULL | |
-+ Letter | char(1) | YES | | NULL | |
-+----------+----------+------+-----+---------+-------+
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_datalog_describe(myddas,'Hello World').
+ +----------+----------+------+-----+---------+-------+
+ | Field | Type | Null | Key | Default | Extra |
+ +----------+----------+------+-----+---------+-------+
+ + Number | int(11) | YES | | NULL | |
+ + Name | char(10) | YES | | NULL | |
+ + Letter | char(1) | YES | | NULL | |
+ +----------+----------+------+-----+---------+-------+
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
@@ -533,20 +533,20 @@ yes
-@pred db_describe(+)
+ @pred db_describe(+)
-The `db_describe/3` predicate does the same action as
-db_datalog_describe/2 predicate but with one major
-difference. The results are returned by backtracking. For example, the
-last query:
+ The `db_describe/3` predicate does the same action as
+ db_datalog_describe/2 predicate but with one major
+ difference. The results are returned by backtracking. For example, the
+ last query:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_describe(myddas,'Hello World',Term).
-Term = tableInfo('Number',int(11),'YES','',null(0),'') ? ;
-Term = tableInfo('Name',char(10),'YES','',null(1),'' ? ;
-Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ;
-no
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_describe(myddas,'Hello World',Term).
+ Term = tableInfo('Number',int(11),'YES','',null(0),'') ? ;
+ Term = tableInfo('Name',char(10),'YES','',null(1),'' ? ;
+ Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ;
+ no
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
@@ -554,29 +554,29 @@ no
/** @defgroup Enumerating_Relations Enumeration Relations Describing_a_Relation Describing a Relation
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/** @pred db_datalog_show_tables(+).
-@pred db_datalog_show_tables
+ @pred db_datalog_show_tables
-If we need to know what relations exists in a given MySQL Schema, we can use
-the `db_datalog_show_tables/1` predicate. As db_datalog_describe/2,
-it does not returns any value, but instead prints to the screen the result of the
-`SHOW TABLES` command, the same way as it would be in the MySQL prompt.
+ If we need to know what relations exists in a given MySQL Schema, we can use
+ the `db_datalog_show_tables/1` predicate. As db_datalog_describe/2,
+ it does not returns any value, but instead prints to the screen the result of the
+ `SHOW TABLES` command, the same way as it would be in the MySQL prompt.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_datalog_show_tables(myddas).
-+-----------------+
-| Tables_in_guest |
-+-----------------+
-| Hello World |
-+-----------------+
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_datalog_show_tables(myddas).
+ +-----------------+
+ | Tables_in_guest |
+ +-----------------+
+ | Hello World |
+ +-----------------+
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
@@ -584,20 +584,20 @@ yes
-@pred db_show_tables(?)
+ @pred db_show_tables(?)
-The db_show_tables/2 predicate does the same action as
-`db_show_tables/1` predicate but with one major difference. The
-results are returned by backtracking. For example, given the last query:
+ The db_show_tables/2 predicate does the same action as
+ `db_show_tables/1` predicate but with one major difference. The
+ results are returned by backtracking. For example, given the last query:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_show_tables(myddas,Table).
-Table = table('Hello World') ? ;
-no
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_show_tables(myddas,Table).
+ Table = table('Hello World') ? ;
+ no
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
@@ -605,92 +605,92 @@ no
/** @defgroup The_MYDDAS_MySQL_Top_Level The MYDDAS MySQL Top Level
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/**
-@pred db_top_level(+,+,+,+,+).
-@pred db_top_level(+,+,+,+).
+ @pred db_top_level(+,+,+,+,+).
+ @pred db_top_level(+,+,+,+).
-Through MYDDAS is also possible to access the MySQL Database Server, in
-the same wthe mysql client. In this mode, is possible to query the
-SQL server by just using the standard SQL language. This mode is exactly the same as
-different from the standard mysql client. We can use this
-mode, by invoking the db top level/5. as one of the following:
+ Through MYDDAS is also possible to access the MySQL Database Server, in
+ the same wthe mysql client. In this mode, is possible to query the
+ SQL server by just using the standard SQL language. This mode is exactly the same as
+ different from the standard mysql client. We can use this
+ mode, by invoking the db top level/5. as one of the following:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_top_level(mysql,Connection,Host/Database,User,Password).
-?- db_top_level(mysql,Connection,Host/Database/Port,User,Password).
-?- db_top_level(mysql,Connection,Host/Database/UnixSocket,User,Password).
-?- db_top_level(mysql,Connection,Host/Database/Port/UnixSocket,User,Password).
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_top_level(mysql,Connection,Host/Database,User,Password).
+ ?- db_top_level(mysql,Connection,Host/Database/Port,User,Password).
+ ?- db_top_level(mysql,Connection,Host/Database/UnixSocket,User,Password).
+ ?- db_top_level(mysql,Connection,Host/Database/Port/UnixSocket,User,Password).
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Usage is similar as the one described for the db_open/5 predicate
-discussed above. If the login is successful, automatically the prompt of
-the mysql client will be used. For example:
+ Usage is similar as the one described for the db_open/5 predicate
+ discussed above. If the login is successful, automatically the prompt of
+ the mysql client will be used. For example:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-opens a
-connection identified by the `con1` atom, to an instance of a MySQL server
-running on host `localhost`, using database guest `db` and user `guest` with
-empty password. After this is possible to use MYDDAS as the mysql
-client.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ opens a
+ connection identified by the `con1` atom, to an instance of a MySQL server
+ running on host `localhost`, using database guest `db` and user `guest` with
+ empty password. After this is possible to use MYDDAS as the mysql
+ client.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
-Reading table information for completion of table and column names
-You can turn off this feature to get a quicker startup with -A
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
+ Reading table information for completion of table and column names
+ You can turn off this feature to get a quicker startup with -A
-Welcome to the MySQL monitor.
-Commands end with ; or \g.
+ Welcome to the MySQL monitor.
+ Commands end with ; or \g.
-Your MySQL connection id is 4468 to server version: 4.0.20
-Type 'help;' or '\h' for help.
-Type '\c' to clear the buffer.
-mysql> exit
-Bye
-yes
-?-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ Your MySQL connection id is 4468 to server version: 4.0.20
+ Type 'help;' or '\h' for help.
+ Type '\c' to clear the buffer.
+ mysql> exit
+ Bye
+ yes
+ ?-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
%%@}
/** @defgroup Other_MYDDAS_Properties Other MYDDAS Properties
-@ingroup MYDDAS
-@{
+ @ingroup MYDDAS
+ @{
*/
/**
-@pred db_verbose(+).
+ @pred db_verbose(+).
-When we ask a question to YAP, using a predicate asserted by
-db_import/3, or by db_view/3, this will generate a SQL
-`QUERY`. If we want to see that query, we must to this at a given
-point in our session on YAP.
+ When we ask a question to YAP, using a predicate asserted by
+ db_import/3, or by db_view/3, this will generate a SQL
+ `QUERY`. If we want to see that query, we must to this at a given
+ point in our session on YAP.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_verbose(1).
-yes
-?-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-If we want to
-disable this feature, we must call the `db_verbose/1` predicate with the value 0.
-\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_verbose(1).
+ yes
+ ?-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ If we want to
+ disable this feature, we must call the `db_verbose/1` predicate with the value 0.
+ \
*/
/**
-@pred db_top_level(+,+,+,+).
+ @pred db_top_level(+,+,+,+).
*/
@@ -701,62 +701,62 @@ disable this feature, we must call the `db_verbose/1` predicate with the value 0
-When we create a new database predicate, by using db_import/3,
-db_view/3 or db_insert/3, that predicate will be asserted
-by default on the `user` module. If we want to change this value, we can
-use the db_module/1 predicate to do so.
+ When we create a new database predicate, by using db_import/3,
+ db_view/3 or db_insert/3, that predicate will be asserted
+ by default on the `user` module. If we want to change this value, we can
+ use the db_module/1 predicate to do so.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_module(lists).
-yes
-?-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-By executing this predicate, all of the predicates asserted by the
-predicates enumerated earlier will created in the lists module.
-If we want to put back the value on default, we can manually put the
-value user. Example:
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_module(lists).
+ yes
+ ?-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ By executing this predicate, all of the predicates asserted by the
+ predicates enumerated earlier will created in the lists module.
+ If we want to put back the value on default, we can manually put the
+ value user. Example:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_module(user).
-yes
-?-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_module(user).
+ yes
+ ?-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-We can also see in what module the predicates are being asserted by doing:
+ We can also see in what module the predicates are being asserted by doing:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_module(X).
-X=user
-yes
-?-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_module(X).
+ X=user
+ yes
+ ?-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/** @pred db_my_result_set(?).
-The MySQL C API permits two modes for transferring the data generated by
-a query to the client, in our case YAP. The first mode, and the default
-mode used by the MYDDAS-MySQL, is to store the result. This mode copies all the
-information generated to the client side.
+ The MySQL C API permits two modes for transferring the data generated by
+ a query to the client, in our case YAP. The first mode, and the default
+ mode used by the MYDDAS-MySQL, is to store the result. This mode copies all the
+ information generated to the client side.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_my_result_set(X).
-X=store_result
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_my_result_set(X).
+ X=store_result
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The other mode that we can use is use result. This one uses the result
-set created directly from the server. If we want to use this mode, he
-simply do
+ The other mode that we can use is use result. This one uses the result
+ set created directly from the server. If we want to use this mode, he
+ simply do
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?- db_my_result_set(use_result).
-yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-After this command, all
-of the database predicates will use use result by default. We can change
-this by doing again `db_my_result_set(store_result)`.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?- db_my_result_set(use_result).
+ yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ After this command, all
+ of the database predicates will use use result by default. We can change
+ this by doing again `db_my_result_set(store_result)`.
*/
@@ -764,21 +764,21 @@ this by doing again `db_my_result_set(store_result)`.
-@pred db_my_sql_mode(?SQL_Mode).
+ @pred db_my_sql_mode(?SQL_Mode).
-The MySQL server allows the user to change the SQL mode. This can be
-very useful for debugging proposes. For example, if we want MySQL server
-not to ignore the INSERT statement warnings and instead of taking
-action, report an error, we could use the following SQL mode.
+ The MySQL server allows the user to change the SQL mode. This can be
+ very useful for debugging proposes. For example, if we want MySQL server
+ not to ignore the INSERT statement warnings and instead of taking
+ action, report an error, we could use the following SQL mode.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-?-db_my_sql_mode(traditional). yes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-You can see the available SQL Modes at the MySQL homepage at
-.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ?-db_my_sql_mode(traditional). yes
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ You can see the available SQL Modes at the MySQL homepage at
+ .
*/
@@ -786,89 +786,89 @@ You can see the available SQL Modes at the MySQL homepage at
#ifdef MYDDAS_TOP_LEVEL
:- use_module(myddas_top_level,[
- db_top_level/4,
- db_top_level/5,
- db_datalog_select/3
- ]).
+ db_top_level/4,
+ db_top_level/5,
+ db_datalog_select/3
+ ]).
#endif
:- use_module(myddas_assert_predicates,[
- 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
- ]).
+ 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
+ ]).
#ifdef MYDDAS_MYSQL
:- use_module(myddas_mysql,[
- db_my_result_set/1,
- db_datalog_describe/1,
- db_datalog_describe/2,
- db_describe/3,
- db_describe/2,
- db_datalog_show_tables/1,
- db_datalog_show_tables/0,
- db_show_tables/2,
- db_show_tables/1,
- db_show_database/2,
- db_show_databases/2,
- db_show_databases/1,
- db_change_database/2,
- db_call_procedure/4,
- db_call_procedure/3,
- db_my_sql_mode/1,
- db_my_sql_mode/2,
- db_sql_mode/1,
- db_sql_mode/2
- ]).
+ db_my_result_set/1,
+ db_datalog_describe/1,
+ db_datalog_describe/2,
+ db_describe/3,
+ db_describe/2,
+ db_datalog_show_tables/1,
+ db_datalog_show_tables/0,
+ db_show_tables/2,
+ db_show_tables/1,
+ db_show_database/2,
+ db_show_databases/2,
+ db_show_databases/1,
+ db_change_database/2,
+ db_call_procedure/4,
+ db_call_procedure/3,
+ db_my_sql_mode/1,
+ db_my_sql_mode/2,
+ db_sql_mode/1,
+ db_sql_mode/2
+ ]).
#endif /* MYDDAS_MYSQL */
:- use_module(myddas_util_predicates,[
- '$prolog2sql'/3,
- '$create_multi_query'/3,
- '$get_multi_results'/4,
- '$process_sql_goal'/4,
- '$process_fields'/3,
- '$get_values_for_insert'/3,
- '$make_atom'/2,
- '$write_or_not'/1,
- '$abolish_all'/1,
- '$make_a_list'/2,
- '$get_table_name'/2,
- '$get_values_for_update'/4,
- '$extract_args'/4,
-#ifdef MYDDAS_STATS
- '$make_stats_list'/2,
-#endif
- '$lenght'/2
- ]).
+ '$prolog2sql'/3,
+ '$create_multi_query'/3,
+ '$get_multi_results'/4,
+ '$process_sql_goal'/4,
+ '$process_fields'/3,
+ '$get_values_for_insert'/3,
+ '$make_atom'/2,
+ '$write_or_not'/1,
+ '$abolish_all'/1,
+ '$make_a_list'/2,
+ '$get_table_name'/2,
+ '$get_values_for_update'/4,
+ '$extract_args'/4,
+ #ifdef MYDDAS_STATS
+ '$make_stats_list'/2,
+ #endif
+ '$lenght'/2
+ ]).
:- use_module(myddas_errors,[
- '$error_checks'/1
- ]).
+ '$error_checks'/1
+ ]).
:- use_module(myddas_prolog2sql,[
- translate/3,
- queries_atom/2
- ]).
+ translate/3,
+ queries_atom/2
+ ]).
:- use_module(lists,[
- append/3
- ]).
+ append/3
+ ]).
:- use_module(library(parameters)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_open/5
-% db_open/4
- %
+ % db_open/5
+ % db_open/4
+ %
#if 1 // MYDDAS_DECLARATIONS
:- db_open(Protocol) extra_arguments
@@ -958,19 +958,15 @@ i_integer(X) =:= integer(X) \/ i_var(X) \/ err(integer(X)),
list( Protocol ) .
/*
-((Protocol = odbc) :-
-c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) ),
+ c_db_c_db_odbc_connect_connect ==> c_db_odbc_connect,
+ c_db_my_connect ==> c_db_connect,
+ c_c_postgres_connect_connect ==> c_postgres_connect,
+ c_sqlite3_connect ==> sqlite3.
+*/
-((Protocol = mysql) :-
- c^c_db_my_connect(Host,User,Password,Db,Port,Socket,Handle)),
+ %c_db_odbc_connect ==> i_atom( Password ) * i_atom( User ) *
-((Protocol = postgres) :- c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle)),
-((Protocol = sqlite3) :-
- c^c_sqlite3_connect(File,User,Password,Handle),
- t_atom(File), i_atom(User)),
-
- Protocol in [ mysql, postgres, odbc, sqlite3 ],
(- (c^c_sqlite3_connect(File,User,Password,Handle)) :- (c ^fail) ).
@@ -1029,32 +1025,27 @@ c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) +
c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle) +
c^c_sqlite3_connect(File,User,Password,Handle).
*/
-
-
db_open(Protocol) :- true.
#else
-db_close:-
-db_close(myddas).
-db_close(Connection):-
-'$error_checks'(db_close(Connection)),
-get_value(Connection,Con),
- '$abolish_all'(Con).
-db_close(Connection) :-
-'$error_checks'(db_close(Connection)),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-( ConType == mysql ->
- c_db_my_disconnect(Con)
-;ConType == postgres ->
- c_postgres_disconnect(Con)
-;ConType == sqlite3 ->
- c_sqlite3_disconnect(Con)
-;
- c_db_odbc_disconnect(Con)
-),
-set_value(Connection,[]). % "deletes" atom
+db_open:-
+ db_open(myddas).
+
+db_open(Protocol) :-
+ '$error_checks'(db_open(Protocol)),
+ get_value(Protocol,Con),
+ c_db_connection_type(Con,ConType),
+ ( ConType == mysql ->
+ c_db_my_disconnect(Con)
+ ;ConType == postgres ->
+ c_postgres_disconnect(Con)
+ ;ConType == sqlite3 ->
+ c_sqlite3_disconnect(Con)
+ ;
+ c_db_odbc_disconnect(Con)
+ ),
+ set_value(Protocol,[]). % "deletes" atom
#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1062,99 +1053,99 @@ set_value(Connection,[]). % "deletes" atom
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_close/1
-% db_close/0
-%
+ % db_close/1
+ % db_close/0
+ %
db_close:-
-db_close(myddas).
-db_close(Connection):-
-'$error_checks'(db_close(Connection)),
-get_value(Connection,Con),
- '$abolish_all'(Con).
-db_close(Connection) :-
-'$error_checks'(db_close(Connection)),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-( ConType == mysql ->
- c_db_my_disconnect(Con)
-;ConType == postgres ->
- c_postgres_disconnect(Con)
-;ConType == sqlite3 ->
- c_sqlite3_disconnect(Con)
-;
- c_db_odbc_disconnect(Con)
-),
-set_value(Connection,[]). % "deletes" atom
+ db_close(myddas).
+db_close(Protocol):-
+ '$error_checks'(db_close(Protocol)),
+ get_value(Protocol,Con),
+ '$abolish_all'(Con).
+db_close(Protocol) :-
+ '$error_checks'(db_close(Protocol)),
+ get_value(Protocol,Con),
+ c_db_connection_type(Con,ConType),
+ ( ConType == mysql ->
+ c_db_my_disconnect(Con)
+ ;ConType == postgres ->
+ c_postgres_disconnect(Con)
+ ;ConType == sqlite3 ->
+ c_sqlite3_disconnect(Con)
+ ;
+ c_db_odbc_disconnect(Con)
+ ),
+ set_value(Protocol,[]). % "deletes" atom
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_verbose/1
-%
-%
+ % db_verbose/1
+ %
+ %
db_verbose(X):-
-var(X),!,
-get_value(db_verbose,X).
+ var(X),!,
+ get_value(db_verbose,X).
db_verbose(N):-!,
-set_value(db_verbose,N).
-%default value
+ set_value(db_verbose,N).
+ %default value
:- set_value(db_verbose,0).
:- set_value(db_verbose_filename,myddas_queries).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_module/1
-%
-%
+ % db_module/1
+ %
+ %
db_module(X):-
-var(X),!,
-get_value(db_module,X).
+ var(X),!,
+ get_value(db_module,X).
db_module(ModuleName):-
-set_value(db_module,ModuleName).
-% default value
+ set_value(db_module,ModuleName).
+ % default value
:- db_module(user).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_is_database_predicate(+,+,+)
-%
-%
+ % db_is_database_predicate(+,+,+)
+ %
+ %
db_is_database_predicate(Module,PredName,Arity):-
-'$error_checks'(db_is_database_predicate(PredName,Arity,Module)),
-c_db_check_if_exists_pred(PredName,Arity,Module).
+ '$error_checks'(db_is_database_predicate(PredName,Arity,Module)),
+ c_db_check_if_exists_pred(PredName,Arity,Module).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef MYDDAS_STATS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_stats(+,-)
-%
-%
+ % db_stats(+,-)
+ %
+ %
db_stats(List):-
-db_stats(myddas,List).
+ db_stats(myddas,List).
-db_stats(Connection,List):-
-'$error_checks'(db_stats(Connection,List)),
-NumberOfStats = 10,
-'$make_a_list'(NumberOfStats,ListX1),
-( var(Connection) ->
- c_db_stats(0,ListX1)
-;
- get_value(Connection,Conn),
- c_db_stats(Conn,ListX1)
-),
-'$make_stats_list'(ListX1,List).
+db_stats(Protocol,List):-
+ '$error_checks'(db_stats(Protocol,List)),
+ NumberOfStats = 10,
+ '$make_a_list'(NumberOfStats,ListX1),
+ ( var(Protocol) ->
+ c_db_stats(0,ListX1)
+ ;
+ get_value(Protocol,Conn),
+ c_db_stats(Conn,ListX1)
+ ),
+ '$make_stats_list'(ListX1,List).
#ifdef DEBUG
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_stats_time(+,-)
-% Reference is C pointer (memory reference)
-%
+ % db_stats_time(+,-)
+ % Reference is C pointer (memory reference)
+ %
db_stats_time(Reference,Time):-
-'$error_checks'(db_stats_time(Reference,Time)),
-c_db_stats_time(Reference,Time).
+ '$error_checks'(db_stats_time(Reference,Time)),
+ c_db_stats_time(Reference,Time).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#endif /* DEBUG */
@@ -1163,292 +1154,292 @@ c_db_stats_time(Reference,Time).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_sql(+,+,-)
-%
-%
+ % db_sql(+,+,-)
+ %
+ %
-%compatibility
-db_sql_select(Connection,SQL,LA):-
-db_sql(Connection,SQL,LA).
+ %compatibility
+db_sql_select(Protocol,SQL,LA):-
+ db_sql(Protocol,SQL,LA).
db_sql(SQL,LA):-
-db_sql(myddas,SQL,LA).
+ db_sql(myddas,SQL,LA).
db_sql(Connection,SQL,LA):-
-'$error_checks'(db_sql(Connection,SQL,LA)),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-'$write_or_not'(SQL),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(SQL,ResultSet,Con,Mode,Arity)
-;ConType == postgres ->
- postgres_result_set(Mode),
- c_postgres_query(SQL,ResultSet,Con,Mode,Arity)
-;ConType == sqlite3 ->
- sqlite3_result_set(Mode),
- c_sqlite3_query(SQL,ResultSet,Con,Mode,Arity)
-;
- c_db_odbc_number_of_fields_in_query(SQL,Con,Arity)
-),
-'$make_a_list'(Arity,LA),
-( ConType == mysql ->
- !,c_db_my_row(ResultSet,Arity,LA)
-;
- '$make_a_list'(Arity,BindList),
- c_db_odbc_query(SQL,ResultSet,Arity,BindList,Con),!,
- c_db_odbc_row(ResultSet,BindList,LA)
-).
+ '$error_checks'(db_sql(Connection,SQL,LA)),
+ get_value(Connection,Con),
+ c_db_connection_type(Con,ConType),
+ '$write_or_not'(SQL),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(SQL,ResultSet,Con,Mode,Arity)
+ ;ConType == postgres ->
+ postgres_result_set(Mode),
+ c_postgres_query(SQL,ResultSet,Con,Mode,Arity)
+ ;ConType == sqlite3 ->
+ sqlite3_result_set(Mode),
+ c_sqlite3_query(SQL,ResultSet,Con,Mode,Arity)
+ ;
+ c_db_odbc_number_of_fields_in_query(SQL,Con,Arity)
+ ),
+ '$make_a_list'(Arity,LA),
+ ( ConType == mysql ->
+ !,c_db_my_row(ResultSet,Arity,LA)
+ ;
+ '$make_a_list'(Arity,BindList),
+ c_db_odbc_query(SQL,ResultSet,Arity,BindList,Con),!,
+ c_db_odbc_row(ResultSet,BindList,LA)
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_prolog_select(+,+,+)
-%
-%
+ % db_prolog_select(+,+,+)
+ %
+ %
db_prolog_select(LA,DbGoal):-
-db_prolog_select(myddas,LA,DbGoal).
+ db_prolog_select(myddas,LA,DbGoal).
db_prolog_select(Connection,LA,DbGoal):-
-'$lenght'(LA,Arity),
-Name=viewname,
-functor(ViewName,Name,Arity),
-% build arg list for viewname/Arity
-ViewName=..[Name|LA],
+ '$lenght'(LA,Arity),
+ Name=viewname,
+ functor(ViewName,Name,Arity),
+ % build arg list for viewname/Arity
+ ViewName=..[Name|LA],
-'$prolog2sql'(ViewName,DbGoal,SQL),
+ '$prolog2sql'(ViewName,DbGoal,SQL),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-'$write_or_not'(SQL),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(SQL,ResultSet,Con,Mode,_),
- !,c_db_my_row(ResultSet,Arity,LA)
-;
- true
-).
+ get_value(Connection,Con),
+ c_db_connection_type(Con,ConType),
+ '$write_or_not'(SQL),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(SQL,ResultSet,Con,Mode,_),
+ !,c_db_my_row(ResultSet,Arity,LA)
+ ;
+ true
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_prolog_select_multi(+,+,-)
-% db_prolog_select_multi(guest,[(ramos(A,C),A=C),(ramos(D,B),B=10)],[[A],[D,B]]).
-%
+ % db_prolog_select_multi(+,+,-)
+ % db_prolog_select_multi(guest,[(ramos(A,C),A=C),(ramos(D,B),B=10)],[[A],[D,B]]).
+ %
db_prolog_select_multi(Connection,DbGoalsList,ListOfResults) :-
-'$error_checks'(db_prolog_select_multi(Connection,DbGoalsList,ListOfResults)),
-'$create_multi_query'(ListOfResults,DbGoalsList,SQL),
+ '$error_checks'(db_prolog_select_multi(Connection,DbGoalsList,ListOfResults)),
+ '$create_multi_query'(ListOfResults,DbGoalsList,SQL),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-'$write_or_not'(SQL),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(SQL,ResultSet,Con,Mode,_)
-;
- true
-),
-'$get_multi_results'(Con,ConType,ResultSet,ListOfResults).
+ get_value(Connection,Con),
+ c_db_connection_type(Con,ConType),
+ '$write_or_not'(SQL),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(SQL,ResultSet,Con,Mode,_)
+ ;
+ true
+ ),
+ '$get_multi_results'(Con,ConType,ResultSet,ListOfResults).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_command/2
-%
-%
+ % db_command/2
+ %
+ %
db_command(Connection,SQL):-
-'$error_checks'(db_command(Connection,SQL)),
-get_value(Connection,Con),
-'$write_or_not'(SQL),
-c_db_connection_type(Con,ConType),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(SQL,_,Con,Mode,_)
-;
- true
-).
+ '$error_checks'(db_command(Connection,SQL)),
+ get_value(Connection,Con),
+ '$write_or_not'(SQL),
+ c_db_connection_type(Con,ConType),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(SQL,_,Con,Mode,_)
+ ;
+ true
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_assert/2
-% db_assert/1
-%
+ % db_assert/2
+ % db_assert/1
+ %
db_assert(PredName):-
-db_assert(myddas,PredName).
+ db_assert(myddas,PredName).
db_assert(Connection,PredName):-
-translate(PredName,PredName,Code),
-'$error_checks'(db_insert2(Connection,PredName,Code)),
-'$get_values_for_insert'(Code,ValuesList,RelName),
-'$make_atom'(['INSERT INTO `',RelName,'` VALUES '|ValuesList],SQL),
+ translate(PredName,PredName,Code),
+ '$error_checks'(db_insert2(Connection,PredName,Code)),
+ '$get_values_for_insert'(Code,ValuesList,RelName),
+ '$make_atom'(['INSERT INTO `',RelName,'` VALUES '|ValuesList],SQL),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-'$write_or_not'(SQL),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(SQL,_,Con,Mode,_)
-;ConType == postgres ->
- postgres_result_set(Mode),
- c_postgres_query(SQL,_,Con,Mode,_)
-;ConType == sqlite3 ->
- sqlite3_result_set(Mode),
- c_sqlite3_query(SQL,_,Con,Mode,_)
-;
- c_db_odbc_query(SQL,_,_,_,Con)
-).
+ get_value(Connection,Con),
+ c_db_connection_type(Con,ConType),
+ '$write_or_not'(SQL),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(SQL,_,Con,Mode,_)
+ ;ConType == postgres ->
+ postgres_result_set(Mode),
+ c_postgres_query(SQL,_,Con,Mode,_)
+ ;ConType == sqlite3 ->
+ sqlite3_result_set(Mode),
+ c_sqlite3_query(SQL,_,Con,Mode,_)
+ ;
+ c_db_odbc_query(SQL,_,_,_,Con)
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_create_table/3
-% FieldsList = [field(Name,Type,Null,Key,DefaultValue)]
-% Example [field(campo1,'char(12)',y,y,a),field(campo2,int,y,y,0)]
-% TODO Test with ODBC & Type Checks
+ % db_create_table/3
+ % FieldsList = [field(Name,Type,Null,Key,DefaultValue)]
+ % Example [field(campo1,'char(12)',y,y,a),field(campo2,int,y,y,0)]
+ % TODO Test with ODBC & Type Checks
db_create_table(Connection,TableName,FieldsInf):-
-'$error_checks'(db_create_table(Connection,TableName,FieldsInf)),
-get_value(Connection,Con),
+ '$error_checks'(db_create_table(Connection,TableName,FieldsInf)),
+ get_value(Connection,Con),
-'$process_fields'(FieldsInf,FieldString,KeysSQL),
-'$make_atom'(['CREATE TABLE `',TableName,'` ( ',FieldString,KeysSQL,' )'],FinalSQL),
+ '$process_fields'(FieldsInf,FieldString,KeysSQL),
+ '$make_atom'(['CREATE TABLE `',TableName,'` ( ',FieldString,KeysSQL,' )'],FinalSQL),
-c_db_connection_type(Con,ConType),
-'$write_or_not'(FinalSQL),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(FinalSQL,_,Con,Mode,_)
-;ConType == posgres ->
- postgres_result_set(Mode),
- c_postsgres_query(FinalSQL,_,Con,Mode,_)
-;ConType == sqlite3 ->
- sqlite3_result_set(Mode),
- c_sqlite3_query(FinalSQL,_,Con,Mode,_)
-;
- c_db_odbc_query(FinalSQL,_,_,_,Con)
-).
+ c_db_connection_type(Con,ConType),
+ '$write_or_not'(FinalSQL),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(FinalSQL,_,Con,Mode,_)
+ ;ConType == posgres ->
+ postgres_result_set(Mode),
+ c_postsgres_query(FinalSQL,_,Con,Mode,_)
+ ;ConType == sqlite3 ->
+ sqlite3_result_set(Mode),
+ c_sqlite3_query(FinalSQL,_,Con,Mode,_)
+ ;
+ c_db_odbc_query(FinalSQL,_,_,_,Con)
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_export_view/4
-% TODO Test with ODBC
-%
+ % db_export_view/4
+ % TODO Test with ODBC
+ %
db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf):-
-'$error_checks'(db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf)),
-get_value(Connection,Con),
-'$process_sql_goal'(TableViewName,SQLorDbGoal,TableName,SQL),
+ '$error_checks'(db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf)),
+ get_value(Connection,Con),
+ '$process_sql_goal'(TableViewName,SQLorDbGoal,TableName,SQL),
-% Case there's some information about the
-% attribute fields of the relation given
-% by the user
-( FieldsInf == [] ->
- '$make_atom'(['CREATE TABLE ',TableName,' AS ',SQL],FinalSQL)
-;
- '$process_fields'(FieldsInf,FieldString,KeysSQL),
- '$make_atom'(['CREATE TABLE ',TableName,' (',FieldString,KeysSQL,') AS ',SQL],FinalSQL)
-),
+ % Case there's some information about the
+ % attribute fields of the relation given
+ % by the user
+ ( FieldsInf == [] ->
+ '$make_atom'(['CREATE TABLE ',TableName,' AS ',SQL],FinalSQL)
+ ;
+ '$process_fields'(FieldsInf,FieldString,KeysSQL),
+ '$make_atom'(['CREATE TABLE ',TableName,' (',FieldString,KeysSQL,') AS ',SQL],FinalSQL)
+ ),
-c_db_connection_type(Con,ConType),
-'$write_or_not'(FinalSQL),
-( ConType == mysql ->
- db_my_result_set(Mode),
- c_db_my_query(FinalSQL,_,Con,Mode,_)
-;
- c_db_odbc_query(FinalSQL,_,_,_,Con)
-).
+ c_db_connection_type(Con,ConType),
+ '$write_or_not'(FinalSQL),
+ ( ConType == mysql ->
+ db_my_result_set(Mode),
+ c_db_my_query(FinalSQL,_,Con,Mode,_)
+ ;
+ c_db_odbc_query(FinalSQL,_,_,_,Con)
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_update/2
-% BUG: db_update dosen't work for this case, just an example
-% db_update(my1,edge(1,3)-edge(99,99)).
-% The case where the set condition is "set" to change all the fields
+ % db_update/2
+ % BUG: db_update dosen't work for this case, just an example
+ % db_update(my1,edge(1,3)-edge(99,99)).
+ % The case where the set condition is "set" to change all the fields
db_update(Connection,WherePred-SetPred):-
-%TODO: error_checks
-get_value(Connection,Conn),
+ %TODO: error_checks
+ get_value(Connection,Conn),
-% Match and Values must be "unifiable"
-functor(WherePred,PredName,Arity),
-functor(SetPred,PredName,Arity),
+ % Match and Values must be "unifiable"
+ functor(WherePred,PredName,Arity),
+ functor(SetPred,PredName,Arity),
-functor(NewRelation,PredName,Arity),
+ functor(NewRelation,PredName,Arity),
-'$extract_args'(WherePred,1,Arity,WhereArgs),
-'$extract_args'(SetPred,1,Arity,SetArgs),
+ '$extract_args'(WherePred,1,Arity,WhereArgs),
+ '$extract_args'(SetPred,1,Arity,SetArgs),
-copy_term(WhereArgs,WhereArgsTemp),
-NewRelation=..[PredName|WhereArgsTemp],
-translate(NewRelation,NewRelation,Code),
+ copy_term(WhereArgs,WhereArgsTemp),
+ NewRelation=..[PredName|WhereArgsTemp],
+ translate(NewRelation,NewRelation,Code),
-'$get_values_for_update'(Code,SetArgs,SetCondition,WhereCondition),
+ '$get_values_for_update'(Code,SetArgs,SetCondition,WhereCondition),
-'$get_table_name'(Code,TableName),
-append(SetCondition,WhereCondition,Conditions),
-'$make_atom'(['UPDATE `',TableName,'` '|Conditions],SQL),
-'$write_or_not'(SQL),
-db_my_result_set(Mode),
-c_db_my_query(SQL,_,Conn,Mode,_).
+ '$get_table_name'(Code,TableName),
+ append(SetCondition,WhereCondition,Conditions),
+ '$make_atom'(['UPDATE `',TableName,'` '|Conditions],SQL),
+ '$write_or_not'(SQL),
+ db_my_result_set(Mode),
+ c_db_my_query(SQL,_,Conn,Mode,_).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_get_attributes_types/3
-% db_get_attributes_types/2
-%
+ % db_get_attributes_types/3
+ % db_get_attributes_types/2
+ %
db_get_attributes_types(RelationName,TypesList) :-
-db_get_attributes_types(myddas,RelationName,TypesList).
+ db_get_attributes_types(myddas,RelationName,TypesList).
db_get_attributes_types(Connection,RelationName,TypesList) :-
-'$error_checks'(db_get_attributes_types(Connection,RelationName,TypesList)),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-( ConType == mysql ->
- c_db_my_number_of_fields(RelationName,Con,Arity)
-;
- c_db_odbc_number_of_fields(RelationName,Con,Arity)
-),
-Size is 2*Arity,
-'$make_a_list'(Size,TypesList),
-c_db_connection_type(Con,ConType),
-( ConType == mysql ->
- c_db_my_get_attributes_types(RelationName,Con,TypesList)
-;
- c_db_odbc_get_attributes_types(RelationName,Con,TypesList)
-).
+ '$error_checks'(db_get_attributes_types(Connection,RelationName,TypesList)),
+ get_value(Connection,Con),
+ c_db_connection_type(Con,ConType),
+ ( ConType == mysql ->
+ c_db_my_number_of_fields(RelationName,Con,Arity)
+ ;
+ c_db_odbc_number_of_fields(RelationName,Con,Arity)
+ ),
+ Size is 2*Arity,
+ '$make_a_list'(Size,TypesList),
+ c_db_connection_type(Con,ConType),
+ ( ConType == mysql ->
+ c_db_my_get_attributes_types(RelationName,Con,TypesList)
+ ;
+ c_db_odbc_get_attributes_types(RelationName,Con,TypesList)
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_number_of_fields/3
-%
-%
+ % db_number_of_fields/3
+ %
+ %
db_number_of_fields(RelationName,Arity) :-
-db_number_of_fields(myddas,RelationName,Arity).
+ db_number_of_fields(myddas,RelationName,Arity).
db_number_of_fields(Connection,RelationName,Arity) :-
-'$error_checks'(db_number_of_fields(Connection,RelationName,Arity)),
-get_value(Connection,Con),
-c_db_connection_type(Con,ConType),
-( ConType == mysql ->
- c_db_my_number_of_fields(RelationName,Con,Arity)
-;ConType == postgres ->
- c_postgres_number_of_fields(RelationName,Con,Arity)
-;ConType == sqlite3 ->
- c_sqlite3_number_of_fields(RelationName,Con,Arity)
-;
- c_db_odbc_number_of_fields(RelationName,Con,Arity)
-).
+ '$error_checks'(db_number_of_fields(Connection,RelationName,Arity)),
+ get_value(Connection,Con),
+ c_db_connection_type(Con,ConType),
+ ( ConType == mysql ->
+ c_db_my_number_of_fields(RelationName,Con,Arity)
+ ;ConType == postgres ->
+ c_postgres_number_of_fields(RelationName,Con,Arity)
+ ;ConType == sqlite3 ->
+ c_sqlite3_number_of_fields(RelationName,Con,Arity)
+ ;
+ c_db_odbc_number_of_fields(RelationName,Con,Arity)
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% db_multi_queries_number(+,+)
-% TODO: EVERITHING
-%
+ % db_multi_queries_number(+,+)
+ % TODO: EVERITHING
+ %
db_multi_queries_number(Connection,Number) :-
-'$error_checks'(db_multi_queries_number(Connection,Number)),
-get_value(Connection,Con),
-c_db_multi_queries_number(Con,Number).
+ '$error_checks'(db_multi_queries_number(Connection,Number)),
+ get_value(Connection,Con),
+ c_db_multi_queries_number(Con,Number).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/packages/raptor b/packages/raptor
index b36fdac22..36f99e3c3 160000
--- a/packages/raptor
+++ b/packages/raptor
@@ -1 +1 @@
-Subproject commit b36fdac2281b7eef141095375d81456410dbcd2f
+Subproject commit 36f99e3c3c978fef25f899dc4fab1ffee334d73c
diff --git a/packages/swig/Makefile.in b/packages/swig/Makefile.in
index f95b101ec..568ef840c 100644
--- a/packages/swig/Makefile.in
+++ b/packages/swig/Makefile.in
@@ -116,8 +116,7 @@ android/jni/yap_wrap.cpp: $(YAP_SWIG_INTERFACE) android/AndroidManifest.xml
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o $@ $<
install-android: android
- adb uninstall pt.up.fc.dcc.yap
- adb install android/bin/JavaYap-debug.apk
+ adb install -r android/bin/JavaYap-debug.apk
R:
diff --git a/packages/swig/android/JavaYap.java b/packages/swig/android/JavaYap.java
index 72e03c6a4..4f34539c7 100644
--- a/packages/swig/android/JavaYap.java
+++ b/packages/swig/android/JavaYap.java
@@ -53,180 +53,184 @@ class DoNotDeleteErrorHandler implements DatabaseErrorHandler {
}
public class JavaYap extends Activity
{
- TextView outputText = null;
- ScrollView scroller = null;
- YAPEngine eng = null;
- EditText text;
- String str;
- String buf;
+ TextView outputText = null;
+ ScrollView scroller = null;
+ YAPEngine eng = null;
+ EditText text;
+ String str;
+ String buf;
- void runQuery(String str)
- {
- try
- {
- YAPQuery q = eng.query( str );
+ void runQuery(String str)
+ {
+ try
+ {
+ YAPQuery q = eng.query( str );
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "onQueryButtonClick called");
- }
- YAPListTerm vs0 = q.namedVars();
- Boolean rc;
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "onQueryButtonClick called");
+ }
+ YAPListTerm vs0 = q.namedVars();
+ Boolean rc;
- // text.setText("");
- if (vs0.nil()) {
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "q0=\n");
- }
- if (q.next()) {
- outputText.append( "yes\n" );
- } else {
- outputText.append( "no\n" );
- }
- } else {
- int i=1;
- if (BuildConfig.DEBUG) {
- //Log.i(TAG, "q1= "+vs0.text()+"\n");
+ // text.setText("");
+ if (vs0.nil()) {
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "q0=\n");
+ }
+ if (q.next()) {
+ outputText.append( "yes\n" );
+ } else {
+ outputText.append( "no\n" );
+ }
+ } else {
+ int i=1;
+ if (BuildConfig.DEBUG) {
+ //Log.i(TAG, "q1= "+vs0.text()+"\n");
- }
- while (rc = q.next()) {
- if (BuildConfig.DEBUG) {
- //Log.i(TAG, "q= "+vs0.text()+"\n");
-
- }
- YAPListTerm vs = vs0;
- while(!vs.nil()){
- YAPTerm eq = vs.car();
- //outputText.append(Integer.toString(i) + ": " + eq.text() );
- outputText.append(Integer.toString(i++) + ":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
- vs = vs.cdr();
- }
- }
- }
- q.close();
- } catch(Exception e){
- outputText.append("Exception thrown :" + e);
- return;
- }
+ }
+ while (rc = q.next()) {
+ YAPListTerm vs = vs0;
+ while(!vs.nil()){
+ YAPTerm eq = vs.car();
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "q= "+vs0+"\n");
+ }
+ //outputText.append(Integer.toString(i) + ": " + eq.text() );
+ outputText.append(Integer.toString(i++));
+ Log.i(TAG, "q= "+ eq.getArg(1)+"\n");
+ Log.i(TAG, "q= "+ eq.getArg(2)+"\n");
+ Log.i(TAG, "q= "+ eq.getArg(1).text()+"\n");
+ Log.i(TAG, "q= "+ eq.getArg(2).text()+"\n");
+outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
+ vs = vs.cdr();
+ }
+ }
}
+ q.close();
+ } catch(Exception e){
+ outputText.append("Exception thrown :" + e);
+ return;
+ }
+ }
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- String s = null;
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ String s = null;
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
- try {
- PackageManager m = getPackageManager();
- s = getPackageName();
- PackageInfo p = m.getPackageInfo(s, 0);
- //s = p.applicationInfo.dataDir;
- AssetManager mgr = getResources().getAssets();
- Log.i(TAG, "mgr=" +mgr + " " + s);
- load(mgr);
- } catch(NameNotFoundException e) {
- Log.e(TAG, "Couldn't find package information in PackageManager", e);
- }
- Log.i(TAG, "mgr=" +mgr);
+ try {
+ PackageManager m = getPackageManager();
+ s = getPackageName();
+ PackageInfo p = m.getPackageInfo(s, 0);
+ //s = p.applicationInfo.dataDir;
+ AssetManager mgr = getResources().getAssets();
+ Log.i(TAG, "mgr=" +mgr + " " + s);
+ load(mgr);
+ } catch(NameNotFoundException e) {
+ Log.e(TAG, "Couldn't find package information in PackageManager", e);
+ }
+ Log.i(TAG, "mgr=" +mgr);
- text = (EditText)findViewById(R.id.EditText01);
- outputText = (TextView)findViewById(R.id.OutputText);
- outputText.setText("Application " + s + "\nPress 'Query' to start...\n");
- outputText.setMovementMethod(new ScrollingMovementMethod());
- scroller = (ScrollView)findViewById(R.id.Scroller);
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "window making done");
- }
- eng = new YAPEngine( );
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "engine done");
- }
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "onClearButtonClick called");
- }
- JavaCallback callback = new JavaCallback( outputText );
- // set the Java Callback
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "before setting callback");
- }
- eng.setYAPCallback(callback);
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "callback done");
- }
- }
-
- public void onClearButtonClick(View view)
- {
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "onClearButtonClick called");
- }
- // Ensure scroll to end of text
- scroller.post(new Runnable() {
- public void run() {
- scroller.fullScroll(ScrollView.FOCUS_DOWN);
- text.setText("");
- }
- });
+ text = (EditText)findViewById(R.id.EditText01);
+ outputText = (TextView)findViewById(R.id.OutputText);
+ outputText.setText("Application " + s + "\nPress 'Query' to start...\n");
+ outputText.setMovementMethod(new ScrollingMovementMethod());
+ scroller = (ScrollView)findViewById(R.id.Scroller);
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "window making done");
+ }
+ eng = new YAPEngine( );
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "engine done");
+ }
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "onClearButtonClick called");
+ }
+ JavaCallback callback = new JavaCallback( outputText );
+ // set the Java Callback
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "before setting callback");
+ }
+ eng.setYAPCallback(callback);
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "callback done");
+ }
+ }
+
+ public void onClearButtonClick(View view)
+ {
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "onClearButtonClick called");
+ }
+ // Ensure scroll to end of text
+ scroller.post(new Runnable() {
+ public void run() {
+ scroller.fullScroll(ScrollView.FOCUS_DOWN);
+ text.setText("");
}
+ });
+ }
- public void onQueryButtonClick(View view)
- {
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "onQueryButtonClick called");
- }
- // Ensure scroll to end of text
- scroller.post(new Runnable() {
- public void run() {
- scroller.fullScroll(ScrollView.FOCUS_DOWN);
- str = text.getText().toString();
- outputText.append("?- " + str);
- Log.i(TAG, "onQueryButtonClick "+str + "\n");
- runQuery(str);
- }
- });
+ public void onQueryButtonClick(View view)
+ {
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "onQueryButtonClick called");
+ }
+ // Ensure scroll to end of text
+ scroller.post(new Runnable() {
+ public void run() {
+ scroller.fullScroll(ScrollView.FOCUS_DOWN);
+ str = text.getText().toString();
+ outputText.append("?- " + str);
+ Log.i(TAG, "onQueryButtonClick "+str + "\n");
+ runQuery(str);
}
+ });
+ }
- public void onQuerySelectionButtonClick(View view)
- {
- if (BuildConfig.DEBUG) {
- Log.i(TAG, "onQuerySelectionButtonClick called");
- }
- // Ensure scroll to end of text
- scroller.post(new Runnable() {
- public void run() {
- scroller.fullScroll(ScrollView.FOCUS_DOWN);
- int startSelection = text.getSelectionStart();
- int endSelection = text.getSelectionEnd();
- str = text.getText().toString().substring( startSelection, endSelection );
- Log.i(TAG, "onQuerySelectionButtonClick "+str);
- outputText.append("?- " + str + "\n");
- runQuery(str);
- }
- });
+ public void onQuerySelectionButtonClick(View view)
+ {
+ if (BuildConfig.DEBUG) {
+ Log.i(TAG, "onQuerySelectionButtonClick called");
+ }
+ // Ensure scroll to end of text
+ scroller.post(new Runnable() {
+ public void run() {
+ scroller.fullScroll(ScrollView.FOCUS_DOWN);
+ int startSelection = text.getSelectionStart();
+ int endSelection = text.getSelectionEnd();
+ str = text.getText().toString().substring( startSelection, endSelection );
+ Log.i(TAG, "onQuerySelectionButtonClick "+str);
+ outputText.append("?- " + str + "\n");
+ runQuery(str);
}
+ });
+ }
- /** static constructor */
- static {
- System.loadLibrary("android");
- System.loadLibrary("log");
- System.loadLibrary("gmp");
- System.loadLibrary("sqliteX");
- System.loadLibrary("example");
- }
+ /** static constructor */
+ static {
+ System.loadLibrary("android");
+ System.loadLibrary("log");
+ System.loadLibrary("gmp");
+ System.loadLibrary("sqliteX");
+ System.loadLibrary("example");
+ }
- private static native void load(AssetManager mgr);
+ private static native void load(AssetManager mgr);
- private AssetManager mgr;
+ private AssetManager mgr;
- private static final String TAG = "JavaYap";
+ private static final String TAG = "JavaYap";
}
class JavaCallback extends YAPCallback
{
- TextView output;
+ TextView output;
public JavaCallback( TextView outputText )
{
@@ -238,15 +242,15 @@ class JavaCallback extends YAPCallback
public void run()
{
- Log.i(TAG, "java callback ");
- System.out.println("JavaCallback.run() ");
+ Log.i(TAG, "java callback ");
+ System.out.println("JavaCallback.run() ");
}
public void run(String s)
{
Log.i(TAG, "java callback ");
output.append(s);
- }
+ }
private static final String TAG = "JavaCallback";