Hello,
org.postgresql.jdbc1.AbstractJdbc1Statement.setBinaryStream()
in postgresql 7.4.1 wrongly assumes, that
java.io.InputStream.read(byte[] b,int offset,int len )
will always read len bytes. InputStream only guarantees to
return at least 1 byte per call. The attached patch solves the bug.
Btw. setBinaryStream() should really throw an SQLException, if
in can not read as many bytes as expected from the InputStream.
Otherwise the application might silently loss data.
Regards
Martin
--
Martin Holz <[EMAIL PROTECTED]>
Softwareentwicklung / Vernetztes Studium - Chemie
FIZ CHEMIE Berlin
Franklin Str. 11
D-10587 Berlin
*** AbstractJdbc1Statement.java.orig 2004-01-07 14:09:31.000000000 +0100
--- AbstractJdbc1Statement.java 2004-01-07 14:21:28.000000000 +0100
***************
*** 1466,1477 ****
//handling very large values. Thus the implementation ends up calling
//setBytes() since there is no current way to stream the value to the server
byte[] l_bytes = new byte[length];
! int l_bytesRead;
! try
{
! l_bytesRead = x.read(l_bytes, 0, length);
! }
! catch (IOException l_ioe)
{
throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
}
--- 1466,1482 ----
//handling very large values. Thus the implementation ends up calling
//setBytes() since there is no current way to stream the value to the server
byte[] l_bytes = new byte[length];
! int l_bytesRead = 0;
! try
{
! while (true)
! {
! int n = x.read(l_bytes, l_bytesRead, length - l_bytesRead);
! if (n == -1) break;
! l_bytesRead += n;
! }
!
! } catch (IOException l_ioe)
{
throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
}
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster