Search in sources :

Example 6 with JaqyResultSetMetaData

use of com.teradata.jaqy.connection.JaqyResultSetMetaData in project jaqy by Teradata.

the class ResultSetUtils method getDisplayWidth.

public static int getDisplayWidth(JaqyResultSet rs, int column) throws SQLException {
    JaqyResultSetMetaData meta = rs.getMetaData();
    // some JDBC drivers (notably SQLite JDBC does not have
    // the correct display size settings.  So here we force
    // the correct calculation.
    int displaySize = meta.getColumnDisplaySize(column);
    int type = meta.getColumnType(column);
    int computeSize = displaySize;
    switch(type) {
        case Types.INTEGER:
            {
                computeSize = 10;
                if (meta.isSigned(column))
                    ++computeSize;
                break;
            }
        case Types.REAL:
            {
                int precision = meta.getPrecision(column);
                if (precision <= 7) {
                    // we are dealing a 4-byte real
                    computeSize = precision + 2;
                    if (meta.isSigned(column))
                        ++computeSize;
                } else if (precision <= 53) {
                    computeSize = precision + 2;
                    if (meta.isSigned(column))
                        ++computeSize;
                }
                break;
            }
        case Types.BINARY:
        case Types.VARBINARY:
            {
                int size = meta.getColumnDisplaySize(column);
                computeSize = size * 2;
                break;
            }
        default:
            {
                computeSize = displaySize;
                break;
            }
    }
    return Math.min(computeSize, displaySize);
}
Also used : JaqyResultSetMetaData(com.teradata.jaqy.connection.JaqyResultSetMetaData)

Aggregations

JaqyResultSetMetaData (com.teradata.jaqy.connection.JaqyResultSetMetaData)6 JaqyHelper (com.teradata.jaqy.interfaces.JaqyHelper)4 TypeHandler (com.teradata.jaqy.typehandler.TypeHandler)3 JaqyResultSet (com.teradata.jaqy.interfaces.JaqyResultSet)1 InMemoryResultSetMetaData (com.teradata.jaqy.resultset.InMemoryResultSetMetaData)1 FullColumnInfo (com.teradata.jaqy.schema.FullColumnInfo)1 CSVExportInfo (com.teradata.jaqy.utils.CSVExportInfo)1 ColumnNode (com.teradata.jaqy.utils.exp.ColumnNode)1 ExpNode (com.teradata.jaqy.utils.exp.ExpNode)1 StringReader (java.io.StringReader)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 JsonString (javax.json.JsonString)1 CSVPrinter (org.apache.commons.csv.CSVPrinter)1 CookJsonParser (org.yuanheng.cookjson.CookJsonParser)1 TextJsonParser (org.yuanheng.cookjson.TextJsonParser)1