Search in sources :

Example 46 with Query

use of org.jpl7.Query in project packages-jpl by SWI-Prolog.

the class Query method get1.

private final boolean get1() {
    // close the query;
    if (Prolog.next_solution(qid)) {
        return true;
    } else {
        // if failure was due to throw/1, build exception term and
        // throw it
        term_t exception_term_t = Prolog.exception(qid);
        if (exception_term_t.value != 0L) {
            Term exception_term = Term.getTerm(new HashMap<term_t, Variable>(), exception_term_t);
            close();
            throw new PrologException(exception_term);
        } else {
            close();
            return false;
        }
    }
}
Also used : org.jpl7.fli.term_t(org.jpl7.fli.term_t)

Example 47 with Query

use of org.jpl7.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testGetSolution1.

public void testGetSolution1() {
    Query q = new Query("fail");
    q.open();
    q.getSolution();
    assertTrue("an opened query on which getSolution has failed once is closed", !q.isOpen());
}
Also used : Query(org.jpl7.Query)

Example 48 with Query

use of org.jpl7.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testDontTellMeMode1.

public void testDontTellMeMode1() {
    final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)");
    JPL.setDTMMode(true);
    assertTrue("in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for just one variable", q.oneSolution().keySet().size() == 1);
}
Also used : Query(org.jpl7.Query)

Example 49 with Query

use of org.jpl7.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testJRef2.

public void testJRef2() {
    int i = 76543;
    Integer I = new Integer(i);
    Query q = new Query("jpl_call(?,intValue,[],I2)", JPL.newJRef(I));
    Term I2 = q.oneSolution().get("I2");
    assertTrue(I2.isInteger() && I2.intValue() == i);
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger) Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 50 with Query

use of org.jpl7.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testWouter1.

public void testWouter1() {
    // Wouter says this fails under OS X Mavericks
    // 10.9 x86-64
    // too big for an int
    long n = 7381783232223l;
    Compound term = new Compound("is", new Term[] { new Variable("X"), new org.jpl7.Integer(n) });
    Map<String, Term>[] solutions = new Query(term).allSolutions();
    assertEquals(1, solutions.length);
    Map<String, Term> solution = solutions[0];
    assertTrue(solution.containsKey("X"));
    Object result = solution.get("X");
    assertTrue(result instanceof org.jpl7.Integer);
    assertEquals(n, ((org.jpl7.Integer) result).longValue());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Integer(org.jpl7.Integer) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Map(java.util.Map)

Aggregations

Query (org.jpl7.Query)56 Term (org.jpl7.Term)33 Variable (org.jpl7.Variable)23 Atom (org.jpl7.Atom)16 Compound (org.jpl7.Compound)16 Map (java.util.Map)13 Query (com.google.datastore.v1.Query)12 Test (org.junit.Test)8 GqlQuery (com.google.datastore.v1.GqlQuery)7 Integer (org.jpl7.Integer)6 Datastore (com.google.datastore.v1.client.Datastore)4 SplitQueryFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn)4 Entity (com.google.datastore.v1.Entity)3 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)3 BigInteger (java.math.BigInteger)3 PrologException (org.jpl7.PrologException)3 PartitionId (com.google.datastore.v1.PartitionId)2 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)2 JPLException (org.jpl7.JPLException)2 Handle (org.skife.jdbi.v2.Handle)2