Exemple #1
0
 static Table newSingleColumnTable(
     Database paramDatabase,
     HsqlNameManager.HsqlName paramHsqlName1,
     int paramInt,
     HsqlNameManager.HsqlName paramHsqlName2,
     Type paramType) {
   TableDerived localTableDerived = new TableDerived(paramDatabase, paramHsqlName1, paramInt);
   ColumnSchema localColumnSchema = new ColumnSchema(paramHsqlName2, paramType, false, true, null);
   localTableDerived.addColumn(localColumnSchema);
   localTableDerived.createPrimaryKeyConstraint(localTableDerived.getName(), new int[] {0}, true);
   return localTableDerived;
 }
  public Object[] getValues(Session session) {

    RowIterator it = table.rowIterator(session);

    if (it.hasNext()) {
      Row row = it.getNextRow();

      if (it.hasNext()) {
        throw Error.error(ErrorCode.X_21000);
      }

      return row.getData();
    } else {
      return new Object[table.getColumnCount()];
    }
  }
  /** Fills the table with a result set */
  public void materialise(Session session) {

    PersistentStore store;

    // table constructors
    if (isDataExpression) {
      store = session.sessionData.getSubqueryRowStore(table);

      dataExpression.insertValuesIntoSubqueryTable(session, store);

      return;
    }

    Result result = queryExpression.getResult(session, isExistsPredicate ? 1 : 0);

    if (uniqueRows) {
      RowSetNavigatorData navigator = ((RowSetNavigatorData) result.getNavigator());

      navigator.removeDuplicates();
    }

    store = session.sessionData.getSubqueryRowStore(table);

    table.insertResult(store, result);
    result.getNavigator().close();
  }
  public void prepareTable(Session session) {

    if (table != null) {
      return;
    }

    if (view == null) {
      table = TableUtil.newSubqueryTable(database, null);

      if (isDataExpression) {
        TableUtil.setTableColumnsForSubquery(
            table, dataExpression.nodeDataTypes, uniqueRows || isUniquePredicate, uniqueRows);
      } else {
        TableUtil.setTableColumnsForSubquery(
            table, queryExpression, uniqueRows || isUniquePredicate);
      }
    } else {
      table = new TableDerived(database, view.getName(), TableBase.VIEW_TABLE, queryExpression);
      table.columnList = view.columnList;
      table.columnCount = table.columnList.size();

      table.createPrimaryKey();
    }
  }
  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);
  }