-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using alias on condition combined with AND or OR fails #834
Comments
Assuming this is pseudo-code this should be correct. Can you provide a small code example that reproduces this? |
public class ObjectBoxActivity extends AppCompatActivity {
private static final String TAG = "ObjectBoxActivity";
BoxStore store;
Box<TestEntity> box;
Query<TestEntity> query;
Query<TestEntity> query2;
int size;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(TAG, "onCreate: ");
store = MyObjectBox.builder()
.androidContext(this)
.build();
boolean start = new AndroidObjectBrowser(store).start(this);
box = store.boxFor(TestEntity.class);
query = box.query().less(TestEntity_.value, 0).or().greater(TestEntity_.value, 0).build();
// query2 = box.query().less(TestEntity_.value, 0).parameterAlias("one").or().greater(TestEntity_.value, 0).parameterAlias("two") .build();
box.removeAll();
box.put(new TestEntity(9));
box.put(new TestEntity(7));
box.put(new TestEntity(6));
box.put(new TestEntity(16));
box.put(new TestEntity(13));
box.put(new TestEntity(23));
box.put(new TestEntity(26));
size = box.query().build().find().size();
Log.e(TAG, "all size: " + size);
size = query.setParameter(TestEntity_.value, 10).setParameter(TestEntity_.value, 20).find().size();
Log.e(TAG, "size: " + size);
// size = query2.setParameter("one", 10).setParameter("two", 20).find().size();
// Log.e(TAG, "size: " + size);
}
} Log
if open query2
@Entity
public class TestEntity {
@Id(assignable = false)
public long id;
private int value;
public TestEntity() {
}
public TestEntity(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
} |
Thanks, you have found a bug! Using
Workaround: use the new Query API in Example: Query<TestEntity> query = box.query(
TestEntity_.value.less(0).alias("less")
.or(TestEntity_.value.greater(0).alias("greater"))
).build(); |
When will 3.0.0 be released |
When it's done, sorry. Another workaround I forgot to mention: re-build the |
Thanks |
A fix is available with |
This fix was backported and is now also available with |
Fixed with |
I want to find (i < 10 or i > 20) list
I have tried
less(param, 0).or().greater(param, 0) then setParameter(param, 10).setParameter(param, 20)
and
less(param, 0).parameterAlias("one").or().greater(param, 0).parameterAlias("two") then setParameter("one", 10).setParameter("two", 20)
none of them work
The text was updated successfully, but these errors were encountered: