1

I want to delete all rows in a table with a specific ID (not primary key). I have tested two different methods, but they only remove the first row it finds with the specific ID:

db.delete(CalendarTable.TABLE_NAME, "repeat_group="+repeatGroup, null);

and

db.delete(CalendarTable.TABLE_NAME, "repeat_group=?", new String[]{Integer.toString(repeatGroup)});

None of these methods works, how can I remove ALL rows in a table with this specific ID? Thanks in advance!

UPDATE: Lol, the method above did work! It was just me the stupid one that called the my own method delete() instead of deleteRepeatGroup(), guess I'm too tired! Anyways, thank you guys for taking your time.

7
  • it should work ... are you using transaction ? Commented Oct 11, 2011 at 13:07
  • I dont think I'm using transaction, how can I be sure if I do? Commented Oct 11, 2011 at 13:08
  • I even tried: db.rawQuery("DELETE FROM calendar WHERE repeat_group="+repeatGroup, null); Commented Oct 11, 2011 at 13:18
  • It has nothing do with transaction. The solution can be you can a raw query as the first answer suggest. Commented Oct 11, 2011 at 13:19
  • I've tried a raw query too. Doesn't work, only deletes the first row =/ Commented Oct 11, 2011 at 13:21

2 Answers 2

1

If everything else fails, you can try the following. Get all rows in the table with the ID you are trying to delete and save the rowID's in an array. Then iterate over the array and delete each row.

I hope this works as expected

Sign up to request clarification or add additional context in comments.

Comments

1

you can use

String urQuery = "delete from tablename where Id in ("
    + Id + ")";

here Id may have all ids separated by comma ex. "id1,id2".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.