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.
This commit is contained in:
Jim Nelson 2012-07-11 18:08:24 -07:00
parent 54e3ba7dcf
commit 106c47ff33
3 changed files with 14 additions and 11 deletions

View file

@ -201,11 +201,11 @@ public class Geary.Db.Statement : Geary.Db.Context {
/** /**
* index is zero-based. * index is zero-based.
* *
* This is merely a front for bind_int64(). It's provided to offer more verbosity in the * This will bind the value to the column as an int64 unless it's INVALID_ROWID, in which case
* caller's code. * the column is bound as NULL.
*/ */
public Statement bind_rowid(int index, int64 rowid) throws DatabaseError { 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);
} }
/** /**

View file

@ -100,20 +100,20 @@ private class Geary.ImapDB.Account : Object {
Geary.FolderPath path = imap_folder.get_path(); Geary.FolderPath path = imap_folder.get_path();
yield db.exec_transaction_async(Db.TransactionType.RW, (cx) => { yield db.exec_transaction_async(Db.TransactionType.RW, (cx) => {
// get the parent of this folder, creating parents if necessary // get the parent of this folder, creating parents if necessary ... ok if this fails,
int64 parent_id; // that just means the folder has no parents
if (!do_fetch_parent_id(cx, path, true, out parent_id, cancellable)) int64 parent_id = Db.INVALID_ROWID;
return Db.TransactionOutcome.ROLLBACK; do_fetch_parent_id(cx, path, true, out parent_id, cancellable);
// create the folder object // create the folder object
Db.Statement stmt = cx.prepare( Db.Statement stmt = cx.prepare(
"INSERT INTO FolderTable (name, parent_id, last_seen_total, uid_validity, uid_next, attributes) " "INSERT INTO FolderTable (name, parent_id, last_seen_total, uid_validity, uid_next, attributes) "
+ "VALUES (?, ?, ?, ?, ?)"); + "VALUES (?, ?, ?, ?, ?, ?)");
stmt.bind_string(0, path.basename); stmt.bind_string(0, path.basename);
stmt.bind_rowid(1, parent_id); stmt.bind_rowid(1, parent_id);
stmt.bind_int(2, properties.messages); stmt.bind_int(2, properties.messages);
stmt.bind_int64(3, properties.uid_validity.value); stmt.bind_int64(3, (properties.uid_validity != null) ? properties.uid_validity.value : 0);
stmt.bind_int64(4, properties.uid_next.value); stmt.bind_int64(4, (properties.uid_next != null) ? properties.uid_next.value : 0);
stmt.bind_string(5, properties.attrs.serialize()); stmt.bind_string(5, properties.attrs.serialize());
stmt.exec(cancellable); stmt.exec(cancellable);

View file

@ -276,7 +276,10 @@ private abstract class Geary.GenericImapAccount : Geary.EngineAccount {
engine_added.add(build_folder((ImapDB.Folder) yield local.fetch_folder_async( engine_added.add(build_folder((ImapDB.Folder) yield local.fetch_folder_async(
remote_folder.get_path(), cancellable))); remote_folder.get_path(), cancellable)));
} catch (Error convert_err) { } 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);
} }
} }
} }