Expressions with date function

From: Andrew Willerding (awillerdin..allistacti.com)
Date: Mon Jul 23 2007 - 14:45:07 EDT

  • Next message: Peter Schröder: "AW: 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 : Mon Jul 23 2007 - 14:52:29 EDT