Soprano 2.9.4
Soprano::QueryResultIterator Class Reference

An iterator for query results. More...

#include <Soprano/QueryResultIterator>

Inheritance diagram for Soprano::QueryResultIterator:

Public Member Functions

 QueryResultIterator ()
 QueryResultIterator (const QueryResultIterator &)
 QueryResultIterator (QueryResultIteratorBackend *qr)
virtual ~QueryResultIterator ()
QueryResultIteratoroperator= (const QueryResultIterator &)
Statement currentStatement () const
BindingSet currentBindings () const
bool boolValue () const
Node operator[] (int offset) const
Node operator[] (const QString name) 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< BindingSetallBindings ()
StatementIterator iterateStatements () const
NodeIterator iterateBindings (const QString &variableName) const
NodeIterator iterateBindings (int offset) const
StatementIterator iterateStatementsFromBindings (const QString &subjectBindingName, const QString &predicateBindingName, const QString &objectBindingName, const QString &contextBindingName=QString(), const Statement &templateStatement=Statement()) const
Public Member Functions inherited from Soprano::Iterator< BindingSet >
 Iterator ()
virtual ~Iterator ()
Iteratoroperator= (const Iterator &)
void close ()
bool next ()
BindingSet current () const
BindingSet operator* () const
bool isValid () const
QList< BindingSetallElements ()
Public Member Functions inherited from Soprano::Error::ErrorCache
virtual ~ErrorCache ()
virtual Error lastError () const

Additional Inherited Members

Protected Member Functions inherited from Soprano::Iterator< BindingSet >
void setBackend (IteratorBackend< BindingSet > *b)
IteratorBackend< BindingSet > * backend () const
Protected Member Functions inherited from Soprano::Error::ErrorCache
 ErrorCache ()
void clearError () const
void setError (const Error &) const
void setError (const QString &errorMessage, int code=ErrorUnknown) const

Detailed Description

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:

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 ) );
}
An iterator for query results.
Node binding(const QString &name) const
BindingSet currentBindings() const
Statement currentStatement() const

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 );
Q_FOREACH( Soprano::BindingSet bs, allBindings ) {
modifyTheModel( model, bs );
}
Represents one set of bindings in the result of a select query.
Definition bindingset.h:49
QList< BindingSet > allBindings()

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 may result in undefined behaviour and even crashes. An iterator needs to be closed by the same thread that opened it (except if the iterator contains special code to handle such a situation.)

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

For further details on Soprano iterators see Iterator.

Author
Daniele Galdi danie.nosp@m.le.g.nosp@m.aldi@.nosp@m.gmai.nosp@m.l.com
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org

Definition at line 108 of file queryresultiterator.h.

Constructor & Destructor Documentation

◆ QueryResultIterator() [1/3]

Soprano::QueryResultIterator::QueryResultIterator ( )

Creates and empty, invalid iterator.

◆ QueryResultIterator() [2/3]

Soprano::QueryResultIterator::QueryResultIterator ( const QueryResultIterator & )

Copy constructor. Copies of iterators share their data.

◆ QueryResultIterator() [3/3]

Soprano::QueryResultIterator::QueryResultIterator ( QueryResultIteratorBackend * qr)

Create a new QueryResultIterator which uses qr as backend. QueryResultIterator will take ownership of the QueryResultIteratorBackend.

◆ ~QueryResultIterator()

virtual Soprano::QueryResultIterator::~QueryResultIterator ( )
virtual

Destructor.

Member Function Documentation

◆ operator=()

QueryResultIterator & Soprano::QueryResultIterator::operator= ( const QueryResultIterator & )

Copies of iterators share their data.

◆ currentStatement()

Statement Soprano::QueryResultIterator::currentStatement ( ) const

Retrieve the current Statement after a call to next. This method does only make sense for graph queries.

◆ currentBindings()

BindingSet Soprano::QueryResultIterator::currentBindings ( ) const

Convenience method that puts all current bindings into one map. This method does only make sense for tuple queries.

◆ boolValue()

bool Soprano::QueryResultIterator::boolValue ( ) const

This method does only make sense for boolean queries.

Returns
The result of a boolean query (SPARQL ASK).
See also
isBool()

◆ operator[]() [1/2]

Node Soprano::QueryResultIterator::operator[] ( int offset) const

Get the current binding for a variable by index.

Parameters
offsetThe index of the requested variable.

This is equivalent to binding(int) const.

Returns
The binding for the requested variable or and invalid node if offset is out of bounds, i.e. bigger or equal to bindingCount().
Since
2.2

◆ operator[]() [2/2]

Node Soprano::QueryResultIterator::operator[] ( const QString name) const

Get the current binding for a variable.

Parameters
nameThe name of the requested variable.

This is equivalent to binding(const QString&) const.

Returns
The binding for the requested variable or and invalid node if the bindings do not contain the variable.
Since
2.2

◆ binding() [1/2]

Node Soprano::QueryResultIterator::binding ( const QString & name) const

Get the current binding for a variable.

Parameters
nameThe name of the requested variable.

This method does only make sense for tuple queries.

Returns
The binding for the requested variable or and invalid node if the bindings do not contain the variable.

◆ binding() [2/2]

Node Soprano::QueryResultIterator::binding ( int offset) const

Get the current binding for a variable by index.

Parameters
offsetThe index of the requested variable.

This method does only make sense for tuple queries.

Returns
The binding for the requested variable or and invalid node if offset is out of bounds, i.e. bigger or equal to bindingCount().

◆ bindingCount()

int Soprano::QueryResultIterator::bindingCount ( ) const

The number of bindings in this query result.

This method does only make sense for tuple queries.

Returns
The number of bindings.

◆ bindingNames()

QStringList Soprano::QueryResultIterator::bindingNames ( ) const

This method does only make sense for tuple queries.

Returns
The names of the bound variables in this query result.

◆ isGraph()

bool Soprano::QueryResultIterator::isGraph ( ) const

Check if this is a graph result.

Returns
true if this result refers to a graph query, i.e. currentStatement() and iterateStatements() return valid values.

◆ isBinding()

bool Soprano::QueryResultIterator::isBinding ( ) const

Check if this is a tuple result.

Returns
true if this result refers to a tuple query, i.e. currentBindings(), binding(), bindingCount(), bindingNames(), and allBindings() return valid values.

◆ isBool()

bool Soprano::QueryResultIterator::isBool ( ) const

Check if this is a boolean result.

There is no need to call next() for boolean results.

Returns
true if this result refers to a boolean query (SPARQL ASK), i.e. boolValue() returns a valid value.

◆ allBindings()

QList< BindingSet > Soprano::QueryResultIterator::allBindings ( )

Convenience method that collects all binding sets that are left in the iterator.

◆ iterateStatements()

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.

Warning
The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
Returns
A wrapper iterator over the statements in a graph query.

◆ iterateBindings() [1/2]

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.

Parameters
variableNameThe name of the requested variable.
Warning
The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
Returns
A wrapper iterator over one column in a tuple query or an invalid iterator if the result does not contain bindings for variableName.

◆ iterateBindings() [2/2]

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.

Parameters
offsetThe index of the requested variable.
Warning
The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
Returns
A wrapper iterator over one column in a tuple query or an invalid iterator if offset is out of bounds, i.e. bigger or equal to bindingCount().

◆ iterateStatementsFromBindings()

StatementIterator Soprano::QueryResultIterator::iterateStatementsFromBindings ( const QString & subjectBindingName,
const QString & predicateBindingName,
const QString & objectBindingName,
const QString & contextBindingName = QString(),
const Statement & templateStatement = Statement() ) const

Convenience method that creates an iterator over statements constructed from the values of the provided bindings.

The typical usage would be with a query as follows:

model->executeQuery( "select * where { graph ?c { ?s ?p ?o . } }" )
.iterateStatementsFromBindings( "s", "p", "o", "c" );
An iterator that provides a stream of Statements.
Parameters
subjectBindingNameThe name of the binding that will be used to set the subject of the constructed statements.
predicateBindingNameThe name of the binding that will be used to set the predicate of the constructed statements.
objectBindingNameThe name of the binding that will be used to set the object of the constructed statements.
contextBindingNameThe name of the binding that will be used to set the context of the constructed statements.
templateStatementIf any of the provided binding names is empty the corresponding nodes in the resulting statements will be filled by templateStatement.
Warning
The new iterator is just a wrapper around this one. Thus, changing it will also change this one.
Returns
A wrapper iterator over statements constructed from the specified bindings.
Since
2.2

The documentation for this class was generated from the following file: