[tracker/binary-log-2: 8/50] Fixed a few uint vs. int issues for consistency



commit 77b9e284e7987c390b31eb239aa0bc01cf161468
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jan 4 16:12:53 2010 +0100

    Fixed a few uint vs. int issues for consistency

 src/libtracker-common/tracker-class.c           |   26 ++++++++--------
 src/libtracker-common/tracker-class.h           |    4 +-
 src/libtracker-common/tracker-property.c        |   28 +++++++++---------
 src/libtracker-common/tracker-property.h        |    4 +-
 src/libtracker-data/tracker-data-manager.c      |    8 ++--
 src/libtracker-data/tracker-data-query.c        |    6 ++--
 src/libtracker-data/tracker-data-update.c       |   36 +++++++++++++---------
 src/libtracker-db/tracker-db-interface-sqlite.c |   23 ++++++++++++++
 src/libtracker-db/tracker-db-interface.c        |   19 ++++++++++++
 src/libtracker-db/tracker-db-interface.h        |   11 +++++++
 10 files changed, 112 insertions(+), 53 deletions(-)
---
diff --git a/src/libtracker-common/tracker-class.c b/src/libtracker-common/tracker-class.c
index 1f81dfe..e79fda7 100644
--- a/src/libtracker-common/tracker-class.c
+++ b/src/libtracker-common/tracker-class.c
@@ -37,7 +37,7 @@ struct _TrackerClassPriv {
 	gchar *uri;
 	gchar *name;
 	gint count;
-	gint id;
+	guint32 id;
 
 	GArray *super_classes;
 };
@@ -96,13 +96,13 @@ tracker_class_class_init (TrackerClassClass *klass)
 	                                                   G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
 	                                 PROP_ID,
-	                                 g_param_spec_int ("id",
-	                                                   "id",
-	                                                   "Id",
-	                                                   0,
-	                                                   INT_MAX,
-	                                                   0,
-	                                                   G_PARAM_READABLE | G_PARAM_WRITABLE));
+	                                 g_param_spec_uint ("id",
+	                                                    "id",
+	                                                    "Id",
+	                                                    0,
+	                                                    G_MAXUINT,
+	                                                    0,
+	                                                    G_PARAM_READABLE | G_PARAM_WRITABLE));
 
 	g_type_class_add_private (object_class, sizeof (TrackerClassPriv));
 }
@@ -114,7 +114,7 @@ tracker_class_init (TrackerClass *service)
 
 	priv = GET_PRIV (service);
 
-	priv->id = -1;
+	priv->id = 0;
 	priv->super_classes = g_array_new (TRUE, TRUE, sizeof (TrackerClass *));
 }
 
@@ -154,7 +154,7 @@ class_get_property (GObject    *object,
 		g_value_set_int (value, priv->count);
 		break;
 	case PROP_ID:
-		g_value_set_int (value, priv->id);
+		g_value_set_uint (value, priv->id);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -179,7 +179,7 @@ class_set_property (GObject      *object,
 		break;
 	case PROP_ID:
 		tracker_class_set_id (TRACKER_CLASS (object),
-		                      g_value_get_int (value));
+		                      g_value_get_uint (value));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -233,7 +233,7 @@ tracker_class_get_count (TrackerClass *service)
 	return priv->count;
 }
 
-gint
+guint32
 tracker_class_get_id (TrackerClass *service)
 {
 	TrackerClassPriv *priv;
@@ -316,7 +316,7 @@ tracker_class_set_count (TrackerClass *service,
 
 void
 tracker_class_set_id (TrackerClass *service,
-                      gint          value)
+                      guint32       value)
 {
 	TrackerClassPriv *priv;
 
diff --git a/src/libtracker-common/tracker-class.h b/src/libtracker-common/tracker-class.h
index ceca625..2643fb5 100644
--- a/src/libtracker-common/tracker-class.h
+++ b/src/libtracker-common/tracker-class.h
@@ -52,7 +52,7 @@ TrackerClass *  tracker_class_new               (void);
 const gchar *   tracker_class_get_uri           (TrackerClass  *service);
 const gchar *   tracker_class_get_name          (TrackerClass  *service);
 gint            tracker_class_get_count         (TrackerClass  *service);
-gint            tracker_class_get_id            (TrackerClass  *service);
+guint32         tracker_class_get_id            (TrackerClass  *service);
 
 TrackerClass  **tracker_class_get_super_classes (TrackerClass  *service);
 void            tracker_class_set_uri           (TrackerClass  *service,
@@ -64,7 +64,7 @@ void            tracker_class_set_super_classes (TrackerClass  *self,
 void            tracker_class_add_super_class   (TrackerClass  *self,
                                                  TrackerClass  *value);
 void            tracker_class_set_id            (TrackerClass  *service,
-                                                 gint           id);
+                                                 guint32        id);
 
 G_END_DECLS
 
diff --git a/src/libtracker-common/tracker-property.c b/src/libtracker-common/tracker-property.c
index 5f1ca2b..9527e0b 100644
--- a/src/libtracker-common/tracker-property.c
+++ b/src/libtracker-common/tracker-property.c
@@ -47,7 +47,7 @@ struct _TrackerPropertyPriv {
 	TrackerClass   *domain;
 	TrackerClass   *range;
 	gint           weight;
-	gint           id;
+	guint32        id;
 	gboolean       indexed;
 	gboolean       fulltext_indexed;
 	gboolean       embedded;
@@ -203,13 +203,13 @@ tracker_property_class_init (TrackerPropertyClass *klass)
 	                                                   G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
 	                                 PROP_ID,
-	                                 g_param_spec_int ("id",
-	                                                   "id",
-	                                                   "Id",
-	                                                   0,
-	                                                   G_MAXINT,
-	                                                   1,
-	                                                   G_PARAM_READWRITE));
+	                                 g_param_spec_uint ("id",
+	                                                    "id",
+	                                                    "Id",
+	                                                    0,
+	                                                    G_MAXUINT,
+	                                                    0,
+	                                                    G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
 	                                 PROP_INDEXED,
 	                                 g_param_spec_boolean ("indexed",
@@ -271,7 +271,7 @@ tracker_property_init (TrackerProperty *field)
 
 	priv = GET_PRIV (field);
 
-	priv->id = -1;
+	priv->id = 0;
 	priv->weight = 1;
 	priv->embedded = TRUE;
 	priv->filtered = TRUE;
@@ -333,7 +333,7 @@ property_get_property (GObject    *object,
 		g_value_set_int (value, priv->weight);
 		break;
 	case PROP_ID:
-		g_value_set_int (value, priv->id);
+		g_value_set_uint (value, priv->id);
 		break;
 	case PROP_INDEXED:
 		g_value_set_boolean (value, priv->indexed);
@@ -391,7 +391,7 @@ property_set_property (GObject      *object,
 		break;
 	case PROP_ID:
 		tracker_property_set_id (TRACKER_PROPERTY (object),
-		                         g_value_get_int (value));
+		                         g_value_get_uint (value));
 		break;
 	case PROP_INDEXED:
 		tracker_property_set_indexed (TRACKER_PROPERTY (object),
@@ -553,12 +553,12 @@ tracker_property_get_weight (TrackerProperty *field)
 	return priv->weight;
 }
 
-gint
+guint32
 tracker_property_get_id (TrackerProperty *field)
 {
 	TrackerPropertyPriv *priv;
 
-	g_return_val_if_fail (TRACKER_IS_PROPERTY (field), -1);
+	g_return_val_if_fail (TRACKER_IS_PROPERTY (field), 0);
 
 	priv = GET_PRIV (field);
 
@@ -805,7 +805,7 @@ tracker_property_set_weight (TrackerProperty *field,
 
 void
 tracker_property_set_id (TrackerProperty *field,
-                         gint             value)
+                         guint32          value)
 {
 	TrackerPropertyPriv *priv;
 	g_return_if_fail (TRACKER_IS_PROPERTY (field));
diff --git a/src/libtracker-common/tracker-property.h b/src/libtracker-common/tracker-property.h
index 1ec000d..6ac84c8 100644
--- a/src/libtracker-common/tracker-property.h
+++ b/src/libtracker-common/tracker-property.h
@@ -79,7 +79,7 @@ TrackerPropertyType tracker_property_get_data_type        (TrackerProperty
 TrackerClass *      tracker_property_get_domain           (TrackerProperty      *property);
 TrackerClass *      tracker_property_get_range            (TrackerProperty      *property);
 gint                tracker_property_get_weight           (TrackerProperty      *property);
-gint                tracker_property_get_id               (TrackerProperty      *property);
+guint32             tracker_property_get_id               (TrackerProperty      *property);
 gboolean            tracker_property_get_indexed          (TrackerProperty      *property);
 gboolean            tracker_property_get_fulltext_indexed (TrackerProperty      *property);
 gboolean            tracker_property_get_embedded         (TrackerProperty      *property);
@@ -100,7 +100,7 @@ void                tracker_property_set_range            (TrackerProperty
 void                tracker_property_set_weight           (TrackerProperty      *property,
                                                            gint                  value);
 void                tracker_property_set_id               (TrackerProperty      *property,
-                                                           gint                  value);
+                                                           guint32               value);
 void                tracker_property_set_indexed          (TrackerProperty      *property,
                                                            gboolean              value);
 void                tracker_property_set_fulltext_indexed (TrackerProperty      *property,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c9cc411..1995c98 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -406,12 +406,12 @@ db_get_static_data (TrackerDBInterface *iface)
 		while (tracker_db_cursor_iter_next (cursor)) {
 			TrackerClass *class;
 			const gchar  *uri;
-			gint          id;
+			guint         id;
 			gint          count;
 
 			class = tracker_class_new ();
 
-			id = tracker_db_cursor_get_int (cursor, 0);
+			id = tracker_db_cursor_get_uint (cursor, 0);
 			uri = tracker_db_cursor_get_string (cursor, 1);
 
 			tracker_class_set_uri (class, uri);
@@ -461,11 +461,11 @@ db_get_static_data (TrackerDBInterface *iface)
 			const gchar     *uri, *domain_uri, *range_uri;
 			gboolean         multi_valued, indexed, fulltext_indexed;
 			gboolean         transient, annotation, is_inverse_functional_property;
-			gint             id;
+			guint             id;
 
 			property = tracker_property_new ();
 
-			id = tracker_db_cursor_get_int (cursor, 0);
+			id = tracker_db_cursor_get_uint (cursor, 0);
 			uri = tracker_db_cursor_get_string (cursor, 1);
 			domain_uri = tracker_db_cursor_get_string (cursor, 2);
 			range_uri = tracker_db_cursor_get_string (cursor, 3);
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index cc31804..ada9672 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -73,12 +73,12 @@ tracker_data_query_rdf_type (guint32 id)
 }
 
 guint32
-tracker_data_query_resource_id (const gchar        *uri)
+tracker_data_query_resource_id (const gchar *uri)
 {
 	TrackerDBCursor *cursor;
 	TrackerDBInterface *iface;
 	TrackerDBStatement *stmt;
-	guint32                     id = 0;
+	guint32 id = 0;
 
 	g_return_val_if_fail (uri != NULL, 0);
 
@@ -92,7 +92,7 @@ tracker_data_query_resource_id (const gchar        *uri)
 
 	if (cursor) {
 		tracker_db_cursor_iter_next (cursor);
-		id = tracker_db_cursor_get_int (cursor, 0);
+		id = tracker_db_cursor_get_uint (cursor, 0);
 		g_object_unref (cursor);
 	}
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 56e01c2..c901bd0 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -415,6 +415,9 @@ statement_bind_gvalue (TrackerDBStatement *stmt,
 	case G_TYPE_INT:
 		tracker_db_statement_bind_int (stmt, idx, g_value_get_int (value));
 		break;
+	case G_TYPE_UINT:
+		tracker_db_statement_bind_uint (stmt, idx, g_value_get_uint (value));
+		break;
 	case G_TYPE_INT64:
 		tracker_db_statement_bind_int64 (stmt, idx, g_value_get_int64 (value));
 		break;
@@ -645,7 +648,8 @@ static void
 tracker_data_blank_buffer_flush (GError **error)
 {
 	/* end of blank node */
-	gint i, id;
+	gint i;
+	guint32 id;
 	gchar *subject;
 	gchar *blank_uri;
 	const gchar *sha1;
@@ -771,6 +775,8 @@ value_equal (GValue *value1,
 	switch (type) {
 	case G_TYPE_STRING:
 		return (strcmp (g_value_get_string (value1), g_value_get_string (value2)) == 0);
+	case G_TYPE_UINT:
+		return g_value_get_uint (value1) == g_value_get_uint (value2);
 	case G_TYPE_INT:
 		return g_value_get_int (value1) == g_value_get_int (value2);
 	case G_TYPE_DOUBLE:
@@ -966,7 +972,7 @@ string_to_gvalue (const gchar         *value,
                   TrackerPropertyType  type,
                   GValue              *gvalue)
 {
-	guint32                     object_id;
+	guint32 object_id;
 
 	switch (type) {
 	case TRACKER_PROPERTY_TYPE_STRING:
@@ -994,8 +1000,8 @@ string_to_gvalue (const gchar         *value,
 		break;
 	case TRACKER_PROPERTY_TYPE_RESOURCE:
 		object_id = ensure_resource_id (value);
-		g_value_init (gvalue, G_TYPE_INT);
-		g_value_set_int (gvalue, object_id);
+		g_value_init (gvalue, G_TYPE_UINT);
+		g_value_set_uint (gvalue, object_id);
 		break;
 	default:
 		g_warn_if_reached ();
@@ -1239,7 +1245,7 @@ tracker_data_delete_statement (const gchar  *graph,
 {
 	TrackerClass       *class;
 	TrackerProperty    *field;
-	gint                subject_id;
+	guint32             subject_id;
 
 	g_return_if_fail (subject != NULL);
 	g_return_if_fail (predicate != NULL);
@@ -1286,14 +1292,14 @@ tracker_data_delete_statement (const gchar  *graph,
 	} else {
 		field = tracker_ontology_get_property_by_uri (predicate);
 		if (field != NULL) {
-			gint id = tracker_property_get_id (field);
+			guint32 id = tracker_property_get_id (field);
 			if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
 				tracker_db_journal_append_delete_statement_code (resource_buffer->id,
-					(id != -1) ? id : tracker_data_query_resource_id (predicate),
+					(id != 0) ? id : tracker_data_query_resource_id (predicate),
 					query_resource_id (object));
 			} else {
 				tracker_db_journal_append_delete_statement (resource_buffer->id,
-					(id != -1) ? id : tracker_data_query_resource_id (predicate),
+					(id != 0) ? id : tracker_data_query_resource_id (predicate),
 					object);
 			}
 
@@ -1434,7 +1440,7 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 	GError          *actual_error = NULL;
 	TrackerClass    *class;
 	TrackerProperty *property;
-	gint             prop_id = -1;
+	guint32          prop_id = 0;
 
 	g_return_if_fail (subject != NULL);
 	g_return_if_fail (predicate != NULL);
@@ -1505,7 +1511,7 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 	}
 
 	tracker_db_journal_append_insert_statement_code (resource_buffer->id,
-		(prop_id != -1) ? prop_id : tracker_data_query_resource_id (predicate),
+		(prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate),
 		query_resource_id (object));
 
 	if (strcmp (predicate, RDF_PREFIX "type") == 0) {
@@ -1553,7 +1559,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 {
 	GError          *actual_error = NULL;
 	TrackerProperty *property;
-	gint             id = -1;
+	guint32          id = 0;
 
 	g_return_if_fail (subject != NULL);
 	g_return_if_fail (predicate != NULL);
@@ -1584,7 +1590,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 	}
 
 	tracker_db_journal_append_insert_statement (resource_buffer->id,
-		(id != -1) ? id : tracker_data_query_resource_id (predicate),
+		(id != 0) ? id : tracker_data_query_resource_id (predicate),
 		object);
 
 	/* add value to metadata database */
@@ -1912,11 +1918,11 @@ tracker_data_delete_resource_description (const gchar *graph,
 	TrackerDBStatement *stmt;
 	TrackerDBResultSet *result_set, *single_result, *multi_result;
 	TrackerClass       *class;
-	GString                    *sql;
-	TrackerProperty           **properties, *property;
+	GString            *sql;
+	TrackerProperty   **properties, *property;
 	int                 i;
 	gboolean            first, bail_out = FALSE;
-	gint                resource_id;
+	guint32             resource_id;
 	guint               p, n_props;
 
 	/* We use result_sets instead of cursors here because it's possible
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 65b9810..144c20d 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -997,6 +997,19 @@ tracker_db_statement_sqlite_bind_int (TrackerDBStatement         *stmt,
 	sqlite3_bind_int (priv->stmt, index + 1, value);
 }
 
+static void
+tracker_db_statement_sqlite_bind_uint (TrackerDBStatement         *stmt,
+                                      int                         index,
+                                      guint                       value)
+{
+	TrackerDBStatementSqlitePrivate *priv;
+
+	priv = TRACKER_DB_STATEMENT_SQLITE_GET_PRIVATE (stmt);
+
+	g_assert (!priv->stmt_is_sunk);
+
+	sqlite3_bind_int64 (priv->stmt, index + 1, (gint64) value);
+}
 
 
 static void
@@ -1117,6 +1130,14 @@ tracker_db_cursor_sqlite_get_int (TrackerDBCursor *cursor,  guint column)
 	return (gint) sqlite3_column_int (priv->stmt, column);
 }
 
+static guint
+tracker_db_cursor_sqlite_get_uint (TrackerDBCursor *cursor,  guint column)
+{
+	TrackerDBCursorSqlitePrivate *priv;
+	priv = TRACKER_DB_CURSOR_SQLITE_GET_PRIVATE (cursor);
+	return (guint) sqlite3_column_int64 (priv->stmt, column);
+}
+
 
 static gdouble
 tracker_db_cursor_sqlite_get_double (TrackerDBCursor *cursor,  guint column)
@@ -1188,6 +1209,7 @@ tracker_db_statement_sqlite_iface_init (TrackerDBStatementIface *iface)
 {
 	iface->bind_double = tracker_db_statement_sqlite_bind_double;
 	iface->bind_int = tracker_db_statement_sqlite_bind_int;
+	iface->bind_uint = tracker_db_statement_sqlite_bind_uint;
 	iface->bind_int64 = tracker_db_statement_sqlite_bind_int64;
 	iface->bind_null = tracker_db_statement_sqlite_bind_null;
 	iface->bind_text = tracker_db_statement_sqlite_bind_text;
@@ -1206,6 +1228,7 @@ tracker_db_cursor_sqlite_iface_init (TrackerDBCursorIface *iface)
 	iface->get_int = tracker_db_cursor_sqlite_get_int;
 	iface->get_double = tracker_db_cursor_sqlite_get_double;
 	iface->get_string = tracker_db_cursor_sqlite_get_string;
+	iface->get_uint = tracker_db_cursor_sqlite_get_uint;
 }
 
 static void
diff --git a/src/libtracker-db/tracker-db-interface.c b/src/libtracker-db/tracker-db-interface.c
index 210aed7..db296b2 100644
--- a/src/libtracker-db/tracker-db-interface.c
+++ b/src/libtracker-db/tracker-db-interface.c
@@ -428,6 +428,17 @@ tracker_db_statement_bind_int (TrackerDBStatement       *stmt,
 
 
 void
+tracker_db_statement_bind_uint (TrackerDBStatement       *stmt,
+                               int                       idx,
+                               guint                     value)
+{
+	g_return_if_fail (TRACKER_IS_DB_STATEMENT (stmt));
+
+	TRACKER_DB_STATEMENT_GET_IFACE (stmt)->bind_uint (stmt, idx, value);
+}
+
+
+void
 tracker_db_statement_bind_int64 (TrackerDBStatement     *stmt,
                                  int                     idx,
                                  gint64                          value)
@@ -528,6 +539,14 @@ tracker_db_cursor_get_int (TrackerDBCursor *cursor, guint            column)
 	return TRACKER_DB_CURSOR_GET_IFACE (cursor)->get_int (cursor, column);
 }
 
+guint
+tracker_db_cursor_get_uint (TrackerDBCursor *cursor, guint            column)
+{
+	g_return_val_if_fail (TRACKER_IS_DB_CURSOR (cursor), -1);
+
+	return TRACKER_DB_CURSOR_GET_IFACE (cursor)->get_uint (cursor, column);
+}
+
 gdouble
 tracker_db_cursor_get_double (TrackerDBCursor *cursor, guint            column)
 {
diff --git a/src/libtracker-db/tracker-db-interface.h b/src/libtracker-db/tracker-db-interface.h
index 1f9dae7..7c466a8 100644
--- a/src/libtracker-db/tracker-db-interface.h
+++ b/src/libtracker-db/tracker-db-interface.h
@@ -89,6 +89,9 @@ struct TrackerDBStatementIface {
 	void                 (* bind_int)       (TrackerDBStatement  *stmt,
 	                                         int                  index,
 	                                         int                  value);
+	void                 (* bind_uint)      (TrackerDBStatement  *stmt,
+	                                         int                  index,
+	                                         guint                value);
 	void                 (* bind_int64)     (TrackerDBStatement  *stmt,
 	                                         int                  index,
 	                                         gint64                       value);
@@ -126,6 +129,9 @@ struct TrackerDBCursorIface {
 	                                guint            column);
 	gdouble       (*get_double)    (TrackerDBCursor *cursor,
 	                                guint            column);
+	guint         (*get_uint)       (TrackerDBCursor *cursor,
+	                                 guint            column);
+
 };
 
 GQuark              tracker_db_interface_error_quark       (void);
@@ -159,6 +165,9 @@ void                tracker_db_statement_bind_double       (TrackerDBStatement
 void                tracker_db_statement_bind_int          (TrackerDBStatement  *stmt,
                                                             int                  index,
                                                             int                  value);
+void                tracker_db_statement_bind_uint         (TrackerDBStatement  *stmt,
+                                                            int                  index,
+                                                            guint                value);
 void                tracker_db_statement_bind_int64        (TrackerDBStatement  *stmt,
                                                             int                  index,
                                                             gint64               value);
@@ -203,6 +212,8 @@ gint                tracker_db_cursor_get_int              (TrackerDBCursor
                                                             guint                column);
 gdouble             tracker_db_cursor_get_double           (TrackerDBCursor     *cursor,
                                                             guint                column);
+guint               tracker_db_cursor_get_uint              (TrackerDBCursor     *cursor,
+                                                             guint                column);
 
 G_END_DECLS
 



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