[tracker] libtracker-sparql: cursor_get_n_columns() should only be called after cursor_next()



commit 750f4de46cb6a983fcc9165538cdb0f3679f42c5
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Mon Aug 23 17:39:29 2010 +0200

    libtracker-sparql: cursor_get_n_columns() should only be called after cursor_next()

 src/libtracker-sparql/tracker-cursor.vala |    3 +++
 src/tracker-utils/tracker-sparql.c        |   18 ++++++------------
 2 files changed, 9 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-cursor.vala b/src/libtracker-sparql/tracker-cursor.vala
index 5aaa0d8..5d0e4cf 100644
--- a/src/libtracker-sparql/tracker-cursor.vala
+++ b/src/libtracker-sparql/tracker-cursor.vala
@@ -71,6 +71,9 @@ public abstract class Tracker.Sparql.Cursor : Object {
 		 * @self: a #TrackerSparqlCursor
 		 *
 		 * Returns the number of columns available in the results to iterate.
+		 * This method should only be called after a successful
+		 * tracker_sparql_cursor_next(); otherwise its return value will be
+		 * undefined.
 		 *
 		 * Returns: a #gint with the number of columns.
 		 */
diff --git a/src/tracker-utils/tracker-sparql.c b/src/tracker-utils/tracker-sparql.c
index 7b17975..f489951 100644
--- a/src/tracker-utils/tracker-sparql.c
+++ b/src/tracker-utils/tracker-sparql.c
@@ -178,19 +178,13 @@ print_cursor (TrackerSparqlCursor *cursor,
 				count++;
 			}
 		} else {
-			gint n_cols;
-
-			n_cols = tracker_sparql_cursor_get_n_columns (cursor);
-
 			while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
 				gint col;
 
-				for (col = 0; col < n_cols; col++) {
-					if (col == 0) {
-						g_print ("  %s", tracker_sparql_cursor_get_string (cursor, col, NULL));
-					} else {
-						g_print (", %s", tracker_sparql_cursor_get_string (cursor, col, NULL));
-					}
+				for (col = 0; col < tracker_sparql_cursor_get_n_columns (cursor); col++) {
+					g_print ("%c %s",
+					         col == 0 ? ' ' : ',',
+					         tracker_sparql_cursor_get_string (cursor, col, NULL));
 				}
 
 				g_print ("\n");
@@ -536,8 +530,8 @@ main (int argc, char **argv)
 						n = 0;
 						while (g_hash_table_iter_next (&iter, &key, &value)) {
 							g_print ("%s%s: %s",
-							         n > 0 ? ", " : "", 
-							         (const gchar *) key, 
+							         n > 0 ? ", " : "",
+							         (const gchar *) key,
 							         (const gchar *) value);
 							n++;
 						}



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