Пример #1
0
 boolean hasColumn(int paramInt) {
   switch (this.constType) {
     case 3:
       return this.rangeVariable.usedColumns[paramInt];
     case 1:
     case 2:
     case 4:
       return ArrayUtil.find(this.core.mainCols, paramInt) != -1;
     case 0:
       return ArrayUtil.find(this.core.refCols, paramInt) != -1;
   }
   throw Error.runtimeError(201, "Constraint");
 }
Пример #2
0
  String getStatement(int startPosition, short[] startTokens) {

    int semiPosition = 0;

    while (true) {
      if (token.tokenType == Tokens.SEMICOLON) {
        semiPosition = scanner.getPosition();
      } else if (token.tokenType == Tokens.X_ENDPARSE) {
        if (semiPosition == 0) {
          break;
        } else {
          rewind(semiPosition);

          break;
        }
      } else {
        semiPosition = 0;

        if (ArrayUtil.find(startTokens, token.tokenType) != -1) {
          break;
        }
      }

      read();
    }

    String sql = scanner.getPart(startPosition, scanner.getPosition());

    return sql;
  }
Пример #3
0
  boolean hasColumn(int colIndex) {

    switch (constType) {
      case CHECK:
        return rangeVariable.usedColumns[colIndex];

      case PRIMARY_KEY:
      case UNIQUE:
      case MAIN:
        return ArrayUtil.find(core.mainCols, colIndex) != -1;

      case FOREIGN_KEY:
        return ArrayUtil.find(core.refCols, colIndex) != -1;

      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "Constraint");
    }
  }
Пример #4
0
 boolean hasColumnPlus(int paramInt) {
   switch (this.constType) {
     case 3:
       return (this.rangeVariable.usedColumns[paramInt] != 0)
           && (ArrayUtil.countTrueElements(this.rangeVariable.usedColumns) > 1);
     case 2:
     case 4:
       return (this.core.mainCols.length != 1)
           && (ArrayUtil.find(this.core.mainCols, paramInt) != -1);
     case 1:
       return (ArrayUtil.find(this.core.mainCols, paramInt) != -1)
           && ((this.core.mainCols.length != 1) || (this.core.mainTable != this.core.refTable));
     case 0:
       return (ArrayUtil.find(this.core.refCols, paramInt) != -1)
           && ((this.core.mainCols.length != 1) || (this.core.mainTable != this.core.refTable));
   }
   throw Error.runtimeError(201, "Constraint");
 }
Пример #5
0
  boolean hasColumnPlus(int colIndex) {

    switch (constType) {
      case CHECK:
        return rangeVariable.usedColumns[colIndex]
            && ArrayUtil.countTrueElements(rangeVariable.usedColumns) > 1;

      case PRIMARY_KEY:
      case UNIQUE:
        return core.mainCols.length != 1 && ArrayUtil.find(core.mainCols, colIndex) != -1;

      case MAIN:
        return ArrayUtil.find(core.mainCols, colIndex) != -1
            && (core.mainCols.length != 1 || core.mainTable != core.refTable);

      case FOREIGN_KEY:
        return ArrayUtil.find(core.refCols, colIndex) != -1
            && (core.mainCols.length != 1 || core.mainTable == core.refTable);

      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "Constraint");
    }
  }
  /** Initializes this connection. */
  private void init() {

    runnerThread = Thread.currentThread();
    keepAlive = true;

    try {
      socket.setTcpNoDelay(true);

      dataInput = new DataInputStream(socket.getInputStream());
      dataOutput = new BufferedOutputStream(socket.getOutputStream());

      Result resultIn = Result.read(rowIn, dataInput);
      Result resultOut;

      try {
        int dbIndex = ArrayUtil.find(server.dbAlias, resultIn.subSubString);

        dbID = server.dbID[dbIndex];
        user = resultIn.getMainString();
        password = resultIn.getSubString();

        if (!server.isSilent()) {
          server.printWithThread(mThread + ":trying to connect user " + user);
        }

        session =
            DatabaseManager.newSession(dbID, resultIn.getMainString(), resultIn.getSubString());
        resultOut = new Result(ResultConstants.UPDATECOUNT);
        resultOut.databaseID = session.getDatabase().databaseID;
        resultOut.sessionID = session.getId();
      } catch (HsqlException e) {
        session = null;
        resultOut = new Result(e, null);
      } catch (ArrayIndexOutOfBoundsException e) {
        session = null;
        resultOut = new Result(Trace.error(Trace.DATABASE_NOT_EXISTS), resultIn.subSubString);
      }

      Result.write(resultOut, rowOut, dataOutput);

      return;
    } catch (Exception e) {
      server.printWithThread(mThread + ":couldn't connect " + user);
    }

    close();
  }
  void moveConditionsToInner(Session session, RangeVariable[] ranges) {

    Expression[] colExpr;
    int exclude;
    HsqlArrayList conditionsList;
    Expression condition = null;

    if (whereConditions.length > 1) {
      return;
    }

    if (joinConditions.length > 1) {
      return;
    }

    for (int i = 0; i < ranges.length; i++) {
      if (ranges[i].isLeftJoin || ranges[i].isRightJoin) {
        return;
      }
    }

    exclude = ArrayUtil.find(ranges, this);
    conditionsList = new HsqlArrayList();

    addConditionsToList(conditionsList, joinConditions[0].indexCond);

    if (joinConditions[0].indexCond != null
        && joinConditions[0].indexCond[0] != joinConditions[0].indexEndCond[0]) {
      addConditionsToList(conditionsList, joinConditions[0].indexEndCond);
    }

    addConditionsToList(conditionsList, whereConditions[0].indexCond);
    addConditionsToList(conditionsList, whereConditions[0].indexEndCond);
    RangeVariableResolver.decomposeAndConditions(
        session, joinConditions[0].nonIndexCondition, conditionsList);
    RangeVariableResolver.decomposeAndConditions(
        session, whereConditions[0].nonIndexCondition, conditionsList);

    for (int i = conditionsList.size() - 1; i >= 0; i--) {
      Expression e = (Expression) conditionsList.get(i);

      if (e == null || e.isTrue() || e.hasReference(ranges, exclude)) {
        conditionsList.remove(i);

        continue;
      }
    }

    if (conditionsList.size() == 0) {
      if (rangeTable.isView()) {
        ((TableDerived) rangeTable).resetToView();
      }

      return;
    }

    QueryExpression queryExpression = rangeTable.getQueryExpression();

    colExpr = ((QuerySpecification) queryExpression).exprColumns;

    for (int i = 0; i < conditionsList.size(); i++) {
      Expression e = (Expression) conditionsList.get(i);
      OrderedHashSet set = e.collectRangeVariables(null);

      e = e.duplicate();
      e = e.replaceColumnReferences(this, colExpr);

      if (e.collectAllSubqueries(null) != null) {
        return;
      }

      if (set != null) {
        for (int j = 0; j < set.size(); j++) {
          RangeVariable range = (RangeVariable) set.get(j);

          if (this != range && range.rangeType == RangeVariable.TABLE_RANGE) {
            queryExpression.setCorrelated();
          }
        }
      }

      condition = ExpressionLogical.andExpressions(condition, e);
    }

    queryExpression.addExtraConditions(condition);
  }
Пример #8
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);
  }