db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lance J. Andersen" <Lance.Ander...@Sun.COM>
Subject Re: should Clob.getSubstring() allow length of 0?
Date Mon, 17 Jul 2006 15:14:25 GMT
Here is the description of String.subString()


      substring

public String <http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html> *substring*(int
beginIndex,
                        int endIndex)

    Returns a new string that is a substring of this string. The
    substring begins at the specified |beginIndex| and extends to the
    character at index |endIndex - 1|. Thus the length of the substring
    is |endIndex-beginIndex|.

    Examples:

         "hamburger".substring(4, 8) returns "urge"
         "smiles".substring(1, 5) returns "mile"
         

    *Parameters:*
        |beginIndex| - the beginning index, inclusive.
        |endIndex| - the ending index, exclusive. 
    *Returns:*
        the specified substring. 
    *Throws:*
        |IndexOutOfBoundsException
        <http://java.sun.com/j2se/1.5.0/docs/api/java/lang/IndexOutOfBoundsException.html>|
        - if the |beginIndex| is negative, or |endIndex| is larger than
        the length of this |String| object, or |beginIndex| is larger
        than |endIndex|.



So this indicates to me that a SQLException is what is to be expected in 
this case in the case of Kathey's example.

Regards
Lance


Craig L Russell wrote:
> Hi Lance,
>
> Now that Kathey has kicked it back to you and me, how about updating 
> the to-be-released JDBC 4 to point out that a length of zero for the 
> getSubString is valid?
>
> String getSubString(long pos,
>                     int length)
>                     throws SQLException
> Retrieves a copy of the specified substring in the CLOB value 
> designated by this Clob object. The substring begins at position pos 
> and has up to length consecutive characters.
>
> Parameters:
> pos - the first character of the substring to be extracted. The first 
> character is at position 1.
> length - the number of consecutive characters to be copied
>
> We might simply add to this description.
>
> length - the number of consecutive characters to be copied; 0 is a 
> valid value
>
> We have a similar case with Blob byte[ ] getBytes().
>
> Can you run this past the expert group for a quick consensus?
>
> Thanks,
>
> Craig
>
> On Jul 14, 2006, at 11:13 PM, Kathey Marsden wrote:
>
>> Craig L Russell wrote:
>>
>>> You can always work around odd code on the other side of an  
>>> incompletely defined interface. But you probably have code on the  
>>> Derby side that also checks for the clob.length() == 0 and take 
>>> some  extraordinary action.
>>>
>>> So much easier for neither side to check for zero length and let 
>>> the  natural boundary condition happen.
>>>
>> I am happy that you agree that the original  DDLUtils code was 
>> perfectly reasonable at not as Lance described it.   I will exit this 
>> issue now and allow you,  Lance, or someone else with interest 
>> determine the correct behavior, check it with Derby  and  file a 
>> Derby bug if needed.
>>
>> Kathey
>>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>

Mime
View raw message