class QueryResultIterator


Module soprano
Namespace Soprano
Class QueryResultIterator
Inherits Iterator
\class QueryResultIterator queryresultiterator.h Soprano/QueryResultIterator

An iterator for query results.

%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:

  • A Statement: Graph query results are represented as a stream of statements.
  • See also currentStatement() and iterateStatements().
  • A BindingSet: Tuple query results are represented by a set of variable bindings
  • according to the variables used in the query. The bindings can be accessed as a set through the normal Iterator method current() or separately through #binding(int) const or #binding(const QString&) const.
  • A boolean value: This is a special case in which the query was a boolean query
  • (a SPARQL ASK query). In this case there is nothing to iterate but only a single boolean value which can be accessed through boolValue().

    Example:

    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 allBindings = it.allBindings();
    Q_FOREACH( Soprano.BindingSet bs, allBindings ) {
    modifyTheModel( model, bs );
    }
    

    For further details on %Soprano iterators see Iterator.

    Be aware that iterators in Soprano are shared objects which means that copies of one iterator object work on the same data.

    Author Daniele Galdi
    Sebastian Trueg



    methods