Commit 5c751488 authored by Mygod's avatar Mygod

Add support for downgrading the database for whatever reason

And it simply kills all the data.
parent ae833210
...@@ -27,8 +27,8 @@ import android.content.pm.ApplicationInfo ...@@ -27,8 +27,8 @@ import android.content.pm.ApplicationInfo
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import android.preference.PreferenceManager import android.preference.PreferenceManager
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.preference.OrmLitePreferenceDataStore
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import com.j256.ormlite.android.AndroidDatabaseConnection
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
import com.j256.ormlite.dao.Dao import com.j256.ormlite.dao.Dao
import com.j256.ormlite.support.ConnectionSource import com.j256.ormlite.support.ConnectionSource
...@@ -68,9 +68,7 @@ class DBHelper(val context: Context) ...@@ -68,9 +68,7 @@ class DBHelper(val context: Context)
onCreate(database, connectionSource) onCreate(database, connectionSource)
} }
def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, newVersion: Int) {
newVersion: Int) {
if (oldVersion != newVersion) {
if (oldVersion < 7) { if (oldVersion < 7) {
recreate(database, connectionSource) recreate(database, connectionSource)
return return
...@@ -156,8 +154,13 @@ class DBHelper(val context: Context) ...@@ -156,8 +154,13 @@ class DBHelper(val context: Context)
case ex: Exception => case ex: Exception =>
app.track(ex) app.track(ex)
recreate(database, connectionSource) recreate(database, connectionSource)
return
} }
} }
override def onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
val connection = new AndroidDatabaseConnection(db, true)
connectionSource.saveSpecialConnection(connection)
recreate(db, connectionSource)
connectionSource.clearSpecialConnection(connection)
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment