[tracker/return-types: 14/26] Fixed that you need to run cursor.next() a first time to get a correct cursor.n_columns



commit da6e7ee693145612b615f8ac8531424f0168644a
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Sep 10 14:01:46 2010 +0200

    Fixed that you need to run cursor.next() a first time to get a correct cursor.n_columns

 src/libtracker-bus/tracker-bus-fd-cursor.c    |    4 ++++
 tests/functional-tests/shared-query-test.vala |   19 ++++++-------------
 2 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index 2d54aa5..a9985fc 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -292,6 +292,9 @@ tracker_bus_fd_query (DBusGConnection  *gconnection,
 	                              (gssize *) &cursor->buffer_size,
 	                              &cursor->variable_names,
 	                              &inner_error);
+
+	cursor->n_columns = g_strv_length (cursor->variable_names);
+
 	/* message is destroyed by tracker_dbus_send_and_splice */
 
 	if (G_UNLIKELY (inner_error)) {
@@ -333,6 +336,7 @@ query_async_cb (gpointer  buffer,
 		cursor->buffer = buffer;
 		cursor->buffer_size = buffer_size;
 		cursor->variable_names = g_strdupv (variable_names);
+		cursor->n_columns = g_strv_length (cursor->variable_names);
 
 		g_simple_async_result_set_op_res_gpointer (res, cursor, g_object_unref);
 	}
diff --git a/tests/functional-tests/shared-query-test.vala b/tests/functional-tests/shared-query-test.vala
index 334d0e8..3fc3ea5 100644
--- a/tests/functional-tests/shared-query-test.vala
+++ b/tests/functional-tests/shared-query-test.vala
@@ -11,22 +11,15 @@ public class TestApp : GLib.Object {
 	}
 
 	int iter_cursor (Cursor cursor) {
-		bool first = true;
+		int i;
 
 		try {
-			while (cursor.next()) {
-				int i;
-
-				// Apparently for async I need to do a first cursor.next()
-				// before cursor.n_columns is correct :-\
+			for (i = 0; i < cursor.n_columns; i++) {
+				print ("| %s ", cursor.get_variable_name (i));
+			}
+			print ("| -> %d columns\n", cursor.n_columns);
 
-				if (first) {
-					for (i = 0; i < cursor.n_columns; i++) {
-						print ("| %s ", cursor.get_variable_name (i));
-					}
-					print ("| -> %d columns\n", cursor.n_columns);
-					first = false;
-				}
+			while (cursor.next()) {
 
 				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]