summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-09-04 12:08:17 -0700
committerYorke Lee <yorkelee@google.com>2013-09-04 12:20:30 -0700
commit023ce8c0e22e70595be3a65c7c480e911b124aa6 (patch)
tree2fa5bbc9e550d01a732f42578c0d64f3d81e1bb0
parent1aed2184ac987d2ab42735994bf7aa5047d66e5e (diff)
Fix Dialer crash due to missing database columns
Upgrade steps were not being run correctly due to a bug in getProperty. Tables should be dropped in onCreate in case onCreate is being called by a subclass. Bug: 10618836 Change-Id: Ia832b9a1859b93d51e9d8fe10feae1585fa93b40
-rw-r--r--src/com/android/dialer/database/DialerDatabaseHelper.java23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/com/android/dialer/database/DialerDatabaseHelper.java b/src/com/android/dialer/database/DialerDatabaseHelper.java
index 2fa561fd8..4bf8eda6b 100644
--- a/src/com/android/dialer/database/DialerDatabaseHelper.java
+++ b/src/com/android/dialer/database/DialerDatabaseHelper.java
@@ -71,7 +71,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
* 0-98 KeyLimePie
* </pre>
*/
- public static final int DATABASE_VERSION = 3;
+ public static final int DATABASE_VERSION = 4;
public static final String DATABASE_NAME = "dialer.db";
/**
@@ -337,6 +337,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
*/
@Override
public void onCreate(SQLiteDatabase db) {
+ dropTables(db);
db.execSQL("CREATE TABLE " + Tables.SMARTDIAL_TABLE + " (" +
SmartDialDbColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
SmartDialDbColumns.DATA_ID + " INTEGER, " +
@@ -369,6 +370,12 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
resetSmartDialLastUpdatedTime();
}
+ public void dropTables(SQLiteDatabase db) {
+ db.execSQL("DROP TABLE IF EXISTS " + Tables.PREFIX_TABLE);
+ db.execSQL("DROP TABLE IF EXISTS " + Tables.SMARTDIAL_TABLE);
+ db.execSQL("DROP TABLE IF EXISTS " + Tables.PROPERTIES);
+ }
+
@Override
public void onUpgrade(SQLiteDatabase db, int oldNumber, int newNumber) {
// Disregard the old version and new versions provided by SQLiteOpenHelper, we will read
@@ -382,21 +389,11 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
Log.e(TAG, "Malformed database version..recreating database");
}
- if (oldVersion < 2) {
- db.execSQL("DROP TABLE IF EXISTS " + Tables.PREFIX_TABLE);
- db.execSQL("DROP TABLE IF EXISTS " + Tables.SMARTDIAL_TABLE);
+ if (oldVersion < 4) {
onCreate(db);
return;
}
- if (oldVersion < 3) {
- db.execSQL("CREATE TABLE " + Tables.PROPERTIES + " (" +
- PropertiesColumns.PROPERTY_KEY + " TEXT PRIMARY KEY, " +
- PropertiesColumns.PROPERTY_VALUE + " TEXT " +
- ");");
- oldVersion = 3;
- }
-
if (oldVersion != DATABASE_VERSION) {
throw new IllegalStateException(
"error upgrading the database to version " + DATABASE_VERSION);
@@ -447,7 +444,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
}
public int getPropertyAsInt(SQLiteDatabase db, String key, int defaultValue) {
- final String stored = getProperty(db, DATABASE_VERSION_PROPERTY, "");
+ final String stored = getProperty(db, key, "");
try {
return Integer.parseInt(stored);
} catch (NumberFormatException e) {