I am new to this issue and have not reviewed the patch yet. I am just
trying to understand what the correct behavior is. If this has
already been discussed feel free to point that out.I know Sunitha
submitted some fixes in this area, but she will not be able to look
at these for awhile.
In your test it is obvious that the first instance of the stream can
not be used anymore since you use the same variable. What if the
test instead did:
InputStream is1 = rs.getBinaryStream(1);
System.out.println("Here goes first stream");
System.out.println(is1.read());
System.out.println(is1.read());
System.out.println(is1.read());
InputStream is2 = rs.getBinaryStream(1);
System.out.println("Here goes 2nd stream");
System.out.println(is2.read());
System.out.println(is2.read());
System.out.println(is2.read());
System.out.println("Here goes first stream continuing");
System.out.println(is1.read());
System.out.println(is1.read());
System.out.println(is1.read());
Also if you have not done so, please always test a short blob (ie.
something shorter than 4k and a long blob (something longer than
32k or whatever is the page size of the table being used). There
are 2 very different paths through the code, depending on size of
the datatypes. In the short case they are passed around in memory
as a single object and in the long case there is an underlying
stream that should only be read once. I believe the new test covers
a lot of these cases.
My main concern with stream issues is that it should always be
possible to write a program that reads and/or writes as a stream
and Derby should never need to instantiate the complete blob/clob
in memory. Historically this has been broken many times, I believe
I believe sunitha added a range of tests to the "large" suite so
you should run that suite with your change also.
Tomohito Nakayama (JIRA) wrote:
[ http://issues.apache.org/jira/browse/DERBY-721?page=all ]
Tomohito Nakayama updated DERBY-721:
------------------------------------
Attachment: DERBY-721_3.patch
Description of patch :
I judged that SQLException should not be thrown in
InputStream#close/Reader#close.
I remove calling resetStream method from close method and
implemented Resetable interface in UTF8Reader and BinaryToRawStream and
reset them from EmbedResultSet.
Test of patch:
I executed derbyall and does not found new error.
State of InputStream retrieved from resultset is not clean , if there exists
previous InputStream .
---------------------------------------------------------------------------------------------------
Key: DERBY-721
URL: http://issues.apache.org/jira/browse/DERBY-721
Project: Derby
Type: Bug
Components: Unknown
Environment: [EMAIL PROTECTED]:~/derby/dev/trunk$ cat /proc/version
Linux version 2.6.12-1-386 ([EMAIL PROTECTED]) (gcc version 4.0.2 20050917 (prerelease) (Debian 4.0.1-8)) #1 Tue Sep 27 12:41:08 JST 2005
[EMAIL PROTECTED]:~/derby/dev/trunk$ java -version
java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot(TM) Client VM (build 1.4.2_10-b03, mixed mode)
Reporter: Tomohito Nakayama
Assignee: Tomohito Nakayama
Attachments: DERBY-721.patch, DERBY-721_2.patch, DERBY-721_3.patch,
testLob.java, testLob2.java, testResult.txt, testResult2.txt
State of InputStream retrieved from ResultSet was not clean , if there exists
previous InputStream retrieved from ResultSet .
Test code ...
PreparedStatement pst = conn.prepareStatement("insert into a(b)
values(?)");
byte[] data = new byte[1024 * 1024];
for(int i = 0;
i < 1024 * 1024;
i ++){
data[i] = (byte)(i % 256);
}
pst.setBinaryStream(1,new ByteArrayInputStream(data),data.length);
pst.executeUpdate();
pst.close();
st = conn.createStatement();
ResultSet rs = st.executeQuery("select b from a");
rs.next();
InputStream is = rs.getBinaryStream(1);
System.out.println("Here goes first stream");
System.out.println(is.read());
System.out.println(is.read());
System.out.println(is.read());
is = rs.getBinaryStream(1);
System.out.println("Here goes 2nd stream");
System.out.println(is.read());
System.out.println(is.read());
System.out.println(is.read());
Result ....
[EMAIL PROTECTED]:~/derby/test/20051121$ java testLob
Here goes first stream
0
1
2
Here goes 2nd stream
7
8
9
It is expected that result printed from first stream is as same as result
printed from 2nd.