From 7edd1cb53cc2a0abbd08ac70ad5494076588ccd8 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 4 Sep 2014 22:48:13 +0200 Subject: [PATCH] Simplify database upgrade when adding 'notify_class' to 'folders' --- src/com/fsck/k9/mail/store/LocalStore.java | 49 ++++------------------ 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 2981ad5b4..232b9fce0 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -701,31 +701,19 @@ public class LocalStore extends Store implements Serializable { } if (db.getVersion() < 50) { try { - db.execSQL("ALTER TABLE folders ADD notify_class TEXT"); + db.execSQL("ALTER TABLE folders ADD notify_class TEXT default '" + + Folder.FolderClass.INHERITED.name() + "'"); } catch (SQLiteException e) { if (! e.getMessage().startsWith("duplicate column name:")) { throw e; } } - Cursor cursor = null; - try { - SharedPreferences prefs = getPreferences(); - cursor = db.rawQuery("SELECT id, name FROM folders", null); - while (cursor.moveToNext()) { - try { - int id = cursor.getInt(0); - String name = cursor.getString(1); - update50Metadata(db, prefs, id, name); - } catch (Exception e) { - Log.e(K9.LOG_TAG, " error trying to ugpgrade a folder notify class", e); - } - } - } catch (SQLiteException e) { - Log.e(K9.LOG_TAG, "Exception while upgrading database to v50. folder classes may have vanished", e); - } finally { - Utility.closeQuietly(cursor); - } + ContentValues cv = new ContentValues(); + cv.put("notify_class", Folder.FolderClass.FIRST_CLASS.name()); + + db.update("folders", cv, "name = ?", + new String[] { getAccount().getInboxFolderName() }); } } @@ -781,29 +769,6 @@ public class LocalStore extends Store implements Serializable { new Object[] { integrate, inTopGroup, syncClass, pushClass, displayClass, id }); } - - private void update50Metadata(final SQLiteDatabase db, SharedPreferences prefs, int id, String name) { - - Folder.FolderClass notifyClass = Folder.FolderClass.INHERITED; - - if (mAccount.getInboxFolderName().equals(name)) { - notifyClass = Folder.FolderClass.FIRST_CLASS; - } - - try { - notifyClass = Folder.FolderClass.valueOf(prefs.getString(uUid + "." + name + ".notifyMode", notifyClass.name())); - } catch (Exception e) { - Log.e(K9.LOG_TAG, " Throwing away an error while trying to upgrade folder metadata", e); - } - - if (notifyClass == Folder.FolderClass.NONE) { - notifyClass = Folder.FolderClass.INHERITED; - } - - db.execSQL("UPDATE folders SET notify_class=? WHERE id = ?", - new Object[] { notifyClass, id }); - - } }