Blob .getBytes position should start at 1

Поиск
Список
Период
Сортировка
Искать

Blob .getBytes position should start at 1

От:
Emmanuel Bernard <emmanuel@hibernate.org>
Дата:
 From the Javadoc of java.sql.Blob byte[] getBytes(long pos, int length) 
throws SQLException;

   * @param pos the ordinal position of the first byte in the
   *        BLOB value to be extracted; the first byte is at
   *        position 1

pqsql driver assumes the position starts from 0

Patch attached

--
Emmanuel Bernard
http://www.hibernate.org
callto://emmanuelbernard
Index: org/postgresql/jdbc2/AbstractJdbc2BlobClob.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2BlobClob.java,v
retrieving revision 1.1
diff -u -r1.1 AbstractJdbc2BlobClob.java
--- org/postgresql/jdbc2/AbstractJdbc2BlobClob.java	28 Mar 2005 08:52:35 -0000	1.1
+++ org/postgresql/jdbc2/AbstractJdbc2BlobClob.java	6 May 2005 09:59:42 -0000
@@ -46,7 +46,8 @@
 
     public byte[] getBytes(long pos, int length) throws SQLException
     {
-        lo.seek((int)pos, LargeObject.SEEK_SET);
+        //throw an appropriate exception if pos < 1
+        lo.seek((int)pos-1, LargeObject.SEEK_SET);
         return lo.read(length);
     }
 

Re: Blob .getBytes position should start at 1

От:
Kris Jurka <books@ejurka.com>
Дата:


On Fri, 6 May 2005, Emmanuel Bernard wrote:

>  From the Javadoc of java.sql.Blob byte[] getBytes(long pos, int length) 
> throws SQLException;
> 
>    * @param pos the ordinal position of the first byte in the
>    *        BLOB value to be extracted; the first byte is at
>    *        position 1
> 
> pqsql driver assumes the position starts from 0
> 

Indeed.  I've put a fix in 7.4, 8.0, and HEAD branches.

Thanks.

Kris Jurka
FAQ