pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed[BUG?] Extreme dates
11+ messages / 4 participants
[nested] [flat]
* [BUG?] Extreme dates
@ 2004-05-16 15:02 ow <oneway_111@yahoo.com>
0 siblings, 2 replies; 11+ messages in thread
From: ow @ 2004-05-16 15:02 UTC (permalink / raw)
To: pgsql-jdbc
pg 7.4.2
pgjdbc driver version 213
Hi,
1) It appears that when saving 10/30/0002 (yes, 0002), the jdbc driver saves it
as 02/11/2030.
2) May I suggest including version of the jdbc driver in the jar's
META-INF/MANIFEST.MF file? Jars get renamed, etc but manifest always stays the
same. There's Ant task for populating manifest properties.
Thanks
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-16 20:21 Kris Jurka <books@ejurka.com>
parent: ow <oneway_111@yahoo.com>
1 sibling, 0 replies; 11+ messages in thread
From: Kris Jurka @ 2004-05-16 20:21 UTC (permalink / raw)
To: ow <oneway_111@yahoo.com>; +Cc: pgsql-jdbc
On Sun, 16 May 2004, ow wrote:
> pg 7.4.2
> pgjdbc driver version 213
>
> Hi,
>
> 1) It appears that when saving 10/30/0002 (yes, 0002), the jdbc driver
> saves it as 02/11/2030.
I've tried to duplicate this and have failed. It does appear that Java is
doing something strange with the date, changing it to 11/30/0002, but I
don't understand why, and that has nothing to do with the JDBC driver or
the database. How are you constructing the date value to insert? Please
try the attached test and see what changes are necessary to get the
failure you describe.
>
> 2) May I suggest including version of the jdbc driver in the jar's
> META-INF/MANIFEST.MF file? Jars get renamed, etc but manifest always
> stays the same. There's Ant task for populating manifest properties.
>
The seems like a reasonable thing to do. You can currently determine the
version info from a randomly named pg jdbc jar file by using
org.postgresql.Driver.getVersion(), but that essentially requires writing
a dummy program to do so.
Kris Jurka
Attachments:
DateTest.java (text/plain, 884B) download
import java.sql.*;
import java.util.*;
public class DateTest {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka","");
Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE TEMP TABLE tt (a date)");
stmt.close();
Calendar cal = Calendar.getInstance();
cal.set(2, 10, 30);
java.sql.Date d = new java.sql.Date(cal.getTimeInMillis());
System.out.println("Inserting: " + d);
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tt VALUES (?)");
pstmt.setDate(1,d);
pstmt.executeUpdate();
pstmt.close();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tt");
while (rs.next()) {
System.out.println(rs.getDate(1));
}
}
}
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-17 11:41 Waldomiro <wmiro@ig.com.br>
parent: ow <oneway_111@yahoo.com>
1 sibling, 0 replies; 11+ messages in thread
From: Waldomiro @ 2004-05-17 11:41 UTC (permalink / raw)
To: ow <oneway_111@yahoo.com>; pgsql-jdbc
Save that date as Char
----- Original Message -----
From: "ow" <oneway_111@yahoo.com>
To: <pgsql-jdbc@postgresql.org>
Sent: Sunday, May 16, 2004 12:02 PM
Subject: [JDBC] [BUG?] Extreme dates
> pg 7.4.2
> pgjdbc driver version 213
>
> Hi,
>
> 1) It appears that when saving 10/30/0002 (yes, 0002), the jdbc driver
saves it
> as 02/11/2030.
>
> 2) May I suggest including version of the jdbc driver in the jar's
> META-INF/MANIFEST.MF file? Jars get renamed, etc but manifest always stays
the
> same. There's Ant task for populating manifest properties.
>
> Thanks
>
>
>
>
>
>
>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! - Internet access at a great low price.
> http://promo.yahoo.com/sbc/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>
^ permalink raw reply [nested|flat] 11+ messages in thread
* [BUG?] Extreme dates
@ 2004-05-17 18:17 ow <oneway_111@yahoo.com>
0 siblings, 1 reply; 11+ messages in thread
From: ow @ 2004-05-17 18:17 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: books@ejurka.com
Hi,
> I've tried to duplicate this and have failed. It does appear that Java is
> doing something strange with the date, changing it to 11/30/0002,
Probably because months start with 0.
> Please try the attached test and see what changes are necessary to get the
> failure you describe.
The following test illustrates the issue. The output I get is:
Row number= 0 col 1= 2030-02-11 14:06:00.828 col 2=2004-05-17 14:06:00.828
public void testKillMe() throws Exception {
//--------------- cut here
Class.forName("org.postgresql.Driver");
Connection conn =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/rc","testuser","");
Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE TEMP TABLE tt (aMin timestamp, aMax timestamp)");
stmt.close();
Calendar cal = Calendar.getInstance();
cal.set(2, 10, 30);
// cal.set(0, 0, 0);
java.sql.Date d = new java.sql.Date(cal.getTimeInMillis());
System.out.println("Inserting: " + d);
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tt VALUES (?,
?)");
pstmt.setTimestamp(1, new java.sql.Timestamp(d.getTime()));
pstmt.setTimestamp(2, new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.executeUpdate();
pstmt.close();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tt");
int i = 0;
while (rs.next()) {
System.out.println("Row number = " + i + " col 1= " + rs.getTimestamp(1) + "
col 2=" + rs.getTimestamp(2));
i++;
}
//--------------- cut here
}
Thanks
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-17 20:45 Kris Jurka <books@ejurka.com>
parent: ow <oneway_111@yahoo.com>
0 siblings, 2 replies; 11+ messages in thread
From: Kris Jurka @ 2004-05-17 20:45 UTC (permalink / raw)
To: ow <oneway_111@yahoo.com>; +Cc: pgsql-jdbc
On Mon, 17 May 2004, ow wrote:
> [timestamps like 0002-10-30 are incorrectly seen as 2030-02-10].
Yes, that's a bug alright. I've fixed this in both the stable and
development cvs trees. While looking at this I noticed that the timestamp
code has no provisions for BC dates, so if you're working with years in
that area, that's something to be aware of. Fixing that has gone on the
todo list, but I wanted to get this fix out to you now.
Kris Jurka
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-18 00:34 ow <oneway_111@yahoo.com>
parent: Kris Jurka <books@ejurka.com>
1 sibling, 1 reply; 11+ messages in thread
From: ow @ 2004-05-18 00:34 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: books@ejurka.com
--- Kris Jurka <books@ejurka.com> wrote:
>
> [timestamps like 0002-10-30 are incorrectly seen as 2030-02-10].
...
> Fixing that has gone on the todo list, but I wanted to get this fix out to
> you now.
Is it going to be a new build posted to the website or should I get it from
CVS?
Thanks!
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-18 01:26 Kris Jurka <books@ejurka.com>
parent: ow <oneway_111@yahoo.com>
0 siblings, 1 reply; 11+ messages in thread
From: Kris Jurka @ 2004-05-18 01:26 UTC (permalink / raw)
To: ow <oneway_111@yahoo.com>; +Cc: pgsql-jdbc
On Mon, 17 May 2004, ow wrote:
>
> --- Kris Jurka <books@ejurka.com> wrote:
> >
> > [timestamps like 0002-10-30 are incorrectly seen as 2030-02-10].
> ...
> > Fixing that has gone on the todo list, but I wanted to get this fix out to
> > you now.
>
> Is it going to be a new build posted to the website or should I get it from
> CVS?
>
I don't have access to the jdbc website, currently only Dave or Barry can
post new builds. I will usually post new builds to
http://www.ejurka.com/pgsql/jars every so often because the main website
doesn't get much in the way of updates. This isn't ideal for a number of
reasons:
1) The public website should be up to date.
2) No one knows about http://www.ejurka.com/pgsql/jars
3) I don't bump the official build number when putting up these
intermediate builds so people can have jar files with the same build
number and different code.
I'll start bothering people again about letting me update the website...
Kris Jurka
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-18 20:02 ow <oneway_111@yahoo.com>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 11+ messages in thread
From: ow @ 2004-05-18 20:02 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
--- Kris Jurka <books@ejurka.com> wrote:
> I don't have access to the jdbc website, currently only Dave or Barry can
> post new builds. I will usually post new builds to
> http://www.ejurka.com/pgsql/jars every so often because the main website
> doesn't get much in the way of updates.
Hi,
I tried the jar, it appears that *occasionally* it saves null date as
0002-12-31 (not 100% sure about that, maybe an app error). It also appears
there're some debugging printlns inside.
Anyway, thanks!
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-18 20:24 Kris Jurka <books@ejurka.com>
parent: ow <oneway_111@yahoo.com>
0 siblings, 1 reply; 11+ messages in thread
From: Kris Jurka @ 2004-05-18 20:24 UTC (permalink / raw)
To: ow <oneway_111@yahoo.com>; +Cc: pgsql-jdbc
On Tue, 18 May 2004, ow wrote:
>
> --- Kris Jurka <books@ejurka.com> wrote:
> > I don't have access to the jdbc website, currently only Dave or Barry can
> > post new builds. I will usually post new builds to
> > http://www.ejurka.com/pgsql/jars every so often because the main website
> > doesn't get much in the way of updates.
>
> Hi,
>
> I tried the jar, it appears that *occasionally* it saves null date as
> 0002-12-31 (not 100% sure about that, maybe an app error). It also appears
> there're some debugging printlns inside.
>
Please recheck your own code for both of these problems. I don't believe
the driver is doing either of these.
Kris Jurka
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-19 13:50 Markus Schaber <schabios@logi-track.com>
parent: Kris Jurka <books@ejurka.com>
1 sibling, 0 replies; 11+ messages in thread
From: Markus Schaber @ 2004-05-19 13:50 UTC (permalink / raw)
To: pgsql-jdbc
Hi, Kris,
On Mon, 17 May 2004 15:45:12 -0500 (EST)
Kris Jurka <books@ejurka.com> wrote:
> > [timestamps like 0002-10-30 are incorrectly seen as 2030-02-10].
>
> Yes, that's a bug alright. I've fixed this in both the stable and
> development cvs trees. While looking at this I noticed that the
> timestamp code has no provisions for BC dates, so if you're working
> with years in that area, that's something to be aware of. Fixing that
> has gone on the todo list, but I wanted to get this fix out to you
> now.
I just notified the change in the JDBC CVS, and have a (very small)
remark:
sbuf.append("0") is less efficient than sbuf.append('0').
The first reason is that for storing "0", there is a String object
created by the jvm, with an associated internal char[] array, which is
bound to the Class instance, while '0' as a constant scalar character is
no extra object.
And the second reason is that, as the StringBuffer source shows, adding
a String to a StringBuffer is much more work including a call to
System.ArrayCopy, while adding a simple character is just ensuring the
capacity and putting it in.
Interestingly, the lines below your insertion, already use chars, while
a little bit above, there's another example adding a single-byte String
(maybe because of lazyness to quote a ' inside of '').
So if you feel like peephole-optimizing, you can apply the attached
patch, if not, don't mind.
Thanks for your patience,
Markus Schaber
--
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios@logi-track.com | www.logi-track.com
Attachments:
jdbccharpatch.diff (text/plain, 912B) download
Index: AbstractJdbc1Statement.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
retrieving revision 1.53
diff -u -r1.53 AbstractJdbc1Statement.java
--- AbstractJdbc1Statement.java 17 May 2004 20:39:56 -0000 1.53
+++ AbstractJdbc1Statement.java 18 May 2004 14:39:29 -0000
@@ -1304,7 +1304,7 @@
{
sbuf.setLength(0);
sbuf.ensureCapacity(32);
- sbuf.append("'");
+ sbuf.append('\'');
//format the timestamp
//we do our own formating so that we can get a format
//that works with both timestamp with time zone and
@@ -1318,7 +1318,7 @@
// early years, like 2, don't get misinterpreted
int l_yearlen = String.valueOf(l_year).length();
for (int i=4; i>l_yearlen; i--) {
- sbuf.append("0");
+ sbuf.append('0');
}
sbuf.append(l_year);
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: [BUG?] Extreme dates
@ 2004-05-19 20:20 ow <oneway_111@yahoo.com>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 0 replies; 11+ messages in thread
From: ow @ 2004-05-19 20:20 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
--- Kris Jurka <books@ejurka.com> wrote:
> > Hi,
> >
> > I tried the jar, it appears that *occasionally* it saves null date as
> > 0002-12-31 (not 100% sure about that, maybe an app error). It also appears
> > there're some debugging printlns inside.
> >
>
> Please recheck your own code for both of these problems. I don't believe
> the driver is doing either of these.
>
> Kris Jurka
I think you're right. Must've been an app error. Thanks
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2004-05-19 20:20 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-16 15:02 [BUG?] Extreme dates ow <oneway_111@yahoo.com>
2004-05-16 20:21 ` Kris Jurka <books@ejurka.com>
2004-05-17 11:41 ` Waldomiro <wmiro@ig.com.br>
2004-05-17 18:17 [BUG?] Extreme dates ow <oneway_111@yahoo.com>
2004-05-17 20:45 ` Kris Jurka <books@ejurka.com>
2004-05-18 00:34 ` ow <oneway_111@yahoo.com>
2004-05-18 01:26 ` Kris Jurka <books@ejurka.com>
2004-05-18 20:02 ` ow <oneway_111@yahoo.com>
2004-05-18 20:24 ` Kris Jurka <books@ejurka.com>
2004-05-19 20:20 ` ow <oneway_111@yahoo.com>
2004-05-19 13:50 ` Markus Schaber <schabios@logi-track.com>
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