summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorMike <7153163+hackbar@users.noreply.github.com>2017-11-09 18:54:04 -0800
committerMike <7153163+hackbar@users.noreply.github.com>2017-11-09 18:54:04 -0800
commit74ae2522fe70a5fc9604b57f20203da2bd718fa2 (patch)
treeee75233484f6503db1d95985ccd57951f295ac4c /Source/Android/app/src/main/java
parent4dc425b9c9d1360109ab86ac4268888d498cb04d (diff)
Android: Handle a database downgrade.
This has no effect now, as we've never bumped the database version. Instead, it adds future proofing, and makes moving between a future version with a bump and master clean.
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java
index 1a4f872330..231665094f 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameDatabase.java
@@ -78,6 +78,7 @@ public final class GameDatabase extends SQLiteOpenHelper
+ KEY_DB_ID + TYPE_PRIMARY + SEPARATOR
+ KEY_FOLDER_PATH + TYPE_STRING + CONSTRAINT_UNIQUE + ")";
+ private static final String SQL_DELETE_FOLDERS = "DROP TABLE IF EXISTS " + TABLE_NAME_FOLDERS;
private static final String SQL_DELETE_GAMES = "DROP TABLE IF EXISTS " + TABLE_NAME_GAMES;
public GameDatabase(Context context)
@@ -91,11 +92,19 @@ public final class GameDatabase extends SQLiteOpenHelper
{
Log.debug("[GameDatabase] GameDatabase - Creating database...");
- Log.verbose("[GameDatabase] Executing SQL: " + SQL_CREATE_GAMES);
- database.execSQL(SQL_CREATE_GAMES);
+ execSqlAndLog(database, SQL_CREATE_GAMES);
+ execSqlAndLog(database, SQL_CREATE_FOLDERS);
+ }
+
+ @Override
+ public void onDowngrade(SQLiteDatabase database, int oldVersion, int newVersion)
+ {
+ Log.verbose("[GameDatabase] Downgrades not supporting, clearing databases..");
+ execSqlAndLog(database, SQL_DELETE_FOLDERS);
+ execSqlAndLog(database, SQL_CREATE_FOLDERS);
- Log.verbose("[GameDatabase] Executing SQL: " + SQL_CREATE_FOLDERS);
- database.execSQL(SQL_CREATE_FOLDERS);
+ execSqlAndLog(database, SQL_DELETE_GAMES);
+ execSqlAndLog(database, SQL_CREATE_GAMES);
}
@Override
@@ -103,11 +112,9 @@ public final class GameDatabase extends SQLiteOpenHelper
{
Log.info("[GameDatabase] Upgrading database from schema version " + oldVersion + " to " + newVersion);
- Log.verbose("[GameDatabase] Executing SQL: " + SQL_DELETE_GAMES);
- database.execSQL(SQL_DELETE_GAMES);
-
- Log.verbose("[GameDatabase] Executing SQL: " + SQL_CREATE_GAMES);
- database.execSQL(SQL_CREATE_GAMES);
+ // Delete all the games
+ execSqlAndLog(database, SQL_DELETE_GAMES);
+ execSqlAndLog(database, SQL_CREATE_GAMES);
Log.verbose("[GameDatabase] Re-scanning library with new schema.");
scanLibrary(database);
@@ -283,4 +290,10 @@ public final class GameDatabase extends SQLiteOpenHelper
}
});
}
+
+ private void execSqlAndLog(SQLiteDatabase database, String sql)
+ {
+ Log.verbose("[GameDatabase] Executing SQL: " + sql);
+ database.execSQL(sql);
+ }
}