[evolution-data-server/sqlite-refactor] EBookBackendSqliteDB: Refactoring work in progress.



commit 9fa4d4cb0c48c8d550a62ed586ef374eaa764e62
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Thu Nov 14 17:43:11 2013 +0900

    EBookBackendSqliteDB: Refactoring work in progress.

 .../libedata-book/e-book-backend-sqlitedb.c        |  379 +++++++++-----------
 1 files changed, 176 insertions(+), 203 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index fb21912..768e287 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -99,6 +99,9 @@ struct _EBookBackendSqliteDBPrivate {
 
 G_DEFINE_TYPE (EBookBackendSqliteDB, e_book_backend_sqlitedb, G_TYPE_OBJECT)
 
+G_DEFINE_QUARK (e-book-backend-sqlitedb-error-quark,
+               e_book_backend_sqlitedb_error)
+
 static GHashTable *db_connections = NULL;
 static GMutex dbcon_lock;
 
@@ -129,73 +132,157 @@ static EBookIndexType default_index_types[] = {
        E_BOOK_INDEX_PREFIX
 };
 
-static void
-destroy_search_data (gpointer data)
+/******************************************************
+ *                  Summary Fields                    *
+ ******************************************************/
+
+static SummaryField *
+summary_field_append (GArray *array,
+                      EContactField field,
+                      gboolean *have_attr_list,
+                      GError **error)
 {
-       e_book_backend_sqlitedb_search_data_free (data);
-}
+       const gchar *dbname = NULL;
+       GType        type = G_TYPE_INVALID;
+       gint         i;
+       SummaryField new_field = { 0, };
 
-static SummaryField * append_summary_field (GArray         *array,
-                                           EContactField   field,
-                                           gboolean       *have_attr_list,
-                                           GError        **error);
+       if (field < 1 || field >= E_CONTACT_FIELD_LAST) {
+               g_set_error (
+                       error, E_BOOK_SDB_ERROR, E_BOOK_SDB_ERROR_OTHER,
+                       _("Invalid contact field '%d' specified in summary"), field);
+               return NULL;
+       }
 
-static gboolean upgrade_contacts_table (EBookBackendSqliteDB *ebsdb,
-                                       const gchar          *folderid,
-                                       const gchar          *region,
-                                       const gchar          *lc_collate,
-                                       GError              **error);
-static gboolean sqlitedb_set_locale_internal (EBookBackendSqliteDB *ebsdb,
-                                             const gchar          *locale,
-                                             GError              **error);
+       /* Avoid including the same field twice in the summary */
+       for (i = 0; i < array->len; i++) {
+               SummaryField *iter = &g_array_index (array, SummaryField, i);
+               if (field == iter->field)
+                       return iter;
+       }
 
-static const gchar *
-summary_dbname_from_field (EBookBackendSqliteDB *ebsdb,
-                           EContactField field)
-{
-       gint i;
+       /* Resolve some exceptions, we store these
+        * specific contact fields with different names
+        * than those found in the EContactField table
+        */
+       switch (field) {
+       case E_CONTACT_UID:
+               dbname = "uid";
+               break;
+       case E_CONTACT_IS_LIST:
+               dbname = "is_list";
+               break;
+       default:
+               dbname = e_contact_field_name (field);
+               break;
+       }
 
-       for (i = 0; i < ebsdb->priv->n_summary_fields; i++) {
-               if (ebsdb->priv->summary_fields[i].field == field)
-                       return ebsdb->priv->summary_fields[i].dbname;
+       type = e_contact_field_type (field);
+
+       if (type != G_TYPE_STRING &&
+           type != G_TYPE_BOOLEAN &&
+           type != E_TYPE_CONTACT_ATTR_LIST) {
+               g_set_error (
+                       error, E_BOOK_SDB_ERROR, E_BOOK_SDB_ERROR_OTHER,
+                       _("Contact field '%s' of type '%s' specified in summary, "
+                       "but only boolean, string and string list field types are supported"),
+                       e_contact_pretty_name (field), g_type_name (type));
+               return NULL;
        }
 
-       return NULL;
+       if (type == E_TYPE_CONTACT_ATTR_LIST && have_attr_list)
+               *have_attr_list = TRUE;
+
+       new_field.field  = field;
+       new_field.dbname = dbname;
+       new_field.type   = type;
+       new_field.index  = 0;
+       g_array_append_val (array, new_field);
+
+       return &g_array_index (array, SummaryField, array->len - 1);
 }
 
-static gint
-summary_index_from_field (EBookBackendSqliteDB *ebsdb,
-                         EContactField         field)
+static void
+summary_fields_add_indexes (GArray *array,
+                            EContactField *indexes,
+                            EBookIndexType *index_types,
+                            gint n_indexes,
+                            IndexFlags *attr_list_indexes)
+{
+       gint i, j;
+
+       for (i = 0; i < array->len; i++) {
+               SummaryField *sfield = &g_array_index (array, SummaryField, i);
+
+               for (j = 0; j < n_indexes; j++) {
+                       if (sfield->field == indexes[j]) {
+                               switch (index_types[j]) {
+                               case E_BOOK_INDEX_PREFIX:
+                                       sfield->index |= INDEX_PREFIX;
+
+                                       if (sfield->type == E_TYPE_CONTACT_ATTR_LIST)
+                                               *attr_list_indexes |= INDEX_PREFIX;
+                                       break;
+                               case E_BOOK_INDEX_SUFFIX:
+                                       sfield->index |= INDEX_SUFFIX;
+
+                                       if (sfield->type == E_TYPE_CONTACT_ATTR_LIST)
+                                               *attr_list_indexes |= INDEX_SUFFIX;
+                                       break;
+                               case E_BOOK_INDEX_PHONE:
+                                       sfield->index |= INDEX_PHONE;
+
+                                       if (sfield->type == E_TYPE_CONTACT_ATTR_LIST)
+                                               *attr_list_indexes |= INDEX_PHONE;
+                                       break;
+                               default:
+                                       g_warn_if_reached ();
+                                       break;
+                               }
+                       }
+               }
+       }
+}
+
+static SummaryField *
+summary_field_get (EBookBackendSqliteDB *ebsdb,
+                  EContactField         field)
 {
        gint i;
 
        for (i = 0; i < ebsdb->priv->n_summary_fields; i++) {
                if (ebsdb->priv->summary_fields[i].field == field)
-                       return i;
+                       return &(ebsdb->priv->summary_fields[i]);
        }
 
-       return -1;
+       return NULL;
 }
 
-static gint
-summary_index_from_field_name (EBookBackendSqliteDB *ebsdb,
-                               const gchar *field_name)
+static SummaryField *
+summary_field_get_by_name (EBookBackendSqliteDB *ebsdb,
+                          const gchar          *field_name)
 {
        EContactField field;
 
        field = e_contact_field_id (field_name);
 
-       return summary_index_from_field (ebsdb, field);
+       return summary_field_get (ebsdb, field);
 }
 
-typedef struct {
-       EBookBackendSqliteDB *ebsdb;
-       GSList *list;
-} StoreVCardData;
 
-G_DEFINE_QUARK (
-       e-book-backend-sqlitedb-error-quark,
-       e_book_backend_sqlitedb_error)
+
+
+
+
+
+static gboolean upgrade_contacts_table (EBookBackendSqliteDB *ebsdb,
+                                       const gchar          *folderid,
+                                       const gchar          *region,
+                                       const gchar          *lc_collate,
+                                       GError              **error);
+static gboolean sqlitedb_set_locale_internal (EBookBackendSqliteDB *ebsdb,
+                                             const gchar          *locale,
+                                             GError              **error);
 
 static void
 e_book_backend_sqlitedb_dispose (GObject *object)
@@ -910,7 +997,7 @@ introspect_summary (EBookBackendSqliteDB *ebsdb,
                                }
                        }
                } else {
-                       append_summary_field (summary_fields, field, NULL, NULL);
+                       summary_field_append (summary_fields, field, NULL, NULL);
                }
        }
 
@@ -940,7 +1027,7 @@ introspect_summary (EBookBackendSqliteDB *ebsdb,
 
                        params = g_strsplit (fields[i], ";", 0);
                        field = e_contact_field_id (params[0]);
-                       iter = append_summary_field (summary_fields, field, &have_attr_list, NULL);
+                       iter = summary_field_append (summary_fields, field, &have_attr_list, NULL);
 
                        if (iter) {
                                for (j = 1; params[j]; ++j) {
@@ -1143,11 +1230,11 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                        /* Derive index name from field & folder */
                        tmp = g_strdup_printf (
                                "INDEX_%s_%s",
-                               summary_dbname_from_field (ebsdb, ebsdb->priv->summary_fields[i].field),
+                               ebsdb->priv->summary_fields[i].dbname,
                                folderid);
                        stmt = sqlite3_mprintf (
                                "CREATE INDEX IF NOT EXISTS %Q ON %Q (%s)", tmp, folderid,
-                               summary_dbname_from_field (ebsdb, ebsdb->priv->summary_fields[i].field));
+                               ebsdb->priv->summary_fields[i].dbname);
                        success = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, error);
                        sqlite3_free (stmt);
                        g_free (tmp);
@@ -1156,11 +1243,11 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                        if (ebsdb->priv->summary_fields[i].field != E_CONTACT_REV) {
                                tmp = g_strdup_printf (
                                        "INDEX_%s_localized_%s",
-                                       summary_dbname_from_field (ebsdb, 
ebsdb->priv->summary_fields[i].field),
+                                       ebsdb->priv->summary_fields[i].dbname,
                                        folderid);
                                stmt = sqlite3_mprintf (
                                        "CREATE INDEX IF NOT EXISTS %Q ON %Q (%s_localized)", tmp, folderid,
-                                       summary_dbname_from_field (ebsdb, 
ebsdb->priv->summary_fields[i].field));
+                                       ebsdb->priv->summary_fields[i].dbname);
                                success = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, error);
                                sqlite3_free (stmt);
                                g_free (tmp);
@@ -1173,11 +1260,11 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                        /* Derive index name from field & folder */
                        tmp = g_strdup_printf (
                                "RINDEX_%s_%s",
-                               summary_dbname_from_field (ebsdb, ebsdb->priv->summary_fields[i].field),
+                               ebsdb->priv->summary_fields[i].dbname,
                                folderid);
                        stmt = sqlite3_mprintf (
                                "CREATE INDEX IF NOT EXISTS %Q ON %Q (%s_reverse)", tmp, folderid,
-                               summary_dbname_from_field (ebsdb, ebsdb->priv->summary_fields[i].field));
+                               ebsdb->priv->summary_fields[i].dbname);
                        success = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, error);
                        sqlite3_free (stmt);
                        g_free (tmp);
@@ -1188,11 +1275,11 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                        /* Derive index name from field & folder */
                        tmp = g_strdup_printf (
                                "PINDEX_%s_%s",
-                               summary_dbname_from_field (ebsdb, ebsdb->priv->summary_fields[i].field),
+                               ebsdb->priv->summary_fields[i].dbname,
                                folderid);
                        stmt = sqlite3_mprintf (
                                "CREATE INDEX IF NOT EXISTS %Q ON %Q (%s_phone)", tmp, folderid,
-                               summary_dbname_from_field (ebsdb, ebsdb->priv->summary_fields[i].field));
+                               ebsdb->priv->summary_fields[i].dbname);
                        success = book_backend_sql_exec (ebsdb->priv->db, stmt, NULL, NULL, error);
                        sqlite3_free (stmt);
                        g_free (tmp);
@@ -1669,114 +1756,6 @@ e_book_backend_sqlitedb_new_internal (const gchar *path,
        return ebsdb;
 }
 
-static SummaryField *
-append_summary_field (GArray *array,
-                      EContactField field,
-                      gboolean *have_attr_list,
-                      GError **error)
-{
-       const gchar *dbname = NULL;
-       GType        type = G_TYPE_INVALID;
-       gint         i;
-       SummaryField new_field = { 0, };
-
-       if (field < 1 || field >= E_CONTACT_FIELD_LAST) {
-               g_set_error (
-                       error, E_BOOK_SDB_ERROR, E_BOOK_SDB_ERROR_OTHER,
-                       _("Invalid contact field '%d' specified in summary"), field);
-               return NULL;
-       }
-
-       /* Avoid including the same field twice in the summary */
-       for (i = 0; i < array->len; i++) {
-               SummaryField *iter = &g_array_index (array, SummaryField, i);
-               if (field == iter->field)
-                       return iter;
-       }
-
-       /* Resolve some exceptions, we store these
-        * specific contact fields with different names
-        * than those found in the EContactField table
-        */
-       switch (field) {
-       case E_CONTACT_UID:
-               dbname = "uid";
-               break;
-       case E_CONTACT_IS_LIST:
-               dbname = "is_list";
-               break;
-       default:
-               dbname = e_contact_field_name (field);
-               break;
-       }
-
-       type = e_contact_field_type (field);
-
-       if (type != G_TYPE_STRING &&
-           type != G_TYPE_BOOLEAN &&
-           type != E_TYPE_CONTACT_ATTR_LIST) {
-               g_set_error (
-                       error, E_BOOK_SDB_ERROR, E_BOOK_SDB_ERROR_OTHER,
-                       _("Contact field '%s' of type '%s' specified in summary, "
-                       "but only boolean, string and string list field types are supported"),
-                       e_contact_pretty_name (field), g_type_name (type));
-               return NULL;
-       }
-
-       if (type == E_TYPE_CONTACT_ATTR_LIST && have_attr_list)
-               *have_attr_list = TRUE;
-
-       new_field.field  = field;
-       new_field.dbname = dbname;
-       new_field.type   = type;
-       new_field.index  = 0;
-       g_array_append_val (array, new_field);
-
-       return &g_array_index (array, SummaryField, array->len - 1);
-}
-
-static void
-summary_fields_add_indexes (GArray *array,
-                            EContactField *indexes,
-                            EBookIndexType *index_types,
-                            gint n_indexes,
-                            IndexFlags *attr_list_indexes)
-{
-       gint i, j;
-
-       for (i = 0; i < array->len; i++) {
-               SummaryField *sfield = &g_array_index (array, SummaryField, i);
-
-               for (j = 0; j < n_indexes; j++) {
-                       if (sfield->field == indexes[j]) {
-                               switch (index_types[j]) {
-                               case E_BOOK_INDEX_PREFIX:
-                                       sfield->index |= INDEX_PREFIX;
-
-                                       if (sfield->type == E_TYPE_CONTACT_ATTR_LIST)
-                                               *attr_list_indexes |= INDEX_PREFIX;
-                                       break;
-                               case E_BOOK_INDEX_SUFFIX:
-                                       sfield->index |= INDEX_SUFFIX;
-
-                                       if (sfield->type == E_TYPE_CONTACT_ATTR_LIST)
-                                               *attr_list_indexes |= INDEX_SUFFIX;
-                                       break;
-                               case E_BOOK_INDEX_PHONE:
-                                       sfield->index |= INDEX_PHONE;
-
-                                       if (sfield->type == E_TYPE_CONTACT_ATTR_LIST)
-                                               *attr_list_indexes |= INDEX_PHONE;
-                                       break;
-                               default:
-                                       g_warn_if_reached ();
-                                       break;
-                               }
-                       }
-               }
-       }
-}
-
 /**
  * e_book_backend_sqlitedb_new_full:
  * @path: location where the db would be created
@@ -1837,11 +1816,11 @@ e_book_backend_sqlitedb_new_full (const gchar *path,
        summary_fields = g_array_new (FALSE, FALSE, sizeof (SummaryField));
 
        /* Ensure the non-optional fields first */
-       append_summary_field (summary_fields, E_CONTACT_UID, &have_attr_list, error);
-       append_summary_field (summary_fields, E_CONTACT_REV, &have_attr_list, error);
+       summary_field_append (summary_fields, E_CONTACT_UID, &have_attr_list, error);
+       summary_field_append (summary_fields, E_CONTACT_REV, &have_attr_list, error);
 
        for (i = 0; i < n_fields; i++) {
-               if (!append_summary_field (summary_fields, fields[i], &have_attr_list, error)) {
+               if (!summary_field_append (summary_fields, fields[i], &have_attr_list, error)) {
                        had_error = TRUE;
                        break;
                }
@@ -1910,7 +1889,7 @@ e_book_backend_sqlitedb_new (const gchar *path,
        /* Create the default summary structs */
        summary_fields = g_array_new (FALSE, FALSE, sizeof (SummaryField));
        for (i = 0; i < G_N_ELEMENTS (default_summary_fields); i++)
-               append_summary_field (summary_fields, default_summary_fields[i], &have_attr_list, NULL);
+               summary_field_append (summary_fields, default_summary_fields[i], &have_attr_list, NULL);
 
        /* Add the default index flags */
        summary_fields_add_indexes (
@@ -2844,9 +2823,8 @@ e_book_backend_sqlitedb_check_summary_fields (EBookBackendSqliteDB *ebsdb,
        g_hash_table_iter_init (&iter, fields_of_interest);
        while (g_hash_table_iter_next (&iter, &key, &value)) {
                const gchar  *field_name = key;
-               EContactField field      = e_contact_field_id (field_name);
-
-               if (summary_dbname_from_field (ebsdb, field) == NULL) {
+               
+               if (!summary_field_get_by_name (ebsdb, field_name)) {
                        summary_fields = FALSE;
                        break;
                }
@@ -2972,7 +2950,7 @@ e_book_backend_sqlitedb_get_vcard_string (EBookBackendSqliteDB *ebsdb,
                        vcard_str = s_data->vcard;
                        s_data->vcard = NULL;
 
-                       g_slist_free_full (vcards, destroy_search_data);
+                       g_slist_free_full (vcards, (GDestroyNotify)e_book_backend_sqlitedb_search_data_free);
                        vcards = NULL;
                }
 
@@ -3519,15 +3497,15 @@ field_name_and_query_term (EBookBackendSqliteDB *ebsdb,
                            gchar **query_term,
                            gchar **extra_term)
 {
-       gint summary_index;
+       SummaryField *field;
        gchar *field_name = NULL;
        gchar *value = NULL;
        gchar *extra = NULL;
        gboolean list_attr = FALSE;
 
-       summary_index = summary_index_from_field_name (ebsdb, field_name_input);
+       field = summary_field_get_by_name (ebsdb, field_name_input);
 
-       if (summary_index < 0) {
+       if (field == NULL) {
                g_critical ("Only summary field matches should be converted to sql queries");
                field_name = g_strconcat (folderid, ".", field_name_input, NULL);
                value = convert_string_value (
@@ -3538,22 +3516,21 @@ field_name_and_query_term (EBookBackendSqliteDB *ebsdb,
                gboolean phone_search = FALSE;
 
                /* If its a suffix search and we have reverse data to search... */
-               if (match == MATCH_ENDS_WITH &&
-                   (ebsdb->priv->summary_fields[summary_index].index & INDEX_SUFFIX) != 0)
+               if (match == MATCH_ENDS_WITH && (field->index & INDEX_SUFFIX) != 0)
                        suffix_search = TRUE;
 
                /* If its a phone-number search and we have E.164 data to search... */
                else if ((match == MATCH_PHONE_NUMBER ||
-                               match == MATCH_NATIONAL_PHONE_NUMBER ||
-                               match == MATCH_SHORT_PHONE_NUMBER) &&
-                   (ebsdb->priv->summary_fields[summary_index].index & INDEX_PHONE) != 0)
+                         match == MATCH_NATIONAL_PHONE_NUMBER ||
+                         match == MATCH_SHORT_PHONE_NUMBER) &&
+                        (field->index & INDEX_PHONE) != 0)
                        phone_search = TRUE;
 
                /* Or also if its an exact match, and we *only* have reverse data which is indexed,
                 * then prefer the indexed reverse search. */
                else if (match == MATCH_IS &&
-                        (ebsdb->priv->summary_fields[summary_index].index & INDEX_SUFFIX) != 0 &&
-                        (ebsdb->priv->summary_fields[summary_index].index & INDEX_PREFIX) == 0)
+                        (field->index & INDEX_SUFFIX) != 0 &&
+                        (field->index & INDEX_PREFIX) == 0)
                        suffix_search = TRUE;
 
                if (suffix_search) {
@@ -3562,17 +3539,17 @@ field_name_and_query_term (EBookBackendSqliteDB *ebsdb,
                         *  o Check the reversed column instead
                         *  o Make it a prefix search
                         */
-                       if (ebsdb->priv->summary_fields[summary_index].type == E_TYPE_CONTACT_ATTR_LIST) {
+                       if (field->type == E_TYPE_CONTACT_ATTR_LIST) {
                                field_name = g_strdup ("multi.value_reverse");
                                list_attr = TRUE;
                        } else
                                field_name = g_strconcat (
                                        "summary.",
-                                       ebsdb->priv->summary_fields[summary_index].dbname,
+                                       field->dbname,
                                        "_reverse", NULL);
 
-                       if (ebsdb->priv->summary_fields[summary_index].field == E_CONTACT_UID ||
-                           ebsdb->priv->summary_fields[summary_index].field == E_CONTACT_REV)
+                       if (field->field == E_CONTACT_UID ||
+                           field->field == E_CONTACT_REV)
                                value = convert_string_value (
                                        ebsdb, query_term_input, region, CONVERT_REVERSE,
                                        (match == MATCH_ENDS_WITH) ? MATCH_BEGINS_WITH : MATCH_IS);
@@ -3588,13 +3565,13 @@ field_name_and_query_term (EBookBackendSqliteDB *ebsdb,
                         */
                        const gint country_code = e_phone_number_get_country_code_for_region (region, NULL);
 
-                       if (ebsdb->priv->summary_fields[summary_index].type == E_TYPE_CONTACT_ATTR_LIST) {
+                       if (field->type == E_TYPE_CONTACT_ATTR_LIST) {
                                field_name = g_strdup ("multi.value_phone");
                                list_attr = TRUE;
                        } else {
                                field_name = g_strdup_printf (
                                        "summary.%s_phone",
-                                       ebsdb->priv->summary_fields[summary_index].dbname);
+                                       field->dbname);
                        }
 
                        if (match == MATCH_PHONE_NUMBER) {
@@ -3624,16 +3601,16 @@ field_name_and_query_term (EBookBackendSqliteDB *ebsdb,
 
                        }
                } else {
-                       if (ebsdb->priv->summary_fields[summary_index].type == E_TYPE_CONTACT_ATTR_LIST) {
+                       if (field->type == E_TYPE_CONTACT_ATTR_LIST) {
                                field_name = g_strdup ("multi.value");
                                list_attr = TRUE;
                        } else
                                field_name = g_strconcat (
                                        "summary.",
-                                       ebsdb->priv->summary_fields[summary_index].dbname, NULL);
+                                       field->dbname, NULL);
 
-                       if (ebsdb->priv->summary_fields[summary_index].field == E_CONTACT_UID ||
-                           ebsdb->priv->summary_fields[summary_index].field == E_CONTACT_REV) {
+                       if (field->field == E_CONTACT_UID ||
+                           field->field == E_CONTACT_REV) {
                                value = convert_string_value (
                                        ebsdb, query_term_input, region,
                                        CONVERT_NOTHING, match);
@@ -3719,7 +3696,7 @@ convert_match_exp (struct _ESExp *f,
                                g_free (field_name);
                                g_free (query_term);
 
-                               if (summary_dbname_from_field (ebsdb, E_CONTACT_FAMILY_NAME)) {
+                               if (summary_field_get (ebsdb, E_CONTACT_FAMILY_NAME)) {
                                        field_name = field_name_and_query_term (
                                                ebsdb, qdata->folderid, "family_name",
                                                argv[1]->value.string, NULL,
@@ -3731,7 +3708,7 @@ convert_match_exp (struct _ESExp *f,
                                        g_free (query_term);
                                }
 
-                               if (summary_dbname_from_field (ebsdb, E_CONTACT_GIVEN_NAME)) {
+                               if (summary_field_get (ebsdb, E_CONTACT_GIVEN_NAME)) {
                                        field_name = field_name_and_query_term (
                                                ebsdb, qdata->folderid, "given_name",
                                                argv[1]->value.string, NULL,
@@ -3743,7 +3720,7 @@ convert_match_exp (struct _ESExp *f,
                                        g_free (query_term);
                                }
 
-                               if (summary_dbname_from_field (ebsdb, E_CONTACT_NICKNAME)) {
+                               if (summary_field_get (ebsdb, E_CONTACT_NICKNAME)) {
                                        field_name = field_name_and_query_term (
                                                ebsdb, qdata->folderid, "nickname",
                                                argv[1]->value.string, NULL,
@@ -5079,7 +5056,7 @@ upgrade_contacts_table (EBookBackendSqliteDB *ebsdb,
                g_object_unref (contact);
        }
 
-       g_slist_free_full (vcard_data, destroy_search_data);
+       g_slist_free_full (vcard_data, (GDestroyNotify)e_book_backend_sqlitedb_search_data_free);
 
        if (success) {
 
@@ -5447,19 +5424,17 @@ ebsdb_cursor_order_by_fragment (EBookBackendSqliteDB *ebsdb,
                                gboolean              reverse)
 {
        GString *string;
-       const gchar *field_name;
        gint i;
 
        string = g_string_new ("ORDER BY ");
 
        for (i = 0; i < n_sort_fields; i++) {
-
-               field_name = summary_dbname_from_field (ebsdb, sort_fields[i]);
+               SummaryField *field = summary_field_get (ebsdb, sort_fields[i]);
 
                if (i > 0)
                        g_string_append (string, ", ");
 
-               g_string_append_printf (string, "summary.%s_localized %s", field_name,
+               g_string_append_printf (string, "summary.%s_localized %s", field->dbname,
                                        reverse ?
                                        (sort_types[i] == E_BOOK_CURSOR_SORT_ASCENDING ? "DESC" : "ASC") :
                                        (sort_types[i] == E_BOOK_CURSOR_SORT_ASCENDING ? "ASC"  : "DESC"));
@@ -5547,7 +5522,7 @@ ebsdb_cursor_constraints (EBookBackendSqliteDB *ebsdb,
                          gboolean              include_current_uid)
 {
        GString *string;
-       const gchar *field_name;
+       SummaryField *field;
        gint i, j;
 
        /* Example for:
@@ -5590,16 +5565,15 @@ ebsdb_cursor_constraints (EBookBackendSqliteDB *ebsdb,
 
                /* Create the '=' statements leading up to the current tie breaker */
                for (j = 0; j < i; j++) {
-                       field_name = summary_dbname_from_field (ebsdb, cursor->sort_fields[j]);
+                       field = summary_field_get (ebsdb, cursor->sort_fields[j]);
 
                        stmt = sqlite3_mprintf ("summary.%s_localized = %Q",
-                                               field_name, state->values[j]);
+                                               field->dbname, state->values[j]);
 
                        g_string_append (string, stmt);
                        g_string_append (string, " AND ");
 
                        sqlite3_free (stmt);
-
                }
 
                if (i == cursor->n_sort_fields) {
@@ -5643,10 +5617,9 @@ ebsdb_cursor_constraints (EBookBackendSqliteDB *ebsdb,
                                g_string_append_c (string, '(');
 
                        /* Append the final qualifier for this field */
-                       field_name = summary_dbname_from_field (ebsdb, cursor->sort_fields[i]);
-
+                       field = summary_field_get (ebsdb, cursor->sort_fields[i]);
                        stmt = sqlite3_mprintf ("summary.%s_localized %c %Q",
-                                               field_name,
+                                               field->dbname,
                                                GREATER_OR_LESS (cursor, i, reverse),
                                                state->values[i]);
 
@@ -5656,7 +5629,7 @@ ebsdb_cursor_constraints (EBookBackendSqliteDB *ebsdb,
                        if (include_exact_match) {
 
                                stmt = sqlite3_mprintf (" OR summary.%s_localized = %Q",
-                                                       field_name, state->values[i]);
+                                                       field->dbname, state->values[i]);
 
                                g_string_append (string, stmt);
                                g_string_append_c (string, ')');


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