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

📄 expression.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Copyright (c) 1995-2000, The Hypersonic SQL Group. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the Hypersonic SQL Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals  * on behalf of the Hypersonic SQL Group. * * * For work added by the HSQL Development Group: * * Copyright (c) 2001-2005, The HSQL Development Group * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the HSQL Development Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.hsqldb;import org.hsqldb.HsqlNameManager.HsqlName;import org.hsqldb.index.RowIterator;import org.hsqldb.lib.HashSet;import org.hsqldb.lib.HsqlArrayList;import org.hsqldb.store.ValuePool;// fredt@users 20020215 - patch 1.7.0 by fredt// to preserve column size etc. when SELECT INTO TABLE is used// tony_lai@users 20021020 - patch 1.7.2 - improved aggregates and HAVING// fredt@users 20021112 - patch 1.7.2 by Nitin Chauhan - use of switch// rewrite of the majority of multiple if(){}else{} chains with switch(){}// vorburger@users 20021229 - patch 1.7.2 - null handling// boucherb@users 200307?? - patch 1.7.2 - resolve param nodes// boucherb@users 200307?? - patch 1.7.2 - compress constant expr during resolve// boucherb@users 200307?? - patch 1.7.2 - eager pmd and rsmd// boucherb@users 20031005 - patch 1.7.2 - optimised LIKE// boucherb@users 20031005 - patch 1.7.2 - improved IN value lists// fredt@users 20031012 - patch 1.7.2 - better OUTER JOIN implementation// thomasm@users 20041001 - patch 1.7.3 - BOOLEAN undefined handling// fredt@users 200412xx - patch 1.7.2 - evaluation of time functions// boucherb@users 20050516 - patch 1.8.0 - remove DITypeInfo usage for faster//                                         statement compilation/** * Expression class. * * The core functionality of this class was inherited from HypersonicSQL and * extensively rewritten and extended in successive versions of HSQLDB. * * @author Thomas Mueller (Hypersonic SQL Group) * @version    1.8.0 * @since Hypersonic SQL *//** @todo - fredt - constant TRUE and FALSE type expressions have valueData of  * type BOOLEAN, while computed expressions have no valueData; this should be  * normalised in future  */public class Expression {    // leaf types    static final int VALUE     = 1,                     COLUMN    = 2,                     QUERY     = 3,                     TRUE      = 4,                     FALSE     = -4,    // arbitrary                     VALUELIST = 5,                     ASTERISK  = 6,                     FUNCTION  = 7,                     LIMIT     = 8,                     ROW       = 9;// boucherb@users 20020410 - parametric compiled statements    // new leaf type    static final int PARAM = 9;// --    // operations    static final int NEGATE   = 10,                     ADD      = 11,                     SUBTRACT = 12,                     MULTIPLY = 13,                     DIVIDE   = 14,                     CONCAT   = 15;    // logical operations    static final int NOT           = 20,                     EQUAL         = 21,                     BIGGER_EQUAL  = 22,                     BIGGER        = 23,                     SMALLER       = 24,                     SMALLER_EQUAL = 25,                     NOT_EQUAL     = 26,                     LIKE          = 27,                     AND           = 28,                     OR            = 29,                     IN            = 30,                     EXISTS        = 31,                     ALL           = 32,                     ANY           = 33,                     IS_NULL       = 34;    // aggregate functions    static final int COUNT       = 40,                     SUM         = 41,                     MIN         = 42,                     MAX         = 43,                     AVG         = 44,                     EVERY       = 45,                     SOME        = 46,                     STDDEV_POP  = 47,                     STDDEV_SAMP = 48,                     VAR_POP     = 49,                     VAR_SAMP    = 50;    // system functions    static final int IFNULL      = 60,                     CONVERT     = 61,                     CASEWHEN    = 62,                     EXTRACT     = 63,                     POSITION    = 64,                     TRIM        = 65,                     SUBSTRING   = 66,                     NULLIF      = 67,                     CASE        = 68,                     COALESCE    = 69,                     ALTERNATIVE = 70,                     SEQUENCE    = 71;    // temporary used during parsing    static final int PLUS     = 100,                     OPEN     = 101,                     CLOSE    = 102,                     SELECT   = 103,                     COMMA    = 104,                     BETWEEN  = 106,                     CAST     = 107,                     END      = 108,                     IS       = 109,                     WHEN     = 110,                     THEN     = 111,                     ELSE     = 112,                     ENDWHEN  = 113,                     DISTINCT = 114,                     VIEW     = 115;    // used inside brackets for system functions    static final int     AS                      = 122,                         FOR                     = 123,                         FROM                    = 124,                         BOTH                    = 125,                         LEADING                 = 126,                         TRAILING                = 127,                         YEAR                    = 128,                         MONTH                   = 129,                         DAY                     = 130,                         HOUR                    = 131,                         MINUTE                  = 132,                         SECOND                  = 133,                         TIMEZONE_HOUR           = 134,                         T_TIMEZONE_MINUTE       = 135,                         DOW                     = 136;    static final HashSet SQL_EXTRACT_FIELD_NAMES = new HashSet();    static final HashSet SQL_TRIM_SPECIFICATION  = new HashSet();    static {        SQL_EXTRACT_FIELD_NAMES.addAll(new Object[] {            Token.T_YEAR, Token.T_MONTH, Token.T_DAY, Token.T_HOUR,            Token.T_MINUTE, Token.T_SECOND, Token.T_TIMEZONE_HOUR,            Token.T_TIMEZONE_MINUTE, Token.T_DOW        });        SQL_TRIM_SPECIFICATION.addAll(new Object[] {            Token.T_LEADING, Token.T_TRAILING, Token.T_BOTH        });    }    private static final int AGGREGATE_SELF     = -1;    private static final int AGGREGATE_NONE     = 0;    private static final int AGGREGATE_LEFT     = 1;    private static final int AGGREGATE_RIGHT    = 2;    private static final int AGGREGATE_BOTH     = 3;    private static final int AGGREGATE_FUNCTION = 4;    // type    int         exprType;    private int aggregateSpec = AGGREGATE_NONE;    // nodes    Expression eArg, eArg2;    // VALUE    Object      valueData;    private int dataType;    // VALUE LIST NEW    HashSet         hList;    Expression[]    valueList;    private boolean isFixedConstantValueList;    // QUERY - in single value selects, IN or EXISTS predicates    SubQuery subQuery;    boolean  isQueryCorrelated;    // FUNCTION    Function function;    // LIKE    private Like likeObject;    // COLUMN    private String      catalog;    private String      schema;    private String      tableName;    private String      columnName;    private TableFilter tableFilter;                // null if not yet resolved    TableFilter         outerFilter;                // defined if this is part of an OUTER JOIN condition tree    // COLUMN    private int     columnIndex;    private boolean columnQuoted;    private int     precision;    private int     scale;    private String  columnAlias;                    // if it is a column of a select column list    private boolean aliasQuoted;    //    private boolean isDescending;                   // if it is a column in a order by    int             joinedTableColumnIndex = -1;    // >= 0 when it is used for order by    boolean         isDistinctAggregate;    // PARAM    private boolean isParam;    // does Expression stem from a JOIN <table> ON <expression>    boolean isInJoin;    //    static final Integer INTEGER_0 = ValuePool.getInt(0);    static final Integer INTEGER_1 = ValuePool.getInt(1);    /**     * Creates a new boolean expression     * @param b boolean constant     */    Expression(boolean b) {        exprType = b ? TRUE                     : FALSE;    }    /**     * Creates a new FUNCTION expression     * @param f function     */    Expression(Function f) {        exprType = FUNCTION;        function = f;        if (f.hasAggregate) {            aggregateSpec = AGGREGATE_FUNCTION;        }    }    /**     * Creates a new SEQUENCE expression     * @param sequence number sequence     */    Expression(NumberSequence sequence) {        exprType  = SEQUENCE;        valueData = sequence;        dataType  = sequence.getType();    }    /**     * Copy Constructor. Used by TableFilter to move a condition to a filter.     * @param e source expression     */    Expression(Expression e) {        exprType = e.exprType;        dataType = e.dataType;        eArg     = e.eArg;        eArg2    = e.eArg2;        isInJoin = e.isInJoin;        //        likeObject = e.likeObject;        subQuery   = e.subQuery;        function   = e.function;        checkAggregate();    }    /**     * Creates a new QUERY expression     * @param sq subquery     */    Expression(SubQuery sq) {        exprType = QUERY;        subQuery = sq;    }    /**     * Creates a new VALUELIST expression     * @param valueList array of Expression     */    Expression(Expression[] valueList) {        exprType       = VALUELIST;        this.valueList = valueList;    }    /**     * Creates a new binary (or unary) operation expression     *     * @param type operator type     * @param e operand 1     * @param e2 operand 2     */    Expression(int type, Expression e, Expression e2) {        exprType = type;        eArg     = e;        eArg2    = e2;        checkAggregate();    }    /**     * creates a CONVERT expression     */    Expression(Expression e, int dataType, int precision, int scale) {        this.exprType    = CONVERT;        this.eArg        = e;        this.dataType    = dataType;        this.precision   = precision;        this.scale       = scale;        this.columnAlias = e.columnAlias;        this.aliasQuoted = e.aliasQuoted;        checkAggregate();    }    /**     * Creates a new LIKE expression     *     * @param e operand 1     * @param e2 operand 2     * @param escape escape character     */    Expression(Expression e, Expression e2, Character escape,               boolean hasCollation) {        exprType   = LIKE;        eArg       = e;        eArg2      = e2;        likeObject = new Like(escape, hasCollation);        checkAggregate();    }    /**     * Creates a new ASTERISK or COLUMN expression     * @param table table     * @param column column     */    Expression(String schema, String table, String column) {        this.schema = schema;        tableName   = table;        if (column == null) {            exprType = ASTERISK;        } else {            exprType   = COLUMN;            columnName = column;        }    }    /**     * Creates a new ASTERIX or possibly quoted COLUMN expression     * @param table table     * @param column column name     * @param isquoted boolean     */    Expression(String table, String column, boolean isquoted) {        tableName = table;        if (column == null) {            exprType = ASTERISK;        } else {            exprType     = COLUMN;            columnName   = column;            columnQuoted = isquoted;        }    }    Expression(TableFilter filter, Column column) {        schema    = filter.filterTable.tableName.schema.name;        tableName = filter.getName();        if (column == null) {            exprType = ASTERISK;        } else {            exprType     = COLUMN;            columnName   = column.columnName.name;            columnQuoted = column.columnName.isNameQuoted;            dataType     = column.getType();        }    }

⌨️ 快捷键说明

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