AW: Expressions with date function

From: Peter Schröder (Peter.Schroede..reenet-ag.de)
Date: Tue Jul 24 2007 - 02:45:07 EDT

  • Next message: Aristedes Maniatis: "Re: AW: Expressions with date function"

    hi andrew,

    i am not totally clear about that, but afaik you may not use that date() function in your expression. cayenne will put the right string of a date object to your query, if you pass a date as a parameter.
    take a look at named parameter expressions: http://cayenne.apache.org/doc20/building-expressions.html

    @andrus: on http://cayenne.apache.org/doc20/expressions.html there is still a broken link to BNF expression language!

    -----Ursprüngliche Nachricht-----
    Von: Andrew Willerding [mailto:awillerdin..allistacti.com]
    Gesendet: Montag, 23. Juli 2007 20:45
    An: use..ayenne.apache.org
    Betreff: Expressions with date function

    I'm trying to execute the following equivalent sql expression with
    cayenne V2.0.3

    select * from appointments where status < 2 and group_id = 2 and
    date(dt_appointment) = '20070724'

    where the intent is to select all appointments where the date matches
    the provided date string. The underlying database is MySQL and the
    expression above provides the correct results when directly executed.

    The corresponding Appointments object contains columns named groupId
    (integer), status (integer) and dtAppointment (datetime)

    This is what I've coded...

    Date item = Calendar.getTime();
    String anExp = "groupId = " + identity +
                               " and status < 2" +
                               " and date(dtAppointment) = '" +
                        new
    SimpleDateFormat("yyyyMMdd").format(item.getTime()) + "'";
    Expression exp = Expression.fromString(anExp);
               
    SelectQuery qAppointments = new SelectQuery(Appointments.class, exp);
    List appointments = dc.performQuery(qAppointments, true);

    However I am getting the following error...

    Exception in thread "Thread-55"
    org.apache.cayenne.exp.ExpressionException: [v.2.0.2 January 14 2007]
    [v.2.0.2 January 14 2007] And: invalid child - ObjPath
            at org.apache.cayenne.exp.Expression.fromString(Expression.java:203)
            at
    com.Callista.CallResponse.Reminder.FileServerThread.parseAndImportFileData(FileServerThread.java:261)
            at
    com.Callista.CallResponse.Reminder.FileServerThread.run(FileServerThread.java:128)
    Caused by: org.apache.cayenne.exp.ExpressionException: [v.2.0.2 January
    14 2007] And: invalid child - ObjPath
            at
    org.apache.cayenne.exp.parser.AggregateConditionNode.jjtAddChild(AggregateConditionNode.java:89)
            at
    org.apache.cayenne.exp.parser.JJTExpressionParserState.closeNodeScope(JJTExpressionParserState.java:113)
            at
    org.apache.cayenne.exp.parser.ExpressionParser.andCondition(ExpressionParser.java:129)
            at
    org.apache.cayenne.exp.parser.ExpressionParser.orCondition(ExpressionParser.java:56)
            at
    org.apache.cayenne.exp.parser.ExpressionParser.expression(ExpressionParser.java:49)
            at org.apache.cayenne.exp.Expression.fromString(Expression.java:196)
            ... 2 more

    What am I doing wrong in my expression builder?

    Thanks,

    Andrew



    This archive was generated by hypermail 2.0.0 : Tue Jul 24 2007 - 02:45:08 EDT