johnvdenley
johnvdenley

Reputation: 769

Google App Engine Query Execute only takes 3 arguments

Can anyone tell me why the following code is causing an error on the last line with the command "execute" with the error message:

The method execute(Object, Object, Object) in the type Query is not applicable for the arguments (Long, Long, Date, Date)

Query q = pm.newQuery(Appointment.class,"AdminID == AID"+
  " && EmployeeID == CEID"+
  " && Time > STime"+
  " && Time < ETime");
q.declareImports("import java.util.Date");
q.declareParameters("Long AID, Long CEID, Date STime, Date ETime");
q.setOrdering("Time");
Appointments = (List<Appointment>) q.execute(AdminID, CurrentEmployeeID, Time1, Time2);

As far as I can tell (implied by the error message, the execute function can only take a maximum of 3 arguements, if this is the case, can anyone advise on how to achieve what I want to do? I have tried the following code, but I get a parsing error every time it runs!

Query q = pm.newQuery(Appointment.class,"AdminID == "+AdminID+
  " && EmployeeID == "+CurrentEmployeeID+
  " && Time > "+Time1+
  " && Time < "+Time2);
q.declareImports("import java.util.Date");
q.setOrdering("Time");
Appointments = (List<Appointment>) q.execute();

The Parsing error I get is:

org.datanucleus.store.query.QueryCompilerSyntaxException: Portion of expression could not be parsed: Aug 13 11:44:55 BST 2012 && Time < Mon Aug 13 11:45:05 BST 2012

Upvotes: 1

Views: 271

Answers (1)

Nicholas Albion
Nicholas Albion

Reputation: 3284

Try executeWithArray or executeWithMap.

HashMap<String, Object> params = new HashMap<String, Object>();
params.put( "AID", adminId );
params.put( "CEID", currentEmployeeId );
params.put( "STime", startTime );
params.put( "ETime", endTime );

query.executeWithMap( params );

Notes:

  1. variables should be lowerCamelCase
  2. startTime and endTime are more descriptive than Time1, Time2
  3. "Id" is generally preferred over "ID" - What is correct Java naming convention for id?
  4. your second attempt won't work because it's implicitly calling ..." && Time > " + Time1.toString() + ...

Upvotes: 3

Related Questions