1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Upon request, delete not only the old, but also the new database

This commit is contained in:
cpfeiffer 2016-08-27 22:51:00 +02:00
parent ae2df2580c
commit 8d6e6c8675
2 changed files with 15 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import java.util.concurrent.locks.ReentrantLock;
import nodomain.freeyourgadget.gadgetbridge.database.DBConstants;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBOpenHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
@ -51,6 +52,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class GBApplication extends Application {
// Since this class must not log to slf4j, we use plain android.util.Log
private static final String TAG = "GBApplication";
public static final String DATABASE_NAME = "Gadgetbridge";
private static GBApplication context;
private static final Lock dbLock = new ReentrantLock();
private static DeviceService deviceService;
@ -151,7 +154,7 @@ public class GBApplication extends Application {
}
static void setupDatabase(Context context) {
DBOpenHelper helper = new DBOpenHelper(context, "Gadgetbridge", null);
DBOpenHelper helper = new DBOpenHelper(context, DATABASE_NAME, null);
SQLiteDatabase db = helper.getWritableDatabase();
DaoMaster daoMaster = new DaoMaster(db);
if (lockHandler == null) {
@ -311,12 +314,12 @@ public class GBApplication extends Application {
if (lockHandler != null) {
lockHandler.closeDb();
}
// if (mActivityDatabaseHandler != null) {
// mActivityDatabaseHandler.close();
// mActivityDatabaseHandler = null;
// }
boolean result = getContext().deleteDatabase(DBConstants.DATABASE_NAME);
// mActivityDatabaseHandler = new Activity7DatabaseHandler(getContext());
DBHelper dbHelper = new DBHelper(this);
boolean result = true;
if (dbHelper.existsDB(DBConstants.DATABASE_NAME)) {
result = getContext().deleteDatabase(DBConstants.DATABASE_NAME);
}
result &= getContext().deleteDatabase(DATABASE_NAME);
return result;
}

View File

@ -139,6 +139,11 @@ public class DBHelper {
db.execSQL(statement);
}
public boolean existsDB(String dbName) {
File path = context.getDatabasePath(dbName);
return path != null && path.exists();
}
public static boolean existsColumn(String tableName, String columnName, SQLiteDatabase db) {
try (Cursor res = db.rawQuery("PRAGMA table_info('" + tableName + "')", null)) {
int index = res.getColumnIndex("name");