From 106c47ff3374c4fc7e211df5637f46cb4e9fc346 Mon Sep 17 00:00:00 2001 From: Jim Nelson Date: Wed, 11 Jul 2012 18:08:24 -0700 Subject: [PATCH] Fix Geary crash when creating new database: Closes #5536 This also solves problem of creating a new folder after upgrading a pre-schema 4 database. --- src/engine/db/db-statement.vala | 6 +++--- src/engine/imap-db/imap-db-account.vala | 14 +++++++------- src/engine/impl/geary-generic-imap-account.vala | 5 ++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/engine/db/db-statement.vala b/src/engine/db/db-statement.vala index bcba5143..c1858d24 100644 --- a/src/engine/db/db-statement.vala +++ b/src/engine/db/db-statement.vala @@ -201,11 +201,11 @@ public class Geary.Db.Statement : Geary.Db.Context { /** * index is zero-based. * - * This is merely a front for bind_int64(). It's provided to offer more verbosity in the - * caller's code. + * This will bind the value to the column as an int64 unless it's INVALID_ROWID, in which case + * the column is bound as NULL. */ public Statement bind_rowid(int index, int64 rowid) throws DatabaseError { - return bind_int64(index, rowid); + return (rowid != Db.INVALID_ROWID) ? bind_int64(index, rowid) : bind_null(index); } /** diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala index 3c203a59..ddce4c32 100644 --- a/src/engine/imap-db/imap-db-account.vala +++ b/src/engine/imap-db/imap-db-account.vala @@ -100,20 +100,20 @@ private class Geary.ImapDB.Account : Object { Geary.FolderPath path = imap_folder.get_path(); yield db.exec_transaction_async(Db.TransactionType.RW, (cx) => { - // get the parent of this folder, creating parents if necessary - int64 parent_id; - if (!do_fetch_parent_id(cx, path, true, out parent_id, cancellable)) - return Db.TransactionOutcome.ROLLBACK; + // get the parent of this folder, creating parents if necessary ... ok if this fails, + // that just means the folder has no parents + int64 parent_id = Db.INVALID_ROWID; + do_fetch_parent_id(cx, path, true, out parent_id, cancellable); // create the folder object Db.Statement stmt = cx.prepare( "INSERT INTO FolderTable (name, parent_id, last_seen_total, uid_validity, uid_next, attributes) " - + "VALUES (?, ?, ?, ?, ?)"); + + "VALUES (?, ?, ?, ?, ?, ?)"); stmt.bind_string(0, path.basename); stmt.bind_rowid(1, parent_id); stmt.bind_int(2, properties.messages); - stmt.bind_int64(3, properties.uid_validity.value); - stmt.bind_int64(4, properties.uid_next.value); + stmt.bind_int64(3, (properties.uid_validity != null) ? properties.uid_validity.value : 0); + stmt.bind_int64(4, (properties.uid_next != null) ? properties.uid_next.value : 0); stmt.bind_string(5, properties.attrs.serialize()); stmt.exec(cancellable); diff --git a/src/engine/impl/geary-generic-imap-account.vala b/src/engine/impl/geary-generic-imap-account.vala index 180ad9b0..bd93f82b 100644 --- a/src/engine/impl/geary-generic-imap-account.vala +++ b/src/engine/impl/geary-generic-imap-account.vala @@ -276,7 +276,10 @@ private abstract class Geary.GenericImapAccount : Geary.EngineAccount { engine_added.add(build_folder((ImapDB.Folder) yield local.fetch_folder_async( remote_folder.get_path(), cancellable))); } catch (Error convert_err) { - error("Unable to fetch local folder: %s", convert_err.message); + // This isn't fatal, but irksome ... in the future, when local folders are + // removed, it's possible for one to disappear between cloning it and fetching + // it + debug("Unable to fetch local folder after cloning: %s", convert_err.message); } } }