Exemplo n.º 1
0
 public static String computeTestName(
     final String toScan,
     final int dataType,
     final long precision,
     final int fractionalPrecision) {
   return "\""
       + toScan
       + "\", "
       + IntervalType.getIntervalType(dataType, precision, fractionalPrecision).getDefinition()
       + ", ("
       + precision
       + ","
       + fractionalPrecision
       + ")";
 }
Exemplo n.º 2
0
  IntervalType readIntervalType() {

    int precision = -1;
    int scale = -1;
    int startToken;
    int endToken;

    startToken = endToken = token.tokenType;

    read();

    if (token.tokenType == Tokens.OPENBRACKET) {
      read();

      precision = readInteger();

      if (precision <= 0) {
        throw Error.error(ErrorCode.X_42592);
      }

      if (token.tokenType == Tokens.COMMA) {
        if (startToken != Tokens.SECOND) {
          throw unexpectedToken();
        }

        read();

        scale = readInteger();

        if (scale < 0) {
          throw Error.error(ErrorCode.X_42592);
        }
      }

      readThis(Tokens.CLOSEBRACKET);
    }

    if (token.tokenType == Tokens.TO) {
      read();

      endToken = token.tokenType;

      read();
    }

    if (token.tokenType == Tokens.OPENBRACKET) {
      if (endToken != Tokens.SECOND || endToken == startToken) {
        throw unexpectedToken();
      }

      read();

      scale = readInteger();

      if (scale < 0) {
        throw Error.error(ErrorCode.X_42592);
      }

      readThis(Tokens.CLOSEBRACKET);
    }

    int startIndex = ArrayUtil.find(Tokens.SQL_INTERVAL_FIELD_CODES, startToken);
    int endIndex = ArrayUtil.find(Tokens.SQL_INTERVAL_FIELD_CODES, endToken);

    return IntervalType.getIntervalType(startIndex, endIndex, precision, scale);
  }
Exemplo n.º 3
0
 @Override
 protected void runTest() throws Exception {
   IntervalType t = IntervalType.getIntervalType(m_dataType, m_precision, m_fractionalPrecision);
   Scanner scanner = new Scanner();
   Object i = scanner.convertToDatetimeInterval(null, m_toScan, t);
 }
Exemplo n.º 4
0
  Expression readDateTimeIntervalLiteral() {

    int pos = getPosition();

    switch (token.tokenType) {
      case Tokens.DATE:
        {
          read();

          if (token.tokenType != Tokens.X_VALUE || token.dataType.typeCode != Types.SQL_CHAR) {
            break;
          }

          String s = token.tokenString;

          read();

          Object date = scanner.newDate(s);

          return new ExpressionValue(date, Type.SQL_DATE);
        }
      case Tokens.TIME:
        {
          read();

          if (token.tokenType != Tokens.X_VALUE || token.dataType.typeCode != Types.SQL_CHAR) {
            break;
          }

          String s = token.tokenString;

          read();

          TimeData value = scanner.newTime(s);
          Type dataType = scanner.dateTimeType;

          return new ExpressionValue(value, dataType);
        }
      case Tokens.TIMESTAMP:
        {
          read();

          if (token.tokenType != Tokens.X_VALUE || token.dataType.typeCode != Types.SQL_CHAR) {
            break;
          }

          String s = token.tokenString;

          read();

          Object date = scanner.newTimestamp(s);
          Type dataType = scanner.dateTimeType;

          return new ExpressionValue(date, dataType);
        }
      case Tokens.INTERVAL:
        {
          boolean minus = false;

          read();

          if (token.tokenType == Tokens.MINUS) {
            read();

            minus = true;
          } else if (token.tokenType == Tokens.PLUS) {
            read();
          }

          if (token.tokenType != Tokens.X_VALUE || token.dataType.typeCode != Types.SQL_CHAR) {
            break;
          }

          String s = token.tokenString;

          read();

          IntervalType dataType = readIntervalType();
          Object interval = scanner.newInterval(s, dataType);

          dataType = (IntervalType) scanner.dateTimeType;

          if (minus) {
            interval = dataType.negate(interval);
          }

          return new ExpressionValue(interval, dataType);
        }
      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "Parser");
    }

    rewind(pos);

    return null;
  }