diff --git a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.kt b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.kt index b8a26a12f..90ab0393a 100644 --- a/app/src/main/java/fr/free/nrw/commons/CommonsApplication.kt +++ b/app/src/main/java/fr/free/nrw/commons/CommonsApplication.kt @@ -247,6 +247,11 @@ class CommonsApplication : MultiDexApplication() { DBOpenHelper.CONTRIBUTIONS_TABLE ) //Delete the contributions table in the existing db on older versions + dbOpenHelper.deleteTable( + db, + DBOpenHelper.BOOKMARKS_LOCATIONS + ) + try { contributionDao.deleteAll() } catch (e: SQLiteException) { diff --git a/app/src/main/java/fr/free/nrw/commons/data/DBOpenHelper.kt b/app/src/main/java/fr/free/nrw/commons/data/DBOpenHelper.kt index 660fd2a4a..7aea407ff 100644 --- a/app/src/main/java/fr/free/nrw/commons/data/DBOpenHelper.kt +++ b/app/src/main/java/fr/free/nrw/commons/data/DBOpenHelper.kt @@ -20,6 +20,7 @@ class DBOpenHelper( private const val DATABASE_NAME = "commons.db" private const val DATABASE_VERSION = 21 const val CONTRIBUTIONS_TABLE = "contributions" + const val BOOKMARKS_LOCATIONS = "bookmarksLocations" private const val DROP_TABLE_STATEMENT = "DROP TABLE IF EXISTS %s" } @@ -42,6 +43,7 @@ class DBOpenHelper( RecentSearchesDao.Table.onUpdate(db, from, to) RecentLanguagesDao.Table.onUpdate(db, from, to) deleteTable(db, CONTRIBUTIONS_TABLE) + deleteTable(db, BOOKMARKS_LOCATIONS) } /** diff --git a/app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt b/app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt index 1a6be122e..0f92ce392 100644 --- a/app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt +++ b/app/src/main/java/fr/free/nrw/commons/di/CommonsApplicationModule.kt @@ -276,11 +276,9 @@ open class CommonsApplicationModule(private val applicationContext: Context) { """ ) - // Open old database manually val oldDbPath = "/data/user/0/fr.free.nrw.commons.beta/databases/commons.db" val oldDb = SQLiteDatabase.openDatabase(oldDbPath, null, SQLiteDatabase.OPEN_READONLY) - // Fetch data from old table val cursor = oldDb.rawQuery("SELECT * FROM bookmarksLocations", null) while (cursor.moveToNext()) { @@ -301,10 +299,9 @@ open class CommonsApplicationModule(private val applicationContext: Context) { val locationPic = cursor.getString(cursor.getColumnIndexOrThrow("location_pic")) ?: "" val locationExists = cursor.getInt(cursor.getColumnIndexOrThrow("location_exists")) - // Insert data into new table db.execSQL( """ - INSERT INTO bookmarks_locations ( + INSERT OR REPLACE INTO bookmarks_locations ( location_name, location_language, location_description, location_category, location_label_text, location_label_icon, location_lat, location_long, location_image_url, location_wikipedia_link, location_wikidata_link, @@ -322,9 +319,6 @@ open class CommonsApplicationModule(private val applicationContext: Context) { cursor.close() oldDb.close() - - // Drop the old table - db.execSQL("DROP TABLE IF EXISTS bookmarksLocations") } } }