summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-23 13:10:54 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-09-23 13:10:54 -0700
commit7704d598c451c1a2615a8910d65c593de1757d19 (patch)
treef17a1574e065293cd9218b455a3bfac921706ddf
parent4292815e4e1cb17ed312a6f7f3f881e58a511742 (diff)
parent04d7025262d7f6c5c372ec699d78b18d05b0400b (diff)
downloadandroid_packages_providers_DownloadProvider-7704d598c451c1a2615a8910d65c593de1757d19.tar.gz
android_packages_providers_DownloadProvider-7704d598c451c1a2615a8910d65c593de1757d19.tar.bz2
android_packages_providers_DownloadProvider-7704d598c451c1a2615a8910d65c593de1757d19.zip
am 04d70252: am 36f06f4c: Merge "DB migration to eliminate some null fields in old downloads" into gingerbread
Merge commit '04d7025262d7f6c5c372ec699d78b18d05b0400b' * commit '04d7025262d7f6c5c372ec699d78b18d05b0400b': DB migration to eliminate some null fields in old downloads
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 0e451d04..44d755d3 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -57,7 +57,7 @@ public final class DownloadProvider extends ContentProvider {
/** Database filename */
private static final String DB_NAME = "downloads.db";
/** Current database version */
- private static final int DB_VERSION = 104;
+ private static final int DB_VERSION = 105;
/** Name of table in the database */
private static final String DB_TABLE = "downloads";
@@ -228,12 +228,38 @@ public final class DownloadProvider extends ContentProvider {
"INTEGER NOT NULL DEFAULT 0");
break;
+ case 105:
+ fillNullValues(db);
+ break;
+
default:
throw new IllegalStateException("Don't know how to upgrade to " + version);
}
}
/**
+ * insert() now ensures these four columns are never null for new downloads, so this method
+ * makes that true for existing columns, so that code can rely on this assumption.
+ */
+ private void fillNullValues(SQLiteDatabase db) {
+ ContentValues values = new ContentValues();
+ values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, 0);
+ fillNullValuesForColumn(db, values);
+ values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1);
+ fillNullValuesForColumn(db, values);
+ values.put(Downloads.Impl.COLUMN_TITLE, "");
+ fillNullValuesForColumn(db, values);
+ values.put(Downloads.Impl.COLUMN_DESCRIPTION, "");
+ fillNullValuesForColumn(db, values);
+ }
+
+ private void fillNullValuesForColumn(SQLiteDatabase db, ContentValues values) {
+ String column = values.valueSet().iterator().next().getKey();
+ db.update(DB_TABLE, values, column + " is null", null);
+ values.clear();
+ }
+
+ /**
* Set all existing downloads to the cache partition to be invisible in the downloads UI.
*/
private void makeCacheDownloadsInvisible(SQLiteDatabase db) {
@@ -463,6 +489,7 @@ public final class DownloadProvider extends ContentProvider {
copyStringWithDefault(Downloads.Impl.COLUMN_TITLE, values, filteredValues, "");
copyStringWithDefault(Downloads.Impl.COLUMN_DESCRIPTION, values, filteredValues, "");
filteredValues.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1);
+ filteredValues.put(Downloads.Impl.COLUMN_CURRENT_BYTES, 0);
if (values.containsKey(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI)) {
copyBoolean(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI, values, filteredValues);