Esempio n. 1
0
db_atoms
database_rep::query (tree ql, db_time t, int limit) {
    //cout << "query " << ql << ", " << t << ", " << limit << LF;
    ql= normalize_query (ql);
    //cout << "normalized query " << ql << ", " << t << ", " << limit << LF;
    db_atoms ids= ansatz (ql, t);
    //cout << "ansatz ids= " << ids << LF;
    bool sort_flag= false;
    if (is_tuple (ql))
        for (int i=0; i<N(ql); i++)
            sort_flag= sort_flag || is_tuple (ql[i], "order", 2);
    ids= filter (ids, ql, t, max (limit, sort_flag? 1000: 0));
    //cout << "filtered ids= " << ids << LF;
    for (int i=0; i<N(ql); i++) {
        if (is_tuple (ql[i], "modified", 2) &&
                is_atomic (ql[i][1]) && is_atomic (ql[i][2]) &&
                is_quoted (ql[i][1]->label) && is_quoted (ql[i][2]->label)) {
            string t1= scm_unquote (ql[i][1]->label);
            string t2= scm_unquote (ql[i][2]->label);
            if (is_int (t1) && is_int (t2))
                ids= filter_modified (ids, (db_time) as_long_int (t1),
                                      (db_time) as_long_int (t2));
        }
    }
    //cout << "filtered on modified ids= " << ids << LF;
    ids= sort_results (ids, ql, t);
    //cout << "sorted ids= " << ids << LF;
    if (N(ids) > limit) ids= range (ids, 0, limit);
    return ids;
}
Esempio n. 2
0
inline long int as_long_int (tree t) {
  if (is_atomic (t)) return as_long_int (t->label);
  else return 0; }