My patch once more, based on 'postgresql-jdbc-8.0-311.src.tar.gz'. (Sorry, my last version of this patch made a NullPointerException!) Using this patch, I still have not found any more problems with my application.
With kind regards, Ingolf.
diff -cr postgresql-jdbc-8.0-311.src/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java postgresql-jdbc-8.0-311.src.patched/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java *** postgresql-jdbc-8.0-311.src/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java Wed Mar 23 20:48:17 2005 --- postgresql-jdbc-8.0-311.src.patched/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java Thu Apr 28 17:44:06 2005 *************** *** 23,28 **** --- 23,29 ---- import java.util.StringTokenizer; import java.util.Vector; import java.util.GregorianCalendar; + import java.util.Calendar; import org.postgresql.Driver; import org.postgresql.core.*; import org.postgresql.largeobject.*; *************** *** 2088,2094 **** this.checkResultSet(columnIndex); if (calendar == null) calendar = new GregorianCalendar(); ! return TimestampUtils.toTimestamp(calendar, getString(columnIndex)); } public InputStream getAsciiStream(int columnIndex) throws SQLException --- 2089,2107 ---- this.checkResultSet(columnIndex); if (calendar == null) calendar = new GregorianCalendar(); ! Timestamp ts = TimestampUtils.toTimestamp(calendar, getString(columnIndex)); ! if (null!=ts && java.sql.Types.DATE==getMetaData().getColumnType(columnIndex) ) ! { ! Calendar cal = Calendar.getInstance(); ! cal.setTime(ts); ! cal.set(Calendar.HOUR,0); ! cal.set(Calendar.HOUR_OF_DAY,0); ! cal.set(Calendar.MINUTE,0); ! cal.set(Calendar.SECOND,0); ! cal.set(Calendar.MILLISECOND,0); ! ts.setTime(cal.getTimeInMillis()); ! } ! return ts; } public InputStream getAsciiStream(int columnIndex) throws SQLException diff -cr postgresql-jdbc-8.0-311.src/org/postgresql/test/jdbc2/ResultSetTest.java postgresql-jdbc-8.0-311.src.patched/org/postgresql/test/jdbc2/ResultSetTest.java *** postgresql-jdbc-8.0-311.src/org/postgresql/test/jdbc2/ResultSetTest.java Tue Jan 11 09:25:48 2005 --- postgresql-jdbc-8.0-311.src.patched/org/postgresql/test/jdbc2/ResultSetTest.java Thu Apr 28 17:44:06 2005 *************** *** 46,51 **** --- 46,59 ---- TestUtil.createTable(con, "teststring", "a text"); stmt.executeUpdate("INSERT INTO teststring VALUES ('12345')"); + TestUtil.createTable(con, "testdate", "d date"); + stmt.executeUpdate("INSERT INTO testdate VALUES (CURRENT_DATE)"); + stmt.executeUpdate("INSERT INTO testdate VALUES ( null )"); + + TestUtil.createTable(con, "testtimestamp", "d timestamp"); + stmt.executeUpdate("INSERT INTO testtimestamp VALUES (CURRENT_DATE)"); + stmt.executeUpdate("INSERT INTO testtimestamp VALUES ( null )"); + TestUtil.createTable(con, "testint", "a int"); stmt.executeUpdate("INSERT INTO testint VALUES (12345)"); *************** *** 103,108 **** --- 111,118 ---- { TestUtil.dropTable(con, "testrs"); TestUtil.dropTable(con, "teststring"); + TestUtil.dropTable(con, "testdate"); + TestUtil.dropTable(con, "testtimestamp"); TestUtil.dropTable(con, "testint"); TestUtil.dropTable(con, "testbool"); //TestUtil.dropTable(con, "testbit"); *************** *** 178,183 **** --- 188,233 ---- rs.next(); assertEquals("12", rs.getString(1)); assertEquals("12", new String(rs.getBytes(1))); + } + + public void testDate() throws SQLException + { + Statement stmt = con.createStatement(); + stmt.setMaxFieldSize(2); + + ResultSet rs = stmt.executeQuery("select * from testdate"); + + //independent of how current date is read, it should be a + //date and not a timestamp + while ( rs.next() ) + { + java.sql.Date dtVal = rs.getDate(1); + java.sql.Timestamp tsVal = rs.getTimestamp(1); + if ( null == dtVal ) + assertNull("date is null, timestamp should be null", tsVal); + else + assertEquals("date should stay a date even when it is read by 'getTimestamp()'", dtVal.getTime(), tsVal.getTime()); + } + } + + public void testDateTimestamp() throws SQLException + { + Statement stmt = con.createStatement(); + stmt.setMaxFieldSize(2); + + ResultSet rs = stmt.executeQuery("select * from testtimestamp"); + + //independent of how current date is read, it should be a + //date and not a timestamp + while ( rs.next() ) + { + java.sql.Date dtVal = rs.getDate(1); + java.sql.Timestamp tsVal = rs.getTimestamp(1); + if ( null == dtVal ) + assertNull("date is null, timestamp should be null", tsVal); + else + assertEquals("I stored a date, and I want to get a date", dtVal.getTime(), tsVal.getTime()); + } } public void booleanTests(boolean useServerPrepare) throws SQLException
---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly