[tracker/return-types: 4/18] libtracker-data: Implement tracker_sqlite_cursor_get_value_type



commit 871398b2cfc58dbbc4f475e6f9291bf30fd447b5
Author: Jürg Billeter <j bitron ch>
Date:   Wed Sep 8 18:39:38 2010 +0200

    libtracker-data: Implement tracker_sqlite_cursor_get_value_type

 src/libtracker-data/tracker-db-interface-sqlite.c |   27 ++++++++++++++++----
 1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 1fc13ef..28f0a70 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1310,13 +1310,28 @@ tracker_db_cursor_get_double (TrackerDBCursor *cursor,  guint 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);
+	gint n_columns = sqlite3_column_count (cursor->stmt);
 
-	return TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
+	g_return_val_if_fail (column >= 0 && column < n_columns, TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+
+	if (sqlite3_column_type (cursor->stmt, column) == SQLITE_NULL) {
+		return TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
+	} else if (column < cursor->n_types) {
+		switch (cursor->types[column]) {
+		case TRACKER_PROPERTY_TYPE_RESOURCE:
+			return TRACKER_SPARQL_VALUE_TYPE_URI;
+		case TRACKER_PROPERTY_TYPE_INTEGER:
+			return TRACKER_SPARQL_VALUE_TYPE_INTEGER;
+		case TRACKER_PROPERTY_TYPE_DOUBLE:
+			return TRACKER_SPARQL_VALUE_TYPE_DOUBLE;
+		case TRACKER_PROPERTY_TYPE_DATETIME:
+			return TRACKER_SPARQL_VALUE_TYPE_DATETIME;
+		default:
+			return TRACKER_SPARQL_VALUE_TYPE_STRING;
+		}
+	} else {
+		return TRACKER_SPARQL_VALUE_TYPE_STRING;
+	}
 }
 
 const gchar*



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