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

📄 databasecommandinterpreter.java

📁 一個Light Weighted的Java Database Engin 適合各個領域之Java數据庫編輯.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if (type != Types.TIMESTAMP && length == 0) {                throw Trace.error(Trace.INVALID_SIZE_PRECISION);            }            if (tokenizer.isGetThis(Token.T_COMMA)) {                scale = tokenizer.getInt();                Trace.check(Types.acceptsScaleCreateParam(type),                            Trace.UNEXPECTED_TOKEN);            }            tokenizer.getThis(Token.T_CLOSEBRACKET);        } else if (type == Types.CHAR && database.sqlEnforceStrictSize) {            length = 1;        } else if (type == Types.VARCHAR && database.sqlEnforceStrictSize) {            throw Trace.error(Trace.COLUMN_SIZE_REQUIRED);        }        /**         * @todo fredt - drop support for SET IGNORECASE and replace the         * type name with a qualifier specifying the case sensitivity of VARCHAR         */        if (type == Types.VARCHAR && database.isIgnoreCase()) {            type = Types.VARCHAR_IGNORECASE;        }        if (type == Types.FLOAT && length > 53) {            throw Trace.error(Trace.NUMERIC_VALUE_OUT_OF_RANGE);        }        if (type == Types.TIMESTAMP) {            if (!hasLength) {                length = 6;            } else if (length != 0 && length != 6) {                throw Trace.error(Trace.NUMERIC_VALUE_OUT_OF_RANGE);            }        }        token = tokenizer.getSimpleToken();        if (token.equals(Token.T_DEFAULT)) {            defaultExpr = processCreateDefaultExpression(type, length, scale);            token       = tokenizer.getSimpleToken();        } else if (token.equals(Token.T_GENERATED)) {            tokenizer.getThis(Token.T_BY);            tokenizer.getThis(Token.T_DEFAULT);            tokenizer.getThis(Token.T_AS);            tokenizer.getThis(Token.T_IDENTITY);            if (tokenizer.isGetThis(Token.T_OPENBRACKET)) {                tokenizer.getThis(Token.T_START);                tokenizer.getThis(Token.T_WITH);                identityStart = tokenizer.getBigint();                if (tokenizer.isGetThis(Token.T_COMMA)) {                    tokenizer.getThis(Token.T_INCREMENT);                    tokenizer.getThis(Token.T_BY);                    identityIncrement = tokenizer.getBigint();                }                tokenizer.getThis(Token.T_CLOSEBRACKET);            }            isIdentity   = true;            isPrimaryKey = true;            token        = tokenizer.getSimpleToken();        }        // fredt@users - accept IDENTITY before or after NOT NULL        if (token.equals(Token.T_IDENTITY)) {            isIdentity   = true;            isPrimaryKey = true;            token        = tokenizer.getSimpleToken();        }        if (token.equals(Token.T_NULL)) {            token = tokenizer.getSimpleToken();        } else if (token.equals(Token.T_NOT)) {            tokenizer.getThis(Token.T_NULL);            isNullable = false;            token      = tokenizer.getSimpleToken();        }        if (token.equals(Token.T_IDENTITY)) {            if (isIdentity) {                throw Trace.error(Trace.SECOND_PRIMARY_KEY, Token.T_IDENTITY);            }            isIdentity   = true;            isPrimaryKey = true;            token        = tokenizer.getSimpleToken();        }        if (token.equals(Token.T_PRIMARY)) {            tokenizer.getThis(Token.T_KEY);            isPrimaryKey = true;        } else {            tokenizer.back();        }        // make sure IDENTITY and DEFAULT are not used together        if (isIdentity && defaultExpr != null) {            throw Trace.error(Trace.UNEXPECTED_TOKEN, Token.T_DEFAULT);        }        Column column = new Column(hsqlName, isNullable, type, length, scale,                                   isPrimaryKey, defaultExpr);        column.setIdentity(isIdentity, identityStart, identityIncrement);        return column;    }    /**     * @param type data type of column     * @param length maximum length of column     * @throws HsqlException     * @return new Expression     */    private Expression processCreateDefaultExpression(int type, int length,            int scale) throws HsqlException {        if (type == Types.OTHER) {            throw Trace.error(Trace.WRONG_DEFAULT_CLAUSE);        }        Parser     parser = new Parser(session, database, tokenizer);        Expression expr   = parser.readDefaultClause(type);        expr.resolveTypes(session);        if (expr.getType() == Expression.VALUE                || (expr.getType() == Expression.FUNCTION                    && expr.function.isSimple)) {            Object defValTemp;            try {                defValTemp = expr.getValue(session, type);            } catch (HsqlException e) {                throw Trace.error(Trace.WRONG_DEFAULT_CLAUSE);            }            if (defValTemp != null && database.sqlEnforceStrictSize) {                try {                    Column.enforceSize(defValTemp, type, length, scale, true);                } catch (HsqlException e) {                    // default value is too long for fixed size column                    throw Trace.error(Trace.WRONG_DEFAULT_CLAUSE);                }            }            return expr;        }        throw Trace.error(Trace.WRONG_DEFAULT_CLAUSE);    }    public static void checkBooleanDefault(String s,                                           int type) throws HsqlException {        if (type != Types.BOOLEAN || s == null) {            return;        }        s = s.toUpperCase();        if (s.equals(Token.T_TRUE) || s.equals(Token.T_FALSE)) {            return;        }        if (s.equals("0") || s.equals("1")) {            return;        }        throw Trace.error(Trace.WRONG_DEFAULT_CLAUSE, s);    }    /**     * Responsible for handling constraints section of CREATE TABLE ...     *     * @param t table     * @param constraint CONSTRAINT keyword used     * @param primarykeycolumn primary columns     * @throws HsqlException     * @return list of constraints     */    private HsqlArrayList processCreateConstraints(Table t,            boolean constraint, int[] primarykeycolumn) throws HsqlException {        String        token;        HsqlArrayList tcList;        Constraint    tempConst;        HsqlName      pkHsqlName;// fredt@users 20020225 - comment// HSQLDB relies on primary index to be the first one defined// and needs original or system added primary key before any// non-unique index is created        tcList = new HsqlArrayList();        tempConst = new Constraint(null, primarykeycolumn, null, null,                                   Constraint.MAIN, Constraint.NO_ACTION,                                   Constraint.NO_ACTION);// tony_lai@users 20020820 - patch 595099        pkHsqlName = null;        tcList.add(tempConst);        if (!constraint) {            return tcList;        }        while (true) {            HsqlName cname = null;            if (tokenizer.isGetThis(Token.T_CONSTRAINT)) {                token = tokenizer.getName();                String constraintSchema = tokenizer.getLongNameFirst();                if (constraintSchema != null) {                    constraintSchema = session.getSchemaNameForWrite(                        tokenizer.getLongNameFirst());                    if (!t.getSchemaName().equals(constraintSchema)) {                        throw Trace.error(                            Trace.INVALID_SCHEMA_NAME_NO_SUBCLASS,                            constraintSchema);                    }                }                cname = database.nameManager.newHsqlName(token,                        tokenizer.wasQuotedIdentifier());            }            token = tokenizer.getSimpleToken();            switch (Token.get(token)) {                case Token.PRIMARY : {                    tokenizer.getThis(Token.T_KEY);                    // tony_lai@users 20020820 - patch 595099                    pkHsqlName = cname;                    int[]      col = processColumnList(t);                    Constraint mainConst;                    mainConst = (Constraint) tcList.get(0);                    if (mainConst.core.mainColArray != null) {                        if (!ArrayUtil.areEqual(mainConst.core.mainColArray,                                                col, col.length, true)) {                            throw Trace.error(Trace.SECOND_PRIMARY_KEY);                        }                    }                    mainConst.core.mainColArray = col;                    mainConst.constName         = pkHsqlName;                    break;                }                case Token.UNIQUE : {                    int[] col = processColumnList(t);                    if (cname == null) {                        cname = database.nameManager.newAutoName("CT");                    }                    tempConst = new Constraint(cname, col, null, null,                                               Constraint.UNIQUE,                                               Constraint.NO_ACTION,                                               Constraint.NO_ACTION);                    tcList.add(tempConst);                    break;                }                case Token.FOREIGN : {                    tokenizer.getThis(Token.T_KEY);                    tempConst = processCreateFK(t, cname);                    if (tempConst.core.refColArray == null) {                        Constraint mainConst = (Constraint) tcList.get(0);                        tempConst.core.refColArray =                            mainConst.core.mainColArray;                        if (tempConst.core.refColArray == null) {                            throw Trace.error(Trace.CONSTRAINT_NOT_FOUND,                                              Trace.TABLE_HAS_NO_PRIMARY_KEY);                        }                    }                    checkFKColumnDefaults(t, tempConst);                    t.checkColumnsMatch(tempConst.core.mainColArray,                                        tempConst.core.refTable,                                        tempConst.core.refColArray);                    tcList.add(tempConst);                    break;                }                case Token.CHECK : {                    if (cname == null) {                        cname = database.nameManager.newAutoName("CT");                    }                    tempConst = new Constraint(cname, null, null, null,                                               Constraint.CHECK, 0, 0);                    processCreateCheckConstraintCondition(tempConst);                    tcList.add(tempConst);                    break;                }            }            token = tokenizer.getSimpleToken();            if (token.equals(Token.T_COMMA)) {                continue;            }            if (token.equals(Token.T_CLOSEBRACKET)) {                break;            }            throw Trace.error(Trace.UNEXPECTED_TOKEN, token);        }        return tcList;    }    /**     * Responsible for handling check constraints section of CREATE TABLE ...     *     * @param c check constraint     * @throws HsqlException     */    private void processCreateCheckConstraintCondition(Constraint c)    throws HsqlException {        tokenizer.getThis(Token.T_OPENBRACKET);        Parser     parser    = new Parser(session, database, tokenizer);        Expression condition = parser.parseExpression();        tokenizer.getThis(Token.T_CLOSEBRACKET);        c.core.check = condition;    }    /**     * Responsible for handling the execution CREATE TABLE SQL statements.     *     * @param type Description of the Parameter     * @throws HsqlException     */    private void processCreateTable(int type) throws HsqlException {        String token = tokenizer.getName();        HsqlName schemaname =            session.getSchemaHsqlNameForWrite(tokenizer.getLongNameFirst());        database.schemaManager.checkUserTableNotExists(session, token,                schemaname.name);        boolean isnamequoted = tokenizer.wasQuotedIdentifier();        int[]   pkCols       = null;        int     colIndex     = 0;        boolean constraint   = false;        Table   t = newTable(type, token, isnamequoted, schemaname);        tokenizer.getThis(Token.T_OPENBRACKET);        while (true) {            token = tokenizer.getString();            switch (Token.get(token)) {                case Token.CONSTRAINT :                case Token.PRIMARY :                case Token.FOREIGN :                case Token.UNIQUE :                case Token.CHECK :                    // fredt@users : check for quoted reserved words used as column names                    constraint = !tokenizer.wasQuotedIdentifier()                                 &&!tokenizer.wasLongName();            }            tokenizer.back();            if (constraint) {                break;            }            Column newcolumn = processCreateColumn();            t.addColumn(newcolumn);            if (newcolumn.isPrimaryKey()) {                Trace.check(pkCols == null, Trace.SECOND_PRIMARY_KEY,                            newcolumn.columnName.name);                pkCols = new int[]{ colIndex };            }            token = tokenizer.getSimpleToken();

⌨️ 快捷键说明

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