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

📄 expression.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (sSelect != null) {            sSelect.resolve(f, false);            sSelect.resolve();        }        if (fFunction != null) {            fFunction.resolve(f);        }        if (iDataType != 0) {            return;        }        switch (iType) {            case FUNCTION :                iDataType = fFunction.getReturnType();                break;            case QUERY :                iDataType = sSelect.eColumn[0].iDataType;                break;            case NEGATE :                iDataType = eArg.iDataType;                break;            case ADD :            case SUBTRACT :            case MULTIPLY :            case DIVIDE :// fredt@users 20011010 - patch 442993 by fredt                iDataType = Column.getCombinedNumberType(eArg.iDataType,                        eArg2.iDataType, iType);                break;            case CONCAT :                iDataType = Types.VARCHAR;                break;            case NOT :            case EQUAL :            case BIGGER_EQUAL :            case BIGGER :            case SMALLER :            case SMALLER_EQUAL :            case NOT_EQUAL :            case LIKE :            case AND :            case OR :            case IN :            case EXISTS :                iDataType = Types.BIT;                break;            case COUNT :                iDataType = Types.INTEGER;                break;            case DIST_COUNT :                if (eArg.iType == ASTERIX) {                    iDataType = Types.INTEGER;                }            case MAX :            case MIN :            case SUM :            case AVG :                iDataType = eArg.iDataType;                break;            case CONVERT :                // it is already set                break;            case IFNULL :            case CASEWHEN :                iDataType = eArg2.iDataType;                break;        }    }// fredt@users 20021012 - patch 1.7.1 by hofhansl@users - use index with negate    /**     * Method declaration     *     *     * @return     */    boolean isResolved() {        if (iType == VALUE || iType == NEGATE) {            return true;        }        if (iType == COLUMN) {            return tFilter != null;        }        // todo: could recurse here, but never miss a 'false'!        return false;    }    /**     * Method declaration     *     *     * @param i     *     * @return     */    static boolean isCompare(int i) {        switch (i) {            case EQUAL :            case BIGGER_EQUAL :            case BIGGER :            case SMALLER :            case SMALLER_EQUAL :            case NOT_EQUAL :                return true;        }        return false;    }    /**     * Method declaration     *     *     * @return     */    String getTableName() {        if (iType == ASTERIX) {            return sTable;        }        if (iType == COLUMN) {            if (tFilter == null) {                return sTable;            } else {                return tFilter.getTable().getName().name;            }        }        // todo        return "";    }    /**     * Method declaration     *     *     * @return     */    String getColumnName() {        if (iType == COLUMN) {            if (tFilter == null) {                return sColumn;            } else {                return tFilter.getTable().getColumn(iColumn).columnName.name;            }        }        return getAlias();    }    /**     * Method declaration     *     *     * @return     */    int getColumnNr() {        return iColumn;    }    /**     * Method declaration     *     *     * @return     */    int getColumnSize() {        return iColumnSize;    }    /**     * Method declaration     *     *     * @return     */    int getColumnScale() {        return iColumnScale;    }    /**     * Method declaration     *     * @return     */    boolean isDistinctAggregate() {        return isDistinctAggregate;    }    /**     * Method declaration     *     * @param type     */    void setDistinctAggregate(boolean type) {        isDistinctAggregate = type;        if (iType == COUNT || iType == DIST_COUNT) {            iType     = type ? DIST_COUNT                             : COUNT;            iDataType = type ? iDataType                             : Types.INTEGER;        }    }    /**     * Method declaration     *     *     * @throws SQLException     */    void swapCondition() throws SQLException {        int i = EQUAL;        switch (iType) {            case BIGGER_EQUAL :                i = SMALLER_EQUAL;                break;            case SMALLER_EQUAL :                i = BIGGER_EQUAL;                break;            case SMALLER :                i = BIGGER;                break;            case BIGGER :                i = SMALLER;                break;            case EQUAL :                break;            default :                Trace.doAssert(false, "Expression.swapCondition");        }        iType = i;        Expression e = eArg;        eArg  = eArg2;        eArg2 = e;    }    /**     * Method declaration     *     *     * @return     */    int getDataType() {        return iDataType;    }    /**     * Method declaration     *     *     * @param type     *     * @return     *     * @throws SQLException     */    Object getValue(int type) throws SQLException {        Object o = getValue();        if ((o == null) || (iDataType == type)) {            return o;        }        return Column.convertObject(o, type);    }    /**     * Method declaration     *     *     * @return     *     * @throws SQLException     */    Object getValue() throws SQLException {        switch (iType) {            case VALUE :                return oData;            case COLUMN :                try {                    return tFilter.oCurrentData[iColumn];                } catch (NullPointerException e) {                    throw Trace.error(Trace.COLUMN_NOT_FOUND, sColumn);                }            case FUNCTION :                return fFunction.getValue();            case QUERY :                return sSelect.getValue(iDataType);            case NEGATE :                return Column.negate(eArg.getValue(iDataType), iDataType);            case COUNT :                // count(*): sum(1); count(col): sum(col<>null)                if (eArg.iType == ASTERIX) {                    return INTEGER_1;                }                if (eArg.getValue() == null) {                    return INTEGER_0;                } else {                    return INTEGER_1;                }            case DIST_COUNT :                if (eArg.iType == ASTERIX) {                    return INTEGER_1;                }            case MAX :            case MIN :            case SUM :            case AVG :                return eArg.getValue();            case EXISTS :                return new Boolean(test());            case CONVERT :                return eArg.getValue(iDataType);            case CASEWHEN :                if (eArg.test()) {                    return eArg2.eArg.getValue();                } else {                    return eArg2.eArg2.getValue();                }        }        // todo: simplify this        Object a = null,               b = null;        if (eArg != null) {            a = eArg.getValue(iDataType);        }        if (eArg2 != null) {            b = eArg2.getValue(iDataType);        }        switch (iType) {            case ADD :                return Column.add(a, b, iDataType);            case SUBTRACT :                return Column.subtract(a, b, iDataType);            case MULTIPLY :                return Column.multiply(a, b, iDataType);            case DIVIDE :                return Column.divide(a, b, iDataType);            case CONCAT :                return Column.concat(a, b);            case IFNULL :                return (a == null) ? b                                   : a;            default :                // must be comparisation                // todo: make sure it is                return new Boolean(test());        }    }    /**     * Method declaration     *     *     * @return     *     * @throws SQLException     */    boolean test() throws SQLException {        switch (iType) {            case TRUE :                return true;            case NOT :                Trace.doAssert(eArg2 == null, "Expression.test");                return !eArg.test();            case AND :                return eArg.test() && eArg2.test();            case OR :                return eArg.test() || eArg2.test();            case LIKE :                // todo: now for all tests a new 'like' object required!                String s    = (String) eArg2.getValue(Types.VARCHAR);                int    type = eArg.iDataType;                Like l = new Like(s, cLikeEscape,                                  type == Column.VARCHAR_IGNORECASE);                String c = (String) eArg.getValue(Types.VARCHAR);                return l.compare(c);            case IN :                return eArg2.testValueList(eArg.getValue(), eArg.iDataType);            case EXISTS :                Result r = eArg.sSelect.getResult(1);    // 1 is already enough                return r.rRoot != null;        }        Trace.check(eArg != null, Trace.GENERAL_ERROR);        Object o    = eArg.getValue();        int    type = eArg.iDataType;        Trace.check(eArg2 != null, Trace.GENERAL_ERROR);        Object o2     = eArg2.getValue(type);        int    result = Column.compare(o, o2, type);        switch (iType) {            case EQUAL :                return result == 0;            case BIGGER :                return result > 0;            case BIGGER_EQUAL :                return result >= 0;            case SMALLER_EQUAL :                return result <= 0;            case SMALLER :                return result < 0;            case NOT_EQUAL :                return result != 0;        }        Trace.doAssert(false, "Expression.test2");        return false;    }    /**     * Method declaration     *     *     * @param o     * @param datatype     *     * @return     *     * @throws SQLException     */    private boolean testValueList(Object o,                                  int datatype) throws SQLException {        if (iType == VALUELIST) {            if (datatype != iDataType) {                o = Column.convertObject(o, iDataType);            }            if (o == null) {                return hListHasNull;            } else {                return hList.containsKey(o);            }        } else if (iType == QUERY) {            // todo: convert to valuelist before if everything is resolvable            Result r    = sSelect.getResult(0);            Record n    = r.rRoot;            int    type = r.colType[0];            if (datatype != type) {                o = Column.convertObject(o, type);            }            while (n != null) {                Object o2 = n.data[0];                if ((o2 != null) && o2.equals(o)) {                    return true;                }                n = n.next;            }            return false;        }        throw Trace.error(Trace.WRONG_DATA_TYPE);    }}

⌨️ 快捷键说明

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