~maria-captains/mariadb-java-client/trunk

« back to all changes in this revision

Viewing changes to src/main/java/org/mariadb/jdbc/MySQLBlob.java

  • Committer: Vladislav Vaintroub
  • Date: 2013-03-27 17:44:16 UTC
  • Revision ID: wlad@montyprogram.com-20130327174416-wjnqb6o8cuezg6gt
CONJ-31 : fix several issues with Clob and PreparedStatement.setCharacterStream()

- non-ASCII  characters can get lost, if  PreparedStatement.setCharacterStream() is used.
- If PreparedStatement.setClob() was used, CLOB was sent to the server using binary introducer (_BINARY). This can potentially lead to wrongly stored non-ASCII characters.

Small cleanups :
-  remove try/catch around code that can't throw exceptions in MySQLPreparedStatement
-  move all tests related to Clobs, Blobs, and streams to BlobTest.java

Thanks to Rune Bremnes, who contributed parts of this patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
350
350
     *                               <code>Blob</code>
351
351
     */
352
352
    public InputStream getBinaryStream(final long pos, final long length) throws SQLException {
353
 
        if (pos < 1 || pos > actualSize || pos + length > actualSize) {
354
 
            throw SQLExceptionMapper.getSQLException("Out of range");
 
353
        if (pos < 1) {
 
354
             throw SQLExceptionMapper.getSQLException("Out of range (position should be > 0)");
 
355
        }
 
356
        if (pos > actualSize) {
 
357
            throw SQLExceptionMapper.getSQLException("Out of range (position > stream size)");
 
358
        }
 
359
        if (pos + length - 1 > actualSize) {
 
360
            throw SQLExceptionMapper.getSQLException("Out of range (position + length - 1 > streamSize)");
355
361
        }
356
362
 
357
363
        return new ByteArrayInputStream(blobContent, (int)pos-1, (int)length);