Replaced DBHelper.TABLE_APK with Schema.ApkTable.NAME

This commit is contained in:
Peter Serwylo 2016-06-30 13:46:41 +10:00
parent d1c04de71a
commit 14958d48e3
6 changed files with 26 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import android.net.Uri;
import android.util.Log; import android.util.Log;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Schema.ApkTable;
import org.fdroid.fdroid.data.Schema.ApkTable.Cols; import org.fdroid.fdroid.data.Schema.ApkTable.Cols;
import org.fdroid.fdroid.data.Schema.RepoTable; import org.fdroid.fdroid.data.Schema.RepoTable;
@ -319,7 +320,7 @@ public class ApkProvider extends FDroidProvider {
@Override @Override
protected String getTableName() { protected String getTableName() {
return DBHelper.TABLE_APK; return ApkTable.NAME;
} }
@Override @Override
@ -338,7 +339,7 @@ public class ApkProvider extends FDroidProvider {
@Override @Override
protected String getRequiredTables() { protected String getRequiredTables() {
return DBHelper.TABLE_APK + " AS apk"; return ApkTable.NAME + " AS apk";
} }
@Override @Override

View File

@ -165,7 +165,7 @@ public class AppProvider extends FDroidProvider {
static final class UpgradeHelper { static final class UpgradeHelper {
public static void updateIconUrls(Context context, SQLiteDatabase db) { public static void updateIconUrls(Context context, SQLiteDatabase db) {
AppProvider.updateIconUrls(context, db, DBHelper.TABLE_APP, DBHelper.TABLE_APK); AppProvider.updateIconUrls(context, db, DBHelper.TABLE_APP, ApkTable.NAME);
} }
} }
@ -527,7 +527,7 @@ public class AppProvider extends FDroidProvider {
} }
protected String getApkTableName() { protected String getApkTableName() {
return DBHelper.TABLE_APK; return ApkTable.NAME;
} }
@Override @Override

View File

@ -21,11 +21,6 @@ class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "fdroid"; private static final String DATABASE_NAME = "fdroid";
// 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 " private static final String CREATE_TABLE_REPO = "create table "
+ RepoTable.NAME + " (_id integer primary key, " + RepoTable.NAME + " (_id integer primary key, "
+ "address text not null, " + "address text not null, "
@ -40,7 +35,7 @@ class DBHelper extends SQLiteOpenHelper {
+ ");"; + ");";
private static final String CREATE_TABLE_APK = private static final String CREATE_TABLE_APK =
"CREATE TABLE " + TABLE_APK + " ( " "CREATE TABLE " + ApkTable.NAME + " ( "
+ "id text not null, " + "id text not null, "
+ "version text not null, " + "version text not null, "
+ "repo integer not null, " + "repo integer not null, "
@ -506,7 +501,7 @@ class DBHelper extends SQLiteOpenHelper {
Utils.debugLog(TAG, "Converting maxSdkVersion value 0 to " + Byte.MAX_VALUE); Utils.debugLog(TAG, "Converting maxSdkVersion value 0 to " + Byte.MAX_VALUE);
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(ApkTable.Cols.MAX_SDK_VERSION, Byte.MAX_VALUE); values.put(ApkTable.Cols.MAX_SDK_VERSION, Byte.MAX_VALUE);
db.update(TABLE_APK, values, ApkTable.Cols.MAX_SDK_VERSION + " < 1", null); db.update(ApkTable.NAME, values, ApkTable.Cols.MAX_SDK_VERSION + " < 1", null);
} }
/** /**
@ -546,7 +541,7 @@ class DBHelper extends SQLiteOpenHelper {
context.getSharedPreferences("FDroid", Context.MODE_PRIVATE).edit() context.getSharedPreferences("FDroid", Context.MODE_PRIVATE).edit()
.putBoolean("triedEmptyUpdate", false).commit(); .putBoolean("triedEmptyUpdate", false).commit();
db.execSQL("drop table " + TABLE_APP); db.execSQL("drop table " + TABLE_APP);
db.execSQL("drop table " + TABLE_APK); db.execSQL("drop table " + ApkTable.NAME);
clearRepoEtags(db); clearRepoEtags(db);
createAppApk(db); createAppApk(db);
} }
@ -555,8 +550,8 @@ class DBHelper extends SQLiteOpenHelper {
db.execSQL(CREATE_TABLE_APP); db.execSQL(CREATE_TABLE_APP);
db.execSQL("create index app_id on " + TABLE_APP + " (id);"); db.execSQL("create index app_id on " + TABLE_APP + " (id);");
db.execSQL(CREATE_TABLE_APK); db.execSQL(CREATE_TABLE_APK);
db.execSQL("create index apk_vercode on " + TABLE_APK + " (vercode);"); db.execSQL("create index apk_vercode on " + ApkTable.NAME + " (vercode);");
db.execSQL("create index apk_id on " + TABLE_APK + " (id);"); db.execSQL("create index apk_id on " + ApkTable.NAME + " (id);");
} }
/** /**
@ -579,8 +574,8 @@ class DBHelper extends SQLiteOpenHelper {
return; return;
} }
Utils.debugLog(TAG, "Adding " + ApkTable.Cols.TARGET_SDK_VERSION Utils.debugLog(TAG, "Adding " + ApkTable.Cols.TARGET_SDK_VERSION
+ " columns to " + TABLE_APK); + " columns to " + ApkTable.NAME);
db.execSQL("alter table " + TABLE_APK + " add column " db.execSQL("alter table " + ApkTable.NAME + " add column "
+ ApkTable.Cols.TARGET_SDK_VERSION + " integer"); + ApkTable.Cols.TARGET_SDK_VERSION + " integer");
} }

View File

@ -70,8 +70,13 @@ public interface Schema {
} }
} }
/**
* This 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.
*/
interface ApkTable { interface ApkTable {
String NAME = DBHelper.TABLE_APK; String NAME = "fdroid_apk";
interface Cols extends BaseColumns { interface Cols extends BaseColumns {
String _COUNT_DISTINCT_ID = "countDistinct"; String _COUNT_DISTINCT_ID = "countDistinct";

View File

@ -7,6 +7,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import org.fdroid.fdroid.data.Schema.ApkTable;
import java.util.List; import java.util.List;
/** /**
@ -18,7 +20,7 @@ public class TempApkProvider extends ApkProvider {
private static final String PROVIDER_NAME = "TempApkProvider"; private static final String PROVIDER_NAME = "TempApkProvider";
static final String TABLE_TEMP_APK = "temp_" + DBHelper.TABLE_APK; static final String TABLE_TEMP_APK = "temp_" + ApkTable.NAME;
private static final String PATH_INIT = "init"; private static final String PATH_INIT = "init";
@ -128,7 +130,7 @@ public class TempApkProvider extends ApkProvider {
private void initTable() { private void initTable() {
final SQLiteDatabase db = db(); final SQLiteDatabase db = db();
final String memoryDbName = TempAppProvider.DB; final String memoryDbName = TempAppProvider.DB;
db.execSQL("CREATE TABLE " + memoryDbName + "." + getTableName() + " AS SELECT * FROM main." + DBHelper.TABLE_APK); db.execSQL("CREATE TABLE " + memoryDbName + "." + getTableName() + " AS SELECT * FROM main." + ApkTable.NAME);
db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_vercode on " + getTableName() + " (vercode);"); db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_vercode on " + getTableName() + " (vercode);");
db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_id on " + getTableName() + " (id);"); db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_id on " + getTableName() + " (id);");
db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_compatible ON " + getTableName() + " (compatible);"); db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_compatible ON " + getTableName() + " (compatible);");

View File

@ -7,6 +7,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.net.Uri; import android.net.Uri;
import org.fdroid.fdroid.data.Schema.ApkTable;
/** /**
* This class does all of its operations in a temporary sqlite table. * This class does all of its operations in a temporary sqlite table.
*/ */
@ -144,8 +146,8 @@ public class TempAppProvider extends AppProvider {
db.execSQL("DELETE FROM " + DBHelper.TABLE_APP + " WHERE 1"); db.execSQL("DELETE FROM " + DBHelper.TABLE_APP + " WHERE 1");
db.execSQL("INSERT INTO " + DBHelper.TABLE_APP + " SELECT * FROM " + tempApp); db.execSQL("INSERT INTO " + DBHelper.TABLE_APP + " SELECT * FROM " + tempApp);
db.execSQL("DELETE FROM " + DBHelper.TABLE_APK + " WHERE 1"); db.execSQL("DELETE FROM " + ApkTable.NAME + " WHERE 1");
db.execSQL("INSERT INTO " + DBHelper.TABLE_APK + " SELECT * FROM " + tempApk); db.execSQL("INSERT INTO " + ApkTable.NAME + " SELECT * FROM " + tempApk);
db.setTransactionSuccessful(); db.setTransactionSuccessful();