Fix update count, breakage from rebase, and broken tests.

The update count was broken because I added the join onto the
apk table, and in the process, forced a GROUP BY on the AppProvider
queries. This group by made the COUNT(*) actually count the number
of apks for each app, not the total rows.
This commit is contained in:
Peter Serwylo 2015-04-01 15:39:13 +11:00
parent 2a481f6889
commit a2be7d9013
3 changed files with 11 additions and 7 deletions

View File

@ -61,7 +61,7 @@ import java.util.Locale;
public final class Utils { public final class Utils {
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
private static final String TAG = "org.fdroid.fdroid.Utils"; private static final String TAG = "fdroid.Utils";
public static final int BUFFER_SIZE = 4096; public static final int BUFFER_SIZE = 4096;
@ -75,8 +75,6 @@ public final class Utils {
public static final SimpleDateFormat LOG_DATE_FORMAT = public static final SimpleDateFormat LOG_DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
private static final String TAG = "fdroid.Utils";
public static String getIconsDir(Context context) { public static String getIconsDir(Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); DisplayMetrics metrics = context.getResources().getDisplayMetrics();
String iconsDir; String iconsDir;

View File

@ -259,6 +259,7 @@ public class AppProvider extends FDroidProvider {
private boolean isSuggestedApkTableAdded = false; private boolean isSuggestedApkTableAdded = false;
private boolean requiresInstalledTable = false; private boolean requiresInstalledTable = false;
private boolean categoryFieldAdded = false; private boolean categoryFieldAdded = false;
private boolean countFieldAppended = false;
@Override @Override
protected String getRequiredTables() { protected String getRequiredTables() {
@ -278,7 +279,8 @@ public class AppProvider extends FDroidProvider {
@Override @Override
protected String groupBy() { protected String groupBy() {
return DBHelper.TABLE_APP + ".id"; // If the count field has been requested, then we want to group all rows together.
return countFieldAppended ? null : DBHelper.TABLE_APP + ".id";
} }
public void addSelection(AppQuerySelection selection) { public void addSelection(AppQuerySelection selection) {
@ -329,7 +331,8 @@ public class AppProvider extends FDroidProvider {
} }
private void appendCountField() { private void appendCountField() {
appendField("COUNT(*) AS " + DataColumns._COUNT); countFieldAppended = true;
appendField("COUNT( DISTINCT fdroid_app.id ) AS " + DataColumns._COUNT);
} }
private void addSuggestedApkVersionField() { private void addSuggestedApkVersionField() {

View File

@ -11,6 +11,9 @@ import mock.MockContextSwappableComponents;
import mock.MockInstallablePackageManager; import mock.MockInstallablePackageManager;
import org.fdroid.fdroid.data.ApkProvider; import org.fdroid.fdroid.data.ApkProvider;
import org.fdroid.fdroid.data.AppProvider; import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.receiver.PackageAddedReceiver;
import org.fdroid.fdroid.receiver.PackageRemovedReceiver;
import org.fdroid.fdroid.receiver.PackageUpgradedReceiver;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,7 +22,7 @@ import java.util.List;
public class TestUtils { public class TestUtils {
private static final String TAG = "org.fdroid.fdroid.TestUtils"; private static final String TAG = "fdroid.TestUtils";
public static <T extends Comparable> void assertContainsOnly(List<T> actualList, T[] expectedArray) { public static <T extends Comparable> void assertContainsOnly(List<T> actualList, T[] expectedArray) {
List<T> expectedList = new ArrayList<T>(expectedArray.length); List<T> expectedList = new ArrayList<T>(expectedArray.length);
@ -134,7 +137,7 @@ public class TestUtils {
/** /**
* Will tell {@code pm} that we are installing {@code appId}, and then alert the * Will tell {@code pm} that we are installing {@code appId}, and then alert the
* {@link org.fdroid.fdroid.PackageAddedReceiver}. This will in turn update the * {@link org.fdroid.fdroid.receiver.PackageAddedReceiver}. This will in turn update the
* "installed apps" table in the database. * "installed apps" table in the database.
*/ */
public static void installAndBroadcast( public static void installAndBroadcast(