[tracker/return-types: 1/26] libtracker-sparql, -bus, -data: Added ValueTypes and variable-names APIs to cursor



commit 8eba7915c7a0d573f3a4866f65ec6c2e32806dd5
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Sep 7 17:51:10 2010 +0200

    libtracker-sparql, -bus, -data: Added ValueTypes and variable-names APIs to cursor

 src/libtracker-bus/tracker-array-cursor.vala      |   18 +++
 src/libtracker-bus/tracker-bus-fd-cursor.c        |   26 ++++
 src/libtracker-data/tracker-db-interface-sqlite.c |   25 ++++
 src/libtracker-data/tracker-db-interface.h        |  134 +++++++++++----------
 src/libtracker-sparql/tracker-cursor.vala         |   43 +++++++
 5 files changed, 182 insertions(+), 64 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-array-cursor.vala b/src/libtracker-bus/tracker-array-cursor.vala
index 25ab5fd..df288ff 100644
--- a/src/libtracker-bus/tracker-array-cursor.vala
+++ b/src/libtracker-bus/tracker-array-cursor.vala
@@ -31,6 +31,24 @@ internal class Tracker.Bus.ArrayCursor : Tracker.Sparql.Cursor {
 
 	public override int n_columns { get { return cols; } }
 
+	public override Sparql.ValueType get_value_type (int column)
+	requires (current_row >= 0) {
+
+		// TODO: Implement
+		critical ("Unimplemented");
+
+		return Sparql.ValueType.UNBOUND;
+	}
+
+	public override unowned string? get_variable_name (int column)
+	requires (current_row >= 0) {
+
+		// TODO: Implement
+		critical ("Unimplemented");
+
+		return null;
+	}
+
 	public override unowned string? get_string (int column, out long length = null)
 	requires (current_row >= 0) {
 		unowned string str;
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index d8adda9..6b678f9 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -158,6 +158,30 @@ tracker_bus_fd_cursor_get_n_columns (TrackerBusFDCursor *cursor)
 	return cursor->n_columns;
 }
 
+static TrackerSparqlValueType
+tracker_bus_fd_cursor_get_value_type (TrackerBusFDCursor *cursor,  guint column)
+{
+	/* TODO: Implement */
+
+	g_critical ("Unimplemented");
+
+	g_return_val_if_reached (TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+
+	return TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
+}
+
+static const gchar*
+tracker_bus_fd_cursor_get_variable_name (TrackerBusFDCursor *cursor,  guint column)
+{
+	/* TODO: Implement */
+
+	g_critical ("Unimplemented");
+
+	g_return_val_if_reached (NULL);
+
+	return NULL;
+}
+
 static const gchar *
 tracker_bus_fd_cursor_get_string (TrackerBusFDCursor *cursor,
                                   guint               column,
@@ -192,6 +216,8 @@ tracker_bus_fd_cursor_class_init (TrackerBusFDCursorClass *class)
 
 	object_class->finalize = tracker_bus_fd_cursor_finalize;
 
+	sparql_cursor_class->get_value_type = (TrackerSparqlValueType (*) (TrackerSparqlCursor *, gint)) tracker_bus_fd_cursor_get_value_type;
+	sparql_cursor_class->get_variable_name = (const gchar * (*) (TrackerSparqlCursor *, gint)) tracker_bus_fd_cursor_get_variable_name;
 	sparql_cursor_class->get_n_columns = (gint (*) (TrackerSparqlCursor *)) tracker_bus_fd_cursor_get_n_columns;
 	sparql_cursor_class->get_string = (const gchar * (*) (TrackerSparqlCursor *, gint, glong*)) tracker_bus_fd_cursor_get_string;
 	sparql_cursor_class->next = (gboolean (*) (TrackerSparqlCursor *, GCancellable *, GError **)) tracker_bus_fd_cursor_iter_next;
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index b601e0b..31eddf3 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1172,6 +1172,8 @@ tracker_db_cursor_class_init (TrackerDBCursorClass *class)
 
 	object_class->finalize = tracker_db_cursor_finalize;
 
+	sparql_cursor_class->get_value_type = (TrackerSparqlValueType (*) (TrackerSparqlCursor *, gint)) tracker_db_cursor_get_value_type;
+	sparql_cursor_class->get_variable_name = (const gchar * (*) (TrackerSparqlCursor *, gint)) tracker_db_cursor_get_variable_name;
 	sparql_cursor_class->get_n_columns = (gint (*) (TrackerSparqlCursor *)) tracker_db_cursor_get_n_columns;
 	sparql_cursor_class->get_string = (const gchar * (*) (TrackerSparqlCursor *, gint, glong*)) tracker_db_cursor_get_string;
 	sparql_cursor_class->next = (gboolean (*) (TrackerSparqlCursor *, GCancellable *, GError **)) tracker_db_cursor_iter_next;
@@ -1356,6 +1358,29 @@ tracker_db_cursor_get_double (TrackerDBCursor *cursor,  guint column)
 	return (gdouble) sqlite3_column_double (cursor->stmt, column);
 }
 
+TrackerSparqlValueType
+tracker_db_cursor_get_value_type (TrackerDBCursor *cursor,  guint column)
+{
+	/* TODO: Implement */
+
+	g_critical ("Unimplemented");
+
+	g_return_val_if_reached (TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+
+	return TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
+}
+
+const gchar*
+tracker_db_cursor_get_variable_name (TrackerDBCursor *cursor,  guint column)
+{
+	/* TODO: Implement */
+
+	g_critical ("Unimplemented");
+
+	g_return_val_if_reached (NULL);
+
+	return NULL;
+}
 
 const gchar*
 tracker_db_cursor_get_string (TrackerDBCursor *cursor,  guint column, glong *length)
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index 72b8560..ecf1275 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -23,6 +23,8 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
+#include <libtracker-sparql/tracker-sparql.h>
+
 G_BEGIN_DECLS
 
 #if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
@@ -75,79 +77,83 @@ typedef struct TrackerDBCursor         TrackerDBCursor;
 typedef struct TrackerDBCursorClass    TrackerDBCursorClass;
 typedef struct TrackerDBResultSetPrivate TrackerDBResultSetPrivate;
 
-GQuark              tracker_db_interface_error_quark       (void);
+GQuark                  tracker_db_interface_error_quark        (void);
 
-GType               tracker_db_interface_get_type          (void);
-GType               tracker_db_statement_get_type          (void);
-GType               tracker_db_cursor_get_type             (void);
-GType               tracker_db_result_set_get_type         (void);
+GType                   tracker_db_interface_get_type           (void);
+GType                   tracker_db_statement_get_type           (void);
+GType                   tracker_db_cursor_get_type              (void);
+GType                   tracker_db_result_set_get_type          (void);
 
 /* Functions to create queries/procedures */
-TrackerDBStatement *tracker_db_interface_create_statement  (TrackerDBInterface   *interface,
-                                                            GError              **error,
-                                                            const gchar          *query,
-                                                            ...) G_GNUC_PRINTF (3, 4);
-TrackerDBResultSet *tracker_db_interface_execute_vquery    (TrackerDBInterface   *interface,
-                                                            GError              **error,
-                                                            const gchar          *query,
-                                                            va_list               args);
-TrackerDBResultSet *tracker_db_interface_execute_query     (TrackerDBInterface   *interface,
-                                                            GError              **error,
-                                                            const gchar          *query,
-                                                            ...) G_GNUC_PRINTF (3, 4);
-
-gboolean            tracker_db_interface_start_transaction (TrackerDBInterface  *interface);
-gboolean            tracker_db_interface_end_db_transaction(TrackerDBInterface  *interface);
-void                tracker_db_statement_bind_double       (TrackerDBStatement  *stmt,
-                                                            int                  index,
-                                                            double               value);
-void                tracker_db_statement_bind_int          (TrackerDBStatement  *stmt,
-                                                            int                  index,
-                                                            gint64               value);
-void                tracker_db_statement_bind_null         (TrackerDBStatement  *stmt,
-                                                            int                  index);
-void                tracker_db_statement_bind_text         (TrackerDBStatement  *stmt,
-                                                            int                  index,
-                                                            const gchar         *value);
-TrackerDBResultSet *tracker_db_statement_execute           (TrackerDBStatement  *stmt,
-                                                            GError             **error);
-TrackerDBCursor *   tracker_db_statement_start_cursor      (TrackerDBStatement  *stmt,
-                                                            GError             **error);
+TrackerDBStatement *    tracker_db_interface_create_statement   (TrackerDBInterface   *interface,
+                                                                 GError              **error,
+                                                                 const gchar          *query,
+                                                                 ...) G_GNUC_PRINTF (3, 4);
+TrackerDBResultSet *    tracker_db_interface_execute_vquery     (TrackerDBInterface   *interface,
+                                                                 GError              **error,
+                                                                 const gchar          *query,
+                                                                 va_list               args);
+TrackerDBResultSet *    tracker_db_interface_execute_query      (TrackerDBInterface   *interface,
+                                                                 GError              **error,
+                                                                 const gchar          *query,
+                                                                  ...) G_GNUC_PRINTF (3, 4);
+
+gboolean                tracker_db_interface_start_transaction  (TrackerDBInterface  *interface);
+gboolean                tracker_db_interface_end_db_transaction (TrackerDBInterface  *interface);
+void                    tracker_db_statement_bind_double        (TrackerDBStatement  *stmt,
+                                                                 int                  index,
+                                                                 double               value);
+void                    tracker_db_statement_bind_int           (TrackerDBStatement  *stmt,
+                                                                 int                  index,
+                                                                 gint64               value);
+void                    tracker_db_statement_bind_null          (TrackerDBStatement  *stmt,
+                                                                 int                  index);
+void                    tracker_db_statement_bind_text          (TrackerDBStatement  *stmt,
+                                                                 int                  index,
+                                                                 const gchar         *value);
+TrackerDBResultSet *    tracker_db_statement_execute            (TrackerDBStatement  *stmt,
+                                                                 GError             **error);
+TrackerDBCursor *       tracker_db_statement_start_cursor       (TrackerDBStatement  *stmt,
+                                                                 GError             **error);
 
 /* Semi private TrackerDBResultSet functions */
-TrackerDBResultSet *_tracker_db_result_set_new             (guint                cols);
-void                _tracker_db_result_set_append          (TrackerDBResultSet  *result_set);
-void                _tracker_db_result_set_set_value       (TrackerDBResultSet  *result_set,
-                                                            guint                column,
-                                                            const GValue        *value);
-void                _tracker_db_result_set_get_value       (TrackerDBResultSet  *result_set,
-                                                            guint                column,
-                                                            GValue              *value);
+TrackerDBResultSet *    _tracker_db_result_set_new              (guint                cols);
+void                    _tracker_db_result_set_append           (TrackerDBResultSet  *result_set);
+void                    _tracker_db_result_set_set_value        (TrackerDBResultSet  *result_set,
+                                                                 guint                column,
+                                                                 const GValue        *value);
+void                    _tracker_db_result_set_get_value        (TrackerDBResultSet  *result_set,
+                                                                 guint                column,
+                                                                 GValue              *value);
 
 /* Functions to deal with the resultset */
-void                tracker_db_result_set_get              (TrackerDBResultSet  *result_set,
-                                                            ...);
-void                tracker_db_result_set_rewind           (TrackerDBResultSet  *result_set);
-gboolean            tracker_db_result_set_iter_next        (TrackerDBResultSet  *result_set);
-guint               tracker_db_result_set_get_n_columns    (TrackerDBResultSet  *result_set);
-guint               tracker_db_result_set_get_n_rows       (TrackerDBResultSet  *result_set);
+void                    tracker_db_result_set_get               (TrackerDBResultSet  *result_set,
+                                                                 ...);
+void                    tracker_db_result_set_rewind            (TrackerDBResultSet  *result_set);
+gboolean                tracker_db_result_set_iter_next         (TrackerDBResultSet  *result_set);
+guint                   tracker_db_result_set_get_n_columns     (TrackerDBResultSet  *result_set);
+guint                   tracker_db_result_set_get_n_rows        (TrackerDBResultSet  *result_set);
 
 /* Functions to deal with a cursor */
-void                tracker_db_cursor_rewind               (TrackerDBCursor     *cursor);
-gboolean            tracker_db_cursor_iter_next            (TrackerDBCursor     *cursor,
-                                                            GCancellable        *cancellable,
-                                                            GError             **error);
-guint               tracker_db_cursor_get_n_columns        (TrackerDBCursor     *cursor);
-void                tracker_db_cursor_get_value            (TrackerDBCursor     *cursor,
-                                                            guint                column,
-                                                            GValue              *value);
-const gchar*        tracker_db_cursor_get_string           (TrackerDBCursor     *cursor,
-                                                            guint                column,
-                                                            glong               *length);
-gint64              tracker_db_cursor_get_int              (TrackerDBCursor     *cursor,
-                                                            guint                column);
-gdouble             tracker_db_cursor_get_double           (TrackerDBCursor     *cursor,
-                                                            guint                column);
+void                    tracker_db_cursor_rewind                (TrackerDBCursor     *cursor);
+gboolean                tracker_db_cursor_iter_next             (TrackerDBCursor     *cursor,
+                                                                 GCancellable        *cancellable,
+                                                                 GError             **error);
+guint                   tracker_db_cursor_get_n_columns         (TrackerDBCursor     *cursor);
+const gchar*            tracker_db_cursor_get_variable_name     (TrackerDBCursor     *cursor,
+                                                                 guint                column);
+TrackerSparqlValueType  tracker_db_cursor_get_value_type        (TrackerDBCursor     *cursor,
+                                                                 guint                column);
+void                    tracker_db_cursor_get_value             (TrackerDBCursor     *cursor,
+                                                                 guint                column,
+                                                                 GValue              *value);
+const gchar*            tracker_db_cursor_get_string            (TrackerDBCursor     *cursor,
+                                                                 guint                column,
+                                                                 glong               *length);
+gint64                  tracker_db_cursor_get_int               (TrackerDBCursor     *cursor,
+                                                                 guint                column);
+gdouble                 tracker_db_cursor_get_double            (TrackerDBCursor     *cursor,
+                                                                 guint                column);
 
 G_END_DECLS
 
diff --git a/src/libtracker-sparql/tracker-cursor.vala b/src/libtracker-sparql/tracker-cursor.vala
index 5d0e4cf..ac41fb2 100644
--- a/src/libtracker-sparql/tracker-cursor.vala
+++ b/src/libtracker-sparql/tracker-cursor.vala
@@ -30,6 +30,27 @@
  * </para>
  */
 
+/**
+ * TrackerSparqlValueType:
+ * @TRACKER_SPARQL_VALUE_TYPE_UNBOUND: Unbound value type
+ * @TRACKER_SPARQL_VALUE_TYPE_URI: Uri value type, rdfs:Resource
+ * @TRACKER_SPARQL_VALUE_TYPE_STRING: String value type, xsd:string
+ * @TRACKER_SPARQL_VALUE_TYPE_INTEGER: Integer value type, xsd:integer
+ * @TRACKER_SPARQL_VALUE_TYPE_DOUBLE: Double value type, xsd:double
+ * @TRACKER_SPARQL_VALUE_TYPE_DATETIME: Datetime value type, xsd:dateTime
+ * @TRACKER_SPARQL_VALUE_TYPE_BLANK_NODE: Blank node value type
+ *
+ * Enumeration with the possible types of the cursor's cells
+ */
+public enum Tracker.Sparql.ValueType {
+	UNBOUND ,
+	URI,
+	STRING,
+	INTEGER,
+	DOUBLE,
+	DATETIME,
+	BLANK_NODE
+}
 
 /**
  * TrackerSparqlCursor:
@@ -81,6 +102,28 @@ public abstract class Tracker.Sparql.Cursor : Object {
 	}
 
 	/**
+	 * tracker_sparql_cursor_get_value_type:
+	 * @self: a #TrackerSparqlCursor
+	 * @column: column number to retrieve (first one is 0)
+	 *
+	 * Returns the value type at @column in the current row being iterated.
+	 *
+	 * Returns: a value type
+	 */
+	public abstract ValueType get_value_type (int column);
+
+	/**
+	 * tracker_sparql_cursor_get_variable_name:
+	 * @self: a #TrackerSparqlCursor
+	 * @column: column number to retrieve (first one is 0)
+	 *
+	 * Returns the variable name at @column.
+	 *
+	 * Returns: a string, which should not be freed by the caller.
+	 */
+	public abstract unowned string? get_variable_name (int column);
+
+	/**
 	 * tracker_sparql_cursor_get_string:
 	 * @self: a #TrackerSparqlCursor
 	 * @column: column number to retrieve (first one is 0)



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