How to delete rows in SQLite with multiple by where args using Anko?
Asked Answered
O

1

-2

I hope to delete a row by _id, I hope to delete multiple rows by where args using Anko too.

I have read the article at https://github.com/Kotlin/anko/wiki/Anko-SQLite#updating-values, but I have no result, could you help me?

Orelee answered 16/11, 2017 at 0:42 Comment(0)
C
6

First off, using the update method is wrong. Deleting is not the same as updating. Updating in SQL means changing the value of one or more fields in a row. What you are looking for is the delete method

dbHelper.delete(TABLE_NAME, whereClause="Your actual where statement here", args)

The where statement follows a slightly different syntax than the regular where clauses in SQLite. This is an exception to the update method because it has a method for "regular" SQL through a builder. The delete method does not have this though, so you have to use the Anko syntax.

Essentially you can use this as a where clause:

"someRow = {someRowData} AND differentRow = {otherData}"

and in the arguments:

"someRowData" to "whatever value you want",
"otherData" to 1234

I'm not entirely sure whether or not the AND keyword will work, the syntax isn't fully documented. I assume it should because there's nothing else documented. The general SQLite syntax should be valid, and only the argument replacement (to avoid SQL injection I assume) is different

Complacence answered 20/11, 2017 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.