]> granicus.if.org Git - postgresql/commitdiff
back patching fix for compat 7.1 binary stream issues with the new protocol
authorDave Cramer <davec@fastcrypt.com>
Wed, 17 Dec 2003 15:48:40 +0000 (15:48 +0000)
committerDave Cramer <davec@fastcrypt.com>
Wed, 17 Dec 2003 15:48:40 +0000 (15:48 +0000)
added test for same

src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java
src/interfaces/jdbc/org/postgresql/largeobject/LargeObjectManager.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/OID74Test.java [new file with mode: 0644]

index 6235651fed362edd4971fae27cd5ffe298094bd0..193de9e6105cf9155e9d29381f5b12d6387f00f5 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.16 2003/09/13 04:02:13 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.16.2.1 2003/12/17 15:48:39 davec Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -63,7 +63,7 @@ public class Fastpath
         */
        public Object fastpath(int fnid, boolean resulttype, FastpathArg[] args) throws SQLException
        {
-               if (conn.haveMinimumServerVersion("7.4")) {
+               if (conn.haveMinimumCompatibleVersion("7.4")) {
                        return fastpathV3(fnid, resulttype, args);
                } else {
                        return fastpathV2(fnid, resulttype, args);
index 48743467db7f628c105de5de0352a050537f8904..f49103f56eb9b8de4a0aa756bd89ca0f423287cf 100644 (file)
@@ -11,7 +11,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/largeobject/Attic/LargeObjectManager.java,v 1.10 2003/03/07 18:39:45 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/largeobject/Attic/LargeObjectManager.java,v 1.10.4.1 2003/12/17 15:48:39 davec Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -116,7 +116,7 @@ public class LargeObjectManager
                if (conn.getMetaData().supportsSchemasInTableDefinitions()) {
                        sql = "SELECT p.proname,p.oid "+
                                " FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n "+
-                               " WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND ";
+                               " WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND (";
                } else {
                        sql = "SELECT proname,oid FROM pg_proc WHERE ";
                }
@@ -129,6 +129,10 @@ public class LargeObjectManager
                        " or proname = 'loread'" +
                        " or proname = 'lowrite'";
 
+               if (conn.getMetaData().supportsSchemasInTableDefinitions()) {
+                       sql += ")";
+               }
+
                ResultSet res = conn.createStatement().executeQuery(sql);
 
                if (res == null)
index 31af0c520b7f032730cdb547003aa2bc52d43ba0..7a5acab8e26bab4a8b3f14cf9635a2a803eff3e4 100644 (file)
@@ -57,6 +57,7 @@ public class Jdbc2TestSuite extends TestSuite
 
                // Fastpath/LargeObject
                suite.addTestSuite(BlobTest.class);
+               suite.addTestSuite(OID74Test.class);
 
                suite.addTestSuite(UpdateableResultTest.class );
 
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/OID74Test.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/OID74Test.java
new file mode 100644 (file)
index 0000000..ada46e6
--- /dev/null
@@ -0,0 +1,99 @@
+package org.postgresql.test.jdbc2;\r
+                                                                                                                                                                                     \r
+import org.postgresql.test.TestUtil;\r
+import junit.framework.TestCase;\r
+import java.io.*;\r
+import java.sql.*;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.InputStream;\r
+import java.sql.*;\r
+\r
+/**\r
+ * User: alexei\r
+ * Date: 17-Dec-2003\r
+ * Time: 11:01:44\r
+ * @version $Id: OID74Test.java,v 1.2.2.1 2003/12/17 15:48:40 davec Exp $\r
+ */\r
+public class OID74Test  extends TestCase\r
+{\r
+       private Connection con;\r
+    \r
+\r
+       public OID74Test( String name )\r
+       {\r
+               super(name);\r
+       }\r
+       public void setUp() throws Exception\r
+       {\r
+       }\r
+       public void tearDown() throws Exception\r
+       {\r
+       }\r
+       public void testBinaryStream()\r
+       {\r
+               //set up conection here\r
+               Connection c = null;\r
+               \r
+               Statement st = null; \r
+               try \r
+               {\r
+                       c =  DriverManager.getConnection("jdbc:postgresql://localhost/test?compatible=7.1&user=test");\r
+                       c.setAutoCommit(false);\r
+                       st = c.createStatement();\r
+                       st.execute("CREATE temp TABLE temp (col oid)");\r
+               }\r
+                catch (SQLException e) \r
+               {\r
+                       //another issue: when connecting to 7.3 database and this exception occurs because the table already exists,\r
+                       //st.setBinaryStream throws internal error in LargeObjectManager initialisation code\r
+                       fail("table creating error, probably already exists, code=" + e.getErrorCode());\r
+               }\r
+               finally\r
+               {\r
+                       try{ if (st != null) st.close(); }catch(SQLException ex){};\r
+               }\r
+               \r
+               PreparedStatement pstmt = null;\r
+               try \r
+               {\r
+               \r
+                       pstmt = c.prepareStatement("INSERT INTO temp VALUES (?)");\r
+                       //in case of 7.4 server, should block here\r
+                       pstmt.setBinaryStream(1, new ByteArrayInputStream(new byte[]{1, 2, 3, 4, 5}), 5);\r
+                       assertTrue( (pstmt.executeUpdate() == 1) );\r
+                       pstmt.close();\r
+               \r
+                       pstmt = c.prepareStatement("SELECT col FROM temp LIMIT 1");\r
+                       ResultSet rs = pstmt.executeQuery();\r
+\r
+                       assertTrue("No results from query", rs.next() );\r
+\r
+                       //in case of 7.4 server, should block here\r
+                       InputStream in = rs.getBinaryStream(1);\r
+                       int data;\r
+                       while ((data = in.read()) != -1)\r
+                               System.out.println(data);\r
+                       rs.close();\r
+                       st.close();\r
+                       c.createStatement().executeUpdate("DELETE FROM temp");\r
+                       c.commit();\r
+               }\r
+               catch ( IOException ioex )\r
+               {\r
+                       fail( ioex.getMessage() );\r
+               }\r
+               catch (SQLException ex)\r
+               {\r
+                       fail( ex.getMessage() );\r
+               } \r
+               finally \r
+               {\r
+                       try\r
+                       {\r
+                               if ( c!=null) c.close();\r
+                       }\r
+                       catch( SQLException e1){}\r
+               }\r
+       }       \r
+}\r