Fix migration for DB version 50.
The migration resulted in a query being run which was broken. The query was broken because it was dynamically generated by Java code. This Java code resulted in a valid migration when until very recently when the query was refactored to deal with a new DB structure. Now the query is no longer suitable to be run against a DB_VERSION 49 database. To resolve this, the migration now hard codes the query to a string which is executable when the DB_VERSION is 49.
This commit is contained in:
parent
050d9974b7
commit
0d4d160407
@ -5,7 +5,6 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@ -191,22 +190,6 @@ public class AppProvider extends FDroidProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class that only exists to call private methods in the {@link AppProvider} without having
|
||||
* to go via a Context/ContentResolver. The reason is that if the {@link DBHelper} class
|
||||
* was to try and use its getContext().getContentResolver() in order to access the app
|
||||
* provider, then the AppProvider will end up creating a new instance of a writeable
|
||||
* SQLiteDatabase. This causes problems because the {@link DBHelper} still has its reference
|
||||
* open and locks certain tables.
|
||||
*/
|
||||
static final class UpgradeHelper {
|
||||
|
||||
public static void updateIconUrls(Context context, SQLiteDatabase db) {
|
||||
AppProvider.updateIconUrls(context, db, AppMetadataTable.NAME, ApkTable.NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A QuerySelection which is aware of the option/need to join onto the
|
||||
* installed apps table. Not that the base classes
|
||||
@ -948,7 +931,7 @@ public class AppProvider extends FDroidProvider {
|
||||
updateCompatibleFlags();
|
||||
updateSuggestedFromUpstream();
|
||||
updateSuggestedFromLatest();
|
||||
updateIconUrls(getContext(), db(), getTableName(), getApkTableName());
|
||||
updateIconUrls();
|
||||
}
|
||||
|
||||
private void updatePreferredMetadata() {
|
||||
@ -1047,14 +1030,11 @@ public class AppProvider extends FDroidProvider {
|
||||
db().execSQL(updateSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Made static so that the {@link org.fdroid.fdroid.data.AppProvider.UpgradeHelper} can access
|
||||
* it without instantiating an {@link AppProvider}. This is also the reason it needs to accept
|
||||
* the context and database as arguments.
|
||||
*/
|
||||
private static void updateIconUrls(Context context, SQLiteDatabase db, String appTable, String apkTable) {
|
||||
final String iconsDir = Utils.getIconsDir(context, 1.0);
|
||||
final String iconsDirLarge = Utils.getIconsDir(context, 1.5);
|
||||
private void updateIconUrls() {
|
||||
final String appTable = getTableName();
|
||||
final String apkTable = getApkTableName();
|
||||
final String iconsDir = Utils.getIconsDir(getContext(), 1.0);
|
||||
final String iconsDirLarge = Utils.getIconsDir(getContext(), 1.5);
|
||||
String repoVersion = Integer.toString(Repo.VERSION_DENSITY_SPECIFIC_ICONS);
|
||||
Utils.debugLog(TAG, "Updating icon paths for apps belonging to repos with version >= " + repoVersion);
|
||||
Utils.debugLog(TAG, "Using icons dir '" + iconsDir + "'");
|
||||
@ -1064,7 +1044,7 @@ public class AppProvider extends FDroidProvider {
|
||||
repoVersion, iconsDir, Utils.FALLBACK_ICONS_DIR,
|
||||
repoVersion, iconsDirLarge, Utils.FALLBACK_ICONS_DIR,
|
||||
};
|
||||
db.execSQL(query, params);
|
||||
db().execSQL(query, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -765,7 +765,32 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
return;
|
||||
}
|
||||
Utils.debugLog(TAG, "Recalculating app icon URLs so that the newly added large icons will get updated.");
|
||||
AppProvider.UpgradeHelper.updateIconUrls(context, db);
|
||||
|
||||
String query = "UPDATE fdroid_app "
|
||||
+ "SET iconUrl = ("
|
||||
+ " SELECT (fdroid_repo.address || CASE WHEN fdroid_repo.version >= ? THEN ? ELSE ? END || fdroid_app.icon) "
|
||||
+ " FROM fdroid_apk "
|
||||
+ " JOIN fdroid_repo ON (fdroid_repo._id = fdroid_apk.repo) "
|
||||
+ " WHERE fdroid_app.id = fdroid_apk.id AND fdroid_apk.vercode = fdroid_app.suggestedVercode "
|
||||
+ "), iconUrlLarge = ("
|
||||
+ " SELECT (fdroid_repo.address || CASE WHEN fdroid_repo.version >= ? THEN ? ELSE ? END || fdroid_app.icon) "
|
||||
+ " FROM fdroid_apk "
|
||||
+ " JOIN fdroid_repo ON (fdroid_repo._id = fdroid_apk.repo) "
|
||||
+ " WHERE fdroid_app.id = fdroid_apk.id AND fdroid_apk.vercode = fdroid_app.suggestedVercode"
|
||||
+ ")";
|
||||
|
||||
String iconsDir = Utils.getIconsDir(context, 1.0);
|
||||
String iconsDirLarge = Utils.getIconsDir(context, 1.5);
|
||||
String repoVersion = Integer.toString(Repo.VERSION_DENSITY_SPECIFIC_ICONS);
|
||||
Utils.debugLog(TAG, "Using icons dir '" + iconsDir + "'");
|
||||
Utils.debugLog(TAG, "Using large icons dir '" + iconsDirLarge + "'");
|
||||
String[] args = {
|
||||
repoVersion, iconsDir, Utils.FALLBACK_ICONS_DIR,
|
||||
repoVersion, iconsDirLarge, Utils.FALLBACK_ICONS_DIR,
|
||||
};
|
||||
|
||||
db.rawQuery(query, args);
|
||||
|
||||
clearRepoEtags(db);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user