[libpostgresql-jdbc-java] 03/14: Add a test case to detect if we modify a passed in Calendar object to things like PreparedStatement.setTimestamp. This shows the fix for setDate had an error and that the corresponding ResultSet.get methods had the same problems.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:12 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_312
in repository libpostgresql-jdbc-java.
commit 0580e93ac2020ed460e36285921bd939abfa30c1
Author: Kris Jurka <books at ejurka.com>
Date: Sun May 8 23:52:01 2005 +0000
Add a test case to detect if we modify a passed in Calendar object
to things like PreparedStatement.setTimestamp. This shows the
fix for setDate had an error and that the corresponding ResultSet.get
methods had the same problems.
---
org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 18 ++++++----
org/postgresql/jdbc2/AbstractJdbc2Statement.java | 17 +++++----
org/postgresql/test/jdbc2/TimestampTest.java | 44 +++++++++++++++++++++++-
3 files changed, 64 insertions(+), 15 deletions(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index e45d5f1..1199dda 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -3,7 +3,7 @@
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.71.2.1 2005/02/15 08:55:50 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.71.2.2 2005/03/23 19:48:17 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
+import java.util.Calendar;
import java.util.GregorianCalendar;
import org.postgresql.Driver;
import org.postgresql.core.*;
@@ -383,8 +384,9 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
if (tmp == null)
return null;
- cal = org.postgresql.jdbc2.AbstractJdbc2Statement.changeTime(tmp, cal, false);
- return new java.sql.Date(cal.getTime().getTime());
+ Calendar _cal = (Calendar)cal.clone();
+ _cal = org.postgresql.jdbc2.AbstractJdbc2Statement.changeTime(tmp, _cal, false);
+ return new java.sql.Date(_cal.getTime().getTime());
}
@@ -396,8 +398,9 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
java.util.Date tmp = getTime(i);
if (tmp == null)
return null;
- cal = org.postgresql.jdbc2.AbstractJdbc2Statement.changeTime(tmp, cal, false);
- return new java.sql.Time(cal.getTime().getTime());
+ Calendar _cal = (Calendar)cal.clone();
+ _cal = org.postgresql.jdbc2.AbstractJdbc2Statement.changeTime(tmp, _cal, false);
+ return new java.sql.Time(_cal.getTime().getTime());
}
@@ -409,8 +412,9 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
java.util.Date tmp = getTimestamp(i);
if (tmp == null)
return null;
- cal = org.postgresql.jdbc2.AbstractJdbc2Statement.changeTime(tmp, cal, false);
- return new java.sql.Timestamp(cal.getTime().getTime());
+ Calendar _cal = (Calendar)cal.clone();
+ _cal = org.postgresql.jdbc2.AbstractJdbc2Statement.changeTime(tmp, _cal, false);
+ return new java.sql.Timestamp(_cal.getTime().getTime());
}
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 50a3a33..8bb353e 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.4 2005/02/16 18:30:27 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.5 2005/04/28 14:18:09 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2771,8 +2771,9 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
setDate(i, d);
else
{
- cal = changeTime(d, cal, true);
- setDate(i, new java.sql.Date(cal.getTime().getTime()));
+ Calendar _cal = (Calendar)cal.clone();
+ _cal = changeTime(d, _cal, true);
+ setDate(i, new java.sql.Date(_cal.getTime().getTime()));
}
}
@@ -2783,8 +2784,9 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
setTime(i, t);
else
{
- cal = changeTime(t, cal, true);
- setTime(i, new java.sql.Time(cal.getTime().getTime()));
+ Calendar _cal = (Calendar)cal.clone();
+ _cal = changeTime(t, _cal, true);
+ setTime(i, new java.sql.Time(_cal.getTime().getTime()));
}
}
@@ -2795,8 +2797,9 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
setTimestamp(i, t);
else
{
- cal = changeTime(t, cal, true);
- setTimestamp(i, new java.sql.Timestamp(cal.getTime().getTime()));
+ Calendar _cal = (Calendar)cal.clone();
+ _cal = changeTime(t, _cal, true);
+ setTimestamp(i, new java.sql.Timestamp(_cal.getTime().getTime()));
}
}
diff --git a/org/postgresql/test/jdbc2/TimestampTest.java b/org/postgresql/test/jdbc2/TimestampTest.java
index 7b9dab5..76ab543 100644
--- a/org/postgresql/test/jdbc2/TimestampTest.java
+++ b/org/postgresql/test/jdbc2/TimestampTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/TimestampTest.java,v 1.17 2005/01/11 08:25:48 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/TimestampTest.java,v 1.17.2.1 2005/02/15 08:32:17 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -14,6 +14,7 @@ import junit.framework.TestCase;
import java.sql.*;
import java.util.TimeZone;
+import java.util.Calendar;
import java.util.GregorianCalendar;
import org.postgresql.PGStatement;
@@ -48,6 +49,47 @@ public class TimestampTest extends TestCase
TestUtil.closeDB(con);
}
+ /**
+ * Ensure the driver doesn't modify a Calendar that is passed in.
+ */
+ public void testCalendarModification() throws SQLException
+ {
+ Calendar cal = Calendar.getInstance();
+ Calendar origCal = (Calendar)cal.clone();
+ PreparedStatement ps = con.prepareStatement("INSERT INTO " + TSWOTZ_TABLE + " VALUES (?)");
+
+ ps.setDate(1, new Date(0), cal);
+ ps.executeUpdate();
+ assertEquals(origCal, cal);
+
+ ps.setTimestamp(1, new Timestamp(0), cal);
+ ps.executeUpdate();
+ assertEquals(origCal, cal);
+
+ ps.setTime(1, new Time(0), cal);
+ // Can't actually execute this one because of type mismatch,
+ // but all we're really concerned about is the set call.
+ // ps.executeUpdate();
+ assertEquals(origCal, cal);
+
+ ps.close();
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT ts FROM " + TSWOTZ_TABLE);
+ assertTrue(rs.next());
+
+ rs.getDate(1, cal);
+ assertEquals(origCal, cal);
+
+ rs.getTimestamp(1, cal);
+ assertEquals(origCal, cal);
+
+ rs.getTime(1, cal);
+ assertEquals(origCal, cal);
+
+ rs.close();
+ stmt.close();
+ }
+
public void testInfinity() throws SQLException
{
runInfinityTests(TSWTZ_TABLE, PGStatement.DATE_POSITIVE_INFINITY);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list