Re: Comparing two Dates in cayenne

From: Dhruti Ramani (dhrutiraman..ahoo.com)
Date: Tue Apr 26 2005 - 16:38:49 EDT

  • Next message: Sami Mohammed: "Multiple Database"

    Thank you for replying. But what if I have to use AND in query. For example If i have to find all the deals for specific broker and dates between start and end date. How would I do that?
     
    Thanks,
    Denna

    Andrus Adamchik <andru..bjectstyle.org> wrote:
    Hi Denna,

    Generally you shouldn't attempt to include the dates into expression
    strings. This doesn't translate nicely into JDBC calls. Instead I
    suggest using ExpressionFactory passing it Date objects. E.g.:

    Expression e = ExpressionFactory.betweenExp(dateIn, d1, d2);

    This results in Cayenne passing d1 and d2 Date objects (not strings!)
    to the JDBC driver, thus hiding the details of date conversion to the
    right format for PostgreSQL.

    Andrus

    On Apr 25, 2005, at 5:48 PM, Dhruti Ramani wrote:
    > Hi,
    >
    > I am using cayenne1.1 and postgresql7.* for as database. I have to get
    > all the rows from Deal table which has value of field "dateIn"(Date)
    > between startDate and endDate. The code I have used is this,
    >
    > DateFormat df=DateFormat.getDateInstance(DateFormate.SHORT);
    > Date d1=df.parse(startDate);
    > Date d2=df.parse(endDate);
    > // to get in this format ::: query=dateIn > 'startDate' and dateIn <
    > 'endDate'
    > query="dateIn "+" > "+"'"+startDate+"'"+" and "+"dateIn"+" <
    > "+"'"+endDate+"'";
    > Expression e=Expression.fromString(query);
    > SeleceQuery q=new SelectQuery(Deal.class,e);
    > List alist=dataContext.performQuery(q);
    >
    > But this returns the empty list even if the dataIn value is between
    > the specified range. If I use the same SQL format directly into
    > postgersql it returns the value.
    >
    > Am I doing something wrong?
    >
    > Thanks,
    > Denna

    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com



    This archive was generated by hypermail 2.0.0 : Tue Apr 26 2005 - 16:38:51 EDT