[tracker/sparql-update-delete-id-passing] libtracker-data: Let delete_statement only accepts IDs for subject



commit 3069a24f0429099e9cce12d896c438f2ba93e8f1
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Mar 23 15:30:28 2011 +0100

    libtracker-data: Let delete_statement only accepts IDs for subject

 src/libtracker-data/libtracker-data.vapi      |    2 +-
 src/libtracker-data/tracker-data-manager.c    |    7 ++++---
 src/libtracker-data/tracker-data-update.c     |    9 ++-------
 src/libtracker-data/tracker-data-update.h     |    3 +--
 src/libtracker-data/tracker-sparql-query.vala |   22 +++++++++++++---------
 5 files changed, 21 insertions(+), 22 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 0137c1f..e4ca7ef 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -171,7 +171,7 @@ namespace Tracker {
 		public GLib.Variant update_sparql_blank (string update) throws Sparql.Error;
 		public void load_turtle_file (GLib.File file) throws Sparql.Error;
 		public void notify_transaction (bool start_timer);
-		public void delete_statement (string? graph, string? subject, int s_id, string predicate, string object) throws Sparql.Error, DateError;
+		public void delete_statement (string? graph, int subject_id, string predicate, string object) throws Sparql.Error, DateError;
 		public void update_statement (string? graph, string subject, string predicate, string object) throws Sparql.Error, DateError;
 		public void insert_statement (string? graph, string subject, string predicate, string object) throws Sparql.Error, DateError;
 		public void insert_statement_with_uri (string? graph, string subject, string predicate, string object) throws Sparql.Error;
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index a0a48a9..73eea1f 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -432,7 +432,8 @@ update_property_value (const gchar      *ontology_path,
 				}
 
 				if (!unsup_onto_err) {
-					tracker_data_delete_statement (NULL, subject, 0, predicate, str, &error);
+					gint subject_id = tracker_data_query_resource_id (subject);
+					tracker_data_delete_statement (NULL, subject_id, predicate, str, &error);
 					if (!error)
 						tracker_data_update_buffer_flush (FALSE, &error);
 				}
@@ -1285,7 +1286,7 @@ check_for_deleted_domain_index (TrackerClass *class)
 			tracker_property_del_domain_index (prop, class);
 			tracker_class_del_domain_index (class, prop);
 
-			tracker_data_delete_statement (NULL, tracker_class_get_uri (class), 0,
+			tracker_data_delete_statement (NULL, tracker_class_get_id (class),
 			                               TRACKER_PREFIX "domainIndex",
 			                               tracker_property_get_uri (prop),
 			                               &error);
@@ -1294,7 +1295,7 @@ check_for_deleted_domain_index (TrackerClass *class)
 				g_critical ("Ontology change, %s", error->message);
 				g_clear_error (&error);
 			} else {
-				tracker_data_update_buffer_flush (FALSE, &error);
+				tracker_data_update_buffer_flush (TRUE, &error);
 				if (error) {
 					g_critical ("Ontology change, %s", error->message);
 					g_clear_error (&error);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 9a1bb03..77a3a19 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2113,23 +2113,18 @@ resource_buffer_switch (const gchar *graph,
 
 void
 tracker_data_delete_statement (const gchar  *graph,
-                               const gchar  *subject,
-                               gint          s_id,
+                               gint          subject_id,
                                const gchar  *predicate,
                                const gchar  *object,
                                GError      **error)
 {
 	TrackerClass       *class;
-	gint                subject_id = 0;
 	gboolean            change = FALSE;
 
-	g_return_if_fail (s_id != 0 || subject != NULL);
 	g_return_if_fail (predicate != NULL);
 	g_return_if_fail (object != NULL);
 	g_return_if_fail (in_transaction);
 
-	subject_id = (s_id != 0) ? s_id : query_resource_id (subject);
-
 	if (subject_id == 0) {
 		/* subject not in database */
 		return;
@@ -2223,7 +2218,7 @@ tracker_data_delete_statement (const gchar  *graph,
 				TrackerStatementDelegate *delegate;
 
 				delegate = g_ptr_array_index (delete_callbacks, n);
-				delegate->callback (graph_id, graph, subject_id, subject,
+				delegate->callback (graph_id, graph, subject_id, NULL,
 				                    pred_id, object_id,
 				                    object,
 				                    resource_buffer->types,
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 9da1a88..0ea6eeb 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -50,8 +50,7 @@ GQuark   tracker_data_error_quark                   (void);
 
 /* Metadata */
 void     tracker_data_delete_statement              (const gchar               *graph,
-                                                     const gchar               *subject,
-                                                     gint                       s_id,
+                                                     gint                       subject_id,
                                                      const gchar               *predicate,
                                                      const gchar               *object,
                                                      GError                   **error);
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index d55fae6..6b4d1a2 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -798,31 +798,35 @@ public class Tracker.Sparql.Query : Object {
 		int s_id = 0;
 
 		if (current () == SparqlTokenType.VAR) {
-			string as_str;
-
 			next ();
-			as_str = var_value_map.lookup (get_last_string ().substring (1));
+			result = var_value_map.lookup (get_last_string ().substring (1));
 
 			if (for_del_sub) {
-				s_id = as_str.to_int ();
-				result = null;
-			} else {
-				result = as_str;
+				s_id = result.to_int ();
 			}
-
 		} else if (current () == SparqlTokenType.IRI_REF) {
 			next ();
 			result = get_last_string (1);
+
+			if (for_del_sub) {
+				s_id = Data.query_resource_id (result);
+			}
 		} else if (current () == SparqlTokenType.PN_PREFIX) {
 			// prefixed name with namespace foo:bar
 			next ();
 			string ns = get_last_string ();
 			expect (SparqlTokenType.COLON);
 			result = resolve_prefixed_name (ns, get_last_string ().substring (1));
+			if (for_del_sub) {
+				s_id = Data.query_resource_id (result);
+			}
 		} else if (current () == SparqlTokenType.COLON) {
 			// prefixed name without namespace :bar
 			next ();
 			result = resolve_prefixed_name ("", get_last_string ().substring (1));
+			if (for_del_sub) {
+				s_id = Data.query_resource_id (result);
+			}
 		} else if (accept (SparqlTokenType.BLANK_NODE)) {
 			// _:foo
 			expect (SparqlTokenType.COLON);
@@ -962,7 +966,7 @@ public class Tracker.Sparql.Query : Object {
 				Data.update_statement (current_graph, current_subject, current_predicate, object);
 			} else if (delete_statements) {
 				// delete triple from database
-				Data.delete_statement (current_graph, current_subject, current_subject_id, current_predicate, object);
+				Data.delete_statement (current_graph, current_subject_id, current_predicate, object);
 			} else {
 				// insert triple into database
 				Data.insert_statement (current_graph, current_subject, current_predicate, object);



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