From 3426b3bb2d6c8326a6368ce1e110e8be4236b594 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Mon, 16 Nov 2015 17:51:32 +1100 Subject: [PATCH] CR: Better deal with the possibility of crashes during database update. This is for an abundance of caution. If the guard condition checks for the presence of both username _and_ password fields, then a crash or some sort of force close during the update (after adding username but before password) will mean that next time the app runs, this condition will evaluate to false and the password field will never get added. --- F-Droid/src/org/fdroid/fdroid/data/DBHelper.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java b/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java index 1173517a9..1b89b0ab8 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java +++ b/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java @@ -423,11 +423,16 @@ public class DBHelper extends SQLiteOpenHelper { } private void addCredentialsToRepo(SQLiteDatabase db, int oldVersion) { - if (oldVersion < 52 && !columnExists(db, TABLE_REPO, "username") && !columnExists(db, TABLE_REPO, "password")) { - Utils.debugLog(TAG, "Adding username field to " + TABLE_REPO + " table in db."); - db.execSQL("alter table " + TABLE_REPO + " add column username string;"); - Utils.debugLog(TAG, "Adding password field to " + TABLE_REPO + " table in db."); - db.execSQL("alter table " + TABLE_REPO + " add column password string;"); + if (oldVersion < 52) { + if (!columnExists(db, TABLE_REPO, "username")) { + Utils.debugLog(TAG, "Adding username field to " + TABLE_REPO + " table in db."); + db.execSQL("alter table " + TABLE_REPO + " add column username string;"); + } + + if (!columnExists(db, TABLE_REPO, "password")) { + Utils.debugLog(TAG, "Adding password field to " + TABLE_REPO + " table in db."); + db.execSQL("alter table " + TABLE_REPO + " add column password string;"); + } } }