如何使用Anko在哪里通过args删除多个SQLite中的行? [英] How to delete rows in SQLite with multiple by where args using Anko?

查看:85
本文介绍了如何使用Anko在哪里通过args删除多个SQLite中的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过_id删除一行,也希望通过Anko使用args删除多行.

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

我已阅读 https://github.com上的文章/Kotlin/anko/wiki/Anko-SQLite#updating-values ,但我没有结果,您能帮我吗?

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?

推荐答案

首先,使用update方法是错误的.删除与更新不同.在SQL中更新意味着更改一行中一个或多个字段的值.您正在寻找的是删除方法

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)

where语句的语法与SQLite中常规where子句的语法略有不同.这是update方法的一个例外,因为它有一个用于通过生成器进行常规" SQL的方法.但是delete方法没有这个功能,因此您必须使用Anko语法.

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.

基本上,您可以将其用作where子句:

Essentially you can use this as a where clause:

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

以及参数中:

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

我不完全确定AND关键字是否可以使用,语法没有完整记录.我认为应该这样,因为没有其他文档记录.一般的SQLite语法应该有效,并且只有参数替换(为避免SQL注入,我认为是不同的)

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

这篇关于如何使用Anko在哪里通过args删除多个SQLite中的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆