Skip to content

Commit b6385ef

Browse files
committed
Attached is a patch that fixes 2 test cases of the JDBC test
suite. This reduces the number of failures from 9 to 7. Both ConnectionTest and JBuilderTest did not create their own tables, which caused these test cases to fail with "relation ... does not exist". It appears these test cases relied on tables created by the example code elsewhere in the source tree. I've added the necessary "create table" and "drop table" statements to the test cases, using the column definitions from the example code. While working on that I modified the helper method createTable in JDBC2Tests.java to take a table parameter, rather than using table names passed via the properties in build.xml. I'm not sure what that was good for, and in fact, except for the default table name "jdbctest", this functionality wasn't used at all. Ren? Pijlman
1 parent 7066253 commit b6385ef

File tree

3 files changed

+79
-46
lines changed

3 files changed

+79
-46
lines changed

src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -59,49 +59,38 @@ public static void closeDB(Connection conn) {
5959
}
6060
}
6161

62-
/**
63-
* Helper - creates a test table for use by a test
64-
*/
65-
public static void createTable(Connection conn,String columns) {
66-
try {
67-
Statement st = conn.createStatement();
68-
69-
// Ignore the drop
70-
try {
71-
st.executeUpdate("drop table "+getTableName());
72-
} catch(SQLException se) {
73-
}
74-
75-
// Now create the table
76-
st.executeUpdate("create table "+getTableName()+" ("+columns+")");
77-
78-
st.close();
79-
} catch(SQLException ex) {
80-
TestCase.assert(ex.getMessage(),false);
81-
}
82-
}
83-
84-
/**
85-
* Variant used when more than one table is required
86-
*/
87-
public static void createTable(Connection conn,String id,String columns) {
88-
try {
89-
Statement st = conn.createStatement();
90-
91-
// Ignore the drop
92-
try {
93-
st.executeUpdate("drop table "+getTableName(id));
94-
} catch(SQLException se) {
95-
}
96-
97-
// Now create the table
98-
st.executeUpdate("create table "+getTableName(id)+" ("+columns+")");
99-
100-
st.close();
101-
} catch(SQLException ex) {
102-
TestCase.assert(ex.getMessage(),false);
103-
}
104-
}
62+
/**
63+
* Helper - creates a test table for use by a test
64+
*/
65+
public static void createTable(
66+
Connection conn, String table, String columns) {
67+
try {
68+
Statement st = conn.createStatement();
69+
try {
70+
try {
71+
st.executeUpdate("drop table " + table);
72+
} catch(SQLException se) {
73+
// Intentionally ignore exception
74+
}
75+
76+
// Now create the table
77+
st.executeUpdate( "create table " + table + " (" + columns +
78+
")" );
79+
} finally {
80+
st.close();
81+
}
82+
} catch(SQLException ex) {
83+
TestCase.assert(ex.getMessage(),false);
84+
}
85+
}
86+
87+
// Create the test table whose name is passed via the properties
88+
// (see ../../../build.xml). It appears that the original author of
89+
// this test suite intended to specify all test table names via the
90+
// properties, but this was never fully implemented.
91+
public static void createTable(Connection conn, String columns) {
92+
createTable(conn, getTableName(), columns);
93+
}
10594

10695
/**
10796
* Helper - generates INSERT SQL - very simple

src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* PS: Do you know how difficult it is to type on a train? ;-)
1212
*
13-
* $Id: ConnectionTest.java,v 1.2 2001/02/13 16:39:05 peter Exp $
13+
* $Id: ConnectionTest.java,v 1.3 2001/09/07 22:17:48 momjian Exp $
1414
*/
1515

1616
public class ConnectionTest extends TestCase {
@@ -22,6 +22,30 @@ public ConnectionTest(String name) {
2222
super(name);
2323
}
2424

25+
// Set up the fixture for this testcase: the tables for this test.
26+
protected void setUp() throws Exception {
27+
Connection con = JDBC2Tests.openDB();
28+
29+
JDBC2Tests.createTable( con, "test_a",
30+
"imagename name,image oid,id int4" );
31+
32+
JDBC2Tests.createTable( con, "test_c",
33+
"source text,cost money,imageid int4" );
34+
35+
JDBC2Tests.closeDB(con);
36+
}
37+
38+
// Tear down the fixture for this test case.
39+
protected void tearDown() throws Exception {
40+
Connection con = JDBC2Tests.openDB();
41+
Statement stmt = con.createStatement();
42+
43+
stmt.executeUpdate("DROP TABLE test_a");
44+
stmt.executeUpdate("DROP TABLE test_c");
45+
stmt.close();
46+
JDBC2Tests.closeDB(con);
47+
}
48+
2549
/**
2650
* Tests the two forms of createStatement()
2751
*/
@@ -234,4 +258,4 @@ public void testTypeMaps() {
234258
assert(ex.getMessage(),false);
235259
}
236260
}
237-
}
261+
}

src/interfaces/jdbc/org/postgresql/test/jdbc2/JBuilderTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.math.BigDecimal;
77

88
/**
9-
* $Id: JBuilderTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $
9+
* $Id: JBuilderTest.java,v 1.2 2001/09/07 22:17:48 momjian Exp $
1010
*
1111
* Some simple tests to check that the required components needed for JBuilder
1212
* stay working
@@ -18,6 +18,26 @@ public JBuilderTest(String name) {
1818
super(name);
1919
}
2020

21+
// Set up the fixture for this testcase: the tables for this test.
22+
protected void setUp() throws Exception {
23+
Connection con = JDBC2Tests.openDB();
24+
25+
JDBC2Tests.createTable( con, "test_c",
26+
"source text,cost money,imageid int4" );
27+
28+
JDBC2Tests.closeDB(con);
29+
}
30+
31+
// Tear down the fixture for this test case.
32+
protected void tearDown() throws Exception {
33+
Connection con = JDBC2Tests.openDB();
34+
Statement stmt = con.createStatement();
35+
36+
stmt.executeUpdate("DROP TABLE test_c");
37+
stmt.close();
38+
JDBC2Tests.closeDB(con);
39+
}
40+
2141
/**
2242
* This tests that Money types work. JDBCExplorer barfs if this fails.
2343
*/

0 commit comments

Comments
 (0)