Commit 66d00417 authored by Barry Lind's avatar Barry Lind

Applied jdbc patch from Kim Ho at RedHat to improve boolean support, as well

as some additional regression tests for this an other recent changes.

 Modified Files:
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
 	jdbc/org/postgresql/test/jdbc2/DateTest.java
 	jdbc/org/postgresql/test/jdbc2/ResultSetTest.java
 	jdbc/org/postgresql/test/jdbc2/TimeTest.java
 	jdbc/org/postgresql/test/jdbc2/TimestampTest.java
parent f03d2284
......@@ -9,7 +9,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.20 2003/09/18 04:09:02 barry Exp $
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.21 2003/09/22 04:54:59 barry Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -201,7 +201,11 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
case Types.DOUBLE:
case Types.FLOAT:
case Types.DECIMAL:
s = (s.indexOf(".")==-1) ? s : s.substring(0,s.indexOf("."));
int loc = s.indexOf(".");
if (loc!=-1 && Integer.parseInt(s.substring(loc+1,s.length()))==0)
{
s = s.substring(0,loc);
}
break;
case Types.CHAR:
s = s.trim();
......@@ -232,7 +236,11 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
case Types.DOUBLE:
case Types.FLOAT:
case Types.DECIMAL:
s = (s.indexOf(".")==-1) ? s : s.substring(0,s.indexOf("."));
int loc = s.indexOf(".");
if (loc!=-1 && Integer.parseInt(s.substring(loc+1,s.length()))==0)
{
s = s.substring(0,loc);
}
break;
case Types.CHAR:
s = s.trim();
......
......@@ -5,7 +5,7 @@ import junit.framework.TestCase;
import java.sql.*;
/*
* $Id: DateTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $
* $Id: DateTest.java,v 1.6 2003/09/22 04:55:00 barry Exp $
*
* Some simple tests based on problems reported by users. Hopefully these will
* help prevent previous problems from re-occuring ;-)
......@@ -15,6 +15,7 @@ public class DateTest extends TestCase
{
private Connection con;
private boolean testingSetDate = false;
public DateTest(String name)
{
......@@ -46,11 +47,23 @@ public class DateTest extends TestCase
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1970-06-02'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1999-08-11'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2001-02-13'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1950-04-02'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1970-11-30'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1988-01-01'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2003-07-09'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1934-02-28'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1969-04-03'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1982-08-03'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2012-03-15'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1912-05-01'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1971-12-15'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1984-12-03'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2000-01-01'")));
/* dateTest() contains all of the tests */
dateTest();
assertEquals(4, stmt.executeUpdate("DELETE FROM " + "testdate"));
assertEquals(16, stmt.executeUpdate("DELETE FROM " + "testdate"));
stmt.close();
}
catch (Exception ex)
......@@ -80,13 +93,64 @@ public class DateTest extends TestCase
ps.setDate(1, makeDate(2001, 2, 13));
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Timestamp.valueOf("1950-04-02 12:00:00"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Timestamp.valueOf("1970-11-30 3:00:00"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Timestamp.valueOf("1988-1-1 13:00:00"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Timestamp.valueOf("2003-07-09 12:00:00"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1934-02-28", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1969-04-3", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1982-08-03", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "2012-3-15", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Date.valueOf("1912-5-1"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Date.valueOf("1971-12-15"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Date.valueOf("1984-12-03"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Date.valueOf("2000-1-1"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1944-4-04-01", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1970-01-1-10", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1982-12-14+13", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "2010-08-3+05", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.close();
// Need to set a flag so that the method knows there is an extra test.
testingSetDate = true;
// Fall through helper
dateTest();
testingSetDate = false;
assertEquals(4, stmt.executeUpdate("DELETE FROM testdate"));
assertEquals(20, stmt.executeUpdate("DELETE FROM testdate"));
stmt.close();
}
catch (Exception ex)
......@@ -127,6 +191,122 @@ public class DateTest extends TestCase
assertNotNull(d);
assertEquals(d, makeDate(2001, 2, 13));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1950, 4, 2));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1970, 11, 30));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1988, 1, 1));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(2003, 7, 9));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1934, 2, 28));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1969, 4, 3));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1982, 8, 3));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(2012, 3, 15));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1912, 5, 1));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1971, 12, 15));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(1984, 12, 3));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
assertEquals(d, makeDate(2000, 1, 1));
//now we have to convert the date, cause I fed it a timezone. IF it used it. hence the check
if (testingSetDate)
{
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
java.sql.Date tmpDate = java.sql.Date.valueOf("1944-4-4");
int localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();
if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpDate))
{
localoffset += 60 * 60 * 1000;
}
int Dateoffset = 60 * 60 * 1000;
tmpDate.setTime(tmpDate.getTime() + Dateoffset + localoffset);
assertEquals(d, makeDate(tmpDate.getYear() + 1900, tmpDate.getMonth()+1, tmpDate.getDate()));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
tmpDate = java.sql.Date.valueOf("1970-1-1");
localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();
if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpDate))
{
localoffset += 60 * 60 * 1000;
}
Dateoffset = 10 * 60 * 60 * 1000;
tmpDate.setTime(tmpDate.getTime() + Dateoffset + localoffset);
assertEquals(d, makeDate(tmpDate.getYear() + 1900, tmpDate.getMonth()+1, tmpDate.getDate()));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
tmpDate = java.sql.Date.valueOf("1982-12-14");
localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();
if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpDate))
{
localoffset += 60 * 60 * 1000;
}
Dateoffset = -13 * 60 * 60 * 1000;
tmpDate.setTime(tmpDate.getTime() + Dateoffset + localoffset);
assertEquals(d, makeDate(tmpDate.getYear() + 1900, tmpDate.getMonth()+1, tmpDate.getDate()));
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
tmpDate = java.sql.Date.valueOf("2010-08-03");
localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();
if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpDate))
{
localoffset += 60 * 60 * 1000;
}
Dateoffset = -5 * 60 * 60 * 1000;
tmpDate.setTime(tmpDate.getTime() + Dateoffset + localoffset);
assertEquals(d, makeDate(tmpDate.getYear() + 1900, tmpDate.getMonth()+1, tmpDate.getDate()));
}
assertTrue(!rs.next());
rs.close();
......
......@@ -38,6 +38,35 @@ public class ResultSetTest extends TestCase
TestUtil.createTable(con, "testint", "a int");
stmt.executeUpdate("INSERT INTO testint VALUES (12345)");
TestUtil.createTable(con, "testbool", "a boolean");
TestUtil.createTable(con, "testbit", "a bit");
TestUtil.createTable(con, "testboolstring", "a varchar(30)");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('true')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('false')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('t')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('f')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('1.0')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('0.0')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('TRUE')");
stmt.executeUpdate("INSERT INTO testboolstring VALUES('this is not true')");
TestUtil.createTable(con, "testnumeric", "a numeric");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('1.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('0.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-1.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('1.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('99999.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('99999')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-2.5')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-99999.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-99999')");
stmt.close();
stmt.close();
}
......@@ -47,6 +76,10 @@ public class ResultSetTest extends TestCase
TestUtil.dropTable(con, "testrs");
TestUtil.dropTable(con, "teststring");
TestUtil.dropTable(con, "testint");
TestUtil.dropTable(con, "testbool");
TestUtil.dropTable(con, "testbit");
TestUtil.dropTable(con, "testboolstring");
TestUtil.dropTable(con, "testnumeric");
TestUtil.closeDB(con);
}
......@@ -114,4 +147,139 @@ public class ResultSetTest extends TestCase
assertEquals(rs.getString(1), "12");
assertEquals(new String(rs.getBytes(1)), "12");
}
public void booleanTests(boolean useServerPrepare) throws Exception
{
java.sql.PreparedStatement pstmt = con.prepareStatement("insert into testbool values (?)");
if (useServerPrepare)
((org.postgresql.PGStatement)pstmt).setUseServerPrepare(true);
pstmt.setObject(1, new Float(0), java.sql.Types.BIT);
pstmt.executeUpdate();
pstmt.setObject(1, new Float(1), java.sql.Types.BIT);
pstmt.executeUpdate();
pstmt.setObject(1, "False", java.sql.Types.BIT);
pstmt.executeUpdate();
pstmt.setObject(1, "True", java.sql.Types.BIT);
pstmt.executeUpdate();
ResultSet rs = con.createStatement().executeQuery("select * from testbool");
for (int i = 0; i<2; i++)
{
assertTrue(rs.next());
assertEquals(false, rs.getBoolean(1));
assertTrue(rs.next());
assertEquals(true, rs.getBoolean(1));
}
pstmt = con.prepareStatement("insert into testbit values (?)");
pstmt.setObject(1, new Float(0), java.sql.Types.BIT);
pstmt.executeUpdate();
pstmt.setObject(1, new Float(1), java.sql.Types.BIT);
pstmt.executeUpdate();
pstmt.setObject(1, "false", java.sql.Types.BIT);
pstmt.executeUpdate();
pstmt.setObject(1, "true", java.sql.Types.BIT);
pstmt.executeUpdate();
rs = con.createStatement().executeQuery("select * from testbit");
for (int i = 0;i<2; i++)
{
assertTrue(rs.next());
assertEquals(false, rs.getBoolean(1));
assertTrue(rs.next());
assertEquals(true, rs.getBoolean(1));
}
rs = con.createStatement().executeQuery("select * from testboolstring");
for (int i = 0;i<4; i++)
{
assertTrue(rs.next());
assertEquals(true, rs.getBoolean(1));
assertTrue(rs.next());
assertEquals(false, rs.getBoolean(1));
}
}
public void testBoolean() throws Exception
{
booleanTests(true);
booleanTests(false);
}
public void testgetByte() throws Exception
{
ResultSet rs = con.createStatement().executeQuery("select * from testnumeric");
boolean thrown = false;
assertTrue(rs.next());
assertEquals(1,rs.getByte(1));
assertTrue(rs.next());
assertEquals(0,rs.getByte(1));
assertTrue(rs.next());
assertEquals(-1,rs.getByte(1));
int count = 3;
while (rs.next())
{
try
{
rs.getByte(1);
}
catch (Exception e)
{
thrown = true;
}
if (!thrown)
fail("Exception expected.");
count++;
}
if (count != 9)
fail("Exception expected.");
}
public void testgetShort() throws Exception
{
ResultSet rs = con.createStatement().executeQuery("select * from testnumeric");
boolean thrown = false;
assertTrue(rs.next());
assertEquals(1,rs.getShort(1));
assertTrue(rs.next());
assertEquals(0,rs.getShort(1));
assertTrue(rs.next());
assertEquals(-1,rs.getShort(1));
int count = 3;
while (rs.next())
{
try
{
rs.getShort(1);
}
catch (Exception e)
{
thrown = true;
}
if (!thrown)
fail("Exception expected.");
count++;
}
if (count != 9)
fail("Exception expected.");
}
}
......@@ -5,7 +5,7 @@ import junit.framework.TestCase;
import java.sql.*;
/*
* $Id: TimeTest.java,v 1.5 2002/08/14 20:35:40 barry Exp $
* $Id: TimeTest.java,v 1.6 2003/09/22 04:55:00 barry Exp $
*
* Some simple tests based on problems reported by users. Hopefully these will
* help prevent previous problems from re-occuring ;-)
......@@ -15,6 +15,7 @@ public class TimeTest extends TestCase
{
private Connection con;
private boolean testSetTime = false;
public TimeTest(String name)
{
......@@ -44,11 +45,18 @@ public class TimeTest extends TestCase
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'01:02:03'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'23:59:59'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'12:00:00'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'05:15:21'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'16:21:51'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'12:15:12'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'22:12:01'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'08:46:44'")));
// Fall through helper
timeTest();
assertEquals(2, stmt.executeUpdate("DELETE FROM testtime"));
assertEquals(8, stmt.executeUpdate("DELETE FROM testtime"));
stmt.close();
}
catch (Exception ex)
......@@ -72,11 +80,38 @@ public class TimeTest extends TestCase
ps.setTime(1, makeTime(23, 59, 59));
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Time.valueOf("12:00:00"), java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Time.valueOf("05:15:21"), java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Time.valueOf("16:21:51"), java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Time.valueOf("12:15:12"), java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "22:12:1", java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "8:46:44", java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "5:1:2-03", java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "23:59:59+11", java.sql.Types.TIME);
assertEquals(1, ps.executeUpdate());
// Need to let the test know this one has extra test cases.
testSetTime = true;
// Fall through helper
timeTest();
testSetTime = false;
assertEquals(2, stmt.executeUpdate("DELETE FROM testtime"));
assertEquals(10, stmt.executeUpdate("DELETE FROM testtime"));
stmt.close();
ps.close();
}
......@@ -108,6 +143,66 @@ public class TimeTest extends TestCase
assertNotNull(t);
assertEquals(makeTime(23, 59, 59), t);
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
assertEquals(makeTime(12, 0, 0), t);
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
assertEquals(makeTime(5, 15, 21), t);
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
assertEquals(makeTime(16, 21, 51), t);
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
assertEquals(makeTime(12, 15, 12), t);
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
assertEquals(makeTime(22, 12, 1), t);
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
assertEquals(makeTime(8, 46, 44), t);
// If we're checking for timezones.
if (testSetTime)
{
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
java.sql.Time tmpTime = java.sql.Time.valueOf("5:1:2");
int localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();
if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpTime))
{
localoffset += 60 * 60 * 1000;
}
int Timeoffset = 3 * 60 * 60 * 1000;
tmpTime.setTime(tmpTime.getTime() + Timeoffset + localoffset);
assertEquals(t, makeTime(tmpTime.getHours(), tmpTime.getMinutes(), tmpTime.getSeconds()));
assertTrue(rs.next());
t = rs.getTime(1);
assertNotNull(t);
tmpTime= java.sql.Time.valueOf("23:59:59");
localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();
if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpTime))
{
localoffset += 60 * 60 * 1000;
}
Timeoffset = -11 * 60 * 60 * 1000;
tmpTime.setTime(tmpTime.getTime() + Timeoffset + localoffset);
assertEquals(t, makeTime(tmpTime.getHours(), tmpTime.getMinutes(), tmpTime.getSeconds()));
}
assertTrue(! rs.next());
rs.close();
......
......@@ -5,7 +5,7 @@ import junit.framework.TestCase;
import java.sql.*;
/*
* $Id: TimestampTest.java,v 1.11 2003/05/29 04:39:48 barry Exp $
* $Id: TimestampTest.java,v 1.12 2003/09/22 04:55:00 barry Exp $
*
* Test get/setTimestamp for both timestamp with time zone and
* timestamp without time zone datatypes
......@@ -51,11 +51,28 @@ public class TimestampTest extends TestCase
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS2WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS3WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS4WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS1WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS2WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS3WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS4WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS1WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS2WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS3WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + TS4WTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate1.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate2.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate3.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate4.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime1.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime2.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime3.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime4.getTime()) + "'")));
// Fall through helper
timestampTestWTZ();
assertEquals(4, stmt.executeUpdate("DELETE FROM " + TSWTZ_TABLE));
assertEquals(20, stmt.executeUpdate("DELETE FROM " + TSWTZ_TABLE));
stmt.close();
}
......@@ -89,11 +106,51 @@ public class TimestampTest extends TestCase
pstmt.setTimestamp(1, TS4WTZ);
assertEquals(1, pstmt.executeUpdate());
// With java.sql.Timestamp
pstmt.setObject(1,TS1WTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS2WTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS3WTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS4WTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// With Strings
pstmt.setObject(1,TS1WTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS2WTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS3WTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS4WTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// With java.sql.Date
pstmt.setObject(1,tmpDate1, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpDate2, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpDate3, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpDate4, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// With java.sql.Time
pstmt.setObject(1,tmpTime1, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpTime2, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpTime3, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpTime4, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// Fall through helper
timestampTestWTZ();
assertEquals(4, stmt.executeUpdate("DELETE FROM " + TSWTZ_TABLE));
assertEquals(20, stmt.executeUpdate("DELETE FROM " + TSWTZ_TABLE));
pstmt.close();
stmt.close();
......@@ -120,11 +177,27 @@ public class TimestampTest extends TestCase
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS2WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS3WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS4WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS1WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS2WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS3WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS4WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS1WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS2WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS3WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + TS4WOTZ_PGFORMAT + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate1WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate2WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate3WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpDate4WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime1WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime2WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime3WOTZ.getTime()) + "'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL(TSWOTZ_TABLE, "'" + new java.sql.Timestamp(tmpTime4WOTZ.getTime()) + "'")));
// Fall through helper
timestampTestWOTZ();
assertEquals(4, stmt.executeUpdate("DELETE FROM " + TSWOTZ_TABLE));
assertEquals(20, stmt.executeUpdate("DELETE FROM " + TSWOTZ_TABLE));
stmt.close();
}
......@@ -160,10 +233,51 @@ public class TimestampTest extends TestCase
pstmt.setTimestamp(1, TS4WOTZ);
assertEquals(1, pstmt.executeUpdate());
// With java.sql.Timestamp
pstmt.setObject(1,TS1WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS2WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS3WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS4WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// With Strings
pstmt.setObject(1,TS1WOTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS2WOTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS3WOTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,TS4WOTZ_PGFORMAT, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// With java.sql.Date
pstmt.setObject(1,tmpDate1WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpDate2WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpDate3WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpDate4WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// With java.sql.Time
pstmt.setObject(1,tmpTime1WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpTime2WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpTime3WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
pstmt.setObject(1,tmpTime4WOTZ, java.sql.Types.TIMESTAMP);
assertEquals(1, pstmt.executeUpdate());
// Fall through helper
timestampTestWOTZ();
assertEquals(4, stmt.executeUpdate("DELETE FROM " + TSWOTZ_TABLE));
assertEquals(20, stmt.executeUpdate("DELETE FROM " + TSWOTZ_TABLE));
pstmt.close();
stmt.close();
......@@ -183,28 +297,73 @@ public class TimestampTest extends TestCase
ResultSet rs;
java.sql.Timestamp t;
rs = stmt.executeQuery("select ts from " + TSWTZ_TABLE + " order by ts");
rs = stmt.executeQuery("select ts from " + TSWTZ_TABLE); //removed the order by ts
assertNotNull(rs);
for (int i=0; i<3; i++)
{
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS1WTZ));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS2WTZ));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS3WTZ));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS4WTZ));
}
// Testing for Date
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS1WTZ));
assertEquals(t.getTime(), tmpDate1.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS2WTZ));
assertEquals(t.getTime(), tmpDate2.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS3WTZ));
assertEquals(t.getTime(), tmpDate3.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS4WTZ));
assertEquals(t.getTime(), tmpDate4.getTime());
// Testing for Time
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpTime1.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpTime2.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpTime3.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpTime4.getTime());
assertTrue(! rs.next()); // end of table. Fail if more entries exist.
......@@ -221,29 +380,74 @@ public class TimestampTest extends TestCase
ResultSet rs;
java.sql.Timestamp t;
rs = stmt.executeQuery("select ts from " + TSWOTZ_TABLE + " order by ts");
rs = stmt.executeQuery("select ts from " + TSWOTZ_TABLE); //removed the order by ts
assertNotNull(rs);
for (int i=0; i<3; i++)
{
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS1WOTZ));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS2WOTZ));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS3WOTZ));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS4WOTZ));
}
// Testing for Date
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpDate1WOTZ.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpDate2WOTZ.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS1WOTZ));
assertEquals(t.getTime(), tmpDate3WOTZ.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS2WOTZ));
assertEquals(t.getTime(), tmpDate4WOTZ.getTime());
// Testing for Time
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpTime1WOTZ.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS3WOTZ));
assertEquals(t.getTime(), tmpTime2WOTZ.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(TS4WOTZ));
assertEquals(t.getTime(), tmpTime3WOTZ.getTime());
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertEquals(t.getTime(), tmpTime4WOTZ.getTime());
assertTrue(! rs.next()); // end of table. Fail if more entries exist.
rs.close();
......@@ -311,5 +515,24 @@ public class TimestampTest extends TestCase
private static final String TSWTZ_TABLE = "testtimestampwtz";
private static final String TSWOTZ_TABLE = "testtimestampwotz";
private static final java.sql.Date tmpDate1 = new java.sql.Date(TS1WTZ.getTime());
private static final java.sql.Time tmpTime1 = new java.sql.Time(TS1WTZ.getTime());
private static final java.sql.Date tmpDate2 = new java.sql.Date(TS2WTZ.getTime());
private static final java.sql.Time tmpTime2 = new java.sql.Time(TS2WTZ.getTime());
private static final java.sql.Date tmpDate3 = new java.sql.Date(TS3WTZ.getTime());
private static final java.sql.Time tmpTime3 = new java.sql.Time(TS3WTZ.getTime());
private static final java.sql.Date tmpDate4 = new java.sql.Date(TS4WTZ.getTime());
private static final java.sql.Time tmpTime4 = new java.sql.Time(TS4WTZ.getTime());
private static final java.sql.Date tmpDate1WOTZ = new java.sql.Date(TS1WOTZ.getTime());
private static final java.sql.Time tmpTime1WOTZ = new java.sql.Time(TS1WOTZ.getTime());
private static final java.sql.Date tmpDate2WOTZ = new java.sql.Date(TS2WOTZ.getTime());
private static final java.sql.Time tmpTime2WOTZ = new java.sql.Time(TS2WOTZ.getTime());
private static final java.sql.Date tmpDate3WOTZ = new java.sql.Date(TS3WOTZ.getTime());
private static final java.sql.Time tmpTime3WOTZ = new java.sql.Time(TS3WOTZ.getTime());
private static final java.sql.Date tmpDate4WOTZ = new java.sql.Date(TS4WOTZ.getTime());
private static final java.sql.Time tmpTime4WOTZ = new java.sql.Time(TS4WOTZ.getTime());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment