Ejemplo n.º 1
0
  /**
   * Runs a query with an external variable declaration.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryBindSequence() throws IOException {
    Query query = session.query("declare variable $a external; $a");
    query.bind("a", "1\u00012", "xs:integer");
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", "09\u0002xs:hexBinary\u00012", "xs:integer");
    assertEqual("09", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", Seq.get(new Item[] {Int.get(1), Str.get("X")}, 2));
    assertEqual("1", query.next());
    assertEqual("X", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT));
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT), "xs:integer");
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();
  }
Ejemplo n.º 2
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBind() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("$a", "4");
   assertEqual("4", query.execute());
   query.bind("$a", "5");
   assertEqual("5", query.next());
   query.bind("$a", "6");
   assertEqual("6", query.next());
   query.close();
 }
Ejemplo n.º 3
0
  /**
   * Runs a query with an external variable declaration.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryBindInt() throws IOException {
    Query query = session.query("declare variable $a as xs:integer external; $a");
    query.bind("a", "5", "xs:integer");
    assertEqual("5", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", Int.get(1), "xs:integer");
    assertEqual("1", query.next());
    query.close();
  }
Ejemplo n.º 4
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindDynamic() throws IOException {
   final Query query = session.query("declare variable $a as xs:integer external; $a");
   query.bind("a", "1");
   assertEqual("1", query.execute());
   query.close();
 }
Ejemplo n.º 5
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindEmptySequence() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("a", "()", "empty-sequence()");
   assertNull(query.next());
   query.close();
 }
Ejemplo n.º 6
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindURI() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("$a", "X", "xs:anyURI");
   assertEqual("X", query.next());
   query.close();
 }
Ejemplo n.º 7
0
 /**
  * Binds maps to external variables via JSON.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindJson() throws IOException {
   final String var = "declare variable $x external;",
       map = "{\"foo\":[1,2,3],\"bar\":{\"a\":null,\"\":false}}";
   final String[][] tests = {
     {"for $k in map:keys($x) order by $k descending return $k", "foo bar"},
     {"every $k in map:keys($x('foo')) satisfies $k eq $x('foo')($k)", "true"},
     {"empty($x('bar')('a')) and not($x('bar')(''))", "true"},
   };
   for (final String[] test : tests) {
     final Query q = session.query(var + test[0]);
     try {
       q.bind("$x", map, "json");
       assertEqual(test[1], q.execute());
     } finally {
       q.close();
     }
   }
 }
Ejemplo n.º 8
0
 /**
  * Binds a document node to an external variable.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindDoc() throws IOException {
   final Query query = session.query("declare variable $a external; $a//text()");
   query.bind("$a", "<a>XML</a>", "document-node()");
   assertEqual("XML", query.execute());
 }