This file contains 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
class DatabaseHelper private constructor(context: Context) { | |
companion object { | |
private var instance: DatabaseHelper? = null | |
fun getInstance(context: Context): DatabaseHelper { | |
if (instance == null) { | |
instance = DatabaseHelper(context) | |
} | |
return instance!! | |
} | |
} | |
private val database: SQLiteDatabase = context.openOrCreateDatabase("app_db", Context.MODE_PRIVATE, null) | |
fun executeQuery(query: String) { | |
database.execSQL(query) | |
} | |
fun getData(query: String): Cursor { | |
return database.rawQuery(query, null) | |
} | |
} | |
val databaseHelper = DatabaseHelper.getInstance(applicationContext) | |
val cursor = databaseHelper.getData("SELECT * FROM users") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment