private DataRow[] GetLinearFilteredRows(Range range) { DataRow[] resultRows; if (this.linearExpression == null) { int count = range.Count; resultRows = table.NewRowArray(count); for (int i = 0; i < count; i++) { resultRows[i] = index.GetRow(i + range.Min); } return(resultRows); } ArrayList matchingRows = new ArrayList(); for (int i = range.Min; i <= range.Max; i++) { int record = index.GetRecord(i); if (AcceptRecord(record)) { matchingRows.Add(index.GetRow(i)); } } resultRows = table.NewRowArray(matchingRows.Count); matchingRows.CopyTo((Array)resultRows); return(resultRows); }
internal void CascadeCommit(DataRow row) { if (row.RowState == DataRowState.Detached) { return; } if (acceptRejectRule == AcceptRejectRule.Cascade) { Index childIndex = childKey.GetSortIndex(row.RowState == DataRowState.Deleted ? DataViewRowState.Deleted : DataViewRowState.CurrentRows); object[] key = row.GetKeyValues(parentKey, row.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Default); if (IsKeyNull(key)) { return; } Range range = childIndex.FindRecords(key); if (!range.IsNull) { for (int j = range.Min; j <= range.Max; j++) { DataRow childRow = childIndex.GetRow(j); if (childRow.inCascade) { continue; } childRow.AcceptChanges(); } } } }
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); } } } } }
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); } } } }
internal void CascadeDelete(DataRow row) { if (-1 == row.newRecord) { return; } object[] currentKey = row.GetKeyValues(parentKey, DataRowVersion.Current); if (IsKeyNull(currentKey)) { return; } Index childIndex = childKey.GetSortIndex(); switch (DeleteRule) { 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) { if (range.Count == 1 && childIndex.GetRow(range.Min) == row) { return; } throw ExceptionBuilder.FailedCascadeDelete(ConstraintName); } } break; } case Rule.Cascade: { object[] key = row.GetKeyValues(parentKey, DataRowVersion.Default); Range range = childIndex.FindRecords(key); if (!range.IsNull) { DataRow[] rows = childIndex.GetRows(range); for (int j = 0; j < rows.Length; j++) { DataRow r = rows[j]; if (r.inCascade) { continue; } r.Table.DeleteRow(r); } } 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; if (row != rows[j]) { 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; if (row != rows[j]) { rows[j].SetKeyValues(childKey, proposedKey); } } } break; } default: { Debug.Assert(false, "Unknown Rule value"); break; } } }
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); } } }
internal void CascadeDelete(DataRow row) { if (-1 != row.newRecord) { object[] keyValues = row.GetKeyValues(this.parentKey, DataRowVersion.Current); if (!this.IsKeyNull(keyValues)) { Index sortIndex = this.childKey.GetSortIndex(); switch (this.DeleteRule) { case Rule.None: if (row.Table.DataSet.EnforceConstraints) { Range range4 = sortIndex.FindRecords(keyValues); if (range4.IsNull) { return; } if ((range4.Count != 1) || (sortIndex.GetRow(range4.Min) != row)) { throw ExceptionBuilder.FailedCascadeDelete(this.ConstraintName); } } return; case Rule.Cascade: { object[] key = row.GetKeyValues(this.parentKey, DataRowVersion.Default); Range range3 = sortIndex.FindRecords(key); if (!range3.IsNull) { foreach (DataRow row2 in sortIndex.GetRows(range3)) { if (!row2.inCascade) { row2.Table.DeleteRow(row2); } } } return; } case Rule.SetNull: { object[] objArray3 = new object[this.childKey.ColumnsReference.Length]; for (int i = 0; i < this.childKey.ColumnsReference.Length; i++) { objArray3[i] = DBNull.Value; } Range range2 = sortIndex.FindRecords(keyValues); if (!range2.IsNull) { DataRow[] rows = sortIndex.GetRows(range2); for (int j = 0; j < rows.Length; j++) { if (row != rows[j]) { rows[j].SetKeyValues(this.childKey, objArray3); } } } return; } case Rule.SetDefault: { object[] objArray2 = new object[this.childKey.ColumnsReference.Length]; for (int k = 0; k < this.childKey.ColumnsReference.Length; k++) { objArray2[k] = this.childKey.ColumnsReference[k].DefaultValue; } Range range = sortIndex.FindRecords(keyValues); if (!range.IsNull) { DataRow[] rowArray = sortIndex.GetRows(range); for (int m = 0; m < rowArray.Length; m++) { if (row != rowArray[m]) { rowArray[m].SetKeyValues(this.childKey, objArray2); } } } return; } } } } }