我正在使用SugarORM。
选择代码:
String action = "date_int ASC";
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("A")).orderBy(action).list();
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("B")).orderBy(action).list();问题:
上面得到的列表要么是A类,要么是B。
从官方网站上只能生成和条件的A和B如下:
record_list = Select.from(Records_records.class).where(Condition.prop("category").eq("A"), Condition.prop("category").eq("B")).orderBy(action).list();我如何才能得到一个与(A或B)和按"date_int ASC“顺序排列的类别的组合列表?
谢谢!
发布于 2017-10-11 15:00:08
您可以为此使用whereOr():
record_list = Select.from(Records_records.class).whereOr(Condition.prop("category").eq("A"), Condition.prop("category").eq("B")).orderBy(action).list();它是缺省值和where()使用的OR对应项。
它没有文档化,但是您可以在来源中找到它
@Test
public void testWhereOr(){
Select where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"));
assertEquals("(test = ? )", where.getWhereCond());
assertEquals(1, where.getArgs().length);
assertEquals("satya", where.getArgs()[0]);
where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2));
assertEquals("(test = ? OR prop = ? )", where.getWhereCond());
assertEquals(2, where.getArgs().length);
assertEquals("satya", where.getArgs()[0]);
assertEquals("2", where.getArgs()[1]);
}https://stackoverflow.com/questions/46627223
复制相似问题