Hello Rainer,

EMPIREDB-261 is created. 

- jan

Von meinem iPhone gesendet

> Am 12.07.2017 um 12:58 schrieb Rainer Döbele <[email protected]>:
> 
> Hi Jan,
> 
> yes, this is a bug.
> 
> What is missing IMO is calling reset() in the getter of DBClobData.getReader()
> e.g. like this:
> 
>    /**
>     * Get the Reader for the large string
>     *
>     * @return Returns the reader with the character data for the CLOB
>     */
>    public Reader getReader()
>    {
>        try
>        {
>            reader.reset();
>            return reader;
>        }
>        catch (IOException e)
>        {
>            throw new InternalException(e);
>        }
>    }
> 
> Would you like to create a JIRA issue for that?
> 
> Regards,
> Rainer
> 
>> from: [email protected] [mailto:[email protected]]
>> to: [email protected]
>> subject: Re-usable DBCommand with DBClobData
>> 
>> Hello,
>> 
>> I used to write an importer in Empire-db that has a CLOB (LONGTEXT)
>> column. I wanted to update existing and insert new items, so I did:
>> 
>> cmd.set(DB.col1.to(col1));
>> cmd.set(DB.col2.to(col2));
>> // ...
>> cmd.set(DB.clob_col.to(string));
>> 
>> // try update
>> int updateCount = this.db.executeUpdate(cmd, this.conn);
>> 
>> if (updateCount < 1) {
>>    // not found, insert
>>    cmd.set(DB.id.to(id));
>>    this.db.executeInsert(cmd, this.conn);
>> }
>> 
>> which is, afaik, the way to do it.
>> 
>> Turns out: on the first run clob_col is always empty. I debugged and
>> everything looked fine. The same code is used for INSERT and UPDATE, only
>> the generated statement is different.
>> 
>> Now I tracked it down to DBClobData, which uses a java.io.Reader internally.
>> That reader is consumed on the first try (UPDATE) so its empty on the second
>> try (UPDATE).
>> 
>> AFAIK the DBCommand is designed to be used that way. So I think this is a
>> bug. What do you think?
>> 
>> - jan
> 

Reply via email to