Esempio n. 1
0
  public boolean visit(SQLSelectQueryBlock x) {
    if (x.getFrom() == null) {
      return false;
    }

    setMode(x, Mode.Select);

    if (x.getFrom() instanceof SQLSubqueryTableSource) {
      x.getFrom().accept(this);
      return false;
    }

    if (x.getInto() != null && x.getInto().getExpr() instanceof SQLName) {
      SQLName into = (SQLName) x.getInto().getExpr();
      String ident = into.toString();
      TableStat stat = getTableStat(ident);
      if (stat != null) {
        stat.incrementInsertCount();
      }
    }

    String originalTable = getCurrentTable();

    if (x.getFrom() instanceof SQLExprTableSource) {
      SQLExprTableSource tableSource = (SQLExprTableSource) x.getFrom();
      if (tableSource.getExpr() instanceof SQLName) {
        String ident = tableSource.getExpr().toString();

        setCurrentTable(x, ident);
        x.putAttribute(ATTR_TABLE, ident);
        if (x.getParent() instanceof SQLSelect) {
          x.getParent().putAttribute(ATTR_TABLE, ident);
        }
        x.putAttribute("_old_local_", originalTable);
      }
    }

    if (x.getFrom() != null) {
      x.getFrom().accept(this); // 提前执行,获得aliasMap
      String table = (String) x.getFrom().getAttribute(ATTR_TABLE);
      if (table != null) {
        x.putAttribute(ATTR_TABLE, table);
      }
    }

    // String ident = x.getTable().toString();
    //
    // TableStat stat = getTableStat(ident);
    // stat.incrementInsertCount();
    // return false;

    if (x.getWhere() != null) {
      x.getWhere().setParent(x);
    }

    return true;
  }