MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

The QSparqlConnection class provides an interface for accessing an RDF store. More...

Inheritance diagram for QSparqlConnection:
QObject

List of all members.

Public Types

enum   Feature {
  QuerySize, DefaultGraph, AskQueries, ConstructQueries,
  UpdateQueries, SyncExec, AsyncExec
}

Public Member Functions

  QSparqlConnection (QObject *parent=0)
  QSparqlConnection (const QString &type, const QSparqlConnectionOptions &options=QSparqlConnectionOptions(), QObject *parent=0)
  ~QSparqlConnection ()
QSparqlResult exec (const QSparqlQuery &query)
QSparqlResult exec (const QSparqlQuery &query, const QSparqlQueryOptions &options)
QSparqlResult syncExec (const QSparqlQuery &query)
bool  isValid () const
QString  driverName () const
bool  hasFeature (Feature feature) const
void  addPrefix (const QString &prefix, const QUrl &uri)
void  clearPrefixes ()
QUrl  createUrn () const
QSparqlBinding  createUrn (const QString &name) const

Static Public Member Functions

static QStringList  drivers ()

Friends

class  QSparqlConnectionPrivate
class  SparqlConnection

Detailed Description

The QSparqlConnection class provides an interface for accessing an RDF store.

The user is responsible for freeing any QSparqlResult returned by the connection, when they are no longer needed. However, since the QSparqlResult object is a child of the QSparqlConnection, after the QSparqlConnection has been deleted the QSparqlResult is no longer valid (and doesn't need to be freed).

If you change the parent of a returned QSparqlResult, the user will always be responsible for deleting the result, and ensuring the connection is destroyed AFTER the QSparqlResult has been deleted. Deleting the connection before the QSparqlResult in this scenario will invalidate the result, do not do this.

Meego: The security tokens required to work depend on the specific driver:

Required credential:

TrackerReadAccess To run queries via DBus. Mandatory for queries with QTRACKER driver.

TrackerWriteAccess To run any update. Mandatory for updates with QTRACKER or QTRACKER_DIRECT drivers.

GRP::metadata-user Permission to run queries directly on the DB. Mandatory for queries with QTRACKER_DIRECT


Member Enumeration Documentation

This enum contains a list of features a driver might support. Use hasFeature() to query whether a feature is supported or not.

Enumerator:
QuerySize 

The connection is capable of reporting the size of a query. Note that some databases do not support returning the size (i.e. number of rows returned) of a query, in which case QSparqlQuery::size() will return -1.

DefaultGraph 

The store has a default graph which doesn't have to be specified. Some stores, like Virtuoso, don't have a default graph.

AskQueries 

The connection supports ASK queries

ConstructQueries 

The connection supports CONSTRUCT queries

UpdateQueries 

The connection supports INSERT and DELETE queries

SyncExec 

The connection can execute synchronous queries natively. For connections not supporting SyncExec, QSparqlConnection::syncExec() will execute an asynchronous query and wait until it has finished.

AsyncExec 

The connection can execute asynchronous queries natively. For connections not supporting AsyncExec, QSparqlConnection::exec() will create a thread for executing the query synchronously.

See also:
hasFeature()

Constructor & Destructor Documentation

QSparqlConnection::QSparqlConnection ( QObject parent = 0  )  [explicit]

Constructs an invalid QSparqlConnection.

QSparqlConnection::QSparqlConnection ( const QString type,
const QSparqlConnectionOptions options = QSparqlConnectionOptions(),
QObject parent = 0  
)

Constructs a QSparqlConnection of the given type with the given options. The type is a string which identifies the driver. To get a list of available drivers, use drivers(). The accepted connection options depend on the selected driver. The drivers ignore unneeded connection options.

QSparqlConnection::~QSparqlConnection (  ) 

Destroys the QSparqlConnection object and frees up any resources. Note that QSparqlResult objects that are returned from this class have this object set as their parent, which means that they will be deleted along with the connection it if you don't call QObject::setParent() on them.


Member Function Documentation

void QSparqlConnection::addPrefix ( const QString prefix,
const QUrl uri  
)

Adds a prefix/uri pair to the connection. Each SPARQL query made with the connection will have the prefixes prepended to it.

void QSparqlConnection::clearPrefixes (  ) 

Removes any prefix/uri pairs which have been added to the connection.

QUrl QSparqlConnection::createUrn (  )  const

Creates a new Urn based Uri

QSparqlBinding QSparqlConnection::createUrn ( const QString name  )  const

Creates a Urn for use in an insert query. The given name can be used to substitute the value into the query string.

QString QSparqlConnection::driverName (  )  const

Returns the connection's driver name.

QStringList QSparqlConnection::drivers (  )  [static]

Returns the list of available drivers. The list contains driver names which can be passed to QSparqlConnection constructor.

QSparqlResult * QSparqlConnection::exec ( const QSparqlQuery query  ) 

Executes a SPARQL query on the database asynchronously and returns a pointer to a QSparqlResult object.

If query is empty or if the QSparqlConnection is not valid, exec() returns a QSparqlResult which is in the error state. It won't emit the finished() signal.

If this function fails with "connection not open" error, the most probable reason is that the required driver is not installed.

See also:
QSparqlQuery, QSparqlResult, QSparqlResult::hasError
QSparqlResult * QSparqlConnection::exec ( const QSparqlQuery query,
const QSparqlQueryOptions options  
)

Executes a SPARQL query on the database and returns a pointer to a QSparqlResult object. The query execution is controlled by options.

For asynchronous queries the user can connect to the returned QSparqlResult object's dataReady() and finished() signals to get notified as the query execution proceeds.

For synchronous queries the user can call QSparqlResult::next() to retrieve the next row of the result set synchronously.

The user is responsible for freeing the QSparqlResult when it's no longer used (but not after the QSparqlConnection is deleted). The QSparqlResult object is also a child of the QSparqlConnection, so after the QSparqlConnection has been deleted, the QSparqlResult is no longer valid (and doesn't need to be freed).

If you change the parent of a returned result, you must be responsible for deleting the result, and ensuring the connection is destroyed AFTER the QSparqlResult have been deleted. Deleting the connection before the QSparqlResult will invalidate the results, do not do this.

If query is empty or if the this QSparqlConnection is not valid, exec() returns a QSparqlResult which is in the error state. It won't emit the finished() signal for an asynchronous query.

If this function fails with "connection not open" error, the most probable reason is that the required driver is not installed.

See also:
QSparqlQuery, QSparqlResult, QSparqlResult::dataReady, QSparqlResult::finished, QSparqlResult::hasError, QSparqlQueryOptions
bool QSparqlConnection::hasFeature ( Feature  feature  )  const

Returns true if the QSparqlConnection supports feature feature; otherwise returns false.

bool QSparqlConnection::isValid (  )  const

Returns true if the QSparqlConnection has a valid driver, i.e. the name of the driver given in the constructor was valid.

QSparqlResult * QSparqlConnection::syncExec ( const QSparqlQuery query  ) 

Begins the execution of a SPARQL query on the database synchronously and returns a pointer to a QSparqlResult object.

The user can call QSparqlResult::next() to retrieve the next row of the result set synchronously.

If query is empty or if the QSparqlConnection is not valid, syncExec() returns a QSparqlResult which is in the error state.

If this function fails with "connection not open" error, the most probable reason is that the required driver is not installed.

See also:
QSparqlQuery, QSparqlResult, QSparqlResult::hasError

Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
Commercial Qt/LGPL 2.1 with Nokia exception/GPL 3.0
MeeGo 1.2 Harmattan API