Jin Lee <jinsle..mail.com> wrote:
> Hey all,
>
> Still trying to figure out more of cayenne and was wondering if anyone
> can help answer a question about Expressions.
>
> I have this table:
>
> Table: dates
> ------------------------
> dateId
> dateBegin
> dateEnd
>
> A user enters a date (userDate) and it gets converted to a java.util.Date.
>
> I want the condition to be:
> where userDate between dateBegin and dateEnd
>
> What would be the correct Expression to handle this?
Between is probably database-dependent.
However, you can do
where userDate >= dateBegin and userDate <= dateEnd
or
where userDate > dateBegin and userDate < dateEnd
depending on whether you want between to be inclusive or exclusive.
qualifier1 = ExpressionFactory.lessOrEqualExp("dateBegin", userDate);
qualifier2 = ExpressionFactory.greaterOrEqualExp("dateEnd", userDate);
qualifier3 = qualifier1.andExp(qualifier2);
While researching this, I found that there is a BETWEEN statement, but it
doesn't seem to work on paths, only constant values.
ExpressionFactory.betweenExp(
"estimatedPrice",
new BigDecimal(10),
new BigDecimal(20)));
Maybe you could open a JIRA enhancement issue on this, although this usage
of BETWEEN may not be database-independent since it's operating on two
fields rather than one.
This archive was generated by hypermail 2.0.0 : Thu Feb 17 2005 - 09:20:54 EST