From 6cd5ce7deece9ae127c39fecb36fb2714f099ac4 Mon Sep 17 00:00:00 2001 From: Richard Tibbetts Date: Sun, 2 Nov 2008 03:56:13 +0000 Subject: [PATCH] Fix similar empty-cursor bug when creating a folder on open. Turn tabs into spaces in code I changed last commit. --- src/com/fsck/k9/mail/store/LocalStore.java | 62 ++++++++++------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index ddf80618d..5075c53d0 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -337,25 +337,21 @@ public class LocalStore extends Store { } Cursor cursor = null; try { - cursor = mDb.rawQuery("SELECT id, unread_count, visible_limit FROM folders " - + "where folders.name = ?", - new String[] { - mName - }); - if ( cursor.getCount() == 0 ) { - // Calling exists on open is a little expensive. Instead, just handle it when we don't find it. + cursor = mDb.rawQuery( + "SELECT id, unread_count, visible_limit FROM folders " + + "where folders.name = ?", + new String[] { mName }); + if (cursor.moveToFirst()) { + mFolderId = cursor.getInt(0); + mUnreadMessageCount = cursor.getInt(1); + mVisibleLimit = cursor.getInt(2); + } else { + // Calling exists on open is a little expensive. Instead, + // just handle it when we don't find it. create(FolderType.HOLDS_MESSAGES); open(mode); - } - cursor.moveToFirst(); - mFolderId = cursor.getInt(0); - mUnreadMessageCount = cursor.getInt(1); - mVisibleLimit = cursor.getInt(2); - - - } - finally { + } finally { if (cursor != null) { cursor.close(); } @@ -379,23 +375,23 @@ public class LocalStore extends Store { @Override public boolean exists() throws MessagingException { - Cursor cursor = null; - try { - cursor = mDb.rawQuery("SELECT id FROM folders " - + "where folders.name = ?", - new String[] { this.getName() }); - if (cursor.moveToFirst()) { - int folderId = cursor.getInt(0); - return (folderId > 0) ? true : false; - } else { - return false; - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - } + Cursor cursor = null; + try { + cursor = mDb.rawQuery("SELECT id FROM folders " + + "where folders.name = ?", new String[] { this + .getName() }); + if (cursor.moveToFirst()) { + int folderId = cursor.getInt(0); + return (folderId > 0) ? true : false; + } else { + return false; + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + } @Override public boolean create(FolderType type) throws MessagingException {