Thread: 'current' timestamp chokes jdbc driver

'current' timestamp chokes jdbc driver

From
Joseph Shraibman
Date:
If you set a timestamp field to be 'current' as per
http://www.ca.postgresql.org/docs/postgres/datatype-datetime.html#AEN322
jdbc chokes on selecting that value:
Bad Timestamp Format at 0 in current
        at
org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java:517)
        at org.postgresql.jdbc2.ResultSet.getObject(ResultSet.java:825)

So I created this patch.  I'm not sure if this is correct though,
because maybe its the servers job to convert these.

*** ResultSet.java.orig Mon May  7 18:30:42 2001
--- ResultSet.java      Mon May  7 18:33:38 2001
***************
*** 495,501 ****
        } else if (subsecond) {
          sbuf.append('0');
        }
!
        // could optimize this a tad to remove too many object
creations...
        SimpleDateFormat df = null;

--- 495,505 ----
        } else if (subsecond) {
          sbuf.append('0');
        }
!       String string = sbuf.toString();
!       if (string.equals("current"))
!         return new Timestamp((new java.util.Date()).getTime());
!       else if (string.equals("epoch"))
!         return new Timestamp(0);
        // could optimize this a tad to remove too many object
creations...
        SimpleDateFormat df = null;

***************
*** 512,518 ****
        }

        try {
!           return new Timestamp(df.parse(sbuf.toString()).getTime());
        } catch(ParseException e) {
            throw new PSQLException("postgresql.res.badtimestamp",new
Integer(e.getErrorOffset()),s);
        }
--- 516,522 ----
        }

        try {
!           return new Timestamp(df.parse(string).getTime());
        } catch(ParseException e) {
            throw new PSQLException("postgresql.res.badtimestamp",new
Integer(e.getErrorOffset()),s);
        }
--
Joseph Shraibman
jks@selectacast.net
Increase signal to noise ratio.  http://www.targabot.com

Re: 'current' timestamp chokes jdbc driver

From
Joseph Shraibman
Date:
Tom Lane wrote:
>
> Joseph Shraibman <jks@selectacast.net> writes:
> > If you set a timestamp field to be 'current' as per
> > http://www.ca.postgresql.org/docs/postgres/datatype-datetime.html#AEN322
> > jdbc chokes on selecting that value:
>
> 'current' is deprecated and is going to go away in 7.2 anyway (that's
> why it's undocumented).  So I'm not sure it's worth hacking JDBC to
> deal with it...
>

As long as it is there jdbc should be able to handle it w/o throwing an
Exception, and the jdbc drivers are expected to connect with old
versions of the database so it makes sense to leave the handling in
there permanently (but maybe with a comment).

And 'current' *is* documented, I gave the url above.


--
Joseph Shraibman
jks@selectacast.net
Increase signal to noise ratio.  http://www.targabot.com

Re: 'current' timestamp chokes jdbc driver

From
Tom Lane
Date:
Joseph Shraibman <jks@selectacast.net> writes:
> If you set a timestamp field to be 'current' as per
> http://www.ca.postgresql.org/docs/postgres/datatype-datetime.html#AEN322
> jdbc chokes on selecting that value:

'current' is deprecated and is going to go away in 7.2 anyway (that's
why it's undocumented).  So I'm not sure it's worth hacking JDBC to
deal with it...

            regards, tom lane