Issue Details (XML | Word | Printable)

Key: DERBY-562
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Sunitha Kambhampati
Reporter: Holger Rehn
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Derby

Derby incorrectly throws Exception when streaming to BLOB field

Created: 13/Sep/05 07:37 PM   Updated: 12/Oct/05 02:28 AM
Return to search
Component/s: JDBC
Affects Version/s: 10.0.2.0, 10.0.2.1, 10.0.2.2, 10.1.1.0, 10.1.2.1, 10.2.1.6
Fix Version/s: 10.1.2.1, 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works Derby562.diff.txt 2005-09-21 12:24 PM Sunitha Kambhampati 16 kB
Text File Licensed for inclusion in ASF works Derby562.stat.txt 2005-09-21 12:26 PM Sunitha Kambhampati 0.5 kB
Environment: All

Resolution Date: 07/Oct/05 12:05 PM


 Description  « Hide
Derby incorrectly throws an Exception when streaming to a BLOB in case the used InputStream actually could provide more data than I want to write to the BLOB field.

   PreparedStatement statement = connection.prepareStatement( "insert into FOO(ID,DATA) values(?, ?)" );
   statement.setLong( 1, someValue );
   statement.setBinaryStream( 2, someInputStream, amountOfData ); // amountOfData < amount of data readable from someInputStream
   statement.executeUpdate();

executeUpdate() throws an SQLException with detail message: "Input stream held less data than requested length.: java.io.IOException"

In my case this was first caused by writing an internal buffer (byte[]) to the data base through a ByteArrayInputStream while not limiting the ByteArrayInputStream to the useful data within the buffer but setting amountOfData to the number of useful bytes. So the 2 problems are:
1. the error text is definitly incorrect since I provide more data than neccessary, not less
2. in my opinion this shouldn't throw an exception at all (I checked against 4 other DBMS, all of them worked as intended)

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #292830 Fri Sep 30 18:23:06 UTC 2005 mikem fix of DERBY-562, committing patch for: Sunitha Kambhampati

 This patch
 - changes the error message thrown when the stream is either less or greater than the requested length to
 'Input stream did not have exact amount of data as the requested length.'
 - enhances the characterStreams.out test, to print out the nested sql exceptions to ensure that the proper error message is returned.
 - updates to the master files.

 I verified that we are testing for these two error cases (ie stream has less or more data than requested length), for the following supported stream related api - setCharacterStream, setAsciiStream, setBinaryStream on PreparedStatement. Derby does not support setUnicodeStream api that is deprecated in jdbc 3.0.
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/RawToBinaryFormatStream.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ReaderToUTF8Stream.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/characterStreams.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/characterStreams.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties

Repository Revision Date User Message
ASF #306965 Fri Oct 07 00:07:49 UTC 2005 kmarsden DERBY-562 Derby incorrectly throws Exception when streaming to BLOB field
Merged from trunk with:
svn merge -r 292829:292830 https://svn.apache.org/repos/asf/db/derby/code/trunk
Contributed by Sunitha Kambhampati
Files Changed
MODIFY /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/RawToBinaryFormatStream.java
MODIFY /db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/reference/SQLState.java
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/resultsetStream.out
MODIFY /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/ReaderToUTF8Stream.java
MODIFY /db/derby/code/branches/10.1/java/engine/org/apache/derby/loc/messages_en.properties
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/characterStreams.out
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/characterStreams.java