Tracker.SparqlCursor

g GObject.Object GObject.Object Tracker.SparqlCursor Tracker.SparqlCursor GObject.Object->Tracker.SparqlCursor

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

close ()

get_boolean (column)

get_connection ()

get_datetime (column)

get_double (column)

get_integer (column)

get_langstring (column)

get_n_columns ()

get_string (column)

get_value_type (column)

get_variable_name (column)

is_bound (column)

next (cancellable)

next_async (cancellable, callback, *user_data)

next_finish (res)

rewind ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

connection

Tracker.SparqlConnection

r/w/co

connection

n-columns

int

r

n-columns

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Tracker.SparqlCursor(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Tracker.SparqlCursorClass

TrackerSparqlCursor provides the methods to iterate the results of a SPARQL query.

Cursors are obtained through e.g. [method`SparqlStatement`.execute] or [method`SparqlConnection`.query] after the SPARQL query has been executed.

When created, a cursor does not point to any element, [method`SparqlCursor`.next] is necessary to iterate one by one to the first (and following) results. When the cursor iterated across all rows in the result set, [method`SparqlCursor`.next] will return False with no error set.

On each row, it is possible to extract the result values through the [method`SparqlCursor`.get_integer], [method`SparqlCursor`.get_string], etc… family of methods. The column index of those functions starts at 0. The number of columns is dependent on the SPARQL query issued, but may be checked at runtime through the [method`SparqlCursor`.get_n_columns] method.

After a cursor is iterated, it is recommended to call [method`SparqlCursor`.close] explicitly to free up resources for other users of the same [class`SparqlConnection`], this is especially important in garbage collected languages. These resources will be also implicitly freed on cursor object finalization.

It is possible to use a given TrackerSparqlCursor in other threads than the one it was created from. It must be however used from just one thread at any given time.

close()

Closes the cursor. The object can only be freed after this call.

get_boolean(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

a boolean value.

Return type:

bool

Retrieve a boolean for the current row in column.

If the row/column do not have a boolean value, the result is undefined, see [method`SparqlCursor`.get_value_type].

get_connection()
Returns:

the cursor [class`SparqlConnection`]. The returned object must not be unreferenced by the caller.

Return type:

Tracker.SparqlConnection

Returns the [class`SparqlConnection`] associated with this TrackerSparqlCursor.

get_datetime(column)
Parameters:

column (int) – Column number to retrieve (first one is 0)

Returns:

[type`GLib`.DateTime] object, or None if the given column does not contain a xsd:date or xsd:dateTime.

Return type:

GLib.DateTime or None

Retrieves a [type`GLib`.DateTime] pointer for the current row in column.

New in version 3.2.

get_double(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

a double value.

Return type:

float

Retrieve a double for the current row in column.

If the row/column do not have a integer or double value, the result is undefined, see [method`SparqlCursor`.get_value_type].

get_integer(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

a 64-bit integer value.

Return type:

int

Retrieve an integer for the current row in column.

If the row/column do not have an integer value, the result is undefined, see [method`SparqlCursor`.get_value_type].

get_langstring(column)
Parameters:

column (int) – column number to retrieve

Returns:

a string which must not be freed. None is returned if the column is not in the [0, n_columns] range, or if the row/column refer to a nullable optional value in the result set.

langtag:

language tag of the returned string, or None if the string has no language tag

length:

length of the returned string

Return type:

(str or None, langtag: str, length: int)

Retrieves a string representation of the data in the current row in column. If the string has language information (i.e. it is a rdf:langString](rdf-ontology.html#rdf:langString)), the language tag will be returned in the location provided through langtag. This language tag will typically be in a format conforming RFC 5646.

New in version 3.7.

get_n_columns()
Returns:

The number of columns returned in the result set.

Return type:

int

Retrieves the number of columns available in the result set.

This method should only be called after a successful [method`SparqlCursor`.next], otherwise its return value will be undefined.

get_string(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

a string which must not be freed. None is returned if the column is not in the [0, n_columns] range, or if the row/column refer to a nullable optional value in the result set.

length:

length of the returned string, or None

Return type:

(str or None, length: int)

Retrieves a string representation of the data in the current row in column.

Any type may be converted to a string. If the value is not bound (See [method`SparqlCursor`.is_bound]) this method will return None.

get_value_type(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

a [enum`SparqlValueType`] expressing the content type of the given column for the current row.

Return type:

Tracker.SparqlValueType

Returns the data type bound to the current row and the given column.

If the column is unbound, the value will be Tracker.SparqlValueType.UNBOUND. See also [method`SparqlCursor`.is_bound].

Values of type #TRACKER_SPARQL_VALUE_TYPE_RESOURCE and Tracker.SparqlValueType.BLANK_NODE can be considered equivalent, the difference is the resource being referenced as a named IRI or a blank node.

All other [enum`SparqlValueType`] value types refer to literal values.

get_variable_name(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

The name of the given column.

Return type:

str or None

Retrieves the name of the given column.

This name will be defined at the SPARQL query, either implicitly from the names of the variables returned in the resultset, or explicitly through the AS ?var SPARQL syntax.

is_bound(column)
Parameters:

column (int) – column number to retrieve (first one is 0)

Returns:

a True or False.

Return type:

bool

Returns whether the given column has a bound value in the current row.

This may not be the case through e.g. the OPTIONAL { } SPARQL syntax.

next(cancellable)
Parameters:

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

Raises:

GLib.Error

Returns:

False if there are no more results or if an error is found, otherwise True.

Return type:

bool

Iterates the cursor to the next result.

If the cursor was not started, it will point to the first result after this call. This operation is completely synchronous and it may block, see [method`SparqlCursor`.next_async] for an asynchronous variant.

next_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 asynchronous operation is finished.

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

Iterates the cursor asyncronously to the next result.

If the cursor was not started, it will point to the first result after this operation completes.

In the period between this call and the corresponding [method`SparqlCursor`.next_finish] call, the other cursor methods should not be used, nor their results trusted. The cursor should only be iterated once at a time.

next_finish(res)
Parameters:

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

Raises:

GLib.Error

Returns:

False if there are no more results or if an error is found, otherwise True.

Return type:

bool

Finishes the asynchronous iteration to the next result started with [method`SparqlCursor`.next_async].

rewind()

Resets the iterator to point back to the first result.

Deprecated since version 3.5: This function only works on cursors from direct [class`SparqlConnection`] objects and cannot work reliably across all cursor types. Issue a different query to obtain a new cursor.

Property Details

Tracker.SparqlCursor.props.connection
Name:

connection

Type:

Tracker.SparqlConnection

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The [class`SparqlConnection`] used to retrieve the results.

Tracker.SparqlCursor.props.n_columns
Name:

n-columns

Type:

int

Default Value:

0

Flags:

READABLE

Number of columns available in the result set.