How to delete rows in SQLite with multiple where args?

前端 未结 6 1034
陌清茗
陌清茗 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:40

    Android official documentation tells here that using execSQL is not the proper way to delete records.

    I would like to suggest the following simple method. Using provided delete() api.

    String[] idArray = new String[] {"1", "2", "3"};
    String idsCSV = TextUtils.join(",", idArray);
    SQLiteDatabase db = getWritableDatabase();
    if (db != null) {
        db.delete("table_name", "id IN (" + idsCSV + ")", null);
        db.close();
    }
    

提交回复
热议问题