Apps     Components     Interfaces     All Files     Source Tree     source: tos.lib.TinyDB.QueryResultIntf.nc

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).
Author: Sam Madden

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

Commands

Commands - Details

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