コード例 #1
0
  void encodeQuery(SQL sql, Query q, QueryPlan qp) {
    if (!Filter.isTrueOrNull(q.getFilter())) {
      GeoPkgFilterSQLEncoder sqlfe = new GeoPkgFilterSQLEncoder();
      sqlfe.setPrepared(false);
      try {
        sql.add(" WHERE ").add(sqlfe.encode(q.getFilter(), null));
        qp.filtered();
      } catch (Exception e) {
        Log.d("geopkg", "Unable to natively encode filter: " + q.getFilter(), e);
      }
    }

    if (q.getLimit() != null) {
      sql.add(" LIMIT ").add(q.getLimit());
      qp.offsetted();
    }
    if (q.getOffset() != null) {
      sql.add(" OFFSET ").add(q.getOffset());
      qp.limited();
    }
  }
コード例 #2
0
  long count(FeatureEntry entry, Query q) throws IOException {

    if (!Envelopes.isNull(q.getBounds())) {
      return Cursors.size(cursor(entry, q));
    }

    SQL sql = new SQL("SELECT count(*) FROM ").name(entry.getTableName());

    QueryPlan qp = new QueryPlan(q);
    encodeQuery(sql, q, qp);

    if (q.isFiltered() && !qp.isFiltered()) {
      return Cursors.size(cursor(entry, q));
    }

    Cursor c = db.rawQuery(log(sql.toString()), null);
    try {
      c.moveToNext();
      return c.getLong(0);
    } finally {
      c.close();
    }
  }