Created
January 19, 2023 11:32
-
-
Save alibahaaa/40d4f2a5d53dda22e8bc5d93bf848114 to your computer and use it in GitHub Desktop.
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