在Android中使用Content Provider批量删除项目 [英] Batch Delete items with Content Provider in Android
本文介绍了在Android中使用Content Provider批量删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图批量删除表中的某些项目.
I'm trying to batch delete some items in a table.
String ids = { "1", "2", "3" };
mContentResolver.delete(uri, MyTables._ID + "=?", ids);
但是我仍然收到以下错误消息
However I keep getting this following error
java.lang.IllegalArgumentException:绑定参数太多.提供了3个参数,但该语句需要1个参数.
java.lang.IllegalArgumentException: Too many bind arguments. 3 arguments were provided but the statement needs 1 arguments.
推荐答案
发生错误是因为在传递三个参数时,where子句中只有一个占位符(?).您应该这样做:
The error occurs because you have a single placeholder (?) in your where clause, while you pass three arguments. You should do:
String ids = { "1", "2", "3" };
mContentResolver.delete(uri, MyTables._ID + "=? OR " + MyTables._ID + "=? OR " + MyTables._ID + "=?", ids);
我不知道SQLite是否支持IN子句,如果这样,您也可以这样做:
I do not know if SQLite supports the IN clause, if so you could also do:
String ids = { "1, 2, 3" };
mContentResolver.delete(uri, MyTables._ID + " IN (?)", ids);
这篇关于在Android中使用Content Provider批量删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文