You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Marc Guillemot <mg...@yahoo.fr> on 2003/01/07 16:50:39 UTC

Re: Query on date field: pb with Criteria.addDate

Does someone use Criteria.addDate?
I'm always stuck with this problem.

Marc.

----- Original Message -----
From: "Marc Guillemot" <mg...@yahoo.fr>
To: <tu...@jakarta.apache.org>
Sent: Friday, December 20, 2002 6:31 PM
Subject: Query on date field: pb with Criteria.addDate


> Hi,
>
> I  want to perform a doSelect with a criteria on a date field.
> I've tryed
>     Criteria.addDate
> and
>     Criteria.add with a GregorianCalendar as parameter
> but in both cases I get an sql error (I use MySQL with the
> org.gjt.mm.mysql.Driver driver) because the generated sql query just
> contains the toString() representation of the GregorianCalendar:
>
> SELECT Tasks.ID, Tasks.WORKERID, Tasks.STARTDATE, Tasks.ENDDATE,
> Tasks.PAUSE, Tasks.DESCRIPTION, Tasks.COMMENT, Tasks.STATUS,
> Tasks.VALIDATORID, Tasks.VALIDATIONDATE FROM Tasks WHERE
>
Tasks.ENDDATE<=java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllF
>
ieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berli
>
n",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRu
>
le=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
>
00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDa
>
yOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,e
>
ndDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysIn
>
FirstWeek=4,ERA=1,YEAR=2002,MONTH=11,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_M
>
ONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOU
> R_OF_DAY=?,MINUTE=?,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
>
> Does Torque provide a way to perform a query with criteria on date fields?
>
> Marc.




Re: Query on date field: pb with Criteria.addDate

Posted by Peter Courcoux <pe...@courcoux.biz>.
Hi Marc,

Glad that helped.

The last time I had to do something like this I ended up writing the sql
and dealing with the village record objects directly. 

I only recently ( this week ) discovered that this approach worked and I
have not had time to examine the Criteria source in depth to see how it
is done. 

Perhaps someone with more knowledge of the code can answer the question.

I will try to look at it myself soon but it will not be this week.

Regards,

Peter


On Wed, 2003-01-08 at 08:48, Marc Guillemot wrote:
> Thanks Peter, it functions for me too with MySql on DATETIME columns.
> 
> However because of the strange way needed to add the criteria I wonder if it
> functions accidentaly or if it is really portable.
> 
> Marc.
> 
> ----- Original Message -----
> From: "Peter Courcoux" <pe...@courcoux.biz>
> Newsgroups: gmane.comp.jakarta.turbine.torque.user
> Sent: Tuesday, January 07, 2003 5:25 PM
> Subject: Re: Query on date field: pb with Criteria.addDate
> 
> 
> > Marc,
> >
> > Try criteria.add(YourtablePeer.YOURCOLUMN, (Object) date,
> > Criteria.COMPARISON)
> >
> > This works for me using postgresql where date is a java.util.Date object
> > and the column is type TIMESTAMP. I'm not sure that I have tried other
> > column types or db's.
> >
> > I hope that this helps.
> >
> >
> >
> > On Tue, 2003-01-07 at 15:50, Marc Guillemot wrote:
> > > Does someone use Criteria.addDate?
> > > I'm always stuck with this problem.
> > >
> > > Marc.
> > >
> > > ----- Original Message -----
> > > From: "Marc Guillemot" <mg...@yahoo.fr>
> > > To: <tu...@jakarta.apache.org>
> > > Sent: Friday, December 20, 2002 6:31 PM
> > > Subject: Query on date field: pb with Criteria.addDate
> > >
> > >
> > > > Hi,
> > > >
> > > > I  want to perform a doSelect with a criteria on a date field.
> > > > I've tryed
> > > >     Criteria.addDate
> > > > and
> > > >     Criteria.add with a GregorianCalendar as parameter
> > > > but in both cases I get an sql error (I use MySQL with the
> > > > org.gjt.mm.mysql.Driver driver) because the generated sql query just
> > > > contains the toString() representation of the GregorianCalendar:
> > > >
> > > > SELECT Tasks.ID, Tasks.WORKERID, Tasks.STARTDATE, Tasks.ENDDATE,
> > > > Tasks.PAUSE, Tasks.DESCRIPTION, Tasks.COMMENT, Tasks.STATUS,
> > > > Tasks.VALIDATORID, Tasks.VALIDATIONDATE FROM Tasks WHERE
> > > >
> > >
> Tasks.ENDDATE<=java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllF
> > > >
> > >
> ieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berli
> > > >
> > >
> n",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRu
> > > >
> > >
> le=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
> > > >
> > >
> 00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDa
> > > >
> > >
> yOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,e
> > > >
> > >
> ndDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysIn
> > > >
> > >
> FirstWeek=4,ERA=1,YEAR=2002,MONTH=11,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_M
> > > >
> > >
> ONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOU
> > > > R_OF_DAY=?,MINUTE=?,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
> > > >
> > > > Does Torque provide a way to perform a query with criteria on date
> fields?
> > > >
> > > > Marc.
> > >
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> > --
> > Peter Courcoux <pe...@courcoux.biz>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
Peter Courcoux <pe...@courcoux.biz>

Re: Query on date field: pb with Criteria.addDate

Posted by Marc Guillemot <ma...@amath.net>.
Thanks Peter, it functions for me too with MySql on DATETIME columns.

However because of the strange way needed to add the criteria I wonder if it
functions accidentaly or if it is really portable.

Marc.

----- Original Message -----
From: "Peter Courcoux" <pe...@courcoux.biz>
Newsgroups: gmane.comp.jakarta.turbine.torque.user
Sent: Tuesday, January 07, 2003 5:25 PM
Subject: Re: Query on date field: pb with Criteria.addDate


> Marc,
>
> Try criteria.add(YourtablePeer.YOURCOLUMN, (Object) date,
> Criteria.COMPARISON)
>
> This works for me using postgresql where date is a java.util.Date object
> and the column is type TIMESTAMP. I'm not sure that I have tried other
> column types or db's.
>
> I hope that this helps.
>
> Peter
>
>
>
> On Tue, 2003-01-07 at 15:50, Marc Guillemot wrote:
> > Does someone use Criteria.addDate?
> > I'm always stuck with this problem.
> >
> > Marc.
> >
> > ----- Original Message -----
> > From: "Marc Guillemot" <mg...@yahoo.fr>
> > To: <tu...@jakarta.apache.org>
> > Sent: Friday, December 20, 2002 6:31 PM
> > Subject: Query on date field: pb with Criteria.addDate
> >
> >
> > > Hi,
> > >
> > > I  want to perform a doSelect with a criteria on a date field.
> > > I've tryed
> > >     Criteria.addDate
> > > and
> > >     Criteria.add with a GregorianCalendar as parameter
> > > but in both cases I get an sql error (I use MySQL with the
> > > org.gjt.mm.mysql.Driver driver) because the generated sql query just
> > > contains the toString() representation of the GregorianCalendar:
> > >
> > > SELECT Tasks.ID, Tasks.WORKERID, Tasks.STARTDATE, Tasks.ENDDATE,
> > > Tasks.PAUSE, Tasks.DESCRIPTION, Tasks.COMMENT, Tasks.STATUS,
> > > Tasks.VALIDATORID, Tasks.VALIDATIONDATE FROM Tasks WHERE
> > >
> >
Tasks.ENDDATE<=java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllF
> > >
> >
ieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berli
> > >
> >
n",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRu
> > >
> >
le=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
> > >
> >
00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDa
> > >
> >
yOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,e
> > >
> >
ndDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysIn
> > >
> >
FirstWeek=4,ERA=1,YEAR=2002,MONTH=11,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_M
> > >
> >
ONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOU
> > > R_OF_DAY=?,MINUTE=?,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
> > >
> > > Does Torque provide a way to perform a query with criteria on date
fields?
> > >
> > > Marc.
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> --
> Peter Courcoux <pe...@courcoux.biz>


Re: Query on date field: pb with Criteria.addDate

Posted by Peter Courcoux <pe...@courcoux.biz>.
Marc,

Try criteria.add(YourtablePeer.YOURCOLUMN, (Object) date,
Criteria.COMPARISON)

This works for me using postgresql where date is a java.util.Date object
and the column is type TIMESTAMP. I'm not sure that I have tried other
column types or db's.

I hope that this helps.

Peter



On Tue, 2003-01-07 at 15:50, Marc Guillemot wrote:
> Does someone use Criteria.addDate?
> I'm always stuck with this problem.
> 
> Marc.
> 
> ----- Original Message -----
> From: "Marc Guillemot" <mg...@yahoo.fr>
> To: <tu...@jakarta.apache.org>
> Sent: Friday, December 20, 2002 6:31 PM
> Subject: Query on date field: pb with Criteria.addDate
> 
> 
> > Hi,
> >
> > I  want to perform a doSelect with a criteria on a date field.
> > I've tryed
> >     Criteria.addDate
> > and
> >     Criteria.add with a GregorianCalendar as parameter
> > but in both cases I get an sql error (I use MySQL with the
> > org.gjt.mm.mysql.Driver driver) because the generated sql query just
> > contains the toString() representation of the GregorianCalendar:
> >
> > SELECT Tasks.ID, Tasks.WORKERID, Tasks.STARTDATE, Tasks.ENDDATE,
> > Tasks.PAUSE, Tasks.DESCRIPTION, Tasks.COMMENT, Tasks.STATUS,
> > Tasks.VALIDATORID, Tasks.VALIDATIONDATE FROM Tasks WHERE
> >
> Tasks.ENDDATE<=java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllF
> >
> ieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berli
> >
> n",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRu
> >
> le=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=36000
> >
> 00,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDa
> >
> yOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,e
> >
> ndDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysIn
> >
> FirstWeek=4,ERA=1,YEAR=2002,MONTH=11,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_M
> >
> ONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOU
> > R_OF_DAY=?,MINUTE=?,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
> >
> > Does Torque provide a way to perform a query with criteria on date fields?
> >
> > Marc.
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
Peter Courcoux <pe...@courcoux.biz>