Hi Ivan,

generally if you want two constraints on the same column you must combine them 
with an AND or OR operator.
e.g.
cmd.where(EMP.LASTNAME.like("%foo%").and(EMP.LASTNAME.isNot("fool")));
or:
cmd.where(EMP.LASTNAME.like("%foo%").or(EMP.LASTNAME.is("master")));

The behavior to replace an existing constraint is by design.

IMO the behavior when providing a list of constraints is also OK, although one 
can argue that the behavior should be the same.

But your other issue when providing an empty list is certainly a bug.
I will fix it immediately.

Regards
Rainer


from: Ivan Nemeth [mailto:[email protected]]
to: user
re: Constraint on the same column

Hi,

another issue with constraints.

you can't add two constraint on the same column with 
DBCommand.where(DBCommandExpr expr) method. The documentation says

"If another restriction already exists for the same column it will be replaced."

So if I want to query persons who's name starts with "A" but is not "Adam", I 
can do the following:

cmd.select(TABLE.getColumns());
cmd.where(TABLE.NAME.like("A%"));
cmd.where(TABLE.NAME.isNot("Adam"));

Due to the above mentioned restriction this won't work because the first 
constraint will be dropped away, and I'll get ALL persons except Adam.

But if I use constraint list it's OK:

cmd.select(TABLE.getColumns());
List wheres = new ArrayList();
wheres.add(TABLE.NAME.like("A%"));
wheres.add(TABLE.NAME.isNot("Adam"));
cmd.addWhereConstraints(wheres);


Thanks,
Ivan



Reply via email to