'current' timestamp chokes jdbc driver

From: Joseph Shraibman <jks(at)selectacast(dot)net>
To: "'pgsql-jdbc(at)postgresql(dot)org'" <pgsql-jdbc(at)postgresql(dot)org>
Subject: 'current' timestamp chokes jdbc driver
Date: 2001-05-07 22:43:19
Message-ID: 3AF72507.9E9DED36@selectacast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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(at)selectacast(dot)net
Increase signal to noise ratio. http://www.targabot.com

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2001-05-07 23:51:28 Re: 'current' timestamp chokes jdbc driver
Previous Message Joseph Shraibman 2001-05-07 20:43:29 Re: Updateable ResultSet