alberking alberking - 1 year ago 110
Android Question

How to delete rows in SQLite with multiple where args?

I want to delete rows which satisfy any of multiple conditions.

For example, I pass a list of IDs, and I want to delete all rows with these

(IDs are unique).

This would be:

String[] ids = {"0", "1", "2", "3",...};
database.delete("rows" , "id=? OR id=? OR id=? OR id=? OR ..." , ids );

Is there any way to do it compact without multiple

Answer Source

You may get it done through db.execSQL method and SQL's IN keyword. For example:

String args = TextUtils.join(", ", ids);

db.execSQL(String.format("DELETE FROM rows WHERE ids IN (%s);", args));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download