tracker r2479 - in branches/libtracker-data: . src/libtracker-data src/trackerd
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2479 - in branches/libtracker-data: . src/libtracker-data src/trackerd
- Date: Mon, 10 Nov 2008 10:24:51 +0000 (UTC)
Author: juergbi
Date: Mon Nov 10 10:24:51 2008
New Revision: 2479
URL: http://svn.gnome.org/viewvc/tracker?rev=2479&view=rev
Log:
2008-11-10 JÃrg Billeter <j bitron ch>
* src/libtracker-data/tracker-data-search.c:
* src/libtracker-data/tracker-data-search.h:
* src/trackerd/tracker-files.c:
Move SQL query from trackerd/tracker-files to
libtracker-data/tracker-data-search
Modified:
branches/libtracker-data/ChangeLog
branches/libtracker-data/src/libtracker-data/tracker-data-search.c
branches/libtracker-data/src/libtracker-data/tracker-data-search.h
branches/libtracker-data/src/trackerd/tracker-files.c
Modified: branches/libtracker-data/src/libtracker-data/tracker-data-search.c
==============================================================================
--- branches/libtracker-data/src/libtracker-data/tracker-data-search.c (original)
+++ branches/libtracker-data/src/libtracker-data/tracker-data-search.c Mon Nov 10 10:24:51 2008
@@ -36,6 +36,7 @@
#include <libtracker-db/tracker-db-manager.h>
#include "tracker-data-manager.h"
+#include "tracker-data-query.h"
#include "tracker-data-schema.h"
#include "tracker-data-search.h"
#include "tracker-query-tree.h"
@@ -1367,3 +1368,119 @@
return count;
}
+TrackerDBResultSet *
+tracker_data_search_metadata_in_path (const gchar *path,
+ gchar **fields,
+ GError **error)
+{
+ TrackerDBInterface *iface;
+ TrackerDBResultSet *result_set;
+ TrackerField *defs[255];
+ guint i;
+ gchar *uri_filtered;
+ guint32 file_id;
+ GString *sql;
+ gboolean needs_join[255];
+ gchar *query;
+
+ g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (fields != NULL, NULL);
+ g_return_val_if_fail (g_strv_length (fields) > 0, NULL);
+
+ /* Get fields for metadata list provided */
+ for (i = 0; i < g_strv_length (fields); i++) {
+ defs[i] = tracker_ontology_get_field_by_name (fields[i]);
+
+ if (!defs[i]) {
+ g_set_error (error, TRACKER_DBUS_ERROR, 0,
+ "Metadata field '%s' was not found",
+ fields[i]);
+ return NULL;
+ }
+
+ }
+ defs [g_strv_length (fields)] = NULL;
+
+
+ if (g_str_has_suffix (path, G_DIR_SEPARATOR_S)) {
+ /* Remove trailing 'G_DIR_SEPARATOR' */
+ uri_filtered = g_strndup (path, strlen (path) - 1);
+ } else {
+ uri_filtered = g_strdup (path);
+ }
+
+ iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
+
+ /* Get file ID in database */
+ file_id = tracker_data_query_file_id (NULL, uri_filtered);
+ if (file_id == 0) {
+ g_free (uri_filtered);
+ g_set_error (error, TRACKER_DBUS_ERROR, 0,
+ "File or directory was not in database, path:'%s'",
+ path);
+ return NULL;
+ }
+
+ /* Build SELECT clause */
+ sql = g_string_new (" ");
+ g_string_append_printf (sql,
+ "SELECT (F.Path || '%s' || F.Name) as PathName ",
+ G_DIR_SEPARATOR_S);
+
+ for (i = 1; i <= g_strv_length (fields); i++) {
+ gchar *field;
+
+ field = tracker_data_schema_get_field_name ("Files", fields[i-1]);
+
+ if (field) {
+ g_string_append_printf (sql, ", F.%s ", field);
+ g_free (field);
+ needs_join[i - 1] = FALSE;
+ } else {
+ gchar *display_field;
+
+ display_field = tracker_ontology_field_get_display_name (defs[i-1]);
+ g_string_append_printf (sql, ", M%d.%s ", i, display_field);
+ g_free (display_field);
+ needs_join[i - 1] = TRUE;
+ }
+ }
+
+ /* Build FROM clause */
+ g_string_append (sql,
+ " FROM Services F ");
+
+ for (i = 0; i < g_strv_length (fields); i++) {
+ const gchar *table;
+
+ if (!needs_join[i]) {
+ continue;
+ }
+
+ table = tracker_data_schema_metadata_field_get_db_table (tracker_field_get_data_type (defs[i]));
+
+ g_string_append_printf (sql,
+ " LEFT OUTER JOIN %s M%d ON "
+ "F.ID = M%d.ServiceID AND "
+ "M%d.MetaDataID = %s ",
+ table,
+ i+1,
+ i+1,
+ i+1,
+ tracker_field_get_id (defs[i]));
+ }
+
+ /* Build WHERE clause */
+ g_string_append_printf (sql,
+ " WHERE F.Path = '%s' ",
+ uri_filtered);
+ g_free (uri_filtered);
+
+ query = g_string_free (sql, FALSE);
+ result_set = tracker_db_interface_execute_query (iface, NULL, query);
+
+ g_free (query);
+
+ return result_set;
+}
+
Modified: branches/libtracker-data/src/libtracker-data/tracker-data-search.h
==============================================================================
--- branches/libtracker-data/src/libtracker-data/tracker-data-search.h (original)
+++ branches/libtracker-data/src/libtracker-data/tracker-data-search.h Mon Nov 10 10:24:51 2008
@@ -74,40 +74,44 @@
TrackerDBResultSet *tracker_data_search_keywords_get_list (TrackerDBInterface *iface,
const gchar *service);
-TrackerDBResultSet *tracker_data_search_get_unique_values (const gchar *service_type,
- gchar **fields,
- const gchar *query_condition,
- gboolean order_desc,
- gint offset,
- gint max_hits,
- GError **error);
-gint tracker_data_search_get_sum (const gchar *service_type,
- const gchar *field,
- const gchar *query_condition,
- GError **error);
-gint tracker_data_search_get_count (const gchar *service_type,
- const gchar *field,
- const gchar *query_condition,
- GError **error);
-
-TrackerDBResultSet *tracker_data_search_get_unique_values_with_count (const gchar *service_type,
- gchar **fields,
- const gchar *query_condition,
- const gchar *count,
- gboolean order_desc,
- gint offset,
- gint max_hits,
- GError **error);
-
-TrackerDBResultSet *tracker_data_search_get_unique_values_with_count_and_sum (const gchar *service_type,
- gchar **fields,
- const gchar *query_condition,
- const gchar *count,
- const gchar *sum,
- gboolean order_desc,
- gint offset,
- gint max_hits,
- GError **error);
+TrackerDBResultSet *tracker_data_search_get_unique_values (const gchar *service_type,
+ gchar **fields,
+ const gchar *query_condition,
+ gboolean order_desc,
+ gint offset,
+ gint max_hits,
+ GError **error);
+gint tracker_data_search_get_sum (const gchar *service_type,
+ const gchar *field,
+ const gchar *query_condition,
+ GError **error);
+gint tracker_data_search_get_count (const gchar *service_type,
+ const gchar *field,
+ const gchar *query_condition,
+ GError **error);
+
+TrackerDBResultSet *tracker_data_search_get_unique_values_with_count (const gchar *service_type,
+ gchar **fields,
+ const gchar *query_condition,
+ const gchar *count,
+ gboolean order_desc,
+ gint offset,
+ gint max_hits,
+ GError **error);
+
+TrackerDBResultSet *tracker_data_search_get_unique_values_with_count_and_sum (const gchar *service_type,
+ gchar **fields,
+ const gchar *query_condition,
+ const gchar *count,
+ const gchar *sum,
+ gboolean order_desc,
+ gint offset,
+ gint max_hits,
+ GError **error);
+
+TrackerDBResultSet *tracker_data_search_metadata_in_path (const gchar *path,
+ gchar **fields,
+ GError **error);
G_END_DECLS
Modified: branches/libtracker-data/src/trackerd/tracker-files.c
==============================================================================
--- branches/libtracker-data/src/trackerd/tracker-files.c (original)
+++ branches/libtracker-data/src/trackerd/tracker-files.c Mon Nov 10 10:24:51 2008
@@ -717,16 +717,8 @@
DBusGMethodInvocation *context,
GError **error)
{
- TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
- TrackerField *defs[255];
guint request_id;
- guint i;
- gchar *uri_filtered;
- guint32 file_id;
- GString *sql;
- gboolean needs_join[255];
- gchar *query;
GPtrArray *values;
GError *actual_error = NULL;
@@ -743,112 +735,21 @@
uri,
g_strv_length (fields));
+ result_set = tracker_data_search_metadata_in_path (uri,
+ fields,
+ &actual_error);
- /* Get fields for metadata list provided */
- for (i = 0; i < g_strv_length (fields); i++) {
- defs[i] = tracker_ontology_get_field_by_name (fields[i]);
-
- if (!defs[i]) {
- tracker_dbus_request_failed (request_id,
- &actual_error,
- "Metadata field '%s' was not found",
- fields[i]);
- dbus_g_method_return_error (context, actual_error);
- g_error_free (actual_error);
- return;
- }
-
- }
- defs [g_strv_length (fields)] = NULL;
-
-
- if (g_str_has_suffix (uri, G_DIR_SEPARATOR_S)) {
- /* Remove trailing 'G_DIR_SEPARATOR' */
- uri_filtered = g_strndup (uri, strlen (uri) - 1);
- } else {
- uri_filtered = g_strdup (uri);
- }
-
- iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
-
- /* Get file ID in database */
- file_id = tracker_data_query_file_id (NULL, uri_filtered);
- if (file_id == 0) {
- g_free (uri_filtered);
- tracker_dbus_request_failed (request_id,
- &actual_error,
- "File or directory was not in database, uri:'%s'",
- uri);
- dbus_g_method_return_error (context, actual_error);
- g_error_free (actual_error);
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
return;
}
- /* Build SELECT clause */
- sql = g_string_new (" ");
- g_string_append_printf (sql,
- "SELECT (F.Path || '%s' || F.Name) as PathName ",
- G_DIR_SEPARATOR_S);
-
- for (i = 1; i <= g_strv_length (fields); i++) {
- gchar *field;
-
- field = tracker_data_schema_get_field_name ("Files", fields[i-1]);
-
- if (field) {
- g_string_append_printf (sql, ", F.%s ", field);
- g_free (field);
- needs_join[i - 1] = FALSE;
- } else {
- gchar *display_field;
-
- display_field = tracker_ontology_field_get_display_name (defs[i-1]);
- g_string_append_printf (sql, ", M%d.%s ", i, display_field);
- g_free (display_field);
- needs_join[i - 1] = TRUE;
- }
- }
-
- /* Build FROM clause */
- g_string_append (sql,
- " FROM Services F ");
-
- for (i = 0; i < g_strv_length (fields); i++) {
- const gchar *table;
-
- if (!needs_join[i]) {
- continue;
- }
-
- table = tracker_data_schema_metadata_field_get_db_table (tracker_field_get_data_type (defs[i]));
-
- g_string_append_printf (sql,
- " LEFT OUTER JOIN %s M%d ON "
- "F.ID = M%d.ServiceID AND "
- "M%d.MetaDataID = %s ",
- table,
- i+1,
- i+1,
- i+1,
- tracker_field_get_id (defs[i]));
- }
-
- /* Build WHERE clause */
- g_string_append_printf (sql,
- " WHERE F.Path = '%s' ",
- uri_filtered);
- g_free (uri_filtered);
-
- query = g_string_free (sql, FALSE);
- result_set = tracker_db_interface_execute_query (iface, NULL, query);
values = tracker_dbus_query_result_to_ptr_array (result_set);
if (result_set) {
g_object_unref (result_set);
}
- g_free (query);
-
dbus_g_method_return (context, values);
tracker_dbus_results_ptr_array_free (&values);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]