protected void tearDown() throws Exception { // System.err.println("++++++ TESTS END (" + getName() + ") ++++++"); TimeZone.setDefault(saveTZ); TestUtil.dropTable(con, "testtimezone"); TestUtil.closeDB(con); }
/** * Ensure the cancel call does not return before it has completed. Previously it did which * cancelled future queries. */ public void testSingleThreadCancel() throws Exception { Connection con = TestUtil.openDB(); Statement stmt = con.createStatement(); for (int i = 0; i < 100; i++) { ResultSet rs = stmt.executeQuery("SELECT 1"); rs.close(); stmt.cancel(); } TestUtil.closeDB(con); }
public void xtestLocking() throws Exception { Connection con = TestUtil.openDB(); Connection con2 = TestUtil.openDB(); TestUtil.createTable(con, "test_lock", "name text"); Statement st = con.createStatement(); Statement st2 = con2.createStatement(); con.setAutoCommit(false); st.execute("lock table test_lock"); st2.executeUpdate("insert into test_lock ( name ) values ('hello')"); con.commit(); TestUtil.dropTable(con, "test_lock"); con.close(); con2.close(); }
/* * Some versions of the driver would return rs as a null? * * Sasha <*****@*****.**> was having this problem. * * Added Feb 13 2001 */ public void testDatabaseSelectNullBug() throws Exception { 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); }
protected void setUp() throws Exception { _conn = TestUtil.openDB(); Statement stmt = _conn.createStatement(); stmt.execute("CREATE TEMP TABLE hold(a int)"); stmt.execute("INSERT INTO hold VALUES (1)"); stmt.execute("INSERT INTO hold VALUES (2)"); stmt.close(); }
/* * (non-Javadoc) * * @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception { Statement stmt = con.createStatement(); stmt.execute("drop function Numeric_Proc(out decimal, out decimal, out decimal)"); stmt.execute("drop function test_somein_someout(int4)"); stmt.execute("drop function test_allinout( inout int4, inout varchar, inout int8)"); stmt.execute("drop function mysum(a int, b int)"); stmt.execute("drop function myiofunc(a INOUT int, b OUT int) "); stmt.execute("drop function myif(a INOUT int, b IN int)"); stmt.close(); TestUtil.closeDB(con); }
protected void setUp() throws Exception { // We must change the default TZ before establishing the connection. TimeZone.setDefault( TimeZone.getTimeZone("GMT+01")); // Arbitrary timezone that doesn't match our test timezones connect(); TestUtil.createTable( con, "testtimezone", "seq int4, tstz timestamp with time zone, ts timestamp without time zone, t time without time zone, tz time with time zone, d date"); // This is not obvious, but the "gmt-3" timezone is actually 3 hours *ahead* of GMT // so will produce +03 timestamptz output con.createStatement().executeUpdate("set timezone = 'gmt-3'"); min73 = TestUtil.haveMinimumServerVersion(con, "7.3"); min74 = TestUtil.haveMinimumServerVersion(con, "7.4"); // System.err.println("++++++ TESTS START (" + getName() + ") ++++++"); }
@Override public void setUp() throws Exception { super.setUp(); TestUtil.createTable( con, "BugFreezeTable", "Col1 INTEGER NOT NULL," + "Col2 DATE NOT NULL," + "Col3 DOUBLE PRECISION NULL," + "Col4 SMALLINT NOT NULL," + "Col5 NUMERIC (10) NULL," + "Col6 DATE NULL," + "Col7 NUMERIC (10) NOT NULL," + "Col8 NUMERIC (10) NULL"); }
public void testTimezoneWithSeconds() throws SQLException { if (!TestUtil.haveMinimumServerVersion(con, "8.2")) return; Statement stmt = con.createStatement(); stmt.execute("SET TimeZone = 'Europe/Paris'"); for (int i = 0; i < PREPARE_THRESHOLD; i++) { PreparedStatement ps = con.prepareStatement("SELECT '1920-01-01'::timestamptz"); ResultSet rs = ps.executeQuery(); rs.next(); // select extract(epoch from '1920-01-01'::timestamptz - 'epoch'::timestamptz) * 1000; assertEquals(-1577923200000L, rs.getTimestamp(1).getTime()); ps.close(); } }
/* * (non-Javadoc) * * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { con = TestUtil.openDB(); Statement stmt = con.createStatement(); stmt.execute( "create temp table numeric_tab (MAX_VAL NUMERIC(30,15), MIN_VAL NUMERIC(30,15), NULL_VAL NUMERIC(30,15) NULL)"); stmt.execute("insert into numeric_tab values ( 999999999999999,0.000000000000001, null)"); stmt.execute( "CREATE OR REPLACE FUNCTION mysum(a int, b int) returns int AS 'BEGIN return a + b; END;' LANGUAGE plpgsql"); stmt.execute( "CREATE OR REPLACE FUNCTION myiofunc(a INOUT int, b OUT int) AS 'BEGIN b := a; a := 1; END;' LANGUAGE plpgsql"); stmt.execute( "CREATE OR REPLACE FUNCTION myif(a INOUT int, b IN int) AS 'BEGIN a := b; END;' LANGUAGE plpgsql"); stmt.execute( "create or replace function " + "Numeric_Proc( OUT IMAX NUMERIC(30,15), OUT IMIN NUMERIC(30,15), OUT INUL NUMERIC(30,15)) as " + "'begin " + "select max_val into imax from numeric_tab;" + "select min_val into imin from numeric_tab;" + "select null_val into inul from numeric_tab;" + " end;' " + "language plpgsql;"); stmt.execute( "CREATE OR REPLACE FUNCTION test_somein_someout(" + "pa IN int4," + "pb OUT varchar," + "pc OUT int8)" + " AS " + "'begin " + "pb := ''out'';" + "pc := pa + 1;" + "end;'" + "LANGUAGE plpgsql VOLATILE;"); stmt.execute( "CREATE OR REPLACE FUNCTION test_allinout(" + "pa INOUT int4," + "pb INOUT varchar," + "pc INOUT int8)" + " AS " + "'begin " + "pa := pa + 1;" + "pb := ''foo out'';" + "pc := pa + 1;" + "end;'" + "LANGUAGE plpgsql VOLATILE;"); }
private void checkDatabaseContents(String query, String[][] correct) throws Exception { Connection con2 = TestUtil.openDB(); Statement s = con2.createStatement(); assertFalse(s.execute("set time zone 'UTC'")); assertTrue(s.execute(query)); ResultSet rs = s.getResultSet(); for (int j = 0; j < correct.length; ++j) { assertTrue(rs.next()); for (int i = 0; i < correct[j].length; ++i) { assertEquals("On row " + (j + 1), correct[j][i], rs.getString(i + 1)); } } assertFalse(rs.next()); rs.close(); s.close(); con2.close(); }
public void testWarning() throws Exception { Connection con = TestUtil.openDB(); Statement stmt = con.createStatement(); stmt.execute("CREATE TEMP TABLE t(a int primary key)"); SQLWarning warning = stmt.getWarnings(); // We should get a warning about primary key index creation // it's possible we won't depending on the server's // client_min_messages setting. while (warning != null) { // Verify that the SQLWarning is serializable. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(warning); oos.close(); warning = warning.getNextWarning(); } stmt.close(); con.close(); }
public void testError() throws Exception { 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) { // Verify that the SQLException is serializable. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ex); oos.close(); } con.commit(); con.close(); }
@Override public void tearDown() throws SQLException { TestUtil.dropTable(con, "BugFreezeTable"); super.tearDown(); }
private void connect() throws Exception { Properties p = new Properties(); PGProperty.PREPARE_THRESHOLD.set(p, 1); con = TestUtil.openDB(p); }
protected void tearDown() throws SQLException { Statement stmt = _conn.createStatement(); stmt.execute("DROP TABLE hold"); stmt.close(); TestUtil.closeDB(_conn); }