You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Fedor Karpelevitch <fe...@Barra.COM> on 2001/09/05 17:56:36 UTC

RE: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/uti l/db SqlExpression.java

> -----Original Message-----
> From: John McNally [mailto:jmcnally@collab.net]
> Sent: Tuesday, September 04, 2001 1:59 PM
> To: turbine-dev@jakarta.apache.org
> Subject: Re: cvs commit:
> jakarta-turbine-2/src/java/org/apache/turbine/util/db 
> SqlExpression.java
> 
> 
> fedor@apache.org wrote:
> > 
> <snip>
> > 
> > 
> >   1.2       +4 -2      
> jakarta-turbine-2/src/java/org/apache/turbine/util/db/SqlExpre
> ssion.java
> > 
> >   Index: SqlExpression.java
> >   
> ===================================================================
> >   RCS file: 
> /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/d
> b/SqlExpression.java,v
> >   retrieving revision 1.1
> >   retrieving revision 1.2
> >   diff -u -r1.1 -r1.2
> >   --- SqlExpression.java        2001/08/16 05:09:49     1.1
> >   +++ SqlExpression.java        2001/09/01 08:37:14     1.2
> >   @@ -59,6 +59,7 @@
> >    import java.util.Date;
> >    import java.util.Iterator;
> >    import java.util.List;
> >   +import java.sql.Timestamp;
> > 
> >    import org.apache.turbine.om.DateKey;
> >    import org.apache.turbine.om.ObjectKey;
> >   @@ -79,7 +80,7 @@
> >     *
> >     * @author <a 
> href="mailto:john.mcnally@clearink.com">John D. McNally</a>
> >     * @author <a 
> href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
> >   - * @version $Id: SqlExpression.java,v 1.1 2001/08/16 
> 05:09:49 jvanzyl Exp $
> >   + * @version $Id: SqlExpression.java,v 1.2 2001/09/01 
> 08:37:14 fedor Exp $
> >     */
> >    public class SqlExpression
> >    {
> >   @@ -290,7 +291,8 @@
> >               else if( criteria instanceof java.util.Date ||
> >                        criteria instanceof DateKey)
> >               {
> >   -               criteria = db.getDateString(criteria.toString());
> >   +               Date dt = criteria instanceof Date?(Date) 
> criteria:((DateKey)criteria).getDate();
> >   +               criteria = "{ts '" + new 
> Timestamp(dt.getTime()).toString() + "'}";
> >               }
> >               else if( criteria instanceof Boolean )
> >               {
> > 
> > 
> 
> This will cause a loss of precision, if criteria is a Timestamp the
> getTime() method only returns integral seconds.  

_milliseconds_ - should be enough. And if you are eventually converting to
Date you will lose nanos anyway.

> 
> I have a question/reservation about the jdbc escape.  If the 
> column is a
> date column of some type other than timestamp, is the driver 
> expected to
> parse the jdbc escape properly?  It seems conceivable that it may just
> throw an exception.

not sure about this, but so far this is the best solution I know about...

fedor.

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util/db SqlExpression.java

Posted by John McNally <jm...@collab.net>.
Fedor Karpelevitch wrote:
> 
> > -----Original Message-----
> > From: John McNally [mailto:jmcnally@collab.net]
> > Sent: Tuesday, September 04, 2001 1:59 PM
> > To: turbine-dev@jakarta.apache.org
> > Subject: Re: cvs commit:
> > jakarta-turbine-2/src/java/org/apache/turbine/util/db
> > SqlExpression.java
> >
> >
> > fedor@apache.org wrote:
> > >
> > <snip>
> > >
> > >
> > >   1.2       +4 -2
> > jakarta-turbine-2/src/java/org/apache/turbine/util/db/SqlExpre
> > ssion.java
> > >
> > >   Index: SqlExpression.java
> > >
> > ===================================================================
> > >   RCS file:
> > /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/d
> > b/SqlExpression.java,v
> > >   retrieving revision 1.1
> > >   retrieving revision 1.2
> > >   diff -u -r1.1 -r1.2
> > >   --- SqlExpression.java        2001/08/16 05:09:49     1.1
> > >   +++ SqlExpression.java        2001/09/01 08:37:14     1.2
> > >   @@ -59,6 +59,7 @@
> > >    import java.util.Date;
> > >    import java.util.Iterator;
> > >    import java.util.List;
> > >   +import java.sql.Timestamp;
> > >
> > >    import org.apache.turbine.om.DateKey;
> > >    import org.apache.turbine.om.ObjectKey;
> > >   @@ -79,7 +80,7 @@
> > >     *
> > >     * @author <a
> > href="mailto:john.mcnally@clearink.com">John D. McNally</a>
> > >     * @author <a
> > href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
> > >   - * @version $Id: SqlExpression.java,v 1.1 2001/08/16
> > 05:09:49 jvanzyl Exp $
> > >   + * @version $Id: SqlExpression.java,v 1.2 2001/09/01
> > 08:37:14 fedor Exp $
> > >     */
> > >    public class SqlExpression
> > >    {
> > >   @@ -290,7 +291,8 @@
> > >               else if( criteria instanceof java.util.Date ||
> > >                        criteria instanceof DateKey)
> > >               {
> > >   -               criteria = db.getDateString(criteria.toString());
> > >   +               Date dt = criteria instanceof Date?(Date)
> > criteria:((DateKey)criteria).getDate();
> > >   +               criteria = "{ts '" + new
> > Timestamp(dt.getTime()).toString() + "'}";
> > >               }
> > >               else if( criteria instanceof Boolean )
> > >               {
> > >
> > >
> >
> > This will cause a loss of precision, if criteria is a Timestamp the
> > getTime() method only returns integral seconds.
> 
> _milliseconds_ - should be enough. And if you are eventually converting to
> Date you will lose nanos anyway.
> 

I am pretty sure you lose the millis as well that is what I am trying to
avoid.

The millis are not stored as part of the long in a Timestamp

d = new java.util.Date(1234);
timestamp = new Timestamp(d.getTime())

timestamp.getTime() = 1000
timestamp.getNanos() = 234000000

> >
> > I have a question/reservation about the jdbc escape.  If the
> > column is a
> > date column of some type other than timestamp, is the driver
> > expected to
> > parse the jdbc escape properly?  It seems conceivable that it may just
> > throw an exception.
> 
> not sure about this, but so far this is the best solution I know about...
> 

The DB adapters are not such a bad method considering they already
exist.  But if there are no problems with the escape, then the default
adapter method will just cover all cases.

john mcnally

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org