Select CRUD operation

The select operation will read and return data from the database. What follows is its implementation:

     val NOTE = object : Crud<Note> { 
        override fun select( 
            args: Pair<String, String> 
        ): List<Note> = select(listOf(args)) 
        override fun select(args: Collection<Pair<String, String>>): List<Note> { val db = DbHelper(name, version).writableDatabase val selection = StringBuilder() val selectionArgs = mutableListOf<String>() args.forEach { arg -> selection.append("${arg.first} == ?") selectionArgs.add(arg.second) } val result = mutableListOf<Note>() val cursor = db.query( true, DbHelper.TABLE_NOTES, null, selection.toString(), selectionArgs.toTypedArray(), null, null, null, null ) while (cursor.moveToNext()) { val id = cursor.getLong(cursor.getColumnIndexOrThrow ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.