Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserDBHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, DB_NAME, null, DB_VERSION) {
- companion object {
- const val DB_NAME = "DB_User"
- const val DB_VERSION = 1
- const val TABLE_USER = "table_User"
- const val CULM_ID = "id"
- const val CULM_NAME = "name"
- const val CULM_AGE = "age"
- private var instance: UserDBHelper? = null
- @Synchronized
- fun getInstance(ctx: Context): UserDBHelper {
- if (instance == null) {
- instance = UserDBHelper(ctx.getApplicationContext())
- }
- return instance!!
- }
- }
- override fun onCreate(db: SQLiteDatabase) {
- db.createTable(TABLE_USER, true,
- CULM_ID to INTEGER + PRIMARY_KEY + UNIQUE,
- CULM_NAME to TEXT,
- CULM_AGE to INTEGER)
- }
- override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
- db.dropTable(TABLE_USER, true)
- }
- }
Add Comment
Please, Sign In to add comment