[tracker/wip/carlosg/serialize-api: 26/36] libtracker-data: Handle annotating value types in cursors
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/serialize-api: 26/36] libtracker-data: Handle annotating value types in cursors
- Date: Fri, 4 Feb 2022 18:24:10 +0000 (UTC)
commit 1259052fd78feefc42e64681ffe5072dda3117e7
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jan 30 13:32:55 2022 +0100
libtracker-data: Handle annotating value types in cursors
These annotations come as extra internal columns held in the cursor
itself, existing after the user-visible columns. Each of the user
visible columns may have an extra column (in the same order) holding
the TrackerPropertyType that applies to that column and row.
If these extra columns do not exist, we ATM still resort to the
traditional ways (static value type, then second guess from SQLite).
src/libtracker-data/tracker-db-interface-sqlite.c | 66 +++++++++++++++++++++++
1 file changed, 66 insertions(+)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index bb1357603..c40e0be77 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -3570,6 +3570,68 @@ tracker_db_cursor_get_boolean (TrackerSparqlCursor *sparql_cursor,
return (g_strcmp0 (tracker_db_cursor_get_string (cursor, column, NULL), "true") == 0);
}
+static gboolean
+tracker_db_cursor_get_annotated_value_type (TrackerDBCursor *cursor,
+ guint column,
+ TrackerSparqlValueType *value_type)
+{
+ TrackerDBInterface *iface;
+ TrackerPropertyType property_type;
+ gboolean is_null;
+
+ if (cursor->n_columns == 0)
+ return FALSE;
+
+ iface = cursor->ref_stmt->db_interface;
+
+ tracker_db_interface_lock (iface);
+
+ /* The value type may be annotated in extra columns, one per
+ * user-visible column.
+ */
+ property_type = sqlite3_column_int64 (cursor->stmt, column + cursor->n_columns);
+ is_null = sqlite3_column_type (cursor->stmt, column) == SQLITE_NULL;
+
+ tracker_db_interface_unlock (iface);
+
+ if (is_null) {
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
+ return TRUE;
+ }
+
+ switch (property_type) {
+ case TRACKER_PROPERTY_TYPE_UNKNOWN:
+ return FALSE;
+ case TRACKER_PROPERTY_TYPE_STRING:
+ case TRACKER_PROPERTY_TYPE_LANGSTRING:
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_STRING;
+ return TRUE;
+ case TRACKER_PROPERTY_TYPE_BOOLEAN:
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_BOOLEAN;
+ return TRUE;
+ case TRACKER_PROPERTY_TYPE_INTEGER:
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_INTEGER;
+ return TRUE;
+ case TRACKER_PROPERTY_TYPE_DOUBLE:
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_DOUBLE;
+ return TRUE;
+ case TRACKER_PROPERTY_TYPE_DATE:
+ case TRACKER_PROPERTY_TYPE_DATETIME:
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_DATETIME;
+ return TRUE;
+ case TRACKER_PROPERTY_TYPE_RESOURCE:
+ if (g_str_has_prefix (tracker_db_cursor_get_string (cursor, column, NULL),
+ "urn:bnode:"))
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_BLANK_NODE;
+ else
+ *value_type = TRACKER_SPARQL_VALUE_TYPE_URI;
+
+ return TRUE;
+ };
+
+ g_assert_not_reached ();
+}
+
TrackerSparqlValueType
tracker_db_cursor_get_value_type (TrackerDBCursor *cursor,
guint column)
@@ -3577,9 +3639,13 @@ tracker_db_cursor_get_value_type (TrackerDBCursor *cursor,
TrackerDBInterface *iface;
gint column_type;
guint n_columns = tracker_db_cursor_get_n_columns (cursor);
+ TrackerSparqlValueType value_type;
g_return_val_if_fail (column < n_columns, TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+ if (tracker_db_cursor_get_annotated_value_type (cursor, column, &value_type))
+ return value_type;
+
iface = cursor->ref_stmt->db_interface;
tracker_db_interface_lock (iface);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]