[tracker/property-changes: 6/6] libtracker-data: Deal with UNIQUE in tracker:indexed ontology change



commit c262e12039db6f5e8fbc096f20a87215694c50a3
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Apr 1 17:07:51 2010 +0200

    libtracker-data: Deal with UNIQUE in tracker:indexed ontology change

 src/libtracker-data/tracker-data-manager.c |   35 ++++++++++++++++++---------
 1 files changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 19281f9..90e796a 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -102,6 +102,11 @@ set_index_for_multi_value_property (TrackerDBInterface *iface,
                                     const gchar *field_name,
                                     gboolean enabled)
 {
+	tracker_db_interface_execute_query (iface, NULL,
+	                                    "DROP INDEX IF EXISTS \"%s_%s_ID_ID\"",
+	                                    service_name,
+	                                    field_name);
+
 	if (enabled) {
 		tracker_db_interface_execute_query (iface, NULL,
 		                                    "CREATE INDEX \"%s_%s_ID\" ON \"%s_%s\" (ID)",
@@ -109,11 +114,25 @@ set_index_for_multi_value_property (TrackerDBInterface *iface,
 		                                    field_name,
 		                                    service_name,
 		                                    field_name);
+		tracker_db_interface_execute_query (iface, NULL,
+		                                    "CREATE UNIQUE INDEX \"%s_%s_ID_ID\" ON \"%s_%s\" (\"%s\", ID)",
+		                                    service_name,
+		                                    field_name,
+		                                    service_name,
+		                                    field_name,
+		                                    field_name);
 	} else {
 		tracker_db_interface_execute_query (iface, NULL,
 		                                    "DROP INDEX IF EXISTS \"%s_%s_ID\"",
 		                                    service_name,
 		                                    field_name);
+		tracker_db_interface_execute_query (iface, NULL,
+		                                    "CREATE UNIQUE INDEX \"%s_%s_ID_ID\" ON \"%s_%s\" (ID, \"%s\")",
+		                                    service_name,
+		                                    field_name,
+		                                    service_name,
+		                                    field_name,
+		                                    field_name);
 	}
 }
 
@@ -1264,26 +1283,18 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
 				}
 			}
 
+			tracker_db_interface_execute_query (iface, NULL,
+			                                    "%s)", sql->str);
+
 			/* multiple values */
 			if (tracker_property_get_indexed (property)) {
 				/* use different UNIQUE index for properties whose
 				 * value should be indexed to minimize index size */
-				tracker_db_interface_execute_query (iface, NULL,
-				                                    "%s, "
-				                                    "UNIQUE (\"%s\", ID))",
-				                                    sql->str,
-				                                    field_name);
-
 				set_index_for_multi_value_property (iface, service_name, field_name, TRUE);
-
 			} else {
+				set_index_for_multi_value_property (iface, service_name, field_name, FALSE);
 				/* we still have to include the property value in
 				 * the unique index for proper constraints */
-				tracker_db_interface_execute_query (iface, NULL,
-				                                    "%s, "
-				                                    "UNIQUE (ID, \"%s\"))",
-				                                    sql->str,
-				                                    field_name);
 			}
 
 			g_string_free (sql, TRUE);



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