我在执行此类查询时因java.lang.UnsupportedOperationException: Syntax error
而崩溃:
public RealmResults<MyObject> getMyObjects(List<Integer> ids, boolean filter) {
Realm realm = null;
try {
realm = Realm.getDefaultInstance();
RealmQuery<MyObject> query = realm.where(MyObject.class);
query = query.beginGroup();
for (int i=0; i< ids.size(); i++) {
query = query.equalTo("id", ids.get(i));
if (i != ids.size() -1) {
query = query.or();
}
}
query = query.endGroup();
if (filter) {
query = query.equalTo("someBoolean", true);
}
return query.findAll();
} finally {
if (realm != null) realm.close();
}
}
删除query = query.beginGroup();
和query = query.endGroup();
会导致语法错误消失,但我不确定查询是否会产生相同的结果。
有人可以帮我指出语法错误的位置及其发生的原因吗?