Simplify detach code by catching exception istead of querying for attached dbs.
This commit is contained in:
parent
721dcb00c1
commit
f9b22442ed
@ -3,21 +3,15 @@ package org.fdroid.fdroid.data;
|
|||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.UriMatcher;
|
import android.content.UriMatcher;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.net.Uri;
|
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.
|
* This class does all of its operations in a temporary sqlite table.
|
||||||
*/
|
*/
|
||||||
public class TempAppProvider extends AppProvider {
|
public class TempAppProvider extends AppProvider {
|
||||||
|
|
||||||
private static final String TAG = "TempAppProvider";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the in memory database used for updating.
|
* The name of the in memory database used for updating.
|
||||||
*/
|
*/
|
||||||
@ -120,18 +114,12 @@ public class TempAppProvider extends AppProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ensureTempTableDetached(SQLiteDatabase db) {
|
private void ensureTempTableDetached(SQLiteDatabase db) {
|
||||||
Cursor cursor = db.rawQuery("PRAGMA database_list", null);
|
|
||||||
try {
|
try {
|
||||||
cursor.moveToFirst();
|
db.execSQL("DETACH DATABASE " + DB);
|
||||||
while (!cursor.isAfterLast()) {
|
} catch (SQLiteException e) {
|
||||||
String name = cursor.getString(cursor.getColumnIndex("name"));
|
// We expect that most of the time the database will not exist unless an error occurred
|
||||||
if (TextUtils.equals(name, DB)) {
|
// midway through the last update, The resulting exception is:
|
||||||
db.execSQL("DETACH DATABASE " + DB);
|
// android.database.sqlite.SQLiteException: no such database: temp_update_db (code 1)
|
||||||
}
|
|
||||||
cursor.moveToNext();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user