我想删除“TYPE = 0”记录,我的代码:
cv.put(Call.NAME, titleString);
cv.put(Call.BUILD_NAME, "");
cv.put(Call.BUILD, build);
cv.put(Call.UNIT, unit);
cv.put(Call.ROOM, room);
cv.put(Call.TIME, date);
cv.put(Call.TYPE, 0);//
cv.put(Call.DEVICETYPE, doordevicetype);
cv.put(Call.PHOTO, baos.toByteArray());
cv.put(Call.CONTACT_ID, 9999);
Uri contactUri, uriRet;
ContentResolver resolver = getContentResolver();
uriRet = resolver.insert(contactUri, cv);
所以我可以插入很多记录,一些记录Call.TYPE=0
,一些Call.TYPE=1
,所以我想删除所有Call.TYPE=1
。我的代码:
int a=getContentResolver().delete(Call.CONTENT_URI, Call.TYPE +"=" +1, null);
但应用删除了所有记录,包括Call.TYPE=0
。我不知道出了什么问题。添加,插入,更新记录一切正常,但删除一些reocrds没有效果,请问一些建议吗?
答案 0 :(得分:2)
在匹配TYPE = 1 ...
时使用此代码删除特定行 String[] selectionArgs=new String[]{String.valueOf(1)};
// this is for which argument to match with TYPE=1 and delete row
String selection=""+TablenName.TYPE+"=?"; // this is where condition
getContentResolver().delete( Call.CONTENT_URI, selection, selectionArgs);
Note : just refer this [link][1]. its usefull to understand for , how delete are happening..
[1]: http://www.w3schools.com/sql/sql_delete.asp