5
5
import java .sql .*;
6
6
7
7
/*
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 $
9
9
*
10
10
* Test get/setTimestamp for both timestamp with time zone and
11
11
* timestamp without time zone datatypes
@@ -52,11 +52,12 @@ public void testGetTimestampWTZ()
52
52
assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS1WTZ_PGFORMAT +"'" )));
53
53
assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS2WTZ_PGFORMAT +"'" )));
54
54
assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS3WTZ_PGFORMAT +"'" )));
55
+ assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWTZ_TABLE ,"'" +TS4WTZ_PGFORMAT +"'" )));
55
56
56
57
// Fall through helper
57
58
timestampTestWTZ ();
58
59
59
- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
60
+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
60
61
61
62
stmt .close ();
62
63
}
@@ -88,10 +89,13 @@ public void testSetTimestampWTZ()
88
89
pstmt .setTimestamp (1 ,TS3WTZ );
89
90
assertEquals (1 ,pstmt .executeUpdate ());
90
91
92
+ pstmt .setTimestamp (1 ,TS4WTZ );
93
+ assertEquals (1 ,pstmt .executeUpdate ());
94
+
91
95
// Fall through helper
92
96
timestampTestWTZ ();
93
97
94
- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
98
+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWTZ_TABLE ));
95
99
96
100
pstmt .close ();
97
101
stmt .close ();
@@ -117,11 +121,12 @@ public void testGetTimestampWOTZ()
117
121
assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS1WOTZ_PGFORMAT +"'" )));
118
122
assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS2WOTZ_PGFORMAT +"'" )));
119
123
assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS3WOTZ_PGFORMAT +"'" )));
124
+ assertEquals (1 ,stmt .executeUpdate (TestUtil .insertSQL (TSWOTZ_TABLE ,"'" +TS4WOTZ_PGFORMAT +"'" )));
120
125
121
126
// Fall through helper
122
127
timestampTestWOTZ ();
123
128
124
- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
129
+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
125
130
126
131
stmt .close ();
127
132
}
@@ -154,10 +159,13 @@ public void testSetTimestampWOTZ()
154
159
pstmt .setTimestamp (1 ,TS3WOTZ );
155
160
assertEquals (1 ,pstmt .executeUpdate ());
156
161
162
+ pstmt .setTimestamp (1 ,TS4WOTZ );
163
+ assertEquals (1 ,pstmt .executeUpdate ());
164
+
157
165
// Fall through helper
158
166
timestampTestWOTZ ();
159
167
160
- assertEquals (3 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
168
+ assertEquals (4 ,stmt .executeUpdate ("DELETE FROM " +TSWOTZ_TABLE ));
161
169
162
170
pstmt .close ();
163
171
stmt .close ();
@@ -195,6 +203,11 @@ private void timestampTestWTZ() throws SQLException
195
203
assertNotNull (t );
196
204
assertTrue (t .equals (TS3WTZ ));
197
205
206
+ assertTrue (rs .next ());
207
+ t =rs .getTimestamp (1 );
208
+ assertNotNull (t );
209
+ assertTrue (t .equals (TS4WTZ ));
210
+
198
211
assertTrue (!rs .next ());// end of table. Fail if more entries exist.
199
212
200
213
rs .close ();
@@ -216,17 +229,22 @@ private void timestampTestWOTZ() throws SQLException
216
229
assertTrue (rs .next ());
217
230
t =rs .getTimestamp (1 );
218
231
assertNotNull (t );
219
- assertTrue (t .toString (). equals (TS1WOTZ_JAVAFORMAT ));
232
+ assertTrue (t .equals (TS1WOTZ ));
220
233
221
234
assertTrue (rs .next ());
222
235
t =rs .getTimestamp (1 );
223
236
assertNotNull (t );
224
- assertTrue (t .toString (). equals (TS2WOTZ_JAVAFORMAT ));
237
+ assertTrue (t .equals (TS2WOTZ ));
225
238
226
239
assertTrue (rs .next ());
227
240
t =rs .getTimestamp (1 );
228
241
assertNotNull (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 ));
230
248
231
249
assertTrue (!rs .next ());// end of table. Fail if more entries exist.
232
250
@@ -277,20 +295,21 @@ private static java.sql.Timestamp getTimestamp(int y, int m, int d, int h, int m
277
295
private static final java .sql .Timestamp TS3WTZ =getTimestamp (2000 ,7 ,7 ,15 ,0 ,0 ,123000000 ,"GMT" );
278
296
private static final String TS3WTZ_PGFORMAT ="2000-07-07 15:00:00.123+00" ;
279
297
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
+
280
301
281
302
private static final java .sql .Timestamp TS1WOTZ =getTimestamp (1950 ,2 ,7 ,15 ,0 ,0 ,100000000 ,null );
282
303
private 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" ;
284
304
285
305
private static final java .sql .Timestamp TS2WOTZ =getTimestamp (2000 ,2 ,7 ,15 ,0 ,0 ,120000000 ,null );
286
306
private 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" ;
289
307
290
308
private static final java .sql .Timestamp TS3WOTZ =getTimestamp (2000 ,7 ,7 ,15 ,0 ,0 ,123000000 ,null );
291
309
private 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" ;
294
313
295
314
private static final String TSWTZ_TABLE ="testtimestampwtz" ;
296
315
private static final String TSWOTZ_TABLE ="testtimestampwotz" ;