google-code-export / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

Regression with RESULT_SET returned from stored functions, regarding CLOB data types #334

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Similar to this issue here:
http://code.google.com/p/h2database/issues/detail?id=333

There is some lacking implementation in SimpleResultSet, which is now causing 
problems when passing CLOB data types in ResultSet's returned from stored 
functions.

This can be reproduced with the attached database schema and this code snippet:

---------------------------------------------------------------
PreparedStatement stmt = connection.prepareStatement(
    "select f_get_one_cursor((1,)) from dual");
ResultSet rs = stmt.executeQuery();
rs.next();
ResultSet cursor = (ResultSet) rs.getObject(1);
cursor.next();
String string = cursor.getString(8);

// This is a "toString()" overview of the clob, instead of its content
System.out.println(string);
---------------------------------------------------------------

The problem is in the implementation of SimpleResultSet:

---------------------------------------------------------------
    public String getString(int columnIndex) throws SQLException {
        Object o = get(columnIndex);
        return o == null ? null : o.toString();
    }
---------------------------------------------------------------

JdbcResultSet has this implementation (get(int) returns Value, not Object). 
That should also be the case for SimpleResultSet

---------------------------------------------------------------
    public String getString(int columnIndex) throws SQLException {
        try {
            debugCodeCall("getString", columnIndex);
            return get(columnIndex).getString();
        } catch (Exception e) {
            throw logAndConvert(e);
        }
    }
---------------------------------------------------------------

If I encounter more issues like this, I'll let you know

Original issue reported on code.google.com by lukas.eder@gmail.com on 18 Jul 2011 at 5:49

GoogleCodeExporter commented 9 years ago
Committed in the trunk

Original comment by thomas.t...@gmail.com on 17 Oct 2011 at 6:49

GoogleCodeExporter commented 9 years ago
Thank you. I'll check the fix asap

Original comment by lukas.eder@gmail.com on 18 Oct 2011 at 7:42

GoogleCodeExporter commented 9 years ago
Hmm, maybe I'm missing something, but when I execute this against the latest 
version on trunk:

---------------------------------------------------------------
PreparedStatement stmt = connection.prepareStatement(
    "select f_get_one_cursor((1,)) from dual");
ResultSet rs = stmt.executeQuery();
rs.next();
ResultSet cursor = (ResultSet) rs.getObject(1);
cursor.next();
String string = cursor.getString(8);

// This is a "toString()" overview of the clob, instead of its content
System.out.println(string);
---------------------------------------------------------------

I still get a simple toString() version of the CLOB and not the Clob's String 
contents:

clob0: SPACE(858 /* table: 66 id: 1 */)

Column 8 in the cursor returned from f_get_one_cursor (source in Issue 333) is 
of type CLOB. When selecting from a table, CLOB's are correctly streamed into a 
String when calling ResultSet.getString(). But when selecting from a 
cursor/ResultSet returned from a stored function, then ResultSet.getString() 
does not provide Clob data anymore. This, however, works correctly:

---------------------------------------------------------------
Clob clob = cursor.getClob(8);
System.out.println(clob.getSubString(1, (int) clob.length()));
---------------------------------------------------------------

Original comment by lukas.eder@gmail.com on 19 Oct 2011 at 6:52

GoogleCodeExporter commented 9 years ago
Fixed in the trunk.

Original comment by thomas.t...@gmail.com on 17 Nov 2011 at 7:14

GoogleCodeExporter commented 9 years ago
Thanks a lot, Thomas!

Original comment by lukas.eder@gmail.com on 20 Nov 2011 at 9:01

GoogleCodeExporter commented 9 years ago
Fixed in version 1.3.162

Original comment by thomas.t...@gmail.com on 26 Nov 2011 at 12:55

GoogleCodeExporter commented 9 years ago
Works for me now. Thanks again

Original comment by lukas.eder@gmail.com on 10 Dec 2011 at 5:55