Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...