如何从Android SQLite查询的dymanic ArrayList中编写WHERE IN子句

前端之家收集整理的这篇文章主要介绍了如何从Android SQLite查询的dymanic ArrayList中编写WHERE IN子句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在 Android sqlite查询中编写where in子句?

检索单个客户的功能

public Cursor getCustomers(int groupId) {
    return db.query(TABLE_CUSTOMERS,new String[] { KEY_CUSTOMER_ID,KEY_NAME},KEY_GROUP_ID+" = "+groupId,null,null);
}

功能检索更多客户

public Cursor getCustomers(ArrayList<Integer> groupIds) {
    // Need to apply SELECT id,name FROM customers WHERE id IN (11,13,...18);
    //return db.query(TABLE_CUSTOMERS,KEY_GROUP_ID+" = "+groupIds,null);
}

groupId ArrayList的大小是动态的.

解决方法

return db.query(TABLE_CUSTOMERS,KEY_NAME },KEY_GROUP_ID + " >=" + groupIdsLowLimit + " and " + KEY_GROUP_ID + " <=" + groupIdsUpLimit,null);

String where = "";
for (int i = 0; i < list.size(); i++) {
    where = where + KEY_GROUP_ID + " =" + list.get(i).toString() + "";
    if (i != (list.size() - 1))
        where = where + " or";
}

return db.query(TABLE_CUSTOMERS,where,null);
原文链接:https://www.f2er.com/android/314304.html

猜你在找的Android相关文章