GetParentRow() static private method

static private GetParentRow ( DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version ) : DataRow
parentKey DataKey
childKey DataKey
childRow DataRow
version DataRowVersion
return DataRow
Exemplo n.º 1
0
        internal override void CheckConstraint(DataRow childRow, DataRowAction action)
        {
            if ((action == DataRowAction.Change ||
                 action == DataRowAction.Add ||
                 action == DataRowAction.Rollback) &&
                Table.DataSet != null && Table.DataSet.EnforceConstraints &&
                childRow.HasKeyChanged(_childKey))
            {
                // This branch is for cascading case verification.
                DataRowVersion version        = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
                object[]       childKeyValues = childRow.GetKeyValues(_childKey);
                // check to see if this is just a change to my parent's proposed value.
                if (childRow.HasVersion(version))
                {
                    // this is the new proposed value for the parent.
                    DataRow parentRow = DataRelation.GetParentRow(ParentKey, ChildKey, childRow, version);
                    if (parentRow != null && parentRow._inCascade)
                    {
                        object[] parentKeyValues = parentRow.GetKeyValues(_parentKey, action == DataRowAction.Rollback ? version : DataRowVersion.Default);

                        int parentKeyValuesRecord = childRow.Table.NewRecord();
                        childRow.Table.SetKeyValues(_childKey, parentKeyValues, parentKeyValuesRecord);
                        if (_childKey.RecordsEqual(childRow._tempRecord, parentKeyValuesRecord))
                        {
                            return;
                        }
                    }
                }

                // now check to see if someone exists... it will have to be in a parent row's current, not a proposed.
                object[] childValues = childRow.GetKeyValues(_childKey);
                if (!IsKeyNull(childValues))
                {
                    Index parentIndex = _parentKey.GetSortIndex();
                    if (!parentIndex.IsKeyInIndex(childValues))
                    {
                        // could be self-join constraint
                        if (_childKey.Table == _parentKey.Table && childRow._tempRecord != -1)
                        {
                            int lo = 0;
                            for (lo = 0; lo < childValues.Length; lo++)
                            {
                                DataColumn column = _parentKey.ColumnsReference[lo];
                                object     value  = column.ConvertValue(childValues[lo]);
                                if (0 != column.CompareValueTo(childRow._tempRecord, value))
                                {
                                    break;
                                }
                            }
                            if (lo == childValues.Length)
                            {
                                return;
                            }
                        }
                        throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, childKeyValues);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public DataRow GetParentRow(DataRelation relation, DataRowVersion version)
 {
     if (relation == null)
     {
         return(null);
     }
     if (relation.DataSet != this._table.DataSet)
     {
         throw ExceptionBuilder.RelationForeignRow();
     }
     if (relation.ChildKey.Table != this._table)
     {
         throw ExceptionBuilder.GetParentRowTableMismatch(relation.ChildTable.TableName, this._table.TableName);
     }
     return(DataRelation.GetParentRow(relation.ParentKey, relation.ChildKey, this, version));
 }
Exemplo n.º 3
0
 internal override void CheckConstraint(DataRow childRow, DataRowAction action)
 {
     if (((((action == DataRowAction.Change) || (action == DataRowAction.Add)) || (action == DataRowAction.Rollback)) && ((this.Table.DataSet != null) && this.Table.DataSet.EnforceConstraints)) && childRow.HasKeyChanged(this.childKey))
     {
         DataRowVersion version   = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
         object[]       keyValues = childRow.GetKeyValues(this.childKey);
         if (childRow.HasVersion(version))
         {
             DataRow row = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
             if ((row != null) && row.inCascade)
             {
                 object[] objArray2 = row.GetKeyValues(this.parentKey, (action == DataRowAction.Rollback) ? version : DataRowVersion.Default);
                 int      record    = childRow.Table.NewRecord();
                 childRow.Table.SetKeyValues(this.childKey, objArray2, record);
                 if (this.childKey.RecordsEqual(childRow.tempRecord, record))
                 {
                     return;
                 }
             }
         }
         object[] values = childRow.GetKeyValues(this.childKey);
         if (!this.IsKeyNull(values) && !this.parentKey.GetSortIndex().IsKeyInIndex(values))
         {
             if ((this.childKey.Table == this.parentKey.Table) && (childRow.tempRecord != -1))
             {
                 int index = 0;
                 index = 0;
                 while (index < values.Length)
                 {
                     DataColumn column = this.parentKey.ColumnsReference[index];
                     object     obj2   = column.ConvertValue(values[index]);
                     if (column.CompareValueTo(childRow.tempRecord, obj2) != 0)
                     {
                         break;
                     }
                     index++;
                 }
                 if (index == values.Length)
                 {
                     return;
                 }
             }
             throw ExceptionBuilder.ForeignKeyViolation(this.ConstraintName, keyValues);
         }
     }
 }
Exemplo n.º 4
0
        internal override void CheckConstraint(DataRow childRow, DataRowAction action)
        {
            Debug.Assert(Table.DataSet != null, "Relation " + ConstraintName + " isn't part of a DataSet, so this check shouldn't be happening.");
            if ((action == DataRowAction.Change ||
                 action == DataRowAction.Add ||
                 action == DataRowAction.Rollback) &&
                Table.DataSet != null && Table.DataSet.EnforceConstraints &&
                childRow.HasKeyChanged(childKey))
            {
                // This branch is for cascading case verification.
                DataRowVersion version        = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
                object[]       childKeyValues = childRow.GetKeyValues(childKey);
                // check to see if this is just a change to my parent's proposed value.
                if (childRow.HasVersion(version))
                {
                    // this is the new proposed value for the parent.
                    DataRow parentRow = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
                    if (parentRow != null && parentRow.inCascade)
                    {
                        object[] parentKeyValues = parentRow.GetKeyValues(parentKey, action == DataRowAction.Rollback ? version : DataRowVersion.Default);

#if DEBUG
                        if (CompModSwitches.Data_Constraints.TraceVerbose)
                        {
                            Debug.WriteLine("Parent and Child values on constraint check.");
                            for (int i = 0; i < childKeyValues.Length; i++)
                            {
                                Debug.WriteLine("... " + i.ToString() + ": " + Convert.ToString(parentKeyValues[i]) +
                                                ", " + Convert.ToString(childKeyValues[i]));
                            }
                        }
#endif

                        int parentKeyValuesRecord = childRow.Table.NewRecord();
                        childRow.Table.SetKeyValues(childKey, parentKeyValues, parentKeyValuesRecord);
                        if (childKey.RecordsEqual(childRow.tempRecord, parentKeyValuesRecord))
                        {
                            return;
                        }
                    }
                }

                // now check to see if someone exists... it will have to be in a parent row's current, not a proposed.
                object[] childValues = childRow.GetKeyValues(childKey);
                if (!IsKeyNull(childValues))
                {
                    Index parentIndex = parentKey.GetSortIndex();
                    if (!parentIndex.IsKeyInIndex(childValues))
                    {
                        // could be self-join constraint
                        if (childKey.Table == parentKey.Table && childRow.tempRecord != -1)
                        {
                            int lo = 0;
                            for (lo = 0; lo < childValues.Length; lo++)
                            {
                                if (parentKey.Columns[lo].CompareToValue(childRow.tempRecord, childValues[lo]) != 0)
                                {
                                    break;
                                }
                            }
                            if (lo == childValues.Length)
                            {
                                return;
                            }
                        }

                        throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, childKeyValues);
                    }
                }
            }
        }