[evolution-data-server/wip/camel-more-gobject] Make CamelDB a GObject descendant



commit a663909456f37e11c3450c03b6fe322fae7f34e2
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 1 19:39:44 2016 +0100

    Make CamelDB a GObject descendant

 src/camel/camel-db.c             |  207 ++++++++++++++++----------
 src/camel/camel-db.h             |  305 +++++++++++++++++++++++++-------------
 src/camel/camel-folder-summary.c |    2 +-
 src/camel/camel-store.c          |    5 +-
 4 files changed, 336 insertions(+), 183 deletions(-)
---
diff --git a/src/camel/camel-db.c b/src/camel/camel-db.c
index 222a880..9411794 100644
--- a/src/camel/camel-db.c
+++ b/src/camel/camel-db.c
@@ -29,6 +29,8 @@
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
+#include <sqlite3.h>
+
 #include "camel-debug.h"
 #include "camel-object.h"
 #include "camel-string-utils.h"
@@ -437,6 +439,9 @@ init_sqlite_vfs (void)
 
        sqlite3_vfs_register (&vfs, 1);
 
+       if (g_getenv ("CAMEL_SQLITE_SHARED_CACHE"))
+               sqlite3_enable_shared_cache (TRUE);
+
        return NULL;
 }
 
@@ -481,14 +486,56 @@ init_sqlite_vfs (void)
        }
 
 struct _CamelDBPrivate {
+       sqlite3 *db;
        GTimer *timer;
        GRWLock rwlock;
-       gchar *file_name;
+       gchar *filename;
        GMutex transaction_lock;
        GThread *transaction_thread;
        guint32 transaction_level;
 };
 
+G_DEFINE_TYPE (CamelDB, camel_db, G_TYPE_OBJECT)
+
+static void
+camel_db_finalize (GObject *object)
+{
+       CamelDB *cdb = CAMEL_DB (object);
+
+       sqlite3_close (cdb->priv->db);
+       g_rw_lock_clear (&cdb->priv->rwlock);
+       g_mutex_clear (&cdb->priv->transaction_lock);
+       g_free (cdb->priv->filename);
+
+       d (g_print ("\nDatabase succesfully closed \n"));
+
+       /* Chain up to parent's finalize() method. */
+       G_OBJECT_CLASS (camel_db_parent_class)->finalize (object);
+}
+
+static void
+camel_db_class_init (CamelDBClass *class)
+{
+       GObjectClass *object_class;
+
+       g_type_class_add_private (class, sizeof (CamelDBPrivate));
+
+       object_class = G_OBJECT_CLASS (class);
+       object_class->finalize = camel_db_finalize;
+}
+
+static void
+camel_db_init (CamelDB *cdb)
+{
+       cdb->priv = G_TYPE_INSTANCE_GET_PRIVATE (cdb, CAMEL_TYPE_DB, CamelDBPrivate);
+
+       g_rw_lock_init (&cdb->priv->rwlock);
+       g_mutex_init (&cdb->priv->transaction_lock);
+       cdb->priv->transaction_thread = NULL;
+       cdb->priv->transaction_level = 0;
+       cdb->priv->timer = NULL;
+}
+
 /**
  * cdb_sql_exec 
  * @db: 
@@ -713,7 +760,7 @@ camel_db_command_internal (CamelDB *cdb,
        cdb_writer_lock (cdb);
 
        START (stmt);
-       ret = cdb_sql_exec (cdb->db, stmt, NULL, NULL, out_sqlite_error_code, error);
+       ret = cdb_sql_exec (cdb->priv->db, stmt, NULL, NULL, out_sqlite_error_code, error);
        END;
 
        cdb_writer_unlock (cdb);
@@ -722,13 +769,18 @@ camel_db_command_internal (CamelDB *cdb,
 }
 
 /**
- * camel_db_open:
+ * camel_db_new:
+ * @filename: A filename with the database to open/create
+ * @error: (out): a #GError for error messages
  *
- * Since: 2.24
+ * Returns: (transfer full): A new #CamelDB with @filename as its database file.
+ *   Free it with g_object_unref() when no longer needed.
+ *
+ * Since: 3.24
  **/
 CamelDB *
-camel_db_open (const gchar *path,
-               GError **error)
+camel_db_new (const gchar *filename,
+              GError **error)
 {
        static GOnce vfs_once = G_ONCE_INIT;
        CamelDB *cdb;
@@ -739,10 +791,8 @@ camel_db_open (const gchar *path,
 
        g_once (&vfs_once, (GThreadFunc) init_sqlite_vfs, NULL);
 
-       CAMEL_DB_USE_SHARED_CACHE;
-
  reopen:
-       ret = sqlite3_open (path, &db);
+       ret = sqlite3_open (filename, &db);
        if (ret) {
                if (!db) {
                        g_set_error (
@@ -752,7 +802,7 @@ camel_db_open (const gchar *path,
                } else {
                        const gchar *errmsg;
                        errmsg = sqlite3_errmsg (db);
-                       d (g_print ("Can't open database %s: %s\n", path, errmsg));
+                       d (g_print ("Can't open database %s: %s\n", filename, errmsg));
                        g_set_error (
                                error, CAMEL_ERROR,
                                CAMEL_ERROR_GENERIC, "%s", errmsg);
@@ -761,15 +811,9 @@ camel_db_open (const gchar *path,
                return NULL;
        }
 
-       cdb = g_new (CamelDB, 1);
-       cdb->db = db;
-       cdb->priv = g_new0 (CamelDBPrivate, 1);
-       cdb->priv->file_name = g_strdup (path);
-       g_rw_lock_init (&cdb->priv->rwlock);
-       g_mutex_init (&cdb->priv->transaction_lock);
-       cdb->priv->transaction_thread = NULL;
-       cdb->priv->transaction_level = 0;
-       cdb->priv->timer = NULL;
+       cdb = g_object_new (CAMEL_TYPE_DB, NULL);
+       cdb->priv->db = db;
+       cdb->priv->filename = g_strdup (filename);
        d (g_print ("\nDatabase succesfully opened  \n"));
 
        sqlite3_create_function (db, "MATCH", 2, SQLITE_UTF8, NULL, cdb_match_func, NULL, NULL);
@@ -799,16 +843,16 @@ camel_db_open (const gchar *path,
            cdb_sqlite_error_code == SQLITE_NOTADB)) {
                gchar *second_filename;
 
-               camel_db_close (cdb);
+               g_clear_object (&cdb);
 
                reopening = TRUE;
 
-               second_filename = g_strconcat (path, ".corrupt", NULL);
-               if (g_rename (path, second_filename) == -1) {
+               second_filename = g_strconcat (filename, ".corrupt", NULL);
+               if (g_rename (filename, second_filename) == -1) {
                        if (!local_error) {
                                g_set_error (&local_error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                        _("Could not rename '%s' to %s: %s"),
-                                       path, second_filename, g_strerror (errno));
+                                       filename, second_filename, g_strerror (errno));
                        }
 
                        g_propagate_error (error, local_error);
@@ -820,7 +864,7 @@ camel_db_open (const gchar *path,
 
                g_free (second_filename);
 
-               g_warning ("%s: Failed to open '%s', renamed old file to .corrupt; code:%s (%d) error:%s", 
G_STRFUNC, path,
+               g_warning ("%s: Failed to open '%s', renamed old file to .corrupt; code:%s (%d) error:%s", 
G_STRFUNC, filename,
                        cdb_sqlite_error_code == SQLITE_CANTOPEN ? "SQLITE_CANTOPEN" :
                        cdb_sqlite_error_code == SQLITE_CORRUPT ? "SQLITE_CORRUPT" :
                        cdb_sqlite_error_code == SQLITE_NOTADB ? "SQLITE_NOTADB" : "???",
@@ -833,44 +877,29 @@ camel_db_open (const gchar *path,
 
        if (local_error) {
                g_propagate_error (error, local_error);
-               camel_db_close (cdb);
+               g_clear_object (&cdb);
                return NULL;
        }
 
-       sqlite3_busy_timeout (cdb->db, CAMEL_DB_SLEEP_INTERVAL);
+       sqlite3_busy_timeout (cdb->priv->db, CAMEL_DB_SLEEP_INTERVAL);
 
        return cdb;
 }
 
 /**
- * camel_db_clone:
+ * camel_db_get_filename:
+ * @cdb: a #CamelDB
  *
- * Since: 2.26
+ * Returns: (transfer none): A filename associated with @cdb.
+ *
+ * Since: 3.24
  **/
-CamelDB *
-camel_db_clone (CamelDB *cdb,
-                GError **error)
+const gchar *
+camel_db_get_filename (CamelDB *cdb)
 {
-       return camel_db_open (cdb->priv->file_name, error);
-}
+       g_return_val_if_fail (CAMEL_IS_DB (cdb), NULL);
 
-/**
- * camel_db_close:
- *
- * Since: 2.24
- **/
-void
-camel_db_close (CamelDB *cdb)
-{
-       if (cdb) {
-               sqlite3_close (cdb->db);
-               g_rw_lock_clear (&cdb->priv->rwlock);
-               g_mutex_clear (&cdb->priv->transaction_lock);
-               g_free (cdb->priv->file_name);
-               g_free (cdb->priv);
-               g_free (cdb);
-               d (g_print ("\nDatabase succesfully closed \n"));
-       }
+       return cdb->priv->filename;
 }
 
 /**
@@ -885,18 +914,18 @@ camel_db_set_collate (CamelDB *cdb,
                       const gchar *collate,
                       CamelDBCollate func)
 {
-               gint ret = 0;
+       gint ret = 0;
 
-               if (!cdb)
-                       return 0;
+       if (!cdb)
+               return 0;
 
-               cdb_writer_lock (cdb);
-               d (g_print ("Creating Collation %s on %s with %p\n", collate, col, (gpointer) func));
-               if (collate && func)
-                       ret = sqlite3_create_collation (cdb->db, collate, SQLITE_UTF8,  NULL, func);
-               cdb_writer_unlock (cdb);
+       cdb_writer_lock (cdb);
+       d (g_print ("Creating Collation %s on %s with %p\n", collate, col, (gpointer) func));
+       if (collate && func)
+               ret = sqlite3_create_collation (cdb->priv->db, collate, SQLITE_UTF8,  NULL, func);
+       cdb_writer_unlock (cdb);
 
-               return ret;
+       return ret;
 }
 
 /**
@@ -932,7 +961,7 @@ camel_db_begin_transaction (CamelDB *cdb,
        stmt = cdb_construct_transaction_stmt (cdb, "SAVEPOINT ");
 
        STARTTS (stmt);
-       res = cdb_sql_exec (cdb->db, stmt, NULL, NULL, NULL, error);
+       res = cdb_sql_exec (cdb->priv->db, stmt, NULL, NULL, NULL, error);
        g_free (stmt);
 
        return res;
@@ -954,12 +983,12 @@ camel_db_end_transaction (CamelDB *cdb,
                return -1;
 
        stmt = cdb_construct_transaction_stmt (cdb, "RELEASE SAVEPOINT ");
-       ret = cdb_sql_exec (cdb->db, stmt, NULL, NULL, NULL, error);
+       ret = cdb_sql_exec (cdb->priv->db, stmt, NULL, NULL, NULL, error);
        g_free (stmt);
 
        ENDTS;
        cdb_writer_unlock (cdb);
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        return ret;
 }
@@ -977,11 +1006,11 @@ camel_db_abort_transaction (CamelDB *cdb,
        gint ret;
 
        stmt = cdb_construct_transaction_stmt (cdb, "ROLLBACK TO SAVEPOINT ");
-       ret = cdb_sql_exec (cdb->db, stmt, NULL, NULL, NULL, error);
+       ret = cdb_sql_exec (cdb->priv->db, stmt, NULL, NULL, NULL, error);
        g_free (stmt);
 
        cdb_writer_unlock (cdb);
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        return ret;
 }
@@ -1001,7 +1030,7 @@ camel_db_add_to_transaction (CamelDB *cdb,
 
        g_return_val_if_fail (cdb_is_in_transaction (cdb), -1);
 
-       return (cdb_sql_exec (cdb->db, stmt, NULL, NULL, NULL, error));
+       return (cdb_sql_exec (cdb->priv->db, stmt, NULL, NULL, NULL, error));
 }
 
 /**
@@ -1031,7 +1060,7 @@ camel_db_transaction_command (CamelDB *cdb,
 
        while (qry_list) {
                query = qry_list->data;
-               ret = cdb_sql_exec (cdb->db, query, NULL, NULL, NULL, error);
+               ret = cdb_sql_exec (cdb->priv->db, query, NULL, NULL, NULL, error);
                if (ret)
                        goto end;
                qry_list = g_list_next (qry_list);
@@ -1079,12 +1108,12 @@ camel_db_count_message_info (CamelDB *cdb,
        cdb_reader_lock (cdb);
 
        START (query);
-       ret = cdb_sql_exec (cdb->db, query, count_cb, count, NULL, error);
+       ret = cdb_sql_exec (cdb->priv->db, query, count_cb, count, NULL, error);
        END;
 
        cdb_reader_unlock (cdb);
 
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        return ret;
 }
@@ -1287,11 +1316,11 @@ camel_db_select (CamelDB *cdb,
        cdb_reader_lock (cdb);
 
        START (stmt);
-       ret = cdb_sql_exec (cdb->db, stmt, callback, user_data, NULL, error);
+       ret = cdb_sql_exec (cdb->priv->db, stmt, callback, user_data, NULL, error);
        END;
 
        cdb_reader_unlock (cdb);
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        return ret;
 }
@@ -1369,7 +1398,7 @@ camel_db_get_folder_uids (CamelDB *db,
  **/
 GPtrArray *
 camel_db_get_folder_junk_uids (CamelDB *db,
-                               gchar *folder_name,
+                               const gchar *folder_name,
                                GError **error)
 {
         gchar *sel_query;
@@ -1441,7 +1470,7 @@ camel_db_create_folders_table (CamelDB *cdb,
                "visible_count INTEGER, "
                "jnd_count INTEGER, "
                "bdata TEXT )";
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        ret = camel_db_command (cdb, query, error);
 
@@ -2121,7 +2150,7 @@ camel_db_delete_uid (CamelDB *cdb,
 
        ret = camel_db_end_transaction (cdb, error);
 
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
        return ret;
 }
 
@@ -2172,7 +2201,7 @@ cdb_delete_ids (CamelDB *cdb,
        else
                ret = camel_db_end_transaction (cdb, error);
 
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        g_string_free (str, TRUE);
 
@@ -2253,7 +2282,7 @@ camel_db_delete_folder (CamelDB *cdb,
 
        ret = camel_db_end_transaction (cdb, error);
 
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
        return ret;
 }
 
@@ -2291,7 +2320,7 @@ camel_db_rename_folder (CamelDB *cdb,
 
        ret = camel_db_end_transaction (cdb, error);
 
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
        return ret;
 }
 
@@ -2618,11 +2647,11 @@ camel_db_maybe_run_maintenance (CamelDB *cdb,
 
        cdb_writer_lock (cdb);
 
-       if (cdb_sql_exec (cdb->db, "PRAGMA page_count;", get_number_cb, &page_count, NULL, &local_error) == 
SQLITE_OK &&
-           cdb_sql_exec (cdb->db, "PRAGMA freelist_count;", get_number_cb, &freelist_count, NULL, 
&local_error) == SQLITE_OK) {
+       if (cdb_sql_exec (cdb->priv->db, "PRAGMA page_count;", get_number_cb, &page_count, NULL, 
&local_error) == SQLITE_OK &&
+           cdb_sql_exec (cdb->priv->db, "PRAGMA freelist_count;", get_number_cb, &freelist_count, NULL, 
&local_error) == SQLITE_OK) {
                /* Vacuum, if there's more than 5% of the free pages */
                success = !page_count || !freelist_count || freelist_count * 1000 / page_count <= 50 ||
-                   cdb_sql_exec (cdb->db, "vacuum;", NULL, NULL, NULL, &local_error) == SQLITE_OK;
+                   cdb_sql_exec (cdb->priv->db, "vacuum;", NULL, NULL, NULL, &local_error) == SQLITE_OK;
        }
 
        cdb_writer_unlock (cdb);
@@ -2634,3 +2663,23 @@ camel_db_maybe_run_maintenance (CamelDB *cdb,
 
        return success;
 }
+
+/**
+ * camel_db_release_cache_memory:
+ *
+ * Instructs sqlite to release its memory, if possible. This can be avoided
+ * when CAMEL_SQLITE_FREE_CACHE environment variable is set.
+ *
+ * Since: 3.24
+ **/
+void
+camel_db_release_cache_memory (void)
+{
+       static gint env_set = -1;
+
+       if (env_set == -1)
+               env_set = g_getenv("CAMEL_SQLITE_FREE_CACHE") ? 1 : 0;
+
+       if (!env_set)
+               sqlite3_release_memory (CAMEL_DB_FREE_CACHE_SIZE);
+}
diff --git a/src/camel/camel-db.h b/src/camel/camel-db.h
index 726686c..d88cab8 100644
--- a/src/camel/camel-db.h
+++ b/src/camel/camel-db.h
@@ -24,11 +24,58 @@
 #ifndef CAMEL_DB_H
 #define CAMEL_DB_H
 
-#include <sqlite3.h>
 #include <glib.h>
+#include <glib-object.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_DB \
+       (camel_db_get_type ())
+#define CAMEL_DB(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), CAMEL_TYPE_DB, CamelDB))
+#define CAMEL_DB_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), CAMEL_TYPE_DB, CamelDBClass))
+#define CAMEL_IS_DB(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), CAMEL_TYPE_DB))
+#define CAMEL_IS_DB_CLASS(obj) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), CAMEL_TYPE_DB))
+#define CAMEL_DB_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), CAMEL_TYPE_DB, CamelDBClass))
 
 G_BEGIN_DECLS
 
+typedef struct _CamelDB CamelDB;
+typedef struct _CamelDBClass CamelDBClass;
+typedef struct _CamelDBPrivate CamelDBPrivate;
+
+/**
+ * CamelDB:
+ *
+ * Since: 2.24
+ **/
+struct _CamelDB {
+       GObject parent;
+       CamelDBPrivate *priv;
+};
+
+struct _CamelDBClass {
+       GObjectClass parent_class;
+
+       /* Padding for future expansion */
+       gpointer reserved[20];
+};
+
+/**
+ * CamelDBCollate:
+ *
+ * Since: 2.24
+ **/
+typedef gint (*CamelDBCollate)(gpointer enc, gint length1, gconstpointer data1, gint length2, gconstpointer 
data2);
+
 /**
  * CAMEL_DB_FILE:
  *
@@ -59,27 +106,6 @@ G_BEGIN_DECLS
  **/
 #define CAMEL_DB_IN_MEMORY_TABLE_LIMIT 100000
 
-typedef struct _CamelDBPrivate CamelDBPrivate;
-
-/**
- * CamelDBCollate:
- *
- * Since: 2.24
- **/
-typedef gint (*CamelDBCollate)(gpointer enc, gint length1, gconstpointer data1, gint length2, gconstpointer 
data2);
-
-/**
- * CamelDB:
- *
- * Since: 2.24
- **/
-struct _CamelDB {
-       sqlite3 *db;
-       /* this lock has been replaced with a rw lock which sits inside priv. 
-        * This is currently unused. Keeping it, not to break the ABI */
-       GMutex *lock;
-       CamelDBPrivate *priv;
-};
 
 /**
  * CAMEL_DB_FREE_CACHE_SIZE:
@@ -96,20 +122,6 @@ struct _CamelDB {
 #define CAMEL_DB_SLEEP_INTERVAL 1*10*10
 
 /**
- * CAMEL_DB_RELEASE_SQLITE_MEMORY:
- *
- * Since: 2.24
- **/
-#define CAMEL_DB_RELEASE_SQLITE_MEMORY if(!g_getenv("CAMEL_SQLITE_FREE_CACHE")) 
sqlite3_release_memory(CAMEL_DB_FREE_CACHE_SIZE);
-
-/**
- * CAMEL_DB_USE_SHARED_CACHE:
- *
- * Since: 2.24
- **/
-#define CAMEL_DB_USE_SHARED_CACHE if(g_getenv("CAMEL_SQLITE_SHARED_CACHE")) 
sqlite3_enable_shared_cache(TRUE);
-
-/**
  * CamelMIRecord:
  * @uid:
  *     Message UID
@@ -215,8 +227,6 @@ typedef struct _CamelFIRecord {
        gchar *bdata;
 } CamelFIRecord;
 
-typedef struct _CamelDB CamelDB;
-
 /**
  * CamelDBKnownColumnNames:
  *
@@ -270,68 +280,163 @@ CamelDBKnownColumnNames camel_db_get_column_ident (GHashTable **hash, gint index
  **/
 typedef gint (*CamelDBSelectCB) (gpointer user_data, gint ncol, gchar **colvalues, gchar **colnames);
 
-CamelDB * camel_db_open (const gchar *path, GError **error);
-CamelDB * camel_db_clone (CamelDB *cdb, GError **error);
-void camel_db_close (CamelDB *cdb);
-gint camel_db_command (CamelDB *cdb, const gchar *stmt, GError **error);
-
-gint camel_db_transaction_command (CamelDB *cdb, GList *qry_list, GError **error);
-
-gint camel_db_begin_transaction (CamelDB *cdb, GError **error);
-gint camel_db_add_to_transaction (CamelDB *cdb, const gchar *query, GError **error);
-gint camel_db_end_transaction (CamelDB *cdb, GError **error);
-gint camel_db_abort_transaction (CamelDB *cdb, GError **error);
-gint camel_db_clear_folder_summary (CamelDB *cdb, const gchar *folder, GError **error);
-gint camel_db_rename_folder (CamelDB *cdb, const gchar *old_folder, const gchar *new_folder, GError **error);
-
-gint camel_db_delete_folder (CamelDB *cdb, const gchar *folder, GError **error);
-gint camel_db_delete_uid (CamelDB *cdb, const gchar *folder, const gchar *uid, GError **error);
-/*int camel_db_delete_uids (CamelDB *cdb, GError **error, gint nargs, ... );*/
-gint camel_db_delete_uids (CamelDB *cdb, const gchar * folder_name, GList *uids, GError **error);
-
-gint camel_db_create_folders_table (CamelDB *cdb, GError **error);
-gint camel_db_select (CamelDB *cdb, const gchar * stmt, CamelDBSelectCB callback, gpointer user_data, GError 
**error);
-
-gint camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, GError **error);
-gint camel_db_read_folder_info_record (CamelDB *cdb, const gchar *folder_name, CamelFIRecord *record, GError 
**error);
-
-gint camel_db_prepare_message_info_table (CamelDB *cdb, const gchar *folder_name, GError **error);
-
-gint camel_db_write_message_info_record (CamelDB *cdb, const gchar *folder_name, CamelMIRecord *record, 
GError **error);
-gint camel_db_write_fresh_message_info_record (CamelDB *cdb, const gchar *folder_name, CamelMIRecord 
*record, GError **error);
-gint camel_db_read_message_info_records (CamelDB *cdb, const gchar *folder_name, gpointer user_data, 
CamelDBSelectCB read_mir_callback, GError **error);
-gint camel_db_read_message_info_record_with_uid (CamelDB *cdb, const gchar *folder_name, const gchar *uid, 
gpointer user_data, CamelDBSelectCB read_mir_callback, GError **error);
-
-gint camel_db_count_junk_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError 
**error);
-gint camel_db_count_unread_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError 
**error);
-gint camel_db_count_deleted_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError 
**error);
-gint camel_db_count_total_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError 
**error);
-
-gint camel_db_count_visible_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError 
**error);
-gint camel_db_count_visible_unread_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, 
GError **error);
-
-gint camel_db_count_junk_not_deleted_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, 
GError **error);
-gint camel_db_count_message_info (CamelDB *cdb, const gchar *query, guint32 *count, GError **error);
-void camel_db_camel_mir_free (CamelMIRecord *record);
-
-gint camel_db_get_folder_uids (CamelDB *db, const gchar *folder_name, const gchar *sort_by, const gchar 
*collate, GHashTable *hash, GError **error);
-
-GPtrArray * camel_db_get_folder_junk_uids (CamelDB *db, gchar *folder_name, GError **error);
-GPtrArray * camel_db_get_folder_deleted_uids (CamelDB *db, const gchar *folder_name, GError **error);
-
-gchar * camel_db_sqlize_string (const gchar *string);
-void camel_db_free_sqlized_string (gchar *string);
-
-gchar * camel_db_get_column_name (const gchar *raw_name);
-gint camel_db_set_collate (CamelDB *cdb, const gchar *col, const gchar *collate, CamelDBCollate func);
-
-gint camel_db_start_in_memory_transactions (CamelDB *cdb, GError **error);
-gint camel_db_flush_in_memory_transactions (CamelDB *cdb, const gchar * folder_name, GError **error);
-
-gint
-camel_db_reset_folder_version (CamelDB *cdb, const gchar *folder_name, gint reset_version, GError **error);
-
-gboolean camel_db_maybe_run_maintenance (CamelDB *cdb, GError **error);
+GType          camel_db_get_type               (void) G_GNUC_CONST;
+
+CamelDB *      camel_db_new                    (const gchar *filename,
+                                                GError **error);
+const gchar *  camel_db_get_filename           (CamelDB *cdb);
+gint           camel_db_command                (CamelDB *cdb,
+                                                const gchar *stmt,
+                                                GError **error);
+gint           camel_db_transaction_command    (CamelDB *cdb,
+                                                GList *qry_list,
+                                                GError **error);
+gint           camel_db_begin_transaction      (CamelDB *cdb,
+                                                GError **error);
+gint           camel_db_add_to_transaction     (CamelDB *cdb,
+                                                const gchar *query,
+                                                GError **error);
+gint           camel_db_end_transaction        (CamelDB *cdb,
+                                                GError **error);
+gint           camel_db_abort_transaction      (CamelDB *cdb,
+                                                GError **error);
+gint           camel_db_clear_folder_summary   (CamelDB *cdb,
+                                                const gchar *folder,
+                                                GError **error);
+gint           camel_db_rename_folder          (CamelDB *cdb,
+                                                const gchar *old_folder,
+                                                const gchar *new_folder,
+                                                GError **error);
+gint           camel_db_delete_folder          (CamelDB *cdb,
+                                                const gchar *folder,
+                                                GError **error);
+gint           camel_db_delete_uid             (CamelDB *cdb,
+                                                const gchar *folder,
+                                                const gchar *uid,
+                                                GError **error);
+gint           camel_db_delete_uids            (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                GList *uids,
+                                                GError **error);
+gint           camel_db_create_folders_table   (CamelDB *cdb,
+                                                GError **error);
+gint           camel_db_select                 (CamelDB *cdb,
+                                                const gchar *stmt,
+                                                CamelDBSelectCB callback,
+                                                gpointer user_data,
+                                                GError **error);
+gint           camel_db_write_folder_info_record
+                                               (CamelDB *cdb,
+                                                CamelFIRecord *record,
+                                                GError **error);
+gint           camel_db_read_folder_info_record
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                CamelFIRecord *record,
+                                                GError **error);
+gint           camel_db_prepare_message_info_table
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                GError **error);
+gint           camel_db_write_message_info_record
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                CamelMIRecord *record,
+                                                GError **error);
+gint           camel_db_write_fresh_message_info_record
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                CamelMIRecord *record,
+                                                GError **error);
+gint           camel_db_read_message_info_records
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                gpointer user_data,
+                                                CamelDBSelectCB read_mir_callback,
+                                                GError **error);
+gint           camel_db_read_message_info_record_with_uid
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                const gchar *uid,
+                                                gpointer user_data,
+                                                CamelDBSelectCB read_mir_callback,
+                                                GError **error);
+gint           camel_db_count_junk_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_unread_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_deleted_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_total_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_visible_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_visible_unread_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_junk_not_deleted_message_info
+                                               (CamelDB *cdb,
+                                                const gchar *table_name,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_count_message_info     (CamelDB *cdb,
+                                                const gchar *query,
+                                                guint32 *count,
+                                                GError **error);
+gint           camel_db_get_folder_uids        (CamelDB *db,
+                                                const gchar *folder_name,
+                                                const gchar *sort_by,
+                                                const gchar *collate,
+                                                GHashTable *hash,
+                                                GError **error);
+GPtrArray *    camel_db_get_folder_junk_uids   (CamelDB *db,
+                                                const gchar *folder_name,
+                                                GError **error);
+GPtrArray *    camel_db_get_folder_deleted_uids
+                                               (CamelDB *db,
+                                                const gchar *folder_name,
+                                                GError **error);
+gint           camel_db_set_collate            (CamelDB *cdb,
+                                                const gchar *col,
+                                                const gchar *collate,
+                                                CamelDBCollate func);
+gint           camel_db_start_in_memory_transactions
+                                               (CamelDB *cdb,
+                                                GError **error);
+gint           camel_db_flush_in_memory_transactions
+                                               (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                GError **error);
+gint           camel_db_reset_folder_version   (CamelDB *cdb,
+                                                const gchar *folder_name,
+                                                gint reset_version,
+                                                GError **error);
+gboolean       camel_db_maybe_run_maintenance  (CamelDB *cdb,
+                                                GError **error);
+
+void           camel_db_release_cache_memory   (void);
+
+gchar *                camel_db_sqlize_string          (const gchar *string);
+void           camel_db_free_sqlized_string    (gchar *string);
+gchar *                camel_db_get_column_name        (const gchar *raw_name);
+void           camel_db_camel_mir_free         (CamelMIRecord *record);
 
 G_END_DECLS
 
diff --git a/src/camel/camel-folder-summary.c b/src/camel/camel-folder-summary.c
index 237d554..f520824 100644
--- a/src/camel/camel-folder-summary.c
+++ b/src/camel/camel-folder-summary.c
@@ -1403,7 +1403,7 @@ remove_cache (CamelSession *session,
 {
        GSList *to_remove_infos = NULL;
 
-       CAMEL_DB_RELEASE_SQLITE_MEMORY;
+       camel_db_release_cache_memory ();
 
        if (time (NULL) - summary->priv->cache_load_time < SUMMARY_CACHE_DROP)
                return;
diff --git a/src/camel/camel-store.c b/src/camel/camel-store.c
index 7325343..f246ad6 100644
--- a/src/camel/camel-store.c
+++ b/src/camel/camel-store.c
@@ -349,8 +349,7 @@ store_finalize (GObject *object)
                camel_object_bag_destroy (store->folders);
 
        if (store->cdb_r != NULL) {
-               camel_db_close (store->cdb_r);
-               store->cdb_r = NULL;
+               g_clear_object (&store->cdb_r);
                store->cdb_w = NULL;
        }
 
@@ -559,7 +558,7 @@ store_initable_init (GInitable *initable,
 
        /* This is for reading from the store */
        filename = g_build_filename (user_dir, CAMEL_DB_FILE, NULL);
-       store->cdb_r = camel_db_open (filename, error);
+       store->cdb_r = camel_db_new (filename, error);
        g_free (filename);
 
        if (store->cdb_r == NULL)


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