|
|
|
@@ -21,15 +21,13 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
|
|
|
|
private static final String DATABASE_NAME = "fdroid";
|
|
|
|
|
|
|
|
|
|
public static final String TABLE_REPO = "fdroid_repo";
|
|
|
|
|
|
|
|
|
|
// The TABLE_APK table stores details of all the application versions we
|
|
|
|
|
// know about. Each relates directly back to an entry in TABLE_APP.
|
|
|
|
|
// This information is retrieved from the repositories.
|
|
|
|
|
public static final String TABLE_APK = "fdroid_apk";
|
|
|
|
|
|
|
|
|
|
private static final String CREATE_TABLE_REPO = "create table "
|
|
|
|
|
+ TABLE_REPO + " (_id integer primary key, "
|
|
|
|
|
+ RepoTable.NAME + " (_id integer primary key, "
|
|
|
|
|
+ "address text not null, "
|
|
|
|
|
+ "name text, description text, inuse integer not null, "
|
|
|
|
|
+ "priority integer not null, pubkey text, fingerprint text, "
|
|
|
|
@@ -128,7 +126,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
}
|
|
|
|
|
Utils.debugLog(TAG, "Populating repo names from the url");
|
|
|
|
|
final String[] columns = {"address", "_id"};
|
|
|
|
|
Cursor cursor = db.query(TABLE_REPO, columns,
|
|
|
|
|
Cursor cursor = db.query(RepoTable.NAME, columns,
|
|
|
|
|
"name IS NULL OR name = ''", null, null, null, null);
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
@@ -141,7 +139,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
values.put("name", name);
|
|
|
|
|
final String[] args = {Long.toString(id)};
|
|
|
|
|
Utils.debugLog(TAG, "Setting repo name to '" + name + "' for repo " + address);
|
|
|
|
|
db.update(TABLE_REPO, values, "_id = ?", args);
|
|
|
|
|
db.update(RepoTable.NAME, values, "_id = ?", args);
|
|
|
|
|
cursor.moveToNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -150,17 +148,17 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void renameRepoId(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
if (oldVersion >= 36 || columnExists(db, TABLE_REPO, "_id")) {
|
|
|
|
|
if (oldVersion >= 36 || columnExists(db, RepoTable.NAME, "_id")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils.debugLog(TAG, "Renaming " + TABLE_REPO + ".id to _id");
|
|
|
|
|
Utils.debugLog(TAG, "Renaming " + RepoTable.NAME + ".id to _id");
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// http://stackoverflow.com/questions/805363/how-do-i-rename-a-column-in-a-sqlite-database-table#805508
|
|
|
|
|
String tempTableName = TABLE_REPO + "__temp__";
|
|
|
|
|
db.execSQL("ALTER TABLE " + TABLE_REPO + " RENAME TO " + tempTableName + ";");
|
|
|
|
|
String tempTableName = RepoTable.NAME + "__temp__";
|
|
|
|
|
db.execSQL("ALTER TABLE " + RepoTable.NAME + " RENAME TO " + tempTableName + ";");
|
|
|
|
|
|
|
|
|
|
// I realise this is available in the CREATE_TABLE_REPO above,
|
|
|
|
|
// however I have a feeling that it will need to be the same as the
|
|
|
|
@@ -169,7 +167,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
// got removed, then it will break the "insert select"
|
|
|
|
|
// statement. Therefore, I've put a copy of CREATE_TABLE_REPO
|
|
|
|
|
// here that is the same as it was at DBVersion 36.
|
|
|
|
|
String createTableDdl = "create table " + TABLE_REPO + " ("
|
|
|
|
|
String createTableDdl = "create table " + RepoTable.NAME + " ("
|
|
|
|
|
+ "_id integer not null primary key, "
|
|
|
|
|
+ "address text not null, "
|
|
|
|
|
+ "name text, "
|
|
|
|
@@ -188,7 +186,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
String nonIdFields = "address, name, description, inuse, priority, " +
|
|
|
|
|
"pubkey, fingerprint, maxage, version, lastetag, lastUpdated";
|
|
|
|
|
|
|
|
|
|
String insertSql = "INSERT INTO " + TABLE_REPO +
|
|
|
|
|
String insertSql = "INSERT INTO " + RepoTable.NAME +
|
|
|
|
|
"(_id, " + nonIdFields + " ) " +
|
|
|
|
|
"SELECT id, " + nonIdFields + " FROM " + tempTableName + ";";
|
|
|
|
|
|
|
|
|
@@ -271,7 +269,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
values.put(RepoTable.Cols.TIMESTAMP, 0);
|
|
|
|
|
|
|
|
|
|
Utils.debugLog(TAG, "Adding repository " + name);
|
|
|
|
|
db.insert(TABLE_REPO, null, values);
|
|
|
|
|
db.insert(RepoTable.NAME, null, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@@ -314,7 +312,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<Repo> oldrepos = new ArrayList<>();
|
|
|
|
|
Cursor cursor = db.query(TABLE_REPO,
|
|
|
|
|
Cursor cursor = db.query(RepoTable.NAME,
|
|
|
|
|
new String[] {"address", "inuse", "pubkey"},
|
|
|
|
|
null, null, null, null, null);
|
|
|
|
|
if (cursor != null) {
|
|
|
|
@@ -331,7 +329,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
db.execSQL("drop table " + TABLE_REPO);
|
|
|
|
|
db.execSQL("drop table " + RepoTable.NAME);
|
|
|
|
|
db.execSQL(CREATE_TABLE_REPO);
|
|
|
|
|
for (final Repo repo : oldrepos) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
@@ -340,7 +338,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
values.put("priority", 10);
|
|
|
|
|
values.put("pubkey", repo.signingCertificate);
|
|
|
|
|
values.put("lastetag", (String) null);
|
|
|
|
|
db.insert(TABLE_REPO, null, values);
|
|
|
|
|
db.insert(RepoTable.NAME, null, values);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -350,7 +348,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
values.clear();
|
|
|
|
|
values.put("name", context.getString(nameResId));
|
|
|
|
|
values.put("description", context.getString(descriptionResId));
|
|
|
|
|
db.update(TABLE_REPO, values, "address = ?", new String[] {
|
|
|
|
|
db.update(RepoTable.NAME, values, "address = ?", new String[] {
|
|
|
|
|
context.getString(addressResId),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -360,16 +358,16 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
* default repos with values from strings.xml.
|
|
|
|
|
*/
|
|
|
|
|
private void addNameAndDescriptionToRepo(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
boolean nameExists = columnExists(db, TABLE_REPO, "name");
|
|
|
|
|
boolean descriptionExists = columnExists(db, TABLE_REPO, "description");
|
|
|
|
|
boolean nameExists = columnExists(db, RepoTable.NAME, "name");
|
|
|
|
|
boolean descriptionExists = columnExists(db, RepoTable.NAME, "description");
|
|
|
|
|
if (oldVersion >= 21 || (nameExists && descriptionExists)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!nameExists) {
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column name text");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column name text");
|
|
|
|
|
}
|
|
|
|
|
if (!descriptionExists) {
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column description text");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column description text");
|
|
|
|
|
}
|
|
|
|
|
insertNameAndDescription(db, R.string.fdroid_repo_address,
|
|
|
|
|
R.string.fdroid_repo_name, R.string.fdroid_repo_description);
|
|
|
|
@@ -390,11 +388,11 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
if (oldVersion >= 44) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!columnExists(db, TABLE_REPO, "fingerprint")) {
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column fingerprint text");
|
|
|
|
|
if (!columnExists(db, RepoTable.NAME, "fingerprint")) {
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column fingerprint text");
|
|
|
|
|
}
|
|
|
|
|
List<Repo> oldrepos = new ArrayList<>();
|
|
|
|
|
Cursor cursor = db.query(TABLE_REPO,
|
|
|
|
|
Cursor cursor = db.query(RepoTable.NAME,
|
|
|
|
|
new String[] {"address", "pubkey"},
|
|
|
|
|
null, null, null, null, null);
|
|
|
|
|
if (cursor != null) {
|
|
|
|
@@ -413,52 +411,52 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
for (final Repo repo : oldrepos) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
values.put("fingerprint", Utils.calcFingerprint(repo.signingCertificate));
|
|
|
|
|
db.update(TABLE_REPO, values, "address = ?", new String[] {repo.address});
|
|
|
|
|
db.update(RepoTable.NAME, values, "address = ?", new String[] {repo.address});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addMaxAgeToRepo(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
if (oldVersion >= 30 || columnExists(db, TABLE_REPO, "maxage")) {
|
|
|
|
|
if (oldVersion >= 30 || columnExists(db, RepoTable.NAME, "maxage")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column maxage integer not null default 0");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column maxage integer not null default 0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addVersionToRepo(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
if (oldVersion >= 33 || columnExists(db, TABLE_REPO, "version")) {
|
|
|
|
|
if (oldVersion >= 33 || columnExists(db, RepoTable.NAME, "version")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column version integer not null default 0");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column version integer not null default 0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addLastUpdatedToRepo(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
if (oldVersion >= 35 || columnExists(db, TABLE_REPO, "lastUpdated")) {
|
|
|
|
|
if (oldVersion >= 35 || columnExists(db, RepoTable.NAME, "lastUpdated")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Utils.debugLog(TAG, "Adding lastUpdated column to " + TABLE_REPO);
|
|
|
|
|
db.execSQL("Alter table " + TABLE_REPO + " add column lastUpdated string");
|
|
|
|
|
Utils.debugLog(TAG, "Adding lastUpdated column to " + RepoTable.NAME);
|
|
|
|
|
db.execSQL("Alter table " + RepoTable.NAME + " add column lastUpdated string");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addIsSwapToRepo(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
if (oldVersion >= 47 || columnExists(db, TABLE_REPO, "isSwap")) {
|
|
|
|
|
if (oldVersion >= 47 || columnExists(db, RepoTable.NAME, "isSwap")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Utils.debugLog(TAG, "Adding isSwap field to " + TABLE_REPO + " table in db.");
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column isSwap boolean default 0;");
|
|
|
|
|
Utils.debugLog(TAG, "Adding isSwap field to " + RepoTable.NAME + " table in db.");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column isSwap boolean default 0;");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addCredentialsToRepo(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|
if (oldVersion >= 52) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!columnExists(db, TABLE_REPO, "username")) {
|
|
|
|
|
Utils.debugLog(TAG, "Adding username field to " + TABLE_REPO + " table in db.");
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column username string;");
|
|
|
|
|
if (!columnExists(db, Schema.RepoTable.NAME, "username")) {
|
|
|
|
|
Utils.debugLog(TAG, "Adding username field to " + RepoTable.NAME + " table in db.");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column username string;");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!columnExists(db, TABLE_REPO, "password")) {
|
|
|
|
|
Utils.debugLog(TAG, "Adding password field to " + TABLE_REPO + " table in db.");
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column password string;");
|
|
|
|
|
if (!columnExists(db, RepoTable.NAME, "password")) {
|
|
|
|
|
Utils.debugLog(TAG, "Adding password field to " + RepoTable.NAME + " table in db.");
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column password string;");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -519,9 +517,9 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
if (oldVersion >= 55) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!columnExists(db, TABLE_REPO, RepoTable.Cols.TIMESTAMP)) {
|
|
|
|
|
Utils.debugLog(TAG, "Adding " + RepoTable.Cols.TIMESTAMP + " column to " + TABLE_REPO);
|
|
|
|
|
db.execSQL("alter table " + TABLE_REPO + " add column "
|
|
|
|
|
if (!columnExists(db, RepoTable.NAME, RepoTable.Cols.TIMESTAMP)) {
|
|
|
|
|
Utils.debugLog(TAG, "Adding " + RepoTable.Cols.TIMESTAMP + " column to " + RepoTable.NAME);
|
|
|
|
|
db.execSQL("alter table " + RepoTable.NAME + " add column "
|
|
|
|
|
+ RepoTable.Cols.TIMESTAMP + " integer not null default 0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -533,7 +531,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|
|
|
|
*/
|
|
|
|
|
private void clearRepoEtags(SQLiteDatabase db) {
|
|
|
|
|
Utils.debugLog(TAG, "Clearing repo etags, so next update will not be skipped with \"Repos up to date\".");
|
|
|
|
|
db.execSQL("update " + TABLE_REPO + " set lastetag = NULL");
|
|
|
|
|
db.execSQL("update " + RepoTable.NAME + " set lastetag = NULL");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void resetTransient(SQLiteDatabase db, int oldVersion) {
|
|
|
|
|