SQLite的更新具有参数化IN(...)子句 [英] Sqlite UPDATE with parameterised IN (...) clause

查看:294
本文介绍了SQLite的更新具有参数化IN(...)子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我正与SQLite数据库 - 我打了一个奇怪的问题

In my app I'm working with sqlite database - and I hit a strange issue.

我有一个看起来像这样的表:

I have a table that looks like this:

_id   field1   field2   status
---   ------   ------   ------
 1    value    value    ...
 2    value    value    ...
...

在一个地方,我需要更新一些行将它们设置为另一种状态,所以我想

At one place, I need to update some rows to set them to another status, so I'm trying

SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("status", STATUS_SENT);
Set<Integer> ids = datasource.getCompletedIds();
String idparam = TextUtils.join(",", ids);
int cnt = db.update(TABLE_ORDERS, cv, "_id in (?)", new String[] { idparam });
Log.d("db", "updated " + cnt + " rows");
db.close();

但是没有得到更新 - 和 db.update 返回0。我在想什么

However nothing gets updated - and db.update returns 0. What am I missing?

推荐答案

我不开心推荐的没有的使用参数,但是这种情况下,它实际上不是格式所有的<$ C $容易C> 标记(与普通整数,就像安全):

I'm not happy recommending not using parameters, but it this case, it's actually easier than formatting all those ? markers (and with plain integers, just as safe):

db.update(TABLE_ORDERS, cv, "_id IN (" + idparam + ")", null);

这篇关于SQLite的更新具有参数化IN(...)子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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