#include <Soprano/QueryResultIterator>
Public Member Functions | |
QueryResultIterator () | |
QueryResultIterator (const QueryResultIterator &) | |
QueryResultIterator (QueryResultIteratorBackend *qr) | |
virtual | ~QueryResultIterator () |
QueryResultIterator & | operator= (const QueryResultIterator &) |
Statement | currentStatement () const |
BindingSet | currentBindings () const |
bool | boolValue () const |
Node | binding (const QString &name) const |
Node | binding (int offset) const |
int | bindingCount () const |
QStringList | bindingNames () const |
bool | isGraph () const |
bool | isBinding () const |
bool | isBool () const |
QList< BindingSet > | allBindings () |
StatementIterator | iterateStatements () const |
NodeIterator | iterateBindings (const QString &variableName) const |
NodeIterator | iterateBindings (int offset) const |
Query results in Soprano are wrapped in a QueryResultIterator.
Query iterators are returned by Model::executeQuery(). In contrast to NodeIterator or StatementIterator QueryResultIterator has a set of different access methods for the current dataset which can be one of three things:
QueryResultIterator it = model->executeQuery( someGraphQuery ); while( it.next() ) { doSomething( it.currentStatement() ); } QueryResultIterator it2 = model->executeQuery( someTupleQuery ); while( it.next() ) { doSomethingElse( it.currentBindings() ); doSomethingCompletelyDifferent( it.binding( "x" ) ); doSomethingEntirelyDifferent( it.binding( 0 ) ); }
Many backends do lock the underlying Model during iteration. Thus, it is always a good idea to cache the results if they are to be used to modify the model to prevent a deadlock:
Soprano::QueryResultIterator it = model->executeQuery( someTupleQuery ); QList<BindingSet> allBindings = it.allBindings(); Q_FOREACH( Soprano::BindingSet bs, allBindings ) { modifyTheModel( model, bs ); }
Iterators have to be closed. This can either be achieved by deleting the iterator, finishing it (next() does return false
), or calling close(). Before that other operations on the Model may block.
Iterators are not thread-safe. Two threads using the same iterator at the same time may result in undefined behaviour and even crashes.
Definition at line 106 of file queryresultiterator.h.
Soprano::QueryResultIterator::QueryResultIterator | ( | ) |
Creates and empty, invalid iterator.
Soprano::QueryResultIterator::QueryResultIterator | ( | const QueryResultIterator & | ) |
Copy constructor. Copies of iterators share their data.
Soprano::QueryResultIterator::QueryResultIterator | ( | QueryResultIteratorBackend * | qr | ) |
Create a new QueryResultIterator which uses qr as backend. QueryResultIterator will take ownership of the QueryResultIteratorBackend.
virtual Soprano::QueryResultIterator::~QueryResultIterator | ( | ) | [virtual] |
Destructor.
QueryResultIterator& Soprano::QueryResultIterator::operator= | ( | const QueryResultIterator & | ) |
Copies of iterators share their data.
Statement Soprano::QueryResultIterator::currentStatement | ( | ) | const |
Retrieve the current Statement after a call to next. This method does only make sense for graph queries.
BindingSet Soprano::QueryResultIterator::currentBindings | ( | ) | const |
Convenience method that puts all current bindings into one map. This method does only make sense for tuple queries.
bool Soprano::QueryResultIterator::boolValue | ( | ) | const |
This method does only make sense for boolean queries.
Get the current binding for a variable.
name | The name of the requested variable. |
Node Soprano::QueryResultIterator::binding | ( | int | offset | ) | const |
Get the current binding for a variable by index.
offset | The index of the requested variable. |
int Soprano::QueryResultIterator::bindingCount | ( | ) | const |
The number of bindings in this query result.
This method does only make sense for tuple queries.
QStringList Soprano::QueryResultIterator::bindingNames | ( | ) | const |
This method does only make sense for tuple queries.
bool Soprano::QueryResultIterator::isGraph | ( | ) | const |
Check if this is a graph result.
true
if this result refers to a graph query, i.e. currentStatement() and iterateStatements() return valid values. bool Soprano::QueryResultIterator::isBinding | ( | ) | const |
Check if this is a tuple result.
true
if this result refers to a tuple query, i.e. currentBindings(), binding(), bindingCount(), bindingNames(), and allBindings() return valid values. bool Soprano::QueryResultIterator::isBool | ( | ) | const |
Check if this is a boolean result.
There is no need to call next() for boolean results. However, for internal reasons backends need to always return true
for boolean queries.
true
if this result refers to a boolean query (SPARQL ASK), i.e. boolValue() returns a valid value. QList<BindingSet> Soprano::QueryResultIterator::allBindings | ( | ) |
Convenience method that collects all binding sets that are left in the iterator.
StatementIterator Soprano::QueryResultIterator::iterateStatements | ( | ) | const |
Convenience method that creates an iterator over the statements in this query result. This method does only make sense for graph queries.
NodeIterator Soprano::QueryResultIterator::iterateBindings | ( | const QString & | variableName | ) | const |
Convenience method that creates an iterator over one column of bindings in this query result. This method does only make sense for tuple queries.
variableName | The name of the requested variable. |
NodeIterator Soprano::QueryResultIterator::iterateBindings | ( | int | offset | ) | const |
Convenience method that creates an iterator over one column of bindings in this query result. This method does only make sense for tuple queries.
offset | The index of the requested variable. |