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

时光总嘲笑我的痴心妄想 提交于 2019-12-13 09:18:50

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/47319732/how-to-delete-rows-in-sqlite-with-multiple-by-where-args-using-anko

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!