From: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
To: pgsql-jdbc@postgresql.org
Subject: Bug in setClob() ?
Date: Thu, 11 Sep 2014 19:06:28 +0200
Message-ID: <5411D694.206@eppesuigoccas.homedns.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: giuseppe@eppesuigoccas.homedns.org
Subject: Re: Bug in setClob() ?
In-Reply-To: <5411D694.206@eppesuigoccas.homedns.org>
References: <5411D694.206@eppesuigoccas.homedns.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox