diff -X /tmp/exclude -Nacr jdbc/org/postgresql/test/TestUtil.java jdbc.test_exception_cleanups/org/postgresql/test/TestUtil.java *** jdbc/org/postgresql/test/TestUtil.java Tue Dec 2 15:13:57 2003 --- jdbc.test_exception_cleanups/org/postgresql/test/TestUtil.java Tue Dec 2 19:23:56 2003 *************** *** 59,97 **** /* * Helper - opens a connection. */ ! public static java.sql.Connection openDB() { ! try ! { ! Class.forName("org.postgresql.Driver"); ! return java.sql.DriverManager.getConnection(getURL(), getUser(), getPassword()); ! } ! catch (ClassNotFoundException ex) ! { ! TestCase.fail(ex.getMessage()); ! } ! catch (SQLException ex) ! { ! TestCase.fail(ex.getMessage()); ! } ! return null; } /* * Helper - closes an open connection. This rewrites SQLException to a failed * assertion. It's static so other classes can use it. */ ! public static void closeDB(Connection con) { ! try ! { ! if (con != null) ! con.close(); ! } ! catch (SQLException ex) ! { ! TestCase.fail(ex.getMessage()); ! } } /* --- 59,78 ---- /* * Helper - opens a connection. */ ! public static java.sql.Connection openDB() throws SQLException { ! org.postgresql.Driver.setLogLevel(org.postgresql.Driver.INFO); // Also loads class. ! return java.sql.DriverManager.getConnection(getURL(), getUser(), getPassword()); } /* * Helper - closes an open connection. This rewrites SQLException to a failed * assertion. It's static so other classes can use it. */ ! public static void closeDB(Connection con) throws SQLException { ! if (con != null) ! con.close(); } /* *************** *** 99,163 **** */ public static void createTable(Connection con, String table, ! String columns) { ! try ! { ! Statement st = con.createStatement(); ! try ! { ! // Drop the table ! dropTable(con, table); ! ! // Now create the table ! st.executeUpdate("create table " + table + " (" + columns + ")"); ! } ! finally ! { ! st.close(); ! } ! } ! catch (SQLException ex) ! { ! TestCase.fail(ex.getMessage()); } } /* * Helper - drops a table */ ! public static void dropTable(Connection con, String table) { ! try ! { ! Statement stmt = con.createStatement(); ! try ! { ! String sql = "DROP TABLE " + table; ! if (haveMinimumServerVersion(con,"7.3")) { ! sql += " CASCADE "; ! } ! stmt.executeUpdate(sql); ! } ! catch (SQLException ex) ! { ! // Since every create table issues a drop table ! // it's easy to get a table doesn't exist error. ! // we want to ignore these, but if we're in a ! // transaction we need to restart. ! // If the test case wants to catch this error ! // itself it should issue the drop SQL directly. ! if (ex.getMessage().indexOf("does not exist") != -1) { ! if (!con.getAutoCommit()) { ! con.rollback(); ! } ! ! } ! } ! } ! catch (SQLException ex) ! { ! TestCase.fail(ex.getMessage()); } } --- 80,120 ---- */ public static void createTable(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 table " + table + " (" + columns + ")"); ! } finally { ! st.close(); } } /* * Helper - drops a table */ ! public static void dropTable(Connection con, String table) throws SQLException { ! Statement stmt = con.createStatement(); ! try { ! String sql = "DROP TABLE " + table; ! if (haveMinimumServerVersion(con,"7.3")) { ! sql += " CASCADE "; ! } ! stmt.executeUpdate(sql); ! } catch (SQLException ex) { ! // Since every create table issues a drop table ! // it's easy to get a table doesn't exist error. ! // we want to ignore these, but if we're in a ! // transaction we need to restart. ! // If the test case wants to catch errors ! // itself it should issue the drop SQL directly. ! if (!con.getAutoCommit()) ! con.rollback(); } } diff -X /tmp/exclude -Nacr jdbc/org/postgresql/test/jdbc2/MiscTest.java jdbc.test_exception_cleanups/org/postgresql/test/jdbc2/MiscTest.java *** jdbc/org/postgresql/test/jdbc2/MiscTest.java Tue Dec 2 15:13:57 2003 --- jdbc.test_exception_cleanups/org/postgresql/test/jdbc2/MiscTest.java Tue Dec 2 19:23:56 2003 *************** *** 26,79 **** * * Added Feb 13 2001 */ ! public void testDatabaseSelectNullBug() { ! try ! { ! Connection con = TestUtil.openDB(); ! ! Statement st = con.createStatement(); ! ResultSet rs = st.executeQuery("select datname from pg_database"); ! assertNotNull(rs); ! ! while (rs.next()) { rs.getString(1); } ! ! rs.close(); ! st.close(); ! ! TestUtil.closeDB(con); ! } ! catch (Exception ex) ! { ! fail(ex.getMessage()); ! } } ! public void testError() { Connection con = TestUtil.openDB(); try { - // transaction mode con.setAutoCommit(false); Statement stmt = con.createStatement(); stmt.execute("select 1/0"); fail( "Should not execute this, as a SQLException s/b thrown" ); con.commit(); ! } ! catch ( Exception ex ) ! {} ! try ! { ! con.commit(); ! con.close(); ! } ! catch ( Exception ex) ! {} } public void xtestLocking() --- 26,65 ---- * * Added Feb 13 2001 */ ! public void testDatabaseSelectNullBug() throws SQLException { ! Connection con = TestUtil.openDB(); ! ! Statement st = con.createStatement(); ! ResultSet rs = st.executeQuery("select datname from pg_database"); ! assertNotNull(rs); ! ! while (rs.next()) { rs.getString(1); } ! ! rs.close(); ! st.close(); ! ! TestUtil.closeDB(con); } ! public void testError() throws SQLException { Connection con = TestUtil.openDB(); try { // transaction mode con.setAutoCommit(false); Statement stmt = con.createStatement(); stmt.execute("select 1/0"); fail( "Should not execute this, as a SQLException s/b thrown" ); con.commit(); ! } catch (SQLException ex) {} ! ! con.commit(); ! con.close(); } public void xtestLocking()