aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/test/jdbc2
diff options
context:
space:
mode:
authorBarry Lind <barry@xythos.com>2003-05-03 20:40:45 +0000
committerBarry Lind <barry@xythos.com>2003-05-03 20:40:45 +0000
commit5295fffc26d9bb02fc3b51cbb4f7de744ee50046 (patch)
tree73ca858d05b3272bdd243aaadc927dafdf8d2467 /src/interfaces/jdbc/org/postgresql/test/jdbc2
parent721996d88906393b5f9fb4191e8c54726fa478fc (diff)
downloadpostgresql-5295fffc26d9bb02fc3b51cbb4f7de744ee50046.tar.gz
postgresql-5295fffc26d9bb02fc3b51cbb4f7de744ee50046.zip
Patch to fix up LONGVARBINARY support submitted by Amit Gollapudi
(agollapudi@demandsolutions.com). Also applied the RefCursor support patch by Nic Ferrier. This patch allows you too return a get a result set from a function that returns a refcursor. For example: call.registerOutParameter(1, Types.OTHER); call.execute(); ResultSet rs = (ResultSet) call.getObject(1); Modified Files: jdbc/org/postgresql/core/BaseStatement.java jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java jdbc/org/postgresql/jdbc1/Jdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java jdbc/org/postgresql/jdbc2/Jdbc2Statement.java jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java jdbc/org/postgresql/jdbc3/Jdbc3Statement.java Added Files: jdbc/org/postgresql/PGRefCursorResultSet.java jdbc/org/postgresql/jdbc1/Jdbc1RefCursorResultSet.java jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java jdbc/org/postgresql/jdbc3/Jdbc3RefCursorResultSet.java jdbc/org/postgresql/test/jdbc2/RefCursorTest.java
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/test/jdbc2')
-rw-r--r--src/interfaces/jdbc/org/postgresql/test/jdbc2/RefCursorTest.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/RefCursorTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/RefCursorTest.java
new file mode 100644
index 00000000000..a3ce71cb155
--- /dev/null
+++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/RefCursorTest.java
@@ -0,0 +1,100 @@
+package org.postgresql.test.jdbc2;
+
+import org.postgresql.test.TestUtil;
+import junit.framework.TestCase;
+import java.io.*;
+import java.sql.*;
+
+/*
+ * RefCursor ResultSet tests.
+ * This test case is basically the same as the ResultSet test case.
+ *
+ * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
+ */
+public class RefCursorTest extends TestCase
+{
+ private Connection con;
+
+ public RefCursorTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ // this is the same as the ResultSet setup.
+ con = TestUtil.openDB();
+ Statement stmt = con.createStatement();
+
+ TestUtil.createTable(con, "testrs", "id integer");
+
+ stmt.executeUpdate("INSERT INTO testrs VALUES (1)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (2)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (3)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (4)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (6)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (9)");
+
+
+ // Create the functions.
+ stmt.execute ("CREATE OR REPLACE FUNCTION testspg__getRefcursor () RETURNS refcursor AS '"
+ + "declare v_resset; begin open v_resset for select id from testrs order by id; "
+ + "return v_resset; end;' LANGUAGE 'plpgsql';");
+ stmt.execute ("CREATE OR REPLACE FUNCTION testspg__getEmptyRefcursor () RETURNS refcursor AS '"
+ + "declare v_resset; begin open v_resset for select id from testrs where id < 1 order by id; "
+ + "return v_resset; end;' LANGUAGE 'plpgsql';");
+ stmt.close();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ Statement stmt = con.createStatement ();
+ stmt.execute ("drop FUNCTION testspg__getRefcursor ();");
+ stmt.execute ("drop FUNCTION testspg__getEmptyRefcursor ();");
+ TestUtil.dropTable(con, "testrs");
+ TestUtil.closeDB(con);
+ }
+
+ public void testResult() throws Exception
+ {
+ CallableStatement call = con.prepareCall("{ ? = call testspg__getRefcursor () }");
+ call.registerOutParameter(1, Types.OTHER);
+ call.execute();
+ ResultSet rs = (ResultSet) call.getObject(1);
+
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 1);
+
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 2);
+
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 3);
+
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 4);
+
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 6);
+
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 9);
+
+ assertTrue(!rs.next());
+
+ call.close();
+ }
+
+
+ public void testEmptyResult() throws Exception
+ {
+ CallableStatement call = con.prepareCall("{ ? = call testspg__getRefcursor () }");
+ call.registerOutParameter(1, Types.OTHER);
+ call.execute();
+
+ ResultSet rs = (ResultSet) call.getObject(1);
+ assertTrue(!rs.next());
+
+ call.close();
+ }
+}