static uint32_t getDisplaySize()

in contrib/native/client/src/clientlib/fieldmeta.cpp [280:352]


static uint32_t getDisplaySize(const ::common::MajorType& type) {
    if (type.mode() == ::common::DM_REPEATED || type.minor_type() == ::common::LIST) {
      return 0;
    }

    uint32_t precision = getPrecision(type);

    switch(type.minor_type()) {
    case ::common::BIT:             return 1; // 1 digit

    case ::common::TINYINT:         return 4; // sign + 3 digit
    case ::common::SMALLINT:        return 6; // sign + 5 digits
    case ::common::INT:             return 11; // sign + 10 digits
    case ::common::BIGINT:          return 20; // sign + 19 digits

    case ::common::UINT1:          return 3; // 3 digits
    case ::common::UINT2:          return 5; // 5 digits
    case ::common::UINT4:          return 10; // 10 digits
    case ::common::UINT8:          return 19; // 19 digits

    case ::common::FLOAT4:          return 14; // sign + 7 digits + decimal point + E + 2 digits
    case ::common::FLOAT8:          return 24; // sign + 15 digits + decimal point + E + 3 digits

    case ::common::DECIMAL9:
    case ::common::DECIMAL18:
    case ::common::DECIMAL28DENSE:
    case ::common::DECIMAL28SPARSE:
    case ::common::DECIMAL38DENSE:
    case ::common::DECIMAL38SPARSE:
    case ::common::VARDECIMAL:
    case ::common::MONEY:           return 2 + precision; // precision of the column plus a sign and a decimal point

    case ::common::VARCHAR:
    case ::common::FIXEDCHAR:
    case ::common::VAR16CHAR:
    case ::common::FIXED16CHAR:     return precision; // number of characters

    case ::common::VARBINARY:
    case ::common::FIXEDBINARY:     return 2 * precision; // each binary byte is represented as a 2digit hex number

    case ::common::DATE:            return 10; // yyyy-mm-dd
    case ::common::TIME:
      return precision > 0
        ? 9 + precision // hh-mm-ss.SSS
        : 8; // hh-mm-ss
    case ::common::TIMETZ:
      return precision > 0
        ? 15 + precision // hh-mm-ss.SSS-zz:zz
        : 14; // hh-mm-ss-zz:zz
    case ::common::TIMESTAMP:
      return precision > 0
         ? 20 + precision // yyyy-mm-ddThh:mm:ss.SSS
         : 19; // yyyy-mm-ddThh:mm:ss
    case ::common::TIMESTAMPTZ:
      return precision > 0
        ? 26 + precision // yyyy-mm-ddThh:mm:ss.SSS:ZZ-ZZ
        : 25; // yyyy-mm-ddThh:mm:ss-ZZ:ZZ

    case ::common::INTERVALYEAR:
      return precision > 0
          ? 5 + precision // P..Y12M
          : 9; // we assume max is P9999Y12M

    case ::common::INTERVALDAY:
      return precision > 0
          ? 12 + precision // P..DT12H60M60S assuming fractional seconds precision is not supported
          : 22; // the first 4 bytes give the number of days, so we assume max is P2147483648DT12H60M60S

    default:
    	// We don't know how to compute a display size, let's return 0 (unknown)
    	return 0;
}
}