Hi,
Thanks!
You are right, this is a bug (only when using the server mode by the way).
I didn't know the BLOB/CLOB needs to stay open when the result set is
closed. The result set is also closed when there are no more rows, that's
why case A fails as well.
This will be fixed in the next release. I hope I can completely get rid of
the BLOB/CLOB temp files when using the server mode, but I'm not sure yet.
Regards,
Thomas
On Monday, November 28, 2011, Christian Bauer wrote:
> The following test fails on H2 but works on Derby:
>
> public static void main(String args[]) throws Exception {
> Connection conn =
> DriverManager.getConnection("jdbc:derby:test;create=true");
> //Connection conn =
> DriverManager.getConnection("jdbc:h2:tcp://localhost/mem:test", "sa", "");
>
> conn.createStatement().executeUpdate("drop table ITEM");
> //conn.createStatement().executeUpdate("drop table if exists ITEM");
> conn.createStatement().executeUpdate("create table ITEM (FOO blob)");
> conn.setAutoCommit(false);
>
> // INSERT
> PreparedStatement statement = conn.prepareStatement("insert into ITEM
> (FOO) values (?)");
> byte[] bytes = new byte[131072];
> new Random().nextBytes(bytes);
> statement.setBinaryStream(1, new ByteArrayInputStream(bytes));
> int result = statement.executeUpdate();
> assert result == 1;
> statement.close();
> conn.commit();
>
> // SELECT
> ResultSet rs = conn.createStatement().executeQuery("select * from
> ITEM");
> Blob blob = null;
> while(rs.next()) {
> blob = rs.getBlob(1);
> // Works
> //assert blob != null;
> //bytes = blob.getBytes(1, (int)blob.length());
> //assert bytes.length == 131072;
> }
>
> // Failure A
> //assert blob != null;
> //bytes = blob.getBytes(1, (int)blob.length());
> //assert bytes.length == 131072;
>
> rs.close();
>
> // Failure B
> //assert blob != null;
> //bytes = blob.getBytes(1, (int)blob.length());
> //assert bytes.length == 131072;
>
> conn.commit();
>
> // Failure C
> //assert blob != null;
> //bytes = blob.getBytes(1, (int)blob.length());
> //assert bytes.length == 131072;
>
> conn.close();
> }
>
> Expected is that Failure A and B pass, as they do on Derby. H2 seems to
> restrict the validity of the blob to the iteration of the ResultSet, not
> even the open/close status of the ResultSet. It should use the transaction
> scope.
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To post to this group, send email to
> [email protected]<javascript:;>
> .
> To unsubscribe from this group, send email to
> [email protected] <javascript:;>.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.