]> granicus.if.org Git - postgresql/commitdiff
Additional jdbc regression tests submitted by Oliver Jowett. Some tests are
authorBarry Lind <barry@xythos.com>
Mon, 22 Sep 2003 05:38:01 +0000 (05:38 +0000)
committerBarry Lind <barry@xythos.com>
Mon, 22 Sep 2003 05:38:01 +0000 (05:38 +0000)
currently commented out, pending fixes for the bugs these tests uncovered.

 Modified Files:
  jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
  jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java
 Added Files:
  jdbc/org/postgresql/test/jdbc2/CursorFetchTest.java

src/interfaces/jdbc/org/postgresql/test/jdbc2/CursorFetchTest.java [new file with mode: 0644]
src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java

diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/CursorFetchTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/CursorFetchTest.java
new file mode 100644 (file)
index 0000000..def403f
--- /dev/null
@@ -0,0 +1,92 @@
+package org.postgresql.test.jdbc2;
+import java.sql.*;
+import junit.framework.TestCase;
+import org.postgresql.test.TestUtil;
+/*
+ *  Tests for using non-zero setFetchSize().
+ */
+public class CursorFetchTest extends TestCase
+{
+       private Connection con;
+       public CursorFetchTest(String name)
+       {
+               super(name);
+       }
+       protected void setUp() throws Exception
+       {
+               con = TestUtil.openDB();
+               TestUtil.createTable(con, "test_fetch", "value integer");
+               con.setAutoCommit(false);
+       }
+       protected void tearDown() throws Exception
+       {
+               con.rollback();
+               con.setAutoCommit(true);
+               TestUtil.dropTable(con, "test_fetch");
+               TestUtil.closeDB(con);
+       }
+       protected void createRows(int count) throws Exception
+       {
+               PreparedStatement stmt = con.prepareStatement("insert into test_fetch(value) values(?)");
+               for (int i = 0; i < count; ++i) {
+                       stmt.setInt(1,i);
+                       stmt.executeUpdate();
+               }
+       }
+
+       // Test various fetchsizes.
+       public void testBasicFetch() throws Exception
+       {
+               createRows(100);
+               PreparedStatement stmt = con.prepareStatement("select * from test_fetch order by value");
+               int[] testSizes = { 0, 1, 49, 50, 51, 99, 100, 101 };
+               for (int i = 0; i < testSizes.length; ++i) {
+                       stmt.setFetchSize(testSizes[i]);
+                       ResultSet rs = stmt.executeQuery();
+                       int count = 0;
+                       while (rs.next()) {
+                               assertEquals("query value error with fetch size " + testSizes[i], count, rs.getInt(1));
+                               ++count;
+                       }
+                       assertEquals("total query size error with fetch size " + testSizes[i], 100, count);
+               }
+       }
+
+       // Test odd queries that should not be transformed into cursor-based fetches.
+       public void TODO_FAILS_testInsert() throws Exception
+       {
+               // INSERT should not be transformed.
+               PreparedStatement stmt = con.prepareStatement("insert into test_fetch(value) values(1)");
+               stmt.setFetchSize(100); // Should be meaningless.
+               stmt.executeUpdate();
+       }
+
+       public void TODO_FAILS_testMultistatement() throws Exception
+       {
+               // Queries with multiple statements should not be transformed.
+
+               createRows(100); // 0 .. 99
+               PreparedStatement stmt = con.prepareStatement("insert into test_fetch(value) values(100); select * from test_fetch order by value");
+               stmt.setFetchSize(10);
+               ResultSet rs = stmt.executeQuery();
+               
+               int count = 0;
+               while (rs.next()) {
+                       assertEquals(count, rs.getInt(1));
+                       ++count;
+               }
+               assertEquals(101, count);
+       }       
+}
index 4a8548a3cf4f02d77b58d4053220f583e5409847..31af0c520b7f032730cdb547003aa2bc52d43ba0 100644 (file)
@@ -61,6 +61,7 @@ public class Jdbc2TestSuite extends TestSuite
                suite.addTestSuite(UpdateableResultTest.class );
 
                suite.addTestSuite(CallableStmtTest.class );
+               suite.addTestSuite(CursorFetchTest.class);
 
                // That's all folks
                return suite;
index aa5831385fc017e256ec42afdb173f8f8bb40411..aeb356f2b14f8adc960b7626fab26b19dc346fe7 100644 (file)
@@ -229,4 +229,37 @@ public class ServerPreparedStmtTest extends TestCase
                        TestUtil.dropTable(con, "testsps_bytea");
                }
        }
+
+       // Check statements are not transformed when they shouldn't be.
+       public void TODO_FAILS_testCreateTable() throws Exception {
+               // CREATE TABLE isn't supported by PREPARE; the driver should realize this and
+               // still complete without error.
+               PreparedStatement pstmt = con.prepareStatement("CREATE TABLE testsps_bad(data int)");
+               ((PGStatement)pstmt).setUseServerPrepare(true);
+               pstmt.executeUpdate();
+               TestUtil.dropTable(con, "testsps_bad");
+       }
+
+       public void TODO_FAILS_testMultistatement() throws Exception {
+               // Shouldn't try to PREPARE this one, if we do we get:
+               //   PREPARE x(int,int) AS INSERT .... $1 ; INSERT ... $2    -- syntax error
+               try {
+                       TestUtil.createTable(con, "testsps_multiple", "data int");
+                       PreparedStatement pstmt = con.prepareStatement("INSERT INTO testsps_multiple(data) VALUES (?); INSERT INTO testsps_multiple(data) VALUES (?)");
+                       ((PGStatement)pstmt).setUseServerPrepare(true);                 
+                       pstmt.setInt(1, 1);
+                       pstmt.setInt(2, 2);
+                       pstmt.executeUpdate(); // Two inserts.
+
+                       pstmt.setInt(1, 3);
+                       pstmt.setInt(2, 4);
+                       pstmt.executeUpdate(); // Two more inserts.
+                       
+                       ResultSet check = con.createStatement().executeQuery("SELECT COUNT(*) FROM testsps_multiple");
+                       assertTrue(check.next());
+                       assertEquals(4, check.getInt(1));
+               } finally {
+                       TestUtil.dropTable(con, "testsps_multiple");
+               }
+       }
 }