### Eclipse Workspace Patch 1.0 #P postgres jdbc Index: org/postgresql/test/TestUtil.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/TestUtil.java,v retrieving revision 1.22 diff -u -r1.22 TestUtil.java --- org/postgresql/test/TestUtil.java 1 Dec 2006 08:53:46 -0000 1.22 +++ org/postgresql/test/TestUtil.java 6 Feb 2007 09:27:07 -0000 @@ -218,6 +218,29 @@ } /* + * Helper - creates a test function for use by a test + */ + public static void createFunction(Connection con, + String function, + String args, + String returnType, + String body) throws SQLException + { + Statement st = con.createStatement(); + try + { + String sql = "CREATE OR REPLACE FUNCTION " + function + "(" + args + ") "; + sql += "RETURNS " + returnType + " AS "; + sql += "$BODY$ BEGIN " + body + " END; $BODY$ LANGUAGE 'plpgsql' VOLATILE"; + st.executeUpdate(sql); + } + finally + { + st.close(); + } + } + + /* * drop a sequence because older versions don't have dependency * information for serials */ @@ -262,6 +285,29 @@ } } + public static void dropFunction(Connection con, String function) throws SQLException + { + Statement stmt = con.createStatement(); + try + { + String sql = "DROP FUNCTION " + function +";"; + stmt.executeUpdate(sql); + } + finally + { + stmt.close(); + } +// 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 then we've got trouble +// if (!con.getAutoCommit()) +// throw ex; +// } + } + /* * Helper - generates INSERT SQL - very simple */