[CONJ-137] Writing blob with size -1 Created: 2015-02-09  Updated: 2015-09-15  Resolved: 2015-09-15

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.1.8
Fix Version/s: 1.3.0

Type: Bug Priority: Major
Reporter: Frank Cornelis Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Sprint: Sprint connector/j 1.3.0

 Description   

When trying to write a blob via an input stream of unknown size, you most likely end up with an initialization of the JPA Blob field like:

public final void setDocument(InputStream inputStream, EntityManager entityManager) {
        HibernateEntityManager hibernateEntityManager = entityManager.unwrap(HibernateEntityManager.class);
        Session session = hibernateEntityManager.getSession();
        LobHelper lobHelper = session.getLobHelper();
        this.document = lobHelper.createBlob(inputStream, -1);
}

while this works for the MySQL Java Connector, it does not for the MariaDB Java Client.
The following patch fixes this issue:

--- ./src/main/java/org/mariadb/jdbc/internal/common/query/parameters/ParameterWriter.java.orig	2015-02-09 17:01:52.494722950 +0100
+++ ./src/main/java/org/mariadb/jdbc/internal/common/query/parameters/ParameterWriter.java	2015-02-09 17:13:43.683386990 +0100
@@ -91,7 +91,7 @@
 
         for (;;) {
             int bytesToRead = (int)Math.min(bytesLeft, buffer.length);
-            if(bytesToRead == 0)
+            if(bytesToRead <= 0)
                 break;
             len = is.read(buffer,0, bytesToRead);
             if (len <= 0)



 Comments   
Comment by Diego Dupin [ 2015-09-15 ]

corrected in 1.3.0 (buffering has been redesigned for more performance, and this issue has been verifyed)

Generated at Thu Feb 08 03:13:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.