Search in sources :

Example 1 with FormatCode

use of org.adbcj.postgresql.codec.FormatCode in project adbcj by mheath.

the class BackendMessageDecoder method decodeRowDescription.

private AbstractBackendMessage decodeRowDescription(DecoderInputStream input) throws IOException {
    Charset charset = connectionState.getBackendCharset();
    int fieldCount = input.readUnsignedShort();
    PgField[] fields = new PgField[fieldCount];
    for (int i = 0; i < fieldCount; i++) {
        String name = input.readString(charset);
        int tableOid = input.readInt();
        int columnAttributeNumber = input.readUnsignedShort();
        int typeOid = input.readInt();
        short typeSize = input.readShort();
        int typeModifier = input.readInt();
        FormatCode code = FormatCode.values()[input.readShort()];
        Type type;
        switch(typeOid) {
            case PgFieldType.BOOLEAN:
                type = Type.BOOLEAN;
                break;
            case PgFieldType.BIGINT:
                type = Type.BIGINT;
                break;
            case PgFieldType.CHAR:
                type = Type.CHAR;
                break;
            case PgFieldType.DATE:
                type = Type.DATE;
                break;
            case PgFieldType.DOUBLE:
                type = Type.DOUBLE;
                break;
            case PgFieldType.INTEGER:
                type = Type.INTEGER;
                break;
            case PgFieldType.REAL:
                type = Type.REAL;
                break;
            case PgFieldType.SMALLINT:
                type = Type.SMALLINT;
                break;
            case PgFieldType.VARCHAR:
                type = Type.VARCHAR;
                break;
            default:
                // TODO Convert more typeOids to ADBCJ types
                throw new IllegalStateException("Unable to handle field type with oid " + typeOid);
        }
        fields[i] = new PgField(i, connectionState.getDatabaseName(), type, name, tableOid, columnAttributeNumber, code, typeSize, typeModifier);
        logger.debug("Setting fields for current result set: {}", fields);
        connectionState.setCurrentResultSetFields(fields);
    }
    return new RowDescriptionMessage(fields);
}
Also used : PgField(org.adbcj.postgresql.codec.PgField) PgFieldType(org.adbcj.postgresql.codec.PgFieldType) Type(org.adbcj.Type) FormatCode(org.adbcj.postgresql.codec.FormatCode) Charset(java.nio.charset.Charset)

Aggregations

Charset (java.nio.charset.Charset)1 Type (org.adbcj.Type)1 FormatCode (org.adbcj.postgresql.codec.FormatCode)1 PgField (org.adbcj.postgresql.codec.PgField)1 PgFieldType (org.adbcj.postgresql.codec.PgFieldType)1