[evolution-data-server/openismus-work-master: 104/122] EBookBackendSqliteDB: Adding comments around loops



commit 7e9016c62386d4d939e474be40189ffd075088bb
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sun Oct 6 00:43:59 2013 +0200

    EBookBackendSqliteDB: Adding comments around loops

 .../libedata-book/e-book-backend-sqlitedb.c        |   39 ++++++++++++++------
 1 files changed, 27 insertions(+), 12 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index be89513..ac77c5d 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -1008,6 +1008,12 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
        string = g_string_new (
                "CREATE TABLE IF NOT EXISTS %Q ( uid TEXT PRIMARY KEY, ");
 
+       /* Add column creation statements for each summary field.
+        *
+        * Start looping over the summary fields only starting with the second element,
+        * the first element (which is always the UID), is already specified in the
+        * CREATE TABLE statement which we are building.
+        */
        for (i = 1; i < ebsdb->priv->n_summary_fields; i++) {
                if (ebsdb->priv->summary_fields[i].type == G_TYPE_STRING) {
                        g_string_append (string, ebsdb->priv->summary_fields[i].dbname);
@@ -1059,14 +1065,17 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
 
                tmp = sqlite3_mprintf ("ALTER TABLE %Q ADD COLUMN ", folderid);
 
-               for (i = 1; i < ebsdb->priv->n_summary_fields && success; i++) {
+               /* UID and REV are always the first two summary fields, in this
+                * case we want to localize all strings EXCEPT these two, so
+                * we start iterating with the third element.
+                */
+               for (i = 2; i < ebsdb->priv->n_summary_fields && success; i++) {
 
-                       if (ebsdb->priv->summary_fields[i].type == G_TYPE_STRING &&
-                           ebsdb->priv->summary_fields[i].field != E_CONTACT_REV) {
+                       if (ebsdb->priv->summary_fields[i].type == G_TYPE_STRING) {
                                string = g_string_new (tmp);
 
                                g_string_append (string, ebsdb->priv->summary_fields[i].dbname);
-                               g_string_append (string, "_localized TEXT, ");
+                               g_string_append (string, "_localized TEXT");
 
                                success = book_backend_sql_exec (
                                        ebsdb->priv->db, string->str, NULL, NULL , error);
@@ -2089,6 +2098,10 @@ insert_stmt_from_contact (EBookBackendSqliteDB *ebsdb,
                /* Multi values go into a separate table/statement */
                if (ebsdb->priv->summary_fields[i].type != E_TYPE_CONTACT_ATTR_LIST) {
 
+                       /* Only add a ", " before every field except the first,
+                        * this will not break because the first 2 fields (UID & REV)
+                        * are string fields.
+                        */
                        if (i > 0)
                                g_string_append (string, ", ");
 
@@ -2124,14 +2137,21 @@ insert_stmt_from_contact (EBookBackendSqliteDB *ebsdb,
         */
        g_string_append (string, " VALUES (");
        for (i = 0; i < ebsdb->priv->n_summary_fields; i++) {
+
+               if (ebsdb->priv->summary_fields[i].type != E_TYPE_CONTACT_ATTR_LIST) {
+                       /* Only add a ", " before every field except the first,
+                        * this will not break because the first 2 fields (UID & REV)
+                        * are string fields.
+                        */
+                       if (i > 0)
+                               g_string_append (string, ", ");
+               }
+
                if (ebsdb->priv->summary_fields[i].type == G_TYPE_STRING) {
                        gchar *val;
                        gchar *normal;
                        gchar *localized = NULL;
 
-                       if (i > 0)
-                               g_string_append (string, ", ");
-
                        val = e_contact_get (contact, ebsdb->priv->summary_fields[i].field);
 
                        /* Special exception, never normalize/localize the UID or REV string */
@@ -2178,9 +2198,6 @@ insert_stmt_from_contact (EBookBackendSqliteDB *ebsdb,
                } else if (ebsdb->priv->summary_fields[i].type == G_TYPE_BOOLEAN) {
                        gboolean val;
 
-                       if (i > 0)
-                               g_string_append (string, ", ");
-
                        val = e_contact_get (contact, ebsdb->priv->summary_fields[i].field) ? TRUE : FALSE;
                        g_string_append_printf (string, "%d", val ? 1 : 0);
 
@@ -5491,8 +5508,6 @@ ebsdb_cursor_set_state (EBookBackendSqliteDB *ebsdb,
 {
        EContact *contact;
 
-       g_assert (vcard);
-
        contact = e_contact_new_from_vcard (vcard);
        ebsdb_cursor_set_state_from_contact (ebsdb, cursor, contact);
        g_object_unref (contact);


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