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

📄 sqlparser.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Generated By:JavaCC: Do not edit this line. SQLParser.java *//*   Derby - File org.apache.derby.impl.sql.compile.sqlgrammar.jj   Copyright 1997, 2005 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.*/package org.apache.derby.impl.sql.compile;import org.apache.derby.iapi.sql.Statement;import org.apache.derby.iapi.sql.StatementType;/* aggregates */import org.apache.derby.impl.sql.compile.CountAggregateDefinition;import org.apache.derby.impl.sql.compile.MaxMinAggregateDefinition;import org.apache.derby.impl.sql.compile.SumAvgAggregateDefinition;import org.apache.derby.impl.sql.compile.AggregateNode;import org.apache.derby.impl.sql.compile.BinaryOperatorNode;import org.apache.derby.impl.sql.compile.CallStatementNode;import  org.apache.derby.impl.sql.compile.CharConstantNode;import  org.apache.derby.impl.sql.compile.CastNode;import org.apache.derby.impl.sql.compile.ColumnDefinitionNode;import org.apache.derby.impl.sql.compile.ColumnReference;import org.apache.derby.impl.sql.compile.CursorNode;import org.apache.derby.impl.sql.compile.FromBaseTable;import org.apache.derby.impl.sql.compile.FromList;import org.apache.derby.impl.sql.compile.FromSubquery;import org.apache.derby.impl.sql.compile.FromTable;import org.apache.derby.impl.sql.compile.GroupByList;import org.apache.derby.impl.sql.compile.HasNodeVisitor;import org.apache.derby.impl.sql.compile.JavaToSQLValueNode;import org.apache.derby.impl.sql.compile.JoinNode;import org.apache.derby.impl.sql.compile.MethodCallNode;import org.apache.derby.impl.sql.compile.QueryTreeNode;import org.apache.derby.impl.sql.compile.ReplaceAggregatesWithCRVisitor;import org.apache.derby.impl.sql.compile.ResultColumnList;import org.apache.derby.impl.sql.compile.ResultColumn;import org.apache.derby.impl.sql.compile.OrderByList;import org.apache.derby.impl.sql.compile.OrderByColumn;import org.apache.derby.impl.sql.compile.ResultSetNode;import org.apache.derby.impl.sql.compile.SelectNode;import org.apache.derby.impl.sql.compile.SubqueryNode;import org.apache.derby.impl.sql.compile.TableName;import org.apache.derby.impl.sql.compile.TernaryOperatorNode;import org.apache.derby.impl.sql.compile.ParameterNode;import org.apache.derby.impl.sql.compile.ConstraintDefinitionNode;import org.apache.derby.impl.sql.compile.DMLModStatementNode;import org.apache.derby.impl.sql.compile.StatementNode;import org.apache.derby.impl.sql.compile.TableElementList;import org.apache.derby.impl.sql.compile.TableElementNode;import org.apache.derby.impl.sql.compile.TableOperatorNode;import org.apache.derby.impl.sql.compile.TransactionStatementNode;import org.apache.derby.impl.sql.compile.TriggerReferencingStruct;import org.apache.derby.impl.sql.compile.UnionNode;import org.apache.derby.impl.sql.compile.IntersectOrExceptNode;import org.apache.derby.impl.sql.compile.UnaryOperatorNode;import org.apache.derby.impl.sql.compile.UntypedNullConstantNode;import org.apache.derby.impl.sql.compile.UpdateNode;import org.apache.derby.impl.sql.compile.UserTypeConstantNode;import org.apache.derby.impl.sql.compile.ValueNode;import org.apache.derby.impl.sql.compile.ValueNodeList;import org.apache.derby.impl.sql.compile.GroupByColumn;import org.apache.derby.impl.sql.compile.CurrentDatetimeOperatorNode;import org.apache.derby.impl.sql.compile.CreateStatementNode;import org.apache.derby.impl.sql.compile.AlterTableNode;import org.apache.derby.impl.sql.compile.StringSlicer;import org.apache.derby.impl.sql.compile.ParseException;import org.apache.derby.impl.sql.compile.Token;import org.apache.derby.impl.sql.compile.TokenMgrError;import org.apache.derby.impl.sql.compile.SQLParserConstants;import org.apache.derby.impl.sql.compile.CharStream;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;import org.apache.derby.iapi.sql.execute.ConstantAction;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.sql.compile.TypeCompiler;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.types.DateTimeDataValue;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataTypeUtilities;import org.apache.derby.iapi.types.StringDataValue;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.JDBC30Translation;import org.apache.derby.iapi.reference.Limits;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.sql.compile.NodeFactory;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.catalog.AliasInfo;import org.apache.derby.catalog.TypeDescriptor;import org.apache.derby.catalog.types.RoutineAliasInfo;import org.apache.derby.iapi.services.io.FormatableProperties;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.util.ReuseFactory;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.util.StringUtil;import java.sql.Types;import java.util.Properties;import java.util.Vector;import java.lang.Character;public class SQLParser implements SQLParserConstants {        private static final String[] SAVEPOINT_CLAUSE_NAMES = {"UNIQUE", "ON ROLLBACK RETAIN LOCKS", "ON ROLLBACK RETAIN CURSORS"};        private static final String[] PROCEDURE_CLAUSE_NAMES =                {null, "SPECIFIC", "RESULT SET", "LANGUAGE", "EXTERNAL NAME", "PARAMETER STYLE", "SQL", "ON NULL INPUT"};        private static final String[] TEMPORARY_TABLE_CLAUSE_NAMES = {"NOT LOGGED", "ON COMMIT", "ON ROLLBACK"};        /* The default length of a char or bit if the length is omitted */        private static final int        DEFAULT_STRING_COLUMN_LENGTH = 1;        // Defines for ON or USING clauses        private static final int        ON_OR_USING_CLAUSE_SIZE = 2;        private static final int        ON_CLAUSE = 0;        private static final int        USING_CLAUSE = 1;        // Defines for optional table clauses        private static final int        OPTIONAL_TABLE_CLAUSES_SIZE = 3;        private static final int        OPTIONAL_TABLE_CLAUSES_TABLE_PROPERTIES = 0;        private static final int        OPTIONAL_TABLE_CLAUSES_DERIVED_RCL = 1;        private static final int        OPTIONAL_TABLE_CLAUSES_CORRELATION_NAME = 2;        // Define for UTF8 max        private static final int        MAX_UTF8_LENGTH = 65535;    // Constants for set operator types    private static final int NO_SET_OP = 0;    private static final int UNION_OP = 1;    private static final int UNION_ALL_OP = 2;    private static final int EXCEPT_OP = 3;    private static final int EXCEPT_ALL_OP = 4;    private static final int INTERSECT_OP = 5;    private static final int INTERSECT_ALL_OP = 6;        private StringSlicer                            stringSlicer;        private Object[]                                        paramDefaults;        private String                                          statementSQLText;        private NodeFactory                                     nodeFactory;        private ContextManager                          cm;        private CompilerContext                         compilerContext;        /* The number of the next ? parameter */        private int                     parameterNumber;        /* The list of ? parameters */        private Vector                  parameterList;        /* Remember if the last identifier or keyword was a	 * delimited identifier.  This is used for remembering	 * if the xxx in SERIALIZE(xxx) was a delimited identifier	 * because we need to know whether or not we can convert	 * xxx to upper case if we try to resolve it as a class	 * alias at bind time.	 */        private Boolean lastTokenDelimitedIdentifier = Boolean.FALSE;        private Boolean nextToLastTokenDelimitedIdentifier = Boolean.FALSE;        /*	** Remember the last token we got that was an identifier	*/        private Token   lastIdentifierToken;        private Token   nextToLastIdentifierToken;        static final String SINGLEQUOTES = "\'\'";        static final String DOUBLEQUOTES = "\"\"";        static final String DEFAULT_INDEX_TYPE = "BTREE";        //the following 2 booleans are used to make sure only null or not null is        //defined for a column while creating a table or altering a table. Defining        //both at the same time will be an error case.        boolean explicitNotNull = false;        boolean explicitNull = false;        //this vector keeps a list of explicitly nullable columns, so that if they        //get used in the table level primary key constraint, it will result in an        //exception.	        Vector explicitlyNullableColumnsList = new Vector();        final void setCompilerContext(CompilerContext cc) {                this.compilerContext = cc;                this.cm = cc.getContextManager();        }        /**	  *	Get the NodeFactory for this database.	  *	  *	@return	The NodeFactory for this database.	  * @exception StandardException		Thrown on error	  */        private final NodeFactory       getNodeFactory()        throws StandardException        {                if ( nodeFactory == null )                {                        nodeFactory = getCompilerContext().getNodeFactory();                }                return  nodeFactory;        }        private final CompilerContext getCompilerContext()        {                return compilerContext;        }        private DataTypeDescriptor getDataTypeServices(int type, int precision, int scale,                        int length)        {                return new DataTypeDescriptor(                                        TypeId.getBuiltInTypeId(type),                                        precision,                                        scale,                                        true, /* assume nullable for now, change it if not nullable */                                        length                                );        }        private DataTypeDescriptor getJavaClassDataTypeDescriptor(String javaClassName)        {                return new DataTypeDescriptor(                                        TypeId.getUserDefinedTypeId(                                                                javaClassName,                                                                lastTokenDelimitedIdentifier.booleanValue()),                                        true);        }        private LanguageConnectionContext getLanguageConnectionContext()        {                return (LanguageConnectionContext) getContextManager().getContext(                                                                                LanguageConnectionContext.CONTEXT_ID);        }        /**		Utility method for checking that the underlying database has been		upgraded to the required level to use this functionality. Used to		disallow SQL statements that would leave on-disk formats that would		not be understood by a engine that matches the current upgrade level		of the database. Throws an exception if the database is not a the required level.		<P>		Typically used for CREATE statements at the parser level. Called usually just		before the node is created, or can be called in just a partial syntax fragment				@param majorVersion Data Dictionary major version (DataDictionary.DD_ constant)		@param feature SQL Feature name, for error text.	*/        private void checkVersion(int version, String feature) throws StandardException        {                getLanguageConnectionContext().getDataDictionary().checkVersion(                                version, feature);        }        /**		Check that the current mode supports internal extensions.		@param feature Description of feature for exception.		@exception StandardException current mode does not support statement	*/        private void checkInternalFeature(String feature) throws StandardException        {                CompilerContext cc = getCompilerContext();                if ((cc.getReliability() & CompilerContext.INTERNAL_SQL_ILLEGAL) != 0)                        throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, feature);        }        /**	 * check if the type length is ok for the given type.	 */        private void checkTypeLimits(int type, int length)                throws StandardException        {        boolean valid = true;        switch (type) {                case Types.BINARY:                case Types.CHAR:                        if (length  > Limits.DB2_CHAR_MAXWIDTH)                                valid = false;                        break;                case Types.VARBINARY:                case Types.VARCHAR:                        if (length  > Limits.DB2_VARCHAR_MAXWIDTH)                                valid = false;                        break;                default:                        break;        }        if (!valid)  // If these limits are too big                 {                        DataTypeDescriptor charDTD =                                DataTypeDescriptor.getBuiltInDataTypeDescriptor(type, length);                        throw StandardException.newException(SQLState.LANG_DB2_LENGTH_PRECISION_SCALE_VIOLATION, charDTD.getSQLstring());                }        }        // Get the current ContextManager        private final ContextManager getContextManager()        {                return cm;        }        private StringSlicer    getStringSlicer()        {                if ( stringSlicer == null )                {                        stringSlicer = new StringSlicer( statementSQLText);                }                return  stringSlicer;        }        /*	** Compress 2 adjacent (single or double) quotes into a single (s or d) quote when	** found in the middle of a String.	** NOTE:  """" or '''' will be compressed into "" or ''.

⌨️ 快捷键说明

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