Is there a good definition in the specification as to how the Clob.setXXX methods are defined to work? Section 16.3.3. of JDBC 3.0 has wording that is pretty vague. The javadoc for these methods doesn't help much either. (Similar concern for Blob.setXXX)
Q1 - I can think of three possible implementations for the setXXX methods:
A) Overwite any existing data from the passed in position
B) Replace the data from passed in position onwards
C) Insert the data into the value at the position
For example, with an existing Clob with value "To be or not to be", and calling setString(7, "is all") I can see getting:
A) "To be is all to be"
B) "To be is all"
C) "To be is allor not to be"
From a quick check of the (ugly, see
DERBY-684) client code, I think it implements B.
Q2 - is that if I call setXXXStream() but never write to the stream, is the value modified?
What if the stream is written to with 0 bytes/characters?
If the defined behaviour above is B) then there's a case to be made that it should be truncated to length matching the passed in position.
Q3 - setString returns the number of characters written, is that allowed to be different to the number of characters that are requested to be written? Like OutputStream.writr(byte)?
Sorry if these answers are obvious.
BTW - there is a bug in the javadoc for Clob.truncate() that indicates for the parameter that the truncation is in bytes. The overview of the method indicates correctly it is in characters. This still seems to be an issue in JDBC 4.