[tracker/harmattan-pre-signal-updates: 1273/1380] libtracker-data: Register our collator function



commit 16fa6a1c889702888ad7f47963082d486604c361
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Aug 19 13:41:54 2010 +0200

    libtracker-data: Register our collator function

 src/libtracker-data/tracker-db-interface-sqlite.c |   62 +++++++++++---------
 src/libtracker-data/tracker-db-interface-sqlite.h |    8 +--
 2 files changed, 35 insertions(+), 35 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 207fe73..fae1e23 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -34,6 +34,8 @@
 #include <libtracker-fts/tracker-fts.h>
 #endif
 
+#include "tracker-collation.h"
+
 #include "tracker-db-interface-sqlite.h"
 
 struct TrackerDBInterface {
@@ -46,6 +48,8 @@ struct TrackerDBInterface {
 
 	GSList *function_data;
 
+	gpointer collator;
+
 	guint ro : 1;
 #if HAVE_TRACKER_FTS
 	guint fts_initialized : 1;
@@ -79,6 +83,12 @@ struct TrackerDBStatementClass {
 	GObjectClass parent_class;
 };
 
+typedef gint (* TrackerDBCollationFunc) (gpointer      collator,
+                                         gint          len1,
+                                         gconstpointer str1,
+                                         gint          len2,
+                                         gconstpointer str2);
+
 static TrackerDBStatement       * tracker_db_statement_sqlite_new (TrackerDBInterface     *db_interface,
                                                                    sqlite3_stmt           *sqlite_stmt);
 static TrackerDBCursor          * tracker_db_cursor_sqlite_new    (sqlite3_stmt           *sqlite_stmt,
@@ -480,6 +490,20 @@ check_interrupt (void *user_data)
 	return g_cancellable_is_cancelled (db_interface->cancellable) ? 1 : 0;
 }
 
+static gboolean
+set_collation_function (TrackerDBInterface     *interface,
+                        const gchar            *name,
+                        TrackerDBCollationFunc  func)
+{
+	gint result;
+
+	g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (interface), FALSE);
+
+	result = sqlite3_create_collation (interface->db, name, SQLITE_UTF8, interface->collator, func);
+
+	return (result == SQLITE_OK);
+}
+
 static void
 open_database (TrackerDBInterface *db_interface)
 {
@@ -499,6 +523,14 @@ open_database (TrackerDBInterface *db_interface)
 		g_message ("Opened sqlite3 database:'%s'", db_interface->filename);
 	}
 
+	/* Set our unicode collation function */
+	if (!db_interface->collator) {
+		db_interface->collator = tracker_collation_init ();
+		set_collation_function (db_interface,
+		                        TRACKER_COLLATION_NAME,
+		                        tracker_collation_utf8);
+	}
+
 	sqlite3_progress_handler (db_interface->db, 100,
 	                          check_interrupt, db_interface);
 
@@ -643,6 +675,8 @@ tracker_db_interface_sqlite_finalize (GObject *object)
 
 	g_free (db_interface->filename);
 
+	tracker_collation_deinit (db_interface->collator);
+
 	G_OBJECT_CLASS (tracker_db_interface_parent_class)->finalize (object);
 }
 
@@ -974,34 +1008,6 @@ tracker_db_interface_sqlite_new_ro (const gchar *filename)
 	                     NULL);
 }
 
-static gint
-collation_function (gpointer      data,
-                    int           len1,
-                    gconstpointer str1,
-                    int           len2,
-                    gconstpointer str2)
-{
-	TrackerDBCollationFunc func;
-
-	func = (TrackerDBCollationFunc) data;
-
-	return (func) ((gchar *) str1, len1, (gchar *) str2, len2);
-}
-
-gboolean
-tracker_db_interface_sqlite_set_collation_function (TrackerDBInterface       *interface,
-                                                    const gchar              *name,
-                                                    TrackerDBCollationFunc    func)
-{
-	gint result;
-
-	g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (interface), FALSE);
-
-	result = sqlite3_create_collation (interface->db, name, SQLITE_UTF8, func, &collation_function);
-
-	return (result == SQLITE_OK);
-}
-
 gint64
 tracker_db_interface_sqlite_get_last_insert_id (TrackerDBInterface *interface)
 {
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index 52a45d2..a923a08 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -28,16 +28,10 @@ G_BEGIN_DECLS
 #error "only <libtracker-data/tracker-data.h> must be included directly."
 #endif
 
-typedef gint (* TrackerDBCollationFunc) (gchar *str1,
-                                         gint   len1,
-                                         gchar *str2,
-                                         gint   len2);
+#define TRACKER_COLLATION_NAME "TRACKER"
 
 TrackerDBInterface *tracker_db_interface_sqlite_new                    (const gchar              *filename);
 TrackerDBInterface *tracker_db_interface_sqlite_new_ro                 (const gchar              *filename);
-gboolean            tracker_db_interface_sqlite_set_collation_function (TrackerDBInterface       *interface,
-                                                                        const gchar              *name,
-                                                                        TrackerDBCollationFunc    func);
 gint64              tracker_db_interface_sqlite_get_last_insert_id     (TrackerDBInterface       *interface);
 void                tracker_db_interface_sqlite_enable_shared_cache    (void);
 void                tracker_db_interface_sqlite_fts_init               (TrackerDBInterface       *interface,



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