Package org.hsqldb.lib

Examples of org.hsqldb.lib.HsqlArrayList


                }
            }
        }

        if (isCheck && nonDeterministic) {
            HsqlArrayList list = new HsqlArrayList();

            RangeVariableResolver.decomposeAndConditions(this, list);

            for (int i = 0; i < list.size(); i++) {
                nonDeterministic = true;

                Expression e = (Expression) list.get(i);
                Expression e1;

                if (e instanceof ExpressionLogical) {
                    boolean b = ((ExpressionLogical) e).convertToSmaller();
View Full Code Here


         *  When a new section starts, we pass the list of lines
         *  to the test method to be processed.
         */
        try {
            while (true) {
                HsqlArrayList section = sqlReader.getSection();

                startLine = sqlReader.getStartLineNumber();

                if (section.size() == 0) {
                    break;
                }

                testSection(statement, section, sourceName, startLine);
            }
View Full Code Here

     * @param s Contains the type, expected result and SQL for the test
     */
    static void test(Statement stat, String s, String sourceName, int line) {

        //maintain the interface for this method
        HsqlArrayList section = new HsqlArrayList();

        section.add(s);
        testSection(stat, section, sourceName, line);
    }
View Full Code Here

     *  String objects
     */
    static HsqlArrayList getColumnNames(Database db, Table table, Tokenizer t,
                                        boolean full) throws HsqlException {

        HsqlArrayList columns = new HsqlArrayList();

        while (true) {
            if (full) {
                String   token  = t.getSimpleName();
                boolean  quoted = t.wasQuotedIdentifier();
                HsqlName name   = db.nameManager.newHsqlName(token, quoted);

                columns.add(name);
            } else {
                columns.add(t.getName());

                if (t.wasLongName()
                        && !t.getLongNameFirst().equals(
                            table.getName().name)) {
                    throw (Trace.error(Trace.TABLE_NOT_FOUND,
View Full Code Here

        else {
            tokenizer.back();
        }

        // parse column list
        HsqlArrayList vcolumn = new HsqlArrayList();

        do {
            int        expPos = tokenizer.getPosition();
            Expression e      = parseExpression();

            if (isCompilingView()) {
                if (e.getType() == Expression.ASTERISK) {
                    if (select.asteriskPositions == null) {
                        select.asteriskPositions = new IntKeyHashMap();
                    }

                    // remember the position of the asterisk. For the moment, just
                    // remember the expression, so it can later be found and replaced
                    // with the concrete column list
                    select.asteriskPositions.put(expPos, e);
                }
            }

            token = tokenizer.getString();

            if (tokenizer.wasThis(Token.T_AS)) {
                e.setAlias(tokenizer.getSimpleName(),
                           tokenizer.wasQuotedIdentifier());

                token = tokenizer.getString();
            } else if (tokenizer.wasSimpleName()) {
                e.setAlias(token, tokenizer.wasQuotedIdentifier());

                token = tokenizer.getString();
            }

            vcolumn.add(e);
        } while (tokenizer.wasThis(Token.T_COMMA));

        if (token.equals(Token.T_INTO)) {
            boolean getname = true;

            token           = tokenizer.getString();
            select.intoType = database.getDefaultTableType();

            if (tokenizer.wasSimpleToken()) {
                switch (Token.get(token)) {

                    case Token.CACHED :
                        select.intoType = Table.CACHED_TABLE;
                        break;

                    case Token.TEMP :
                        select.intoType = Table.TEMP_TABLE;
                        break;

                    case Token.TEXT :
                        select.intoType = Table.TEXT_TABLE;
                        break;

                    case Token.MEMORY :
                        select.intoType = Table.MEMORY_TABLE;
                        break;

                    default :
                        getname = false;
                        break;
                }

                if (getname) {
                    token = tokenizer.getName();
                }
            }

            if (!tokenizer.wasName()) {
                tokenizer.throwUnexpected();
            }

            select.sIntoTable = database.nameManager.newHsqlName(token,
                    tokenizer.wasQuotedIdentifier());
            select.sIntoTable.schema =
                session.getSchemaHsqlName(tokenizer.getLongNameFirst());
            token = tokenizer.getString();
        }

        tokenizer.matchThis(Token.T_FROM);

        Expression condition = null;

        // parse table list
        HsqlArrayList vfilter = new HsqlArrayList();

        vfilter.add(parseTableFilter(false));

        while (true) {
            token = tokenizer.getString();

            boolean cross = false;

            if (tokenizer.wasThis(Token.T_INNER)) {
                tokenizer.getThis(Token.T_JOIN);

                token = Token.T_JOIN;
            } else if (tokenizer.wasThis(Token.T_CROSS)) {
                tokenizer.getThis(Token.T_JOIN);

                token = Token.T_JOIN;
                cross = true;
            }

            if (token.equals(Token.T_LEFT)
                    && !tokenizer.wasQuotedIdentifier()) {
                tokenizer.isGetThis(Token.T_OUTER);
                tokenizer.getThis(Token.T_JOIN);

                TableFilter tf = parseTableFilter(true);

                vfilter.add(tf);
                tokenizer.getThis(Token.T_ON);

                Expression newcondition = parseExpression();

                newcondition.checkTables(vfilter);

                condition = addJoinCondition(condition, newcondition, tf,
                                             true);

                // MarcH HuugO RIGHT JOIN SUPPORT
            } else if (token.equals(Token.T_RIGHT)
                       && !tokenizer.wasQuotedIdentifier()) {
                tokenizer.isGetThis(Token.T_OUTER);
                tokenizer.getThis(Token.T_JOIN);

                // this object is not an outerjoin, the next object is an outerjoin
                TableFilter tf = parseTableFilter(false);

                // insert new condition as first element in a new vfilter (nvfilter), copy the content of vfilter and rename nvfilter back to vfilter.
                HsqlArrayList nvfilter = new HsqlArrayList();

                nvfilter.add(tf);
                nvfilter.addAll(vfilter);

                vfilter = nvfilter;

                // set isOuterJoin correct
                ((TableFilter) vfilter.get(1)).isOuterJoin = true;
View Full Code Here

            read();
        } else {
            tokenizer.back();

            HsqlArrayList v = new HsqlArrayList();

            while (true) {
                Expression value = parseExpression();

                if (value.exprType == Expression.VALUE
                        && value.valueData == null && !value.isParam()) {
                    throw Trace.error(Trace.NULL_IN_VALUE_LIST);
                }

                v.add(value);
                read();

                if (iToken != Expression.COMMA) {
                    break;
                }
            }

            Expression[] valueList;

            valueList = (Expression[]) v.toArray(new Expression[v.size()]);
            b         = new Expression(valueList);
        }

        readThis(Expression.CLOSE);
View Full Code Here

    CompiledStatement compileInsertStatement() throws HsqlException {

        clearParameters();
        tokenizer.getThis(Token.T_INTO);

        HsqlArrayList columnNames;
        boolean[]     columnCheckList;
        int[]         columnMap;
        int           len;
        String        token = tokenizer.getName();
        String schema = session.getSchemaName(tokenizer.getLongNameFirst());
        Table table = database.schemaManager.getTable(session, token, schema);

        checkTableWriteAccess(table, UserManager.INSERT);

        columnNames     = null;
        columnCheckList = null;
        columnMap       = table.getColumnMap();
        len             = table.getColumnCount();

        int brackets = parseOpenBrackets();

        token = tokenizer.getString();

        if (brackets == 1 && !tokenizer.wasThis(Token.T_SELECT)) {
            brackets = 0;

            tokenizer.back();

            columnNames = getColumnNames(database, table, tokenizer, false);

            if (columnNames.size() > len) {
                throw Trace.error(Trace.COLUMN_COUNT_DOES_NOT_MATCH);
            }

            len             = columnNames.size();
            columnCheckList = table.getNewColumnCheckList();
            columnMap       = new int[len];

            for (int i = 0; i < len; i++) {
                int ci = table.getColumnNr((String) columnNames.get(i));

                columnMap[i]        = ci;
                columnCheckList[ci] = true;
            }
View Full Code Here

     */
    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[]      cols = processColumnList(t, false);
                    Constraint mainConst;

                    mainConst = (Constraint) tcList.get(0);

                    if (mainConst.core.mainColArray != null) {
                        if (!ArrayUtil.areEqual(mainConst.core.mainColArray,
                                                cols, cols.length, true)) {
                            throw Trace.error(Trace.SECOND_PRIMARY_KEY);
                        }
                    }

                    mainConst.core.mainColArray = cols;
                    mainConst.constName         = pkHsqlName;

                    break;
                }
                case Token.UNIQUE : {
                    int[] col = processColumnList(t, false);

                    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,
                                               Constraint.NO_ACTION,
                                               Constraint.NO_ACTION);

                    processCreateCheckConstraintCondition(tempConst);
                    tcList.add(tempConst);

                    break;
                }
            }

View Full Code Here

            }

            throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
        }

        HsqlArrayList tempConstraints = processCreateConstraints(t,
            constraint, pkCols);

        if (tokenizer.isGetThis(Token.T_ON)) {
            if (!t.isTemp) {
                throw Trace.error(Trace.UNEXPECTED_TOKEN, Token.T_ON);
            }

            tokenizer.getThis(Token.T_COMMIT);

            token = tokenizer.getSimpleToken();

            if (token.equals(Token.T_DELETE)) {}
            else if (token.equals(Token.T_PRESERVE)) {
                t.onCommitPreserve = true;
            } else {
                throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
            }

            tokenizer.getThis(Token.T_ROWS);
        }

        try {
            session.commit();

            Constraint primaryConst = (Constraint) tempConstraints.get(0);

            t.createPrimaryKey(null, primaryConst.core.mainColArray, true);

            if (primaryConst.core.mainColArray != null) {
                if (primaryConst.constName == null) {
                    primaryConst.constName = t.makeSysPKName();
                }

                Constraint newconstraint =
                    new Constraint(primaryConst.constName, t,
                                   t.getPrimaryIndex(),
                                   Constraint.PRIMARY_KEY);

                t.addConstraint(newconstraint);
                database.schemaManager.registerConstraintName(
                    primaryConst.constName.name, t.getName());
            }

            for (int i = 1; i < tempConstraints.size(); i++) {
                Constraint tempConst = (Constraint) tempConstraints.get(i);

                if (tempConst.constType == Constraint.UNIQUE) {
                    TableWorks tableWorks = new TableWorks(session, t);

                    tableWorks.createUniqueConstraint(
View Full Code Here

        // definitions to script without double quotes around column names
        // in certain cases; the workaround here discards such scripted column
        // lists when used in OOo
        if (tokenizer.isGetThis(Token.T_OPENBRACKET)) {
            try {
                HsqlArrayList list = Parser.getColumnNames(database, null,
                    tokenizer, true);

                colList = new HsqlName[list.size()];
                colList = (HsqlName[]) list.toArray(colList);

                //added lines to make sure all valid columns are quoted
                if (database.isStoredFileAccess()) {
                    for (int i = 0; i < colList.length; i++) {
                        if (!colList[i].isNameQuoted) {
View Full Code Here

TOP

Related Classes of org.hsqldb.lib.HsqlArrayList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.