diff -X /tmp/exclude -Nacr jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java jdbc.serverprepare_rollback_tests/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java *** jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java Mon Sep 22 17:38:01 2003 --- jdbc.serverprepare_rollback_tests/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java Tue Dec 2 19:38:32 2003 *************** *** 6,11 **** --- 6,12 ---- import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; + import java.sql.SQLException; import junit.framework.TestCase; *************** *** 262,265 **** --- 263,316 ---- TestUtil.dropTable(con, "testsps_multiple"); } } + + public void testPrepareRollbackExecute() throws Exception { + // Driver needs to work out that the PREPARE failed and it should not + // try to EXECUTE it subsequently. + + con.setAutoCommit(false); + + // Cause a deliberate error + try { + con.createStatement().executeQuery("deliberate error"); + fail("Didn't generate an exception"); + } catch (SQLException e) {} + + PreparedStatement pstmt = con.prepareStatement("SELECT 1"); + ((PGStatement)pstmt).setUseServerPrepare(true); + + try { + pstmt.executeQuery(); + fail("Didn't generate an exception"); + } catch (SQLException e) {} + + // Now try the (valid) prepared statement in a fresh txn + con.rollback(); + pstmt.executeQuery(); // Should not generate an exception. + } + + public void testPrepareRollbackDeallocate() throws Exception { + // Driver needs to work out that the PREPARE failed and it should not + // try to DEALLOCATE it subsequently. + + con.setAutoCommit(false); + + // Cause a deliberate error + try { + con.createStatement().executeQuery("deliberate error"); + fail("Didn't generate an exception"); + } catch (SQLException e) {} + + PreparedStatement pstmt = con.prepareStatement("SELECT 1"); + ((PGStatement)pstmt).setUseServerPrepare(true); + + try { + pstmt.executeQuery(); + fail("Didn't generate an exception"); + } catch (SQLException e) {} + + con.rollback(); + pstmt.close(); // Should *not* DEALLOCATE as this will cause an error. + con.createStatement().executeQuery("SELECT 1"); // Should not generate an exception. + } }