Add files from parent branch HEAD:
authorbranch-fixup <branch-fixup>
Wed, 17 Dec 2003 15:45:05 +0000 (15:45 +0000)
committerbranch-fixup <branch-fixup>
Wed, 17 Dec 2003 15:45:05 +0000 (15:45 +0000)
src/interfaces/jdbc/org/postgresql/test/jdbc2/OID74Test.java

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

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..3aacedc
--- /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$\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