db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: How are we supposed to use Blob.getBinaryStream(long, long) ?
Date Mon, 16 Feb 2009 16:25:41 GMT
Daniel Noll <daniel@nuix.com> writes:

> If everything in this Javadoc is true then it is in fact *impossible*
> to read the final byte of the blob.
>
> Suppose you have a blob of length 20, and you want to read bytes 11
> through 20.  You pass 11 as the starting position (indexed from 1, so
> it's actually byte 10 of the original byte array) and length 10.  This
> then throws an SQLException, because 11 + 10 = 21, which is greater
> than 20, so you can't do that.

My guess is that this is a typo in the JDBC spec and that the intention
is that it should be possible to fetch the last byte too. (The same
wording is used in Clob.getCharacterStream(long,long) by the way.)

> And Derby is completely faithful to this seemingly ridiculous rule:
>
>     java.sql.SQLException: Sum of position('11') and length('10') is
>         greater than the size of the LOB.
>
> So what are we supposed to do, use this method to read all chunks
> *except* the last one, and then use getBytes(long,long) to read the
> last chunk?

Right, that's one possible workaround. Please file a bug report against
Derby so that we can get this fixed.

> P.S. you can pass length 9 here to make Derby happy.  Then you receive
> an InputStream where you can only read 9 bytes before the read loop
> goes into an infinite loop, due to Derby's read(byte[],int,int)
> returning 0 at EOS instead of -1.

And another bug report for this one, please. :)

Thanks for letting us know about these problems.

-- 
Knut Anders

Mime
View raw message