Example #1
0
        private Result GetExplainResult(Session session)
        {
            Result result = Result.NewSingleColumnStringResult("OPERATION", this.Describe(session));
            OrderedHashSet <QNameManager.QName> references = this.GetReferences();

            object[] data = new object[] { "Object References" };
            result.navigator.Add(data);
            for (int i = 0; i < references.Size(); i++)
            {
                QNameManager.QName name      = references.Get(i);
                object[]           objArray2 = new object[] { name.GetSchemaQualifiedStatementName() };
                result.navigator.Add(objArray2);
            }
            object[] objArray3 = new object[] { "Read Locks" };
            result.navigator.Add(objArray3);
            for (int j = 0; j < base.ReadTableNames.Length; j++)
            {
                QNameManager.QName name2     = base.ReadTableNames[j];
                object[]           objArray4 = new object[] { name2.GetSchemaQualifiedStatementName() };
                result.navigator.Add(objArray4);
            }
            object[] objArray5 = new object[] { "WriteLocks" };
            result.navigator.Add(objArray5);
            for (int k = 0; k < base.WriteTableNames.Length; k++)
            {
                QNameManager.QName name3     = base.WriteTableNames[k];
                object[]           objArray6 = new object[] { name3.GetSchemaQualifiedStatementName() };
                result.navigator.Add(objArray6);
            }
            return(result);
        }
Example #2
0
        private static void DropDomain(Session session, QNameManager.QName name, bool cascade)
        {
            SqlType schemaObject = (SqlType)session.database.schemaManager.GetSchemaObject(name);
            OrderedHashSet <QNameManager.QName> referencingObjectNames = session.database.schemaManager.GetReferencingObjectNames(schemaObject.GetName());

            if (!cascade && (referencingObjectNames.Size() > 0))
            {
                QNameManager.QName name2 = referencingObjectNames.Get(0);
                throw Error.GetError(0x157e, name2.GetSchemaQualifiedStatementName());
            }
            Constraint[] constraints = schemaObject.userTypeModifier.GetConstraints();
            referencingObjectNames.Clear();
            for (int i = 0; i < constraints.Length; i++)
            {
                referencingObjectNames.Add(constraints[i].GetName());
            }
            session.database.schemaManager.RemoveSchemaObjects(referencingObjectNames);
            session.database.schemaManager.RemoveSchemaObject(schemaObject.GetName(), cascade);
            schemaObject.userTypeModifier = null;
        }
Example #3
0
        public List <string> GetRightsSQL()
        {
            List <string> list = new List <string>();
            string        directRolesAsString = this.GetDirectRolesAsString();

            if (directRolesAsString.Length != 0)
            {
                StringBuilder builder = new StringBuilder(0x80);
                builder.Append("GRANT").Append(' ').Append(directRolesAsString);
                builder.Append(' ').Append("TO").Append(' ');
                builder.Append(this.GetStatementName());
                list.Add(builder.ToString());
            }
            MultiValueHashMap <QNameManager.QName, Right> rights = this.GetRights();
            Iterator <QNameManager.QName> iterator = rights.GetKeySet().GetIterator();

            while (iterator.HasNext())
            {
                QNameManager.QName key       = iterator.Next();
                Iterator <Right>   iterator2 = rights.Get(key);
                while (iterator2.HasNext())
                {
                    Right              right    = iterator2.Next();
                    StringBuilder      builder2 = new StringBuilder(0x80);
                    QNameManager.QName name2    = key;
                    switch (name2.type)
                    {
                    case 3:
                    case 4:
                    {
                        Table table = this.granteeManager.database.schemaManager.FindUserTable(null, name2.Name, name2.schema.Name);
                        if (table != null)
                        {
                            builder2.Append("GRANT").Append(' ');
                            builder2.Append(right.GetTableRightsSQL(table));
                            builder2.Append(' ').Append("ON").Append(' ');
                            builder2.Append("TABLE").Append(' ');
                            builder2.Append(name2.GetSchemaQualifiedStatementName());
                        }
                        break;
                    }

                    case 7:
                        if (((NumberSequence)this.granteeManager.database.schemaManager.FindSchemaObject(name2.Name, name2.schema.Name, 7)) != null)
                        {
                            builder2.Append("GRANT").Append(' ');
                            builder2.Append("USAGE");
                            builder2.Append(' ').Append("ON").Append(' ');
                            builder2.Append("SEQUENCE").Append(' ');
                            builder2.Append(name2.GetSchemaQualifiedStatementName());
                        }
                        break;

                    case 12:
                        if (((SqlType)this.granteeManager.database.schemaManager.FindSchemaObject(name2.Name, name2.schema.Name, 13)) != null)
                        {
                            builder2.Append("GRANT").Append(' ');
                            builder2.Append("USAGE");
                            builder2.Append(' ').Append("ON").Append(' ');
                            builder2.Append("TYPE").Append(' ');
                            builder2.Append(name2.GetSchemaQualifiedStatementName());
                        }
                        break;

                    case 13:
                        if (((SqlType)this.granteeManager.database.schemaManager.FindSchemaObject(name2.Name, name2.schema.Name, 13)) != null)
                        {
                            builder2.Append("GRANT").Append(' ');
                            builder2.Append("USAGE");
                            builder2.Append(' ').Append("ON").Append(' ');
                            builder2.Append("DOMAIN").Append(' ');
                            builder2.Append(name2.GetSchemaQualifiedStatementName());
                        }
                        break;

                    case 0x10:
                    case 0x11:
                    case 0x18:
                    case 0x1b:
                    {
                        ISchemaObject obj2 = this.granteeManager.database.schemaManager.FindSchemaObject(name2.Name, name2.schema.Name, name2.type);
                        if (obj2 != null)
                        {
                            builder2.Append("GRANT").Append(' ');
                            builder2.Append("EXECUTE").Append(' ');
                            builder2.Append("ON").Append(' ');
                            builder2.Append("SPECIFIC").Append(' ');
                            if (obj2.GetSchemaObjectType() == 0x11)
                            {
                                builder2.Append("PROCEDURE");
                            }
                            else if (obj2.GetSchemaObjectType() == 0x1b)
                            {
                                builder2.Append("AGGREGATE");
                            }
                            else
                            {
                                builder2.Append("FUNCTION");
                            }
                            builder2.Append(' ');
                            builder2.Append(name2.GetSchemaQualifiedStatementName());
                        }
                        break;
                    }
                    }
                    if (builder2.Length != 0)
                    {
                        builder2.Append(' ').Append("TO").Append(' ');
                        builder2.Append(this.GetStatementName());
                        list.Add(builder2.ToString());
                    }
                }
            }
            return(list);
        }
Example #4
0
        public void DropColumn(int colIndex, bool cascade)
        {
            OrderedHashSet <QNameManager.QName> dropConstraintSet     = new OrderedHashSet <QNameManager.QName>();
            OrderedHashSet <Constraint>         dependentConstraints  = this._table.GetDependentConstraints(colIndex);
            OrderedHashSet <Constraint>         containingConstraints = this._table.GetContainingConstraints(colIndex);
            OrderedHashSet <QNameManager.QName> containingIndexNames  = this._table.GetContainingIndexNames(colIndex);
            ColumnSchema column = this._table.GetColumn(colIndex);

            QNameManager.QName name = column.GetName();
            OrderedHashSet <QNameManager.QName> referencingObjectNames = this._database.schemaManager.GetReferencingObjectNames(this._table.GetName(), name);

            this.CheckModifyTable();
            if (!cascade)
            {
                if (!containingConstraints.IsEmpty())
                {
                    QNameManager.QName name2 = containingConstraints.Get(0).GetName();
                    throw Error.GetError(0x15a0, name2.GetSchemaQualifiedStatementName());
                }
                if (!referencingObjectNames.IsEmpty())
                {
                    for (int j = 0; j < referencingObjectNames.Size(); j++)
                    {
                        QNameManager.QName name3 = referencingObjectNames.Get(j);
                        if (name3 != name)
                        {
                            for (int k = 0; k < dependentConstraints.Size(); k++)
                            {
                                if (dependentConstraints.Get(k).GetName() == name3)
                                {
                                    continue;
                                }
                            }
                            throw Error.GetError(0x15a0, name3.GetSchemaQualifiedStatementName());
                        }
                    }
                }
            }
            dependentConstraints.AddAll(containingConstraints);
            containingConstraints.Clear();
            OrderedHashSet <Table> tableSet = new OrderedHashSet <Table>();

            for (int i = 0; i < dependentConstraints.Size(); i++)
            {
                Constraint constraint = dependentConstraints.Get(i);
                if (constraint.ConstType == 0)
                {
                    tableSet.Add(constraint.GetMain());
                    dropConstraintSet.Add(constraint.GetMainName());
                    dropConstraintSet.Add(constraint.GetRefName());
                    containingIndexNames.Add(constraint.GetRefIndex().GetName());
                }
                if (constraint.ConstType == 1)
                {
                    tableSet.Add(constraint.GetRef());
                    dropConstraintSet.Add(constraint.GetMainName());
                    dropConstraintSet.Add(constraint.GetRefName());
                    containingIndexNames.Add(constraint.GetRefIndex().GetName());
                }
                dropConstraintSet.Add(constraint.GetName());
            }
            tableSet = this.MakeNewTables(tableSet, dropConstraintSet, containingIndexNames);
            Table newTable = this._table.MoveDefinition(this._session, this._table.TableType, null, null, null, colIndex, -1, dropConstraintSet, containingIndexNames);

            this.MoveData(this._table, newTable, colIndex, -1);
            this._database.schemaManager.RemoveSchemaObjects(referencingObjectNames);
            this._database.schemaManager.RemoveSchemaObjects(dropConstraintSet);
            this._database.schemaManager.RemoveSchemaObject(name);
            this.SetNewTableInSchema(newTable);
            this.SetNewTablesInSchema(tableSet);
            this.UpdateConstraints(newTable, this.EmptySetQName);
            this.UpdateConstraints(tableSet, dropConstraintSet);
            this._database.schemaManager.RecompileDependentObjects(tableSet);
            this._database.schemaManager.RecompileDependentObjects(newTable);
            newTable.Compile(this._session, null);
            if (column.GetDataType().IsLobType())
            {
                IRowIterator rowIterator = this._table.GetRowIterator(this._session);
                while (rowIterator.HasNext())
                {
                    object[] rowData = rowIterator.GetNextRow().RowData;
                    if (rowData[colIndex] != null)
                    {
                        this._session.sessionData.AdjustLobUsageCount(rowData[colIndex], -1);
                    }
                }
            }
            this._table = newTable;
        }