简记利用ContentProvider执行删除操作

先贴一下API文档的解释

public abstract int delete (Uri uri, String selection, String[] selectionArgs)
Added in  API level 1

Implement this to handle requests to delete one or more rows. The implementation should apply the selection clause when performing deletion, allowing the operation to affect multiple rows in a directory. As a courtesy, call notifyChange() after deleting. This method can be called from multiple threads, as described in Processes and Threads.

The implementation is responsible for parsing out a row ID at the end of the URI, if a specific row is being deleted. That is, the client would pass in content://contacts/people/22and the implementation is responsible for parsing the record number (22) when creating a SQL statement.

Parameters
uri The full URI to query, including a row ID (if a specific record is requested).
selection An optional restriction to apply to rows when deleting.
Returns
  • The number of rows affected.
Throws

SQLException

我乍一看API的介绍,发现参数介绍中并没有包括对第三个参数 String[] selectionArgs的介绍,一开始以为是我看走眼,在概述中应该能找到相关解释,后来仔细翻译过来也没有,只确定它是selection的参数,后来回忆了一下SQLite的SQL语句,想到了execSQL(String sql, Object[] bindArgs)方法,想到了一个例子。

sqliteDatabase.execsql("insert into table(_id,_name,_num) values(?,?,?)",new String[]{id,name,num});

这句语句表示插入三个参数到表table中,以此类比,delete方法可能为

getContentResolver().delete(URI , "id=?,name=?,num=?",new String[]{id,name,num});

意思是什么就很明了了,适合判断多组数据同时满足的操作。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值