示例#1
0
        internal void CascadeRollback(DataRow row)
        {
            Index sortIndex = this.childKey.GetSortIndex((row.RowState == DataRowState.Deleted) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);

            object[] keyValues = row.GetKeyValues(this.parentKey, (row.RowState == DataRowState.Modified) ? DataRowVersion.Current : DataRowVersion.Default);
            if (!this.IsKeyNull(keyValues))
            {
                Range range = sortIndex.FindRecords(keyValues);
                if (this.acceptRejectRule == System.Data.AcceptRejectRule.Cascade)
                {
                    if (!range.IsNull)
                    {
                        DataRow[] rows = sortIndex.GetRows(range);
                        for (int i = 0; i < rows.Length; i++)
                        {
                            if (!rows[i].inCascade)
                            {
                                rows[i].RejectChanges();
                            }
                        }
                    }
                }
                else if (((((row.RowState != DataRowState.Deleted) && row.Table.DataSet.EnforceConstraints) && !range.IsNull) && ((range.Count != 1) || (sortIndex.GetRow(range.Min) != row))) && row.HasKeyChanged(this.parentKey))
                {
                    throw ExceptionBuilder.FailedCascadeUpdate(this.ConstraintName);
                }
            }
        }
示例#2
0
        internal void CascadeRollback(DataRow row)
        {
            Debug.Assert(row.Table.DataSet != null);

            Index childIndex = _childKey.GetSortIndex(row.RowState == DataRowState.Deleted ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);

            object[] key = row.GetKeyValues(_parentKey, row.RowState == DataRowState.Modified ? DataRowVersion.Current : DataRowVersion.Default);

            if (IsKeyNull(key))
            {
                return;
            }

            Range range = childIndex.FindRecords(key);

            if (_acceptRejectRule == AcceptRejectRule.Cascade)
            {
                if (!range.IsNull)
                {
                    DataRow[] rows = childIndex.GetRows(range);
                    for (int j = 0; j < rows.Length; j++)
                    {
                        if (rows[j]._inCascade)
                        {
                            continue;
                        }
                        rows[j].RejectChanges();
                    }
                }
            }
            else
            {
                // AcceptRejectRule.None
                if (row.RowState != DataRowState.Deleted && row.Table.DataSet.EnforceConstraints)
                {
                    if (!range.IsNull)
                    {
                        if (range.Count == 1 && childIndex.GetRow(range.Min) == row)
                        {
                            return;
                        }

                        if (row.HasKeyChanged(_parentKey))
                        {// if key is not changed, this will not cause child to be stranded
                            throw ExceptionBuilder.FailedCascadeUpdate(ConstraintName);
                        }
                    }
                }
            }
        }
示例#3
0
        internal void CascadeRollback(DataRow row)
        {
            Index childIndex = childKey.GetSortIndex(row.RowState == DataRowState.Deleted  ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);

            object[] key = row.GetKeyValues(parentKey, row.RowState == DataRowState.Modified ? DataRowVersion.Current        : DataRowVersion.Default);

            // Bug : This is definitely not a proper fix. (Ref. MDAC Bug 73592)
            if (IsKeyNull(key))
            {
                return;
            }

            Range range = childIndex.FindRecords(key);

            if (acceptRejectRule == AcceptRejectRule.Cascade)
            {
                if (!range.IsNull)
                {
                    DataRow[] rows = childIndex.GetRows(range);
                    for (int j = 0; j < rows.Length; j++)
                    {
                        if (rows[j].inCascade)
                        {
                            continue;
                        }
                        rows[j].RejectChanges();
                    }
                }
            }
            else
            {
                // AcceptRejectRule.None
                if (row.RowState != DataRowState.Deleted && row.Table.DataSet.EnforceConstraints)
                {
                    if (!range.IsNull)
                    {
                        if (range.Count == 1 && childIndex.GetRow(range.Min) == row)
                        {
                            return;
                        }

                        throw ExceptionBuilder.FailedCascadeUpdate(ConstraintName);
                    }
                }
            }
        }
示例#4
0
        internal void CascadeUpdate(DataRow row)
        {
            if (-1 == row.newRecord)
            {
                return;
            }

            object[] currentKey = row.GetKeyValues(parentKey, DataRowVersion.Current);
            if (!Table.DataSet.fInReadXml && IsKeyNull(currentKey))
            {
                return;
            }

            Index childIndex = childKey.GetSortIndex();

            switch (UpdateRule)
            {
            case Rule.None: {
                if (row.Table.DataSet.EnforceConstraints)
                {
                    // if we're not cascading deletes, we should throw if we're going to strand a child row under enforceConstraints.
                    Range range = childIndex.FindRecords(currentKey);
                    if (!range.IsNull)
                    {
                        throw ExceptionBuilder.FailedCascadeUpdate(ConstraintName);
                    }
                }
                break;
            }

            case Rule.Cascade: {
                Range range = childIndex.FindRecords(currentKey);
                if (!range.IsNull)
                {
                    object[]  proposedKey = row.GetKeyValues(parentKey, DataRowVersion.Proposed);
                    DataRow[] rows        = childIndex.GetRows(range);
                    for (int j = 0; j < rows.Length; j++)
                    {
                        // if (rows[j].inCascade)
                        //    continue;
                        rows[j].SetKeyValues(childKey, proposedKey);
                    }
                }
                break;
            }

            case Rule.SetNull: {
                object[] proposedKey = new object[childKey.Columns.Length];
                for (int i = 0; i < childKey.Columns.Length; i++)
                {
                    proposedKey[i] = DBNull.Value;
                }
                Range range = childIndex.FindRecords(currentKey);
                if (!range.IsNull)
                {
                    DataRow[] rows = childIndex.GetRows(range);
                    for (int j = 0; j < rows.Length; j++)
                    {
                        // if (rows[j].inCascade)
                        //    continue;
                        rows[j].SetKeyValues(childKey, proposedKey);
                    }
                }
                break;
            }

            case Rule.SetDefault: {
                object[] proposedKey = new object[childKey.Columns.Length];
                for (int i = 0; i < childKey.Columns.Length; i++)
                {
                    proposedKey[i] = childKey.Columns[i].DefaultValue;
                }
                Range range = childIndex.FindRecords(currentKey);
                if (!range.IsNull)
                {
                    DataRow[] rows = childIndex.GetRows(range);
                    for (int j = 0; j < rows.Length; j++)
                    {
                        // if (rows[j].inCascade)
                        //    continue;
                        rows[j].SetKeyValues(childKey, proposedKey);
                    }
                }
                break;
            }

            default: {
                Debug.Assert(false, "Unknown Rule value");
                break;
            }
            }
        }
示例#5
0
        internal void CascadeUpdate(DataRow row)
        {
            if (-1 != row.newRecord)
            {
                object[] keyValues = row.GetKeyValues(this.parentKey, DataRowVersion.Current);
                if (this.Table.DataSet.fInReadXml || !this.IsKeyNull(keyValues))
                {
                    Index sortIndex = this.childKey.GetSortIndex();
                    switch (this.UpdateRule)
                    {
                    case Rule.None:
                        if (row.Table.DataSet.EnforceConstraints && !sortIndex.FindRecords(keyValues).IsNull)
                        {
                            throw ExceptionBuilder.FailedCascadeUpdate(this.ConstraintName);
                        }
                        return;

                    case Rule.Cascade:
                    {
                        Range range3 = sortIndex.FindRecords(keyValues);
                        if (!range3.IsNull)
                        {
                            object[]  objArray4 = row.GetKeyValues(this.parentKey, DataRowVersion.Proposed);
                            DataRow[] rows      = sortIndex.GetRows(range3);
                            for (int i = 0; i < rows.Length; i++)
                            {
                                rows[i].SetKeyValues(this.childKey, objArray4);
                            }
                        }
                        return;
                    }

                    case Rule.SetNull:
                    {
                        object[] objArray3 = new object[this.childKey.ColumnsReference.Length];
                        for (int j = 0; j < this.childKey.ColumnsReference.Length; j++)
                        {
                            objArray3[j] = DBNull.Value;
                        }
                        Range range2 = sortIndex.FindRecords(keyValues);
                        if (!range2.IsNull)
                        {
                            DataRow[] rowArray2 = sortIndex.GetRows(range2);
                            for (int k = 0; k < rowArray2.Length; k++)
                            {
                                rowArray2[k].SetKeyValues(this.childKey, objArray3);
                            }
                        }
                        return;
                    }

                    case Rule.SetDefault:
                    {
                        object[] objArray2 = new object[this.childKey.ColumnsReference.Length];
                        for (int m = 0; m < this.childKey.ColumnsReference.Length; m++)
                        {
                            objArray2[m] = this.childKey.ColumnsReference[m].DefaultValue;
                        }
                        Range range = sortIndex.FindRecords(keyValues);
                        if (!range.IsNull)
                        {
                            DataRow[] rowArray = sortIndex.GetRows(range);
                            for (int n = 0; n < rowArray.Length; n++)
                            {
                                rowArray[n].SetKeyValues(this.childKey, objArray2);
                            }
                        }
                        return;
                    }
                    }
                }
            }
        }