Commit 9218ee42 authored by Max Lv's avatar Max Lv

fix the database issue

parent cc5fafbd
...@@ -107,7 +107,11 @@ trait BaseService { ...@@ -107,7 +107,11 @@ trait BaseService {
if (state != s) { if (state != s) {
val n = callbacks.beginBroadcast() val n = callbacks.beginBroadcast()
for (i <- 0 to n - 1) { for (i <- 0 to n - 1) {
try {
callbacks.getBroadcastItem(i).stateChanged(s, msg) callbacks.getBroadcastItem(i).stateChanged(s, msg)
} catch {
case _: Exception => // Ignore
}
} }
callbacks.finishBroadcast() callbacks.finishBroadcast()
state = s state = s
......
...@@ -50,20 +50,24 @@ object DBHelper { ...@@ -50,20 +50,24 @@ object DBHelper {
val PROFILE = "profile.db" val PROFILE = "profile.db"
} }
class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 8) { class DBHelper(val context: Context)
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 8) {
lazy val profileDao:Dao[Profile,Int] = getDao(classOf[Profile]) lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile])
def onCreate(database: SQLiteDatabase, connectionSource: ConnectionSource) { def onCreate(database: SQLiteDatabase, connectionSource: ConnectionSource) {
TableUtils.createTable(connectionSource, classOf[Profile]) TableUtils.createTable(connectionSource, classOf[Profile])
} }
def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, newVersion: Int) { def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int,
newVersion: Int) {
if (oldVersion != newVersion) {
if (oldVersion < 8) { if (oldVersion < 8) {
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns INTEGER;") profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;")
} else { } else {
TableUtils.dropTable(connectionSource, classOf[Profile], true) profileDao.executeRaw("DROP TABLE IF EXISTS 'profile';")
}
onCreate(database, connectionSource) onCreate(database, connectionSource)
} }
}
}
} }
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