Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tgs.app.submission1_aplikasifootballleague.db
- import android.content.Context
- import android.database.sqlite.SQLiteDatabase
- import org.jetbrains.anko.db.*
- class MyDatabaseOpenHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "FavoriteTeam.db", null, 1) {
- companion object {
- private var instance: MyDatabaseOpenHelper? = null
- @Synchronized
- fun getInstance(ctx: Context) : MyDatabaseOpenHelper {
- if (instance == null){
- instance = MyDatabaseOpenHelper(ctx.applicationContext)
- }
- return instance as MyDatabaseOpenHelper
- }
- }
- override fun onCreate(p0: SQLiteDatabase?) {
- p0?.createTable(Favorite.TABLE_FAVORITE, true,
- Favorite.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT,
- Favorite.ID_EVENT to TEXT + UNIQUE,
- Favorite.DATE_EVENT to TEXT,
- Favorite.STR_HOME_TEAM to TEXT,
- Favorite.STR_AWAY_TEAM to TEXT,
- Favorite.INT_HOME_TEAM to TEXT,
- Favorite.INT_AWAY_TEAM to TEXT)
- }
- override fun onUpgrade(p0: SQLiteDatabase?, p1: Int, p2: Int) {
- p0?.dropTable(Favorite.TABLE_FAVORITE, true)
- }
- }
- //Access property for Context
- val Context.database: MyDatabaseOpenHelper
- get() = MyDatabaseOpenHelper.getInstance(applicationContext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement