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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.