4 #include <TupleSchema.h>
6 #include <BindingTable.h>
11 * A Query is an implementation of a generic ABI over relations. It's
12 * more or less a "virtual Relation" representing a logical composite
13 * access of actual relations, and as such its active part is held in
14 * a separate \ref Querytype record similar to how \ref ItemKeyFun
15 * records define valye types.
17 typedef struct Query {
18 struct QueryCallbacks *def;
22 * \brief Creates an assignment Query.
24 * \param arity is the assignment tuple arity.
26 * \param names is the (char*) names to assign.
28 * \param values is the (void*) values to asign.
30 * The two tuples must have the same arity for assigning names[i] to
31 * values[i]. This Query makes the given names have the given values,
32 * once for each (*next) call following a (*reset) call.
36 extern Query *Query_assign(int arity,Tuple *names,Tuple *values);
39 * \brief Create a Query record for lookup data in a Relation.
41 * \param r is the relation being queried.
43 * \param names is a same-arity tuple of binding names for the
44 * columns, using \b 0 for unnamed columns.
46 * \param values is a same--arity tuple of query values, using \b 0 for
47 * columns to enumerate.
49 * The names and values tuples identify bindings and values to use for
50 * the search query, and which bindings to set up from the successive
51 * results. Names that are bound beforhand identify constraining
52 * values, and the names that are unbound gain successive values from
53 * the matching tuples.
57 extern Query *Query_Relation(Relation *r,Tuple *names,Tuple *values);
60 * \brief Create a Query record for a conjunction of queries.
62 * \param n is the number of sub queries.
64 * \param ... are the sub queries.
66 * The conjunction query processes the sub queries in order resulting
67 * in the sequence of their combined bindings.
71 extern Query *Query_and(int n,...);
74 * \brief Create a Query record for a disjunction of queries.
76 * \param n is the number of sub queries.
78 * \param ... are the sub queries.
80 * The disjunction query processed the sub queries in order to find
81 * all their individual "true" binding combinations. It processes one
82 * sub query at a time to exhaustion and provide their individudal
83 * binding sequences separately.
87 extern Query *Query_or(int n,...);
90 * \brief Invoke a consequent callback function for each successful
93 * \param q is the antecedent query to process.
95 * \param bt is the binding table to use.
97 * \param consequent is the callback function to invoke for each
99 * \param data is the caller's context data.
101 * This function prrocesses the Query for establishing its binding
102 * sequence and inokes the consequent callback function for each
103 * binding as it is provided.
107 extern void Query_rule(
108 Query *q,BindingTable *bt,
109 int (*consequent)(BindingTable *bt,void *data),