[tracker/sparql-update] libtracker-data, tracker-store: Support for REPLACE on single values



commit 782a7b4000899bfea88ef5dd7166231543a52e4f
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Mar 9 11:49:35 2011 +0100

    libtracker-data, tracker-store: Support for REPLACE on single values

 src/libtracker-data/tracker-data-update.c |  154 ++++++++++++++++++++---------
 src/tracker-store/tracker-resources.vala  |    4 +-
 2 files changed, 107 insertions(+), 51 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 275db01..f276630 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -762,7 +762,7 @@ tracker_data_resource_buffer_flush (GError **error)
 	TrackerDataUpdateBufferProperty *property;
 	GHashTableIter                  iter;
 	const gchar                    *table_name;
-	gint                            i, param;
+	gint                            i, y, param;
 	GError                         *actual_error = NULL;
 
 	iface = tracker_db_manager_get_db_interface ();
@@ -774,70 +774,124 @@ tracker_data_resource_buffer_flush (GError **error)
 				property = &g_array_index (table->properties, TrackerDataUpdateBufferProperty, i);
 
 				if (table->update_value) {
-					g_critical ("Unimplemented SPARQL Update UPDATE feature called");
 
-					g_set_error_literal (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNSUPPORTED,
-					                     "Unimplemented SPARQL Update UPDATE feature called");
+					g_critical ("Unimplemented feature, SPARQL REPLACE for multi-value");
 
-					continue;
+					return;
 
-				} else if (table->delete_value) {
-					/* delete rows for multiple value properties */
-					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
-					                                              "DELETE FROM \"%s\" WHERE ID = ? AND \"%s\" = ?",
-					                                              table_name,
-					                                              property->name);
-				} else if (property->date_time) {
 					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
-					                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:localDate\", \"%s:localTime\", \"%s:graph\") VALUES (?, ?, ?, ?, ?)",
-					                                              table_name,
-					                                              property->name,
-					                                              property->name,
-					                                              property->name,
-					                                              property->name);
-				} else {
+					                                              "DELETE FROM \"%s\" WHERE ID = ?",
+					                                              table_name);
+
+					tracker_db_statement_execute (stmt, &actual_error);
+					g_object_unref (stmt);
+
+					if (actual_error) {
+						g_propagate_error (error, actual_error);
+						return;
+					}
+
+					statement_bind_gvalue (stmt, &param, &property->value);
+
 					stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
-					                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:graph\") VALUES (?, ?, ?)",
+					                                              "UPDATE \"%s\" SET \"%s\" = ? WHERE ID = ?",
 					                                              table_name,
-					                                              property->name,
 					                                              property->name);
-				}
 
-				if (actual_error) {
-					g_propagate_error (error, actual_error);
-					return;
-				}
+					if (actual_error) {
+						g_propagate_error (error, actual_error);
+						return;
+					}
 
-				param = 0;
+					/* TODO: loop over set */
+					for (y = 0; y < 0; y++) {
+						if (property->date_time) {
+							stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
+							                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:localDate\", \"%s:localTime\", \"%s:graph\") VALUES (?, ?, ?, ?, ?)",
+							                                              table_name,
+							                                              property->name,
+							                                              property->name,
+							                                              property->name,
+							                                              property->name);
+						} else {
+							stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
+							                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:graph\") VALUES (?, ?, ?)",
+							                                              table_name,
+							                                              property->name,
+							                                              property->name);
+						}
 
-				tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
-				statement_bind_gvalue (stmt, &param, &property->value);
+						param = 0;
 
-				if (property->graph != 0) {
-					tracker_db_statement_bind_int (stmt, param++, property->graph);
+						tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
+						/* TODO: add values[i]
+						 statement_bind_gvalue (stmt, &param, &property->values[i]); */
+
+						if (property->graph != 0) {
+							tracker_db_statement_bind_int (stmt, param++, property->graph);
+						} else {
+							tracker_db_statement_bind_null (stmt, param++);
+						}
+
+						tracker_db_statement_execute (stmt, &actual_error);
+						g_object_unref (stmt);
+
+						if (actual_error) {
+							g_propagate_error (error, actual_error);
+							return;
+						}
+					}
 				} else {
-					tracker_db_statement_bind_null (stmt, param++);
-				}
+					if (table->delete_value) {
+						/* delete rows for multiple value properties */
+						stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
+						                                              "DELETE FROM \"%s\" WHERE ID = ? AND \"%s\" = ?",
+						                                              table_name,
+						                                              property->name);
+					} else if (property->date_time) {
+						stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
+						                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:localDate\", \"%s:localTime\", \"%s:graph\") VALUES (?, ?, ?, ?, ?)",
+						                                              table_name,
+						                                              property->name,
+						                                              property->name,
+						                                              property->name,
+						                                              property->name);
+					} else {
+						stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
+						                                              "INSERT OR IGNORE INTO \"%s\" (ID, \"%s\", \"%s:graph\") VALUES (?, ?, ?)",
+						                                              table_name,
+						                                              property->name,
+						                                              property->name);
+					}
 
-				tracker_db_statement_execute (stmt, &actual_error);
-				g_object_unref (stmt);
+					if (actual_error) {
+						g_propagate_error (error, actual_error);
+						return;
+					}
 
-				if (actual_error) {
-					g_propagate_error (error, actual_error);
-					return;
-				}
-			}
-		} else {
-			GString *sql, *values_sql;
+					param = 0;
 
-			if (table->update_value) {
-				g_critical ("Unimplemented SPARQL Update UPDATE feature called");
+					tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
+					statement_bind_gvalue (stmt, &param, &property->value);
 
-				g_set_error_literal (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNSUPPORTED,
-				                     "Unimplemented SPARQL Update UPDATE feature called");
+					if (property->graph != 0) {
+						tracker_db_statement_bind_int (stmt, param++, property->graph);
+					} else {
+						tracker_db_statement_bind_null (stmt, param++);
+					}
+
+					tracker_db_statement_execute (stmt, &actual_error);
+					g_object_unref (stmt);
+
+					if (actual_error) {
+						g_propagate_error (error, actual_error);
+						return;
+					}
+				}
 
-				continue;
 			}
+		} else {
+			GString *sql, *values_sql;
 
 			if (table->delete_row) {
 				/* remove entry from rdf:type table */
@@ -878,6 +932,8 @@ tracker_data_resource_buffer_flush (GError **error)
 				continue;
 			}
 
+			/* table->update_value should also work with this */
+
 			if (table->insert) {
 				sql = g_string_new ("INSERT INTO \"");
 				values_sql = g_string_new ("VALUES (?");
@@ -934,14 +990,14 @@ tracker_data_resource_buffer_flush (GError **error)
 				g_string_append (values_sql, ")");
 
 				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
-					                                      "%s %s", sql->str, values_sql->str);
+				                                              "%s %s", sql->str, values_sql->str);
 				g_string_free (sql, TRUE);
 				g_string_free (values_sql, TRUE);
 			} else {
 				g_string_append (sql, " WHERE ID = ?");
 
 				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
-					                                      "%s", sql->str);
+				                                              "%s", sql->str);
 				g_string_free (sql, TRUE);
 			}
 
diff --git a/src/tracker-store/tracker-resources.vala b/src/tracker-store/tracker-resources.vala
index 3ef3bb4..e23a3c1 100644
--- a/src/tracker-store/tracker-resources.vala
+++ b/src/tracker-store/tracker-resources.vala
@@ -309,13 +309,13 @@ public class Tracker.Resources : Object {
 		}
 	}
 
-	void on_statement_inserted (int graph_id, string? graph, int subject_id, string subject, int pred_id, int object_id, string object, PtrArray rdf_types) {
+	void on_statement_inserted (int graph_id, string? graph, int subject_id, string subject, int pred_id, int object_id, string? object, PtrArray rdf_types) {
 		Tracker.Events.add_insert (graph_id, subject_id, subject, pred_id, object_id, object, rdf_types);
 		Tracker.Writeback.check (graph_id, graph, subject_id, subject, pred_id, object_id, object, rdf_types);
 		check_graph_updated_signal ();
 	}
 
-	void on_statement_deleted (int graph_id, string? graph, int subject_id, string subject, int pred_id, int object_id, string object, PtrArray rdf_types) {
+	void on_statement_deleted (int graph_id, string? graph, int subject_id, string subject, int pred_id, int object_id, string? object, PtrArray rdf_types) {
 		Tracker.Events.add_delete (graph_id, subject_id, subject, pred_id, object_id, object, rdf_types);
 		Tracker.Writeback.check (graph_id, graph, subject_id, subject, pred_id, object_id, object, rdf_types);
 		check_graph_updated_signal ();



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