Ensure constants always used for fields in ApkProvider.

This commit is contained in:
Peter Serwylo 2016-06-30 15:35:12 +10:00
parent 942cfb59d6
commit 47fa5a94b3
4 changed files with 10 additions and 10 deletions

View File

@ -350,8 +350,8 @@ public class ApkProvider extends FDroidProvider {
appendField("rowid", "apk", "_id");
} else if (field.equals(Cols._COUNT)) {
appendField("COUNT(*) AS " + Cols._COUNT);
} else if (field.equals(Cols._COUNT_DISTINCT_ID)) {
appendField("COUNT(DISTINCT apk.id) AS " + Cols._COUNT_DISTINCT_ID);
} else if (field.equals(Cols._COUNT_DISTINCT)) {
appendField("COUNT(DISTINCT apk." + Cols.PACKAGE_NAME + ") AS " + Cols._COUNT_DISTINCT);
} else {
appendField(field, "apk");
}
@ -360,7 +360,7 @@ public class ApkProvider extends FDroidProvider {
private void addRepoField(String field, String alias) {
if (!repoTableRequired) {
repoTableRequired = true;
leftJoin(RepoTable.NAME, "repo", "apk.repo = repo._id");
leftJoin(RepoTable.NAME, "repo", "apk." + Cols.REPO_ID + " = repo." + RepoTable.Cols._ID);
}
appendField(field, "repo", alias);
}
@ -374,7 +374,7 @@ public class ApkProvider extends FDroidProvider {
}
private QuerySelection querySingle(Uri uri) {
final String selection = " vercode = ? and id = ? ";
final String selection = Cols.VERSION_CODE + " = ? and " + Cols.PACKAGE_NAME + " = ? ";
final String[] args = {
// First (0th) path segment is the word "apk",
// and we are not interested in it.
@ -412,7 +412,7 @@ public class ApkProvider extends FDroidProvider {
if (i != 0) {
sb.append(" OR ");
}
sb.append(" ( id = ? AND vercode = ? ) ");
sb.append(" ( " + Cols.PACKAGE_NAME + " = ? AND " + Cols.VERSION_CODE + " = ? ) ");
}
return new QuerySelection(sb.toString(), args);
}

View File

@ -195,7 +195,7 @@ public class RepoProvider extends FDroidProvider {
public static int countAppsForRepo(Context context, long repoId) {
ContentResolver resolver = context.getContentResolver();
final String[] projection = {Schema.ApkTable.Cols._COUNT_DISTINCT_ID};
final String[] projection = {Schema.ApkTable.Cols._COUNT_DISTINCT};
Uri apkUri = ApkProvider.getRepoUri(repoId);
Cursor cursor = resolver.query(apkUri, projection, null, null, null);
int count = 0;

View File

@ -80,7 +80,7 @@ public interface Schema {
String NAME = "fdroid_apk";
interface Cols extends BaseColumns {
String _COUNT_DISTINCT_ID = "countDistinct";
String _COUNT_DISTINCT = "countDistinct";
String PACKAGE_NAME = "id";
String VERSION_NAME = "version";

View File

@ -131,9 +131,9 @@ public class TempApkProvider extends ApkProvider {
final SQLiteDatabase db = db();
final String memoryDbName = TempAppProvider.DB;
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_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_vercode on " + getTableName() + " (" + ApkTable.Cols.VERSION_CODE + ");");
db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_id on " + getTableName() + " (" + ApkTable.Cols.PACKAGE_NAME + ");");
db.execSQL("CREATE INDEX IF NOT EXISTS " + memoryDbName + ".apk_compatible ON " + getTableName() + " (" + ApkTable.Cols.IS_COMPATIBLE + ");");
}
}