[ 
http://issues.apache.org/jira/browse/DERBY-1516?page=comments#action_12426647 ] 
            
Craig Russell commented on DERBY-1516:
--------------------------------------

Dan observes:

> Since this has been a tricky area to get correct, it seems that adding 
> Javadoc comments to the methods your are modifying in the Derby 
> implementations of Clob & Blob would add great value. Otherwise a few months 
> from now someone may change the code again thinking it is wrong (especially 
> since the code no longer matches the javadoc). 

Could you please be a bit more specific, so I can do this in one pass? Which 
parts of the code do you want to be better commented; e.g. just the parts I 
modified, or the entire method?

> In Derby's JDBC implementation notes this comment exists for getSubString 

> http://db.apache.org/derby/papers/JDBCImplementation.html#getSubString%28int+pos%2C+int+length%29
>  

> If the pos (position) argument is greater than the length of the CLOB then an 
> exception is thrown. This matches the semantics of the SQL SUBSTR function. 

> Does that need to be corrected, do we have an issue because the new code will 
> not match SQL SUBSTR?

Yes, that needs to be corrected, and I propose:
If the pos (position) argument is greater than the length + 1 of the CLOB then 
an exception is thrown. This matches the semantics of the 
java.lang.String.subString(int beginIndex, int endIndex) method. 

A similar change is needed for Blob.getBytes
If the pos (position) argument is greater than the length of the BLOB then an 
exception is thrown. This matches the semantics of the SQL SUBSTR function.

I propose:
If the pos (position) argument is greater than the length + 1 of the BLOB then 
an exception is thrown. This matches the semantics of the 
java.lang.System.arraycopy method.

I don't think that matching SQL semantics is as important as matching java 
language semantics. After all, this API is a java language API.

> Inconsistent behavior for getBytes and getSubString for embedded versus 
> network
> -------------------------------------------------------------------------------
>
>                 Key: DERBY-1516
>                 URL: http://issues.apache.org/jira/browse/DERBY-1516
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>            Reporter: Craig Russell
>         Assigned To: Craig Russell
>            Priority: Minor
>         Attachments: DERBY-1516.patch, DERBY-1516.patch, DERBY-1516.patch, 
> DERBY-1516.patch, DERBY-1516.patch, DERBY-1516.patch
>
>
> org.apache.derby.client.am.Clob.getSubString(pos, length) and 
> org.apache.derby.client.am.Blob.getBytes(pos, length) check the length for 
> less than zero. 
>             if ((pos <= 0) || (length < 0)) {
>                 throw new SqlException(agent_.logWriter_, "Invalid position " 
> + pos + " or length " + length);
> But org.apache.derby.impl.jdbc.EmbedClob(pos, length) and 
> org.apache.derby.impl.jdbc.EmbedBlob(pos, length) check the length for less 
> than or equal to zero.
>        if (length <= 0)
>             throw Util.generateCsSQLException(
>                 SQLState.BLOB_NONPOSITIVE_LENGTH, new Integer(length));
> The specification does not disallow length of zero, so zero length should be 
> allowed. I believe that the implementation in org.apache.derby.client.am is 
> correct, and the implementation in org.apache.derby.impl.jdbc is incorrect. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to