[tracker/wip/carlosg/anonymous-nodes: 15/24] libtracker-data: Handle blank node tokens in TrackerSparql




commit 85218384d2afdd3c5bb234cb046b4da1b57ea372
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Sep 25 14:32:05 2021 +0200

    libtracker-data: Handle blank node tokens in TrackerSparql
    
    These are unused yet, but the machinery is now able to resolve
    those to resource ROWIDs.

 src/libtracker-data/tracker-sparql.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 3a3a06c04..a83876ee9 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2042,6 +2042,15 @@ value_init_from_token (TrackerSparql    *sparql,
                        GError          **error)
 {
        GBytes *literal;
+       gint64 bnode_id;
+
+       bnode_id = tracker_token_get_bnode (token);
+
+       if (bnode_id != 0) {
+               g_value_init (value, G_TYPE_INT64);
+               g_value_set_int64 (value, bnode_id);
+               return;
+       }
 
        literal = tracker_token_get_literal (token);
 
@@ -2065,6 +2074,23 @@ value_init_from_token (TrackerSparql    *sparql,
        }
 }
 
+static gint64
+tracker_sparql_get_subject_id (TrackerSparql  *sparql,
+                               GError        **error)
+{
+       const gchar *subject_str;
+       gint64 bnode_id;
+
+       bnode_id = tracker_token_get_bnode (&sparql->current_state->subject);
+       if (bnode_id != 0)
+               return bnode_id;
+
+       subject_str = tracker_token_get_idstring (&sparql->current_state->subject);
+       return tracker_data_update_ensure_resource (tracker_data_manager_get_data (sparql->data_manager),
+                                                   subject_str,
+                                                   error);
+}
+
 static gboolean
 tracker_sparql_apply_quad (TrackerSparql  *sparql,
                            GError        **error)
@@ -2087,7 +2113,7 @@ tracker_sparql_apply_quad (TrackerSparql  *sparql,
            sparql->current_state->type == TRACKER_SPARQL_TYPE_DELETE ||
            sparql->current_state->type == TRACKER_SPARQL_TYPE_UPDATE) {
                TrackerOntologies *ontologies;
-               const gchar *property, *subject_str;
+               const gchar *property;
 
                ontologies = tracker_data_manager_get_ontologies (sparql->data_manager);
                property = tracker_token_get_idstring (&sparql->current_state->predicate);
@@ -2111,10 +2137,7 @@ tracker_sparql_apply_quad (TrackerSparql  *sparql,
                        return FALSE;
                }
 
-               subject_str = tracker_token_get_idstring (&sparql->current_state->subject);
-               subject = tracker_data_update_ensure_resource (tracker_data_manager_get_data 
(sparql->data_manager),
-                                                              subject_str,
-                                                              error);
+               subject = tracker_sparql_get_subject_id (sparql, error);
                if (subject == 0)
                        return FALSE;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]