⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        buildResult(r, limitcount);        if (isAggregated &&!isGrouped &&!isDistinctAggregate) {            addAggregateRow(r, aggregateRow, len, aggregateCount);        } else if (isGrouped) {            groupResult(r);        } else if (isDistinctAggregate) {            r.removeDuplicates();            buildDistinctAggregates(r);            for (int i = 0; i < len; i++) {                Expression e = eColumn[i];                e.setDistinctAggregate(false);                r.colType[i]  = e.getDataType();                r.colSize[i]  = e.getColumnSize();                r.colScale[i] = e.getColumnScale();            }        }        // the result is maybe bigger (due to group and order by)        // but don't tell this anybody else        if (isDistinctSelect) {            int fullColumnCount = r.getColumnCount();            r.setColumnCount(iResultLen);            r.removeDuplicates();            r.setColumnCount(fullColumnCount);        }        if (iOrderLen != 0) {            int order[] = new int[iOrderLen];            int way[]   = new int[iOrderLen];// fredt@users 20020230 - patch 495938 by johnhobs@users - GROUP BY order            for (int i = iResultLen + (isGrouped ? iGroupLen                                                 : 0), j = 0; j < iOrderLen;                    i++, j++) {                order[j] = i;                way[j]   = eColumn[i].isDescending() ? -1                                                     : 1;            }            r.sortResult(order, way);        }        // fredt - now there is no need for the sort and group columns        r.setColumnCount(iResultLen);        for (int i = 0; i < iResultLen; i++) {            Expression e = eColumn[i];            r.sLabel[i]        = e.getAlias();            r.isLabelQuoted[i] = e.isAliasQuoted();            r.sTable[i]        = e.getTableName();            r.sName[i]         = e.getColumnName();        }// fredt@users 20020130 - patch 471710 - LIMIT rewritten        r.trimResult(limitStart, limitCount);        if (sUnion != null) {            Result x = sUnion.getResult(0);            if (iUnionType == UNION) {                r.append(x);                r.removeDuplicates();            } else if (iUnionType == UNIONALL) {                r.append(x);            } else if (iUnionType == INTERSECT) {                r.removeDifferent(x);            } else if (iUnionType == EXCEPT) {                r.removeSecond(x);            }        }        return r;    }    /**     * Method declaration     *     *     * @param row     * @param n     * @param len     *     * @throws SQLException     */    private void updateAggregateRow(Object row[], Object n[],                                    int len) throws SQLException {        for (int i = 0; i < len; i++) {            int type = eColumn[i].getDataType();            switch (eColumn[i].getType()) {                case Expression.DIST_COUNT :                    Integer increment = (n[i] == null) ? Expression.INTEGER_0                                                       : Expression.INTEGER_1;                    row[i] = Column.sum(row[i], increment, Types.INTEGER);                    break;                case Expression.COUNT :                case Expression.AVG :                case Expression.SUM :                    row[i] = Column.sum(row[i], n[i], type);                    break;                case Expression.MIN :                    row[i] = Column.min(row[i], n[i], type);                    break;                case Expression.MAX :                    row[i] = Column.max(row[i], n[i], type);                    break;                default :                    row[i] = n[i];                    break;            }        }    }    /**     * Method declaration     *     *     * @param x     * @param row     * @param len     * @param count     *     * @throws SQLException     */    private void addAggregateRow(Result x, Object row[], int len,                                 int count) throws SQLException {        for (int i = 0; i < len; i++) {            int t = eColumn[i].getType();            if (t == Expression.AVG) {                row[i] = Column.avg(row[i], eColumn[i].getDataType(), count);            } else if (t == Expression.COUNT) {                // this fixes the problem with count(*) on a empty table                if (row[i] == null) {                    row[i] = Expression.INTEGER_0;                }            }        }        x.add(row);    }    private void buildResult(Result r, int limitcount) throws SQLException {        int     len     = eColumn.length;        int     count   = 0;        int     filter  = tFilter.length;        boolean first[] = new boolean[filter];        int     level   = 0;        boolean addtoaggregate = isAggregated &&!isGrouped                                 &&!isDistinctAggregate;        while (level >= 0 &&!isPreProcess) {            TableFilter t = tFilter[level];            boolean     found;            if (!first[level]) {                found        = t.findFirst();                first[level] = found;            } else {                found        = t.next();                first[level] = found;            }            if (!found) {                level--;                continue;            }            if (level < filter - 1) {                level++;                continue;            }            // apply condition            if (eCondition == null || eCondition.test()) {                Object row[] = new Object[len];                for (int i = 0; i < len; i++) {                    row[i] = eColumn[i].getValue();                }                count++;// fredt@users 20010701 - patch for bug 416144 416146 430615 by fredt                if (addtoaggregate) {                    updateAggregateRow(aggregateRow, row, len);                } else {                    r.add(row);                    if (count >= limitcount) {                        break;                    }                }            }        }        if (addtoaggregate) {            aggregateCount = count;        }    }    private void groupResult(Result r) throws SQLException {        int len     = eColumn.length;        int count   = 0;        int order[] = new int[iGroupLen];        int way[]   = new int[iGroupLen];        for (int i = iResultLen, j = 0; j < iGroupLen; i++, j++) {            order[j] = i;            way[j]   = 1;        }        r.sortResult(order, way);        Record n = r.rRoot;        Result x = new Result(len);        do {            Object row[] = new Object[len];            count = 0;            boolean newgroup = false;            while (n != null && newgroup == false) {                count++;// fredt@users 20020215 - patch 476650 by johnhobs@users - GROUP BY aggregates                for (int i = iResultLen; i < iResultLen + iGroupLen; i++) {                    if (n.next == null) {                        newgroup = true;                    } else if (Column.compare(                            n.data[i], n.next.data[i], r.colType[i]) != 0) {                        // can't use .equals because 'null' is also one group                        newgroup = true;                    }                }                updateAggregateRow(row, n.data, len);                n = n.next;            }// fredt@users 20020320 - patch 476650 by fredt - empty GROUP BY            if (isAggregated || count > 0) {                addAggregateRow(x, row, len, count);            }        } while (n != null);        r.setRows(x);    }    private void buildDistinctAggregates(Result r) throws SQLException {        int    len   = eColumn.length;        int    count = 0;        Record n     = r.rRoot;        Result x     = new Result(len);        Object row[] = new Object[len];        count = 0;        while (n != null) {            count++;            updateAggregateRow(row, n.data, len);            n = n.next;        }        if (isAggregated || count > 0) {            addAggregateRow(x, row, len, count);        }        r.setRows(x);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -