summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-09-04 19:40:05 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-04 19:40:06 +0000
commitefcd37e2d54f0f4d38fdc71cfab3460c1e0c507a (patch)
tree8ff13216ea3fe7eddce2219403b97d735c867bce
parentf802f432822f3b1e05b1253f51c6c17c8f97b752 (diff)
parent023ce8c0e22e70595be3a65c7c480e911b124aa6 (diff)
Merge "Fix Dialer crash due to missing database columns" into klp-dev
-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) {