From af546ae10190ac076cd7b091cd064fb8a5c03519 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 8 Jul 2015 02:55:35 +0200 Subject: apply database fix for bogus rows introduced by issue #1402 --- .../keychain/provider/KeychainDatabase.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index 3346926ec..92ad7372a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -53,7 +53,7 @@ import java.io.IOException; */ public class KeychainDatabase extends SQLiteOpenHelper { private static final String DATABASE_NAME = "openkeychain.db"; - private static final int DATABASE_VERSION = 10; + private static final int DATABASE_VERSION = 11; static Boolean apgHack = false; private Context mContext; @@ -274,6 +274,12 @@ public class KeychainDatabase extends SQLiteOpenHelper { db.execSQL(CREATE_CERTS); case 10: // do nothing here, just consolidate + case 11: + db.execSQL("DELETE FROM api_accounts WHERE key_id BETWEEN 0 AND 3"); + if (oldVersion == 10) { + // no consolidate if we are updating from 10, we're just here for the api_accounts fix + return; + } } @@ -297,10 +303,11 @@ public class KeychainDatabase extends SQLiteOpenHelper { // It's the Java way =( String[] dbs = context.databaseList(); for (String db : dbs) { - if (db.equals("apg.db")) { + if ("apg.db".equals(db)) { hasApgDb = true; - } else if (db.equals("apg_old.db")) { + } else if ("apg_old.db".equals(db)) { Log.d(Constants.TAG, "Found apg_old.db, delete it!"); + // noinspection ResultOfMethodCallIgnored - if it doesn't happen, it doesn't happen. context.getDatabasePath("apg_old.db").delete(); } } @@ -384,7 +391,7 @@ public class KeychainDatabase extends SQLiteOpenHelper { } } - // delete old database + // noinspection ResultOfMethodCallIgnored - not much we can do if this doesn't work context.getDatabasePath("apg.db").delete(); } @@ -416,6 +423,7 @@ public class KeychainDatabase extends SQLiteOpenHelper { } else { in = context.getDatabasePath(DATABASE_NAME); out = context.getDatabasePath("debug_backup.db"); + // noinspection ResultOfMethodCallIgnored - this is a pure debug feature, anyways out.createNewFile(); } if (!in.canRead()) { -- cgit v1.2.3