55import java .sql .*;
66
77/*
8- * $Id: TimestampTest.java,v 1.9 2002/09/06 21:23:06 momjian Exp $
8+ * $Id: TimestampTest.java,v 1.10 2003/01/14 09:13:51 barry Exp $
99 *
1010 * Test get/setTimestamp for both timestamp with time zone and
1111 * timestamp without time zone datatypes
@@ -52,11 +52,12 @@ public void testGetTimestampWTZ()
5252assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS1WTZ_PGFORMAT +"'" )));
5353assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS2WTZ_PGFORMAT +"'" )));
5454assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS3WTZ_PGFORMAT +"'" )));
55+ assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS4WTZ_PGFORMAT +"'" )));
5556
5657// Fall through helper
5758timestampTestWTZ ();
5859
59- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
60+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
6061
6162stmt .close ();
6263}
@@ -88,10 +89,13 @@ public void testSetTimestampWTZ()
8889pstmt .setTimestamp (1 ,TS3WTZ );
8990assertEquals (1 ,pstmt .executeUpdate ());
9091
92+ pstmt .setTimestamp (1 ,TS4WTZ );
93+ assertEquals (1 ,pstmt .executeUpdate ());
94+
9195// Fall through helper
9296timestampTestWTZ ();
9397
94- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
98+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
9599
96100pstmt .close ();
97101stmt .close ();
@@ -117,11 +121,12 @@ public void testGetTimestampWOTZ()
117121assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS1WOTZ_PGFORMAT +"'" )));
118122assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS2WOTZ_PGFORMAT +"'" )));
119123assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS3WOTZ_PGFORMAT +"'" )));
124+ assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS4WOTZ_PGFORMAT +"'" )));
120125
121126// Fall through helper
122127timestampTestWOTZ ();
123128
124- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
129+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
125130
126131stmt .close ();
127132}
@@ -154,10 +159,13 @@ public void testSetTimestampWOTZ()
154159pstmt .setTimestamp (1 ,TS3WOTZ );
155160assertEquals (1 ,pstmt .executeUpdate ());
156161
162+ pstmt .setTimestamp (1 ,TS4WOTZ );
163+ assertEquals (1 ,pstmt .executeUpdate ());
164+
157165// Fall through helper
158166timestampTestWOTZ ();
159167
160- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
168+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
161169
162170pstmt .close ();
163171stmt .close ();
@@ -195,6 +203,11 @@ private void timestampTestWTZ() throws SQLException
195203assertNotNull (t );
196204assertTrue (t .equals (TS3WTZ ));
197205
206+ assertTrue (rs .next ());
207+ t =rs .getTimestamp (1 );
208+ assertNotNull (t );
209+ assertTrue (t .equals (TS4WTZ ));
210+
198211assertTrue (!rs .next ());// end of table. Fail if more entries exist.
199212
200213rs .close ();
@@ -216,17 +229,22 @@ private void timestampTestWOTZ() throws SQLException
216229assertTrue (rs .next ());
217230t =rs .getTimestamp (1 );
218231assertNotNull (t );
219- assertTrue (t .toString (). equals (TS1WOTZ_JAVAFORMAT ));
232+ assertTrue (t .equals (TS1WOTZ ));
220233
221234assertTrue (rs .next ());
222235t =rs .getTimestamp (1 );
223236assertNotNull (t );
224- assertTrue (t .toString (). equals (TS2WOTZ_JAVAFORMAT ));
237+ assertTrue (t .equals (TS2WOTZ ));
225238
226239assertTrue (rs .next ());
227240t =rs .getTimestamp (1 );
228241assertNotNull (t );
229- assertTrue (t .toString ().equals (TS3WOTZ_JAVAFORMAT ));
242+ assertTrue (t .equals (TS3WOTZ ));
243+
244+ assertTrue (rs .next ());
245+ t =rs .getTimestamp (1 );
246+ assertNotNull (t );
247+ assertTrue (t .equals (TS4WOTZ ));
230248
231249assertTrue (!rs .next ());// end of table. Fail if more entries exist.
232250
@@ -277,20 +295,21 @@ private static java.sql.Timestamp getTimestamp(int y, int m, int d, int h, int m
277295private static final java .sql .Timestamp TS3WTZ =getTimestamp (2000 ,7 ,7 ,15 ,0 ,0 ,123000000 ,"GMT" );
278296private static final String TS3WTZ_PGFORMAT ="2000-07-07 15:00:00.123+00" ;
279297
298+ private static final java .sql .Timestamp TS4WTZ =getTimestamp (2000 ,7 ,7 ,15 ,0 ,0 ,123456000 ,"GMT" );
299+ private static final String TS4WTZ_PGFORMAT ="2000-07-07 15:00:00.123456+00" ;
300+
280301
281302private static final java .sql .Timestamp TS1WOTZ =getTimestamp (1950 ,2 ,7 ,15 ,0 ,0 ,100000000 ,null );
282303private static final String TS1WOTZ_PGFORMAT ="1950-02-07 15:00:00.1" ;
283- private static final String TS1WOTZ_JAVAFORMAT ="1950-02-07 15:00:00.1" ;
284304
285305private static final java .sql .Timestamp TS2WOTZ =getTimestamp (2000 ,2 ,7 ,15 ,0 ,0 ,120000000 ,null );
286306private static final String TS2WOTZ_PGFORMAT ="2000-02-07 15:00:00.12" ;
287- //there is probably a bug here in that this needs to be .1 instead of .12, but I couldn't find it now
288- private static final String TS2WOTZ_JAVAFORMAT ="2000-02-07 15:00:00.1" ;
289307
290308private static final java .sql .Timestamp TS3WOTZ =getTimestamp (2000 ,7 ,7 ,15 ,0 ,0 ,123000000 ,null );
291309private static final String TS3WOTZ_PGFORMAT ="2000-07-07 15:00:00.123" ;
292- //there is probably a bug here in that this needs to be .12 instead of .123, but I couldn't find it now
293- private static final String TS3WOTZ_JAVAFORMAT ="2000-07-07 15:00:00.12" ;
310+
311+ private static final java .sql .Timestamp TS4WOTZ =getTimestamp (2000 ,7 ,7 ,15 ,0 ,0 ,123456000 ,null );
312+ private static final String TS4WOTZ_PGFORMAT ="2000-07-07 15:00:00.123456" ;
294313
295314private static final String TSWTZ_TABLE ="testtimestampwtz" ;
296315private static final String TSWOTZ_TABLE ="testtimestampwotz" ;