db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dag H. Wanvik (JIRA)" <derby-...@db.apache.org>
Subject [jira] Commented: (DERBY-1516) Inconsistent behavior for getBytes and getSubString for embedded versus network
Date Thu, 03 Aug 2006 17:08:15 GMT
    [ http://issues.apache.org/jira/browse/DERBY-1516?page=comments#action_12425568 ] 
            
Dag H. Wanvik commented on DERBY-1516:
--------------------------------------

If you are modelling this on the java.lang.String modulo indexing, it
seems to me that this is slightly wrong:

"The position must be between 1 and the last position of the Lob".

I think it should be 

"The position must be between 1 and the last position + 1 of the Lob",
cf. this example which does not throw exceptions. In the substring of
t2, the position is *one past* the final position of the string, final
position being 0.

                String t1 = "";
                String t2 = "a";
                
                String t3;
                
                try {
                        System.out.println("t1.substring(0,0) = '" +
                                                           t1.substring(0,0) +  "'");
                } catch (IndexOutOfBoundsException e) {
                        System.out.println("t1.substring(0,0) throws");
                }

                try {
                        System.out.println("t2.substring(1,1) = '" +
                                                           t2.substring(1,1) +  "'");
                } catch (IndexOutOfBoundsException e) {
                        System.out.println("t2.substring(1,1) throws");
                }
    }

that is, you can always request an empty string from the position
*immediately after* the last byte, but not further out. This would
remove the asymmetry you have in the code, too:

                if (this.length() == 0) {
                    if (pos > 1) {
                    throw new SqlException(agent_.logWriter_, 
                        new ClientMessageId(SQLState.BLOB_POSITION_TOO_LARGE), 
                        new Long(pos));
                    }
                } else { // this.length() > 0
                    if (pos > this.length()) {
                    throw new SqlException(agent_.logWriter_, 
                        new ClientMessageId(SQLState.BLOB_POSITION_TOO_LARGE), 
                        new Long(pos));                    
                    }
                }
would reduce to:

                if (pos > this.length() + 1) {
                    throw new SqlException(agent_.logWriter_, 
                        new ClientMessageId(SQLState.BLOB_POSITION_TOO_LARGE), 
                        new Long(pos));
                }

I also think this is the symmetry one would want for programming
convenience, like you have mentioned. 


> 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
>
>
> 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

        

Mime
View raw message