[tracker/sparql-update] libtracker-data: REPLACE with multi value properties will work just like INSERT does



commit ee292aafa6850ce93c4743d916f0dad6c940c3f1
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Mar 9 14:08:45 2011 +0100

    libtracker-data: REPLACE with multi value properties will work just like INSERT does

 src/libtracker-data/tracker-data-update.c |   91 +++++++++++++----------------
 1 files changed, 40 insertions(+), 51 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index f95723e..dafb0d3 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, y, param;
+	gint                            i, param;
 	GError                         *actual_error = NULL;
 
 	iface = tracker_db_manager_get_db_interface ();
@@ -773,62 +773,51 @@ tracker_data_resource_buffer_flush (GError **error)
 			for (i = 0; i < table->properties->len; i++) {
 				property = &g_array_index (table->properties, TrackerDataUpdateBufferProperty, i);
 
-				if (table->update_value) {
-
-					g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNSUPPORTED,
-					             "REPLACE used with multi value property `%s'",
-					             property->name);
-
-					return;
-
+				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 {
-					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);
-					}
+					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);
+				}
 
-					if (actual_error) {
-						g_propagate_error (error, actual_error);
-						return;
-					}
+				if (actual_error) {
+					g_propagate_error (error, actual_error);
+					return;
+				}
 
-					param = 0;
+				param = 0;
 
-					tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
-					statement_bind_gvalue (stmt, &param, &property->value);
+				tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
+				statement_bind_gvalue (stmt, &param, &property->value);
 
-					if (property->graph != 0) {
-						tracker_db_statement_bind_int (stmt, param++, property->graph);
-					} else {
-						tracker_db_statement_bind_null (stmt, param++);
-					}
+				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);
+				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;



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