pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: [INTERFACES] JDBC, Timestamps, and DateStyle
4+ messages / 3 participants
[nested] [flat]
* Re: [INTERFACES] JDBC, Timestamps, and DateStyle
@ 1998-10-27 10:55 Peter T Mount <peter@taer.maidstone.gov.uk>
parent: Aleksey Demakov <avd@gcom.ru>
0 siblings, 1 reply; 4+ messages in thread
From: Peter T Mount @ 1998-10-27 10:55 UTC (permalink / raw)
To: Aleksey Demakov <avd@gcom.ru>; +Cc: pgsql-interfaces@postgresql.org, Peter T Mount <peter@retep.org.uk>
On 27 Oct 1998, Aleksey Demakov wrote:
>
> I had problems reading datetime fields with the ResultSet.getTimestamp
> method. First, it looks like this method always assumes that DateStyle
> is ISO. At the same time the driver checks current DateStyle in the case
> of Dates and acts accordingly. IMHO, it's a bit incosistent.
>
> As I recall the ODBC driver has no such problems because it always uses
> the same format for communication with backend. It sets it when it opens
> a connection.
I had thought of doing the same, but ran out of time (other things forced
me away for a while)...
> But it is not my main problem since I can set DateStyle by myself.
>
> The other problem is that the driver simetimes fails to parse timestamps.
> I found two reasons for this. The first is that the timestamp can contain
> fractions of second. The second relates to timezones. I don't quite
> understand it, though. I simply rewrote the code so it works for me. And
> I believe it should also work for others.
>
> The patch is below.
I'll take a look at it when I get home.
[patch snipped]
Peter
^ permalink raw reply [nested|flat] 4+ messages in thread
* JDBC, Timestamps, and DateStyle
@ 1998-10-27 11:51 Aleksey Demakov <avd@gcom.ru>
0 siblings, 1 reply; 4+ messages in thread
From: Aleksey Demakov @ 1998-10-27 11:51 UTC (permalink / raw)
To: pgsql-interfaces; +Cc: Peter T Mount <peter@retep.org.uk>
I had problems reading datetime fields with the ResultSet.getTimestamp
method. First, it looks like this method always assumes that DateStyle
is ISO. At the same time the driver checks current DateStyle in the case
of Dates and acts accordingly. IMHO, it's a bit incosistent.
As I recall the ODBC driver has no such problems because it always uses
the same format for communication with backend. It sets it when it opens
a connection.
But it is not my main problem since I can set DateStyle by myself.
The other problem is that the driver simetimes fails to parse timestamps.
I found two reasons for this. The first is that the timestamp can contain
fractions of second. The second relates to timezones. I don't quite
understand it, though. I simply rewrote the code so it works for me. And
I believe it should also work for others.
The patch is below.
Aleksey
inline patch 1: ResultSet.java (+22/-8 lines) download inline-1.patch
*** ResultSet.java.old Thu Sep 3 14:00:49 1998
--- ResultSet.java Tue Oct 27 16:21:53 1998
***************
*** 448,463 ****
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
! SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
!
if (s != null)
{
! int TZ = new Float(s.substring(19)).intValue();
! TZ = TZ * 60 * 60 * 1000;
! TimeZone zone = TimeZone.getDefault();
! zone.setRawOffset(TZ);
! String nm = zone.getID();
! s = s.substring(0,18) + nm;
try {
java.util.Date d = df.parse(s);
return new Timestamp(d.getTime());
--- 448,477 ----
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
! SimpleDateFormat df;
if (s != null)
{
! int i = 19;
! if (s.charAt(i) == '.')
! {
! i++;
! while(Character.isDigit(s.charAt(i)))
! i++;
! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSzzz");
! }
! else
! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
!
! int TZ = new Float(s.substring(i)).intValue();
! String sign;
! if (TZ < 0)
! {
! sign = "-";
! TZ = -TZ;
! }
! else
! sign = "+";
! s = s.substring(0,i) + "GMT" + sign + TZ/10 + TZ%10 + ":00";
try {
java.util.Date d = df.parse(s);
return new Timestamp(d.getTime());
--
Aleksey Demakov
avd@gcom.ru
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [INTERFACES] JDBC, Timestamps, and DateStyle
@ 1998-10-27 15:02 Thomas G. Lockhart <lockhart@alumni.caltech.edu>
parent: Peter T Mount <peter@taer.maidstone.gov.uk>
0 siblings, 1 reply; 4+ messages in thread
From: Thomas G. Lockhart @ 1998-10-27 15:02 UTC (permalink / raw)
To: Peter T Mount <peter@taer.maidstone.gov.uk>; Aleksey Demakov <avd@gcom.ru>; +Cc: pgsql-interfaces@postgreSQL.org, Peter T Mount <peter@retep.org.uk>
> > But it is not my main problem since I can set DateStyle by myself.
> > The other problem is that the driver simetimes fails to parse
> > timestamps.
> > ... The timestamp can contain fractions of second.
If this is the actual Postgres timestamp data type, it should not be
showing fractional seconds afaik. It would be good to be able to handle
that, since sometime soon it will become more like the datetime type,
but at the moment it is implemented as a "seconds from 1970" integer. So
the code which decides whether or not to print fractions should never
see a fraction to print...
Also, afaik timestamp always prints in the "ISO-8601" format as a
feature from the original implementer. I think he was wanting some M$
interoperability. I kept that convention when I rewrote the I/O for the
data type, but I'm not sure if it is desirable in the long run.
Are you _sure_ you are talking about the timestamp type??
- Tom
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [INTERFACES] JDBC, Timestamps, and DateStyle
@ 1998-10-27 16:51 Aleksey Demakov <avd@gcom.ru>
parent: Thomas G. Lockhart <lockhart@alumni.caltech.edu>
0 siblings, 0 replies; 4+ messages in thread
From: Aleksey Demakov @ 1998-10-27 16:51 UTC (permalink / raw)
To: Thomas G. Lockhart <lockhart@alumni.caltech.edu>; +Cc: pgsql-interfaces@postgreSQL.org, "Peter T Mount" <peter@retep.org.uk>
"Thomas G. Lockhart" <lockhart@alumni.caltech.edu> writes:
> Are you _sure_ you are talking about the timestamp type??
Yes. I'm sure I'm talking about _JDBC's_ Timestamp type. As for
Postgres it's datetime type.
Aleksey
--
Aleksey Demakov
avd@gcom.ru
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1998-10-27 16:51 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-10-27 11:51 JDBC, Timestamps, and DateStyle Aleksey Demakov <avd@gcom.ru>
1998-10-27 10:55 ` Peter T Mount <peter@taer.maidstone.gov.uk>
1998-10-27 15:02 ` Thomas G. Lockhart <lockhart@alumni.caltech.edu>
1998-10-27 16:51 ` Aleksey Demakov <avd@gcom.ru>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox