Example #1
0
  @Override
  public Type getAggregateType(Type other) {

    if (this == other) {
      return this;
    }

    if (other.isCharacterType()) {
      return other.getAggregateType(this);
    }

    switch (other.typeCode) {
      case Types.SQL_ALL_TYPES:
        return this;

      case Types.SQL_REAL:
      case Types.SQL_FLOAT:
      case Types.SQL_DOUBLE:
      case Types.SQL_NUMERIC:
      case Types.SQL_DECIMAL:
      case Types.TINYINT:
      case Types.SQL_SMALLINT:
      case Types.SQL_INTEGER:
      case Types.SQL_BIGINT:
        break;

      default:
        throw Error.error(ErrorCode.X_42562);
    }

    if (typeWidth == DOUBLE_WIDTH) {
      return this;
    }

    if (((NumberType) other).typeWidth == DOUBLE_WIDTH) {
      return other;
    }

    if (typeWidth <= BIGINT_WIDTH && ((NumberType) other).typeWidth <= BIGINT_WIDTH) {
      return (typeWidth > ((NumberType) other).typeWidth) ? this : other;
    }

    int newScale = scale > other.scale ? scale : other.scale;
    long newDigits =
        precision - scale > other.precision - other.scale
            ? precision - scale
            : other.precision - other.scale;

    return getNumberType(Types.SQL_DECIMAL, newDigits + newScale, newScale);
  }
Example #2
0
  @Override
  public boolean canConvertFrom(Type otherType) {

    if (otherType.typeCode == Types.SQL_ALL_TYPES) {
      return true;
    }

    if (otherType.isNumberType()) {
      return true;
    }

    if (otherType.isIntervalType()) {
      return true;
    }

    if (otherType.isCharacterType()) {
      return true;
    }

    return false;
  }
Example #3
0
  public Type getAggregateType(Type other) {

    if (typeCode == other.typeCode) {
      return precision >= other.precision ? this : other;
    }

    if (other.isCharacterType()) {
      return other.getAggregateType(this);
    }

    switch (other.typeCode) {
      case Types.SQL_ALL_TYPES:
        return this;

      case Types.SQL_BIT:
      case Types.SQL_BIT_VARYING:
        {
          long bytePrecision = (other.precision + 7) / 8;

          return precision >= bytePrecision ? this : getBinaryType(this.typeCode, bytePrecision);
        }
      case Types.SQL_BINARY:
        return precision >= other.precision ? this : getBinaryType(typeCode, other.precision);

      case Types.SQL_VARBINARY:
        if (typeCode == Types.SQL_BLOB) {
          return precision >= other.precision ? this : getBinaryType(typeCode, other.precision);
        } else {
          return other.precision >= precision ? other : getBinaryType(other.typeCode, precision);
        }
      case Types.SQL_BLOB:
        return other.precision >= precision ? other : getBinaryType(other.typeCode, precision);

      default:
        throw Error.error(ErrorCode.X_42562);
    }
  }
Example #4
0
 public boolean canConvertFrom(Type otherType) {
   return otherType.typeCode == Types.SQL_ALL_TYPES
       || otherType.isBinaryType()
       || otherType.isCharacterType();
 }