[tracker] libtracker-db: Remove unused functions



commit 9c4b978e50487a16b626ba7c13e4ab26dbf57407
Author: Jürg Billeter <j bitron ch>
Date:   Thu Mar 18 12:46:35 2010 +0100

    libtracker-db: Remove unused functions

 src/libtracker-db/tracker-db-dbus.c        |  447 +---------------------------
 src/libtracker-db/tracker-db-dbus.h        |    9 -
 tests/libtracker-db/tracker-db-dbus-test.c |  135 ---------
 3 files changed, 5 insertions(+), 586 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-dbus.c b/src/libtracker-db/tracker-db-dbus.c
index 94d005b..8ac9e85 100644
--- a/src/libtracker-db/tracker-db-dbus.c
+++ b/src/libtracker-db/tracker-db-dbus.c
@@ -24,179 +24,10 @@
 
 #include "tracker-db-dbus.h"
 
-typedef struct {
-	gint     key;
-	gpointer value;
-} OneRow;
-
-typedef struct {
-	gpointer value;
-} OneElem;
-
-static inline void
-row_add (GPtrArray *row,
-         gchar     *value)
-{
-	OneElem *elem;
-	GSList  *list = NULL;
-
-	elem = g_slice_new (OneElem);
-	list = NULL;
-
-	list = g_slist_prepend (list, value);
-	elem->value = list;
-	g_ptr_array_add (row, elem);
-}
-
-static inline gboolean
-row_insert (GPtrArray *row,
-            gchar     *value,
-            guint      lindex)
-{
-	OneElem *elem;
-	GSList  *list;
-	GSList  *iter;
-
-	elem = g_ptr_array_index (row, lindex);
-	list = elem->value;
-
-	/* We check for duplicate values here so that
-	 * we can have several multivalued fields in
-	 * the same query.
-	 */
-	for (iter = list; iter; iter=iter->next) {
-		if (strcmp (iter->data, value) == 0) {
-			return FALSE;
-		}
-	}
-
-	list = g_slist_prepend (list, value);
-	elem->value = list;
-
-	return TRUE;
-}
-
-static inline void
-row_destroy (GPtrArray *row)
-{
-	guint i;
-
-	for (i = 0; i < row->len; i++) {
-		OneElem *elem;
-		GSList  *list;
-
-		elem = g_ptr_array_index (row, i);
-		list = elem->value;
-		g_slist_foreach (list,
-		                 (GFunc) g_free,
-		                 NULL);
-		g_slist_free (list);
-		g_slice_free (OneElem, elem);
-	}
-
-	g_ptr_array_free (row, TRUE);
-}
-
-static inline gpointer
-rows_lookup (GPtrArray *rows,
-             gint       key)
-{
-	guint    i;
-	gpointer value = NULL;
-
-	for (i = 0; i < rows->len; i++) {
-		OneRow *row;
-
-		row = g_ptr_array_index (rows, i);
-
-		if (row->key == key) {
-			value = row->value;
-			break;
-		}
-	}
-
-	return value;
-}
-
-static inline void
-rows_destroy (GPtrArray *rows)
-{
-	guint i;
-
-	for (i = 0; i < rows->len; i++) {
-		OneRow *row;
-
-		row = g_ptr_array_index (rows, i);
-		row_destroy (row->value);
-		g_slice_free (OneRow, row);
-	}
-
-	g_ptr_array_free (rows, TRUE);
-}
-
-static inline void
-rows_add (GPtrArray *rows,
-          gint       key,
-          gpointer   value)
-{
-	OneRow *row;
-
-	row = g_slice_new (OneRow);
-
-	row->key = key;
-	row->value = value;
-
-	g_ptr_array_add (rows, row);
-}
-
-static inline void
-rows_migrate (GPtrArray *rows,
-              GPtrArray *result)
-{
-	guint i, j;
-
-	/* Go thought the lists and join with | separator */
-	for (i = 0; i < rows->len; i++) {
-		OneRow     *row;
-		GPtrArray  *array;
-		gchar     **strv;
-
-		row   = g_ptr_array_index (rows, i);
-		array = row->value;
-
-		strv = g_new0 (gchar*, array->len + 1);
-
-		for (j = 0; j < array->len; j++) {
-			OneElem *elem;
-			GSList  *list;
-			GSList  *iter;
-			GString *string;
-
-			elem   = g_ptr_array_index (array, j);
-			list   = elem->value;
-			string = g_string_new((gchar *)list->data);
-
-			for (iter = list->next; iter; iter = iter->next) {
-				g_string_append_printf (string, "|%s", (gchar *)iter->data);
-			}
-
-			strv[j] = string->str;
-
-			g_string_free (string, FALSE);
-		}
-
-		strv[array->len] = NULL;
-
-		g_ptr_array_add (result, strv);
-	}
-}
-
-static gchar **
-dbus_query_result_to_strv (TrackerDBResultSet *result_set,
-                           gint                        column,
-                           gint                       *count,
-                           gboolean            numeric)
-
+gchar **
+tracker_dbus_query_result_to_strv (TrackerDBResultSet *result_set,
+                                   gint                column,
+                                   gint               *count)
 {
 	gchar **strv = NULL;
 	gint    rows = 0;
@@ -205,7 +36,6 @@ dbus_query_result_to_strv (TrackerDBResultSet *result_set,
 	if (result_set) {
 		gchar    *str;
 		gboolean  valid = TRUE;
-		gint      value;
 
 		/* Make sure we rewind before iterating the result set */
 		tracker_db_result_set_rewind (result_set);
@@ -214,12 +44,7 @@ dbus_query_result_to_strv (TrackerDBResultSet *result_set,
 		strv = g_new (gchar*, rows + 1);
 
 		while (valid) {
-			if (numeric) {
-				tracker_db_result_set_get (result_set, column, &value, -1);
-				str = g_strdup_printf ("%d", value);
-			} else {
-				tracker_db_result_set_get (result_set, column, &str, -1);
-			}
+			tracker_db_result_set_get (result_set, column, &str, -1);
 
 			if (!str) {
 				valid = tracker_db_result_set_iter_next (result_set);
@@ -246,178 +71,6 @@ dbus_query_result_to_strv (TrackerDBResultSet *result_set,
 	return strv;
 }
 
-gchar **
-tracker_dbus_query_result_to_strv (TrackerDBResultSet *result_set,
-                                   gint                        column,
-                                   gint                       *count)
-{
-	return dbus_query_result_to_strv (result_set, column, count, FALSE);
-}
-
-gchar **
-tracker_dbus_query_result_numeric_to_strv (TrackerDBResultSet *result_set,
-                                           gint                        column,
-                                           gint                       *count)
-{
-	return dbus_query_result_to_strv (result_set, column, count, TRUE);
-}
-
-gchar **
-tracker_dbus_query_result_columns_to_strv (TrackerDBResultSet *result_set,
-                                           gint                offset_column,
-                                           gint                until_column,
-                                           gboolean            rewind)
-{
-	gchar    **strv = NULL;
-	gint       i = 0;
-	gint       columns = 0;
-	gint       row_counter = 0;
-	gboolean   valid = TRUE;
-
-	if (!result_set) {
-		return NULL;
-	}
-
-	columns = tracker_db_result_set_get_n_columns (result_set);
-
-	if (rewind) {
-		/* Make sure we rewind before iterating the result set */
-		tracker_db_result_set_rewind (result_set);
-	}
-
-	if (!result_set || offset_column > columns) {
-		strv = g_new (gchar*, 1);
-		strv[0] = NULL;
-		return strv;
-	} else if (offset_column == -1) {
-		offset_column = 0;
-	}
-
-	if (until_column == -1) {
-		until_column = columns;
-	}
-
-	strv = g_new (gchar*, until_column + 1);
-
-	while (valid) {
-
-		for (i = offset_column ; i < until_column; i++) {
-			GValue value = {0, };
-			GValue transform = {0, };
-
-			g_value_init (&transform, G_TYPE_STRING);
-
-			_tracker_db_result_set_get_value (result_set, i, &value);
-			if (G_IS_VALUE (&value) && g_value_transform (&value, &transform)) {
-				if (row_counter == 0) {
-					strv[i] = g_value_dup_string (&transform);
-				} else {
-					gchar *new_value, *old_value;
-
-					new_value = g_value_dup_string (&transform);
-					if (new_value != NULL && strlen (new_value) > 0) {
-						old_value = strv [i];
-
-						strv[i] = g_strconcat (old_value, "|", new_value, NULL);
-
-						g_free (old_value);
-					}
-
-					if (new_value) {
-						g_free (new_value);
-					}
-
-				}
-				g_value_unset (&value);
-			} else if (row_counter == 0) {
-				strv[i] = g_strdup ("");
-			}
-			g_value_unset (&transform);
-		}
-
-		row_counter += 1;
-		valid = tracker_db_result_set_iter_next (result_set);
-	}
-	strv[i] = NULL;
-
-	return strv;
-}
-
-
-GHashTable *
-tracker_dbus_query_result_to_hash_table (TrackerDBResultSet *result_set)
-{
-	GHashTable *hash_table;
-	gint        field_count;
-	gboolean    valid = FALSE;
-
-	hash_table = g_hash_table_new_full (g_str_hash,
-	                                    g_str_equal,
-	                                    (GDestroyNotify) g_free,
-	                                    (GDestroyNotify) tracker_dbus_gvalue_slice_free);
-
-	if (result_set) {
-		valid = TRUE;
-
-		/* Make sure we rewind before iterating the result set */
-		tracker_db_result_set_rewind (result_set);
-
-		/* Find out how many columns to iterate */
-		field_count = tracker_db_result_set_get_n_columns (result_set);
-	}
-
-	while (valid) {
-		GValue  *values;
-		gchar  **p;
-		gint     i = 0;
-		gchar   *key;
-		GSList  *list = NULL;
-
-		tracker_db_result_set_get (result_set, 0, &key, -1);
-		values = tracker_dbus_gvalue_slice_new (G_TYPE_STRV);
-
-		for (i = 1; i < field_count; i++) {
-			GValue  transform = { 0, };
-			GValue  value = { 0, };
-			gchar  *str;
-
-			g_value_init (&transform, G_TYPE_STRING);
-			_tracker_db_result_set_get_value (result_set, i, &value);
-
-			if (g_value_transform (&value, &transform)) {
-				str = g_value_dup_string (&transform);
-
-				if (!g_utf8_validate (str, -1, NULL)) {
-					g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
-					g_free (str);
-					str = g_strdup ("");
-				}
-
-				g_value_unset (&transform);
-			} else {
-				str = g_strdup ("");
-			}
-
-			list = g_slist_prepend (list, (gchar*) str);
-
-			g_value_unset (&value);
-		}
-
-		list = g_slist_reverse (list);
-		p = tracker_dbus_slist_to_strv (list);
-
-		g_slist_foreach (list, (GFunc)g_free, NULL);
-		g_slist_free (list);
-
-		g_value_take_boxed (values, p);
-		g_hash_table_insert (hash_table, key, values);
-
-		valid = tracker_db_result_set_iter_next (result_set);
-	}
-
-	return hash_table;
-}
-
 GPtrArray *
 tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set)
 {
@@ -481,93 +134,3 @@ tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set)
 
 	return ptr_array;
 }
-
-GPtrArray *
-tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set)
-{
-	GPtrArray *result;
-	GPtrArray *rows;
-	gboolean   valid = FALSE;
-	gint       columns;
-
-	rows = g_ptr_array_new ();
-
-	if (result_set) {
-		valid = TRUE;
-
-		/* Make sure we rewind before iterating the result set */
-		tracker_db_result_set_rewind (result_set);
-
-		/* Find out how many columns to iterate */
-		columns = tracker_db_result_set_get_n_columns (result_set);
-	}
-
-	while (valid) {
-		GPtrArray *row;
-		GValue     value_in = {0, };
-		gint       key;
-		gint       column;
-		gboolean   add = FALSE;
-
-		/* Get the key and the matching row if exists */
-		_tracker_db_result_set_get_value (result_set, 0, &value_in);
-		key = g_value_get_int (&value_in);
-		row = rows_lookup (rows, key);
-		if (!row) {
-			row = g_ptr_array_new ();
-			add = TRUE;
-		}
-
-		/* Append fields or values to the array */
-		for (column = 1; column < columns; column++) {
-			GValue  transform = { 0, };
-			GValue  value = { 0, };
-			gchar  *str;
-
-			g_value_init (&transform, G_TYPE_STRING);
-
-			_tracker_db_result_set_get_value (result_set,
-			                                  column,
-			                                  &value);
-
-			if (g_value_transform (&value, &transform)) {
-				str = g_value_dup_string (&transform);
-
-				if (!str) {
-					str = g_strdup ("");
-				} else if (!g_utf8_validate (str, -1, NULL)) {
-					g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
-					g_free (str);
-					str = g_strdup ("");
-				}
-			} else {
-				str = g_strdup ("");
-			}
-
-			if (add) {
-				row_add (row, str);
-			} else {
-				if (!row_insert (row, str, column-1)) {
-					/* Failed to insert */
-					g_free (str);
-				}
-			}
-
-			g_value_unset (&value);
-			g_value_unset (&transform);
-		}
-
-		if (add) {
-			rows_add (rows, key, row);
-		}
-
-		valid = tracker_db_result_set_iter_next (result_set);
-	}
-
-	result = g_ptr_array_new ();
-
-	rows_migrate (rows, result);
-	rows_destroy (rows);
-
-	return result;
-}
diff --git a/src/libtracker-db/tracker-db-dbus.h b/src/libtracker-db/tracker-db-dbus.h
index 1ca5c7b..dccc7fd 100644
--- a/src/libtracker-db/tracker-db-dbus.h
+++ b/src/libtracker-db/tracker-db-dbus.h
@@ -34,16 +34,7 @@ G_BEGIN_DECLS
 gchar **    tracker_dbus_query_result_to_strv            (TrackerDBResultSet *result_set,
                                                           gint                column,
                                                           gint               *count);
-gchar **    tracker_dbus_query_result_numeric_to_strv    (TrackerDBResultSet *result_set,
-                                                          gint                column,
-                                                          gint               *count);
-gchar **    tracker_dbus_query_result_columns_to_strv    (TrackerDBResultSet *result_set,
-                                                          gint                offset_column,
-                                                          gint                until_column,
-                                                          gboolean            rewind);
-GHashTable *tracker_dbus_query_result_to_hash_table      (TrackerDBResultSet *result_set);
 GPtrArray * tracker_dbus_query_result_to_ptr_array       (TrackerDBResultSet *result_set);
-GPtrArray * tracker_dbus_query_result_multi_to_ptr_array (TrackerDBResultSet *result_set);
 
 G_END_DECLS
 
diff --git a/tests/libtracker-db/tracker-db-dbus-test.c b/tests/libtracker-db/tracker-db-dbus-test.c
index 5359153..458116f 100644
--- a/tests/libtracker-db/tracker-db-dbus-test.c
+++ b/tests/libtracker-db/tracker-db-dbus-test.c
@@ -187,13 +187,6 @@ test_dbus_query_result_to_strv ()
 }
 
 static void
-test_dbus_query_result_to_hash_table ()
-{
-	/* TODO: Implement */
-	g_print ("- Unimplemented -\n");
-}
-
-static void
 free_string_ptr_array (GPtrArray *array)
 {
 	g_ptr_array_foreach (array, (GFunc)g_strfreev, NULL);
@@ -240,128 +233,6 @@ test_dbus_query_result_to_ptr_array ()
 	g_object_unref (result_set);
 }
 
-
-static void
-test_dbus_query_result_multi_to_ptr_array ()
-{
-	TrackerDBResultSet *result_set = NULL;
-	GPtrArray *result = NULL;
-
-	/* NULL */
-	result = tracker_dbus_query_result_multi_to_ptr_array (result_set);
-	g_assert_cmpint (result->len, ==, 0);
-	free_string_ptr_array (result);
-
-	/* 5 results, 1 column */
-	result_set = get_mock_tracker_db_multi_result (5, 1, FALSE);
-	result = tracker_dbus_query_result_multi_to_ptr_array (result_set);
-
-	g_assert_cmpint (result->len, ==, 5);
-	free_string_ptr_array (result);
-
-	g_object_unref (result_set);
-
-	/* 0 results, 1 columns */
-	result_set = get_mock_tracker_db_multi_result (0, 1, FALSE);
-	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-		result = tracker_dbus_query_result_multi_to_ptr_array (result_set);
-		free_string_ptr_array (result);
-	}
-	g_test_trap_assert_failed ();
-	/* Should raise g_critical (priv->array...); */
-
-	g_object_unref (result_set);
-
-	/*  1 result ... NULL */
-	result_set = get_mock_tracker_db_multi_result (1, 1, TRUE);
-	result = tracker_dbus_query_result_multi_to_ptr_array (result_set);
-	g_assert_cmpint (result->len, ==, 1);
-	free_string_ptr_array (result);
-
-	g_object_unref (result_set);
-
-
-	/* 5 results, 5 columns */
-	result_set = get_mock_tracker_db_multi_result (5, 5, FALSE);
-	result = tracker_dbus_query_result_multi_to_ptr_array (result_set);
-
-	g_assert_cmpint (result->len, ==, 5);
-	free_string_ptr_array (result);
-
-	g_object_unref (result_set);
-
-}
-
-static void
-test_dbus_query_result_columns_to_strv ()
-{
-	TrackerDBResultSet *result_set = NULL;
-	gchar **result = NULL;
-
-	/* NULL */
-	result = tracker_dbus_query_result_columns_to_strv (result_set,
-	                                                    -1,
-	                                                    -1,
-	                                                    TRUE);
-	g_assert_cmpint (g_strv_length (result), ==, 0);
-	g_strfreev (result);
-
-	/* 1 results, 1 column */
-	result_set = get_mock_tracker_db_result (1, 1, FALSE);
-	result = tracker_dbus_query_result_columns_to_strv (result_set, -1, -1, TRUE);
-
-	g_assert_cmpint (g_strv_length (result), ==, 1);
-	g_strfreev (result);
-
-	g_object_unref (result_set);
-
-	/* 1 results, 5 column */
-	result_set = get_mock_tracker_db_result (1, 5, FALSE);
-	result = tracker_dbus_query_result_columns_to_strv (result_set, -1, -1, TRUE);
-
-	g_assert_cmpint (g_strv_length (result), ==, 5);
-	tracker_test_helpers_cmpstr_equal (result[0], "value 0");
-	tracker_test_helpers_cmpstr_equal (result[1], "value 1");
-	g_strfreev (result);
-
-	g_object_unref (result_set);
-
-	/* 2 results, 1 column */
-	result_set = get_mock_tracker_db_result (2, 1, FALSE);
-	result = tracker_dbus_query_result_columns_to_strv (result_set, -1, -1, TRUE);
-
-	g_assert_cmpint (g_strv_length (result), ==, 1);
-	tracker_test_helpers_cmpstr_equal (result[0], "value 0|value 0");
-	g_strfreev (result);
-
-	g_object_unref (result_set);
-
-	/* 2 results, 2 columns */
-	result_set = get_mock_tracker_db_result (2, 2, FALSE);
-	result = tracker_dbus_query_result_columns_to_strv (result_set, -1, -1, TRUE);
-
-	g_assert_cmpint (g_strv_length (result), ==, 2);
-	tracker_test_helpers_cmpstr_equal (result[0], "value 0|value 0");
-	tracker_test_helpers_cmpstr_equal (result[1], "value 1|value 1");
-	g_strfreev (result);
-
-	g_object_unref (result_set);
-
-	/* 2 results, 2 columns with NULL values in (1,1)
-	 * first row 0, first column 0
-	 */
-	result_set = get_custom_mock_tracker_db_result ();
-	result = tracker_dbus_query_result_columns_to_strv (result_set, -1, -1, TRUE);
-
-	g_assert_cmpint (g_strv_length (result), ==, 2);
-	tracker_test_helpers_cmpstr_equal (result[0], "value 0|value 0");
-	tracker_test_helpers_cmpstr_equal (result[1], "value 1");
-	g_strfreev (result);
-
-	g_object_unref (result_set);
-
-}
-
 gint
 main (gint argc, gchar **argv)
 {
@@ -373,14 +244,8 @@ main (gint argc, gchar **argv)
 
 	g_test_add_func ("/libtracker-db/tracker-db-dbus/query_result_to_strv",
 	                 test_dbus_query_result_to_strv);
-	g_test_add_func ("/libtracker-db/tracker-db-dbus/query_result_to_hash_table",
-	                 test_dbus_query_result_to_hash_table);
 	g_test_add_func ("/libtracker-db/tracker-db-dbus/query_result_to_ptr_array",
 	                 test_dbus_query_result_to_ptr_array);
-	g_test_add_func ("/libtracker-db/tracker-db-dbus/query_result_multi_to_ptr_array",
-	                 test_dbus_query_result_multi_to_ptr_array);
-	g_test_add_func ("/libtracker-db/tracker-db-dbus/query_result_columns_to_strv",
-	                 test_dbus_query_result_columns_to_strv);
 	result = g_test_run ();
 
 	/* End */



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