Issue Details (XML | Word | Printable)

Key: DERBY-217
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Satheesh Bandaram
Reporter: Gerald Khin
Votes: 0
Watchers: 1
Operations

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

issue with BLOBs and batch updates in 10.1.0.0

Created: 13/Apr/05 12:30 AM   Updated: 23/Jul/05 05:54 AM
Return to search
Component/s: JDBC
Affects Version/s: 10.1.1.0
Fix Version/s: 10.1.1.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works Derby-217.txt 2005-06-08 09:30 AM Satheesh Bandaram 0.6 kB
Environment: Win XP SP2

Resolution Date: 15/Jun/05 03:39 AM


 Description  « Hide
A batch update statement containing an insert statement with a BLOB value inserts a null BLOB. Here ist the output of sysinfo:

------------------ Java Information ------------------
Java Version: 1.4.2_04
Java Vendor: Sun Microsystems Inc.
Java home: C:\Programme\Java\j2re1.4.2_04
Java classpath: U:\derby\trunk\jars\sane\derby.jar
OS name: Windows XP
OS architecture: x86
OS version: 5.1
Java user name: gk
Java user home: C:\Dokumente und Einstellungen\gk
Java user dir: C:\
java.specification.name: Java Platform API Specification
java.specification.version: 1.4
--------- Derby Information --------
JRE - JDBC: J2SE 1.4.2 - JDBC 3.0
[U:\derby\trunk\jars\sane\derby.jar] 10.1.0.0 alpha - (160290)

And here is a test program to reproduce the isssue:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DerbyBlobIssueRepro {

    public static void main(String[] args) {
        System.setProperty("derby.system.home", "C:\\temp\\");
        
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        }
        catch(ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }

        PreparedStatement stmtBatchInsert = null;
            
        try {
            final Connection conn = getConnection();
            
            createOrRecreateTable(conn);
            
            stmtBatchInsert = getPreparedInsertRowWithBlobStmt(conn);
            
            insertRowWithBlob(stmtBatchInsert, 100);
// insertRowWithBlob(stmtBatchInsert, 200);
            
            stmtBatchInsert.executeBatch();

            conn.commit();
            
            checkBlobLen(conn);
            
            conn.commit();
            
            conn.close();
        }
        catch(SQLException e) {
            e.printStackTrace();
            System.exit(1);
        }
        finally {
            if (stmtBatchInsert != null) { try { stmtBatchInsert.close(); } catch (SQLException e) {} }
        }

        System.exit(0);
    }

    private static void createOrRecreateTable(Connection p_conn) throws SQLException {
        try {
            dropTable(p_conn);
        }
        catch(SQLException e) {
            if (!e.getSQLState().equals("42Y07")) {
                e.printStackTrace();
            }
        }
        
        createTable(p_conn);
    }
    
    private static void dropTable(Connection p_conn) throws SQLException {
        PreparedStatement stmt = null;
        try {
            stmt = p_conn.prepareStatement("DROP TABLE test.blobtest");

            stmt.executeUpdate();
        }
        finally {
            if (stmt != null) { try { stmt.close(); } catch (SQLException e) {} }
        }
    }
    
    private static void createTable(Connection p_conn) throws SQLException {
        PreparedStatement stmt = null;
        try {
            stmt = p_conn.prepareStatement("CREATE TABLE test.blobtest(len INTEGER, bval BLOB(10M))");

            stmt.executeUpdate();
        }
        finally {
            if (stmt != null) { try { stmt.close(); } catch (SQLException e) {} }
        }
    }
    
    
    private static void insertRowWithBlob(PreparedStatement p_stmtInsert, int p_nLen) throws SQLException {
        p_stmtInsert.setInt(1, p_nLen);
        p_stmtInsert.setBytes(2, new byte[p_nLen]);

        p_stmtInsert.addBatch();
    }
    
    private static PreparedStatement getPreparedInsertRowWithBlobStmt(Connection p_conn) throws SQLException {
        return p_conn.prepareStatement("INSERT INTO test.blobtest(len,bval) VALUES (?,?)");
    }
    
    
    private static void checkBlobLen(Connection p_conn) throws SQLException {
        PreparedStatement stmtQuery = null;
        ResultSet rs = null;
        try {
            // try ter update the row, may be there is no row to update
            stmtQuery = p_conn.prepareStatement("SELECT len, bval from test.blobtest");
            
            rs = stmtQuery.executeQuery();
            
            while(rs.next()) {
                final int nLen = rs.getInt(1);
                final byte[] arBytes = rs.getBytes(2);
                
                if (rs.wasNull()) {
                    System.out.println("unexpected null blob");
                }
                else if (nLen != arBytes.length) {
                    System.out.println("unexpected number of bytes, expected: " + nLen + ", was: " + arBytes.length);
                }
            }
        }
        finally {
            if (rs != null) { try { rs.close(); } catch (SQLException e) {} }
            if (stmtQuery != null) { try { stmtQuery.close(); } catch (SQLException e) {} }
        }
    }
    
    private static Connection getConnection() throws SQLException {
        final Connection conn = DriverManager.getConnection("jdbc:derby:derbyblobdb;create=true", "test", "test");
        conn.setAutoCommit(false);
        return conn;
    }
    
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #190127 Sat Jun 11 15:13:39 UTC 2005 djd DERBY-217 add some batch test cases for the setXXX methods to jdbcapi/parameterMapping test.
Work in progress, need another commit to add the remaining setXXX methods.
Files Changed
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/parameterMapping.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/parameterMapping.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/parameterMapping.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/parameterMapping.out

Repository Revision Date User Message
ASF #219679 Tue Jul 19 13:21:52 UTC 2005 djd DERBY-217 Finish adding batch test cases for setXXX methods in jdbcapi/parameterMapping.java
Files Changed
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/parameterMapping.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/parameterMapping.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/parameterMapping.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/parameterMapping.out

Repository Revision Date User Message
ASF #280433 Mon Sep 12 22:39:59 UTC 2005 fuzzylogic DERBY-217: master file update for parameterMapping.out due to revision 219679.

Committed for Army Brown <qozinx@sbcglobal.net>
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ver2.6/parameterMapping.out

Repository Revision Date User Message
ASF #290244 Mon Sep 19 19:25:04 UTC 2005 djd DERBY-217 - Merge additional testing from trunk - fixes are already in the branch.
Merge of 219679 and 280433 - additional testing in parameterMapping.java.
Files Changed
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/parameterMapping.out
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/parameterMapping.out
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ver2.6/parameterMapping.out
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/parameterMapping.out
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/parameterMapping.out