示例#1
0
文件: FNSql.java 项目: yzzo/basex
  /**
   * Extracts connection options.
   *
   * @param arg argument with options
   * @param root expected root element
   * @param ctx query context
   * @return options
   * @throws QueryException query exception
   */
  private TokenObjMap<Object> options(final int arg, final QNm root, final QueryContext ctx)
      throws QueryException {
    // initialize token map
    final TokenObjMap<Object> tm = new TokenObjMap<Object>();
    // argument does not exist...
    if (arg >= expr.length) return tm;

    // empty sequence...
    final Item it = expr[arg].item(ctx, input);
    if (it == null) return tm;

    // XQuery map: convert to internal map
    if (it instanceof Map) return ((Map) it).tokenJavaMap(input);
    // no element: convert XQuery map to internal map
    if (!it.type().eq(SeqType.ELM)) throw NODFUNTYPE.thrw(input, this, it.type);

    // parse nodes
    ANode node = (ANode) it;
    if (!node.qname().eq(root)) PARWHICH.thrw(input, node.qname());

    // interpret query parameters
    final AxisIter ai = node.children();
    while ((node = ai.next()) != null) {
      final QNm qn = node.qname();
      if (!qn.uri().eq(Uri.uri(SQLURI))) PARWHICH.thrw(input, qn);
      tm.add(qn.ln(), node.children().next());
    }
    return tm;
  }
示例#2
0
文件: FNSql.java 项目: yzzo/basex
 /**
  * Executes a prepared statement.
  *
  * @param stmt prepared statement
  * @param ctx query context
  * @return result
  * @throws QueryException query exception
  */
 private NodeCache executePrepStmt(final PreparedStatement stmt, final QueryContext ctx)
     throws QueryException {
   // Get parameters for prepared statement
   final ANode params = (ANode) checkType(expr[1].item(ctx, input), NodeType.ELM);
   if (!params.qname().eq(E_PARAMS)) PARWHICH.thrw(input, params.qname());
   try {
     final int placeCount = stmt.getParameterMetaData().getParameterCount();
     // Check if number of parameters equals number of place holders
     if (placeCount != countParams(params)) PARAMS.thrw(input);
     else setParameters(params.children(), stmt);
     final boolean result = stmt.execute();
     return result ? buildResult(stmt.getResultSet()) : new NodeCache();
   } catch (final SQLException ex) {
     throw SQLEXC.thrw(input, ex.getMessage());
   }
 }
示例#3
0
 /**
  * Adds children of a sub node.
  *
  * @param ch child nodes
  * @param nc node cache
  */
 protected final void addDesc(final AxisMoreIter ch, final NodeCache nc) {
   for (ANode n; (n = ch.next()) != null; ) {
     nc.add(n.finish());
     addDesc(n.children(), nc);
   }
 }
示例#4
0
文件: FNSql.java 项目: yzzo/basex
 /**
  * Counts the numbers of <sql:parameter/> elements.
  *
  * @param params element <sql:parameter/>
  * @return number of parameters
  */
 private long countParams(final ANode params) {
   final AxisIter ch = params.children();
   long c = ch.size();
   if (c == -1) do ++c; while (ch.next() != null);
   return c;
 }