QtSparql  0.2.6
Public Types | Public Member Functions | List of all members
QSparqlQuery Class Reference

The QSparqlQuery class provides a means of executing and manipulating SPARQL statements. More...

Public Types

enum  StatementType {
  SelectStatement, AskStatement, ConstructStatement, DescribeStatement,
  InsertStatement, DeleteStatement
}
 

Public Member Functions

 QSparqlQuery (const QString &query=QString(), StatementType type=SelectStatement)
 
 QSparqlQuery (const QSparqlQuery &other)
 
QSparqlQueryoperator= (const QSparqlQuery &other)
 
 ~QSparqlQuery ()
 
StatementType type () const
 
void setType (StatementType type)
 
QString query () const
 
void setQuery (const QString &query)
 
void bindValue (const QString &placeholder, const QVariant &val)
 
void bindValue (const QSparqlBinding &binding)
 
void bindValues (const QSparqlResultRow &bindings)
 
QVariant boundValue (const QString &placeholder) const
 
QMap< QString, QSparqlBindingboundValues () const
 
void unbindValues ()
 
QString preparedQueryText () const
 

Detailed Description

The QSparqlQuery class provides a means of executing and manipulating SPARQL statements.

QSparqlQuery encapsulates the functionality involved in creating SPARQL queries which are executed on a QSparqlConnection.

It can also be used to execute commands specific to an RDF store which are not standard SPARQL.

To execute the QSparqlQuery, pass it to QSparqlConnection::exec().

QSparqlQuery supports binding of parameter values to placeholders; ?: and $: are used as placeholder markers.

You can retrieve the values of all the fields in a single variable (a map) using boundValues().

Approaches to Binding Values

QSparqlQuery supports replacing placeholders (marked with ?: or $:) with strings.

QSparqlQuery nameQuery("select ?ng ?nf "
"{ ?:contact_uri nco:nameGiven ?ng ; nco:nameFamily ?nf . } ");
nameQuery.bindValue("contact_uri", QUrl(uri));

When replacing strings, the quotes surrounding strings are inserted automatically. Quotes (" and ') inside the strings are escaped.

See also
QSparqlConnection, QSparqlQueryModel, QSparqlResult, QSparqlResultRow, QSparqlBinding, QVariant

Member Enumeration Documentation

◆ StatementType

This enum contains a list of SPARQL statement (or clause) types the driver can create.

Enumerator
SelectStatement 

A SPARQL SELECT statement

AskStatement 

A SPARQL ASK statement

ConstructStatement 

A SPARQL CONSTRUCT statement

DescribeStatement 

A SPARQL DESCRIBE statement

InsertStatement 

A SPARQL INSERT statement

DeleteStatement 

A SPARQL DELETE statement

Constructor & Destructor Documentation

◆ QSparqlQuery() [1/2]

QSparqlQuery::QSparqlQuery ( const QString &  query = QString(),
StatementType  type = SelectStatement 
)
explicit

Constructs a QSparqlQuery object which uses the QSparqlResult result to communicate with a database.

◆ QSparqlQuery() [2/2]

QSparqlQuery::QSparqlQuery ( const QSparqlQuery other)

Constructs a copy of other.

◆ ~QSparqlQuery()

QSparqlQuery::~QSparqlQuery ( )

Destroys the object and frees any allocated resources.

Member Function Documentation

◆ bindValue() [1/2]

void QSparqlQuery::bindValue ( const QSparqlBinding binding)

Set the placeholder binding.name() to be bound to value binding.value() in the query. Note that the placeholder mark (?: or $:) must not be included when specifying the placeholder name.

◆ bindValue() [2/2]

void QSparqlQuery::bindValue ( const QString &  placeholder,
const QVariant &  val 
)

Set the placeholder placeholder to be bound to value val in the query. Note that the placeholder mark (?: or $:) must not be included when specifying the placeholder name.

See also
bindValue(), boundValue() boundValues()

◆ bindValues()

void QSparqlQuery::bindValues ( const QSparqlResultRow bindings)

Iterates through the variable name - value pairs from the bindings and adds them as bindings.

◆ boundValue()

QVariant QSparqlQuery::boundValue ( const QString &  placeholder) const

Returns the value for the placeholder.

See also
boundValues() bindValue()

◆ boundValues()

QMap< QString, QSparqlBinding > QSparqlQuery::boundValues ( ) const

Returns a map of the bound values.

See also
boundValue() bindValue()

◆ operator=()

QSparqlQuery & QSparqlQuery::operator= ( const QSparqlQuery other)

Assigns other to this object.

◆ preparedQueryText()

QString QSparqlQuery::preparedQueryText ( ) const

Replaces the placeholders with the bound values and returns the resulting query.

◆ query()

QString QSparqlQuery::query ( ) const

Returns the query text without replacements.

◆ setQuery()

void QSparqlQuery::setQuery ( const QString &  query)

Sets the query text to query. The bound placeholders are not affected.

◆ setType()

void QSparqlQuery::setType ( StatementType  type)

Sets the statement type to type.

◆ type()

QSparqlQuery::StatementType QSparqlQuery::type ( ) const

Returns the statement type.

◆ unbindValues()

void QSparqlQuery::unbindValues ( )

Clears all bound values.


The documentation for this class was generated from the following files:
QSparqlQuery
The QSparqlQuery class provides a means of executing and manipulating SPARQL statements.
Definition: qsparqlquery.h:65