Created
October 15, 2013 06:14
-
-
Save evilbloodydemon/6987259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val DB_VERSION = 5; | |
| [suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] | |
| public class PillSQLiteHelper(context: Context) : | |
| SQLiteOpenHelper(context, "pills_db", null, DB_VERSION) { | |
| val migrations: Map<Int, String> = mapOf( | |
| 1 to """ | |
| CREATE TABLE pills ( | |
| _id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| name TEXT NOT NULL, | |
| count INTEGER NOT NULL, | |
| times INTEGER NOT NULL | |
| ); | |
| """, | |
| 2 to "ALTER TABLE pills ADD last_medication INTEGER NOT NULL DEFAULT(0)", | |
| 3 to "ALTER TABLE pills ADD used_today INTEGER NOT NULL DEFAULT(0)", | |
| 4 to "ALTER TABLE pills ADD disabled INTEGER NOT NULL DEFAULT(0)", | |
| 5 to "DELETE FROM pills WHERE _id = 1" | |
| ) | |
| public override fun onCreate(db: SQLiteDatabase) { | |
| onUpgrade(db, 0, DB_VERSION) | |
| } | |
| public override fun onUpgrade(db: SQLiteDatabase, oldVer: Int, newVer: Int) { | |
| for(i in (oldVer + 1)..newVer) { | |
| val statement = migrations[i] | |
| if (statement != null) db.execSQL(statement) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment