2015-06-28 21 views
1

SQL的病情,我想執行這樣的SQL語句:在糖ORM

SELECT * FROM arr1 WHERE name IN ('arg1', 'arg2', 'arg3'); 
在SugarORM

,但我不知道如何聲明,使用這個庫。文檔非常適中。我不想使用OR可能很長的args列表。

回答

0

您可以使用基本的查找方法。假設ARR1是你的對象模型的名稱:

Arr1.find(Arr1.class," name IN(?,?,?) ",param1, param2, param3); 
0

您可以使用此代碼

public static List<Product> findByIdList(List<String> idList) { 
    StringBuffer queryString = new StringBuffer("id IN ("); 

    for (int i = 0; i < idList.size(); i++) { 
     queryString.append("?").append(i == idList.size() - 1 ? ")" : ","); 
    } 

    List<Product> products = Product.find(Product.class, queryString.toString(), idList.toArray(new String[idList.size()])); 
    return products; 
}