diff options
author | Steve Howard <showard@google.com> | 2010-09-23 12:44:11 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-09-23 12:44:11 -0700 |
commit | 36f06f4c8497ab47e64bcc5d8cea12a109fede5e (patch) | |
tree | f8f5d06e418dc1d67b78eaff6c4f72c04a8f33cd /src | |
parent | ebb555c0687061993dd6a22d15f6aab2437ee8c5 (diff) | |
parent | 73f5f223477795e10079d25c1eb5f796af1f00a9 (diff) | |
download | android_packages_providers_DownloadProvider-36f06f4c8497ab47e64bcc5d8cea12a109fede5e.tar.gz android_packages_providers_DownloadProvider-36f06f4c8497ab47e64bcc5d8cea12a109fede5e.tar.bz2 android_packages_providers_DownloadProvider-36f06f4c8497ab47e64bcc5d8cea12a109fede5e.zip |
Merge "DB migration to eliminate some null fields in old downloads" into gingerbread
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/providers/downloads/DownloadProvider.java | 29 |
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 26065015..2cbf7fbb 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); |