Issue Details (XML | Word | Printable)

Key: DERBY-628
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Satheesh Bandaram
Reporter: A B
Votes: 0
Watchers: 0
Operations

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

setNull() using Types.VARCHAR for a CLOB parameter fails in embedded mode.

Created: 15/Oct/05 08:52 AM   Updated: 20/Nov/06 02:52 AM
Return to search
Component/s: JDBC
Affects Version/s: None
Fix Version/s: 10.1.3.1, 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works patch 2006-02-08 05:47 AM Satheesh Bandaram 5 kB
Java Source File Licensed for inclusion in ASF works setNull.java 2005-10-15 08:53 AM A B 1 kB

Resolution Date: 25/Apr/06 08:13 AM


 Description  « Hide
If I attempt to call PreparedStatement.setNull() and specify Types.VARCHAR when the actual parameter type (as determined at bind time) is CLOB, Derby in embedded mode will throw an error, while Derby in client/server mode will succeed.

Ex. running the following code:

    st.execute("create table t1 (c clob)");
    PreparedStatement pSt = conn.prepareStatement(
        "insert into t1 values (?)");
    try {
        pSt.setNull(1, Types.VARCHAR);
        pSt.execute();
        System.out.println("Error did NOT reproduce.");
    } catch (SQLException se) {
        System.out.println("Error reproduced:");
        se.printStackTrace();
    }

Against Derby embedded, the result will be:

  Error reproduced:
  SQL Exception: An attempt was made to get a data value of type 'CLOB' from a data value of type 'VARCHAR'.

But against the Network Server, everything works fine. Derby embedded will work in other cases where compatible types are used (ex. using setNull() with Types.INTEGER for a BIGINT parameter), but fails for this particular situation. Thus I'm assuming this is _not_ intentional (i.e. that the above code should work).

Looks like the problem is in iapi.types.DataTypeDescriptor:

    private static boolean isCharacterType(int jdbcType) {

        switch (jdbcType) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return true;
        default:
            return false;
        }
    }

I think CLOB should be included in this list, too, shouldn't it? In iapi.types.TypeId, "isStringTypeId" is true for CLOBs as well as for the other character types, so it seems like the above method should have similar logic.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
A B added a comment - 15/Oct/05 08:53 AM
Attaching a simple program to reproduce the problem. To run against Derby embedded, use

  java setNull

To run against Derby Client, use

  java setNull client

To run against JCC, use

  java setNull jcc

Satheesh Bandaram added a comment - 04/Feb/06 11:45 AM
I have a patch for this issue. I wondered if Derby should also allow setNull on blob column from binary types.

But Derby behaves differently for blob and clobs in SQL:

ij> create table clobBlob(c clob, b blob, v varchar(10), vb varchar(10) for bit data);
0 rows inserted/updated/deleted
ij> insert into clobBlob(c) select v from clobBlob;
0 rows inserted/updated/deleted
ij> insert into clobBlob(b) select vb from clobBlob;
ERROR 42821: Columns of type 'BLOB' cannot hold values of type 'VARCHAR () FOR BIT DATA'.
ij>

Satheesh Bandaram added a comment - 08/Feb/06 05:47 AM
Updated patch. Would like to commit today.

Satheesh Bandaram added a comment - 09/Feb/06 10:01 AM
Fixed with 375877.

Satheesh Bandaram added a comment - 09/Feb/06 10:02 AM
Fix checked in. Verified with the new build.

Satheesh Bandaram added a comment - 25/Apr/06 08:08 AM
Reopening to mark fix in.

Satheesh Bandaram added a comment - 25/Apr/06 08:13 AM
Closing after porting fix to 10.1. SVN number: 396753.

Myrna van Lunteren added a comment - 20/Nov/06 02:52 AM
Also updated the 10.1 j9_13/parameterMapping.out with
http://svn.apache.org/viewvc?view=rev&revision=477009