pengwang
pengwang

Reputation: 19956

getContentResolver().delete filter not effect

i want to delete "TYPE=0" record,my code:

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);

so I can insert many records,some record Call.TYPE=0 ,some Call.TYPE=1, so I want to delete all Call.TYPE=1. My code:

int a=getContentResolver().delete(Call.CONTENT_URI,  Call.TYPE +"=" +1, null);

but the app delete all records,include Call.TYPE=0.I do not know what is wrong. Add,insert,update record all is ok,but delete some reocrds not effect, can you give some advice, please?

Upvotes: 0

Views: 1822

Answers (1)

harikrishnan
harikrishnan

Reputation: 1945

use this code to delete particular row when match 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

Upvotes: 2

Related Questions