[tracker/harmattan-pre-signal-updates: 1318/1380] Implement fetching variable-names further, not working yet



commit a399fa2851efe2d0bbeed18183e5252da7deca2a
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Sep 10 13:19:12 2010 +0200

    Implement fetching variable-names further, not working yet

 src/libtracker-bus/tracker-bus-fd-cursor.c        |    3 ++
 src/libtracker-client/tracker.c                   |    2 +
 src/libtracker-common/tracker-dbus.c              |   39 +++++++++++++++++++-
 src/libtracker-common/tracker-dbus.h              |    2 +
 src/libtracker-data/tracker-db-interface-sqlite.c |   26 --------------
 src/libtracker-data/tracker-db-interface.h        |    1 -
 src/miners/fs/tracker-miner-files.c               |    2 +
 src/tracker-store/tracker-steroids.c              |   12 ++++++-
 tests/functional-tests/shared-query-test.vala     |    7 +++-
 9 files changed, 63 insertions(+), 31 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index 7cd7874..15a5523 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -313,6 +313,7 @@ tracker_bus_fd_query (DBusGConnection  *gconnection,
 static void
 query_async_cb (gpointer  buffer,
                 gssize    buffer_size,
+                GStrv     variable_names,
                 GError   *error,
                 gpointer  user_data)
 {
@@ -331,6 +332,7 @@ query_async_cb (gpointer  buffer,
 
 		cursor->buffer = buffer;
 		cursor->buffer_size = buffer_size;
+		cursor->variable_names = g_strdupv (variable_names);
 
 		g_simple_async_result_set_op_res_gpointer (res, cursor, g_object_unref);
 	}
@@ -388,6 +390,7 @@ tracker_bus_fd_query_async (DBusGConnection     *gconnection,
 	tracker_dbus_send_and_splice_async (connection,
 	                                    message,
 	                                    pipefd[0],
+	                                    TRUE,
 	                                    cancellable,
 	                                    query_async_cb, res);
 	/* message is destroyed by tracker_dbus_send_and_splice_async */
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 1508620..19a8fd3 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -641,6 +641,7 @@ iterator_buffer_read_int (TrackerResultIterator *iterator)
 static void
 callback_iterator (void     *buffer,
                    gssize    buffer_size,
+                   GStrv     variable_names,
                    GError   *error,
                    gpointer  user_data)
 {
@@ -2408,6 +2409,7 @@ tracker_resources_sparql_query_iterate_async (TrackerClient         *client,
 	tracker_dbus_send_and_splice_async (connection,
 	                                    message,
 	                                    pipefd[0],
+	                                    TRUE,
 	                                    cancellable,
 	                                    callback_iterator,
 	                                    fad);
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index e07a90c..340703c 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -56,6 +56,7 @@ typedef struct {
 	DBusPendingCall *call;
 	TrackerDBusSendAndSpliceCallback callback;
 	gpointer user_data;
+	gboolean expect_variable_names;
 } SendAndSpliceData;
 
 static GSList *hooks;
@@ -841,6 +842,7 @@ static SendAndSpliceData *
 send_and_splice_data_new (GInputStream                     *unix_input_stream,
                           GInputStream                     *buffered_input_stream,
                           GOutputStream                    *output_stream,
+                          gboolean                          expect_variable_names,
                           DBusPendingCall                  *call,
                           TrackerDBusSendAndSpliceCallback  callback,
                           gpointer                          user_data)
@@ -854,6 +856,7 @@ send_and_splice_data_new (GInputStream                     *unix_input_stream,
 	data->call = call;
 	data->callback = callback;
 	data->user_data = user_data;
+	data->expect_variable_names = expect_variable_names;
 
 	return data;
 }
@@ -897,25 +900,55 @@ send_and_splice_async_callback (GObject      *source,
 			dbus_set_g_error (&error, &dbus_error);
 			dbus_error_free (&dbus_error);
 
-			(* data->callback) (NULL, -1, error, data->user_data);
+			(* data->callback) (NULL, -1, NULL, error, data->user_data);
 
 			/* Note: GError should be freed by callback. We do this to be aligned
 			 * with the behavior of dbus-glib, where if an error happens, the
 			 * GError passed to the callback is supposed to be disposed by the
 			 * callback itself. */
 		} else {
+			GStrv v_names = NULL;
+
+			if (data->expect_variable_names) {
+				guint i;
+				GPtrArray *found = g_ptr_array_new ();
+				DBusMessageIter iter, arr;
+
+				dbus_message_iter_init (reply, &iter);
+				dbus_message_iter_recurse (&iter, &arr);
+
+				while (dbus_message_iter_has_next(&arr)) {
+					gchar *str;
+
+					dbus_message_iter_get_basic (&arr, &str);
+					g_ptr_array_add (found, str);
+					dbus_message_iter_next (&arr);
+				}
+
+				v_names = g_new0 (gchar *, found->len + 1);
+				for (i = 0; i < found->len; i++) {
+					v_names[i] = g_ptr_array_index (found, i);
+				}
+
+				g_ptr_array_free (found, FALSE);
+			}
+
 			dbus_pending_call_cancel (data->call);
+
 			(* data->callback) (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
 			                    g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
+			                    v_names,
 			                    NULL,
 			                    data->user_data);
+
+			g_strfreev (v_names);
 		}
 	} else {
 		/* If any error happened, we're not passing any received data, so we
 		 * need to free it */
 		g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
 
-		(* data->callback) (NULL, -1, error, data->user_data);
+		(* data->callback) (NULL, -1, NULL, error, data->user_data);
 
 		/* Note: GError should be freed by callback. We do this to be aligned
 		 * with the behavior of dbus-glib, where if an error happens, the
@@ -934,6 +967,7 @@ gboolean
 tracker_dbus_send_and_splice_async (DBusConnection                   *connection,
                                     DBusMessage                      *message,
                                     int                               fd,
+                                    gboolean                          expect_variable_names,
                                     GCancellable                     *cancellable,
                                     TrackerDBusSendAndSpliceCallback  callback,
                                     gpointer                          user_data)
@@ -968,6 +1002,7 @@ tracker_dbus_send_and_splice_async (DBusConnection                   *connection
 	data = send_and_splice_data_new (unix_input_stream,
 	                                 buffered_input_stream,
 	                                 output_stream,
+	                                 expect_variable_names,
 	                                 call,
 	                                 callback,
 	                                 user_data);
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index be3d3c9..3153b35 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -94,6 +94,7 @@ typedef void (*TrackerDBusRequestFunc) (guint    request_id,
 
 typedef void (*TrackerDBusSendAndSpliceCallback) (void     *buffer,
                                                   gssize    buffer_size,
+                                                  GStrv     variable_names,
                                                   GError   *error,
                                                   gpointer  user_data);
 
@@ -180,6 +181,7 @@ gboolean         tracker_dbus_send_and_splice        (DBusConnection
 gboolean         tracker_dbus_send_and_splice_async  (DBusConnection             *connection,
                                                       DBusMessage                *message,
                                                       int                         fd,
+                                                      gboolean                    expect_variable_names,
                                                       GCancellable               *cancellable,
                                                       TrackerDBusSendAndSpliceCallback callback,
                                                       gpointer                    user_data);
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 92f9e68..089c86c 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -70,7 +70,6 @@ struct TrackerDBCursor {
 	sqlite3_stmt *stmt;
 	TrackerDBStatement *ref_stmt;
 	gboolean finished;
-	gchar **variable_names;
 	TrackerPropertyType *types;
 	gint n_types;
 };
@@ -1096,9 +1095,6 @@ tracker_db_cursor_finalize (GObject *object)
 
 	g_free (cursor->types);
 
-	g_strfreev (cursor->variable_names);
-	cursor->variable_names = NULL;
-
 	if (cursor->ref_stmt) {
 		cursor->ref_stmt->stmt_is_sunk = FALSE;
 		tracker_db_statement_sqlite_reset (cursor->ref_stmt);
@@ -1407,28 +1403,6 @@ tracker_db_cursor_get_value_type (TrackerDBCursor *cursor,  guint column)
 	}
 }
 
-const gchar**
-tracker_db_cursor_get_variable_names (TrackerDBCursor *cursor)
-{
-	gint n_columns = sqlite3_column_count (cursor->stmt);
-
-	if (cursor->variable_names == NULL) {
-		gint i;
-
-		cursor->variable_names = g_new0 (gchar *, n_columns);
-
-		for (i = 0 ; i < n_columns; i++) {
-			const char *sqlite_name = sqlite3_column_name (cursor->stmt, i);
-			if (g_str_has_suffix (sqlite_name, "_u")) {
-				/* SPARQL variable */
-				cursor->variable_names[i] = g_strndup (sqlite_name, strlen (sqlite_name - strlen ("_u")));
-			}
-		}
-	}
-
-	return (const gchar **) cursor->variable_names;
-}
-
 const gchar*
 tracker_db_cursor_get_variable_name (TrackerDBCursor *cursor, guint column)
 {
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index 78d5734..d63e1b1 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -148,7 +148,6 @@ gboolean                tracker_db_cursor_iter_next             (TrackerDBCursor
 guint                   tracker_db_cursor_get_n_columns         (TrackerDBCursor     *cursor);
 const gchar*            tracker_db_cursor_get_variable_name     (TrackerDBCursor     *cursor,
                                                                  guint                column);
-const gchar**           tracker_db_cursor_get_variable_names    (TrackerDBCursor     *cursor);
 TrackerSparqlValueType  tracker_db_cursor_get_value_type        (TrackerDBCursor     *cursor,
                                                                  guint                column);
 void                    tracker_db_cursor_get_value             (TrackerDBCursor     *cursor,
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index cc633c3..6438863 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -2011,6 +2011,7 @@ fast_async_data_free (FastAsyncData *data)
 static void
 get_metadata_fast_cb (void     *buffer,
                       gssize    buffer_size,
+                      GStrv     variable_names,
                       GError   *error,
                       gpointer  user_data)
 {
@@ -2083,6 +2084,7 @@ get_metadata_fast_async (DBusConnection  *connection,
 	tracker_dbus_send_and_splice_async (connection,
 	                                    message,
 	                                    pipefd[0],
+	                                    FALSE,
 	                                    cancellable,
 	                                    get_metadata_fast_cb,
 	                                    data);
diff --git a/src/tracker-store/tracker-steroids.c b/src/tracker-store/tracker-steroids.c
index 3c49f05..538514d 100644
--- a/src/tracker-store/tracker-steroids.c
+++ b/src/tracker-store/tracker-steroids.c
@@ -266,6 +266,8 @@ query_inthread (TrackerDBCursor *cursor,
 	gint *column_offsets;
 	gint *column_types;
 	const gchar **column_data;
+	guint i;
+	GStrv variable_names = NULL;
 
 	ptr = g_slice_new0 (InThreadPtr);
 	info = user_data;
@@ -290,6 +292,11 @@ query_inthread (TrackerDBCursor *cursor,
 	column_data = alloca (n_columns * sizeof (gchar*));
 	column_types = alloca (n_columns * sizeof (gchar*));
 
+	variable_names = g_new0 (gchar *, n_columns);
+	for (i = 0; i < n_columns; i++) {
+		variable_names[i] = g_strdup (tracker_db_cursor_get_variable_name (cursor, i));
+	}
+
 	while (tracker_db_cursor_iter_next (cursor, cancellable, &loop_error)) {
 		gint i;
 		guint last_offset = -1;
@@ -373,8 +380,11 @@ end_query_inthread:
 
 	if (loop_error) {
 		ptr->error = loop_error;
+		if (variable_names) {
+			g_strfreev (variable_names);
+		}
 	} else {
-		ptr->variable_names = g_strdupv ((gchar **) tracker_db_cursor_get_variable_names (cursor));
+		ptr->variable_names = variable_names;
 	}
 
 	return ptr;
diff --git a/tests/functional-tests/shared-query-test.vala b/tests/functional-tests/shared-query-test.vala
index 2f0eba9..d3b35da 100644
--- a/tests/functional-tests/shared-query-test.vala
+++ b/tests/functional-tests/shared-query-test.vala
@@ -11,9 +11,14 @@ public class TestApp : GLib.Object {
 	}
 
 	int iter_cursor (Cursor cursor) {
+		int i;
+
+		for (i = 0; i < cursor.n_columns; i++) {
+			print ("%s%s", i != 0 ? " | " : "", cursor.get_variable_name (i));
+		}
+
 		try {
 			while (cursor.next()) {
-				int i;
 
 				for (i = 0; i < cursor.n_columns; i++) {
 					print ("%s%s", i != 0 ? ",":"", cursor.get_string (i));



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