Delete CRUD operation

The delete operation will remove the existing data from the database. What follows is its implementation:

 val NOTE = object : Crud<Note> { ... override fun delete(what: Note): Int = delete(listOf(what)) override fun delete(what: Collection<Note>): Int { val db = DbHelper(name, version).writableDatabase db.beginTransaction() val ids = StringBuilder() what.forEachIndexed { index, item -> ids.append(item.id.toString()) if (index < what.size - 1) { ids.append(", ") } } val table = DbHelper.TABLE_NOTES val statement = db.compileStatement( "DELETE FROM $table WHERE ${DbHelper.ID} IN ($ids);" ) val count = statement.executeUpdateDelete() val success = count > 0 if (success) { db.setTransactionSuccessful() Log.i(tag, "Delete ...

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.