Issue Details (XML | Word | Printable)

Key: DERBY-2345
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Anurag Shekhar
Reporter: V.Narayanan
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

truncate on a Blob does not work when the Blob is in memory

Created: 16/Feb/07 12:39 PM   Updated: 10/Sep/08 05:56 AM
Return to search
Component/s: JDBC
Affects Version/s: None
Fix Version/s: 10.3.1.4

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works derby-2345.diff 2007-02-17 02:28 PM Anurag Shekhar 2 kB
Issue Links:
Reference
 

Resolution Date: 19/Feb/07 11:20 PM


 Description  « Hide
I tried the following repro. After calling the truncate the Blob object still returns the length as 29 (its original length) .

import java.sql.*;

public class TruncateBugRepro {
    
    Connection con = null;
    
    public Connection getEmbeddedConnection() throws Exception {
        if(con == null) {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            con = DriverManager.getConnection
                ("jdbc:derby:DB1;create=true");
        }
        return con;
    }
    
    public void testTruncate() throws Exception {
        //String used to getBytes from and insert into Blob.
        String str = new String("I am a Blob!!! I am a Blob!!!");
        Connection con = getEmbeddedConnection();
        //create the blob
        Blob blob = con.createBlob();
        //insert bytes
        blob.setBytes(1,str.getBytes());
        //Retuns the Blob length as 29
        System.out.println("" + blob.length());
        blob.truncate(14);
        //returns the Blob length as 29
        System.out.println("" + blob.length());
    }
    
    public static void main(String[] args) throws Exception {
        TruncateBugRepro t = new TruncateBugRepro();
        t.testTruncate();
    }
}


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
V.Narayanan added a comment - 16/Feb/07 12:43 PM
Truncate functionality is provided as part of 2247

Anurag Shekhar added a comment - 17/Feb/07 02:29 PM
I had missed reassigning the truncated byte array over original byte array hence this bug. The bug went undetected because the tests i added as part of 2247 wasn't testing truncate for small blob (less than 4k).

In this patch I have fixed this bug and added a test for small blob.

V.Narayanan added a comment - 19/Feb/07 10:39 AM
The repro gives the correct result after the patch is applied. Thank you for the patch.

Kristian Waagan added a comment - 19/Feb/07 11:09 AM
I'm running tests and will commit this patch shortly.

Kristian Waagan added a comment - 19/Feb/07 11:20 PM
Committed with revision 509375.

V.Narayanan added a comment - 10/Sep/08 05:56 AM
The final patch has been committed for this issue. Thanks to Anurag and kristian for the good work!