Search in sources :

Example 1 with CachedClob

use of com.teradata.jaqy.resultset.CachedClob in project jaqy by Teradata.

the class TeradataHelper method getResultSet.

@Override
public JaqyResultSet getResultSet(ResultSet rs, JaqyInterpreter interpreter) throws SQLException {
    if (rs == null)
        return null;
    ResultSetMetaData meta = rs.getMetaData();
    // guess if the output is from SHOW statement.
    if (meta != null && meta.getColumnCount() == 1) {
        int type = meta.getColumnType(1);
        if (TypesUtils.isString(type)) {
            getGlobals().log(Level.INFO, "Potential SHOW ResultSet.");
            // 
            // Teradata SHOW statements due to legacy, use '\r' instead of '\n'
            // characters.  That can be problematic in the output.
            // 
            // Per discussion with a Teradata JDBC architect, no internals of
            // Teradata JDBC should be exposed in OSS code.  So the only thing
            // we can do is to guess the output could be from, and replace
            // the EOL character that way.
            // 
            // All SHOW statements are single column.  Typically, the output
            // is a row of VARCHAR.  However, I am not sure if there is ever
            // a case of having CLOB output, or just multiple rows.
            // 
            // So we do generic handling here.
            // 
            InMemoryResultSet newRS = ResultSetUtils.copyResultSet(rs, 0, this, interpreter);
            rs.close();
            for (Object[] row : newRS.getRows()) {
                for (int i = 0; i < row.length; ++i) {
                    if (row[i] != null) {
                        Object o = row[i];
                        if (o instanceof String) {
                            row[i] = ((String) o).replace('\r', '\n');
                        } else if (o instanceof CachedClob) {
                            CachedClob clob = (CachedClob) o;
                            String s = clob.getSubString(1, (int) clob.length());
                            clob = new CachedClob(s);
                        }
                    }
                }
            }
            rs = newRS;
        }
    }
    return new JaqyDefaultResultSet(rs, this);
}
Also used : CachedClob(com.teradata.jaqy.resultset.CachedClob) InMemoryResultSet(com.teradata.jaqy.resultset.InMemoryResultSet) JaqyDefaultResultSet(com.teradata.jaqy.connection.JaqyDefaultResultSet)

Aggregations

JaqyDefaultResultSet (com.teradata.jaqy.connection.JaqyDefaultResultSet)1 CachedClob (com.teradata.jaqy.resultset.CachedClob)1 InMemoryResultSet (com.teradata.jaqy.resultset.InMemoryResultSet)1