Пример #1
0
  /** Enforces precision and scale limits on type */
  public static Type getType(int type, int collation, long precision, int scale)
      throws HsqlException {

    switch (type) {
      case Types.SQL_ALL_TYPES:
        return null;

        //                return SQL_ALL_TYPES; // needs changes to Expression type resolution
      case Types.SQL_CHAR:
      case Types.SQL_VARCHAR:
      case Types.VARCHAR_IGNORECASE:
      case Types.SQL_CLOB:
        return CharacterType.getCharacterType(type, precision);

      case Types.SQL_INTEGER:
        return SQL_INTEGER;

      case Types.SQL_SMALLINT:
        return SQL_SMALLINT;

      case Types.SQL_BIGINT:
        return SQL_BIGINT;

      case Types.TINYINT:
        return TINYINT;

      case Types.SQL_FLOAT:
        if (precision > 53) {
          throw Trace.error(Trace.NUMERIC_VALUE_OUT_OF_RANGE, "" + precision);
        }
      case Types.SQL_REAL:
      case Types.SQL_DOUBLE:
        return SQL_DOUBLE;

      case Types.SQL_NUMERIC:
      case Types.SQL_DECIMAL:
        if (precision == 0) {
          precision = NumberType.defaultNumericPrecision;
        }

        return NumberType.getNumberType(type, precision, scale);

      case Types.SQL_BOOLEAN:
        return SQL_BOOLEAN;

      case Types.SQL_BINARY:
      case Types.SQL_VARBINARY:
      case Types.SQL_BLOB:
        return BinaryType.getBinaryType(type, precision);

      case Types.SQL_DATE:
      case Types.SQL_TIME:
      case Types.SQL_TIMESTAMP:
        return DateTimeType.getDateTimeType(type, scale);

      case Types.SQL_INTERVAL_YEAR:
      case Types.SQL_INTERVAL_YEAR_TO_MONTH:
      case Types.SQL_INTERVAL_MONTH:
      case Types.SQL_INTERVAL_DAY:
      case Types.SQL_INTERVAL_DAY_TO_HOUR:
      case Types.SQL_INTERVAL_DAY_TO_MINUTE:
      case Types.SQL_INTERVAL_DAY_TO_SECOND:
      case Types.SQL_INTERVAL_HOUR:
      case Types.SQL_INTERVAL_HOUR_TO_MINUTE:
      case Types.SQL_INTERVAL_HOUR_TO_SECOND:
      case Types.SQL_INTERVAL_MINUTE:
      case Types.SQL_INTERVAL_MINUTE_TO_SECOND:
      case Types.SQL_INTERVAL_SECOND:
        return IntervalType.getIntervalType(type, precision, scale);

      case Types.OTHER:
        return OTHER;

      default:
        throw Trace.runtimeError(Trace.UNSUPPORTED_INTERNAL_OPERATION, "Type");
    }
  }
Пример #2
0
  /** Enforces precision and scale limits on type */
  public static Type getType(int type, int collation, long precision, int scale) {

    switch (type) {
      case Types.SQL_ALL_TYPES:
        return SQL_ALL_TYPES;

        //                return SQL_ALL_TYPES; // needs changes to Expression type resolution
      case Types.SQL_CHAR:
      case Types.SQL_VARCHAR:
      case Types.VARCHAR_IGNORECASE:
      case Types.SQL_CLOB:
        return CharacterType.getCharacterType(type, precision);

      case Types.SQL_INTEGER:
        return SQL_INTEGER;

      case Types.SQL_SMALLINT:
        return SQL_SMALLINT;

      case Types.SQL_BIGINT:
        return SQL_BIGINT;

      case Types.TINYINT:
        return TINYINT;

      case Types.SQL_FLOAT:
        if (precision > 53) {
          throw Error.error(ErrorCode.X_42592, "" + precision);
        }

        // fall through
      case Types.SQL_REAL:
      case Types.SQL_DOUBLE:
        return SQL_DOUBLE;

      case Types.SQL_NUMERIC:
      case Types.SQL_DECIMAL:
        if (precision == 0) {
          precision = NumberType.defaultNumericPrecision;
        }

        return NumberType.getNumberType(type, precision, scale);

      case Types.SQL_BOOLEAN:
        return SQL_BOOLEAN;

      case Types.SQL_BINARY:
      case Types.SQL_VARBINARY:
      case Types.SQL_BLOB:
        return BinaryType.getBinaryType(type, precision);

      case Types.SQL_BIT:
      case Types.SQL_BIT_VARYING:
        return BitType.getBitType(type, precision);

      case Types.SQL_DATE:
      case Types.SQL_TIME:
      case Types.SQL_TIME_WITH_TIME_ZONE:
      case Types.SQL_TIMESTAMP:
      case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
        return DateTimeType.getDateTimeType(type, scale);

      case Types.SQL_INTERVAL_YEAR:
      case Types.SQL_INTERVAL_YEAR_TO_MONTH:
      case Types.SQL_INTERVAL_MONTH:
      case Types.SQL_INTERVAL_DAY:
      case Types.SQL_INTERVAL_DAY_TO_HOUR:
      case Types.SQL_INTERVAL_DAY_TO_MINUTE:
      case Types.SQL_INTERVAL_DAY_TO_SECOND:
      case Types.SQL_INTERVAL_HOUR:
      case Types.SQL_INTERVAL_HOUR_TO_MINUTE:
      case Types.SQL_INTERVAL_HOUR_TO_SECOND:
      case Types.SQL_INTERVAL_MINUTE:
      case Types.SQL_INTERVAL_MINUTE_TO_SECOND:
      case Types.SQL_INTERVAL_SECOND:
        return IntervalType.getIntervalType(type, precision, scale);

      case Types.OTHER:
        return OTHER;

      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }
  }