Bug in setClob() ?

Поиск
Список
Период
Сортировка
От Giuseppe Sacco
Тема Bug in setClob() ?
Дата
Msg-id 5411D694.206@eppesuigoccas.homedns.org
обсуждение исходный текст
Ответы Re: Bug in setClob() ?
Re: Bug in setClob() ?
Список pgsql-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


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: Cursors removed with commit
Следующее
От: Giuseppe Sacco
Дата:
Сообщение: Re: Bug in setClob() ?