Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XS7pS-0008DY-P0 for pgsql-jdbc@arkaria.postgresql.org; Thu, 11 Sep 2014 17:06:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XS7pS-00039a-8k for pgsql-jdbc@arkaria.postgresql.org; Thu, 11 Sep 2014 17:06:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XS7pR-00039S-Ng for pgsql-jdbc@postgresql.org; Thu, 11 Sep 2014 17:06:41 +0000 Received: from centrum.lixper.it ([2a01:4f8:131:33a6::2]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XS7pN-0008Rp-Mw for pgsql-jdbc@postgresql.org; Thu, 11 Sep 2014 17:06:40 +0000 Received: from host43-224-dynamic.44-79-r.retail.telecomitalia.it ([79.44.224.43] helo=[192.168.1.5]) by centrum.lixper.it with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1XS7pK-0006ri-O9; Thu, 11 Sep 2014 19:06:34 +0200 Message-ID: <5411D694.206@eppesuigoccas.homedns.org> Date: Thu, 11 Sep 2014 19:06:28 +0200 From: Giuseppe Sacco User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.7.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Bug in setClob() ? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Hello all, I found a problem in org/postgresql/jdbc2/AbstractJdbc2Statement on the setClob(int i, Clob x) method. I created a clob implementation in my application and then passed it to postgresql via this method, but the correct value is not stored in the database. What happen is that this jdbc implementation read all data from my clob using two methods, getAsciiStream() and length(), this way: InputStream l_inStream = x.getAsciiStream(); int l_length = (int) x.length(); LargeObjectManager lom = connection.getLargeObjectAPI(); long oid = lom.createLO(); LargeObject lob = lom.open(oid); OutputStream los = lob.getOutputStream(); try { int c = l_inStream.read(); int p = 0; while (c > -1 && p < l_length) { los.write(c); c = l_inStream.read(); p++; } los.close(); [...] So, it does read from an ASCII stream using a counter based on the number of characters present in the clob. My clob does not contain ASCII characters, but multibyte ones. So, I think I should probably fail on getAsciiStream(), but this driver does not use any other way to get the data. I tried to implement getAsciiStream() as: return new ByteArrayInputStream( data.getBytes() ); but of course the byte array size is in bytes, so if you only read length() bytes, you will not store the complete string. Now, I think the problem is clear, but I don't know what is the best way to fix it. Let see a couple of proposal for changing the setClob implementation in this driver: 1. remove the usage of lenth() and just loop until the l_inStream.read() fail. 2. use getCharacterStream(), when available, with precedence on getAsciiStream() what do you suggest? Will the "los" object accept non ASCII data? Thanks, Giuseppe -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc