gavo.rsc.qtable module

A table representing a query.

This is mainly for streaming applications. The table represents a DB query result. All you can do with the data itself is iterate over the rows. The metadata is usable as with any other table.

class gavo.rsc.qtable.QueryTable(tableDef, query, connection, **kwargs)[source]

Bases: BaseTable, DBMethodsMixin

QueryTables are constructed with a table definition and a DB query feeding this table definition.

A QueryTable must be constructed with a transactional connection (in sqlsupport terms: Writable). If you pass autoClose=True, it will close this connection after the data is delivered.

This funky semantics is for the benefit of taprunner; it needs a connection up front for uploads.

There’s an alternative constructor allowing “quick” construction of the result table (fromColumns).

cleanup()[source]
configureOnClose(parPairs)[source]

adds parameter pairs (as coming back from conn.configure) to a set of pairs to be restored when this qtable is being cleaned up.

For a connection in error, use of this facility will mean that connections will be rolled back automatically (because we couldn’t restore the parameters otherwise).

connection = None
classmethod fromColumns(colSpec, query, connection, **kwargs)[source]

returns a QueryTable object for query, where the result table is inferred from colSpec.

colSpec is a sequence consisting of either dictionaries with constructor arguments to rscdef.Column or complete objects suitable as rscdef.Column objects; further kwargs are passed on the the QueryTable’s constructor.

getPlan()[source]

returns a parsed query plan for the current query.

After you use this method, the iterator is exhausted and the connection will be closed.