Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CheckConstraint() [2/2]

override void System.Data.ForeignKeyConstraint.CheckConstraint ( DataRow childRow,
DataRowAction action )
inlinepackage

Definition at line 552 of file ForeignKeyConstraint.cs.

553 {
554 if ((action != DataRowAction.Change && action != DataRowAction.Add && action != DataRowAction.Rollback) || Table.DataSet == null || !Table.DataSet.EnforceConstraints || !childRow.HasKeyChanged(_childKey))
555 {
556 return;
557 }
558 DataRowVersion dataRowVersion = ((action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current);
559 object[] keyValues = childRow.GetKeyValues(_childKey);
560 if (childRow.HasVersion(dataRowVersion))
561 {
562 DataRow parentRow = DataRelation.GetParentRow(ParentKey, ChildKey, childRow, dataRowVersion);
563 if (parentRow != null && parentRow._inCascade)
564 {
565 object[] keyValues2 = parentRow.GetKeyValues(_parentKey, (action == DataRowAction.Rollback) ? dataRowVersion : DataRowVersion.Default);
566 int num = childRow.Table.NewRecord();
567 childRow.Table.SetKeyValues(_childKey, keyValues2, num);
568 if (_childKey.RecordsEqual(childRow._tempRecord, num))
569 {
570 return;
571 }
572 }
573 }
574 object[] keyValues3 = childRow.GetKeyValues(_childKey);
575 if (IsKeyNull(keyValues3))
576 {
577 return;
578 }
579 Index sortIndex = _parentKey.GetSortIndex();
580 if (sortIndex.IsKeyInIndex(keyValues3))
581 {
582 return;
583 }
584 if (_childKey.Table == _parentKey.Table && childRow._tempRecord != -1)
585 {
586 int num2 = 0;
587 for (num2 = 0; num2 < keyValues3.Length; num2++)
588 {
589 DataColumn dataColumn = _parentKey.ColumnsReference[num2];
590 object value = dataColumn.ConvertValue(keyValues3[num2]);
591 if (dataColumn.CompareValueTo(childRow._tempRecord, value) != 0)
592 {
593 break;
594 }
595 }
596 if (num2 == keyValues3.Length)
597 {
598 return;
599 }
600 }
601 throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, keyValues);
602 }
virtual string ConstraintName
Definition Constraint.cs:24
object ConvertValue(object value)
Index GetSortIndex()
Definition DataKey.cs:184
bool RecordsEqual(int record1, int record2)
Definition DataKey.cs:195
DataColumn[] ColumnsReference
Definition DataKey.cs:7
DataTable Table
Definition DataKey.cs:11

References System.Data.ForeignKeyConstraint._childKey, System.Data.DataRow._inCascade, System.Data.ForeignKeyConstraint._parentKey, System.Data.DataRow._tempRecord, System.action, System.Data.ForeignKeyConstraint.ChildKey, System.Data.DataKey.ColumnsReference, System.Data.DataColumn.CompareValueTo(), System.Data.Constraint.ConstraintName, System.Data.DataColumn.ConvertValue(), System.Data.DataTable.DataSet, System.Data.DataSet.EnforceConstraints, System.Data.ExceptionBuilder.ForeignKeyViolation(), System.Data.DataRow.GetKeyValues(), System.Data.DataRelation.GetParentRow(), System.Data.DataKey.GetSortIndex(), System.Data.DataRow.HasKeyChanged(), System.Data.DataRow.HasVersion(), System.Data.Index.IsKeyInIndex(), System.Data.ForeignKeyConstraint.IsKeyNull(), System.Data.DataTable.NewRecord(), System.Data.ForeignKeyConstraint.ParentKey, System.Data.DataKey.RecordsEqual(), System.Data.DataTable.SetKeyValues(), System.Data.DataKey.Table, System.Data.DataRow.Table, System.Data.ForeignKeyConstraint.Table, and System.value.