import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
class DataBaseHelper(context: Context, dbName: String):
SQLiteOpenHelper(context, dbName, null, 1) {
override fun onCreate(db: SQLiteDatabase?) {}
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int,
newVersion: Int) {}
}
//Connect to the database
val dbHelper = DataBaseHelper(
context,
dbPath + "DatabaseName.sqlite"
)
//SQL query execution
val db = dbHelper.readableDatabase
val cursor = db.rawQuery(
"""SELECT
Language, Percentage
FROM countrylanguage
WHERE CountryCode = 'RUS'
ORDER BY Percentage DESC""", null)
//Get first row
cursor.moveToFirst()
println(cursor.getString(0) +
": " + cursor.getDouble(1))
// Get all rows
while (!cursor.isAfterLast()) {
println(cursor.getString(0) +
": " + cursor.getDouble(1))
cursor.moveToNext()
}
//Close the connection
cursor.close()