tracker r1603 - in branches/indexer-split: . src/libtracker-common src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1603 - in branches/indexer-split: . src/libtracker-common src/trackerd
- Date: Mon, 9 Jun 2008 09:55:17 +0000 (UTC)
Author: mr
Date: Mon Jun 9 09:55:17 2008
New Revision: 1603
URL: http://svn.gnome.org/viewvc/tracker?rev=1603&view=rev
Log:
* src/libtracker-common/tracker-utils.h:
* src/trackerd/Makefile.am:
* src/trackerd/tracker-db-email.c:
* src/trackerd/tracker-db-sqlite.[ch]:
* src/trackerd/tracker-db.[ch]:
* src/trackerd/tracker-dbus.c:
* src/trackerd/tracker-email-utils.h:
* src/trackerd/tracker-files.c:
* src/trackerd/tracker-keywords.c:
* src/trackerd/tracker-metadata.c:
* src/trackerd/tracker-process-files.c:
* src/trackerd/tracker-rdf-query.c:
* src/trackerd/tracker-search.c:
* src/trackerd/tracker-xesam-live-search.c:
* src/trackerd/tracker-xesam-query.c:
* src/trackerd/tracker-xesam.h: Removed tracker-db-sqlite.[ch] and
merged it with tracker-db.[ch].
Removed:
branches/indexer-split/src/trackerd/tracker-db-sqlite.c
branches/indexer-split/src/trackerd/tracker-db-sqlite.h
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/libtracker-common/tracker-utils.h
branches/indexer-split/src/trackerd/Makefile.am
branches/indexer-split/src/trackerd/tracker-db-email.c
branches/indexer-split/src/trackerd/tracker-db.c
branches/indexer-split/src/trackerd/tracker-db.h
branches/indexer-split/src/trackerd/tracker-dbus.c
branches/indexer-split/src/trackerd/tracker-email-utils.h
branches/indexer-split/src/trackerd/tracker-files.c
branches/indexer-split/src/trackerd/tracker-keywords.c
branches/indexer-split/src/trackerd/tracker-metadata.c
branches/indexer-split/src/trackerd/tracker-process-files.c
branches/indexer-split/src/trackerd/tracker-rdf-query.c
branches/indexer-split/src/trackerd/tracker-search.c
branches/indexer-split/src/trackerd/tracker-xesam-live-search.c
branches/indexer-split/src/trackerd/tracker-xesam-query.c
branches/indexer-split/src/trackerd/tracker-xesam.h
Modified: branches/indexer-split/src/libtracker-common/tracker-utils.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-utils.h (original)
+++ branches/indexer-split/src/libtracker-common/tracker-utils.h Mon Jun 9 09:55:17 2008
@@ -22,6 +22,8 @@
#ifndef __LIBTRACKER_COMMON_UTILS_H__
#define __LIBTRACKER_COMMON_UTILS_H__
+#include <glib.h>
+
gboolean tracker_is_empty_string (const char *str);
gchar * tracker_string_replace (const gchar *haystack,
gchar *needle,
Modified: branches/indexer-split/src/trackerd/Makefile.am
==============================================================================
--- branches/indexer-split/src/trackerd/Makefile.am (original)
+++ branches/indexer-split/src/trackerd/Makefile.am Mon Jun 9 09:55:17 2008
@@ -78,8 +78,6 @@
tracker-db.h \
tracker-db-email.c \
tracker-db-email.h \
- tracker-db-sqlite.c \
- tracker-db-sqlite.h \
tracker-dbus.c \
tracker-dbus.h \
tracker-email.c \
Modified: branches/indexer-split/src/trackerd/tracker-db-email.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db-email.c (original)
+++ branches/indexer-split/src/trackerd/tracker-db-email.c Mon Jun 9 09:55:17 2008
@@ -410,7 +410,7 @@
iface = tracker_db_manager_get_db_interface (TRACKER_DB_EMAIL_METADATA);
- return tracker_db_is_file_up_to_date (iface, uri, id);
+ return tracker_db_file_is_up_to_date (iface, uri, id);
}
@@ -744,7 +744,7 @@
g_return_val_if_fail (iface, FALSE);
g_return_val_if_fail (uri, FALSE);
- return tracker_db_get_file_id (iface, uri) != 0 ;
+ return tracker_db_file_get_id (iface, uri) != 0 ;
}
@@ -774,10 +774,12 @@
gboolean
tracker_db_email_delete_email (TrackerDBInterface *iface, const gchar *uri)
{
+ gchar *id;
+
g_return_val_if_fail (iface, FALSE);
g_return_val_if_fail (uri, FALSE);
- gchar *id = tracker_db_get_id (iface, "Emails", uri);
+ id = tracker_db_file_get_id_as_string (iface, "Emails", uri);
if (!id) {
return FALSE;
Modified: branches/indexer-split/src/trackerd/tracker-db.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.c (original)
+++ branches/indexer-split/src/trackerd/tracker-db.c Mon Jun 9 09:55:17 2008
@@ -3,6 +3,7 @@
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
* Copyright (C) 2007, Jason Kivlighn (jkivlighn gmail com)
* Copyright (C) 2007, Creative Commons (http://creativecommons.org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -22,192 +23,589 @@
#include "config.h"
-#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-os-dependant.h>
+#include <string.h>
+#include <fcntl.h>
+#include <zlib.h>
+
+#include <glib/gstdio.h>
+
+#include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-nfs-lock.h>
+#include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-utils.h>
+
+#include <libtracker-db/tracker-db-interface-sqlite.h>
+#include <libtracker-db/tracker-db-manager.h>
#include "tracker-db.h"
#include "tracker-process-files.h"
+#include "tracker-query-tree.h"
+#include "tracker-watcher.h"
+#include "tracker-xesam-manager.h"
+
+#define ZLIBBUFSIZ 8192
+
+extern Tracker *tracker;
+
+static gchar *
+compress_string (const gchar *ptr,
+ gint size,
+ gint *compressed_size)
+{
+ z_stream zs;
+ gchar *buf, *swap;
+ unsigned char obuf[ZLIBBUFSIZ];
+ gint rv, asiz, bsiz, osiz;
-gboolean
-tracker_db_is_file_up_to_date (TrackerDBInterface *iface,
- const gchar *uri,
- guint32 * id)
+ if (size < 0) {
+ size = strlen (ptr);
+ }
+
+ zs.zalloc = Z_NULL;
+ zs.zfree = Z_NULL;
+ zs.opaque = Z_NULL;
+
+ if (deflateInit2 (&zs, 6, Z_DEFLATED, 15, 6, Z_DEFAULT_STRATEGY) != Z_OK) {
+ return NULL;
+ }
+
+ asiz = size + 16;
+
+ if (asiz < ZLIBBUFSIZ) {
+ asiz = ZLIBBUFSIZ;
+ }
+
+ if (!(buf = malloc (asiz))) {
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ bsiz = 0;
+ zs.next_in = (unsigned char *)ptr;
+ zs.avail_in = size;
+ zs.next_out = obuf;
+ zs.avail_out = ZLIBBUFSIZ;
+
+ while ((rv = deflate (&zs, Z_FINISH)) == Z_OK) {
+ osiz = ZLIBBUFSIZ - zs.avail_out;
+
+ if (bsiz + osiz > asiz) {
+ asiz = asiz * 2 + osiz;
+
+ if (!(swap = realloc (buf, asiz))) {
+ free (buf);
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ buf = swap;
+ }
+
+ memcpy (buf + bsiz, obuf, osiz);
+ bsiz += osiz;
+ zs.next_out = obuf;
+ zs.avail_out = ZLIBBUFSIZ;
+ }
+
+ if (rv != Z_STREAM_END) {
+ free (buf);
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ osiz = ZLIBBUFSIZ - zs.avail_out;
+
+ if (bsiz + osiz + 1 > asiz) {
+ asiz = asiz * 2 + osiz;
+
+ if (!(swap = realloc (buf, asiz))) {
+ free (buf);
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ buf = swap;
+ }
+
+ memcpy (buf + bsiz, obuf, osiz);
+ bsiz += osiz;
+ buf[bsiz] = '\0';
+
+ *compressed_size = bsiz;
+
+ deflateEnd (&zs);
+
+ return buf;
+}
+
+static gboolean
+db_exec_proc_no_reply (TrackerDBInterface *iface,
+ const gchar *procedure,
+ ...)
{
TrackerDBResultSet *result_set;
- gchar *path, *name;
- gint32 index_time;
+ va_list args;
g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), FALSE);
- g_return_val_if_fail (uri != NULL, FALSE);
- g_return_val_if_fail (id != NULL, FALSE);
+ g_return_val_if_fail (procedure != NULL, FALSE);
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_file_get_vfs_name (uri);
- path = tracker_file_get_vfs_path (uri);
+ va_start (args, procedure);
+ result_set = tracker_db_interface_execute_vprocedure (iface,
+ NULL,
+ procedure,
+ args);
+ va_end (args);
+
+ if (result_set) {
+ g_object_unref (result_set);
}
- result_set = tracker_db_exec_proc (iface,
- "GetServiceID",
- path,
- name,
- NULL);
+ return TRUE;
+}
- g_free (path);
- g_free (name);
+static void
+db_save_full_text (TrackerDBInterface *iface,
+ const gchar *str_file_id,
+ const gchar *text,
+ gint length)
+{
+ gchar *compressed, *value = NULL;
+ gint bytes_compressed;
+ const gchar *field_id;
+
+ compressed = compress_string (text, length, &bytes_compressed);
+
+ if (compressed) {
+ g_debug ("Compressed full text size of %d to %d",
+ length, bytes_compressed);
+ value = compressed;
+ } else {
+ g_warning ("Could not compress text'%*s...', length:%d",
+ 16, text, length);
+ value = g_strdup (text);
+ bytes_compressed = length;
+ }
- index_time = 0;
- *id = 0;
+ field_id = tracker_ontology_get_field_id ("File:Contents");
- if (result_set) {
- tracker_db_result_set_get (result_set,
- 0, id,
- 1, &index_time,
- -1);
+ if (!field_id) {
+ g_warning ("Metadata not found for type:'File:Contents'");
+ g_free (value);
+ return;
+ }
- g_object_unref (result_set);
- } else {
- return FALSE;
+ tracker_db_interface_execute_procedure_len (iface,
+ NULL,
+ "SaveServiceContents",
+ str_file_id,
+ -1,
+ field_id,
+ -1,
+ value,
+ bytes_compressed,
+ NULL);
+ g_free (value);
+}
+
+static void
+update_metadata_index (const gchar *id,
+ const gchar *service,
+ TrackerField *def,
+ const gchar *old_value,
+ const gchar *new_value)
+{
+ GHashTable *old_table;
+ GHashTable *new_table;
+ gint sid;
+
+ g_return_if_fail (TRACKER_IS_FIELD (def));
+
+ old_table = NULL;
+ new_table = NULL;
+
+ if (old_value) {
+ old_table = tracker_parser_text (old_table,
+ old_value,
+ tracker_field_get_weight (def),
+ tracker->language,
+ tracker_config_get_max_words_to_index (tracker->config),
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
}
- if (index_time < tracker_file_get_mtime (uri)) {
- return FALSE;
+ /* Parse new metadata value */
+ if (new_value) {
+ new_table = tracker_parser_text (new_table,
+ new_value,
+ tracker_field_get_weight (def),
+ tracker->language,
+ tracker_config_get_max_words_to_index (tracker->config),
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
}
- return TRUE;
+ /* We only do differential updates so only changed words scores are updated */
+ sid = tracker_ontology_get_id_for_service_type (service);
+#if 0
+ tracker_db_update_differential_index (old_table, new_table, id, sid);
+#endif
+
+ tracker_parser_text_free (old_table);
+ tracker_parser_text_free (new_table);
}
-guint32
-tracker_db_get_file_id (TrackerDBInterface *iface,
- const gchar *uri)
+static gchar *
+format_date (const gchar *avalue)
{
- TrackerDBResultSet *result_set;
- gchar *path, *name;
- guint32 id;
+ gchar *dvalue;
- g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), 0);
- g_return_val_if_fail (uri != NULL, 0);
+ dvalue = tracker_date_format (avalue);
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_file_get_vfs_name (uri);
- path = tracker_file_get_vfs_path (uri);
+ if (dvalue) {
+ time_t time;
+
+ time = tracker_string_to_date (dvalue);
+ g_free (dvalue);
+
+ if (time != -1) {
+ return tracker_int_to_string (time);
+ }
}
- result_set = tracker_db_exec_proc (iface,
- "GetServiceID",
- path,
- name,
- NULL);
+ return NULL;
+}
- g_free (path);
- g_free (name);
+static gchar *
+get_backup_id (TrackerDBInterface *iface,
+ const gchar *id)
+{
+ TrackerDBResultSet *result_set;
+ gchar *backup_id = NULL;
- id = 0;
+ result_set = tracker_db_exec_proc (iface,
+ "GetBackupServiceByID",
+ id,
+ NULL);
if (result_set) {
- tracker_db_result_set_get (result_set, 0, &id, -1);
+ tracker_db_result_set_get (result_set, 0, &backup_id, -1);
g_object_unref (result_set);
}
- return id;
+ if (!backup_id) {
+ gint64 id;
+
+ tracker_db_exec_proc (iface,
+ "InsertBackupService",
+ id,
+ NULL);
+ id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (iface));
+ backup_id = tracker_int_to_string (id);
+ }
+
+ return backup_id;
}
-TrackerDBFileInfo *
-tracker_db_get_file_info (TrackerDBInterface *iface,
- TrackerDBFileInfo *info)
+static inline void
+backup_non_embedded_metadata (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key_id,
+ const gchar *value)
{
- TrackerDBResultSet *result_set;
- gchar *path, *name;
+ gchar *backup_id;
+
+ backup_id = get_backup_id (iface, id);
+
+ if (backup_id) {
+ tracker_db_exec_proc (tracker_db_manager_get_db_interface (TRACKER_DB_COMMON),
+ "SetBackupMetadata",
+ backup_id,
+ key_id,
+ value,
+ NULL);
+ g_free (backup_id);
+ }
+}
- g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), info);
- g_return_val_if_fail (info != NULL, info);
+static inline void
+backup_delete_non_embedded_metadata_value (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key_id,
+ const gchar *value)
+{
+ gchar *backup_id;
- if (!tracker_db_file_info_is_valid (info)) {
+ backup_id = get_backup_id (iface, id);
+
+ if (backup_id) {
+ tracker_db_exec_proc (tracker_db_manager_get_db_interface (TRACKER_DB_COMMON),
+ "DeleteBackupMetadataValue",
+ backup_id,
+ key_id,
+ value,
+ NULL);
+ g_free (backup_id);
+ }
+}
+
+static inline void
+backup_delete_non_embedded_metadata (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key_id)
+{
+ gchar *backup_id;
+
+ backup_id = get_backup_id (iface, id);
+
+ if (backup_id) {
+ tracker_db_exec_proc (tracker_db_manager_get_db_interface (TRACKER_DB_COMMON),
+ "DeleteBackupMetadata",
+ backup_id,
+ key_id,
+ NULL);
+ g_free (backup_id);
+ }
+}
+
+static gchar *
+remove_value (const gchar *str,
+ const gchar *del_str)
+{
+ GString *s = NULL;
+ gchar **p;
+ gchar **strv;
+
+ strv = g_strsplit (str, "|", -1);
+
+ for (p = strv; *p; p++) {
+ if (tracker_is_empty_string (*p)) {
+ continue;
+ }
+
+ if (strcmp (del_str, *p) != 0) {
+ if (!s) {
+ s = g_string_new (*p);
+ } else {
+ g_string_append_printf (s, "%s%s", "|", *p);
+ }
+ }
+ }
+
+ g_strfreev (strv);
+
+ if (!s) {
return NULL;
}
- name = g_path_get_basename (info->uri);
- path = g_path_get_dirname (info->uri);
+ return g_string_free (s, FALSE);
+}
+
+/* Deprecated */
+static guint32
+db_create_event (TrackerDBInterface *iface,
+ const gchar *service_id_str,
+ const gchar *type)
+{
+ TrackerDBResultSet *result_set;
+ gchar *eid;
+ gint i;
+ guint32 id = 0;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), 0);
result_set = tracker_db_exec_proc (iface,
- "GetServiceID",
- path,
- name,
+ "GetNewEventID",
NULL);
- g_free (name);
- g_free (path);
+ if (!result_set) {
+ g_critical ("Could not create event, GetNewEventID failed");
+ return 0;
+ }
- if (result_set) {
- gint id, indextime, service_type_id;
- gboolean is_directory;
+ tracker_db_result_set_get (result_set, 0, &eid, -1);
+ i = atoi (eid);
+ g_free (eid);
- tracker_db_result_set_get (result_set,
- 0, &id,
- 1, &indextime,
- 2, &is_directory,
- 3, &service_type_id,
- -1);
+ i++;
+ eid = tracker_int_to_string (i);
- if (id > 0) {
- info->file_id = id;
- info->is_new = FALSE;
- }
+ result_set = tracker_db_exec_proc (iface,
+ "UpdateNewEventID",
+ eid,
+ NULL);
+ if (result_set)
+ g_object_unref (result_set);
- info->indextime = indextime;
- info->is_directory = is_directory;
- info->service_type_id = service_type_id;
+ /* Uses the Events table */
+ result_set = tracker_db_exec_proc (iface,
+ "CreateEvent",
+ eid,
+ service_id_str,
+ type,
+ NULL);
+
+ id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (iface));
+ if (result_set) {
g_object_unref (result_set);
}
- return info;
+ g_free (eid);
+
+ tracker_xesam_manager_wakeup (NULL);
+
+ return id;
}
-gchar **
-tracker_db_get_files_in_folder (TrackerDBInterface *iface,
- const gchar *uri)
+static void
+delete_index_for_service (TrackerDBInterface *iface,
+ guint32 id)
{
- TrackerDBResultSet *result_set;
- GPtrArray *array;
+ gchar *str_file_id;
- g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
- g_return_val_if_fail (uri != NULL, NULL);
+ str_file_id = tracker_uint_to_string (id);
+
+ tracker_db_exec_proc (tracker_db_manager_get_db_interface_content (iface),
+ "DeleteAllContents",
+ str_file_id,
+ NULL);
+
+ g_free (str_file_id);
+}
+
+static void
+dec_stat (gint id)
+{
+ TrackerDBInterface *iface;
+ gchar *service;
+ gchar *parent;
+
+ service = tracker_ontology_get_service_type_by_id (id);
+
+ if (!service) {
+ return;
+ }
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+ tracker_db_exec_proc (iface, "DecStat", service, NULL);
+
+ parent = tracker_ontology_get_parent_service (service);
+
+ if (parent) {
+ tracker_db_exec_proc (iface, "DecStat", parent, NULL);
+ g_free (parent);
+ }
+
+ g_free (service);
+}
+
+/* Update all non-dirs in a dir for a file move */
+static void
+directory_move_files (TrackerDBInterface *iface,
+ const gchar *moved_from_uri,
+ const gchar *moved_to_uri)
+{
+ TrackerDBResultSet *result_set;
+
+ /* Get all sub files (excluding folders) that were moved and add watches */
result_set = tracker_db_exec_proc (iface,
- "SelectFileChild",
- uri,
+ "SelectFileChildWithoutDirs",
+ moved_from_uri,
NULL);
- array = g_ptr_array_new ();
if (result_set) {
- gchar *name, *prefix;
+ gchar *prefix;
+ gchar *name;
+ gchar *file_name;
+ gchar *moved_file_name;
gboolean valid = TRUE;
while (valid) {
tracker_db_result_set_get (result_set,
- 1, &prefix,
- 2, &name,
+ 0, &prefix,
+ 1, &name,
-1);
- g_ptr_array_add (array, g_build_filename (prefix, name, NULL));
+ if (prefix && name) {
+ file_name = g_build_filename (prefix, name, NULL);
+ moved_file_name = g_build_filename (moved_to_uri, name, NULL);
+
+ tracker_db_file_move (iface, file_name, moved_file_name);
+
+ g_free (moved_file_name);
+ g_free (file_name);
+ g_free (prefix);
+ g_free (name);
+ }
- g_free (prefix);
- g_free (name);
valid = tracker_db_result_set_iter_next (result_set);
}
g_object_unref (result_set);
}
+}
+
+static inline void
+directory_move (TrackerDBInterface *iface,
+ const gchar *moved_from_uri,
+ const gchar *moved_to_uri)
+{
+ /* Stop watching old dir, start watching new dir */
+ tracker_watcher_remove_dir (moved_from_uri, TRUE, iface);
+
+ tracker_db_file_move (iface, moved_from_uri, moved_to_uri);
+ directory_move_files (iface, moved_from_uri, moved_to_uri);
+
+ tracker_watcher_add_dir (moved_to_uri, iface);
+}
+
+static gint
+get_memory_usage (void)
+{
+#if defined(__linux__)
+ gint fd, length, mem = 0;
+ gchar buffer[8192];
+ gchar *stat_file;
+ gchar **terms;
+
+ stat_file = g_strdup_printf ("/proc/%d/stat", tracker->pid);
+ fd = g_open (stat_file, O_RDONLY);
+ g_free (stat_file);
+
+ if (fd ==-1) {
+ return 0;
+ }
+
+ length = read (fd, buffer, 8192);
+ buffer[length] = 0;
+ close (fd);
+
+ terms = g_strsplit (buffer, " ", -1);
+
+ if (terms) {
+ gint i;
+
+ for (i = 0; i < 24; i++) {
+ if (!terms[i]) {
+ break;
+ }
+
+ if (i == 23) {
+ mem = 4 * atoi (terms[23]);
+ }
+ }
+ }
- g_ptr_array_add (array, NULL);
+ g_strfreev (terms);
- return (gchar**) g_ptr_array_free (array, FALSE);
+ return mem;
+#endif
+ return 0;
}
void
@@ -221,3 +619,2851 @@
{
/* Nothing to do? */
}
+
+void
+tracker_db_close (TrackerDBInterface *iface)
+{
+ if (iface) {
+ g_object_unref (iface);
+ }
+
+ g_message ("Closed database");
+}
+
+void
+tracker_db_refresh_all (TrackerDBInterface *iface)
+{
+#if 0
+ gboolean cache_trans = FALSE;
+ DBConnection *cache = db_con->cache;
+ DBConnection *emails = db_con->emails;
+
+ if (cache && tracker_db_interface_end_transaction (cache->db)) {
+ cache_trans = TRUE;
+ }
+
+ /* close and reopen all databases */
+ tracker_db_close (db_con->db);
+ tracker_db_close (db_con->blob->db);
+
+ tracker_db_close (emails->blob->db);
+ tracker_db_close (emails->common->db);
+ tracker_db_close (emails->db);
+
+ db_con->db = open_db_interface (TRACKER_DB_FILE_METADATA);
+
+ emails->common->db = open_db_interface (TRACKER_DB_COMMON);
+
+ open_email_db (emails);
+
+ if (cache_trans) {
+ tracker_db_interface_start_transaction (cache->db);
+ }
+
+#endif
+}
+
+gboolean
+tracker_db_exec_no_reply (TrackerDBInterface *iface,
+ const gchar *query,
+ ...)
+{
+ TrackerDBResultSet *result_set;
+ va_list args;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), FALSE);
+ g_return_val_if_fail (query != NULL, FALSE);
+
+ tracker_nfs_lock_obtain ();
+
+ va_start (args, query);
+ result_set = tracker_db_interface_execute_vquery (iface, NULL, query, args);
+ va_end (args);
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+
+ tracker_nfs_lock_release ();
+
+ return TRUE;
+}
+
+TrackerDBResultSet *
+tracker_db_exec (TrackerDBInterface *iface,
+ const gchar *query,
+ ...)
+{
+ TrackerDBResultSet *result_set;
+ va_list args;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (query != NULL, NULL);
+
+ tracker_nfs_lock_obtain ();
+
+ va_start (args, query);
+ result_set = tracker_db_interface_execute_vquery (iface,
+ NULL,
+ query,
+ args);
+ va_end (args);
+
+ tracker_nfs_lock_release ();
+
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_exec_proc (TrackerDBInterface *iface,
+ const gchar *procedure,
+ ...)
+{
+ TrackerDBResultSet *result_set;
+ va_list args;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (procedure != NULL, NULL);
+
+ va_start (args, procedure);
+ result_set = tracker_db_interface_execute_vprocedure (iface,
+ NULL,
+ procedure,
+ args);
+ va_end (args);
+
+ return result_set;
+}
+
+gchar *
+tracker_db_get_field_name (const gchar *service,
+ const gchar *meta_name)
+{
+ gint key_field;
+
+ /* Replace with tracker_ontology_get_field_column_in_services */
+ key_field = tracker_ontology_metadata_key_in_service (service, meta_name);
+
+ if (key_field > 0) {
+ return g_strdup_printf ("KeyMetadata%d", key_field);
+ }
+
+ if (strcasecmp (meta_name, "File:Path") == 0) return g_strdup ("Path");
+ if (strcasecmp (meta_name, "File:Name") == 0) return g_strdup ("Name");
+ if (strcasecmp (meta_name, "File:Mime") == 0) return g_strdup ("Mime");
+ if (strcasecmp (meta_name, "File:Size") == 0) return g_strdup ("Size");
+ if (strcasecmp (meta_name, "File:Rank") == 0) return g_strdup ("Rank");
+ if (strcasecmp (meta_name, "File:Modified") == 0) return g_strdup ("IndexTime");
+
+ return NULL;
+}
+
+TrackerDBResultSet *
+tracker_db_search_text (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *search_string,
+ gint offset,
+ gint limit,
+ gboolean save_results,
+ gboolean detailed)
+{
+ TrackerQueryTree *tree;
+ TrackerDBResultSet *result_set, *result;
+ gchar **array;
+ GArray *hits;
+ gint count;
+ gboolean detailed_emails = FALSE, detailed_apps = FALSE;
+ gint service_array[255];
+ const gchar *procedure;
+ GArray *services = NULL;
+ GSList *duds = NULL;
+ guint i = 0;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
+ g_return_val_if_fail (search_string != NULL, NULL);
+ g_return_val_if_fail (offset < 0, NULL);
+
+ array = tracker_parser_text_into_array (search_string,
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config));
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetRelatedServiceIDs",
+ service,
+ service,
+ NULL);
+
+ if (result_set) {
+ gboolean valid = TRUE;
+ gint type_id;
+
+ while (valid) {
+ tracker_db_result_set_get (result_set, 0, &type_id, -1);
+ service_array[i] = type_id;
+ i++;
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ service_array[i] = 0;
+ services = g_array_new (TRUE, TRUE, sizeof (gint));
+ g_array_append_vals (services, service_array, i);
+ g_object_unref (result_set);
+ }
+
+ tree = tracker_query_tree_new (search_string,
+ tracker->file_index,
+ tracker->config,
+ tracker->language,
+ services);
+ hits = tracker_query_tree_get_hits (tree, offset, limit);
+ result = NULL;
+
+ if (save_results) {
+ tracker_db_interface_start_transaction (iface);
+ tracker_db_exec_proc (iface,
+ "DeleteSearchResults1",
+ NULL);
+ }
+
+ count = 0;
+
+ for (i = 0; i < hits->len; i++) {
+ TrackerSearchHit hit;
+ char *str_id;
+
+ if (count >= limit) {
+ break;
+ }
+
+ hit = g_array_index (hits, TrackerSearchHit, i);
+ str_id = tracker_uint_to_string (hit.service_id);
+
+ /* We save results into SearchResults table instead of
+ * returing an array of array of strings
+ */
+ if (save_results) {
+ gchar *str_score;
+
+ str_score = tracker_int_to_string (hit.score);
+ tracker_db_exec_proc (iface,
+ "InsertSearchResult1",
+ str_id,
+ str_score,
+ NULL);
+ g_free (str_id);
+ g_free (str_score);
+
+ continue;
+ }
+
+ if (detailed) {
+ if (strcmp (service, "Emails") == 0) {
+ detailed_emails = TRUE;
+ procedure = "GetEmailByID";
+ } else if (strcmp (service, "Applications") == 0) {
+ detailed_apps = TRUE;
+ procedure = "GetApplicationByID";
+ } else {
+ procedure = "GetFileByID2";
+ }
+ } else {
+ procedure = "GetFileByID";
+ }
+
+ result_set = tracker_db_exec_proc (iface,
+ procedure,
+ str_id,
+ NULL);
+ g_free (str_id);
+
+ if (result_set) {
+ gchar *path;
+
+ tracker_db_result_set_get (result_set, 0, &path, -1);
+
+ if (!detailed || detailed_emails || detailed_apps ||
+ (detailed && g_file_test (path, G_FILE_TEST_EXISTS))) {
+ guint columns, i;
+
+ columns = tracker_db_result_set_get_n_columns (result_set);
+
+ if (G_UNLIKELY (!result)) {
+ guint columns;
+
+ columns = tracker_db_result_set_get_n_columns (result_set);
+ result = _tracker_db_result_set_new (columns);
+ }
+
+ _tracker_db_result_set_append (result);
+
+ for (i = 0; i < columns; i++) {
+ GValue value = { 0, };
+
+ _tracker_db_result_set_get_value (result_set, i, &value);
+ _tracker_db_result_set_set_value (result, i, &value);
+ g_value_unset (&value);
+ }
+ }
+
+ g_free (path);
+ g_object_unref (result_set);
+ } else {
+ g_warning ("Dud hit for search detected");
+ duds = g_slist_prepend (duds, &hit);
+ }
+ }
+
+ if (save_results) {
+ tracker_db_interface_end_transaction (iface);
+ }
+
+ /* Delete duds */
+ if (duds) {
+ GSList *words, *w;
+ Indexer *indexer;
+
+ words = tracker_query_tree_get_words (tree);
+ indexer = tracker_query_tree_get_indexer (tree);
+
+ for (w = words; w; w = w->next) {
+ tracker_remove_dud_hits (indexer, (const gchar *) w->data, duds);
+ }
+
+ g_slist_free (words);
+ }
+
+ g_object_unref (tree);
+ g_array_free (hits, TRUE);
+ g_array_free (services, TRUE);
+
+ if (!result) {
+ return NULL;
+ }
+
+ if (tracker_db_result_set_get_n_rows (result) == 0) {
+ g_object_unref (result);
+ return NULL;
+ }
+
+ tracker_db_result_set_rewind (result);
+
+ return result;
+}
+
+TrackerDBResultSet *
+tracker_db_metadata_get (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key)
+{
+ TrackerField *def;
+ const gchar *proc = NULL;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (id, NULL);
+ g_return_val_if_fail (key, NULL);
+
+ def = tracker_ontology_get_field_def (key);
+
+ if (!def) {
+ g_warning ("Metadata not found for id:'%s' and type:'%s'", id, key);
+ return NULL;
+ }
+
+ switch (tracker_field_get_data_type (def)) {
+ case TRACKER_FIELD_TYPE_INDEX:
+ case TRACKER_FIELD_TYPE_STRING:
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ proc = "GetMetadata";
+ break;
+
+ case TRACKER_FIELD_TYPE_INTEGER:
+ case TRACKER_FIELD_TYPE_DATE:
+ proc = "GetMetadataNumeric";
+ break;
+
+ case TRACKER_FIELD_TYPE_FULLTEXT:
+ proc = "GetContents";
+ break;
+
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ proc = "GetMetadataKeyword";
+ break;
+
+ default:
+ g_warning ("Metadata could not be retrieved as type:%d is not supported",
+ tracker_field_get_data_type (def));
+ return NULL;
+ }
+
+ return tracker_db_exec_proc (iface,
+ proc,
+ id,
+ tracker_field_get_id (def),
+ NULL);
+}
+
+/* Gets specified metadata value as a single row (multple values for a
+ * metadata type are returned delimited by "|" )
+ */
+gchar *
+tracker_db_metadata_get_delimited (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key)
+{
+ TrackerDBResultSet *result_set;
+ GString *s = NULL;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (id != NULL, NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+
+ result_set = tracker_db_metadata_get (iface, id, key);
+
+ if (result_set) {
+ gchar *str;
+ gboolean valid = TRUE;
+
+ while (valid) {
+ tracker_db_result_set_get (result_set, 0, &str, -1);
+
+ if (s) {
+ g_string_append_printf (s, "|%s", str);
+ } else {
+ s = g_string_new (str);
+ }
+
+ g_free (str);
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ if (s) {
+ return g_string_free (s, FALSE);
+ } else {
+ return NULL;
+ }
+}
+
+gchar *
+tracker_db_metadata_get_related_names (TrackerDBInterface *iface,
+ const gchar *name)
+{
+ TrackerDBResultSet *result_set;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetMetadataAliasesForName",
+ name,
+ name,
+ NULL);
+
+ if (result_set) {
+ GString *s = NULL;
+ gboolean valid = TRUE;
+ gint id;
+
+ while (valid) {
+ tracker_db_result_set_get (result_set, 1, &id, -1);
+
+ if (s) {
+ g_string_append_printf (s, ", %d", id);
+ } else {
+ s = g_string_new ("");
+ g_string_append_printf (s, "%d", id);
+ }
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+
+ return g_string_free (s, FALSE);
+ }
+
+ return NULL;
+}
+
+TrackerDBResultSet *
+tracker_db_xesam_get_metadata_names (TrackerDBInterface *iface,
+ const gchar *name)
+{
+ TrackerDBResultSet *result_set;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetXesamMetaDataLookups",
+ name,
+ NULL);
+
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_xesam_get_service_names (TrackerDBInterface *iface,
+ const gchar *name)
+{
+ TrackerDBResultSet *result_set;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetXesamServiceLookups",
+ name,
+ NULL);
+
+ return result_set;
+}
+
+const gchar *
+tracker_db_metadata_get_table (TrackerFieldType type)
+{
+ switch (type) {
+ case TRACKER_FIELD_TYPE_INDEX:
+ case TRACKER_FIELD_TYPE_STRING:
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ return "ServiceMetaData";
+
+ case TRACKER_FIELD_TYPE_INTEGER:
+ case TRACKER_FIELD_TYPE_DATE:
+ return "ServiceNumericMetaData";
+
+ case TRACKER_FIELD_TYPE_BLOB:
+ return "ServiceBlobMetaData";
+
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ return "ServiceKeywordMetaData";
+
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+/* Fast insert of embedded metadata. Table parameter is used to build
+ * up a unique word list of indexable contents.
+ */
+void
+tracker_db_metadata_insert_single_embedded (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ const gchar *value,
+ GHashTable *hash_table)
+{
+ gchar *array[1];
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (value != NULL);
+ g_return_if_fail (hash_table != NULL);
+
+ array[0] = (gchar*) value;
+
+ tracker_db_metadata_insert_embedded (iface, service, id, key, array, hash_table);
+}
+
+void
+tracker_db_metadata_insert_embedded (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ gchar **values,
+ GHashTable *hash_table)
+{
+ TrackerField *def;
+ gint key_field = 0;
+ guint i;
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (values != NULL);
+ g_return_if_fail (hash_table != NULL);
+
+ def = tracker_ontology_get_field_def (key);
+
+ if (!def) {
+ g_warning ("Metadata with key:'%s' not found", key);
+ return;
+ }
+
+ g_return_if_fail (tracker_field_get_embedded (def));
+
+ key_field = tracker_ontology_metadata_key_in_service (service, key);
+
+ switch (tracker_field_get_data_type (def)) {
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ for (i = 0; i < g_strv_length (values); i++) {
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ if (hash_table) {
+ gchar *mvalue;
+
+ mvalue = tracker_parser_text_to_string (values[i],
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ FALSE,
+ FALSE,
+ FALSE);
+
+ hash_table = tracker_parser_text_fast (hash_table,
+ mvalue,
+ tracker_field_get_weight (def));
+
+ g_free (mvalue);
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadataKeyword",
+ id,
+ tracker_field_get_id (def),
+ values[i],
+ NULL);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_INDEX:
+ for (i = 0; i < g_strv_length (values); i++) {
+ gchar *mvalue;
+
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ mvalue = tracker_parser_text_to_string (values[i],
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
+
+ hash_table = tracker_parser_text_fast (hash_table,
+ mvalue,
+ tracker_field_get_weight (def));
+
+ tracker_db_exec_proc (iface,
+ "SetMetadata",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ values[i],
+ NULL);
+
+ g_free (mvalue);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_FULLTEXT:
+ for (i = 0; i < g_strv_length (values); i++) {
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ if (hash_table) {
+ hash_table = tracker_parser_text (hash_table,
+ values[i],
+ tracker_field_get_weight (def),
+ tracker->language,
+ tracker_config_get_max_words_to_index (tracker->config),
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
+ }
+
+ db_save_full_text (tracker_db_manager_get_db_interface_content (iface),
+ id,
+ values[i],
+ strlen (values[i]));
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ for (i = 0; i < g_strv_length (values); i++) {
+ if (!values[i]) {
+ continue;
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadata",
+ id,
+ tracker_field_get_id (def),
+ " ",
+ values[i],
+ NULL);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_STRING:
+ for (i = 0; i < g_strv_length (values); i++) {
+ gchar *mvalue;
+
+ if (!values[i]) {
+ continue;
+ }
+
+ mvalue = tracker_parser_text_to_string (values[i],
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
+ tracker_db_exec_proc (iface,
+ "SetMetadata",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ values[i],
+ NULL);
+
+ g_free (mvalue);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_INTEGER:
+ for (i = 0; i < g_strv_length (values); i++) {
+ if (!values[i]) {
+ continue;
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadataNumeric",
+ id,
+ tracker_field_get_id (def),
+ values[i],
+ NULL);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_DATE:
+ for (i = 0; i < g_strv_length (values); i++) {
+ gchar *mvalue;
+
+ if (!values[i]) {
+ continue;
+ }
+
+ mvalue = format_date (values[i]);
+
+ if (!mvalue) {
+ g_warning ("Could not format date:'%s'", values[i]);
+ continue;
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadataNumeric",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ NULL);
+
+ g_free (mvalue);
+ }
+ break;
+
+ default:
+ g_warning ("Metadata could not be set as type:%d for "
+ "metadata:'%s' is not supported",
+ tracker_field_get_data_type (def),
+ key);
+ break;
+ }
+
+ if (key_field > 0 && values[0]) {
+ gchar *esc_value = NULL;
+
+ if (tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_DATE) {
+ esc_value = format_date (values[0]);
+ } else {
+ gchar *str;
+
+ str = tracker_string_list_to_string (values, g_strv_length (values), '|');
+ esc_value = tracker_escape_string (str);
+ g_free (str);
+ }
+
+ if (esc_value) {
+ tracker_db_exec_no_reply (iface,
+ "update Services set KeyMetadata%d = '%s' where id = %s",
+ key_field,
+ esc_value,
+ id);
+
+ g_free (esc_value);
+ }
+ }
+}
+
+void
+tracker_db_metadata_set_single (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ const gchar *value,
+ gboolean do_backup)
+{
+ gchar *array[1];
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (value != NULL);
+
+ array[0] = (gchar*) value;
+
+ tracker_db_metadata_set (iface, service, id, key, array, do_backup);
+}
+
+gchar *
+tracker_db_metadata_set (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ gchar **values,
+ gboolean do_backup)
+{
+ TrackerField *def;
+ gchar *old_value = NULL;
+ gchar *new_value = NULL;
+ gchar *res_service;
+ gboolean update_index;
+ gint key_field = 0;
+ guint i;
+ guint length;
+ GString *str = NULL;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
+ g_return_val_if_fail (id != NULL, NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+ g_return_val_if_fail (values != NULL, NULL);
+
+ if (strcmp (id, "0") == 0) {
+ return NULL;
+ }
+
+ def = tracker_ontology_get_field_def (key);
+
+ if (!def) {
+ g_warning ("Metadata type:'%s' not found", key);
+ return NULL;
+ }
+
+ res_service = tracker_db_service_get_by_entity (iface, id);
+
+ if (!res_service) {
+ g_warning ("Service not found for id:'%s'", id);
+ return NULL;
+ }
+
+ length = g_strv_length (values);
+
+ if (tracker_field_get_multiple_values (def) && length > 1) {
+ str = g_string_new ("");
+ }
+
+ key_field = tracker_ontology_metadata_key_in_service (res_service, key);
+
+ update_index =
+ tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_INDEX ||
+ tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_KEYWORD ||
+ tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_FULLTEXT;
+
+ if (update_index) {
+ old_value = tracker_db_metadata_get_delimited (iface, id, key);
+ }
+
+ /* delete old value if metadata does not support multiple values */
+ if (!tracker_field_get_multiple_values (def)) {
+ tracker_db_metadata_delete (iface, service, id, key, FALSE);
+ }
+
+ switch (tracker_field_get_data_type (def)) {
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ for (i = 0; i < length; i++) {
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadataKeyword",
+ id,
+ tracker_field_get_id (def),
+ values[i],
+ NULL);
+
+ /* Backup non-embedded data for embedded services */
+ if (do_backup &&
+ !tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_non_embedded_metadata (iface,
+ id,
+ tracker_field_get_id (def),
+ values[i]);
+ }
+
+ if (str) {
+ g_string_append_printf (str, " %s ", values[i]);
+ } else {
+ new_value = values[i];
+ }
+
+ g_message ("Saving keyword:'%s'", values[i]);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_INDEX:
+ for (i = 0; i < length; i++) {
+ gchar *mvalue;
+
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ if (str) {
+ g_string_append_printf (str, " %s ", values[i]);
+ } else {
+ new_value = values[i];
+ }
+
+ /* Backup non-embedded data for embedded services */
+ if (do_backup &&
+ !tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_non_embedded_metadata (iface, id, tracker_field_get_id (def), values[i]);
+ }
+
+ mvalue = tracker_parser_text_to_string (values[i],
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
+ tracker_db_exec_proc (iface,
+ "SetMetadata",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ values[i],
+ NULL);
+ g_free (mvalue);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_FULLTEXT:
+ /* We do not support multiple values for fulltext clobs */
+ if (values[0]) {
+ /* FIXME: is the blog the metadata blob/email
+ * blob or something else?
+ */
+ db_save_full_text (tracker_db_manager_get_db_interface_content (iface),
+ id,
+ values[0],
+ strlen (values[0]));
+ new_value = values[0];
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_STRING:
+ for (i = 0; i < length; i++) {
+ gchar *mvalue;
+
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ /* Backup non-embedded data for embedded services */
+ if (do_backup &&
+ !tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_non_embedded_metadata (iface,
+ id,
+ tracker_field_get_id (def),
+ values[i]);
+ }
+
+ mvalue = tracker_parser_text_to_string (values[i],
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
+ tracker_db_exec_proc (iface,
+ "SetMetadata",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ values[i],
+ NULL);
+ g_free (mvalue);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ for (i = 0; i < length; i++) {
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ /* Backup non-embedded data for embedded services */
+ if (do_backup &&
+ !tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_non_embedded_metadata (iface,
+ id,
+ tracker_field_get_id (def),
+ values[i]);
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadata",
+ id,
+ tracker_field_get_id (def),
+ " ",
+ values[i],
+ NULL);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_INTEGER:
+ for (i = 0; i < length; i++) {
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ /* Backup non-embedded data for embedded services */
+ if (do_backup &&
+ !tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_non_embedded_metadata (iface,
+ id,
+ tracker_field_get_id (def),
+ values[i]);
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadataNumeric",
+ id,
+ tracker_field_get_id (def),
+ values[i],
+ NULL);
+ }
+ break;
+
+ case TRACKER_FIELD_TYPE_DATE:
+ for (i = 0; i < length; i++) {
+ gchar *mvalue;
+
+ if (!values[i] || !values[i][0]) {
+ continue;
+ }
+
+ mvalue = format_date (values[i]);
+
+ if (!mvalue) {
+ g_warning ("Could not format date:'%s'", values[i]);
+ continue;
+ }
+
+ tracker_db_exec_proc (iface,
+ "SetMetadataNumeric",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ NULL);
+
+ /* backup non-embedded data for embedded services */
+ if (do_backup &&
+ !tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_non_embedded_metadata (iface,
+ id,
+ tracker_field_get_id (def),
+ mvalue);
+ }
+
+
+ g_free (mvalue);
+ }
+ break;
+
+ default:
+ g_warning ("Metadata could not be set as type:%d for "
+ "metadata:'%s' is not supported",
+ tracker_field_get_data_type (def),
+ key);
+ break;
+ }
+
+ if (key_field > 0) {
+ if (values[0]) {
+ gchar *esc_value = NULL;
+
+ if (tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_DATE) {
+ esc_value = format_date (values[0]);
+
+ if (!esc_value) {
+ return NULL;
+ }
+ } else {
+ gchar *str;
+
+ str = tracker_string_list_to_string (values, length, '|');
+ esc_value = tracker_escape_string (str);
+ g_free (str);
+ }
+
+ tracker_db_exec_no_reply (iface,
+ "update Services set KeyMetadata%d = '%s' where id = %s",
+ key_field,
+ esc_value,
+ id);
+
+ g_free (esc_value);
+ }
+
+ }
+
+ /* Update fulltext index differentially with current and new
+ * values.
+ */
+ if (update_index) {
+ if (str) {
+ update_metadata_index (id, res_service, def, old_value, str->str);
+ g_string_free (str, TRUE);
+ } else {
+ update_metadata_index (id, res_service, def, old_value, new_value);
+ }
+ }
+
+ g_free (old_value);
+ g_free (res_service);
+
+ return NULL;
+}
+
+void
+tracker_db_metadata_delete_value (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ const gchar *value)
+{
+ TrackerField *def;
+ gchar *old_value = NULL;
+ gchar *new_value = NULL;
+ gchar *mvalue;
+ gchar *res_service;
+ gboolean update_index;
+ gint key_field;
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (key != NULL);
+
+ /* Get type details */
+ def = tracker_ontology_get_field_def (key);
+
+ if (!def) {
+ return;
+ }
+
+ if (!tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_delete_non_embedded_metadata_value (iface,
+ id,
+ tracker_field_get_id (def),
+ value);
+ }
+
+ res_service = tracker_db_service_get_by_entity (iface, id);
+
+ if (!res_service) {
+ g_warning ("Entity not found");
+ return;
+ }
+
+ key_field = tracker_ontology_metadata_key_in_service (res_service, key);
+
+ update_index =
+ tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_INDEX ||
+ tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_KEYWORD;
+
+ if (update_index) {
+ /* Get current value and claculate the new value */
+ old_value = tracker_db_metadata_get_delimited (iface, id, key);
+
+ if (old_value) {
+ new_value = remove_value (old_value, value);
+ } else {
+ g_free (res_service);
+ return;
+ }
+ }
+
+ /* Perform deletion */
+ switch (tracker_field_get_data_type (def)) {
+ case TRACKER_FIELD_TYPE_INDEX:
+ case TRACKER_FIELD_TYPE_STRING:
+ mvalue = tracker_parser_text_to_string (value,
+ tracker->language,
+ tracker_config_get_max_word_length (tracker->config),
+ tracker_config_get_min_word_length (tracker->config),
+ tracker_field_get_filtered (def),
+ tracker_field_get_filtered (def),
+ tracker_field_get_delimited (def));
+ tracker_db_exec_proc (iface,
+ "DeleteMetadataValue",
+ id,
+ tracker_field_get_id (def),
+ mvalue,
+ NULL);
+ g_free (mvalue);
+ break;
+
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ tracker_db_exec_proc (iface,
+ "DeleteMetadataValue",
+ id,
+ tracker_field_get_id (def),
+ value,
+ NULL);
+ break;
+
+ case TRACKER_FIELD_TYPE_INTEGER:
+ case TRACKER_FIELD_TYPE_DATE:
+ tracker_db_exec_proc (iface,
+ "DeleteMetadataNumericValue",
+ id,
+ tracker_field_get_id (def),
+ value,
+ NULL);
+ break;
+
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ tracker_db_exec_proc (iface,
+ "DeleteMetadataKeywordValue",
+ id,
+ tracker_field_get_id (def),
+ value,
+ NULL);
+ break;
+
+ default:
+ g_warning ("Metadata could not be deleted as type:%d for "
+ "metadata:'%s' is not supported",
+ tracker_field_get_data_type (def),
+ key);
+ break;
+ }
+
+ if (key_field > 0) {
+ TrackerDBResultSet *result_set;
+ gchar *value;
+
+ result_set = tracker_db_metadata_get (iface, id, key);
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 0, &value, -1);
+
+ if (value) {
+ gchar *esc_value;
+
+ esc_value = tracker_escape_string (value);
+ tracker_db_exec_no_reply (iface,
+ "update Services set KeyMetadata%d = '%s' where id = %s",
+ key_field,
+ esc_value,
+ id);
+
+ g_free (esc_value);
+ g_free (value);
+ } else {
+ tracker_db_exec_no_reply (iface,
+ "update Services set KeyMetadata%d = NULL where id = %s",
+ key_field,
+ id);
+ }
+
+ g_object_unref (result_set);
+ } else {
+ tracker_db_exec_no_reply (iface,
+ "update Services set KeyMetadata%d = NULL where id = %s",
+ key_field,
+ id);
+ }
+ }
+
+ /* Update fulltext index differentially with old and new values */
+ if (update_index) {
+ update_metadata_index (id,
+ service,
+ def,
+ old_value,
+ new_value);
+ }
+
+ g_free (new_value);
+ g_free (old_value);
+ g_free (res_service);
+}
+
+void
+tracker_db_metadata_delete (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ gboolean update_indexes)
+{
+ TrackerField *def;
+ gchar *old_value = NULL;
+ gchar *res_service;
+ gboolean update_index;
+ gint key_field;
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (service != NULL);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (key != NULL);
+
+ /* Get type details */
+ def = tracker_ontology_get_field_def(key);
+
+ if (!def) {
+ return;
+ }
+
+ if (!tracker_field_get_embedded (def) &&
+ tracker_ontology_service_type_has_embedded (service)) {
+ backup_delete_non_embedded_metadata (iface,
+ id,
+ tracker_field_get_id (def));
+ }
+
+ res_service = tracker_db_service_get_by_entity (iface, id);
+
+ if (!res_service) {
+ g_warning ("Entity not found");
+ return;
+ }
+
+ key_field = tracker_ontology_metadata_key_in_service (res_service, key);
+
+ update_index =
+ update_indexes &&
+ (tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_INDEX ||
+ tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_KEYWORD);
+
+ if (update_index) {
+ /* Get current value */
+ old_value = tracker_db_metadata_get_delimited (iface, id, key);
+ }
+
+ if (key_field > 0) {
+ tracker_db_exec_no_reply (iface,
+ "update Services set KeyMetadata%d = NULL where id = %s",
+ key_field, id);
+ }
+
+ /* Perform deletion */
+ switch (tracker_field_get_data_type (def)) {
+ case TRACKER_FIELD_TYPE_INDEX:
+ case TRACKER_FIELD_TYPE_STRING:
+ case TRACKER_FIELD_TYPE_DOUBLE:
+ tracker_db_exec_proc (iface,
+ "DeleteMetadata",
+ id,
+ tracker_field_get_id (def),
+ NULL);
+ break;
+
+ case TRACKER_FIELD_TYPE_INTEGER:
+ case TRACKER_FIELD_TYPE_DATE:
+ tracker_db_exec_proc (iface,
+ "DeleteMetadataNumeric",
+ id,
+ tracker_field_get_id (def),
+ NULL);
+ break;
+
+ case TRACKER_FIELD_TYPE_KEYWORD:
+ tracker_db_exec_proc (iface,
+ "DeleteMetadataKeyword",
+ id,
+ tracker_field_get_id (def),
+ NULL);
+ break;
+
+ case TRACKER_FIELD_TYPE_FULLTEXT:
+ tracker_db_exec_proc (iface,
+ "DeleteContent",
+ id,
+ tracker_field_get_id (def),
+ NULL);
+ break;
+
+ default:
+ g_warning ("Metadata could not be deleted as this "
+ "operation is not supported by type:%d "
+ "for metadata:'%s'",
+ tracker_field_get_data_type (def),
+ key);
+ break;
+ }
+
+
+ /* Update fulltext index differentially with old values and NULL */
+ if (update_index && old_value) {
+ update_metadata_index (id, service, def, old_value, " ");
+ }
+
+ g_free (old_value);
+ g_free (res_service);
+}
+
+TrackerDBResultSet *
+tracker_db_live_search_get_hit_count (TrackerDBInterface *iface,
+ const gchar *search_id)
+{
+ /* SELECT count(*)
+ * FROM LiveSearches
+ * WHERE SearchID = ? */
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (search_id != NULL, NULL);
+
+ return tracker_db_exec_proc (iface,
+ "GetLiveSearchHitCount",
+ search_id,
+ NULL);
+}
+
+void
+tracker_db_live_search_start (TrackerDBInterface *iface,
+ const gchar *from_query,
+ const gchar *join_query,
+ const gchar *where_query,
+ const gchar *search_id)
+{
+ /* INSERT
+ * INTO LiveSearches
+ * SELECT ID, SEARCH_ID FROM_QUERY WHERE_QUERY */
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (from_query != NULL);
+ g_return_if_fail (join_query != NULL);
+ g_return_if_fail (where_query != NULL);
+ g_return_if_fail (search_id != NULL);
+
+ tracker_db_exec_no_reply (iface,
+ "INSERT INTO LiveSearches SELECT S.ID, '%s' %s %s %s",
+ search_id,
+ from_query,
+ join_query,
+ where_query);
+}
+
+void
+tracker_db_live_search_stop (TrackerDBInterface *iface,
+ const gchar *search_id)
+{
+ /* DELETE
+ * FROM LiveSearches as X
+ * WHERE E.SearchID = ? */
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (search_id != NULL);
+
+ db_exec_proc_no_reply (iface,
+ "LiveSearchStopSearch",
+ search_id,
+ NULL);
+}
+
+TrackerDBResultSet *
+tracker_db_live_search_get_all_ids (TrackerDBInterface *iface,
+ const gchar *search_id)
+{
+ /* Contract, in @result:
+ * ServiceID is #1 */
+
+ /*
+ * SELECT X.ServiceID
+ * FROM LiveSearches as X
+ * WHERE X.SearchID = SEARCH_ID
+ */
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (search_id != NULL, NULL);
+
+ return tracker_db_exec_proc (iface,
+ "GetLiveSearchAllIDs",
+ search_id,
+ NULL);
+}
+
+TrackerDBResultSet *
+tracker_db_live_search_get_new_ids (TrackerDBInterface *iface,
+ const gchar *search_id,
+ const gchar *from_query,
+ const gchar *query_joins,
+ const gchar *where_query)
+{
+ TrackerDBResultSet *result_set;
+
+ /* Contract, in @result:
+ * ServiceID is #1
+ * EventType is #2 */
+
+ /*
+ * SELECT E.ServiceID, E.EventType
+ * FROM_QUERY, LiveSearches as X, Events as E
+ * QUERY_JOINS
+ * WHERE_QUERY
+ * AND X.ServiceID = E.ServiceID
+ * AND X.SearchID = 'SEARCH_ID'
+ * AND E.EventType = 'Update'
+ * UNION
+ * SELECT E.ServiceID, E.EventType
+ * FROM_QUERY, Events as E
+ * QUERY_JOINS
+ * WHERE_QUERY
+ * AND E.ServiceID = S.ID
+ * AND E.EventType = 'Create'
+ */
+
+ /*
+ * INSERT INTO LiveSearches
+ * SELECT E.ServiceID, 'SEARCH_ID'
+ * FROM_QUERY, Events as E
+ * QUERY_JOINS
+ * WHERE_QUERY
+ * AND E.ServiceID = S.ID
+ * AND E.EventType = 'Create'
+ */
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (search_id != NULL, NULL);
+ g_return_val_if_fail (from_query != NULL, NULL);
+ g_return_val_if_fail (query_joins != NULL, NULL);
+ g_return_val_if_fail (where_query != NULL, NULL);
+
+ result_set = tracker_db_exec (iface,
+ "SELECT E.ServiceID, E.EventType "
+ "%s%s LiveSearches as X, Events as E " /* FROM A1 */
+ "%s" /* JOINS A2 */
+ "%s" /* WHERE A3 */
+ "%sX.ServiceID = E.ServiceID "
+ "AND X.SearchID = '%s' " /* A4 */
+ "AND E.EventType = 'Update' "
+ "UNION "
+ "SELECT E.ServiceID, E.EventType "
+ "%s%s Events as E " /* FROM B1 */
+ "%s" /* JOINS B2 */
+ "%s" /* WHERE B3 */
+ "%sE.ServiceID = S.ID "
+ "AND E.EventType = 'Create' ",
+ from_query ? from_query : "FROM", /* A1 */
+ from_query ? "," : "", /* A1 */
+ query_joins, /* A2 */
+ where_query ? where_query : "WHERE", /* A3 */
+ where_query ? "AND " : "", /* A3 */
+ search_id, /* A4 */
+ from_query ? from_query : "FROM", /* B1 */
+ from_query ? "," : "", /* B1 */
+ query_joins, /* B2 */
+ where_query ? where_query : "WHERE", /* B3 */
+ where_query ? "AND " : ""); /* B3 */
+
+ tracker_db_exec_no_reply (iface,
+ "INSERT INTO LiveSearches "
+ "SELECT E.ServiceID, '%s' " /* B0 */
+ "%s%s Events as E " /* FROM B1 */
+ "%s" /* JOINS B2 */
+ "%s" /* WHERE B3 */
+ "%sE.ServiceID = S.ID"
+ "AND E.EventType = 'Create' ",
+ search_id, /* B0 */
+ from_query ? from_query : "FROM", /* B1 */
+ from_query ? "," : "", /* B1 */
+ query_joins, /* B2 */
+ where_query ? where_query : "WHERE", /* B3 */
+ where_query ? "AND " : ""); /* B3 */
+
+ return result_set;
+}
+
+TrackerDBResultSet*
+tracker_db_live_search_get_deleted_ids (TrackerDBInterface *iface,
+ const gchar *search_id)
+{
+ /* SELECT E.ServiceID
+ * FROM Events as E, LiveSearches as X
+ * WHERE E.ServiceID = X.ServiceID
+ * AND X.SearchID = ?
+ * AND E.EventType IS 'Delete' */
+
+ /* DELETE FROM LiveSearches AS Y WHERE Y.ServiceID IN
+ * SELECT ServiceID FROM Events as E, LiveSearches as X
+ * WHERE E.ServiceID = X.ServiceID
+ * AND X.SearchID = ?
+ * AND E.EventType IS 'Delete' */
+
+ TrackerDBResultSet *result_set;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (search_id != NULL, NULL);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetLiveSearchDeletedIDs",
+ search_id,
+ NULL);
+
+ db_exec_proc_no_reply (iface,
+ "DeleteLiveSearchDeletedIDs",
+ search_id,
+ NULL);
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_live_search_get_hit_data (TrackerDBInterface *iface,
+ const gchar *search_id)
+{
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (search_id != NULL, NULL);
+
+ return tracker_db_exec (iface,
+ "SELECT * FROM LiveSearches as X "
+ "WHERE X.SearchID = '%s'",
+ search_id);
+}
+
+void
+tracker_db_xesam_delete_handled_events (TrackerDBInterface *iface)
+{
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+
+ db_exec_proc_no_reply (iface,
+ "DeleteHandledEvents",
+ NULL);
+}
+
+/* Deprecated */
+guint32
+tracker_db_service_create (TrackerDBInterface *iface,
+ const gchar *service,
+ TrackerDBFileInfo *info)
+{
+ TrackerDBResultSet *result_set;
+ TrackerDBResultSet *result_set_proc;
+ TrackerDBInterface *iface_common;
+ gint i;
+ guint32 id = 0;
+ gchar *sid;
+ gchar *str_mtime;
+ const gchar *str_is_dir;
+ const gchar *str_is_link;
+ gchar *str_filesize;
+ gchar *str_offset;
+ gchar *str_aux;
+ gint service_type_id;
+ gchar *str_service_type_id;
+ gchar *path;
+ gchar *name;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), 0);
+ g_return_val_if_fail (info, 0);
+ g_return_val_if_fail (info->uri, 0);
+ g_return_val_if_fail (info->uri[0], 0);
+ g_return_val_if_fail (service, 0);
+
+ if (info->uri[0] == G_DIR_SEPARATOR) {
+ name = g_path_get_basename (info->uri);
+ path = g_path_get_dirname (info->uri);
+ } else {
+ name = tracker_file_get_vfs_name (info->uri);
+ path = tracker_file_get_vfs_path (info->uri);
+ }
+
+ iface_common = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+
+ /* Get a new unique ID for the service - use mutex to prevent race conditions */
+ result_set = tracker_db_exec_proc (iface_common, "GetNewID", NULL);
+
+ if (!result_set) {
+ g_critical ("Could not create service, GetNewID failed");
+ return 0;
+ }
+
+ tracker_db_result_set_get (result_set, 0, &sid, -1);
+ i = atoi (sid);
+ g_free (sid);
+ i++;
+
+ sid = tracker_int_to_string (i);
+ result_set_proc = tracker_db_exec_proc (iface_common, "UpdateNewID", sid, NULL);
+
+ if (result_set_proc) {
+ g_object_unref (result_set_proc);
+ }
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+
+ if (info->is_directory) {
+ str_is_dir = "1";
+ } else {
+ str_is_dir = "0";
+ }
+
+ if (info->is_link) {
+ str_is_link = "1";
+ } else {
+ str_is_link = "0";
+ }
+
+ str_filesize = tracker_guint32_to_string (info->file_size);
+ str_mtime = tracker_gint32_to_string (info->mtime);
+ str_offset = tracker_gint32_to_string (info->offset);
+
+ service_type_id = tracker_ontology_get_id_for_service_type (service);
+
+ if (info->mime) {
+ g_debug ("service id for %s is %d and sid is %s with mime %s",
+ service, service_type_id, sid, info->mime);
+ } else {
+ g_debug ("service id for %s is %d and sid is %s",
+ service, service_type_id, sid);
+ }
+
+ str_service_type_id = tracker_int_to_string (service_type_id);
+
+ str_aux = tracker_int_to_string (info->aux_id);
+
+ if (service_type_id != -1) {
+ gchar *parent;
+
+ result_set_proc = tracker_db_exec_proc (iface,
+ "CreateService",
+ sid,
+ path,
+ name,
+ str_service_type_id,
+ info->mime,
+ str_filesize,
+ str_is_dir,
+ str_is_link,
+ str_offset,
+ str_mtime,
+ str_aux,
+ NULL);
+
+ if (result_set_proc) {
+ g_object_unref (result_set_proc);
+ }
+
+ /*
+ Undetectable error
+ tracker_error ("ERROR: CreateService uri is %s/%s", path, name);
+ g_free (name);
+ g_free (path);
+ g_free (str_aux);
+ g_free (str_service_type_id);
+ g_free (sid);
+ g_free (str_filesize);
+ g_free (str_mtime);
+ g_free (str_offset);
+ g_static_rec_mutex_unlock (&events_table_lock);
+ return 0;
+ */
+
+ id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (iface));
+
+ if (info->is_hidden) {
+ tracker_db_exec_no_reply (iface,
+ "Update services set Enabled = 0 where ID = %d",
+ (int) id);
+ }
+
+ result_set_proc = tracker_db_exec_proc (iface_common,
+ "IncStat",
+ service,
+ NULL);
+
+ if (result_set_proc) {
+ g_object_unref (result_set_proc);
+ }
+
+ parent = tracker_ontology_get_parent_service (service);
+
+ if (parent) {
+ result_set_proc = tracker_db_exec_proc (iface_common,
+ "IncStat",
+ parent,
+ NULL);
+ if (result_set_proc) {
+ g_object_unref (result_set_proc);
+ }
+
+ g_free (parent);
+ }
+
+ if (tracker_config_get_enable_xesam (tracker->config)) {
+ /* FIXME: Shouldn't this be the common interface? */
+ db_create_event (iface, sid, "Create");
+ }
+ }
+
+ g_free (name);
+ g_free (path);
+ g_free (str_aux);
+ g_free (str_service_type_id);
+ g_free (sid);
+ g_free (str_filesize);
+ g_free (str_mtime);
+ g_free (str_offset);
+
+ return id;
+}
+
+gchar *
+tracker_db_service_get_by_entity (TrackerDBInterface *iface,
+ const gchar *id)
+{
+ TrackerDBResultSet *result_set;
+ gchar *result = NULL;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (id != NULL, NULL);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetFileByID2",
+ id,
+ NULL);
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 1, &result, -1);
+ g_object_unref (result_set);
+ }
+
+ return result;
+}
+
+guint32
+tracker_db_file_get_id (TrackerDBInterface *iface,
+ const gchar *uri)
+{
+ TrackerDBResultSet *result_set;
+ gchar *path, *name;
+ guint32 id;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), 0);
+ g_return_val_if_fail (uri != NULL, 0);
+
+ if (uri[0] == G_DIR_SEPARATOR) {
+ name = g_path_get_basename (uri);
+ path = g_path_get_dirname (uri);
+ } else {
+ name = tracker_file_get_vfs_name (uri);
+ path = tracker_file_get_vfs_path (uri);
+ }
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetServiceID",
+ path,
+ name,
+ NULL);
+
+ g_free (path);
+ g_free (name);
+
+ id = 0;
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 0, &id, -1);
+ g_object_unref (result_set);
+ }
+
+ return id;
+}
+
+gchar *
+tracker_db_file_get_id_as_string (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *uri)
+{
+ gint service_id;
+ guint32 id;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
+
+ /* Do we really need service here? */
+ service_id = tracker_ontology_get_id_for_service_type (service);
+
+ if (service_id == -1) {
+ return NULL;
+ }
+
+ id = tracker_db_file_get_id (iface, uri);
+
+ if (id > 0) {
+ return tracker_uint_to_string (id);
+ }
+
+ return NULL;
+}
+
+TrackerDBFileInfo *
+tracker_db_file_get_info (TrackerDBInterface *iface,
+ TrackerDBFileInfo *info)
+{
+ TrackerDBResultSet *result_set;
+ gchar *path, *name;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), info);
+ g_return_val_if_fail (info != NULL, info);
+
+ if (!tracker_db_file_info_is_valid (info)) {
+ return NULL;
+ }
+
+ name = g_path_get_basename (info->uri);
+ path = g_path_get_dirname (info->uri);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetServiceID",
+ path,
+ name,
+ NULL);
+
+ g_free (name);
+ g_free (path);
+
+ if (result_set) {
+ gint id, indextime, service_type_id;
+ gboolean is_directory;
+
+ tracker_db_result_set_get (result_set,
+ 0, &id,
+ 1, &indextime,
+ 2, &is_directory,
+ 3, &service_type_id,
+ -1);
+
+ if (id > 0) {
+ info->file_id = id;
+ info->is_new = FALSE;
+ }
+
+ info->indextime = indextime;
+ info->is_directory = is_directory;
+ info->service_type_id = service_type_id;
+
+ g_object_unref (result_set);
+ }
+
+ return info;
+}
+
+gboolean
+tracker_db_file_is_up_to_date (TrackerDBInterface *iface,
+ const gchar *uri,
+ guint32 *id)
+{
+ TrackerDBResultSet *result_set;
+ gchar *path, *name;
+ gint32 index_time;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), FALSE);
+ g_return_val_if_fail (uri != NULL, FALSE);
+ g_return_val_if_fail (id != NULL, FALSE);
+
+ if (uri[0] == G_DIR_SEPARATOR) {
+ name = g_path_get_basename (uri);
+ path = g_path_get_dirname (uri);
+ } else {
+ name = tracker_file_get_vfs_name (uri);
+ path = tracker_file_get_vfs_path (uri);
+ }
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetServiceID",
+ path,
+ name,
+ NULL);
+
+ g_free (path);
+ g_free (name);
+
+ index_time = 0;
+ *id = 0;
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set,
+ 0, id,
+ 1, &index_time,
+ -1);
+
+ g_object_unref (result_set);
+ } else {
+ return FALSE;
+ }
+
+ if (index_time < tracker_file_get_mtime (uri)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void
+tracker_db_file_delete (TrackerDBInterface *iface,
+ guint32 file_id)
+{
+ TrackerDBResultSet *result_set;
+ TrackerDBInterface *iface_common;
+ gchar *str_file_id;
+ gchar *name = NULL;
+ gchar *path;
+ gint id;
+
+ iface_common = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface_common));
+
+ delete_index_for_service (iface, file_id);
+
+ str_file_id = tracker_uint_to_string (file_id);
+
+ result_set = tracker_db_exec_proc (iface, "GetFileByID3", str_file_id, NULL);
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set,
+ 0, &name,
+ 1, &path,
+ 3, &id,
+ -1);
+
+ if (name && path) {
+ dec_stat (id);
+
+ tracker_db_exec_proc (iface, "DeleteService1", str_file_id, NULL);
+ tracker_db_exec_proc (iface_common, "DeleteService6", path, name, NULL);
+ tracker_db_exec_proc (iface_common, "DeleteService7", path, name, NULL);
+ tracker_db_exec_proc (iface_common, "DeleteService9", path, name, NULL);
+
+ db_create_event (iface_common, str_file_id, "Delete");
+
+ g_free (name);
+ g_free (path);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ g_free (str_file_id);
+}
+
+void
+tracker_db_directory_delete (TrackerDBInterface *iface,
+ guint32 file_id,
+ const gchar *uri)
+{
+ TrackerDBResultSet *result_set;
+ gchar *str_file_id;
+ gchar *uri_prefix;
+
+ g_return_if_fail (TRACKER_DB_INTERFACE (iface));
+ g_return_if_fail (uri != NULL);
+
+ str_file_id = tracker_uint_to_string (file_id);
+ uri_prefix = g_strconcat (uri, G_DIR_SEPARATOR_S, "*", NULL);
+ delete_index_for_service (iface, file_id);
+
+ /* Get all file id's for all files recursively under directory amd delete them */
+ result_set = tracker_db_exec_proc (iface,
+ "SelectSubFileIDs",
+ uri,
+ uri_prefix,
+ NULL);
+
+ if (result_set) {
+ gboolean valid = TRUE;
+ gint id;
+
+ while (valid) {
+ tracker_db_result_set_get (result_set, 0, &id, -1);
+ tracker_db_file_delete (iface, id);
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ /* Delete directory */
+ tracker_db_file_delete (iface, file_id);
+
+ g_free (uri_prefix);
+ g_free (str_file_id);
+}
+
+void
+tracker_db_uri_insert_pending (const gchar *id,
+ const gchar *action,
+ const gchar *counter,
+ const gchar *uri,
+ const gchar *mime,
+ gboolean is_dir,
+ gboolean is_new,
+ gint service_type_id)
+{
+ TrackerDBInterface *iface;
+ const gchar *str_new;
+ gchar *str_service_type_id;
+ gchar *time_str;
+ time_t time_now;
+ gint i;
+
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (action != NULL);
+ g_return_if_fail (counter != NULL);
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (mime != NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_CACHE);
+
+ time (&time_now);
+
+ i = atoi (counter);
+
+ if (i == 0) {
+ time_str = tracker_int_to_string (i);
+ } else {
+ time_str = tracker_int_to_string (time_now + i);
+ }
+
+ if (is_new) {
+ str_new = "1";
+ } else {
+ str_new = "0";
+ }
+
+ str_service_type_id = tracker_int_to_string (service_type_id);
+
+ tracker_db_exec_proc (iface,
+ "InsertPendingFile",
+ id,
+ action,
+ time_str,
+ uri,
+ mime,
+ is_dir ? "1" : "0",
+ str_new,
+ "1",
+ "1",
+ str_service_type_id,
+ NULL);
+
+ g_free (str_service_type_id);
+ g_free (time_str);
+}
+
+void
+tracker_db_uri_update_pending (const gchar *counter,
+ const gchar *action,
+ const gchar *uri)
+{
+ TrackerDBInterface *iface;
+ gchar *time_str;
+ time_t time_now;
+ gint i;
+
+ g_return_if_fail (counter != NULL);
+ g_return_if_fail (action != NULL);
+ g_return_if_fail (uri != NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_CACHE);
+
+ time (&time_now);
+
+ i = atoi (counter);
+
+ time_str = tracker_int_to_string (time_now + i);
+
+ tracker_db_exec_proc (iface,
+ "UpdatePendingFile",
+ time_str,
+ action,
+ uri,
+ NULL);
+
+ g_free (time_str);
+}
+
+gchar **
+tracker_db_files_get (TrackerDBInterface *iface,
+ const gchar *uri)
+{
+ TrackerDBResultSet *result_set;
+ GPtrArray *array;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ result_set = tracker_db_exec_proc (iface,
+ "SelectFileChild",
+ uri,
+ NULL);
+ array = g_ptr_array_new ();
+
+ if (result_set) {
+ gchar *name, *prefix;
+ gboolean valid = TRUE;
+
+ while (valid) {
+ tracker_db_result_set_get (result_set,
+ 1, &prefix,
+ 2, &name,
+ -1);
+
+ g_ptr_array_add (array, g_build_filename (prefix, name, NULL));
+
+ g_free (prefix);
+ g_free (name);
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ g_ptr_array_add (array, NULL);
+
+ return (gchar**) g_ptr_array_free (array, FALSE);
+}
+
+TrackerDBResultSet *
+tracker_db_files_get_by_service (TrackerDBInterface *iface,
+ const gchar *service,
+ gint offset,
+ gint limit)
+{
+ TrackerDBResultSet *result_set;
+ gchar *str_limit;
+ gchar *str_offset;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
+
+ str_limit = tracker_int_to_string (limit);
+ str_offset = tracker_int_to_string (offset);
+
+ result_set = tracker_db_exec_proc (iface,
+ "GetByServiceType",
+ service,
+ service,
+ str_offset,
+ str_limit,
+ NULL);
+
+ g_free (str_offset);
+ g_free (str_limit);
+
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_files_get_by_mime (TrackerDBInterface *iface,
+ gchar **mimes,
+ gint n,
+ gint offset,
+ gint limit,
+ gboolean vfs)
+{
+ TrackerDBResultSet *result_set;
+ gint i;
+ gchar *service;
+ gchar *query;
+ GString *str;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (mimes != NULL, NULL);
+ g_return_val_if_fail (offset >= 0, NULL);
+
+ if (vfs) {
+ service = "VFS";
+ } else {
+ service = "Files";
+ }
+
+ str = g_string_new ("SELECT DISTINCT F.Path || '/' || F.Name AS uri FROM Services F INNER JOIN ServiceKeywordMetaData M ON F.ID = M.ServiceID WHERE M.MetaDataID = (SELECT ID FROM MetaDataTypes WHERE MetaName ='File:Mime') AND (M.MetaDataValue IN ");
+
+ g_string_append_printf (str, "('%s'", mimes[0]);
+
+ for (i = 1; i < n; i++) {
+ g_string_append_printf (str, ", '%s'", mimes[i]);
+ }
+
+ g_string_append_printf (str,
+ ")) AND (F.ServiceTypeID in (select TypeId from ServiceTypes where TypeName = '%s' or Parent = '%s')) LIMIT %d,%d",
+ service,
+ service,
+ offset,
+ limit);
+
+ query = g_string_free (str, FALSE);
+ result_set = tracker_db_interface_execute_query (iface, NULL, query);
+ g_free (query);
+
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_metadata_get_types (TrackerDBInterface *iface,
+ const gchar *class,
+ gboolean writeable)
+{
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (class != NULL, NULL);
+
+ if (strcmp (class, "*") == 0) {
+ if (writeable) {
+ return tracker_db_exec_proc (iface,
+ "GetWriteableMetadataTypes",
+ NULL);
+ } else {
+ return tracker_db_exec_proc (iface,
+ "GetMetadataTypes",
+ NULL);
+ }
+ } else {
+ if (writeable) {
+ return tracker_db_exec_proc (iface,
+ "GetWriteableMetadataTypesLike",
+ class,
+ NULL);
+ } else {
+ return tracker_db_exec_proc (iface,
+ "GetMetadataTypesLike",
+ class,
+ NULL);
+ }
+ }
+}
+
+TrackerDBResultSet *
+tracker_db_uri_sub_watches_get (const gchar *dir)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ gchar *folder;
+
+ g_return_val_if_fail (dir != NULL, NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_CACHE);
+
+ folder = g_build_filename (dir, "*", NULL);
+ result_set = tracker_db_exec_proc (iface,
+ "GetSubWatches",
+ folder,
+ NULL);
+ g_free (folder);
+
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_uri_sub_watches_delete (const gchar *dir)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ gchar *folder;
+
+ g_return_val_if_fail (dir != NULL, NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_CACHE);
+
+ folder = g_build_filename (dir, "*", NULL);
+ result_set = tracker_db_exec_proc (iface,
+ "DeleteSubWatches",
+ folder,
+ NULL);
+
+ g_free (folder);
+
+ return result_set;
+}
+
+void
+tracker_db_file_move (TrackerDBInterface *iface,
+ const gchar *moved_from_uri,
+ const gchar *moved_to_uri)
+{
+ TrackerDBInterface *iface_common;
+ gchar *str_file_id;
+ gchar *name;
+ gchar *path;
+ gchar *old_name;
+ gchar *old_path;
+ gchar *ext;
+ guint32 id;
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (moved_from_uri != NULL);
+ g_return_if_fail (moved_to_uri != NULL);
+
+ g_message ("Moving file:'%s' to:'%s'",
+ moved_from_uri,
+ moved_to_uri);
+
+ /* If orig file not in DB, treat it asa create action */
+ id = tracker_db_file_get_id (iface, moved_from_uri);
+
+ if (id == 0) {
+ g_warning ("Original file:'%s' not found in database",
+ moved_from_uri);
+ tracker_db_interface_end_transaction (iface);
+ return;
+ }
+
+ str_file_id = tracker_uint_to_string (id);
+ name = g_path_get_basename (moved_to_uri);
+ path = g_path_get_dirname (moved_to_uri);
+ old_name = g_path_get_basename (moved_from_uri);
+ old_path = g_path_get_dirname (moved_from_uri);
+
+ /* Update db so that fileID reflects new uri */
+ tracker_db_exec_proc (iface,
+ "UpdateFileMove",
+ path,
+ name,
+ str_file_id,
+ NULL);
+
+ iface_common = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+ db_create_event (iface_common, str_file_id, "Update");
+
+ /* update File:Path and File:Filename metadata */
+ tracker_db_metadata_set_single (iface,
+ "Files", str_file_id,
+ "File:Path", path,
+ FALSE);
+ tracker_db_metadata_set_single (iface,
+ "Files", str_file_id,
+ "File:Name", name,
+ FALSE);
+
+ ext = strrchr (moved_to_uri, '.');
+ if (ext) {
+ ext++;
+ tracker_db_metadata_set_single (iface,
+ "Files", str_file_id,
+ "File:Ext", ext,
+ FALSE);
+ }
+
+ /* Update backup service if necessary */
+ tracker_db_exec_proc (iface_common,
+ "UpdateBackupService",
+ path,
+ name,
+ old_path,
+ old_name,
+ NULL);
+
+ g_free (str_file_id);
+ g_free (name);
+ g_free (path);
+ g_free (old_name);
+ g_free (old_path);
+}
+
+void
+tracker_db_directory_move (TrackerDBInterface *iface,
+ const gchar *moved_from_uri,
+ const gchar *moved_to_uri)
+{
+ TrackerDBResultSet *result_set;
+ gchar *old_path;
+
+ g_return_if_fail (TRACKER_IS_DB_INTERFACE (iface));
+ g_return_if_fail (moved_from_uri != NULL);
+ g_return_if_fail (moved_to_uri != NULL);
+
+ old_path = g_strconcat (moved_from_uri, G_DIR_SEPARATOR_S, NULL);
+
+ /* Get all sub folders that were moved and add watches */
+ result_set = tracker_db_uri_get_subfolders (iface, moved_from_uri);
+
+ if (result_set) {
+ gboolean valid = TRUE;
+
+ while (valid) {
+ gchar *prefix, *name;
+ gchar *dir_name, *sep, *new_path;
+
+ tracker_db_result_set_get (result_set,
+ 1, &prefix,
+ 2, &name,
+ -1);
+
+ dir_name = g_build_filename (prefix, name, NULL);
+
+ /* Get string after prefix */
+ if (!old_path) {
+ sep = g_strdup (dir_name);
+ } else {
+ gchar *prefix_start;
+
+ prefix_start = strstr (dir_name, old_path);
+
+ if (!prefix_start) {
+ sep = NULL;
+ } else {
+ gchar *str;
+
+ str = prefix_start + strlen (old_path);
+ sep = g_strdup (str);
+ }
+ }
+
+ if (!sep) {
+ g_free (dir_name);
+ continue;
+ }
+
+ new_path = g_build_filename (moved_to_uri, sep, NULL);
+ g_free (sep);
+
+ g_message ("Moving subfolder:'%s' to:'%s'",
+ dir_name,
+ new_path);
+
+ directory_move (iface, dir_name, new_path);
+
+ /* FIXME: Why? */
+ g_usleep (1000);
+
+ g_free (prefix);
+ g_free (name);
+ g_free (new_path);
+ g_free (dir_name);
+
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ directory_move (iface, moved_from_uri, moved_to_uri);
+
+ g_free (old_path);
+}
+
+TrackerDBResultSet *
+tracker_db_uri_get_subfolders (TrackerDBInterface *iface,
+ const gchar *uri)
+{
+ TrackerDBResultSet *result_set;
+ gchar *folder;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ folder = g_strconcat (uri, G_DIR_SEPARATOR_S, "*", NULL);
+ result_set = tracker_db_exec_proc (iface,
+ "SelectFileSubFolders",
+ uri,
+ folder,
+ NULL);
+ g_free (folder);
+
+ return result_set;
+}
+
+TrackerDBResultSet *
+tracker_db_keywords_get_list (TrackerDBInterface *iface,
+ const gchar *service)
+{
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
+
+ return tracker_db_exec_proc (iface,
+ "GetKeywordList",
+ service,
+ service,
+ NULL);
+}
+
+GSList *
+tracker_db_mime_query (TrackerDBInterface *iface,
+ const gchar *stored_proc,
+ gint service_id)
+{
+ TrackerDBResultSet *result_set;
+ GSList *result = NULL;
+ gchar *service_id_str;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (stored_proc != NULL, NULL);
+
+ service_id_str = g_strdup_printf ("%d", service_id);
+ result_set = tracker_db_exec_proc (iface, stored_proc, service_id_str, NULL);
+ g_free (service_id_str);
+
+ if (result_set) {
+ gchar *str;
+ gboolean valid = TRUE;
+
+ while (valid) {
+ tracker_db_result_set_get (result_set, 0, &str, -1);
+ result = g_slist_prepend (result, str);
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ return result;
+}
+
+GSList *
+tracker_db_get_mimes_for_service_id (TrackerDBInterface *iface,
+ gint service_id)
+{
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+
+ return tracker_db_mime_query (iface,
+ "GetMimeForServiceId",
+ service_id);
+}
+
+GSList *
+tracker_db_get_mime_prefixes_for_service_id (TrackerDBInterface *iface,
+ gint service_id)
+{
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+
+ return tracker_db_mime_query (iface,
+ "GetMimePrefixForServiceId",
+ service_id);
+}
+
+TrackerFieldData *
+tracker_db_get_metadata_field (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *field_name,
+ gint field_count,
+ gboolean is_select,
+ gboolean is_condition)
+{
+ TrackerFieldData *field_data = NULL;
+ TrackerField *def;
+
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), NULL);
+ g_return_val_if_fail (service != NULL, NULL);
+ g_return_val_if_fail (field_name != NULL, NULL);
+
+ def = tracker_ontology_get_field_def (field_name);
+
+ if (def) {
+ gchar *alias;
+ const gchar *table_name;
+ gchar *this_field_name;
+ gchar *where_field;
+
+ field_data = g_object_new (TRACKER_TYPE_FIELD_DATA,
+ "is-select", is_select,
+ "is-condition", is_condition,
+ "field-name", field_name,
+ NULL);
+
+ alias = g_strdup_printf ("M%d", field_count);
+ table_name = tracker_db_metadata_get_table (tracker_field_get_data_type (def));
+
+ g_debug ("Field_name: %s :table_name is: %s for data_type: %i",
+ field_name,
+ table_name,
+ tracker_field_get_data_type(def));
+
+ tracker_field_data_set_alias (field_data, alias);
+ tracker_field_data_set_table_name (field_data, table_name);
+ tracker_field_data_set_id_field (field_data, tracker_field_get_id (def));
+ tracker_field_data_set_data_type (field_data, tracker_field_get_data_type (def));
+ tracker_field_data_set_multiple_values (field_data, tracker_field_get_multiple_values (def));
+
+ this_field_name = tracker_db_get_field_name (service, field_name);
+
+ if (this_field_name) {
+ gchar *str;
+
+ str = g_strdup_printf (" S.%s ", this_field_name);
+ tracker_field_data_set_select_field (field_data, str);
+ tracker_field_data_set_needs_join (field_data, FALSE);
+ g_free (str);
+ g_free (this_field_name);
+ } else {
+ gchar *str;
+ gchar *display_field;
+
+ display_field = tracker_ontology_get_display_field (def);
+ str = g_strdup_printf ("M%d.%s", field_count, display_field);
+ tracker_field_data_set_select_field (field_data, str);
+ tracker_field_data_set_needs_join (field_data, TRUE);
+ g_free (str);
+ g_free (display_field);
+ }
+
+ if (tracker_field_get_data_type (def) == TRACKER_FIELD_TYPE_DOUBLE) {
+ where_field = g_strdup_printf ("M%d.MetaDataDisplay", field_count);
+ } else {
+ where_field = g_strdup_printf ("M%d.MetaDataValue", field_count);
+ }
+
+ tracker_field_data_set_where_field (field_data, where_field);
+ g_free (where_field);
+ }
+
+ return field_data;
+}
+
+gchar *
+tracker_db_get_option_string (const gchar *option)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ gchar *value = NULL;
+
+ g_return_val_if_fail (option != NULL, NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+ result_set = tracker_db_exec_proc (iface, "GetOption", option, NULL);
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 0, &value, -1);
+ g_object_unref (result_set);
+ }
+
+ return value;
+}
+
+void
+tracker_db_set_option_string (const gchar *option,
+ const gchar *value)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+
+ g_return_if_fail (option != NULL);
+ g_return_if_fail (value != NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+ result_set = tracker_db_exec_proc (iface, "SetOption", value, option, NULL);
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+}
+
+gint
+tracker_db_get_option_int (const gchar *option)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ gchar *str;
+ gint value = 0;
+
+ g_return_val_if_fail (option != NULL, 0);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+ result_set = tracker_db_exec_proc (iface, "GetOption", option, NULL);
+
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 0, &str, -1);
+
+ if (str) {
+ value = atoi (str);
+ g_free (str);
+ }
+
+ g_object_unref (result_set);
+ }
+
+ return value;
+}
+
+void
+tracker_db_set_option_int (const gchar *option,
+ gint value)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ gchar *str;
+
+ g_return_if_fail (option != NULL);
+
+ iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
+
+ str = tracker_int_to_string (value);
+ result_set = tracker_db_exec_proc (iface, "SetOption", str, option, NULL);
+ g_free (str);
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+}
+
+gboolean
+tracker_db_regulate_transactions (TrackerDBInterface *iface,
+ gint interval)
+{
+ g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), FALSE);
+
+ tracker->index_count++;
+
+ if ((tracker->index_count == 1 ||
+ tracker->index_count == interval ||
+ (tracker->index_count >= interval &&
+ tracker->index_count % interval == 0))) {
+ if (tracker->index_count > 1) {
+ tracker_db_interface_end_transaction (iface);
+ tracker_db_interface_start_transaction (iface);
+
+ g_message ("Current memory usage is %d, word count %d and hits %d",
+ get_memory_usage (),
+ tracker->word_count,
+ tracker->word_detail_count);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
Modified: branches/indexer-split/src/trackerd/tracker-db.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.h (original)
+++ branches/indexer-split/src/trackerd/tracker-db.h Mon Jun 9 09:55:17 2008
@@ -1,6 +1,9 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2007, Jason Kivlighn (jkivlighn gmail com)
+ * Copyright (C) 2007, Creative Commons (http://creativecommons.org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -23,26 +26,208 @@
#include <glib.h>
+#include <libtracker-common/tracker-field.h>
+#include <libtracker-common/tracker-field-data.h>
+#include <libtracker-common/tracker-ontology.h>
+
+#include <libtracker-db/tracker-db-interface.h>
#include <libtracker-db/tracker-db-file-info.h>
-#include "tracker-db-sqlite.h"
+#include "tracker-indexer.h"
+#include "tracker-utils.h"
G_BEGIN_DECLS
-void tracker_db_init (void);
-void tracker_db_shutdown (void);
-gboolean tracker_db_is_file_up_to_date (TrackerDBInterface *iface,
- const gchar *uri,
- guint32 *id);
-TrackerDBFileInfo *tracker_db_get_file_info (TrackerDBInterface *iface,
- TrackerDBFileInfo *info);
-guint32 tracker_db_get_file_id (TrackerDBInterface *iface,
- const gchar *uri);
-gchar * tracker_db_get_id (TrackerDBInterface *iface,
- const gchar *service,
- const gchar *uri);
-gchar ** tracker_db_get_files_in_folder (TrackerDBInterface *iface,
- const gchar *folder_uri);
+void tracker_db_init (void);
+void tracker_db_shutdown (void);
+void tracker_db_refresh_all (TrackerDBInterface *iface);
+
+
+/* Operations for TrackerDBInterface */
+void tracker_db_close (TrackerDBInterface *iface);
+TrackerDBResultSet *tracker_db_exec_proc (TrackerDBInterface *iface,
+ const gchar *procedure,
+ ...);
+gboolean tracker_db_exec_no_reply (TrackerDBInterface *iface,
+ const gchar *query,
+ ...);
+TrackerDBResultSet *tracker_db_exec (TrackerDBInterface *iface,
+ const char *query,
+ ...);
+gchar * tracker_db_get_option_string (const gchar *option);
+void tracker_db_set_option_string (const gchar *option,
+ const gchar *value);
+gint tracker_db_get_option_int (const gchar *option);
+void tracker_db_set_option_int (const gchar *option,
+ gint value);
+
+/* High level transactions things */
+gboolean tracker_db_regulate_transactions (TrackerDBInterface *iface,
+ gint interval);
+
+/* Metadata API */
+gchar * tracker_db_metadata_get_related_names (TrackerDBInterface *iface,
+ const gchar *name);
+const gchar * tracker_db_metadata_get_table (TrackerFieldType type);
+TrackerDBResultSet *tracker_db_metadata_get (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key);
+gchar * tracker_db_metadata_get_delimited (TrackerDBInterface *iface,
+ const gchar *id,
+ const gchar *key);
+gchar * tracker_db_metadata_set (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ gchar **values,
+ gboolean do_backup);
+void tracker_db_metadata_set_single (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ const gchar *value,
+ gboolean do_backup);
+void tracker_db_metadata_insert_embedded (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ gchar **values,
+ GHashTable *table);
+void tracker_db_metadata_insert_single_embedded (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ const gchar *value,
+ GHashTable *table);
+void tracker_db_metadata_delete_value (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ const gchar *value);
+void tracker_db_metadata_delete (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *id,
+ const gchar *key,
+ gboolean update_indexes);
+TrackerDBResultSet *tracker_db_metadata_get_types (TrackerDBInterface *iface,
+ const gchar *class,
+ gboolean writeable);
+
+/* Search API */
+TrackerDBResultSet *tracker_db_search_text (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *search_string,
+ gint offset,
+ gint limit,
+ gboolean save_results,
+ gboolean detailed);
+
+/* Service API */
+guint32 tracker_db_service_create (TrackerDBInterface *iface,
+ const gchar *service,
+ TrackerDBFileInfo *info);
+gchar * tracker_db_service_get_by_entity (TrackerDBInterface *iface,
+ const gchar *id);
+
+/* Files API */
+gchar ** tracker_db_files_get (TrackerDBInterface *iface,
+ const gchar *folder_uri);
+TrackerDBResultSet *tracker_db_files_get_by_service (TrackerDBInterface *iface,
+ const gchar *service,
+ gint offset,
+ gint limit);
+TrackerDBResultSet *tracker_db_files_get_by_mime (TrackerDBInterface *iface,
+ gchar **mimes,
+ gint n,
+ gint offset,
+ gint limit,
+ gboolean vfs);
+guint32 tracker_db_file_get_id (TrackerDBInterface *iface,
+ const gchar *uri);
+gchar * tracker_db_file_get_id_as_string (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *uri);
+TrackerDBFileInfo * tracker_db_file_get_info (TrackerDBInterface *iface,
+ TrackerDBFileInfo *info);
+gboolean tracker_db_file_is_up_to_date (TrackerDBInterface *iface,
+ const gchar *uri,
+ guint32 *id);
+void tracker_db_file_delete (TrackerDBInterface *iface,
+ guint32 file_id);
+void tracker_db_file_move (TrackerDBInterface *iface,
+ const gchar *moved_from_uri,
+ const gchar *moved_to_uri);
+void tracker_db_directory_delete (TrackerDBInterface *iface,
+ guint32 file_id,
+ const gchar *uri);
+void tracker_db_directory_move (TrackerDBInterface *iface,
+ const gchar *moved_from_uri,
+ const gchar *moved_to_uri);
+void tracker_db_uri_insert_pending (const gchar *id,
+ const gchar *action,
+ const gchar *counter,
+ const gchar *uri,
+ const gchar *mime,
+ gboolean is_dir,
+ gboolean is_new,
+ gint service_type_id);
+void tracker_db_uri_update_pending (const gchar *counter,
+ const gchar *action,
+ const gchar *uri);
+TrackerDBResultSet *tracker_db_uri_get_subfolders (TrackerDBInterface *iface,
+ const gchar *uri);
+TrackerDBResultSet *tracker_db_uri_sub_watches_get (const gchar *dir);
+TrackerDBResultSet *tracker_db_uri_sub_watches_delete (const gchar *dir);
+
+/* Keywords API */
+TrackerDBResultSet *tracker_db_keywords_get_list (TrackerDBInterface *iface,
+ const gchar *service);
+
+/* Miscellaneous API */
+GHashTable * tracker_db_get_file_contents_words (TrackerDBInterface *iface,
+ guint32 id,
+ GHashTable *old_table);
+GHashTable * tracker_db_get_indexable_content_words (TrackerDBInterface *iface,
+ guint32 id,
+ GHashTable *table,
+ gboolean embedded_only);
+gchar * tracker_db_get_field_name (const gchar *service,
+ const gchar *meta_name);
+TrackerFieldData * tracker_db_get_metadata_field (TrackerDBInterface *iface,
+ const gchar *service,
+ const gchar *field_name,
+ gint field_count,
+ gboolean is_select,
+ gboolean is_condition);
+
+/* Live Search API */
+void tracker_db_live_search_start (TrackerDBInterface *iface,
+ const gchar *from_query,
+ const gchar *join_query,
+ const gchar *where_query,
+ const gchar *search_id);
+void tracker_db_live_search_stop (TrackerDBInterface *iface,
+ const gchar *search_id);
+TrackerDBResultSet *tracker_db_live_search_get_all_ids (TrackerDBInterface *iface,
+ const gchar *search_id);
+TrackerDBResultSet *tracker_db_live_search_get_new_ids (TrackerDBInterface *iface,
+ const gchar *search_id,
+ const gchar *from_query,
+ const gchar *query_joins,
+ const gchar *where_query);
+TrackerDBResultSet *tracker_db_live_search_get_deleted_ids (TrackerDBInterface *iface,
+ const gchar *search_id);
+TrackerDBResultSet *tracker_db_live_search_get_hit_data (TrackerDBInterface *iface,
+ const gchar *search_id);
+TrackerDBResultSet *tracker_db_live_search_get_hit_count (TrackerDBInterface *iface,
+ const gchar *search_id);
+
+/* XESAM API */
+void tracker_db_xesam_delete_handled_events (TrackerDBInterface *iface);
+TrackerDBResultSet *tracker_db_xesam_get_metadata_names (TrackerDBInterface *iface,
+ const char *name);
+TrackerDBResultSet *tracker_db_xesam_get_service_names (TrackerDBInterface *iface,
+ const char *name);
G_END_DECLS
Modified: branches/indexer-split/src/trackerd/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus.c Mon Jun 9 09:55:17 2008
@@ -25,7 +25,7 @@
#include <libtracker-db/tracker-db-manager.h>
-#include "tracker-db-sqlite.h"
+#include "tracker-db.h"
#include "tracker-dbus.h"
#include "tracker-daemon.h"
#include "tracker-daemon-glue.h"
Modified: branches/indexer-split/src/trackerd/tracker-email-utils.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-utils.h (original)
+++ branches/indexer-split/src/trackerd/tracker-email-utils.h Mon Jun 9 09:55:17 2008
@@ -23,7 +23,7 @@
#include <gmime/gmime.h>
-#include "tracker-db-sqlite.h"
+#include "tracker-db.h"
G_BEGIN_DECLS
Modified: branches/indexer-split/src/trackerd/tracker-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-files.c (original)
+++ branches/indexer-split/src/trackerd/tracker-files.c Mon Jun 9 09:55:17 2008
@@ -83,7 +83,7 @@
iface = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_METADATA);
- file_id = tracker_db_get_file_id (iface, uri);
+ file_id = tracker_db_file_get_id (iface, uri);
exists = file_id > 0;
if (!exists && auto_create) {
@@ -260,7 +260,7 @@
iface = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_METADATA);
- file_id = tracker_db_get_file_id (iface, uri);
+ file_id = tracker_db_file_get_id (iface, uri);
if (file_id == 0) {
tracker_dbus_request_comment (request_id,
"File or directory was not in database to delete, uri:'%s'",
@@ -339,7 +339,7 @@
iface = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_METADATA);
- file_id = tracker_db_get_file_id (iface, uri);
+ file_id = tracker_db_file_get_id (iface, uri);
if (file_id < 1) {
tracker_dbus_request_failed (request_id,
@@ -425,9 +425,9 @@
iface_metadata = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_METADATA);
iface_contents = tracker_db_manager_get_db_interface (TRACKER_DB_FILE_CONTENTS);
- service_id = tracker_db_get_id (iface_metadata, "Files", uri);
+ service_id = tracker_db_file_get_id_as_string (iface_metadata, "Files", uri);
if (!service_id) {
- service_id = tracker_db_get_id (iface_metadata, "Emails", uri);
+ service_id = tracker_db_file_get_id_as_string (iface_metadata, "Emails", uri);
if (!service_id) {
tracker_dbus_request_failed (request_id,
@@ -811,7 +811,7 @@
}
/* Get file ID in database */
- file_id = tracker_db_get_file_id (iface, uri_filtered);
+ file_id = tracker_db_file_get_id (iface, uri_filtered);
if (file_id == 0) {
g_free (uri_filtered);
tracker_dbus_request_failed (request_id,
Modified: branches/indexer-split/src/trackerd/tracker-keywords.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-keywords.c (original)
+++ branches/indexer-split/src/trackerd/tracker-keywords.c Mon Jun 9 09:55:17 2008
@@ -190,7 +190,7 @@
}
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- id = tracker_db_get_id (iface, service, uri);
+ id = tracker_db_file_get_id_as_string (iface, service, uri);
if (!id) {
tracker_dbus_request_failed (request_id,
error,
@@ -255,7 +255,7 @@
}
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- id = tracker_db_get_id (iface, service, uri);
+ id = tracker_db_file_get_id_as_string (iface, service, uri);
tracker_dbus_return_val_if_fail (id != NULL, FALSE, error);
tracker_db_metadata_set (iface,
@@ -318,7 +318,7 @@
}
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- id = tracker_db_get_id (iface, service, uri);
+ id = tracker_db_file_get_id_as_string (iface, service, uri);
if (!id) {
tracker_dbus_request_failed (request_id,
error,
@@ -383,7 +383,7 @@
}
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- id = tracker_db_get_id (iface, service, uri);
+ id = tracker_db_file_get_id_as_string (iface, service, uri);
if (!id) {
tracker_dbus_request_failed (request_id,
error,
Modified: branches/indexer-split/src/trackerd/tracker-metadata.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-metadata.c (original)
+++ branches/indexer-split/src/trackerd/tracker-metadata.c Mon Jun 9 09:55:17 2008
@@ -105,7 +105,7 @@
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- service_id = tracker_db_get_id (iface, service, id);
+ service_id = tracker_db_file_get_id_as_string (iface, service, id);
if (!service_id) {
tracker_dbus_request_failed (request_id,
error,
@@ -241,7 +241,7 @@
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- service_id = tracker_db_get_id (iface, service, id);
+ service_id = tracker_db_file_get_id_as_string (iface, service, id);
if (!service_id) {
tracker_dbus_request_failed (request_id,
error,
Modified: branches/indexer-split/src/trackerd/tracker-process-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-process-files.c (original)
+++ branches/indexer-split/src/trackerd/tracker-process-files.c Mon Jun 9 09:55:17 2008
@@ -413,7 +413,7 @@
gchar **p;
/* Check for any deletions*/
- files = tracker_db_get_files_in_folder (iface, uri);
+ files = tracker_db_files_get (iface, uri);
if (!files) {
return;
@@ -426,7 +426,7 @@
TrackerDBFileInfo *info;
info = tracker_db_file_info_new (str, 1, 0, 0);
- info = tracker_db_get_file_info (iface, info);
+ info = tracker_db_file_get_info (iface, info);
if (!info->is_directory) {
process_index_delete_file (info, iface);
Modified: branches/indexer-split/src/trackerd/tracker-rdf-query.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-rdf-query.c (original)
+++ branches/indexer-split/src/trackerd/tracker-rdf-query.c Mon Jun 9 09:55:17 2008
@@ -21,11 +21,12 @@
#include <libtracker-common/tracker-field-data.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-ontology.h>
#include <libtracker-common/tracker-type-utils.h>
#include <libtracker-common/tracker-utils.h>
#include "tracker-rdf-query.h"
-#include "tracker-db-sqlite.h"
+#include "tracker-db.h"
/* RDF Query Condition
* <rdfq:Condition>
Modified: branches/indexer-split/src/trackerd/tracker-search.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-search.c (original)
+++ branches/indexer-split/src/trackerd/tracker-search.c Mon Jun 9 09:55:17 2008
@@ -35,7 +35,6 @@
#include <libtracker-db/tracker-db-manager.h>
#include "tracker-db.h"
-#include "tracker-db-sqlite.h"
#include "tracker-dbus.h"
#include "tracker-search.h"
#include "tracker-rdf-query.h"
@@ -934,7 +933,7 @@
iface = tracker_db_manager_get_db_interface_by_service (service, FALSE);
- service_id = tracker_db_get_id (iface, service, id);
+ service_id = tracker_db_file_get_id_as_string (iface, service, id);
if (!service_id) {
tracker_dbus_request_failed (request_id,
error,
Modified: branches/indexer-split/src/trackerd/tracker-xesam-live-search.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-live-search.c (original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-live-search.c Mon Jun 9 09:55:17 2008
@@ -28,7 +28,7 @@
#include "tracker-xesam-manager.h"
#include "tracker-xesam-query.h"
#include "tracker-dbus.h"
-#include "tracker-db-sqlite.h"
+#include "tracker-db.h"
struct _TrackerXesamLiveSearchPriv {
TrackerXesamSession *session;
Modified: branches/indexer-split/src/trackerd/tracker-xesam-query.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam-query.c (original)
+++ branches/indexer-split/src/trackerd/tracker-xesam-query.c Mon Jun 9 09:55:17 2008
@@ -27,7 +27,7 @@
#include <libtracker-common/tracker-utils.h>
#include "tracker-xesam-query.h"
-#include "tracker-db-sqlite.h"
+#include "tracker-db.h"
/* XESAM Query Condition
* <query>
Modified: branches/indexer-split/src/trackerd/tracker-xesam.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam.h (original)
+++ branches/indexer-split/src/trackerd/tracker-xesam.h Mon Jun 9 09:55:17 2008
@@ -26,7 +26,7 @@
#include <dbus/dbus-glib-bindings.h>
-#include "tracker-db-sqlite.h"
+#include "tracker-db.h"
#include "tracker-indexer.h"
#define TRACKER_XESAM_SERVICE "org.freedesktop.xesam.searcher"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]