How to delete rows in SQLite with multiple where args?

前端 未结 6 897
陌清茗
陌清茗 2021-02-01 04:59

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 (IDs are uni

6条回答
  •  盖世英雄少女心
    2021-02-01 05:56

    What you want to use is an IN clause, something like (with 4 IDs);

    database.delete("rows", "id IN (?, ?, ?, ?)", ids );
    

    Upon request, this is (one example of) how you can do it dynamically;

    database.delete("rows", 
        "id IN (" + new String(new char[ids.length-1]).replace("\0", "?,") + "?)", 
        ids);
    

提交回复
热议问题