Beispiel #1
0
        /**
         * Method declaration
         *
         *
         * @param withoutindex
         *
         * @return
         *
         * @throws Exception
         */
        public Table moveDefinition(string withoutindex)
        {
            Table tn = new Table(dDatabase, true, getName(), isCached());

            for (int i = 0; i < getColumnCount(); i++)
            {
                tn.addColumn(getColumn(i));
            }

            // todo: there should be nothing special with the primary key!
            if (iVisibleColumns < iColumnCount)
            {
                tn.createPrimaryKey();
            }
            else
            {
                tn.createPrimaryKey(getPrimaryIndex().getColumns()[0]);
            }

            Index idx = null;

            while (true)
            {
                idx = getNextIndex(idx);

                if (idx == null)
                {
                    break;
                }

                if (withoutindex != null && idx.getName().Equals(withoutindex))
                {
                    continue;
                }

                if (idx == getPrimaryIndex())
                {
                    continue;
                }

                tn.createIndex(idx);
            }

            for (int i = 0; i < iConstraintCount; i++)
            {
                Constraint c = (Constraint)vConstraint[i];

                c.replaceTable(this, tn);
            }

            tn.vConstraint = vConstraint;

            return(tn);
        }
Beispiel #2
0
        /**
         * Method declaration
         *
         *
         * @param name
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        public Table getSystemTable(string name, Channel channel)
        {
            if (name.Equals("SYSTEM_PROCEDURES"))
            {
                Table t = createTable(name);

                t.addColumn("PROCEDURE_" + META_CAT, Column.VARCHAR);
                t.addColumn("PROCEDURE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("PROCEDURE_NAME", Column.VARCHAR);
                t.addColumn("NUM_INPUT_PARAMS", Column.INTEGER);
                t.addColumn("NUM_OUTPUT_PARAMS", Column.INTEGER);
                t.addColumn("NUM_RESULT_SETS", Column.INTEGER);
                t.addColumn("REMARKS", Column.VARCHAR);
                t.addColumn("PROCEDURE_TYPE", Column.SMALLINT);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_PROCEDURECOLUMNS"))
            {
                Table t = createTable(name);

                t.addColumn("PROCEDURE_" + META_CAT, Column.VARCHAR);
                t.addColumn("PROCEDURE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("PROCEDURE_NAME", Column.VARCHAR);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn("COLUMN_TYPE", Column.SMALLINT);
                t.addColumn("DATA_TYPE", Column.SMALLINT);
                t.addColumn("TYPE_NAME", Column.VARCHAR);
                t.addColumn("PRECISION", Column.INTEGER);
                t.addColumn("LENGTH", Column.INTEGER);
                t.addColumn("SCALE", Column.SMALLINT);
                t.addColumn("RADIX", Column.SMALLINT);
                t.addColumn("NULLABLE", Column.SMALLINT);
                t.addColumn("REMARKS", Column.VARCHAR);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_TABLES"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TABLE_NAME", Column.VARCHAR);
                t.addColumn("TABLE_TYPE", Column.VARCHAR);
                t.addColumn("REMARKS", Column.VARCHAR);
                t.createPrimaryKey();

                for (int i = 0; i < tTable.Count; i++)
                {
                    Table    table = (Table)tTable[i];
                    object[] o     = t.getNewRow();

                    o[2] = table.getName();
                    o[3] = "TABLE";

                    t.insert(o, null);
                }

                return(t);
            }
            else if (name.Equals("SYSTEM_SCHEMAS"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_CATALOGS"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_TABLETYPES"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_TYPE", Column.VARCHAR);
                t.createPrimaryKey();

                object[] o = t.getNewRow();

                o[0] = "TABLE";

                t.insert(o, null);

                return(t);
            }
            else if (name.Equals("SYSTEM_COLUMNS"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TABLE_NAME", Column.VARCHAR);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn("DATA_TYPE", Column.SMALLINT);
                t.addColumn("TYPE_NAME", Column.VARCHAR);
                t.addColumn(META_COLUMN_SIZE, Column.INTEGER);
                t.addColumn(META_BUFFER_LENGTH, Column.INTEGER);
                t.addColumn(META_DECIMAL_DIGITS, Column.INTEGER);
                t.addColumn(META_NUM_PREC_RADIX, Column.INTEGER);
                t.addColumn("NULLABLE", Column.INTEGER);
                t.addColumn("REMARKS", Column.VARCHAR);

                // Access and Intersolv do not return this fields
                t.addColumn("COLUMN_DEF", Column.VARCHAR);
                t.addColumn("SQL_DATA_TYPE", Column.VARCHAR);
                t.addColumn("SQL_DATETIME_SUB", Column.INTEGER);
                t.addColumn("CHAR_OCTET_LENGTH", Column.INTEGER);
                t.addColumn("ORDINAL_POSITION", Column.VARCHAR);
                t.addColumn("IS_NULLABLE", Column.VARCHAR);
                t.createPrimaryKey();

                for (int i = 0; i < tTable.Count; i++)
                {
                    Table table   = (Table)tTable[i];
                    int   columns = table.getColumnCount();

                    for (int j = 0; j < columns; j++)
                    {
                        object[] o = t.getNewRow();

                        o[2] = table.getName();
                        o[3] = table.getColumnName(j);
                        o[4] = table.getColumnType(j);
                        o[5] = Column.getType(table.getColumnType(j));

                        int nullable;

                        if (table.getColumnIsNullable(j))
                        {
                            nullable = true.ToInt32();
                        }
                        else
                        {
                            nullable = false.ToInt32();
                        }

                        o[10] = nullable;

                        if (table.getIdentityColumn() == j)
                        {
                            o[11] = "IDENTITY";
                        }

                        t.insert(o, null);
                    }
                }

                return(t);
            }
            else if (name.Equals("SYSTEM_COLUMNPRIVILEGES"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TABLE_NAME", Column.VARCHAR);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn("GRANTOR", Column.VARCHAR);
                t.addColumn("GRANTEE", Column.VARCHAR);
                t.addColumn("PRIVILEGE", Column.VARCHAR);
                t.addColumn("IS_GRANTABLE", Column.VARCHAR);
                t.createPrimaryKey();

                /*
                 * // todo: get correct info
                 * for(int i=0;i<tTable.size();i++) {
                 * Table table=(Table)tTable.elementAt(i);
                 * int columns=table.getColumnCount();
                 * for(int j=0;j<columns;j++) {
                 * object o[]=t.getNewRow();
                 * o[2]=table.getName();
                 * o[3]=table.getColumnName(j);
                 * o[4]="sa";
                 * o[6]="FULL";
                 * o[7]="NO";
                 * t.insert(o,null);
                 * }
                 * }
                 */
                return(t);
            }
            else if (name.Equals("SYSTEM_TABLEPRIVILEGES"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TABLE_NAME", Column.VARCHAR);
                t.addColumn("GRANTOR", Column.VARCHAR);
                t.addColumn("GRANTEE", Column.VARCHAR);
                t.addColumn("PRIVILEGE", Column.VARCHAR);
                t.addColumn("IS_GRANTABLE", Column.VARCHAR);
                t.createPrimaryKey();

                for (int i = 0; i < tTable.Count; i++)
                {
                    Table    table = (Table)tTable[i];
                    object[] o     = t.getNewRow();

                    o[2] = table.getName();
                    o[3] = "sa";
                    o[5] = "FULL";

                    t.insert(o, null);
                }

                return(t);
            }
            else if (name.Equals("SYSTEM_BESTROWIDENTIFIER"))
            {
                Table t = createTable(name);

                t.addColumn("SCOPE", Column.SMALLINT);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn("DATA_TYPE", Column.SMALLINT);
                t.addColumn("TYPE_NAME", Column.VARCHAR);
                t.addColumn(META_COLUMN_SIZE, Column.INTEGER);
                t.addColumn(META_BUFFER_LENGTH, Column.INTEGER);
                t.addColumn(META_DECIMAL_DIGITS, Column.SMALLINT);
                t.addColumn("PSEUDO_COLUMN", Column.SMALLINT);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_VERSIONCOLUMNS"))
            {
                Table t = createTable(name);

                t.addColumn("SCOPE", Column.INTEGER);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn("DATA_TYPE", Column.SMALLINT);
                t.addColumn("TYPE_NAME", Column.VARCHAR);
                t.addColumn(META_COLUMN_SIZE, Column.SMALLINT);
                t.addColumn(META_BUFFER_LENGTH, Column.INTEGER);
                t.addColumn(META_DECIMAL_DIGITS, Column.SMALLINT);
                t.addColumn("PSEUDO_COLUMN", Column.SMALLINT);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_PRIMARYKEYS"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TABLE_NAME", Column.VARCHAR);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn("KEY_SEQ", Column.SMALLINT);
                t.addColumn("PK_NAME", Column.VARCHAR);
                t.createPrimaryKey();

                for (int i = 0; i < tTable.Count; i++)
                {
                    Table table = (Table)tTable[i];
                    Index index = table.getIndex("SYSTEM_PK");
                    int[] cols  = index.getColumns();
                    int   len   = cols.Length;

                    for (int j = 0; j < len; j++)
                    {
                        object[] o = t.getNewRow();

                        o[2] = table.getName();
                        o[3] = table.getColumnName(cols[j]);
                        o[4] = j + 1;
                        o[5] = "SYSTEM_PK";

                        t.insert(o, null);
                    }
                }

                return(t);
            }
            else if (name.Equals("SYSTEM_IMPORTEDKEYS"))
            {
                Table t = createTable(name);

                t.addColumn("PKTABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("PKTABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("PKTABLE_NAME", Column.VARCHAR);
                t.addColumn("PKCOLUMN_NAME", Column.VARCHAR);
                t.addColumn("FKTABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("FKTABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("FKTABLE_NAME", Column.VARCHAR);
                t.addColumn("FKCOLUMN_NAME", Column.VARCHAR);
                t.addColumn("KEY_SEQ", Column.SMALLINT);
                t.addColumn("UPDATE_RULE", Column.SMALLINT);
                t.addColumn("DELETE_RULE", Column.SMALLINT);
                t.addColumn("FK_NAME", Column.VARCHAR);
                t.addColumn("PK_NAME", Column.VARCHAR);
                t.addColumn("DEFERRABILITY", Column.SMALLINT);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_EXPORTEDKEYS"))
            {
                Table t = createTable(name);

                t.addColumn("PKTABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("PKTABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("PKTABLE_NAME", Column.VARCHAR);
                t.addColumn("PKCOLUMN_NAME", Column.VARCHAR);
                t.addColumn("FKTABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("FKTABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("FKTABLE_NAME", Column.VARCHAR);
                t.addColumn("FKCOLUMN_NAME", Column.VARCHAR);
                t.addColumn("KEY_SEQ", Column.SMALLINT);
                t.addColumn("UPDATE_RULE", Column.SMALLINT);
                t.addColumn("DELETE_RULE", Column.SMALLINT);
                t.addColumn("FK_NAME", Column.VARCHAR);
                t.addColumn("PK_NAME", Column.VARCHAR);
                t.addColumn("DEFERRABILITY", Column.SMALLINT);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_CROSSREFERENCE"))
            {
                Table t = createTable(name);

                t.addColumn("PKTABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("PKTABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("PKTABLE_NAME", Column.VARCHAR);
                t.addColumn("PKCOLUMN_NAME", Column.VARCHAR);
                t.addColumn("FKTABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("FKTABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("FKTABLE_NAME", Column.VARCHAR);
                t.addColumn("FKCOLUMN_NAME", Column.VARCHAR);
                t.addColumn("KEY_SEQ", Column.INTEGER);
                t.addColumn("UPDATE_RULE", Column.SMALLINT);
                t.addColumn("DELETE_RULE", Column.SMALLINT);
                t.addColumn("FK_NAME", Column.VARCHAR);
                t.addColumn("PK_NAME", Column.VARCHAR);
                t.addColumn("DEFERRABILITY", Column.SMALLINT);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_TYPEINFO"))
            {
                Table t = createTable(name);

                t.addColumn("TYPE_NAME", Column.VARCHAR);
                t.addColumn("DATA_TYPE", Column.SMALLINT);
                t.addColumn("PRECISION", Column.INTEGER);
                t.addColumn("LITERAL_PREFIX", Column.VARCHAR);
                t.addColumn("LITERAL_SUFFIX", Column.VARCHAR);
                t.addColumn("CREATE_PARAMS", Column.VARCHAR);
                t.addColumn("NULLABLE", Column.SMALLINT);
                t.addColumn("CASE_SENSITIVE", Column.VARCHAR);
                t.addColumn("SEARCHABLE", Column.SMALLINT);
                t.addColumn("UNSIGNED_ATTRIBUTE", Column.BIT);
                t.addColumn(META_FIXED_PREC_SCALE, Column.BIT);
                t.addColumn("AUTO_INCREMENT", Column.BIT);
                t.addColumn("LOCAL_TYPE_NAME", Column.VARCHAR);
                t.addColumn("MINIMUM_SCALE", Column.SMALLINT);
                t.addColumn("MAXIMUM_SCALE", Column.SMALLINT);

                // this columns are not supported by Access and Intersolv
                t.addColumn("SQL_DATE_TYPE", Column.INTEGER);
                t.addColumn("SQL_DATETIME_SUB", Column.INTEGER);
                t.addColumn("NUM_PREC_RADIX", Column.INTEGER);
                t.createPrimaryKey();

                for (int i = 0; i < Column.TYPES.Length; i++)
                {
                    object[] o    = t.getNewRow();
                    int      type = Column.TYPES[i];

                    o[0]  = Column.getType(type);
                    o[1]  = type;
                    o[2]  = 0;                       // precision
                    o[6]  = true;                    // need Column to track nullable for this
                    o[7]  = true;                    // case sensitive
                    o[8]  = true;;
                    o[9]  = false;                   // unsigned
                    o[10] = (type == Column.NUMERIC || type == Column.DECIMAL);
                    o[11] = (type == Column.INTEGER);
                    o[12] = o[0];
                    o[13] = 0;
                    o[14] = 0;                        // maximum scale
                    o[15] = 0;
                    o[16] = o[15];
                    o[17] = 10;

                    t.insert(o, null);
                }

                return(t);
            }
            else if (name.Equals("SYSTEM_INDEXINFO"))
            {
                Table t = createTable(name);

                t.addColumn("TABLE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TABLE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TABLE_NAME", Column.VARCHAR);
                t.addColumn("NON_UNIQUE", Column.BIT);
                t.addColumn("INDEX_QUALIFIER", Column.VARCHAR);
                t.addColumn("INDEX_NAME", Column.VARCHAR);
                t.addColumn("TYPE", Column.SMALLINT);
                t.addColumn(META_ORDINAL_POSITON, Column.SMALLINT);
                t.addColumn("COLUMN_NAME", Column.VARCHAR);
                t.addColumn(META_ASC_OR_DESC, Column.VARCHAR);
                t.addColumn("CARDINALITY", Column.INTEGER);
                t.addColumn("PAGES", Column.INTEGER);
                t.addColumn("FILTER_CONDITION", Column.VARCHAR);
                t.createPrimaryKey();

                for (int i = 0; i < tTable.Count; i++)
                {
                    Table table = (Table)tTable[i];
                    Index index = null;

                    while (true)
                    {
                        index = table.getNextIndex(index);

                        if (index == null)
                        {
                            break;
                        }

                        int[] cols = index.getColumns();
                        int   len  = cols.Length;

                        // this removes the column that makes every index unique
                        if (!index.isUnique())
                        {
                            len--;
                        }

                        for (int j = 0; j < len; j++)
                        {
                            object[] o = t.getNewRow();

                            o[2] = table.getName();
                            o[3] = !index.isUnique();
                            o[5] = index.getName();
                            o[6] = 1;
                            o[7] = (j + 1);
                            o[8] = table.getColumnName(cols[j]);
                            o[9] = "A";

                            t.insert(o, null);
                        }
                    }
                }

                return(t);
            }
            else if (name.Equals("SYSTEM_UDTS"))
            {
                Table t = createTable(name);

                t.addColumn("TYPE_" + META_CAT, Column.VARCHAR);
                t.addColumn("TYPE_" + META_SCHEM, Column.VARCHAR);
                t.addColumn("TYPE_NAME", Column.VARCHAR);
                t.addColumn("CLASS_NAME", Column.BIT);
                t.addColumn("DATA_TYPE", Column.VARCHAR);
                t.addColumn("REMARKS", Column.VARCHAR);
                t.createPrimaryKey();

                return(t);
            }
            else if (name.Equals("SYSTEM_CONNECTIONINFO"))
            {
                Table t = createTable(name);

                t.addColumn("KEY", Column.VARCHAR);
                t.addColumn("VALUE", Column.VARCHAR);
                t.createPrimaryKey();

                object[] o = t.getNewRow();

                o[0] = "USER";
                o[1] = channel.getUsername();

                t.insert(o, null);

                o    = t.getNewRow();
                o[0] = "READONLY";
                o[1] = channel.isReadOnly() ? "TRUE" : "FALSE";

                t.insert(o, null);

                o    = t.getNewRow();
                o[0] = "MAXROWS";
                o[1] = "" + channel.getMaxRows();

                t.insert(o, null);

                o    = t.getNewRow();
                o[0] = "DATABASE";
                o[1] = "" + channel.getDatabase().getName();

                t.insert(o, null);

                o    = t.getNewRow();
                o[0] = "IDENTITY";
                o[1] = "" + channel.getLastIdentity();

                t.insert(o, null);

                return(t);
            }
            else if (name.Equals("SYSTEM_USERS"))
            {
                Table t = createTable(name);

                t.addColumn("USER", Column.VARCHAR);
                t.addColumn("ADMIN", Column.BIT);
                t.createPrimaryKey();

                ArrayList v = aAccess.getUsers();

                for (int i = 0; i < v.Count; i++)
                {
                    User u = (User)v[i];

                    // todo: this is not a nice implementation
                    if (u == null)
                    {
                        continue;
                    }

                    string user = u.getName();

                    if (!user.Equals("PUBLIC"))
                    {
                        object[] o = t.getNewRow();

                        o[0] = user;
                        o[1] = u.isAdmin();

                        t.insert(o, null);
                    }
                }

                return(t);
            }

            return(null);
        }
Beispiel #3
0
        /**
         * Method declaration
         *
         *
         * @param withoutindex
         *
         * @return
         *
         * @throws Exception
         */
        public Table moveDefinition(string withoutindex)
        {
            Table tn = new Table(dDatabase, true, getName(), isCached());

            for (int i = 0; i < getColumnCount(); i++)
            {
                tn.addColumn(getColumn(i));
            }

            // todo: there should be nothing special with the primary key!
            if (iVisibleColumns < iColumnCount)
            {
                tn.createPrimaryKey();
            }
            else
            {
                tn.createPrimaryKey(getPrimaryIndex().getColumns()[0]);
            }

            Index idx = null;

            while (true)
            {
                idx = getNextIndex(idx);

                if (idx == null)
                {
                    break;
                }

                if (withoutindex != null && idx.getName().Equals(withoutindex))
                {
                    continue;
                }

                if (idx == getPrimaryIndex())
                {
                    continue;
                }

                tn.createIndex(idx);
            }

            for (int i = 0; i < iConstraintCount; i++)
            {
                Constraint c = (Constraint) vConstraint[i];

                c.replaceTable(this, tn);
            }

            tn.vConstraint = vConstraint;

            return tn;
        }
Beispiel #4
0
        /**
         * Method declaration
         *
         * ALTER TABLE tableName ADD COLUMN columnName columnType;
         * ALTER TABLE tableName DELETE COLUMN columnName;
         *
         * <B>Note: </B>The only change I've made to Sergio's original code was
         * changing the insert's to call insertNoCheck to bypass the trigger
         * mechanism that is a part of hsqldb 1.60 and beyond. - Mark Tutt
         *
         * @return
         *
         * @throws Exception
         */
        public Result processAlter()
        {
            tTokenizer.getThis("TABLE");

            string token = tTokenizer.getstring();

            cChannel.checkReadWrite();

            // cChannel.check(token,Access.ALTER); --> Accessul nu-l inca controleaza...
            string tName = token;
            string swap = tName + "SWAP";

            // nimicirea swapului...
            dDatabase.execute("DROP TABLE " + swap, cChannel);

            Table initialTable = dDatabase.getTable(token, cChannel);
            int   count = 0;

            token = tTokenizer.getstring();

            if (token.Equals("ADD"))
            {
                token = tTokenizer.getstring();

                if (token.Equals("COLUMN"))
                {
                    Table swapTable = new Table(dDatabase, true, swap,
                        initialTable.isCached());

                    // copiem coloanele (fara date) din tabelul initial in swap
                    for (int i = 0; i < initialTable.getColumnCount(); i++)
                    {
                        Column aColumn = initialTable.getColumn(i);

                        swapTable.addColumn(aColumn);
                    }

                    // end Of copiem coloanele...
                    // aflam daca are PrimaryKey & o cream...
                    string  cName = tTokenizer.getstring();
                    string  cType = tTokenizer.getstring();
                    int     iType = Column.getTypeNr(cType);
                    string  sToken = cType;
                    //					int     primarykeycolumn = -1;
                    bool identity = false;
                    int     column = initialTable.getColumnCount() + 1;

                    // !--
                    // stolen from CREATE TABLE...
                    string  sColumn = cName;

                    if (iType == Column.VARCHAR && dDatabase.isIgnoreCase())
                    {
                        iType = Column.VARCHAR_IGNORECASE;
                    }

                    sToken = tTokenizer.getstring();

                    if (iType == Column.DOUBLE && sToken.Equals("PRECISION"))
                    {
                        sToken = tTokenizer.getstring();
                    }

                    if (sToken.Equals("("))
                    {

                        // overread length
                        do
                        {
                            sToken = tTokenizer.getstring();
                        } while (!sToken.Equals(")"));

                        sToken = tTokenizer.getstring();
                    }

                    // !--
                    bool nullable = true;

                    if (sToken.Equals("NULL"))
                    {
                        sToken = tTokenizer.getstring();
                    }
                    else if (sToken.Equals("NOT"))
                    {
                        tTokenizer.getThis("NULL");

                        nullable = false;
                        sToken = tTokenizer.getstring();
                    }

                    /*
                     * if(sToken.Equals("IDENTITY")) {
                     * identity=true;
                     * Trace.check(primarykeycolumn==-1,Trace.SECOND_PRIMARY_KEY,sColumn);
                     * sToken=tTokenizer.getstring();
                     * primarykeycolumn=column;
                     * }
                     *
                     * if(sToken.Equals("PRIMARY")) {
                     * tTokenizer.getThis("KEY");
                     * Trace.check(identity || primarykeycolumn==-1,
                     * Trace.SECOND_PRIMARY_KEY,sColumn);
                     * primarykeycolumn=column;
                     * //sToken=tTokenizer.getstring();
                     * }
                     * //end of STOLEN...
                     */
                    swapTable.addColumn(cName, iType, nullable,
                        identity);    // under construction...

                    if (initialTable.getColumnCount()
                        < initialTable.getInternalColumnCount())
                    {
                        swapTable.createPrimaryKey();
                    }
                    else
                    {
                        swapTable.createPrimaryKey(initialTable.getPrimaryIndex().getColumns()[0]);
                    }

                    // endof PrimaryKey...
                    // sa ne farimam cu indicii... ;-((
                    Index idx = null;

                    while (true)
                    {
                        idx = initialTable.getNextIndex(idx);

                        if (idx == null)
                        {
                            break;
                        }

                        if (idx == initialTable.getPrimaryIndex())
                        {
                            continue;
                        }

                        swapTable.createIndex(idx);
                    }

                    // end of Index...
                    cChannel.commit();
                    dDatabase.linkTable(swapTable);

                    Tokenizer tmpTokenizer = new Tokenizer("SELECT * FROM "
                        + tName);
                    Parser    pp = new Parser(dDatabase, tmpTokenizer, cChannel);
                    string    ff = tmpTokenizer.getstring();

                    if (!initialTable.isEmpty())
                    {
                        Record n = ((Result) pp.processSelect()).rRoot;

                        do
                        {
                            object[] row = swapTable.getNewRow();
                            object[] row1 = n.data;

                            for (int i = 0; i < initialTable.getColumnCount();
                                i++)
                            {
                                row[i] = row1[i];
                            }

                            swapTable.insertNoCheck(row, cChannel);

                            n = n.next;
                        } while (n != null);
                    }

                    dDatabase.execute("DROP TABLE " + tName, cChannel);

                    // cream tabelul vechi cu proprietatile celui nou...
                    initialTable = new Table(dDatabase, true, tName,
                        swapTable.isCached());

                    for (int i = 0; i < swapTable.getColumnCount(); i++)
                    {
                        Column aColumn = swapTable.getColumn(i);

                        initialTable.addColumn(aColumn);
                    }

                    if (swapTable.getColumnCount()
                        < swapTable.getInternalColumnCount())
                    {
                        initialTable.createPrimaryKey();
                    }
                    else
                    {
                        initialTable.createPrimaryKey(swapTable.getPrimaryIndex().getColumns()[0]);
                    }

                    // endof PrimaryKey...
                    // sa ne farimam cu indicii... ;-((
                    idx = null;

                    while (true)
                    {
                        idx = swapTable.getNextIndex(idx);

                        if (idx == null)
                        {
                            break;
                        }

                        if (idx == swapTable.getPrimaryIndex())
                        {
                            continue;
                        }

                        initialTable.createIndex(idx);
                    }

                    // end of Index...
                    cChannel.commit();
                    dDatabase.linkTable(initialTable);

                    // end of cream...
                    // copiem datele din swap in tabel...
                    tmpTokenizer = new Tokenizer("SELECT * FROM " + swap);
                    pp = new Parser(dDatabase, tmpTokenizer, cChannel);
                    ff = tmpTokenizer.getstring();

                    if (!swapTable.isEmpty())
                    {
                        Record n = ((Result) pp.processSelect()).rRoot;

                        do
                        {
                            object[] row = initialTable.getNewRow();
                            object[] row1 = n.data;

                            for (int i = 0; i < swapTable.getColumnCount(); i++)
                            {
                                row[i] = row1[i];
                            }

                            initialTable.insertNoCheck(row, cChannel);

                            n = n.next;
                        } while (n != null);

                        // end of copiem...
                    }

                    dDatabase.execute("DROP TABLE " + swap, cChannel);

                    count = 4;
                }
                else
                {
                    throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
                }
            }
            else if (token.Equals("DELETE"))
            {
                token = tTokenizer.getstring();

                if (token.Equals("COLUMN"))
                {
                    Table  swapTable = new Table(dDatabase, true, swap,
                        initialTable.isCached());
                    string cName = tTokenizer.getstring();
                    int    undesired = initialTable.getColumnNr(cName);

                    for (int i = 0; i < initialTable.getColumnCount(); i++)
                    {
                        Column aColumn = initialTable.getColumn(i);

                        if (i != undesired)
                        {
                            swapTable.addColumn(aColumn);
                        }
                    }

                    int pKey = -1;

                    // !--
                    if (initialTable.getColumnCount()
                        < initialTable.getInternalColumnCount())
                    {
                        swapTable.createPrimaryKey();
                    }
                    else
                    {
                        int[] cols = initialTable.getPrimaryIndex().getColumns();

                        pKey = cols[0];

                        if ((cols[0] > undesired)
                            || (cols[0] + cols.Length < undesired))
                        {
                            if (undesired
                                < initialTable.getPrimaryIndex().getColumns()[0])
                            {

                                // reindexarea...
                                for (int i = 0; i < cols.Length; i++)
                                {
                                    cols[i]--;
                                }

                                // endOf reindexarea...
                            }
                            // MT: This initially wouldn't compile, missing the array index on cols[]
                            swapTable.createPrimaryKey(cols[0]);
                        }
                        else
                        {
                            swapTable.createPrimaryKey();
                        }
                    }

                    // endof PrimaryKey...
                    // sa ne farimam cu indicii... ;-((
                    Index idx = null;

                    while (true)
                    {
                        idx = initialTable.getNextIndex(idx);

                        if (idx == null)
                        {
                            break;
                        }

                        if (idx == initialTable.getPrimaryIndex())
                        {
                            continue;
                        }

                        bool flag = true;
                        int[]   cols = idx.getColumns();

                        for (int i = 0; i < cols.Length; i++)
                        {
                            if (cols[i] == undesired)
                            {
                                flag = false;
                            }
                        }

                        if (flag)
                        {
                            Index tIdx;

                            for (int i = 0; i < cols.Length; i++)
                            {
                                if (cols[i] > undesired)
                                {
                                    cols[i]--;
                                }
                            }

                            tIdx = new Index(idx.getName(), idx.getColumns(),
                                idx.getType(), idx.isUnique());

                            swapTable.createIndex(tIdx);
                        }
                    }

                    // !--
                    cChannel.commit();
                    dDatabase.linkTable(swapTable);

                    Tokenizer tmpTokenizer = new Tokenizer("SELECT * FROM "
                        + tName);
                    Parser    pp = new Parser(dDatabase, tmpTokenizer, cChannel);
                    string    ff = tmpTokenizer.getstring();

                    if (!initialTable.isEmpty())
                    {
                        Record n = ((Result) pp.processSelect()).rRoot;

                        do
                        {
                            object[] row = swapTable.getNewRow();
                            object[] row1 = n.data;
                            int    j = 0;

                            for (int i = 0; i < initialTable.getColumnCount();
                                i++)
                            {
                                if (i != undesired)
                                {
                                    row[j] = row1[i];
                                    j++;
                                }
                            }

                            swapTable.insertNoCheck(row, cChannel);

                            n = n.next;
                        } while (n != null);
                    }

                    dDatabase.execute("DROP TABLE " + tName, cChannel);

                    // cream tabelul vechi cu proprietatile celui nou...
                    initialTable = new Table(dDatabase, true, tName,
                        swapTable.isCached());

                    for (int i = 0; i < swapTable.getColumnCount(); i++)
                    {
                        Column aColumn = swapTable.getColumn(i);

                        initialTable.addColumn(aColumn);
                    }

                    // !--
                    if (swapTable.getColumnCount()
                        < swapTable.getInternalColumnCount())
                    {
                        initialTable.createPrimaryKey();
                    }
                    else
                    {
                        initialTable.createPrimaryKey(swapTable.getPrimaryIndex().getColumns()[0]);
                    }

                    // endof PrimaryKey...
                    // sa ne farimam cu indicii... ;-((
                    idx = null;

                    while (true)
                    {
                        idx = swapTable.getNextIndex(idx);

                        if (idx == null)
                        {
                            break;
                        }

                        if (idx == swapTable.getPrimaryIndex())
                        {
                            continue;
                        }

                        initialTable.createIndex(idx);
                    }

                    // end of Index...
                    // !--
                    cChannel.commit();
                    dDatabase.linkTable(initialTable);

                    // end of cream...
                    // copiem datele din swap in tabel...
                    tmpTokenizer = new Tokenizer("SELECT * FROM " + swap);
                    pp = new Parser(dDatabase, tmpTokenizer, cChannel);
                    ff = tmpTokenizer.getstring();

                    if (!swapTable.isEmpty())
                    {
                        Record n = ((Result) pp.processSelect()).rRoot;

                        do
                        {
                            object[] row = initialTable.getNewRow();
                            object[] row1 = n.data;

                            for (int i = 0; i < swapTable.getColumnCount(); i++)
                            {
                                row[i] = row1[i];
                            }

                            initialTable.insertNoCheck(row, cChannel);

                            n = n.next;
                        } while (n != null);

                        // end of copiem...
                    }

                    dDatabase.execute("DROP TABLE " + swap, cChannel);

                    count = 3;
                }
                else
                {
                    throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
                }

                count = 3;
            }

            Result r = new Result();

            r.iUpdateCount = count;    // --> nu tre inca...??

            return r;
        }
Beispiel #5
0
        /**
         * Method declaration
         *
         *
         * @return
         *
         * @throws Exception
         */
        public Result processSelect()
        {
            Select select = parseSelect();

            if (select.sIntoTable == null)
            {
                // [email protected] begin changes from 1.50
                //	   return select.getResult(cChannel.getMaxRows());
                return select.getResult( select.limitStart, select.limitCount );
                // [email protected] end changes from 1.50
            }
            else
            {
                Result r = select.getResult(0);
                Table  t = new Table(dDatabase, true, select.sIntoTable, false);

                t.addColumns(r);
                t.createPrimaryKey();

                // SELECT .. INTO can't fail because of violation of primary key
                t.insert(r, cChannel);
                dDatabase.linkTable(t);

                int i = r.getSize();

                r = new Result();
                r.iUpdateCount = i;

                return r;
            }
        }
Beispiel #6
0
        /**
         * Method declaration
         *
         *
         * @param outerjoin
         *
         * @return
         *
         * @throws Exception
         */
        private TableFilter parseTableFilter(bool outerjoin)
        {
            string token = tTokenizer.getstring();
            Table  t = null;

            if (token.Equals("("))
            {
                tTokenizer.getThis("SELECT");

                Select s = parseSelect();
                Result r = s.getResult(0);

                // it's not a problem that this table has not a unique name
                t = new Table(dDatabase, false, "SYSTEM_SUBQUERY", false);

                tTokenizer.getThis(")");
                t.addColumns(r);
                t.createPrimaryKey();

                // subquery creation can't fail because of violation of primary key
                t.insert(r, cChannel);
            }
            else
            {
                cChannel.check(token, Access.SELECT);

                t = dDatabase.getTable(token, cChannel);
            }

            string sAlias = null;

            token = tTokenizer.getstring();

            if (token.Equals("AS"))
            {
                sAlias = tTokenizer.getName();
            }
            else if (tTokenizer.wasName())
            {
                sAlias = token;
            }
            else
            {
                tTokenizer.back();
            }

            return new TableFilter(t, sAlias, outerjoin);
        }