add a new db column for import_id to avoid duplicately imported events

This commit is contained in:
tibbi 2017-01-26 23:34:09 +01:00
parent 28e1b06703
commit bee422a15d
1 changed files with 8 additions and 3 deletions

View File

@ -23,6 +23,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
private val COL_TITLE = "title" private val COL_TITLE = "title"
private val COL_DESCRIPTION = "description" private val COL_DESCRIPTION = "description"
private val COL_REMINDER_MINUTES = "reminder_minutes" private val COL_REMINDER_MINUTES = "reminder_minutes"
private val COL_IMPORT_ID = "import_id"
private val META_TABLE_NAME = "events_meta" private val META_TABLE_NAME = "events_meta"
private val COL_EVENT_ID = "event_id" private val COL_EVENT_ID = "event_id"
@ -36,7 +37,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
companion object { companion object {
private val DB_NAME = "events.db" private val DB_NAME = "events.db"
private val DB_VERSION = 3 private val DB_VERSION = 4
lateinit private var mDb: SQLiteDatabase lateinit private var mDb: SQLiteDatabase
} }
@ -51,7 +52,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
override fun onCreate(db: SQLiteDatabase) { override fun onCreate(db: SQLiteDatabase) {
db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY, $COL_START_TS INTEGER, $COL_END_TS INTEGER, $COL_TITLE TEXT, " + db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY, $COL_START_TS INTEGER, $COL_END_TS INTEGER, $COL_TITLE TEXT, " +
"$COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER)") "$COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER, $COL_IMPORT_ID TEXT)")
createMetaTable(db) createMetaTable(db)
} }
@ -61,9 +62,13 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_REMINDER_MINUTES INTEGER DEFAULT -1") db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_REMINDER_MINUTES INTEGER DEFAULT -1")
} }
if (newVersion == 3) { if (oldVersion < 3) {
createMetaTable(db) createMetaTable(db)
} }
if (oldVersion < 4) {
db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_IMPORT_ID TEXT")
}
} }
private fun createMetaTable(db: SQLiteDatabase) { private fun createMetaTable(db: SQLiteDatabase) {