Обсуждение: Bug in setClob() ?

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

Bug in setClob() ?

От
Giuseppe Sacco
Дата:
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


Re: Bug in setClob() ?

От
Giuseppe Sacco
Дата:
Hello,
I just found that the problem I reported has already been solved (since
a few months) in the GIT version.

Do you have any idea about when the next official build will be published?

Thank you,
Giuseppe Sacco


Re: Bug in setClob() ?

От
Giuseppe Sacco
Дата:
Hello,
I just found that the problem I reported has already been solved (since
a few months) in the GIT version.

Do you have any idea about when the next official build will be published?

Thank you,
Giuseppe Sacco


Re: Bug in setClob() ?

От
Craig Ringer
Дата:
On 09/12/2014 04:28 PM, Giuseppe Sacco wrote:
> Do you have any idea about when the next official build will be published?

Probably some time after the final release of PostgreSQL 9.4.

It's mostly a matter of when there's time to do it and the urgency of
queued up fixes.

It's simple to compile the current git head for the driver in the mean time.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services