You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2008/01/08 19:43:53 UTC
svn commit: r610094 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
Author: kmarsden
Date: Tue Jan 8 10:43:51 2008
New Revision: 610094
URL: http://svn.apache.org/viewvc?rev=610094&view=rev
Log:
DERBY-1368 EOFException when reading from blob's binary stream
This patch just adds a test. Bug was fixed previously with 10.2. I am not sure exactly which checkin fixed it.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?rev=610094&r1=610093&r2=610094&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java Tue Jan 8 10:43:51 2008
@@ -1877,5 +1877,77 @@
rs[0] = s.executeQuery("values (1), (2), (3)");
c.close();
}
+
+ /**
+ * EOFException when reading from blob's binary stream
+ * and calling length() twice
+ *
+ * Test with and without lengthless insert.
+ *
+ * @throws SQLException
+ * @throws IOException
+ */
+ public void testDerby1368() throws SQLException, IOException
+ {
+ testDerby1368(true);
+ testDerby1368(false);
+ }
+
+ /**
+ * EOFException when reading from blob's binary stream
+ * and calling length() twice
+ *
+ * @param lengthless Insert data with lengthless method.
+ * @throws SQLException
+ * @throws IOException
+ */
+ public void testDerby1368 (boolean lengthless) throws SQLException, IOException
+ {
+ Statement stmt = createStatement();
+ stmt.execute("create table T1368 (ID char(32) PRIMARY KEY, DATA blob(2G) not null)");
+
+ // add row
+ int length = 1024 * 1024;
+ byte[] data = new byte[length];
+ data[0] = 1;
+ data[1] = 2;
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+
+ PreparedStatement ps = prepareStatement("insert into T1368 (ID, DATA) values (?, ?)");
+
+ ps.setString(1, "id");
+ if (lengthless)
+ ps.setBinaryStream(2, bais);
+ else
+ ps.setBinaryStream(2, bais,length);
+ ps.execute();
+ ps.close();
+
+ // read row
+
+ ps = prepareStatement("select DATA from T1368 where ID = ?");
+ ps.setString(1, "id");
+ ResultSet rs = ps.executeQuery();
+ rs.next();
+ Blob b = rs.getBlob(1);
+
+
+ // test output
+ assertEquals(length,b.length());
+ InputStream in = b.getBinaryStream();
+ assertEquals(1, in.read());
+ //drain the stream
+ while (in.read() != -1 );
+ in.close();
+
+ in = b.getBinaryStream();
+ assertEquals(length,b.length());
+ assertEquals(1, in.read());
+
+ in.close();
+
+ rs.close();
+ stmt.executeUpdate("DROP TABLE T1368");
+ }
}