cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Willerding <awillerd...@callistacti.com>
Subject Expressions with date function
Date Mon, 23 Jul 2007 18:45:07 GMT
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




Mime
View raw message