From bee422a15d39f872d22c71fa27aa7810929f2645 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Jan 2017 23:34:09 +0100 Subject: [PATCH] add a new db column for import_id to avoid duplicately imported events --- .../simplemobiletools/calendar/helpers/DBHelper.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index e0898c809..7972856bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -23,6 +23,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V private val COL_TITLE = "title" private val COL_DESCRIPTION = "description" private val COL_REMINDER_MINUTES = "reminder_minutes" + private val COL_IMPORT_ID = "import_id" private val META_TABLE_NAME = "events_meta" private val COL_EVENT_ID = "event_id" @@ -36,7 +37,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V companion object { private val DB_NAME = "events.db" - private val DB_VERSION = 3 + private val DB_VERSION = 4 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) { 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) } @@ -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") } - if (newVersion == 3) { + if (oldVersion < 3) { createMetaTable(db) } + + if (oldVersion < 4) { + db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_IMPORT_ID TEXT") + } } private fun createMetaTable(db: SQLiteDatabase) {