[evolution-data-server/sqlite-refactor: 5/8] EBookBackendFile: Ported to new EBookBackendSqlite API



commit 26cef02754df098ecd1b898fbe12e4ad4387d114
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Tue Nov 19 23:55:01 2013 +0900

    EBookBackendFile: Ported to new EBookBackendSqlite API

 .../file/e-book-backend-file-migrate-bdb.c         |   21 +-
 .../file/e-book-backend-file-migrate-bdb.h         |    3 +-
 addressbook/backends/file/e-book-backend-file.c    |  218 +++++++++-----------
 3 files changed, 113 insertions(+), 129 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file-migrate-bdb.c 
b/addressbook/backends/file/e-book-backend-file-migrate-bdb.c
index b7cc557..ae72114 100644
--- a/addressbook/backends/file/e-book-backend-file-migrate-bdb.c
+++ b/addressbook/backends/file/e-book-backend-file-migrate-bdb.c
@@ -306,10 +306,9 @@ e_book_backend_file_maybe_upgrade_db (DB *db)
 }
 
 static gboolean
-migrate_bdb_to_sqlitedb (EBookBackendSqliteDB *sqlitedb,
-                         const gchar *sqlite_folder_id,
-                         DB *db,
-                         GError **error)
+migrate_bdb_to_sqlite (EBookBackendSqlite *sqlitedb,
+                      DB *db,
+                      GError **error)
 {
        DBC            *dbc;
        DBT             id_dbt, vcard_dbt;
@@ -363,9 +362,7 @@ migrate_bdb_to_sqlitedb (EBookBackendSqliteDB *sqlitedb,
 
        /* Add the contacts to the SQLite (only if there are any contacts to add) */
        if (contacts &&
-           !e_book_backend_sqlitedb_add_contacts (sqlitedb,
-                                                  sqlite_folder_id,
-                                                  contacts, FALSE, error)) {
+           !e_book_backend_sqlite_add_contacts (sqlitedb, contacts, TRUE, error)) {
                if (error && *error) {
                        g_warning ("Failed to add contacts to sqlite db: %s", (*error)->message);
                } else {
@@ -378,7 +375,10 @@ migrate_bdb_to_sqlitedb (EBookBackendSqliteDB *sqlitedb,
 
        g_slist_free_full (contacts, (GDestroyNotify) g_object_unref);
 
-       if (!e_book_backend_sqlitedb_set_is_populated (sqlitedb, sqlite_folder_id, TRUE, error)) {
+       if (!e_book_backend_sqlite_set_key_value_int (sqlitedb,
+                                                     E_BOOK_SQL_IS_POPULATED_KEY,
+                                                     TRUE,
+                                                     error)) {
                if (error && *error) {
                        g_warning ("Failed to set the sqlitedb populated flag: %s", (*error)->message);
                } else {
@@ -391,8 +391,7 @@ migrate_bdb_to_sqlitedb (EBookBackendSqliteDB *sqlitedb,
 }
 
 gboolean
-e_book_backend_file_migrate_bdb (EBookBackendSqliteDB *sqlitedb,
-                                 const gchar *sqlite_folder_id,
+e_book_backend_file_migrate_bdb (EBookBackendSqlite *sqlitedb,
                                  const gchar *dirname,
                                  const gchar *filename,
                                  GError **error)
@@ -517,7 +516,7 @@ e_book_backend_file_migrate_bdb (EBookBackendSqliteDB *sqlitedb,
        /* Now we have our old BDB up and running and migrated to the latest known BDB version,
         * lets go ahead and now migrate it to the sqlite DB
         */
-       if (migrate_bdb_to_sqlitedb (sqlitedb, sqlite_folder_id, db, error))
+       if (migrate_bdb_to_sqlite (sqlitedb, db, error))
                status = TRUE;
 
  close_db:
diff --git a/addressbook/backends/file/e-book-backend-file-migrate-bdb.h 
b/addressbook/backends/file/e-book-backend-file-migrate-bdb.h
index ab8dc77..d35824b 100644
--- a/addressbook/backends/file/e-book-backend-file-migrate-bdb.h
+++ b/addressbook/backends/file/e-book-backend-file-migrate-bdb.h
@@ -28,8 +28,7 @@
 
 G_BEGIN_DECLS
 
-gboolean e_book_backend_file_migrate_bdb (EBookBackendSqliteDB  *sqlitedb,
-                                         const gchar           *sqlite_folder_id,
+gboolean e_book_backend_file_migrate_bdb (EBookBackendSqlite    *sqlitedb,
                                          const gchar           *dirname,
                                          const gchar           *filename,
                                          GError               **error);
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index b166e6d..0343e5c 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -56,9 +56,11 @@
 
 #define PAS_ID_PREFIX "pas-id-"
 
-#define SQLITEDB_EMAIL_ID    "addressbook localbackend com"
+/* We need to specify the folderid in order to properly
+ * migrate data from the old EBookBackendSqliteDB API.
+ */
 #define SQLITEDB_FOLDER_ID   "folder_id"
-#define SQLITEDB_FOLDER_NAME "folder"
+#define SQLITE_REVISION_KEY  "revision"
 
 /* Forward Declarations */
 static void    e_book_backend_file_initable_init
@@ -82,7 +84,7 @@ struct _EBookBackendFilePrivate {
        GRWLock    lock;
        GList     *cursors;
 
-       EBookBackendSqliteDB *sqlitedb;
+       EBookBackendSqlite *sqlitedb;
 };
 
 /****************************************************************
@@ -647,11 +649,10 @@ e_book_backend_file_bump_revision (EBookBackendFile *bf,
        gboolean success;
 
        new_revision = e_book_backend_file_new_revision (bf);
-
-       success = e_book_backend_sqlitedb_set_revision (bf->priv->sqlitedb,
-                                                       SQLITEDB_FOLDER_ID,
-                                                       new_revision,
-                                                       &local_error);
+       success = e_book_backend_sqlite_set_key_value (bf->priv->sqlitedb,
+                                                      SQLITE_REVISION_KEY,
+                                                      new_revision,
+                                                      &local_error);
 
        if (success) {
                g_free (bf->priv->revision);
@@ -676,10 +677,10 @@ e_book_backend_file_load_revision (EBookBackendFile *bf)
 {
        GError *error = NULL;
 
-       if (!e_book_backend_sqlitedb_get_revision (bf->priv->sqlitedb,
-                                                  SQLITEDB_FOLDER_ID,
-                                                  &bf->priv->revision,
-                                                  &error)) {
+       if (!e_book_backend_sqlite_get_key_value (bf->priv->sqlitedb,
+                                                 SQLITE_REVISION_KEY,
+                                                 &bf->priv->revision,
+                                                 &error)) {
                g_warning (
                        G_STRLOC ": Error loading database revision: %s",
                        error ? error->message : "Unknown error");
@@ -694,10 +695,9 @@ e_book_backend_file_load_locale (EBookBackendFile *bf)
 {
        GError *error = NULL;
 
-       if (!e_book_backend_sqlitedb_get_locale (bf->priv->sqlitedb,
-                                                SQLITEDB_FOLDER_ID,
-                                                &bf->priv->locale,
-                                                &error)) {
+       if (!e_book_backend_sqlite_get_locale (bf->priv->sqlitedb,
+                                              &bf->priv->locale,
+                                              &error)) {
                g_warning (
                        G_STRLOC ": Error loading database locale setting: %s",
                        error ? error->message : "Unknown error");
@@ -826,19 +826,18 @@ do_create (EBookBackendFile *bf,
                GList *tail, *link;
                GSList *slist = NULL, *l;
 
-               /* XXX EBookBackendSqliteDB still uses GSList. */
+               /* XXX EBookBackendSqlite still uses GSList. */
                tail = g_queue_peek_tail_link (&queue);
                for (link = tail; link != NULL; link = g_list_previous (link))
                        slist = g_slist_prepend (slist, link->data);
 
-               if (!e_book_backend_sqlitedb_new_contacts (bf->priv->sqlitedb,
-                                                          SQLITEDB_FOLDER_ID,
-                                                          slist, FALSE,
-                                                          &local_error)) {
+               if (!e_book_backend_sqlite_add_contacts (bf->priv->sqlitedb,
+                                                        slist, FALSE,
+                                                        &local_error)) {
 
                        if (g_error_matches (local_error,
-                                            E_BOOK_SDB_ERROR,
-                                            E_BOOK_SDB_ERROR_CONSTRAINT)) {
+                                            E_BOOK_SQL_ERROR,
+                                            E_BOOK_SQL_ERROR_CONSTRAINT)) {
                                g_set_error (
                                        error, E_BOOK_CLIENT_ERROR,
                                        E_BOOK_CLIENT_ERROR_CONTACT_ID_ALREADY_EXISTS,
@@ -966,9 +965,8 @@ book_view_thread (gpointer data)
        e_flag_set (closure->running);
 
        g_rw_lock_reader_lock (&(bf->priv->lock));
-       summary_list = e_book_backend_sqlitedb_search (
+       summary_list = e_book_backend_sqlite_search (
                bf->priv->sqlitedb,
-               SQLITEDB_FOLDER_ID,
                query, fields_of_interest,
                NULL, NULL, &local_error);
        g_rw_lock_reader_unlock (&(bf->priv->lock));
@@ -988,7 +986,7 @@ book_view_thread (gpointer data)
        }
 
        for (l = summary_list; l; l = l->next) {
-               EbSdbSearchData *data = l->data;
+               EbSqlSearchData *data = l->data;
                gchar *vcard = NULL;
 
                vcard = data->vcard;
@@ -998,7 +996,7 @@ book_view_thread (gpointer data)
                g_free (vcard);
        }
 
-       g_slist_foreach (summary_list, (GFunc) e_book_backend_sqlitedb_search_data_free, NULL);
+       g_slist_foreach (summary_list, (GFunc) e_book_backend_sqlite_search_data_free, NULL);
        g_slist_free (summary_list);
 
        if (e_flag_is_set (closure->running))
@@ -1025,16 +1023,15 @@ view_notify_update (EBookBackendFile *backend,
        sexp = e_data_book_view_get_sexp (view);
        query = e_book_backend_sexp_text (sexp);
 
-       if (e_book_backend_sqlitedb_check_summary_query (backend->priv->sqlitedb, query, NULL) &&
-           e_book_backend_sqlitedb_check_summary_fields (backend->priv->sqlitedb, fields)) {
+       if (e_book_backend_sqlite_check_summary_query (backend->priv->sqlitedb, query, NULL) &&
+           e_book_backend_sqlite_check_summary_fields (backend->priv->sqlitedb, fields)) {
 
                const gchar *uid = e_contact_get_const (contact, E_CONTACT_UID);
                gchar       *vcard;
 
-               vcard = e_book_backend_sqlitedb_get_vcard_string (
+               vcard = e_book_backend_sqlite_get_vcard_string (
                        backend->priv->sqlitedb,
-                       SQLITEDB_FOLDER_ID, uid,
-                       fields, &with_all_required_fields, NULL);
+                       uid, fields, &with_all_required_fields, NULL);
 
                if (vcard) {
                        if (with_all_required_fields) {
@@ -1179,7 +1176,7 @@ book_backend_file_create_contacts_sync (EBookBackend *backend,
 
        g_rw_lock_writer_lock (&(bf->priv->lock));
 
-       success = e_book_backend_sqlitedb_lock_updates (bf->priv->sqlitedb, error);
+       success = e_book_backend_sqlite_lock_updates (bf->priv->sqlitedb, error);
 
        if (success)
                success = do_create (bf, vcards, out_contacts, error);
@@ -1188,13 +1185,13 @@ book_backend_file_create_contacts_sync (EBookBackend *backend,
                success = e_book_backend_file_bump_revision (bf, error);
 
        if (success)
-               success = e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb,
-                                                                 TRUE, error);
+               success = e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb,
+                                                               TRUE, error);
        else {
                GError *local_error = NULL;
 
                /* Rollback transaction */
-               if (!e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb, FALSE, &local_error)) {
+               if (!e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb, FALSE, &local_error)) {
                        g_warning ("Failed to rollback transaction after failing to add contacts: %s",
                                   local_error->message);
                        g_clear_error (&local_error);
@@ -1225,7 +1222,7 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
 
        g_rw_lock_writer_lock (&(bf->priv->lock));
 
-       if (!e_book_backend_sqlitedb_lock_updates (bf->priv->sqlitedb, error))
+       if (!e_book_backend_sqlite_lock_updates (bf->priv->sqlitedb, error))
                status = STATUS_ERROR;
 
        for (ii = 0; ii < length && status != STATUS_ERROR; ii++) {
@@ -1247,10 +1244,8 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
                        break;
                }
 
-               old_contact = e_book_backend_sqlitedb_get_contact (
-                       bf->priv->sqlitedb,
-                       SQLITEDB_FOLDER_ID, id,
-                       NULL, NULL, &local_error);
+               old_contact = e_book_backend_sqlite_get_contact (
+                       bf->priv->sqlitedb, id, NULL, NULL, &local_error);
                if (!old_contact) {
                        g_warning (G_STRLOC ": Failed to load contact %s: %s", id, local_error->message);
                        g_propagate_error (error, local_error);
@@ -1325,7 +1320,7 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
                        mod_link = g_list_next (mod_link);
                }
 
-               /* XXX EBookBackendSqliteDB still uses GSList. */
+               /* XXX EBookBackendSqlite still uses GSList. */
                mod_link = g_queue_peek_tail_link (&mod_contact_queue);
                while (mod_link != NULL) {
                        slist = g_slist_prepend (slist, mod_link->data);
@@ -1333,10 +1328,9 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
                }
 
                /* Update summary as well */
-               if (!e_book_backend_sqlitedb_new_contacts (bf->priv->sqlitedb,
-                                                          SQLITEDB_FOLDER_ID,
-                                                          slist, TRUE,
-                                                          &local_error)) {
+               if (!e_book_backend_sqlite_add_contacts (bf->priv->sqlitedb,
+                                                        slist, TRUE,
+                                                        &local_error)) {
                        g_warning ("Failed to modify contacts: %s", local_error->message);
                        g_propagate_error (error, local_error);
                        local_error = NULL;
@@ -1356,13 +1350,13 @@ book_backend_file_modify_contacts_sync (EBookBackend *backend,
        /* Commit or rollback transaction */
        if (status != STATUS_ERROR) {
 
-               if (!e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb,
-                                                            TRUE, error))
+               if (!e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb,
+                                                          TRUE, error))
                        status = STATUS_ERROR;
 
        } else {
                /* Rollback transaction */
-               if (!e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb, FALSE, &local_error)) {
+               if (!e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb, FALSE, &local_error)) {
                        g_warning ("Failed to rollback transaction after failing to modify contacts: %s",
                                   local_error->message);
                        g_clear_error (&local_error);
@@ -1418,7 +1412,7 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
 
        g_rw_lock_writer_lock (&(bf->priv->lock));
 
-       success = e_book_backend_sqlitedb_lock_updates (bf->priv->sqlitedb, error);
+       success = e_book_backend_sqlite_lock_updates (bf->priv->sqlitedb, error);
 
        for (ii = 0; ii < length && success; ii++) {
                EContact *contact;
@@ -1426,14 +1420,13 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
                /* First load the EContacts which need to be removed, we might delete some
                 * photos from disk because of this...
                 *
-                * Note: sqlitedb backend can probably make this faster by executing a
+                * Note: sqlite backend can probably make this faster by executing a
                 * single query to fetch a list of contacts for a list of ids, the
                 * current method makes a query for each UID.
                 */
-               contact = e_book_backend_sqlitedb_get_contact (
+               contact = e_book_backend_sqlite_get_contact (
                        bf->priv->sqlitedb,
-                       SQLITEDB_FOLDER_ID, uids[ii],
-                       NULL, NULL, &local_error);
+                       uids[ii], NULL, NULL, &local_error);
 
                if (contact) {
                        removed_ids      = g_slist_prepend (removed_ids, g_strdup (uids[ii]));
@@ -1441,8 +1434,8 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
                } else {
 
                        if (g_error_matches (local_error,
-                                            E_BOOK_SDB_ERROR,
-                                            E_BOOK_SDB_ERROR_CONTACT_NOT_FOUND)) {
+                                            E_BOOK_SQL_ERROR,
+                                            E_BOOK_SQL_ERROR_CONTACT_NOT_FOUND)) {
                                g_set_error (
                                        error, E_BOOK_CLIENT_ERROR,
                                        E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND,
@@ -1467,9 +1460,8 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
                }
 
                /* Remove from summary as well */
-               if (!e_book_backend_sqlitedb_remove_contacts (bf->priv->sqlitedb,
-                                                     SQLITEDB_FOLDER_ID,
-                                                     removed_ids, &local_error)) {
+               if (!e_book_backend_sqlite_remove_contacts (bf->priv->sqlitedb,
+                                                           removed_ids, &local_error)) {
                        g_warning ("Failed to remove contacts: %s", local_error->message);
                        g_propagate_error (error, local_error);
                }
@@ -1479,11 +1471,11 @@ book_backend_file_remove_contacts_sync (EBookBackend *backend,
 
        /* Commit or rollback transaction */
        if (success) {
-               success = e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb,
-                                                                 TRUE, error);
+               success = e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb,
+                                                               TRUE, error);
        } else {
                /* Rollback transaction */
-               if (!e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb, FALSE, &local_error)) {
+               if (!e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb, FALSE, &local_error)) {
                        g_warning ("Failed to rollback transaction after failing to modify contacts: %s",
                                   local_error->message);
                        g_clear_error (&local_error);
@@ -1517,10 +1509,9 @@ book_backend_file_get_contact_sync (EBookBackend *backend,
 
        g_rw_lock_reader_lock (&(bf->priv->lock));
 
-       contact = e_book_backend_sqlitedb_get_contact (
+       contact = e_book_backend_sqlite_get_contact (
                bf->priv->sqlitedb,
-               SQLITEDB_FOLDER_ID, uid,
-               NULL, NULL, &local_error);
+               uid, NULL, NULL, &local_error);
 
        g_rw_lock_reader_unlock (&(bf->priv->lock));
 
@@ -1532,8 +1523,8 @@ book_backend_file_get_contact_sync (EBookBackend *backend,
        if (local_error) {
 
                if (g_error_matches (local_error,
-                                    E_BOOK_SDB_ERROR,
-                                    E_BOOK_SDB_ERROR_CONTACT_NOT_FOUND)) {
+                                    E_BOOK_SQL_ERROR,
+                                    E_BOOK_SQL_ERROR_CONTACT_NOT_FOUND)) {
                        g_set_error (
                                error, E_BOOK_CLIENT_ERROR,
                                E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND,
@@ -1563,10 +1554,9 @@ book_backend_file_get_contact_list_sync (EBookBackend *backend,
        d (printf ("book_backend_file_get_contact_list_sync (%s)\n", query));
 
        g_rw_lock_reader_lock (&(bf->priv->lock));
-       summary_list = e_book_backend_sqlitedb_search (
-               bf->priv->sqlitedb, SQLITEDB_FOLDER_ID,
-               query, NULL,
-               NULL, NULL, &local_error);
+       summary_list = e_book_backend_sqlite_search (
+               bf->priv->sqlitedb,
+               query, NULL, NULL, NULL, &local_error);
        g_rw_lock_reader_unlock (&(bf->priv->lock));
 
        if (local_error != NULL) {
@@ -1574,8 +1564,8 @@ book_backend_file_get_contact_list_sync (EBookBackend *backend,
                g_warn_if_fail (summary_list == NULL);
 
                if (g_error_matches (local_error,
-                                    E_BOOK_SDB_ERROR,
-                                    E_BOOK_SDB_ERROR_NOT_SUPPORTED)) {
+                                    E_BOOK_SQL_ERROR,
+                                    E_BOOK_SQL_ERROR_NOT_SUPPORTED)) {
                        g_set_error (
                                error, E_CLIENT_ERROR,
                                E_CLIENT_ERROR_NOT_SUPPORTED,
@@ -1583,8 +1573,8 @@ book_backend_file_get_contact_list_sync (EBookBackend *backend,
                        g_error_free (local_error);
 
                } else if (g_error_matches (local_error,
-                                    E_BOOK_SDB_ERROR,
-                                    E_BOOK_SDB_ERROR_INVALID_QUERY)) {
+                                    E_BOOK_SQL_ERROR,
+                                    E_BOOK_SQL_ERROR_INVALID_QUERY)) {
                        g_set_error (
                                error, E_CLIENT_ERROR,
                                E_CLIENT_ERROR_INVALID_QUERY,
@@ -1600,7 +1590,7 @@ book_backend_file_get_contact_list_sync (EBookBackend *backend,
        }
 
        for (link = summary_list; link != NULL; link = g_slist_next (link)) {
-               EbSdbSearchData *data = link->data;
+               EbSqlSearchData *data = link->data;
                EContact *contact;
 
                contact = e_contact_new_from_vcard (data->vcard);
@@ -1609,7 +1599,7 @@ book_backend_file_get_contact_list_sync (EBookBackend *backend,
 
        g_slist_free_full (
                summary_list, (GDestroyNotify)
-               e_book_backend_sqlitedb_search_data_free);
+               e_book_backend_sqlite_search_data_free);
 
        return success;
 }
@@ -1630,9 +1620,8 @@ book_backend_file_get_contact_list_uids_sync (EBookBackend *backend,
        d (printf ("book_backend_file_get_contact_list_sync (%s)\n", query));
 
        g_rw_lock_reader_lock (&(bf->priv->lock));
-       uids = e_book_backend_sqlitedb_search_uids (
+       uids = e_book_backend_sqlite_search_uids (
                bf->priv->sqlitedb,
-               SQLITEDB_FOLDER_ID,
                query, NULL, &local_error);
        g_rw_lock_reader_unlock (&(bf->priv->lock));
 
@@ -1641,8 +1630,8 @@ book_backend_file_get_contact_list_uids_sync (EBookBackend *backend,
                g_warn_if_fail (uids == NULL);
 
                if (g_error_matches (local_error,
-                                    E_BOOK_SDB_ERROR,
-                                    E_BOOK_SDB_ERROR_NOT_SUPPORTED)) {
+                                    E_BOOK_SQL_ERROR,
+                                    E_BOOK_SQL_ERROR_NOT_SUPPORTED)) {
                        g_set_error (
                                error, E_CLIENT_ERROR,
                                E_CLIENT_ERROR_NOT_SUPPORTED,
@@ -1650,8 +1639,8 @@ book_backend_file_get_contact_list_uids_sync (EBookBackend *backend,
                        g_error_free (local_error);
 
                } else if (g_error_matches (local_error,
-                                    E_BOOK_SDB_ERROR,
-                                    E_BOOK_SDB_ERROR_INVALID_QUERY)) {
+                                    E_BOOK_SQL_ERROR,
+                                    E_BOOK_SQL_ERROR_INVALID_QUERY)) {
                        g_set_error (
                                error, E_CLIENT_ERROR,
                                E_CLIENT_ERROR_INVALID_QUERY,
@@ -1787,8 +1776,8 @@ book_backend_file_set_locale (EBookBackend *backend,
 
        g_rw_lock_writer_lock (&(bf->priv->lock));
 
-       success = e_book_backend_sqlitedb_lock_updates (bf->priv->sqlitedb,
-                                                       &error);
+       success = e_book_backend_sqlite_lock_updates (bf->priv->sqlitedb,
+                                                     &error);
 
        if (!success) {
                g_warning ("Failed to start SQLite transaction: %s", error->message);
@@ -1796,12 +1785,11 @@ book_backend_file_set_locale (EBookBackend *backend,
        }
 
        if (success) {
-               success = e_book_backend_sqlitedb_set_locale (bf->priv->sqlitedb,
-                                                             SQLITEDB_FOLDER_ID,
-                                                             locale,
-                                                             &error);
+               success = e_book_backend_sqlite_set_locale (bf->priv->sqlitedb,
+                                                           locale,
+                                                           &error);
                if (!success) {
-                       g_warning ("Failed to set locale on SQLiteDB: %s", error->message);
+                       g_warning ("Failed to set locale on SQLite: %s", error->message);
                        g_clear_error (&error);
                }
        }
@@ -1810,14 +1798,14 @@ book_backend_file_set_locale (EBookBackend *backend,
                success = e_book_backend_file_bump_revision (bf, &error);
 
                if (!success) {
-                       g_warning ("Failed to set locale on SQLiteDB: %s", error->message);
+                       g_warning ("Failed to set locale on SQLite: %s", error->message);
                        g_clear_error (&error);
                }
        }
 
        if (success) {
-               success = e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb,
-                                                                 TRUE, &error);
+               success = e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb,
+                                                               TRUE, &error);
 
                if (!success) {
                        g_warning ("Failed to commit SQLite transaction: %s", error->message);
@@ -1828,7 +1816,7 @@ book_backend_file_set_locale (EBookBackend *backend,
                GError *error = NULL;
 
                /* Rollback transaction */
-               if (!e_book_backend_sqlitedb_unlock_updates (bf->priv->sqlitedb, FALSE, &error)) {
+               if (!e_book_backend_sqlite_unlock_updates (bf->priv->sqlitedb, FALSE, &error)) {
                        g_warning ("Failed to rollback transaction after failing to add contacts: %s",
                                   error->message);
                        g_clear_error (&error);
@@ -1873,7 +1861,7 @@ book_backend_file_create_cursor (EBookBackend *backend,
 
        cursor = e_data_book_cursor_sqlite_new (backend,
                                                bf->priv->sqlitedb,
-                                               SQLITEDB_FOLDER_ID,
+                                               SQLITE_REVISION_KEY,
                                                sort_fields,
                                                sort_types,
                                                n_fields,
@@ -1925,9 +1913,8 @@ book_backend_file_initable_init (GInitable *initable,
        ESourceRegistry *registry;
        ESource *source;
        const gchar *extension_name;
-       gchar *backup;
-       gchar *dirname;
-       gchar *filename;
+       gchar *backup, *dirname;
+       gchar *filename, *fullpath;
        gboolean success = TRUE;
 
        priv = E_BOOK_BACKEND_FILE_GET_PRIVATE (initable);
@@ -1946,15 +1933,14 @@ book_backend_file_initable_init (GInitable *initable,
                        registry, source, GET_PATH_DB_DIR);
 
        filename = g_build_filename (dirname, "addressbook.db", NULL);
-       backup = g_build_filename (dirname, "addressbook.db.old", NULL);
+       backup   = g_build_filename (dirname, "addressbook.db.old", NULL);
+       fullpath = g_build_filename (dirname, "contacts.db", NULL);
 
        /* The old BDB exists, lets migrate that to sqlite right away. */
        if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
-               priv->sqlitedb = e_book_backend_sqlitedb_new_full (
-                       dirname,
-                       SQLITEDB_EMAIL_ID,
+               priv->sqlitedb = e_book_backend_sqlite_new_full (
+                       fullpath,
                        SQLITEDB_FOLDER_ID,
-                       SQLITEDB_FOLDER_NAME,
                        TRUE, setup_extension,
                        error);
 
@@ -1963,10 +1949,9 @@ book_backend_file_initable_init (GInitable *initable,
                        goto exit;
                }
 
+               /* Do the migration from BDB, see e-book-backend-file-migrate-bdb.c */
                success = e_book_backend_file_migrate_bdb (
-                       priv->sqlitedb,
-                       SQLITEDB_FOLDER_ID,
-                       dirname, filename, error);
+                       priv->sqlitedb, dirname, filename, error);
 
                if (!success)
                        goto exit;
@@ -1988,7 +1973,7 @@ book_backend_file_initable_init (GInitable *initable,
        /* If we already have a handle on this, it means there
         * was an old BDB migrated and no need to reopen it. */
        if (priv->sqlitedb == NULL) {
-               gboolean populated;
+               gint populated = 0;
                GError *local_error = NULL;
 
                /* Ensure the directory exists first. */
@@ -1998,11 +1983,9 @@ book_backend_file_initable_init (GInitable *initable,
                        goto exit;
 
                /* Create the sqlitedb. */
-               priv->sqlitedb = e_book_backend_sqlitedb_new_full (
-                       dirname,
-                       SQLITEDB_EMAIL_ID,
+               priv->sqlitedb = e_book_backend_sqlite_new_full (
+                       fullpath,
                        SQLITEDB_FOLDER_ID,
-                       SQLITEDB_FOLDER_NAME,
                        TRUE, setup_extension,
                        error);
 
@@ -2012,9 +1995,10 @@ book_backend_file_initable_init (GInitable *initable,
                }
 
                /* An sqlite DB only 'exists' if the populated flag is set. */
-               populated = e_book_backend_sqlitedb_get_is_populated (
+               e_book_backend_sqlite_get_key_value_int (
                        priv->sqlitedb,
-                       SQLITEDB_FOLDER_ID,
+                       E_BOOK_SQL_IS_POPULATED_KEY,
+                       &populated,
                        &local_error);
 
                if (local_error != NULL) {
@@ -2025,10 +2009,11 @@ book_backend_file_initable_init (GInitable *initable,
 
                if (!populated) {
                        /* Set the populated flag. */
-                       success = e_book_backend_sqlitedb_set_is_populated (
+                       success = e_book_backend_sqlite_set_key_value_int (
                                priv->sqlitedb,
-                               SQLITEDB_FOLDER_ID,
-                               TRUE, error);
+                               E_BOOK_SQL_IS_POPULATED_KEY,
+                               TRUE,
+                               error);
 
                        if (!success)
                                goto exit;
@@ -2046,6 +2031,7 @@ book_backend_file_initable_init (GInitable *initable,
 
 exit:
        g_free (dirname);
+       g_free (fullpath);
        g_free (filename);
        g_free (backup);
 


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