postgresql-jdbc.git / summary / log / commit / refs
commit 07ea76ecb66e24c541e652bb3f1a19350daea7de
Author: Dave Cramer <davec@fastcrypt.com>
Date: Thu Feb 12 15:38:33 2004 +0000
added createTempTable, and test for getObject
org/postgresql/test/TestUtil.java | 26 +++++++++-
org/postgresql/test/jdbc2/GetXXXTest.java | 79 +++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+), 1 deletion(-)
diff --git a/org/postgresql/test/TestUtil.java b/org/postgresql/test/TestUtil.java
index 63807499..21abdd4a 100644
--- a/org/postgresql/test/TestUtil.java
+++ b/org/postgresql/test/TestUtil.java
@@ -99,7 +99,7 @@ public class TestUtil
try {
// Drop the table
dropTable(con, table);
-
+
// Now create the table
st.executeUpdate("create table " + table + " (" + columns + ")");
} finally {
@@ -107,6 +107,30 @@ public class TestUtil
}
}
+ /**
+ * Helper creates a temporary table
+ * @param con Connection
+ * @param table String
+ * @param columns String
+ * @throws SQLException
+ */
+
+ public static void createTempTable( Connection con,
+ String table,
+ String columns) throws SQLException
+ {
+ Statement st = con.createStatement();
+ try {
+ // Drop the table
+ dropTable(con, table);
+
+ // Now create the table
+ st.executeUpdate("create temp table " + table + " (" + columns + ")");
+ } finally {
+ st.close();
+ }
+ }
+
/*
* Helper - drops a table
*/
diff --git a/org/postgresql/test/jdbc2/GetXXXTest.java b/org/postgresql/test/jdbc2/GetXXXTest.java
new file mode 100644
index 00000000..b4cbb522
--- /dev/null
+++ b/org/postgresql/test/jdbc2/GetXXXTest.java
@@ -0,0 +1,79 @@
+package org.postgresql.test.jdbc2;
+
+import org.postgresql.test.TestUtil;
+import java.util.Calendar;
+import junit.framework.*;
+import java.sql.*;
+import java.util.HashMap;
+/*
+ * $PostgreSQL: $
+ *
+ * Test for getObject
+ */
+
+public class GetXXXTest extends TestCase
+{
+ Connection con = null;
+
+ public GetXXXTest(String name )
+ {
+ super(name);
+ }
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ con = TestUtil.openDB();
+ TestUtil.createTempTable(con, "test_interval",
+ "initial timestamp with time zone, final timestamp with time zone");
+ PreparedStatement pstmt = con.prepareStatement(
+ "insert into test_interval values (?,?)");
+ Calendar cal = Calendar.getInstance();
+ cal.add(Calendar.DAY_OF_YEAR, -1);
+
+ pstmt.setTimestamp(1, new Timestamp(cal.getTimeInMillis()));
+ pstmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
+ assertTrue(pstmt.executeUpdate() == 1);
+ pstmt.close();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ TestUtil.dropTable( con, "test_interval" );
+ con.close();
+ }
+
+ public void testGetObject() throws SQLException
+ {
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery(
+ "select (final-initial) as diff from test_interval");
+ while (rs.next())
+ {
+ String str = (String) rs.getString(1);
+
+ assertNotNull(str);
+ Object obj = rs.getObject(1);
+ assertNotNull(obj);
+ }
+ }
+
+ public void testGetUDT() throws SQLException
+ {
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery("select (final-initial) as diff from test_interval");
+
+ while (rs.next() )
+ {
+ // make this return a PGobject
+ Object obj = rs.getObject(1, new HashMap());
+
+ // it should not be an instance of PGInterval
+ assertTrue(obj instanceof org.postgresql.util.PGInterval);
+
+ }
+
+ }
+
+}
[parent: 6248bce1c5e5]