[tracker/property-changes] libtracker-data: Range change bug fixes
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/property-changes] libtracker-data: Range change bug fixes
- Date: Mon, 5 Apr 2010 12:05:30 +0000 (UTC)
commit 563df202ffbea9041dea545256d3fc6b3dd3b14a
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Apr 5 14:04:36 2010 +0200
libtracker-data: Range change bug fixes
src/libtracker-data/tracker-data-manager.c | 102 +++++++++++++++++++---------
1 files changed, 69 insertions(+), 33 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 062580e..e56ed38 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1283,6 +1283,47 @@ insert_uri_in_resource_table (TrackerDBInterface *iface,
}
static void
+range_change_for (TrackerProperty *property,
+ GString *in_col_sql,
+ GString *sel_col_sql,
+ const gchar *field_name)
+{
+ /* TODO: TYPE_RESOURCE and TYPE_DATETIME are completely unhandled atm, we
+ * should forbid conversion from anything to resource or datetime in error
+ * handling earlier */
+
+ g_string_append_printf (in_col_sql, ", \"%s\", \"%s:graph\"",
+ field_name, field_name);
+
+ if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_INTEGER ||
+ tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DOUBLE) {
+ g_string_append_printf (sel_col_sql, ", \"%s\" + 0, \"%s:graph\"",
+ field_name, field_name);
+ } else if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME) {
+
+ /* TODO (see above) */
+
+ g_string_append_printf (sel_col_sql, ", \"%s\", \"%s:graph\"",
+ field_name, field_name);
+
+ g_string_append_printf (in_col_sql, ", \"%s:localDate\", \"%s:localTime\"",
+ tracker_property_get_name (property),
+ tracker_property_get_name (property));
+
+ g_string_append_printf (sel_col_sql, ", \"%s:localDate\", \"%s:localTime\"",
+ tracker_property_get_name (property),
+ tracker_property_get_name (property));
+
+ } else if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_BOOLEAN) {
+ g_string_append_printf (sel_col_sql, ", \"%s\" != 0, \"%s:graph\"",
+ field_name, field_name);
+ } else {
+ g_string_append_printf (sel_col_sql, ", \"%s\", \"%s:graph\"",
+ field_name, field_name);
+ }
+}
+
+static void
create_decomposed_metadata_property_table (TrackerDBInterface *iface,
TrackerProperty *property,
const gchar *service_name,
@@ -1325,7 +1366,8 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
tracker_property_get_need_recreate (property)))) {
if (transient || tracker_property_get_multiple_values (property)) {
GString *sql;
- GString *col_sql = NULL;
+ GString *in_col_sql = NULL;
+ GString *sel_col_sql = NULL;
GError *error = NULL;
/* multiple values */
@@ -1336,7 +1378,8 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
}
if (in_change && !tracker_property_get_is_new (property)) {
- tracker_db_interface_execute_query (iface, &error, "ALTER TABLE \"%s_%s\" RENAME TO \"%s_%s_TEMP\"",
+ tracker_db_interface_execute_query (iface, &error,
+ "ALTER TABLE \"%s_%s\" RENAME TO \"%s_%s_TEMP\"",
service_name, field_name, service_name, field_name);
if (error) {
g_critical ("Ontology change: Renaming SQL table: %s", error->message);
@@ -1357,9 +1400,10 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
field_name);
if (in_change && !tracker_property_get_is_new (property)) {
- col_sql = g_string_new ("ID");
- g_string_append_printf (col_sql, ", \"%s\", \"%s:graph\"",
- field_name, field_name);
+ in_col_sql = g_string_new ("ID");
+ sel_col_sql = g_string_new ("ID");
+
+ range_change_for (property, in_col_sql, sel_col_sql, field_name);
}
if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME) {
@@ -1370,12 +1414,6 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
", \"%s:localTime\" INTEGER NOT NULL",
tracker_property_get_name (property),
tracker_property_get_name (property));
-
- if (in_change && !tracker_property_get_is_new (property)) {
- g_string_append_printf (col_sql, "\"%s:localDate\", \"%s:localTime\"",
- tracker_property_get_name (property),
- tracker_property_get_name (property));
- }
}
tracker_db_interface_execute_query (iface, &error,
@@ -1400,13 +1438,13 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
g_string_free (sql, TRUE);
- if (in_change && !tracker_property_get_is_new (property) && col_sql) {
+ if (in_change && !tracker_property_get_is_new (property) && in_col_sql && sel_col_sql) {
gchar *query;
query = g_strdup_printf ("INSERT INTO \"%s_%s\"(%s) "
"SELECT %s FROM \"%s_%s_TEMP\"",
- service_name, field_name, col_sql->str,
- col_sql->str, field_name, service_name);
+ service_name, field_name, in_col_sql->str,
+ sel_col_sql->str, service_name, field_name);
tracker_db_interface_execute_query (iface, &error, "%s", query);
@@ -1426,9 +1464,10 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
}
- if (col_sql) {
- g_string_free (col_sql, TRUE);
- }
+ if (sel_col_sql)
+ g_string_free (sel_col_sql, TRUE);
+ if (in_col_sql)
+ g_string_free (in_col_sql, TRUE);
} else if (sql_type_for_single_value) {
*sql_type_for_single_value = sql_type;
@@ -1447,7 +1486,8 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
{
const char *service_name;
GString *create_sql = NULL;
- GString *col_sql = NULL;
+ GString *in_col_sql = NULL;
+ GString *sel_col_sql = NULL;
TrackerProperty **properties, *property;
GSList *class_properties, *field_it;
gboolean main_class;
@@ -1465,7 +1505,8 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
if (in_change) {
tracker_db_interface_execute_query (iface, &error, "ALTER TABLE \"%s\" RENAME TO \"%s_TEMP\"", service_name, service_name);
- col_sql = g_string_new ("ID");
+ in_col_sql = g_string_new ("ID");
+ sel_col_sql = g_string_new ("ID");
if (error) {
g_critical ("Ontology change: Renaming SQL table: %s", error->message);
g_error_free (error);
@@ -1601,15 +1642,8 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
}
if (in_change && put_change) {
- g_string_append_printf (col_sql, ", \"%s\", \"%s:graph\"",
- field_name, field_name);
- if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME) {
- g_string_append_printf (col_sql, ", \"%s:localDate\", \"%s:localTime\"",
- tracker_property_get_name (property),
- tracker_property_get_name (property));
- }
+ range_change_for (property, in_col_sql, sel_col_sql, field_name);
}
-
}
}
}
@@ -1637,14 +1671,14 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
g_slist_free (class_properties);
- if (in_change && col_sql) {
+ if (in_change && sel_col_sql && in_col_sql) {
gchar *query;
GError *error = NULL;
query = g_strdup_printf ("INSERT INTO \"%s\"(%s) "
"SELECT %s FROM \"%s_TEMP\"",
- service_name, col_sql->str,
- col_sql->str, service_name);
+ service_name, in_col_sql->str,
+ sel_col_sql->str, service_name);
tracker_db_interface_execute_query (iface, &error, "%s", query);
if (error) {
@@ -1659,9 +1693,11 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
}
}
- if (col_sql) {
- g_string_free (col_sql, TRUE);
- }
+ if (in_col_sql)
+ g_string_free (in_col_sql, TRUE);
+ if (sel_col_sql)
+ g_string_free (sel_col_sql, TRUE);
+
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]