Ejemplo n.º 1
0
  public static Type getAggregatedType(Type add, Type existing) throws HsqlException {

    if (existing == null || existing.type == Types.SQL_ALL_TYPES) {
      return add;
    }

    if (add == null || add.type == Types.SQL_ALL_TYPES) {
      return existing;
    }

    return existing.getAggregateType(add);
  }
Ejemplo n.º 2
0
  public static Type getAggregateType(Type add, Type existing) {

    if (existing == null || existing.typeCode == Types.SQL_ALL_TYPES) {
      return add;
    }

    if (add == null || add.typeCode == Types.SQL_ALL_TYPES) {
      return existing;
    }

    return existing.getAggregateType(add);
  }
  public Type getAggregateType(Type other) throws HsqlException {

    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);
  }
Ejemplo n.º 4
0
  public void resolveTypes(Session session, Expression parent) {

    switch (opType) {
      case OpTypes.DEFAULT:
        if (parent != null && parent.opType != OpTypes.ROW) {
          throw Error.error(ErrorCode.X_42544);
        }
        break;

      case OpTypes.COALESCE:
        {
          Type type = null;

          for (int i = 0; i < nodes.length; i++) {
            type = Type.getAggregateType(nodes[i].dataType, type);
          }

          dataType = type;

          break;
        }
    }
  }