[tracker/wip/sam/resource] squash! libtracker-sparql: Add TrackerResource class



commit 02b5e328a5bb41d79137095edc3344923be672fa
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Jun 13 17:41:50 2016 +0100

    squash! libtracker-sparql: Add TrackerResource class
    
    Don't generate SPARQL updates that delete all data in the store.
    
    I was presuming that I could do:
    
        DELETE {} WHERE { pattern }
    
    to delete 'pattern', but that seems to delete a lot more stuff. Instead
    you have to repeat the pattern, like:
    
        DELETE { pattern } WHERE { pattern }
    
    This would be nicer if Tracker supported the SPARQL 1.1 'DELETE DATA'
    statement, so we could go:
    
        DELETE DATA { pattern }
    
    but it doesn't right now.

 src/libtracker-sparql/tracker-resource.c |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 5d0e6a7..4cb6281 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -948,19 +948,36 @@ generate_sparql_update (TrackerResource *resource,
 
        g_return_if_fail (tracker_sparql_builder_get_state (builder) == TRACKER_SPARQL_BUILDER_STATE_UPDATE);
 
-       /* First, forget everything you know */
+       /* Delete the existing data. If we don't do this, we may get constraint
+        * violations due to trying to add a second value to a single-valued
+        * property, and we may get old metadata hanging around.
+        *
+        * We have to generate a rather awkward query here, like:
+        *
+        *     DELETE { pattern } WHERE { pattern }
+        *
+        * It would be better if we could use "DELETE DATA { pattern }". This is
+        * allowed in SPARQL update 1.1, but not yet supported by Tracker's store.
+        */
+       data->overwrite_flags = priv->overwrite;
+
        tracker_sparql_builder_delete_open (builder, NULL);
+       if (data->graph_id) {
+               tracker_sparql_builder_graph_open (builder, data->graph_id);
+       }
+       tracker_sparql_builder_subject_iri (builder, priv->identifier);
+       g_hash_table_foreach (priv->properties, generate_sparql_deletes_foreach, data);
+       if (data->graph_id) {
+               tracker_sparql_builder_graph_close (builder);
+       }
        tracker_sparql_builder_delete_close (builder);
+
        tracker_sparql_builder_where_open (builder);
        if (data->graph_id) {
                tracker_sparql_builder_graph_open (builder, data->graph_id);
        }
-
        tracker_sparql_builder_subject_iri (builder, priv->identifier);
-
-       data->overwrite_flags = priv->overwrite;
        g_hash_table_foreach (priv->properties, generate_sparql_deletes_foreach, data);
-
        if (data->graph_id) {
                tracker_sparql_builder_graph_close (builder);
        }


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