Tracker.SparqlStatement

g GObject.Object GObject.Object Tracker.SparqlStatement Tracker.SparqlStatement GObject.Object->Tracker.SparqlStatement

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

bind_boolean (name, value)

bind_datetime (name, value)

bind_double (name, value)

bind_int (name, value)

bind_langstring (name, value, langtag)

bind_string (name, value)

clear_bindings ()

execute (cancellable)

execute_async (cancellable, callback, *user_data)

execute_finish (res)

get_connection ()

get_sparql ()

serialize_async (flags, format, cancellable, callback, *user_data)

serialize_finish (result)

update (cancellable)

update_async (cancellable, callback, *user_data)

update_finish (result)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

connection

Tracker.SparqlConnection

r/w/co

connection

sparql

str

r/w/co

sparql

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Tracker.SparqlStatement(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Tracker.SparqlStatementClass

TrackerSparqlStatement represents a prepared statement for a SPARQL query.

The SPARQL query will be internally compiled into the format that is most optimal to execute the query many times. For connections created through [ctor`Tracker`.SparqlConnection.new] that will be a SQLite compiled statement.

The SPARQL query may contain parameterized variables expressed via the ~ prefix in the SPARQL syntax (e.g. ~var), these may happen anywhere in the SPARQL where a literal or variable would typically happen. These parameterized variables may be mapped to arbitrary values prior to execution. The TrackerSparqlStatement may be reused for future queries with different values.

The argument bindings may be changed through the [method`Tracker`.SparqlStatement.bind_int], [method`Tracker`.SparqlStatement.bind_int], etc… family of functions. Those functions receive a name argument corresponding for the variable name in the SPARQL query (eg. "var" for ~var) and a value to map the variable to.

Once all arguments have a value, the query may be executed through [method`Tracker`.SparqlStatement.execute_async] or [method`Tracker`.SparqlStatement.execute].

It is possible to use any TrackerSparqlStatement from other threads than the one it was created from. However, binding values and executing the statement must only happen from one thread at a time. It is possible to reuse the TrackerSparqlStatement right after [method`Tracker`.SparqlStatement.execute_async] was called, there is no need to wait for [method`Tracker`.SparqlStatement.execute_finish].

In some circumstances, it is possible that the query needs to be recompiled from the SPARQL source. This will happen transparently.

bind_boolean(name, value)
Parameters:
  • name (str) – variable name

  • value (bool) – value

Binds the boolean value to the parameterized variable given by name.

bind_datetime(name, value)
Parameters:

Binds the [type`GLib`.DateTime] value to the parameterized variable given by name.

New in version 3.2.

bind_double(name, value)
Parameters:
  • name (str) – variable name

  • value (float) – value

Binds the double value to the parameterized variable given by name.

bind_int(name, value)
Parameters:
  • name (str) – variable name

  • value (int) – value

Binds the integer value to the parameterized variable given by name.

bind_langstring(name, value, langtag)
Parameters:
  • name (str) – variable name

  • value (str) – value

  • langtag (str) – language tag

Binds the value to the parameterized variable given by name, tagged with the language defined by langtag. The language tag should follow RFC 5646. The parameter will be represented as a rdf:langString.

New in version 3.7.

bind_string(name, value)
Parameters:
  • name (str) – variable name

  • value (str) – value

Binds the string value to the parameterized variable given by name.

clear_bindings()

Clears all bindings.

execute(cancellable)
Parameters:

cancellable (Gio.Cancellable or None) – Optional [type`Gio`.Cancellable]

Raises:

GLib.Error

Returns:

A TrackerSparqlCursor with the query results.

Return type:

Tracker.SparqlCursor

Executes the SELECT or ASK SPARQL query with the currently bound values.

This function also works for DESCRIBE and CONSTRUCT queries that retrieve data from the triple store. These query forms that return RDF data are however more useful together with [method`Tracker`.SparqlStatement.serialize_async].

This function should only be called on TrackerSparqlStatement objects obtained through [method`Tracker`.SparqlConnection.query_statement] or SELECT/CONSTRUCT/DESCRIBE statements loaded through [method`Tracker`.SparqlConnection.load_statement_from_gresource]. An error will be raised if this method is called on a INSERT or DELETE SPARQL query.

execute_async(cancellable, callback, *user_data)
Parameters:
  • cancellable (Gio.Cancellable or None) – Optional [type`Gio`.Cancellable]

  • callback (Gio.AsyncReadyCallback or None) – user-defined [type`Gio`.AsyncReadyCallback] to be called when the asynchronous operation is finished.

  • user_data (object or None) – user-defined data to be passed to callback

Executes asynchronously the SELECT or ASK SPARQL query with the currently bound values.

This function also works for DESCRIBE and CONSTRUCT queries that retrieve data from the triple store. These query forms that return RDF data are however more useful together with [method`Tracker`.SparqlStatement.serialize_async].

This function should only be called on TrackerSparqlStatement objects obtained through [method`Tracker`.SparqlConnection.query_statement] or SELECT/CONSTRUCT/DESCRIBE statements loaded through [method`Tracker`.SparqlConnection.load_statement_from_gresource]. An error will be raised if this method is called on a INSERT or DELETE SPARQL query.

execute_finish(res)
Parameters:

res (Gio.AsyncResult) – a [type`Gio`.AsyncResult] with the result of the operation

Raises:

GLib.Error

Returns:

A TrackerSparqlCursor with the query results.

Return type:

Tracker.SparqlCursor

Finishes the asynchronous operation started through [method`Tracker`.SparqlStatement.execute_async].

get_connection()
Returns:

The SPARQL connection of this statement.

Return type:

Tracker.SparqlConnection

Returns the [class`Tracker`.SparqlConnection] that this statement was created for.

get_sparql()
Returns:

The contained SPARQL query

Return type:

str

Returns the SPARQL string that this prepared statement holds.

serialize_async(flags, format, cancellable, callback, *user_data)
Parameters:

Serializes a DESCRIBE or CONSTRUCT query into the given RDF format.

The query self was created from must be either a DESCRIBE or CONSTRUCT query, an error will be raised otherwise.

This is an asynchronous operation, callback will be invoked when the data is available for reading.

The SPARQL endpoint may not support the specified format, in that case an error will be raised.

The flags argument is reserved for future expansions, currently Tracker.SerializeFlags.NONE must be passed.

New in version 3.3.

serialize_finish(result)
Parameters:

result (Gio.AsyncResult) – a [type`Gio`.AsyncResult] with the result of the operation

Raises:

GLib.Error

Returns:

a [class`Gio`.InputStream] to read RDF content.

Return type:

Gio.InputStream

Finishes the asynchronous operation started through [method`Tracker`.SparqlStatement.serialize_async].

New in version 3.3.

update(cancellable)
Parameters:

cancellable (Gio.Cancellable or None) – Optional [type`Gio`.Cancellable]

Raises:

GLib.Error

Returns:

True if the update finished with no errors, False otherwise

Return type:

bool

Executes the INSERT/DELETE SPARQL query series with the currently bound values.

This function should only be called on TrackerSparqlStatement objects obtained through [method`Tracker`.SparqlConnection.update_statement] or INSERT/DELETE statements loaded through [method`Tracker`.SparqlConnection.load_statement_from_gresource]. An error will be raised if this method is called on SELECT/ASK/DESCRIBE/CONSTRUCT SPARQL queries.

New in version 3.5.

update_async(cancellable, callback, *user_data)
Parameters:
  • cancellable (Gio.Cancellable or None) – Optional [type`Gio`.Cancellable]

  • callback (Gio.AsyncReadyCallback or None) – user-defined [type`Gio`.AsyncReadyCallback] to be called when the asynchronous operation is finished.

  • user_data (object or None) – user-defined data to be passed to callback

Executes asynchronously the INSERT/DELETE SPARQL query series with the currently bound values.

This function should only be called on TrackerSparqlStatement objects obtained through [method`Tracker`.SparqlConnection.update_statement] or INSERT/DELETE statements loaded through [method`Tracker`.SparqlConnection.load_statement_from_gresource]. An error will be raised if this method is called on SELECT/ASK/DESCRIBE/CONSTRUCT SPARQL queries.

New in version 3.5.

update_finish(result)
Parameters:

result (Gio.AsyncResult) – a [type`Gio`.AsyncResult] with the result of the operation

Raises:

GLib.Error

Returns:

True if the update finished with no errors, False otherwise

Return type:

bool

Finishes the asynchronous update started through [method`Tracker`.SparqlStatement.update_async].

New in version 3.5.

Property Details

Tracker.SparqlStatement.props.connection
Name:

connection

Type:

Tracker.SparqlConnection

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The [class`Tracker`.SparqlConnection] the statement was created for.

Tracker.SparqlStatement.props.sparql
Name:

sparql

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

SPARQL query stored in this statement.