From b720fa96fb8e41ac077c1d710d8d3a26dcfd36c1 Mon Sep 17 00:00:00 2001 From: Dave Cramer <davec@fastcrypt.com> Date: Mon, 3 Nov 2003 15:28:26 +0000 Subject: [PATCH] patch for rs.previous and test case as well as patch for allowing server and port to be specified in test cases --- src/interfaces/jdbc/build.xml | 8 ++++++-- .../postgresql/jdbc2/AbstractJdbc2ResultSet.java | 3 ++- .../org/postgresql/test/jdbc2/ResultSetTest.java | 10 ++++++++++ .../test/jdbc2/optional/ConnectionPoolTest.java | 15 ++++----------- .../jdbc2/optional/PoolingDataSourceTest.java | 15 ++++----------- .../test/jdbc2/optional/SimpleDataSourceTest.java | 15 ++++----------- .../test/jdbc3/Jdbc3ConnectionPoolTest.java | 15 ++++----------- .../test/jdbc3/Jdbc3PoolingDataSourceTest.java | 14 ++++---------- .../test/jdbc3/Jdbc3SimpleDataSourceTest.java | 15 ++++----------- 9 files changed, 42 insertions(+), 68 deletions(-) diff --git a/src/interfaces/jdbc/build.xml b/src/interfaces/jdbc/build.xml index 633daa72db3..eccb81674dc 100644 --- a/src/interfaces/jdbc/build.xml +++ b/src/interfaces/jdbc/build.xml @@ -6,7 +6,7 @@ This file now requires Ant 1.4.1. 2002-04-18 - $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.36 2003/08/24 22:10:09 barry Exp $ + $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.37 2003/11/03 15:28:26 davec Exp $ --> @@ -305,7 +305,9 @@ <!-- This compiles and executes the JUnit tests --> <!-- defaults for the tests - override these if required --> - <property name="database" value="jdbc:postgresql:test" /> + <property name="server" value="localhost" /> + <property name="port" value="${def_pgport}" /> + <property name="database" value="test" /> <property name="username" value="test" /> <!-- Password must be something. Doesn't matter if trust is used! --> <property name="password" value="password" /> @@ -337,6 +339,8 @@ <junit> <formatter type="brief" usefile="false"/> + <sysproperty key="server" value="${server}" /> + <sysproperty key="port" value="${port}" /> <sysproperty key="database" value="${database}" /> <sysproperty key="username" value="${username}" /> <sysproperty key="password" value="${password}" /> diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java index b8590dff847..87992f7e44d 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java @@ -9,7 +9,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25 2003/10/29 02:39:09 davec Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.26 2003/11/03 15:28:26 davec Exp $ * *------------------------------------------------------------------------- */ @@ -493,6 +493,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra if (--current_row < 0) return false; this_row = (byte[][]) rows.elementAt(current_row); + rowBuffer = new byte[this_row.length][]; System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); return true; } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java index d7e621e20c6..c09ac49a982 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java @@ -83,6 +83,16 @@ public class ResultSetTest extends TestCase TestUtil.closeDB(con); } + public void testBackward() throws Exception + { + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT * FROM testrs"); + rs.afterLast(); + assertTrue(rs.previous()); + rs.close(); + stmt.close(); + } + public void testAbsolute() throws Exception { Statement stmt = con.createStatement(); diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java index 8f84193990a..caac23d18b2 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java @@ -11,7 +11,7 @@ import java.sql.*; * interface to the PooledConnection is through the CPDS. * * @author Aaron Mulder (ammulder@chariotsolutions.com) - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ public class ConnectionPoolTest extends BaseDataSourceTest { @@ -31,16 +31,9 @@ public class ConnectionPoolTest extends BaseDataSourceTest if (bds == null) { bds = new ConnectionPool(); - String db = TestUtil.getURL(); - if (db.indexOf('/') > -1) - { - db = db.substring(db.lastIndexOf('/') + 1); - } - else if (db.indexOf(':') > -1) - { - db = db.substring(db.lastIndexOf(':') + 1); - } - bds.setDatabaseName(db); + bds.setServerName(TestUtil.getServer()); + bds.setPortNumber(TestUtil.getPort()); + bds.setDatabaseName(TestUtil.getDatabase()); bds.setUser(TestUtil.getUser()); bds.setPassword(TestUtil.getPassword()); } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java index 9b08eca7d0c..6f4a6eaf376 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java @@ -9,7 +9,7 @@ import org.postgresql.jdbc2.optional.BaseDataSource; * Minimal tests for pooling DataSource. Needs many more. * * @author Aaron Mulder (ammulder@chariotsolutions.com) - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class PoolingDataSourceTest extends BaseDataSourceTest { @@ -40,16 +40,9 @@ public class PoolingDataSourceTest extends BaseDataSourceTest if (bds == null) { bds = new PoolingDataSource(); - String db = TestUtil.getURL(); - if (db.indexOf('/') > -1) - { - db = db.substring(db.lastIndexOf('/') + 1); - } - else if (db.indexOf(':') > -1) - { - db = db.substring(db.lastIndexOf(':') + 1); - } - bds.setDatabaseName(db); + bds.setServerName(TestUtil.getServer()); + bds.setPortNumber(TestUtil.getPort()); + bds.setDatabaseName(TestUtil.getDatabase()); bds.setUser(TestUtil.getUser()); bds.setPassword(TestUtil.getPassword()); ((PoolingDataSource) bds).setDataSourceName(DS_NAME); diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/SimpleDataSourceTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/SimpleDataSourceTest.java index b5c3e100ecd..40511222357 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/SimpleDataSourceTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/SimpleDataSourceTest.java @@ -8,7 +8,7 @@ import org.postgresql.jdbc2.optional.SimpleDataSource; * configuration logic. * * @author Aaron Mulder (ammulder@chariotsolutions.com) - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ public class SimpleDataSourceTest extends BaseDataSourceTest { @@ -28,16 +28,9 @@ public class SimpleDataSourceTest extends BaseDataSourceTest if (bds == null) { bds = new SimpleDataSource(); - String db = TestUtil.getURL(); - if (db.indexOf('/') > -1) - { - db = db.substring(db.lastIndexOf('/') + 1); - } - else if (db.indexOf(':') > -1) - { - db = db.substring(db.lastIndexOf(':') + 1); - } - bds.setDatabaseName(db); + bds.setServerName(TestUtil.getServer()); + bds.setPortNumber(TestUtil.getPort()); + bds.setDatabaseName(TestUtil.getDatabase()); bds.setUser(TestUtil.getUser()); bds.setPassword(TestUtil.getPassword()); } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3ConnectionPoolTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3ConnectionPoolTest.java index f679c48f77c..013a18a8f94 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3ConnectionPoolTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3ConnectionPoolTest.java @@ -12,7 +12,7 @@ import javax.sql.PooledConnection; * Tests JDBC3 implementation of ConnectionPoolDataSource. * * @author Aaron Mulder (ammulder@chariotsolutions.com) - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public class Jdbc3ConnectionPoolTest extends ConnectionPoolTest { @@ -29,16 +29,9 @@ public class Jdbc3ConnectionPoolTest extends ConnectionPoolTest if (bds == null) { bds = new Jdbc3ConnectionPool(); - String db = TestUtil.getURL(); - if (db.indexOf('/') > -1) - { - db = db.substring(db.lastIndexOf('/') + 1); - } - else if (db.indexOf(':') > -1) - { - db = db.substring(db.lastIndexOf(':') + 1); - } - bds.setDatabaseName(db); + bds.setServerName(TestUtil.getServer()); + bds.setPortNumber(TestUtil.getPort()); + bds.setDatabaseName(TestUtil.getDatabase()); bds.setUser(TestUtil.getUser()); bds.setPassword(TestUtil.getPassword()); } diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3PoolingDataSourceTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3PoolingDataSourceTest.java index 55374cb1b81..c6c603b7f0c 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3PoolingDataSourceTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3PoolingDataSourceTest.java @@ -13,7 +13,7 @@ import org.postgresql.jdbc2.optional.PoolingDataSource; * Minimal tests for JDBC3 pooling DataSource. Needs many more. * * @author Aaron Mulder (ammulder@chariotsolutions.com) - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class Jdbc3PoolingDataSourceTest extends PoolingDataSourceTest { @@ -42,15 +42,9 @@ public class Jdbc3PoolingDataSourceTest extends PoolingDataSourceTest private void configureDataSource(PoolingDataSource source) { String db = TestUtil.getURL(); - if (db.indexOf('/') > -1) - { - db = db.substring(db.lastIndexOf('/') + 1); - } - else if (db.indexOf(':') > -1) - { - db = db.substring(db.lastIndexOf(':') + 1); - } - source.setDatabaseName(db); + source.setServerName(TestUtil.getServer()); + source.setPortNumber(TestUtil.getPort()); + source.setDatabaseName(TestUtil.getDatabase()); source.setUser(TestUtil.getUser()); source.setPassword(TestUtil.getPassword()); source.setDataSourceName(DS_NAME); diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3SimpleDataSourceTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3SimpleDataSourceTest.java index cef4c83f651..7c1157deb31 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3SimpleDataSourceTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc3/Jdbc3SimpleDataSourceTest.java @@ -10,7 +10,7 @@ import org.postgresql.jdbc3.*; * Tests JDBC3 non-pooling DataSource. * * @author Aaron Mulder (ammulder@chariotsolutions.com) - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class Jdbc3SimpleDataSourceTest extends SimpleDataSourceTest { /** @@ -29,16 +29,9 @@ public class Jdbc3SimpleDataSourceTest extends SimpleDataSourceTest { if (bds == null) { bds = new Jdbc3SimpleDataSource(); - String db = TestUtil.getURL(); - if (db.indexOf('/') > -1) - { - db = db.substring(db.lastIndexOf('/') + 1); - } - else if (db.indexOf(':') > -1) - { - db = db.substring(db.lastIndexOf(':') + 1); - } - bds.setDatabaseName(db); + bds.setServerName(TestUtil.getServer()); + bds.setPortNumber(TestUtil.getPort()); + bds.setDatabaseName(TestUtil.getDatabase()); bds.setUser(TestUtil.getUser()); bds.setPassword(TestUtil.getPassword()); } -- GitLab