Guest User

Untitled

a guest
Jan 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class UserDBHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, DB_NAME, null, DB_VERSION) {
  2.  
  3. companion object {
  4. const val DB_NAME = "DB_User"
  5. const val DB_VERSION = 1
  6.  
  7. const val TABLE_USER = "table_User"
  8.  
  9. const val CULM_ID = "id"
  10. const val CULM_NAME = "name"
  11. const val CULM_AGE = "age"
  12.  
  13. private var instance: UserDBHelper? = null
  14.  
  15. @Synchronized
  16. fun getInstance(ctx: Context): UserDBHelper {
  17. if (instance == null) {
  18. instance = UserDBHelper(ctx.getApplicationContext())
  19. }
  20. return instance!!
  21. }
  22. }
  23.  
  24. override fun onCreate(db: SQLiteDatabase) {
  25. db.createTable(TABLE_USER, true,
  26. CULM_ID to INTEGER + PRIMARY_KEY + UNIQUE,
  27. CULM_NAME to TEXT,
  28. CULM_AGE to INTEGER)
  29. }
  30.  
  31. override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
  32. db.dropTable(TABLE_USER, true)
  33. }
  34. }
Add Comment
Please, Sign In to add comment