Interface: QueryResultIntf
QueryResults are collections tuples or partially aggregated results, either produced locally or
received over the network.
This interface defines routines to marshall / unmarshall them from tuples and
byte arrays.
Note that QueryResults (or ResultTuples) should not be
confused with Tuples (see TupleIntf) which are simple, fixed width
packed arrays of attribute data collected from local fields. Tuples
are used internally to collect data about sensors -- QueryResults are
sent to neighboring motes and stored in result buffers for external
processing.
ResultTuples can be used to get information about specified subtuples of a result.
ResultTuple is defined in TinyDB.h.
They are either aggregates (in which case the individual ResultTuples should be
converted to QueryResults via fromResultTuple and passed to AggOperator for
processing), or
Note that you must be careful with QueryResults, since they are sometimes initalized with
pointers into the data structures that they are created from, such that overwriting
their data can cause dangerous things to happen and the underlying pointers can become
invalid when current tuples / buffers are reused. Situations in which references
may be returned are noted carefully below (usually this is done for large results
for which extra copies would incur a significant memory overhead).
- Components providing this interface:
-
tos.lib.TinyDB.QueryResult
- Components requiring this interface:
-
tos.lib.TinyDB.AggOperator
tos.lib.TinyDB.DBBufferC
tos.lib.TinyDB.ParsedQuery
tos.lib.TinyDB.TupleRouterM
-
TinyDBError
initQueryResult
(QueryResultPtr qr)
-
TinyDBError
fromTuple
(QueryResultPtr qr, ParsedQueryPtr q, TuplePtr t)
-
TinyDBError
toTuplePtr
(QueryResultPtr qr, ParsedQueryPtr q, TupleHandle t)
-
uint16_t resultSize(QueryResultPtr qr, ParsedQueryPtr q)
-
TinyDBError
toBytes
(QueryResultPtr qr, ParsedQueryPtr q, CharPtr bytes)
-
TinyDBError fromBytes(CharPtr bytes, QueryResultPtr qr, ParsedQueryPtr q, uint8_t start)
-
TinyDBError fromMsgBytes(CharPtr bytes, QueryResultPtr qr, ParsedQueryPtr q)
Convert a set of bytes from a network message into a query result (pull the header off the
byte array and use fromBytes to parse.
-
TinyDBError fromResultTuple(ResultTuple r, QueryResultPtr qr, ParsedQueryPtr pq)
Create a QueryResult from a ResultTuple
-
short queryIdFromMsg(CharPtr bytes)
Return the queryId corresponding to the specified QueryResult network message
-
short numRecords(QueryResultPtr qr, ParsedQueryPtr q)
Returns: |
The number of fields in this result |
-
ResultTuple
getResultTuple
(QueryResultPtr qr, short i, ParsedQueryPtr q)
-
TinyDBError addAggResult(QueryResultPtr qr, int16_t groupNo, char *bytes, int16_t size, ParsedQueryPtr q, short exprIdx)
Add an agggreate result for the specified query for the specified expression
If this query result has already been initialized from a tuple, returns err_AlreadyTupleResult
If this query result contains results for a different query id, return err_InvalidQueryId
initQueryResult
TinyDBError initQueryResult(QueryResultPtr qr) Reset / initialize the specified query result so that it contains no data
(does NOT deallocate memory associated with prior data stored in the result
Parameters: |
qr - The query result to initialize.
|
fromTuple
TinyDBError fromTuple(QueryResultPtr qr, ParsedQueryPtr q, TuplePtr t) Create a QueryResult from a TuplePtr. Copies data from t (not just references!)
Parameters: |
qr - The (initialized) QueryResult to fill in
q - The query that t belongs to
t - The tuple to write into the QueryResult
|
toTuplePtr
TinyDBError toTuplePtr(QueryResultPtr qr, ParsedQueryPtr q, TupleHandle t) Create a Tuple from q QueryResult. The returned tuple is a reference into the
query result. Should only be called if the type qr->qrType == kNOT_AGG.
Parameters: |
qr - The QueryResult to build the tuple from
q - The query corresponding to the query result / tuple
t - (on return) The tuple containing the data from the query result
|
toBytes
TinyDBError toBytes(QueryResultPtr qr, ParsedQueryPtr q, CharPtr bytes) Marshall the specified query result into a byte array. The byte array must be at least
resultSize(...) bytes long.
Parameters: |
qr - The QueryResult to marshall
q - The query corresponding to the query result
bytes - The byte array to write the result into.
|
getResultTuple
ResultTuple getResultTuple(QueryResultPtr qr, short i, ParsedQueryPtr q)
Returns: |
The specified sub result from this query result (will contain references into qr)
|
Parameters: |
i - The result number to retrieve (0 .. numRecords)
q - The query corresponding to this query result
|