[tracker] libtracker-db: Remove unused user-defined aggregate SQLite functions



commit a163407891be9719cbc9c239cddc8971102110fa
Author: Jürg Billeter <j bitron ch>
Date:   Thu Mar 18 14:12:53 2010 +0100

    libtracker-db: Remove unused user-defined aggregate SQLite functions

 src/libtracker-db/tracker-db-interface-sqlite.c |  131 -----------------------
 src/libtracker-db/tracker-db-interface-sqlite.h |   14 ---
 src/libtracker-db/tracker-db-manager.c          |   51 ---------
 3 files changed, 0 insertions(+), 196 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 63d8876..dc008ef 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -55,7 +55,6 @@ typedef struct TrackerDBInterfaceSqlitePrivate TrackerDBInterfaceSqlitePrivate;
 typedef struct TrackerDBStatementSqlitePrivate TrackerDBStatementSqlitePrivate;
 typedef struct TrackerDBCursorSqlitePrivate TrackerDBCursorSqlitePrivate;
 typedef struct SqliteFunctionData SqliteFunctionData;
-typedef struct SqliteAggregateData SqliteAggregateData;
 typedef struct TrackerDBCursorSqlite TrackerDBCursorSqlite;
 typedef struct TrackerDBCursorSqliteClass TrackerDBCursorSqliteClass;
 typedef struct TrackerDBStatementSqlite      TrackerDBStatementSqlite;
@@ -79,7 +78,6 @@ struct TrackerDBInterfaceSqlitePrivate {
 	GHashTable *statements;
 
 	GSList *function_data;
-	GSList *aggregate_data;
 
 	guint in_transaction : 1;
 	guint ro : 1;
@@ -102,14 +100,6 @@ struct SqliteFunctionData {
 	TrackerDBFunc func;
 };
 
-struct SqliteAggregateData {
-	TrackerDBInterface *interface;
-	guint               context_size;
-	TrackerDBFuncStep   step;
-	TrackerDBFuncFinal  final;
-
-};
-
 
 struct TrackerDBStatementSqlite {
 	GObject parent_instance;
@@ -267,10 +257,6 @@ close_database (TrackerDBInterfaceSqlitePrivate *priv)
 	g_slist_free (priv->function_data);
 	priv->function_data = NULL;
 
-	g_slist_foreach (priv->aggregate_data, (GFunc) g_free, NULL);
-	g_slist_free (priv->aggregate_data);
-	priv->aggregate_data = NULL;
-
 	sqlite3_close (priv->db);
 }
 
@@ -490,97 +476,6 @@ tracker_db_interface_sqlite_create_statement (TrackerDBInterface *db_interface,
 }
 
 static void
-internal_sqlite3_aggregate_step (sqlite3_context *context,
-                                 int                argc,
-                                 sqlite3_value   *argv[])
-{
-	SqliteAggregateData *data;
-	void *aggregate_context;
-	GValue *values;
-	gint i;
-
-	data = (SqliteAggregateData *) sqlite3_user_data (context);
-	values = g_new0 (GValue, argc);
-
-	/* Transform the arguments */
-	for (i = 0; i < argc; i++) {
-		switch (sqlite3_value_type (argv[i])) {
-		case SQLITE_TEXT:
-			g_value_init (&values[i], G_TYPE_STRING);
-			g_value_set_string (&values[i], (gchar *) sqlite3_value_text (argv[i]));
-			break;
-		case SQLITE_INTEGER:
-			g_value_init (&values[i], G_TYPE_INT);
-			g_value_set_int (&values[i], sqlite3_value_int (argv[i]));
-			break;
-		case SQLITE_FLOAT:
-			g_value_init (&values[i], G_TYPE_DOUBLE);
-			g_value_set_double (&values[i], sqlite3_value_double (argv[i]));
-			break;
-		case SQLITE_NULL:
-			/* Ignore NULLs and let the function handle missing values */
-			break;
-		default:
-			g_critical ("Unknown sqlite3 database value type:%d",
-			            sqlite3_value_type (argv[i]));
-		}
-	}
-
-	aggregate_context = sqlite3_aggregate_context(context, data->context_size);
-
-	/* Call the function */
-	data->step (data->interface, aggregate_context, argc, values);
-
-	/* Now free all this mess */
-	for (i = 0; i < argc; i++) {
-		/* Don't free NULLs */
-		if (G_VALUE_TYPE (&values[i]) != G_TYPE_INVALID) {
-			g_value_unset (&values[i]);
-		}
-	}
-
-	g_free (values);
-}
-
-static void
-internal_sqlite3_aggregate_final (sqlite3_context *context)
-{
-	SqliteAggregateData *data;
-	void *aggregate_context;
-	GValue result;
-
-	data = (SqliteAggregateData *) sqlite3_user_data (context);
-
-	aggregate_context = sqlite3_aggregate_context(context, 0);
-
-	/* Call the function */
-	result = data->final (data->interface, aggregate_context);
-
-	/* And return something appropriate to the context */
-	if (G_VALUE_HOLDS_INT (&result)) {
-		sqlite3_result_int (context, g_value_get_int (&result));
-	} else if (G_VALUE_HOLDS_DOUBLE (&result)) {
-		sqlite3_result_double (context, g_value_get_double (&result));
-	} else if (G_VALUE_HOLDS_STRING (&result)) {
-		sqlite3_result_text (context,
-		                     g_value_dup_string (&result),
-		                     -1, g_free);
-	} else if (G_VALUE_HOLDS (&result, G_TYPE_INVALID)) {
-		sqlite3_result_null (context);
-	} else {
-		g_critical ("Sqlite3 returned type not managed:'%s'",
-		            G_VALUE_TYPE_NAME (&result));
-		sqlite3_result_null (context);
-	}
-
-	/* Now free all this mess */
-
-	if (! G_VALUE_HOLDS (&result, G_TYPE_INVALID)) {
-		g_value_unset (&result);
-	}
-}
-
-static void
 foreach_print_error (gpointer key, gpointer value, gpointer stmt)
 {
 	if (value == stmt)
@@ -764,32 +659,6 @@ tracker_db_interface_sqlite_create_function (TrackerDBInterface *interface,
 	sqlite3_create_function (priv->db, name, n_args, SQLITE_ANY, data, &internal_sqlite3_function, NULL, NULL);
 }
 
-void
-tracker_db_interface_sqlite_create_aggregate (TrackerDBInterface *interface,
-                                              const gchar        *name,
-                                              TrackerDBFuncStep   step,
-                                              gint                n_args,
-                                              TrackerDBFuncFinal  final,
-                                              guint               context_size)
-{
-	SqliteAggregateData *data;
-	TrackerDBInterfaceSqlitePrivate *priv;
-
-	priv = TRACKER_DB_INTERFACE_SQLITE_GET_PRIVATE (interface);
-
-	data = g_new0 (SqliteAggregateData, 1);
-	data->interface = interface;
-	data->context_size = context_size;
-	data->step = step;
-	data->final = final;
-
-	priv->aggregate_data = g_slist_prepend (priv->aggregate_data, data);
-
-	sqlite3_create_function (priv->db, name, n_args, SQLITE_ANY, data, NULL,
-	                         &internal_sqlite3_aggregate_step,
-	                         &internal_sqlite3_aggregate_final);
-}
-
 gboolean
 tracker_db_interface_sqlite_set_collation_function (TrackerDBInterfaceSqlite *interface,
                                                     const gchar                      *name,
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.h b/src/libtracker-db/tracker-db-interface-sqlite.h
index 9fb5d83..f40132b 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.h
+++ b/src/libtracker-db/tracker-db-interface-sqlite.h
@@ -46,14 +46,6 @@ typedef GValue (* TrackerDBFunc) (TrackerDBInterface *interface,
                                   gint                argc,
                                   GValue              argv[]);
 
-typedef void (* TrackerDBFuncStep) (TrackerDBInterface *interface,
-                                    void               *aggregate_context,
-                                    gint                  argc,
-                                    GValue                argv[]);
-
-typedef GValue (* TrackerDBFuncFinal) (TrackerDBInterface *interface,
-                                       void               *aggregate_context);
-
 struct TrackerDBInterfaceSqlite {
 	GObject parent_instance;
 };
@@ -70,12 +62,6 @@ void                tracker_db_interface_sqlite_create_function        (TrackerD
                                                                         const gchar              *name,
                                                                         TrackerDBFunc             func,
                                                                         gint                      n_args);
-void                tracker_db_interface_sqlite_create_aggregate       (TrackerDBInterface       *interface,
-                                                                        const gchar              *name,
-                                                                        TrackerDBFuncStep         step,
-                                                                        gint                      n_args,
-                                                                        TrackerDBFuncFinal        final,
-                                                                        guint                     context_size);
 gboolean            tracker_db_interface_sqlite_set_collation_function (TrackerDBInterfaceSqlite *interface,
                                                                         const gchar              *name,
                                                                         TrackerDBCollationFunc    func);
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 28c083a..5af00e2 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -94,10 +94,6 @@ typedef struct {
 	guint64             mtime;
 } TrackerDBDefinition;
 
-typedef struct {
-	GString *string;     /* The string we are accumulating */
-} AggregateData;
-
 static TrackerDBDefinition dbs[] = {
 	{ TRACKER_DB_UNKNOWN,
 	  TRACKER_DB_LOCATION_USER_DATA_DIR,
@@ -418,46 +414,6 @@ function_sparql_haversine_distance (TrackerDBInterface *interface,
 	return result;
 }
 
-static void
-function_group_concat_step (TrackerDBInterface *interface,
-                            void               *aggregate_context,
-                            gint                argc,
-                            GValue              values[])
-{
-	AggregateData *p;
-
-	g_return_if_fail (argc == 1);
-
-	p = aggregate_context;
-
-	if (!p->string) {
-		p->string = g_string_new ("");
-	} else {
-		p->string = g_string_append (p->string, "|");
-	}
-
-	if (G_VALUE_HOLDS_STRING (&values[0])) {
-		p->string = g_string_append (p->string, g_value_get_string (&values[0]));
-	}
-}
-
-static GValue
-function_group_concat_final (TrackerDBInterface *interface,
-                             void               *aggregate_context)
-{
-	GValue result = { 0, };
-	AggregateData *p;
-
-	p = aggregate_context;
-
-	g_value_init (&result, G_TYPE_STRING);
-	g_value_set_string (&result, p->string->str);
-
-	g_string_free (p->string, TRUE);
-
-	return result;
-}
-
 static GValue
 function_sparql_regex (TrackerDBInterface *interface,
                        gint                  argc,
@@ -551,13 +507,6 @@ db_set_params (TrackerDBInterface *iface,
 		                                             "SparqlHaversineDistance",
 		                                             function_sparql_haversine_distance,
 		                                             4);
-
-		tracker_db_interface_sqlite_create_aggregate (iface,
-		                                              "group_concat",
-		                                              function_group_concat_step,
-		                                              1,
-		                                              function_group_concat_final,
-		                                              sizeof(AggregateData));
 	}
 }
 



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