1

i wanto get the trip which is happened between contractStartdate and contractEndDate+1day. but this following code gives me error.

def tripsForThisContract =  Trip.executeQuery("From Trip where contract_id = ? AND startDate between ? AND DATE_ADD('?',INTERVAL 1 DAY)",[contractId,contractStarts,contractEnds])

please help me.

maaz
  • 3,534
  • 19
  • 61
  • 100
  • Can you show the error and the generated query ? – Teneff Jun 11 '11 at 08:48
  • [2011-06-11 14:08:59:937] ERROR org.hibernate.hql.PARSER ### line 1:112: unexpected token: 1 [2011-06-11 14:08:59:953] ERROR groovy.grails.web.errors.GrailsExceptionResolver ### unexpected token: 1 near line 1, column 112 [From com.springpeople.steer.trips.Trip where contract_id = ? AND startDate between ? AND DATE_ADD('?',INTERVAL 1 DAY)] org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 1 near line 1, column 112 [From com.springpeople.steer.trips.Trip where contract_id = ? AND startDate between ? AND DATE_ADD('?',INTERVAL 1 DAY)] at $Proxy12.createQuery(Unknown Source) – maaz Jun 11 '11 at 08:50

1 Answers1

3

You should deal with the date inside your code. Hql has not all the functions of the underlying database.

Your code should be something like this :

Trip.executeQuery(
"From Trip where contract_id = ? AND startDate between ? AND ?)"
,[contractId,contractStarts, ++contractStarts])
Dónal
  • 185,044
  • 174
  • 569
  • 824
GaetanZ
  • 2,819
  • 3
  • 21
  • 20