Tracker.SparqlCursor¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
connection |
||
r |
n-columns |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Tracker.SparqlCursor(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
- Return type:
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
orNone
) – Optional [type`Gio`.Cancellable]- Raises:
- Returns:
False
if there are no more results or if an error is found, otherwiseTrue
.- Return type:
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
orNone
) – Optional [type`Gio`.Cancellable]callback (
Gio.AsyncReadyCallback
orNone
) – user-defined [type`Gio`.AsyncReadyCallback] to be called when asynchronous operation is finished.user_data (
object
orNone
) – 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:
- Returns:
False
if there are no more results or if an error is found, otherwiseTrue
.- Return type:
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:
- Default Value:
- Flags:
The [class`SparqlConnection`] used to retrieve the results.