kopia lustrzana https://github.com/ge0rg/aprsdroid
outsource resetting of positions table
rodzic
5047ea7df4
commit
a50e18d987
|
@ -91,25 +91,30 @@ class StorageDatabase(context : Context) extends
|
|||
db.execSQL(Position.TABLE_CREATE)
|
||||
Array("call", "lat", "lon").map(col => db.execSQL(Position.TABLE_INDEX.format(col, col)))
|
||||
}
|
||||
def resetPositionsTable(db : SQLiteDatabase) {
|
||||
db.execSQL(Position.TABLE_DROP)
|
||||
db.execSQL(Position.TABLE_CREATE)
|
||||
Array("call", "lat", "lon").map(col => db.execSQL(Position.TABLE_INDEX.format(col, col)))
|
||||
// we can not call getPosts() here due to recursion issues
|
||||
val c = db.query(Post.TABLE, Post.COLUMNS, "TYPE = 0 OR TYPE = 3",
|
||||
null, null, null, "_ID DESC", null)
|
||||
c.moveToFirst()
|
||||
while (!c.isAfterLast()) {
|
||||
val message = c.getString(c.getColumnIndexOrThrow(Post.MESSAGE))
|
||||
val ts = c.getLong(c.getColumnIndexOrThrow(Post.TS))
|
||||
addPosition(ts, message)
|
||||
c.moveToNext()
|
||||
}
|
||||
c.close()
|
||||
}
|
||||
def resetPositionsTable() : Unit = resetPositionsTable(getWritableDatabase())
|
||||
|
||||
override def onUpgrade(db: SQLiteDatabase, from : Int, to : Int) {
|
||||
if (from == 1 && to >= 2) {
|
||||
db.execSQL("ALTER TABLE %s ADD COLUMN %s".format(Post.TABLE, "TYPE INTEGER DEFAULT 0"))
|
||||
}
|
||||
if (from <= 4 && to >= 3) {
|
||||
db.execSQL(Position.TABLE_DROP)
|
||||
db.execSQL(Position.TABLE_CREATE)
|
||||
Array("call", "lat", "lon").map(col => db.execSQL(Position.TABLE_INDEX.format(col, col)))
|
||||
// we can not call getPosts() here due to recursion issues
|
||||
val c = db.query(Post.TABLE, Post.COLUMNS, "TYPE = 0 OR TYPE = 3",
|
||||
null, null, null, "_ID DESC", null)
|
||||
c.moveToFirst()
|
||||
while (!c.isAfterLast()) {
|
||||
val message = c.getString(c.getColumnIndexOrThrow(Post.MESSAGE))
|
||||
val ts = c.getLong(c.getColumnIndexOrThrow(Post.TS))
|
||||
addPosition(ts, message)
|
||||
c.moveToNext()
|
||||
}
|
||||
c.close()
|
||||
resetPositionsTable(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue