Created
October 23, 2017 11:19
-
-
Save abdul-rehman-2050/41dc02af9081bc65277858bb0df74440 to your computer and use it in GitHub Desktop.
access database from assets\databases\test.db
selection queries
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
package learnkotlin.blogspost.com.sqliteex01 | |
import android.content.Context | |
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper | |
/** | |
* Created by mac on 23/10/2017..... | |
* Added this line to dependancey | |
* compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+' | |
* | |
*/ | |
class MyDBAccess(context:Context) { | |
val sqldb = SQLiteAssetHelper(context,"test.sqlite",null,1).writableDatabase | |
fun getDescription(title: String):String{ | |
val c = sqldb?.rawQuery("SELECT * FROM test1 WHERE title=\'$title\'", null) | |
val list = (1 .. c!!.count).map { | |
c.moveToNext() | |
c.getString(c.getColumnIndex("body")) | |
} | |
c.close() | |
return list[0] | |
} | |
fun getValueFromTableTest(): List<String>? { | |
val c = sqldb?.rawQuery("SELECT * FROM test1", null) | |
val list = (1 .. c!!.count).map { | |
c.moveToNext() | |
c.getString(c.getColumnIndex("title")) | |
} | |
c.close() | |
return list | |
} | |
fun closeMyDB() { | |
if (sqldb != null && sqldb.isOpen()) { | |
sqldb.close() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment