rifki_cs29

DatabaseHelper

Jul 1st, 2020
1,003
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.rifki.kotlin.mygithubfinal.db
  2.  
  3. import android.content.Context
  4. import android.database.sqlite.SQLiteDatabase
  5. import android.database.sqlite.SQLiteOpenHelper
  6. import com.rifki.kotlin.mygithubfinal.db.DatabaseContract.FavouriteColumns.Companion.TABLE_NAME
  7. import com.rifki.kotlin.mygithubfinal.db.DatabaseContract.FavouriteColumns
  8.  
  9. internal class DatabaseHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION){
  10.     companion object{
  11.         private const val DATABASE_NAME = "dbgithubfinalapp"
  12.         private const val DATABASE_VERSION = 1
  13.  
  14.         private val SQL_CREATE_TABLE_NOTE = "CREATE TABLE $TABLE_NAME" +
  15.                 "(${FavouriteColumns._ID} INTEGER PRIMARY KEY AUTOINCREMENT," +
  16.                 " ${FavouriteColumns.USERNAME} TEXT NOT NULL UNIQUE," +
  17.                 " ${FavouriteColumns.AVATAR} TEXT NOT NULL," +
  18.                 " ${FavouriteColumns.URL} TEXT NOT NULL)"
  19.  
  20.     }
  21.  
  22.     override fun onCreate(db: SQLiteDatabase) {
  23.         db.execSQL(SQL_CREATE_TABLE_NOTE)
  24.     }
  25.  
  26.     override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
  27.         db.execSQL("DROP TABLE IF EXISTS $TABLE_NAME")
  28.         onCreate(db)
  29.     }
  30.  
  31. }
RAW Paste Data