From f9b22442edd6b5d7b2d3a604fa066bd3a41748c1 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 28 Apr 2016 14:54:38 +1000 Subject: [PATCH] Simplify detach code by catching exception istead of querying for attached dbs. --- .../fdroid/fdroid/data/TempAppProvider.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/data/TempAppProvider.java b/app/src/main/java/org/fdroid/fdroid/data/TempAppProvider.java index 86ac6bc59..d2ee5aa6e 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/TempAppProvider.java +++ b/app/src/main/java/org/fdroid/fdroid/data/TempAppProvider.java @@ -3,21 +3,15 @@ package org.fdroid.fdroid.data; import android.content.ContentValues; import android.content.Context; import android.content.UriMatcher; -import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteException; import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; - -import org.fdroid.fdroid.Utils; /** * This class does all of its operations in a temporary sqlite table. */ public class TempAppProvider extends AppProvider { - private static final String TAG = "TempAppProvider"; - /** * The name of the in memory database used for updating. */ @@ -120,18 +114,12 @@ public class TempAppProvider extends AppProvider { } private void ensureTempTableDetached(SQLiteDatabase db) { - Cursor cursor = db.rawQuery("PRAGMA database_list", null); try { - cursor.moveToFirst(); - while (!cursor.isAfterLast()) { - String name = cursor.getString(cursor.getColumnIndex("name")); - if (TextUtils.equals(name, DB)) { - db.execSQL("DETACH DATABASE " + DB); - } - cursor.moveToNext(); - } - } finally { - cursor.close(); + db.execSQL("DETACH DATABASE " + DB); + } catch (SQLiteException e) { + // We expect that most of the time the database will not exist unless an error occurred + // midway through the last update, The resulting exception is: + // android.database.sqlite.SQLiteException: no such database: temp_update_db (code 1) } }