상속: ForeignKeyConstraintEnumerator
        internal override bool CanBeRemovedFromCollection(ConstraintCollection constraints, bool fThrowException)
        {
            if (this.Equals(constraints.Table.primaryKey))
            {
                if (fThrowException)
                {
                    throw ExceptionBuilder.RemovePrimaryKey(constraints.Table);
                }
                return(false);
            }
            ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.Table.DataSet, this.Table);

            while (enumerator.GetNext())
            {
                ForeignKeyConstraint foreignKeyConstraint = enumerator.GetForeignKeyConstraint();
                if (this.key.ColumnsEqual(foreignKeyConstraint.ParentKey))
                {
                    if (fThrowException)
                    {
                        throw ExceptionBuilder.NeededForForeignKeyConstraint(this, foreignKeyConstraint);
                    }
                    return(false);
                }
            }
            return(true);
        }
 internal override bool CanBeRemovedFromCollection(ConstraintCollection constraints, bool fThrowException)
 {
     if (this.Equals(constraints.Table.primaryKey))
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.RemovePrimaryKey(constraints.Table);
         }
         return false;
     }
     ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.Table.DataSet, this.Table);
     while (enumerator.GetNext())
     {
         ForeignKeyConstraint foreignKeyConstraint = enumerator.GetForeignKeyConstraint();
         if (this.key.ColumnsEqual(foreignKeyConstraint.ParentKey))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.NeededForForeignKeyConstraint(this, foreignKeyConstraint);
             }
             return false;
         }
     }
     return true;
 }
예제 #3
0
        internal override bool CanBeRemovedFromCollection(ConstraintCollection constraints, bool fThrowException)
        {
            if (Equals(constraints.Table._primaryKey))
            {
                Debug.Assert(constraints.Table._primaryKey == this, "If the primary key and this are 'Equal', they should also be '=='");
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.RemovePrimaryKey(constraints.Table);
                }
            }
            for (ParentForeignKeyConstraintEnumerator cs = new ParentForeignKeyConstraintEnumerator(Table.DataSet, Table); cs.GetNext();)
            {
                ForeignKeyConstraint constraint = cs.GetForeignKeyConstraint();
                if (!_key.ColumnsEqual(constraint.ParentKey))
                {
                    continue;
                }

                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.NeededForForeignKeyConstraint(this, constraint);
                }
            }

            return(true);
        }
        internal bool CanRemove(DataTable table, bool fThrowException) {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTableCollection.CanRemove|INFO> %d#, table=%d, fThrowException=%d{bool}\n", ObjectID, (table != null)? table.ObjectID : 0 , fThrowException);
            try {
                if (table == null) {
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.ArgumentNull("table");
                }
                if (table.DataSet != dataSet) {
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
                }

                // allow subclasses to throw.
                dataSet.OnRemoveTable(table);

                if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0) {
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.TableInRelation();
                }

                for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();) {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table) // we can go with (constraint.Table ==  constraint.RelatedTable)
                        continue;
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                }

                for (ChildForeignKeyConstraintEnumerator constraints = new ChildForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();) {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table) // bug 97670
                        continue;

                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                }

                return true;
            }
            finally{
                Bid.ScopeLeave(ref hscp);
            }
        }
예제 #5
0
        internal bool CanRemove(DataColumn column, bool fThrowException)
        {
            if (column == null)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.ArgumentNull("column");
                }
            }
            if (column.table != table)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.CannotRemoveColumn();
                }
            }

            // allow subclasses to complain first.
            table.OnRemoveColumn(column);

            // We need to make sure the column is not involved in any Relations or Constriants
            if (table.primaryKey != null && table.primaryKey.Key.ContainsColumn(column))
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.CannotRemovePrimaryKey();
                }
            }
            for (int i = 0; i < table.ParentRelations.Count; i++)
            {
                if (table.ParentRelations[i].ChildKey.ContainsColumn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveChildKey(table.ParentRelations[i].RelationName);
                    }
                }
            }
            for (int i = 0; i < table.ChildRelations.Count; i++)
            {
                if (table.ChildRelations[i].ParentKey.ContainsColumn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveChildKey(table.ChildRelations[i].RelationName);
                    }
                }
            }
            for (int i = 0; i < table.Constraints.Count; i++)
            {
                if (table.Constraints[i].ContainsColumn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveConstraint(table.Constraints[i].ConstraintName, table.Constraints[i].Table.TableName);
                    }
                }
            }
            if (table.DataSet != null)
            {
                for (ParentForeignKeyConstraintEnumerator en = new ParentForeignKeyConstraintEnumerator(table.DataSet, table); en.GetNext();)
                {
                    Constraint constraint = en.GetConstraint();
                    if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column))
                    {
                        if (!fThrowException)
                        {
                            return(false);
                        }
                        else
                        {
                            throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName);
                        }
                    }
                }
            }

            for (int i = 0; i < ColumnQueue.columnCount; i++)
            {
                DataColumn col = ColumnQueue.columns[i];
                if (fInClear && (col.Table == table || col.Table == null))
                {
                    continue;
                }
                Debug.Assert(col.Computed, "invalid (non an expression) column in the expression column queue");
                DataExpression expr = col.DataExpression;
                if (expr.DependsOn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveExpression(col.ColumnName, col.Expression);
                    }
                }
            }

            return(true);
        }
예제 #6
0
        internal bool CanRemove(DataTable table, bool fThrowException)
        {
            if (table == null)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.ArgumentNull("table");
                }
            }
            if (table.DataSet != dataSet)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
                }
            }

            // allow subclasses to throw.
            dataSet.OnRemoveTableHack(table);

            if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.TableInRelation();
                }
            }

            for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();)
            {
                ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.TableInConstraint(table, constraint);
                }
            }

            for (ChildForeignKeyConstraintEnumerator constraints = new ChildForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();)
            {
                ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.TableInConstraint(table, constraint);
                }
            }

            return(true);
        }
예제 #7
0
 internal void CascadeAll(DataRow row, DataRowAction action) {
     if (DataSet != null && DataSet.fEnableCascading) {
         for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, this); constraints.GetNext();) {
             constraints.GetForeignKeyConstraint().CheckCascade(row, action);
         }
     }
 }
예제 #8
0
        internal bool CanRemove(DataTable table, bool fThrowException)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.CanRemove|INFO> {0}, table={1}, fThrowException={2}", ObjectID, (table != null) ? table.ObjectID : 0, fThrowException);

            try
            {
                if (table == null)
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    throw ExceptionBuilder.ArgumentNull(nameof(table));
                }
                if (table.DataSet != _dataSet)
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
                }

                // allow subclasses to throw.
                _dataSet.OnRemoveTable(table);

                if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0)
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    throw ExceptionBuilder.TableInRelation();
                }

                for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(_dataSet, table); constraints.GetNext();)
                {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table) // we can go with (constraint.Table ==  constraint.RelatedTable)
                    {
                        continue;
                    }
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                    }
                }

                for (ChildForeignKeyConstraintEnumerator constraints = new ChildForeignKeyConstraintEnumerator(_dataSet, table); constraints.GetNext();)
                {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table)
                    {
                        continue;
                    }

                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                    }
                }

                return(true);
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }
예제 #9
0
        internal bool CanRemove(DataColumn?column, bool fThrowException)
        {
            if (column == null)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.ArgumentNull(nameof(column));
                }
            }

            if (column._table != _table)
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.CannotRemoveColumn();
                }
            }

            // allow subclasses to complain first.
            _table.OnRemoveColumnInternal(column);

            // We need to make sure the column is not involved in any Relations or Constriants
            if (_table._primaryKey != null && _table._primaryKey.Key.ContainsColumn(column))
            {
                if (!fThrowException)
                {
                    return(false);
                }
                else
                {
                    throw ExceptionBuilder.CannotRemovePrimaryKey();
                }
            }

            for (int i = 0; i < _table.ParentRelations.Count; i++)
            {
                if (_table.ParentRelations[i].ChildKey.ContainsColumn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveChildKey(_table.ParentRelations[i].RelationName);
                    }
                }
            }

            for (int i = 0; i < _table.ChildRelations.Count; i++)
            {
                if (_table.ChildRelations[i].ParentKey.ContainsColumn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveChildKey(_table.ChildRelations[i].RelationName);
                    }
                }
            }

            for (int i = 0; i < _table.Constraints.Count; i++)
            {
                if (_table.Constraints[i].ContainsColumn(column))
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.CannotRemoveConstraint(_table.Constraints[i].ConstraintName, _table.Constraints[i].Table !.TableName);
                    }
                }
            }

            if (_table.DataSet != null)
            {
                for (ParentForeignKeyConstraintEnumerator en = new ParentForeignKeyConstraintEnumerator(_table.DataSet, _table); en.GetNext();)
                {
                    Constraint constraint = en.GetConstraint();
                    if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column))
                    {
                        if (!fThrowException)
                        {
                            return(false);
                        }
                        else
                        {
                            throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table !.TableName);
                        }
                    }
                }
            }

            if (column._dependentColumns != null)
            {
                for (int i = 0; i < column._dependentColumns.Count; i++)
                {
                    DataColumn col = column._dependentColumns[i];
                    if (_fInClear && (col.Table == _table || col.Table == null))
                    {
                        continue;
                    }

                    if (col.Table == null)
                    {
                        continue;
                    }

                    Debug.Assert(col.Computed, "invalid (non an expression) column in the expression dependent columns");
                    DataExpression?expr = col.DataExpression;
                    if ((expr != null) && (expr.DependsOn(column)))
                    {
                        if (!fThrowException)
                        {
                            return(false);
                        }
                        else
                        {
                            throw ExceptionBuilder.CannotRemoveExpression(col.ColumnName, col.Expression);
                        }
                    }
                }
            }

            // you can't remove a column participating in an index,
            // while index events are suspended else the indexes won't be properly maintained.
            // However, all the above checks should catch those participating columns.
            // except when a column is in a DataView RowFilter or Sort clause
            foreach (Index _ in _table.LiveIndexes)
            {
            }

            return(true);
        }
예제 #10
0
        internal bool CanRemove(DataTable table, bool fThrowException)
        {
            bool   flag;
            IntPtr ptr;

            Bid.ScopeEnter(out ptr, "<ds.DataTableCollection.CanRemove|INFO> %d#, table=%d, fThrowException=%d{bool}\n", this.ObjectID, (table != null) ? table.ObjectID : 0, fThrowException);
            try
            {
                if (table == null)
                {
                    if (fThrowException)
                    {
                        throw ExceptionBuilder.ArgumentNull("table");
                    }
                    return(false);
                }
                if (table.DataSet != this.dataSet)
                {
                    if (fThrowException)
                    {
                        throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
                    }
                    return(false);
                }
                this.dataSet.OnRemoveTable(table);
                if ((table.ChildRelations.Count != 0) || (table.ParentRelations.Count != 0))
                {
                    if (fThrowException)
                    {
                        throw ExceptionBuilder.TableInRelation();
                    }
                    return(false);
                }
                ParentForeignKeyConstraintEnumerator enumerator2 = new ParentForeignKeyConstraintEnumerator(this.dataSet, table);
                while (enumerator2.GetNext())
                {
                    ForeignKeyConstraint foreignKeyConstraint = enumerator2.GetForeignKeyConstraint();
                    if ((foreignKeyConstraint.Table != table) || (foreignKeyConstraint.RelatedTable != table))
                    {
                        if (fThrowException)
                        {
                            throw ExceptionBuilder.TableInConstraint(table, foreignKeyConstraint);
                        }
                        return(false);
                    }
                }
                ChildForeignKeyConstraintEnumerator enumerator = new ChildForeignKeyConstraintEnumerator(this.dataSet, table);
                while (enumerator.GetNext())
                {
                    ForeignKeyConstraint constraint = enumerator.GetForeignKeyConstraint();
                    if ((constraint.Table != table) || (constraint.RelatedTable != table))
                    {
                        if (fThrowException)
                        {
                            throw ExceptionBuilder.TableInConstraint(table, constraint);
                        }
                        return(false);
                    }
                }
                flag = true;
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
            return(flag);
        }
 internal void Clear(bool clearAll)
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataTable.Clear|INFO> %d#, clearAll=%d{bool}\n", this.ObjectID, clearAll);
     try
     {
         this.rowDiffId = null;
         if (this.dataSet != null)
         {
             this.dataSet.OnClearFunctionCalled(this);
         }
         bool flag = this.Rows.Count != 0;
         DataTableClearEventArgs e = null;
         if (flag)
         {
             e = new DataTableClearEventArgs(this);
             this.OnTableClearing(e);
         }
         if ((this.dataSet != null) && this.dataSet.EnforceConstraints)
         {
             ParentForeignKeyConstraintEnumerator enumerator3 = new ParentForeignKeyConstraintEnumerator(this.dataSet, this);
             while (enumerator3.GetNext())
             {
                 enumerator3.GetForeignKeyConstraint().CheckCanClearParentTable(this);
             }
         }
         this.recordManager.Clear(clearAll);
         foreach (DataRow row in this.Rows)
         {
             row.oldRecord = -1;
             row.newRecord = -1;
             row.tempRecord = -1;
             row.rowID = -1L;
             row.RBTreeNodeId = 0;
         }
         this.Rows.ArrayClear();
         this.ResetIndexes();
         if (flag)
         {
             this.OnTableCleared(e);
         }
         foreach (DataColumn column in this.Columns)
         {
             this.EvaluateDependentExpressions(column);
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
 internal void CascadeAll(DataRow row, DataRowAction action)
 {
     if ((this.DataSet != null) && this.DataSet.fEnableCascading)
     {
         ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.dataSet, this);
         while (enumerator.GetNext())
         {
             enumerator.GetForeignKeyConstraint().CheckCascade(row, action);
         }
     }
 }
 internal void RemoveRow(DataRow row, bool check)
 {
     if (row.rowID == -1L)
     {
         throw ExceptionBuilder.RowAlreadyRemoved();
     }
     if (check && (this.dataSet != null))
     {
         ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.dataSet, this);
         while (enumerator.GetNext())
         {
             enumerator.GetForeignKeyConstraint().CheckCanRemoveParentRow(row);
         }
     }
     int oldRecord = row.oldRecord;
     int newRecord = row.newRecord;
     DataViewRowState recordState = row.GetRecordState(oldRecord);
     DataViewRowState state = row.GetRecordState(newRecord);
     row.oldRecord = -1;
     row.newRecord = -1;
     if (oldRecord == newRecord)
     {
         oldRecord = -1;
     }
     this.RecordStateChanged(oldRecord, recordState, DataViewRowState.None, newRecord, state, DataViewRowState.None);
     this.FreeRecord(ref oldRecord);
     this.FreeRecord(ref newRecord);
     row.rowID = -1L;
     this.Rows.ArrayRemove(row);
 }
 internal bool CanRemove(DataTable table, bool fThrowException)
 {
     bool flag;
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataTableCollection.CanRemove|INFO> %d#, table=%d, fThrowException=%d{bool}\n", this.ObjectID, (table != null) ? table.ObjectID : 0, fThrowException);
     try
     {
         if (table == null)
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.ArgumentNull("table");
             }
             return false;
         }
         if (table.DataSet != this.dataSet)
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
             }
             return false;
         }
         this.dataSet.OnRemoveTable(table);
         if ((table.ChildRelations.Count != 0) || (table.ParentRelations.Count != 0))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.TableInRelation();
             }
             return false;
         }
         ParentForeignKeyConstraintEnumerator enumerator2 = new ParentForeignKeyConstraintEnumerator(this.dataSet, table);
         while (enumerator2.GetNext())
         {
             ForeignKeyConstraint foreignKeyConstraint = enumerator2.GetForeignKeyConstraint();
             if ((foreignKeyConstraint.Table != table) || (foreignKeyConstraint.RelatedTable != table))
             {
                 if (fThrowException)
                 {
                     throw ExceptionBuilder.TableInConstraint(table, foreignKeyConstraint);
                 }
                 return false;
             }
         }
         ChildForeignKeyConstraintEnumerator enumerator = new ChildForeignKeyConstraintEnumerator(this.dataSet, table);
         while (enumerator.GetNext())
         {
             ForeignKeyConstraint constraint = enumerator.GetForeignKeyConstraint();
             if ((constraint.Table != table) || (constraint.RelatedTable != table))
             {
                 if (fThrowException)
                 {
                     throw ExceptionBuilder.TableInConstraint(table, constraint);
                 }
                 return false;
             }
         }
         flag = true;
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
     return flag;
 }
 internal bool CanRemove(DataColumn column, bool fThrowException)
 {
     if (column == null)
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.ArgumentNull("column");
         }
         return false;
     }
     if (column.table != this.table)
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.CannotRemoveColumn();
         }
         return false;
     }
     this.table.OnRemoveColumnInternal(column);
     if ((this.table.primaryKey != null) && this.table.primaryKey.Key.ContainsColumn(column))
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.CannotRemovePrimaryKey();
         }
         return false;
     }
     for (int i = 0; i < this.table.ParentRelations.Count; i++)
     {
         if (this.table.ParentRelations[i].ChildKey.ContainsColumn(column))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.CannotRemoveChildKey(this.table.ParentRelations[i].RelationName);
             }
             return false;
         }
     }
     for (int j = 0; j < this.table.ChildRelations.Count; j++)
     {
         if (this.table.ChildRelations[j].ParentKey.ContainsColumn(column))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.CannotRemoveChildKey(this.table.ChildRelations[j].RelationName);
             }
             return false;
         }
     }
     for (int k = 0; k < this.table.Constraints.Count; k++)
     {
         if (this.table.Constraints[k].ContainsColumn(column))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.CannotRemoveConstraint(this.table.Constraints[k].ConstraintName, this.table.Constraints[k].Table.TableName);
             }
             return false;
         }
     }
     if (this.table.DataSet != null)
     {
         ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.table.DataSet, this.table);
         while (enumerator.GetNext())
         {
             Constraint constraint = enumerator.GetConstraint();
             if (((ForeignKeyConstraint) constraint).ParentKey.ContainsColumn(column))
             {
                 if (fThrowException)
                 {
                     throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName);
                 }
                 return false;
             }
         }
     }
     if (column.dependentColumns != null)
     {
         for (int m = 0; m < column.dependentColumns.Count; m++)
         {
             DataColumn column2 = column.dependentColumns[m];
             if ((!this.fInClear || ((column2.Table != this.table) && (column2.Table != null))) && (column2.Table != null))
             {
                 DataExpression dataExpression = column2.DataExpression;
                 if ((dataExpression != null) && dataExpression.DependsOn(column))
                 {
                     if (fThrowException)
                     {
                         throw ExceptionBuilder.CannotRemoveExpression(column2.ColumnName, column2.Expression);
                     }
                     return false;
                 }
             }
         }
     }
     using (List<Index>.Enumerator enumerator2 = this.table.LiveIndexes.GetEnumerator())
     {
         while (enumerator2.MoveNext())
         {
             Index current = enumerator2.Current;
         }
     }
     return true;
 }
        internal override bool CanBeRemovedFromCollection(ConstraintCollection constraints, bool fThrowException) {
            if (this.Equals(constraints.Table.primaryKey)) {
                Debug.Assert(constraints.Table.primaryKey == this, "If the primary key and this are 'Equal', they should also be '=='");
                if (!fThrowException)
                    return false;
                else
                    throw ExceptionBuilder.RemovePrimaryKey(constraints.Table);
            }
            for (ParentForeignKeyConstraintEnumerator cs = new ParentForeignKeyConstraintEnumerator(Table.DataSet, Table); cs.GetNext();) {
                ForeignKeyConstraint constraint = cs.GetForeignKeyConstraint();
                if (!key.ColumnsEqual(constraint.ParentKey))
                    continue;

                if (!fThrowException)
                    return false;
                else
                    throw ExceptionBuilder.NeededForForeignKeyConstraint(this, constraint);
            }

            return true;
        }
예제 #17
0
파일: DataTable.cs 프로젝트: dotnet/corefx
        internal void Clear(bool clearAll)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.Clear|INFO> {0}, clearAll={1}", ObjectID, clearAll);
            try
            {
                Debug.Assert(null == _rowDiffId, "wasn't previously cleared");
                _rowDiffId = null;

                if (_dataSet != null)
                    _dataSet.OnClearFunctionCalled(this);
                bool shouldFireClearEvents = (Rows.Count != 0); // if Rows is already empty, this is noop

                DataTableClearEventArgs e = null;
                if (shouldFireClearEvents)
                {
                    e = new DataTableClearEventArgs(this);
                    OnTableClearing(e);
                }

                if (_dataSet != null && _dataSet.EnforceConstraints)
                {
                    for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(_dataSet, this); constraints.GetNext();)
                    {
                        ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                        constraint.CheckCanClearParentTable(this);
                    }
                }

                _recordManager.Clear(clearAll);

                // this improves performance by iterating over rows instead of computing by index
                foreach (DataRow row in Rows)
                {
                    row._oldRecord = -1;
                    row._newRecord = -1;
                    row._tempRecord = -1;
                    row.rowID = -1;
                    row.RBTreeNodeId = 0;
                }
                Rows.ArrayClear();

                ResetIndexes();

                if (shouldFireClearEvents)
                {
                    OnTableCleared(e);
                }

                foreach (DataColumn column in Columns)
                {
                    EvaluateDependentExpressions(column);
                }
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }
 internal bool CanRemove(DataColumn column, bool fThrowException)
 {
     if (column == null)
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.ArgumentNull("column");
         }
         return(false);
     }
     if (column.table != this.table)
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.CannotRemoveColumn();
         }
         return(false);
     }
     this.table.OnRemoveColumnInternal(column);
     if ((this.table.primaryKey != null) && this.table.primaryKey.Key.ContainsColumn(column))
     {
         if (fThrowException)
         {
             throw ExceptionBuilder.CannotRemovePrimaryKey();
         }
         return(false);
     }
     for (int i = 0; i < this.table.ParentRelations.Count; i++)
     {
         if (this.table.ParentRelations[i].ChildKey.ContainsColumn(column))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.CannotRemoveChildKey(this.table.ParentRelations[i].RelationName);
             }
             return(false);
         }
     }
     for (int j = 0; j < this.table.ChildRelations.Count; j++)
     {
         if (this.table.ChildRelations[j].ParentKey.ContainsColumn(column))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.CannotRemoveChildKey(this.table.ChildRelations[j].RelationName);
             }
             return(false);
         }
     }
     for (int k = 0; k < this.table.Constraints.Count; k++)
     {
         if (this.table.Constraints[k].ContainsColumn(column))
         {
             if (fThrowException)
             {
                 throw ExceptionBuilder.CannotRemoveConstraint(this.table.Constraints[k].ConstraintName, this.table.Constraints[k].Table.TableName);
             }
             return(false);
         }
     }
     if (this.table.DataSet != null)
     {
         ParentForeignKeyConstraintEnumerator enumerator = new ParentForeignKeyConstraintEnumerator(this.table.DataSet, this.table);
         while (enumerator.GetNext())
         {
             Constraint constraint = enumerator.GetConstraint();
             if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column))
             {
                 if (fThrowException)
                 {
                     throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName);
                 }
                 return(false);
             }
         }
     }
     if (column.dependentColumns != null)
     {
         for (int m = 0; m < column.dependentColumns.Count; m++)
         {
             DataColumn column2 = column.dependentColumns[m];
             if ((!this.fInClear || ((column2.Table != this.table) && (column2.Table != null))) && (column2.Table != null))
             {
                 DataExpression dataExpression = column2.DataExpression;
                 if ((dataExpression != null) && dataExpression.DependsOn(column))
                 {
                     if (fThrowException)
                     {
                         throw ExceptionBuilder.CannotRemoveExpression(column2.ColumnName, column2.Expression);
                     }
                     return(false);
                 }
             }
         }
     }
     using (List <Index> .Enumerator enumerator2 = this.table.LiveIndexes.GetEnumerator())
     {
         while (enumerator2.MoveNext())
         {
             Index current = enumerator2.Current;
         }
     }
     return(true);
 }
예제 #19
0
        internal bool CanRemove(DataColumn column, bool fThrowException) {
            if (column == null) {
                if (!fThrowException)
                    return false;
                else
                throw ExceptionBuilder.ArgumentNull("column");
            }
            if (column.table != table) {
                if (!fThrowException)
                    return false;
                else
                throw ExceptionBuilder.CannotRemoveColumn();
            }

            // allow subclasses to complain first.
            table.OnRemoveColumnInternal(column);

            // We need to make sure the column is not involved in any Relations or Constriants
            if (table.primaryKey != null && table.primaryKey.Key.ContainsColumn(column)) {
                if (!fThrowException)
                    return false;
                else
                throw ExceptionBuilder.CannotRemovePrimaryKey();
            }
            for (int i = 0; i < table.ParentRelations.Count; i++) {
                if (table.ParentRelations[i].ChildKey.ContainsColumn(column)) {
                    if (!fThrowException)
                        return false;
                    else
                    throw ExceptionBuilder.CannotRemoveChildKey(table.ParentRelations[i].RelationName);
                }
            }
            for (int i = 0; i < table.ChildRelations.Count; i++) {
                if (table.ChildRelations[i].ParentKey.ContainsColumn(column)) {
                    if (!fThrowException)
                        return false;
                    else
                    throw ExceptionBuilder.CannotRemoveChildKey(table.ChildRelations[i].RelationName);
                }
            }
            for (int i = 0; i < table.Constraints.Count; i++) {
                if (table.Constraints[i].ContainsColumn(column))
                    if (!fThrowException)
                        return false;
                    else
                    throw ExceptionBuilder.CannotRemoveConstraint(table.Constraints[i].ConstraintName, table.Constraints[i].Table.TableName);
            }
            if (table.DataSet != null) {
                for (ParentForeignKeyConstraintEnumerator en = new ParentForeignKeyConstraintEnumerator(table.DataSet, table); en.GetNext();) {
                    Constraint constraint = en.GetConstraint();
                    if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column))
                        if (!fThrowException)
                            return false;
                        else
                            throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName);
                }
            }

            if (column.dependentColumns != null) {
                for (int i = 0; i < column.dependentColumns.Count; i++) {
                    DataColumn col = column.dependentColumns[i];
                    if (fInClear && (col.Table == table || col.Table == null))
                        continue;
                    if (col.Table == null)
                        continue;
                    Debug.Assert(col.Computed, "invalid (non an expression) column in the expression dependent columns");
                    DataExpression expr = col.DataExpression;
                    if ((expr!= null) && (expr.DependsOn(column))) {
                        if (!fThrowException)
                            return false;
                        else
                            throw ExceptionBuilder.CannotRemoveExpression(col.ColumnName, col.Expression);
                    }
                }
            }

            // SQLBU 429176: you can't remove a column participating in an index,
            // while index events are suspended else the indexes won't be properly maintained.
            // However, all the above checks should catch those participating columns.
            // except when a column is in a DataView RowFilter or Sort clause
            foreach (Index index in table.LiveIndexes) {
#if false
                if (!Object.ReferenceEquals(index, column.sortIndex)) {
                    foreach (IndexField field in index.IndexFields) {
                        if (Object.ReferenceEquals(field.Column, column)) {
                            if (fThrowException) {
                                throw ExceptionBuilder.CannotRemoveExpression("DataView", column.ColumnName);
                            }
                            return false;
                        }
                    }
                }
#endif
            }

            return true;
        }
예제 #20
0
        internal void Clear(bool clearAll) {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.Clear|INFO> %d#, clearAll=%d{bool}\n", ObjectID, clearAll);

            try {
                Debug.Assert(null == rowDiffId, "wasn't previously cleared");
                rowDiffId = null;

                if (dataSet != null)
                    dataSet.OnClearFunctionCalled(this);
                bool shouldFireClearEvents = (this.Rows.Count != 0); // if Rows is already empty, this is noop

                DataTableClearEventArgs e = null;
                if (shouldFireClearEvents) {
                    e = new DataTableClearEventArgs (this);
                    OnTableClearing(e);
                }

                if (dataSet != null && dataSet.EnforceConstraints) {

                    for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, this); constraints.GetNext();) {
                        ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                        constraint.CheckCanClearParentTable(this);
                    }
                }

                recordManager.Clear(clearAll);

                // SQLBU 415729: Serious performance issue when calling Clear()
                // this improves performance by iterating over rows instead of computing by index
                foreach(DataRow row in Rows) {
                    row.oldRecord = -1;
                    row.newRecord = -1;
                    row.tempRecord = -1;
                    row.rowID = -1;
                    row.RBTreeNodeId = 0;
                }
                Rows.ArrayClear();

                ResetIndexes();

                if (shouldFireClearEvents) {
                    OnTableCleared(e);
                }

                // SQLBU 501916 - DataTable internal index is corrupted:'5'
                foreach(DataColumn column in Columns) {
                    EvaluateDependentExpressions(column);
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
        internal bool CanRemove(DataTable table, bool fThrowException)
        {
            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<ds.DataTableCollection.CanRemove|INFO> %d#, table=%d, fThrowException=%d{bool}\n", ObjectID, (table != null)? table.ObjectID : 0, fThrowException);
            try {
                if (table == null)
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.ArgumentNull("table");
                    }
                }
                if (table.DataSet != dataSet)
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
                    }
                }

                // allow subclasses to throw.
                dataSet.OnRemoveTable(table);

                if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0)
                {
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInRelation();
                    }
                }

                for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();)
                {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table) // we can go with (constraint.Table ==  constraint.RelatedTable)
                    {
                        continue;
                    }
                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                    }
                }

                for (ChildForeignKeyConstraintEnumerator constraints = new ChildForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();)
                {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table) // bug 97670
                    {
                        continue;
                    }

                    if (!fThrowException)
                    {
                        return(false);
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                    }
                }

                return(true);
            }
            finally{
                Bid.ScopeLeave(ref hscp);
            }
        }
예제 #22
0
        internal void RemoveRow(DataRow row, bool check) {
            if (row.rowID == -1) {
                throw ExceptionBuilder.RowAlreadyRemoved();
            }

            if (check && dataSet != null) {
                for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, this); constraints.GetNext();) {
                    constraints.GetForeignKeyConstraint().CheckCanRemoveParentRow(row);
                }
            }

            int oldRecord = row.oldRecord;
            int newRecord = row.newRecord;

            DataViewRowState oldRecordStatePre = row.GetRecordState(oldRecord);
            DataViewRowState newRecordStatePre = row.GetRecordState(newRecord);

            row.oldRecord = -1;
            row.newRecord = -1;

            if (oldRecord == newRecord) {
                oldRecord = -1;
            }

            RecordStateChanged(oldRecord, oldRecordStatePre, DataViewRowState.None,
                               newRecord, newRecordStatePre, DataViewRowState.None);

            FreeRecord(ref oldRecord);
            FreeRecord(ref newRecord);

            row.rowID = -1;
            Rows.ArrayRemove(row);
        }
예제 #23
0
        internal bool CanRemove(DataTable table, bool fThrowException)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.CanRemove|INFO> {0}, table={1}, fThrowException={2}", ObjectID, (table != null) ? table.ObjectID : 0, fThrowException);
            try
            {
                if (table == null)
                {
                    if (!fThrowException)
                    {
                        return false;
                    }
                    throw ExceptionBuilder.ArgumentNull(nameof(table));
                }
                if (table.DataSet != _dataSet)
                {
                    if (!fThrowException)
                    {
                        return false;
                    }
                    throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
                }

                // allow subclasses to throw.
                _dataSet.OnRemoveTable(table);

                if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0)
                {
                    if (!fThrowException)
                    {
                        return false;
                    }
                    throw ExceptionBuilder.TableInRelation();
                }

                for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(_dataSet, table); constraints.GetNext();)
                {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table) // we can go with (constraint.Table ==  constraint.RelatedTable)
                    {
                        continue;
                    }
                    if (!fThrowException)
                    {
                        return false;
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                    }
                }

                for (ChildForeignKeyConstraintEnumerator constraints = new ChildForeignKeyConstraintEnumerator(_dataSet, table); constraints.GetNext();)
                {
                    ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
                    if (constraint.Table == table && constraint.RelatedTable == table)
                    {
                        continue;
                    }

                    if (!fThrowException)
                    {
                        return false;
                    }
                    else
                    {
                        throw ExceptionBuilder.TableInConstraint(table, constraint);
                    }
                }

                return true;
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }