public RelatedView(DataRowView parentRowView, DataKey parentKey, DataColumn[] childKeyColumns) : base(childKeyColumns[0].Table, false) { this.filterValues = null; this.parentRowView = parentRowView; this.parentKey = parentKey; this.childKey = new DataKey(childKeyColumns, true); Debug.Assert (this.Table == childKey.Table, "Key.Table Must be equal to Current Table"); base.ResetRowViewCache(); }
public RelatedView(DataColumn[] columns, object[] values) : base(columns[0].Table, false) { if (values == null) { throw ExceptionBuilder.ArgumentNull("values"); } this.parentRowView = null; this.parentKey = null; this.childKey = new DataKey(columns, true); this.filterValues = values; Debug.Assert(this.Table == childKey.Table, "Key.Table Must be equal to Current Table"); base.ResetRowViewCache(); }
private void Create(string relationName, DataColumn[] parentColumns, DataColumn[] childColumns, bool createConstraints) { this.parentKey = new DataKey(parentColumns); this.childKey = new DataKey(childColumns); if (parentColumns.Length != childColumns.Length) { throw ExceptionBuilder.KeyLengthMismatch(); } CheckState(); this.relationName = (relationName == null ? "" : relationName); this.createConstraints = createConstraints; }
internal bool HasKeyChanged(DataKey key, DataRowVersion version1, DataRowVersion version2) { if (!HasVersion(version1) || !HasVersion(version2)) { return(true); } for (int i = 0; i < key.Columns.Length; i++) { if (0 != key.Columns[i].Compare(GetRecordFromVersion(version1), GetRecordFromVersion(version2))) { return(true); } } return(false); }
private int CompareRecordToKey(int record1, object val) { Debug.Assert(indexDesc.Length == 1, "Invalid ussage: CompareRecordToKey"); Int32 d = indexDesc[0]; int c = table.Columns[DataKey.ColumnOrder(d)].CompareToValue(record1, val); if (c != 0) { if (DataKey.SortDecending(d)) { c = -c; } return(c); } return(0); }
/// <include file='doc\ConstraintCollection.uex' path='docs/doc[@for="ConstraintCollection.Remove"]/*' /> /// <devdoc> /// <para> /// Removes the specified <see cref='System.Data.Constraint'/> /// from the collection.</para> /// </devdoc> public void Remove(Constraint constraint) { if (constraint == null) { throw ExceptionBuilder.ArgumentNull("constraint"); } // this will throw an exception if it can't be removed, otherwise indicates // whether we need to remove it from the collection. if (CanRemove(constraint, true)) { // constraint can be removed BaseRemove(constraint); ArrayRemove(constraint); if (constraint is UniqueConstraint && ((UniqueConstraint)constraint).IsPrimaryKey) { Table.PrimaryKey = null; } if (constraint is UniqueConstraint) { for (int i = 0; i < Table.ChildRelations.Count; i++) { DataRelation rel = Table.ChildRelations[i]; if (rel.ParentKeyConstraint == constraint) { rel.SetParentKeyConstraint(null); } } DataKey key = ((UniqueConstraint)constraint).Key; key.GetSortIndex().RemoveRef(); } else if (constraint is ForeignKeyConstraint) { for (int i = 0; i < Table.ParentRelations.Count; i++) { DataRelation rel = Table.ParentRelations[i]; if (rel.ChildKeyConstraint == constraint) { rel.SetChildKeyConstraint(null); } } } OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, constraint)); } }
private int CompareRecordToKey(int record1, object[] vals) { for (int i = 0; i < indexDesc.Length; i++) { Int32 d = indexDesc[i]; int c = table.Columns[DataKey.ColumnOrder(d)].CompareToValue(record1, vals[i]); if (c != 0) { if (DataKey.SortDecending(d)) { c = -c; } return(c); } } return(0); }
internal bool Equals(DataKey value) { //check to see if this.columns && key2's columns are equal... DataColumn[] column1 = _columns; DataColumn[] column2 = value._columns; if (column1 == column2) { return(true); } else if (column1 == null || column2 == null) { return(false); } else { return(column1.AsSpan().SequenceEqual(column2)); } }
private int CompareClosestCandidateIndexDesc(int[] id) { int num2 = (id.Length < this.nCandidates) ? id.Length : this.nCandidates; int index = 0; while (index < num2) { ColumnInfo info = this.candidateColumns[DataKey.ColumnOrder(id[index])]; if ((info == null) || (info.expr == null)) { return(index); } if (!info.equalsOperator) { return(index + 1); } index++; } return(index); }
// Returns no. of columns that are matched private int CompareClosestCandidateIndexDesc(int[] id) { int count = (id.Length < nCandidates ? id.Length : nCandidates); int i = 0; for (; i < count; i++) { ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[i])]; if (canColumn == null || canColumn.expr == null) { break; } else if (!canColumn.equalsOperator) { return(i + 1); } } return(i); }
private DataKey GetSrcKey(DataTable src, DataTable dst) { if (src.primaryKey != null) { return(src.primaryKey.Key); } DataKey key = new DataKey(); if (dst.primaryKey == null) { return(key); } DataColumn[] columnsReference = dst.primaryKey.Key.ColumnsReference; DataColumn[] columns = new DataColumn[columnsReference.Length]; for (int i = 0; i < columnsReference.Length; i++) { columns[i] = src.Columns[columnsReference[i].ColumnName]; } return(new DataKey(columns, false)); }
private int Evaluate(int record) { DataRow row = table.recordManager[record]; if (row == null) { return(0); } // UNDONE: perf switch to (row, version) internaly DataRowVersion version = DataRowVersion.Default; if (row.oldRecord == record) { version = DataRowVersion.Original; } else if (row.newRecord == record) { version = DataRowVersion.Current; } else if (row.tempRecord == record) { version = DataRowVersion.Proposed; } int[] id = index.IndexDesc; for (int i = 0; i < matchedCandidates; i++) { Debug.Assert(candidateColumns[DataKey.ColumnOrder(id[i])] != null, "How come this is not a candidate column"); Debug.Assert(candidateColumns[DataKey.ColumnOrder(id[i])].expr != null, "How come there is no associated expression"); int c = Eval(candidateColumns[DataKey.ColumnOrder(id[i])].expr, row, version); if (c != 0) { return(DataKey.SortDecending(id[i]) ? -c : c); } } return(0); }
private void MergeTable(DataTable src, DataTable dst) { int rowsCount = src.Rows.Count; bool wasEmpty = dst.Rows.Count == 0; if (0 < rowsCount) { Index? ndxSearch = null; DataKey key = default(DataKey); dst.SuspendIndexEvents(); try { if (!wasEmpty && dst._primaryKey != null) { key = GetSrcKey(src, dst); if (key.HasValue) { ndxSearch = dst._primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } // this improves performance by iterating over the rows instead of computing their position foreach (DataRow sourceRow in src.Rows) { DataRow?targetRow = null; if (ndxSearch != null) { targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch); } dst.MergeRow(sourceRow, targetRow, _preserveChanges, ndxSearch); } } finally { dst.RestoreIndexEvents(true); } } MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
private DataKey GetSrcKey(DataTable src, DataTable dst) { if (src.primaryKey != null) { return(src.primaryKey.Key); } DataKey key = null; if (dst.primaryKey != null) { DataColumn[] dstColumns = dst.primaryKey.Key.Columns; DataColumn[] srcColumns = new DataColumn[dstColumns.Length]; for (int j = 0; j < dstColumns.Length; j++) { srcColumns[j] = src.Columns[dstColumns[j].ColumnName]; } key = new DataKey(srcColumns); } return(key); }
internal void SetKeyValues(DataKey key, object[] keyValues) { bool flag = true; bool flag2 = this.tempRecord == -1; for (int i = 0; i < keyValues.Length; i++) { object obj2 = this[key.ColumnsReference[i]]; if (!obj2.Equals(keyValues[i])) { if (flag2 && flag) { flag = false; this.BeginEditInternal(); } this[key.ColumnsReference[i]] = keyValues[i]; } } if (!flag) { this.EndEdit(); } }
internal void SetKeyValues(DataKey key, object[] keyValues) { bool fFirstCall = true; bool immediate = (tempRecord == -1); for (int i = 0; i < keyValues.Length; i++) { object value = this[key.Columns[i]]; if (!value.Equals(keyValues[i])) { if (immediate && fFirstCall) { fFirstCall = false; BeginEdit(); } this[key.Columns[i]] = keyValues[i]; } } if (!fFirstCall) { EndEdit(); } }
private DataKey GetSrcKey(DataTable src, DataTable dst) { if (src.primaryKey != null) { return(src.primaryKey.Key); } DataKey key = default(DataKey); if (dst.primaryKey != null) { DataColumn[] dstColumns = dst.primaryKey.Key.ColumnsReference; DataColumn[] srcColumns = new DataColumn[dstColumns.Length]; for (int j = 0; j < dstColumns.Length; j++) { srcColumns[j] = src.Columns[dstColumns[j].ColumnName]; } key = new DataKey(srcColumns, false); // DataKey will take ownership of srcColumns } return(key); }
private void MergeTable(DataTable src, DataTable dst) { int count = src.Rows.Count; bool flag = dst.Rows.Count == 0; if (0 < count) { Index ndx = null; DataKey srcKey = new DataKey(); dst.SuspendIndexEvents(); try { if (!flag && (dst.primaryKey != null)) { srcKey = this.GetSrcKey(src, dst); if (srcKey.HasValue) { ndx = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } foreach (DataRow row2 in src.Rows) { DataRow targetRow = null; if (ndx != null) { targetRow = dst.FindMergeTarget(row2, srcKey, ndx); } dst.MergeRow(row2, targetRow, this.preserveChanges, ndx); } } finally { dst.RestoreIndexEvents(true); } } this.MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
/// <include file='doc\DataKey.uex' path='docs/doc[@for="DataKey.ColumnsEqual"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public virtual bool ColumnsEqual(DataKey key) { DataColumn[] column1 = this.Columns; DataColumn[] column2 = ((DataKey)key).Columns; if (column1 == column2) { return(true); } else if (column1 == null || column2 == null) { return(false); } else if (column1.Length != column2.Length) { return(false); } else { int i, j; for (i = 0; i < column1.Length; i++) { for (j = 0; j < column2.Length; j++) { if (column1[i].Equals(column2[j])) { break; } } if (j == column2.Length) { return(false); } } } return(true); }
internal bool Equals(DataKey value) { DataColumn[] columns = this.columns; DataColumn[] columnArray2 = value.columns; if (columns != columnArray2) { if ((columns == null) || (columnArray2 == null)) { return(false); } if (columns.Length != columnArray2.Length) { return(false); } for (int i = 0; i < columns.Length; i++) { if (!columns[i].Equals(columnArray2[i])) { return(false); } } } return(true); }
internal static DataRow GetParentRow(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) { if (!childRow.HasVersion((version == DataRowVersion.Original) ? DataRowVersion.Original : DataRowVersion.Current) && (childRow.tempRecord == -1)) { return(null); } object[] keyValues = childRow.GetKeyValues(childKey, version); if (IsKeyNull(keyValues)) { return(null); } Index sortIndex = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows); Range range = sortIndex.FindRecords(keyValues); if (range.IsNull) { return(null); } if (range.Count > 1) { throw ExceptionBuilder.MultipleParents(); } return(parentKey.Table.recordManager[sortIndex.GetRecord(range.Min)]); }
// Based on the current index and candidate columns settings, build the linear expression; Should be called only when there is atleast something for Binary Searching private void BuildLinearExpression() { int i; int[] id = index.IndexDesc; int lenId = id.Length; Debug.Assert(matchedCandidates > 0 && matchedCandidates <= lenId, "BuildLinearExpression : Invalid Index"); for (i = 0; i < matchedCandidates; i++) { ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[i])]; Debug.Assert(canColumn != null && canColumn.expr != null, "BuildLinearExpression : Must be a matched candidate"); canColumn.flag = true; } Debug.Assert(matchedCandidates == 1 || candidateColumns[matchedCandidates - 1].equalsOperator, "BuildLinearExpression : Invalid matched candidates"); int lenCanColumns = candidateColumns.Length; for (i = 0; i < lenCanColumns; i++) { if (candidateColumns[i] != null) { if (!candidateColumns[i].flag) { if (candidateColumns[i].expr != null) { this.linearExpression = (this.linearExpression == null ? candidateColumns[i].expr : new BinaryNode(Operators.And, candidateColumns[i].expr, this.linearExpression)); } } else { candidateColumns[i].flag = false; } } } Debug.Assert(this.linearExpression != null, "BuildLinearExpression : How come there is nothing to search linearly"); }
private void populateData(M_ClassApexInfo info, ref DataKey key, ref string currentKey, DataRow contentrow, List<M_ClassApexInvestigation> investigstion) { int col = 0; //Find Operator while (contentrow[col].ToString().Trim() != "") { if (key == DataKey.Key) { currentKey = contentrow[col].ToString().Trim(); key = DataKey.Value; } else { if (currentKey == "Operator") { info.Operator = contentrow[col].ToString(); } key = DataKey.Key; } col += 1; } //Reset Counter col = 0; while (contentrow[col].ToString().Trim() != "") { if (key == DataKey.Key) { currentKey = contentrow[col].ToString().Trim(); key = DataKey.Value; } else { if (currentKey == "Operator") { info.Operator = contentrow[col].ToString(); } else { //Can Write row to table DataRow NewDR = Data.NewRow(); NewDR[0] = info.Location; NewDR[1] = info.Date.ToShortDateString(); if (currentKey == "Finger Dab") { NewDR[2] = "Finger Touch Plate"; } else { NewDR[2] = currentKey; } NewDR[3] = info.Operator; NewDR[4] = contentrow[col].ToString(); string searchString = currentKey + " Investigation"; //Look Up Growth if (investigstion.Count > 0) { var match = (from m in investigstion where m.Investigation.Equals(searchString) select m).Single<M_ClassApexInvestigation>(); //if (match) //{ NewDR[4] = match.Growth + " : " + match.Number; //} } Data.Rows.Add(NewDR); } key = DataKey.Key; } col += 1; } }
private void Create(string relationName, DataColumn[] parentColumns, DataColumn[] childColumns) { if (parentColumns.Length == 0 || childColumns.Length == 0) throw ExceptionBuilder.KeyLengthZero(); if (parentColumns.Length != childColumns.Length) throw ExceptionBuilder.KeyLengthMismatch(); for (int i = 0; i < parentColumns.Length; i++) { if (parentColumns[i].Computed) { throw ExceptionBuilder.ExpressionInConstraint(parentColumns[i]); } if (childColumns[i].Computed) { throw ExceptionBuilder.ExpressionInConstraint(childColumns[i]); } } this.parentKey = new DataKey(parentColumns, true); this.childKey = new DataKey(childColumns, true); ConstraintName = relationName; NonVirtualCheckState(); }
private void Create(string relationName, DataColumn[] parentColumns, DataColumn[] childColumns, bool createConstraints) { long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataRelation.Create|INFO> {0}, relationName='{1}', createConstraints={2}", ObjectID, relationName, createConstraints); try { _parentKey = new DataKey(parentColumns, true); _childKey = new DataKey(childColumns, true); if (parentColumns.Length != childColumns.Length) { throw ExceptionBuilder.KeyLengthMismatch(); } for (int i = 0; i < parentColumns.Length; i++) { if ((parentColumns[i].Table.DataSet == null) || (childColumns[i].Table.DataSet == null)) { throw ExceptionBuilder.ParentOrChildColumnsDoNotHaveDataSet(); } } CheckState(); _relationName = (relationName == null ? "" : relationName); _createConstraints = createConstraints; } finally { DataCommonEventSource.Log.ExitScope(logScopeId); } }
private DataKey GetSrcKey(DataTable src, DataTable dst) { if (src.primaryKey != null) return src.primaryKey.Key; DataKey key = default(DataKey); if (dst.primaryKey != null) { DataColumn[] dstColumns = dst.primaryKey.Key.ColumnsReference; DataColumn[] srcColumns = new DataColumn[dstColumns.Length]; for (int j = 0; j < dstColumns.Length; j++) { srcColumns[j] = src.Columns[dstColumns[j].ColumnName]; } key = new DataKey(srcColumns, false); // DataKey will take ownership of srcColumns } return key; }
internal object[] GetKeyValues(DataKey key, DataRowVersion version) { int record = GetRecordFromVersion(version); return key.GetKeyValues(record); }
internal object[] GetColumnValues(DataColumn[] columns, DataRowVersion version) { DataKey key = new DataKey(columns, false); // temporary key, don't copy columns return GetKeyValues(key, version); }
internal bool HaveValuesChanged(DataColumn[] columns, DataRowVersion version1, DataRowVersion version2) { for (int i = 0; i < columns.Length; i++) { CheckColumn(columns[i]); } DataKey key = new DataKey(columns, false); // temporary key, don't copy columns return HasKeyChanged(key, version1, version2); }
internal void SetKeyValues(DataKey key, object[] keyValues, int record) { for (int i = 0; i < keyValues.Length; i++) { key.ColumnsReference[i][record] = keyValues[i]; } }
internal static DataRow GetParentRow(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) { if (!childRow.HasVersion((version == DataRowVersion.Original) ? DataRowVersion.Original : DataRowVersion.Current)) if (childRow.tempRecord == -1) return null; object[] values = childRow.GetKeyValues(childKey, version); if (IsKeyNull(values)) { return null; } Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows); Range range = index.FindRecords(values); if (range.IsNull) { return null; } if (range.Count > 1) { throw ExceptionBuilder.MultipleParents(); } return parentKey.Table.recordManager[index.GetRecord(range.Min)]; }
/// <devdoc> /// Gets the parent rows for the given child row across the relation using the version given /// </devdoc> internal static DataRow[] GetParentRows(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) { object[] values = childRow.GetKeyValues(childKey, version); if (IsKeyNull(values)) { return parentKey.Table.NewRowArray(0); } Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows); return index.GetRows(values); }
// Based on the required sorting and candidate columns settings, create a new index; Should be called only when there is no existing index to be reused private void CreateIndex() { if (index == null) { if (nCandidates == 0) { index = new Index(table, indexDesc, recordStates, null); } else { int i; int lenCanColumns = candidateColumns.Length; int lenIndexDesc = indexDesc.Length; bool equalsOperator = true; for (i = 0; i < lenCanColumns; i++) { if (candidateColumns[i] != null) { if (!candidateColumns[i].equalsOperator) { equalsOperator = false; break; } } } for (i = 0; i < lenIndexDesc; i++) { if (candidateColumns[DataKey.ColumnOrder(indexDesc[i])] == null) { break; } } int indexNotInCandidates = indexDesc.Length - i; int candidatesNotInIndex = nCandidates - i; int[] ndxDesc = new int[nCandidates + indexNotInCandidates]; if (equalsOperator) { for (i = 0; i < lenIndexDesc; i++) { ndxDesc[candidatesNotInIndex + i] = indexDesc[i]; ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(indexDesc[i])]; if (canColumn != null) { canColumn.flag = true; } } int j = 0; for (i = 0; i < lenCanColumns; i++) { if (candidateColumns[i] != null) { if (!candidateColumns[i].flag) { ndxDesc[j++] = i; } else { candidateColumns[i].flag = false; } } } Debug.Assert(j == candidatesNotInIndex, "Whole ndxDesc should be filled!"); index = new Index(table, ndxDesc, recordStates, null); matchedCandidates = nCandidates; } else { for (i = 0; i < lenIndexDesc; i++) { ndxDesc[i] = indexDesc[i]; ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(indexDesc[i])]; if (canColumn != null) { canColumn.flag = true; } } int j = i; for (i = 0; i < lenCanColumns; i++) { if (candidateColumns[i] != null) { if (!candidateColumns[i].flag) { ndxDesc[j++] = i; } else { candidateColumns[i].flag = false; } } } Debug.Assert(j == nCandidates + indexNotInCandidates, "Whole ndxDesc should be filled!"); index = new Index(table, ndxDesc, recordStates, null); matchedCandidates = 0; if (this.linearExpression != this.expression) { int[] id = index.IndexDesc; while (matchedCandidates < j) // haroona : j = index.IndexDesc.Length { ColumnInfo canColumn = candidateColumns[DataKey.ColumnOrder(id[matchedCandidates])]; if (canColumn == null || canColumn.expr == null) { break; } matchedCandidates++; if (!canColumn.equalsOperator) { break; } } } } } } }
private IndexField[] NewIndexDesc(DataKey key) { IndexField[] indexDesc = key.GetIndexDesc(); IndexField[] destinationArray = new IndexField[indexDesc.Length]; Array.Copy(indexDesc, 0, destinationArray, 0, indexDesc.Length); return destinationArray; }
private DataRow FindRow(DataKey key, object value) { Index index = GetIndex(NewIndexDesc(key)); Range range = index.FindRecords(value); if (range.IsNull) return null; return recordManager[index.GetRecord(range.Min)]; }
private void CreateIndex() { if (this.index == null) { if (this.nCandidates == 0) { this.index = new Index(this.table, this.IndexFields, this.recordStates, null); this.index.AddRef(); } else { int num; int length = this.candidateColumns.Length; int num5 = this.indexDesc.Length; bool flag = true; for (num = 0; num < length; num++) { if ((this.candidateColumns[num] != null) && !this.candidateColumns[num].equalsOperator) { flag = false; break; } } int num2 = 0; for (num = 0; num < num5; num++) { ColumnInfo info4 = this.candidateColumns[DataKey.ColumnOrder(this.indexDesc[num])]; if (info4 != null) { info4.flag = true; num2++; } } int num7 = num5 - num2; int[] ndexDesc = new int[this.nCandidates + num7]; if (flag) { num2 = 0; for (num = 0; num < length; num++) { if (this.candidateColumns[num] != null) { ndexDesc[num2++] = num; this.candidateColumns[num].flag = false; } } for (num = 0; num < num5; num++) { ColumnInfo info = this.candidateColumns[DataKey.ColumnOrder(this.indexDesc[num])]; if ((info == null) || info.flag) { ndexDesc[num2++] = this.indexDesc[num]; if (info != null) { info.flag = false; } } } for (num = 0; num < this.candidateColumns.Length; num++) { if (this.candidateColumns[num] != null) { this.candidateColumns[num].flag = false; } } IndexField[] zeroIndexField = DataTable.zeroIndexField; if (0 < ndexDesc.Length) { zeroIndexField = new IndexField[ndexDesc.Length]; for (int i = 0; i < ndexDesc.Length; i++) { DataColumn column2 = this.table.Columns[DataKey.ColumnOrder(ndexDesc[i])]; bool isDescending = DataKey.SortDecending(ndexDesc[i]); zeroIndexField[i] = new IndexField(column2, isDescending); } } this.index = new Index(this.table, ndexDesc, zeroIndexField, this.recordStates, null); if (!this.IsOperatorIn(this.expression)) { this.index.AddRef(); } this.matchedCandidates = this.nCandidates; } else { num = 0; while (num < num5) { ndexDesc[num] = this.indexDesc[num]; ColumnInfo info3 = this.candidateColumns[DataKey.ColumnOrder(this.indexDesc[num])]; if (info3 != null) { info3.flag = true; } num++; } num2 = num; for (num = 0; num < length; num++) { if (this.candidateColumns[num] != null) { if (!this.candidateColumns[num].flag) { ndexDesc[num2++] = num; } else { this.candidateColumns[num].flag = false; } } } IndexField[] indexFields = DataTable.zeroIndexField; if (0 < ndexDesc.Length) { indexFields = new IndexField[ndexDesc.Length]; for (int j = 0; j < ndexDesc.Length; j++) { DataColumn column = this.table.Columns[DataKey.ColumnOrder(ndexDesc[j])]; bool flag2 = DataKey.SortDecending(ndexDesc[j]); indexFields[j] = new IndexField(column, flag2); } } this.index = new Index(this.table, ndexDesc, indexFields, this.recordStates, null); this.matchedCandidates = 0; if (this.linearExpression != this.expression) { int[] indexDesc = this.index.IndexDesc; while (this.matchedCandidates < num2) { ColumnInfo info2 = this.candidateColumns[DataKey.ColumnOrder(indexDesc[this.matchedCandidates])]; if ((info2 == null) || (info2.expr == null)) { break; } this.matchedCandidates++; if (!info2.equalsOperator) { break; } } } for (num = 0; num < this.candidateColumns.Length; num++) { if (this.candidateColumns[num] != null) { this.candidateColumns[num].flag = false; } } } } } }
internal bool HaveValuesChanged(DataColumn[] columns, DataRowVersion version1, DataRowVersion version2) { for (int i = 0; i < columns.Length; i++) { this.CheckColumn(columns[i]); } DataKey key = new DataKey(columns, false); return this.HasKeyChanged(key, version1, version2); }
internal void SetKeyValues(DataKey key, object[] keyValues) { bool fFirstCall = true; bool immediate = (_tempRecord == -1); for (int i = 0; i < keyValues.Length; i++) { object value = this[key.ColumnsReference[i]]; if (!value.Equals(keyValues[i])) { if (immediate && fFirstCall) { fFirstCall = false; BeginEditInternal(); } this[key.ColumnsReference[i]] = keyValues[i]; } } if (!fFirstCall) { EndEdit(); } }
internal object[] GetColumnValues(DataColumn[] columns, DataRowVersion version) { DataKey key = new DataKey(columns, false); return this.GetKeyValues(key, version); }
internal object[] GetKeyValues(DataKey key) { int record = GetDefaultRecord(); return key.GetKeyValues(record); }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if (relation.ChildTable.DataSet != _dataSet || relation.ParentTable.DataSet != _dataSet) { throw ExceptionBuilder.ForeignRelation(); } relation.CheckState(); if (relation.Nested) { relation.CheckNestedRelations(); } if (relation._relationName.Length == 0) { relation._relationName = AssignName(); } else { RegisterName(relation._relationName); } DataKey childKey = relation.ChildKey; for (int i = 0; i < _relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation)_relations[i] !).ChildKey)) { if (relation.ParentKey.ColumnsEqual(((DataRelation)_relations[i] !).ParentKey)) { throw ExceptionBuilder.RelationAlreadyExists(); } } } _relations.Add(relation); ((DataTableRelationCollection)(relation.ParentTable.ChildRelations)).Add(relation); // Caching in ParentTable -> ChildRelations ((DataTableRelationCollection)(relation.ChildTable.ParentRelations)).Add(relation); // Caching in ChildTable -> ParentRelations relation.SetDataSet(_dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(); } ForeignKeyConstraint?foreignKey = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference); if (relation._createConstraints) { if (foreignKey == null) { relation.ChildTable.Constraints.Add(foreignKey = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference)); // try to name the fk constraint the same as the parent relation: try { foreignKey.ConstraintName = relation.RelationName; } catch (Exception e) when(Common.ADP.IsCatchableExceptionType(e)) { ExceptionBuilder.TraceExceptionWithoutRethrow(e); } } } UniqueConstraint?key = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference); relation.SetParentKeyConstraint(key); relation.SetChildKeyConstraint(foreignKey); }
//check to see if this.columns && key2's columns are equal regardless of order internal bool ColumnsEqual(DataKey key) => ColumnsEqual(_columns, key._columns);
//check to see if this.columns && key2's columns are equal regardless of order internal bool ColumnsEqual(DataKey key) { return ColumnsEqual(this.columns, ((DataKey)key).columns); }
internal bool HasKeyChanged(DataKey key) { return this.HasKeyChanged(key, DataRowVersion.Current, DataRowVersion.Proposed); }
internal object[] GetKeyValues(DataKey key) { return(GetKeyValues(key, DataRowVersion.Default)); }
private void Create(String constraintName, DataColumn[] columns) { for (int i = 0; i < columns.Length; i++) { if (columns[i].Computed) { throw ExceptionBuilder.ExpressionInConstraint(columns[i]); } } this.key = new DataKey(columns, true); ConstraintName = constraintName; NonVirtualCheckState(); }
internal bool HasKeyChanged(DataKey key) { return(HasKeyChanged(key, DataRowVersion.Current, DataRowVersion.Proposed)); }
internal object[] GetKeyValues(DataKey key) { int defaultRecord = this.GetDefaultRecord(); return key.GetKeyValues(defaultRecord); }
internal void MergeRows(DataRow[] rows) { DataTable src = null; DataTable dst = null; DataKey key = default(DataKey); Index ndxSearch = null; bool fEnforce = dataSet.EnforceConstraints; dataSet.EnforceConstraints = false; for (int i = 0; i < rows.Length; i++) { DataRow row = rows[i]; if (row == null) { throw ExceptionBuilder.ArgumentNull("rows[" + i + "]"); } if (row.Table == null) { throw ExceptionBuilder.ArgumentNull("rows[" + i + "].Table"); } //somebody is doing an 'automerge' if (row.Table.DataSet == dataSet) { continue; } if (src != row.Table) // row.Table changed from prev. row. { src = row.Table; dst = MergeSchema(row.Table); if (dst == null) { Debug.Assert(MissingSchemaAction.Ignore == missingSchemaAction, "MergeSchema failed"); dataSet.EnforceConstraints = fEnforce; return; } if (dst.primaryKey != null) { key = GetSrcKey(src, dst); } if (key.HasValue) { // Getting our own copy instead. ndxSearch = dst.primaryKey.Key.GetSortIndex(); // IMO, Better would be to reuse index // ndxSearch = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added ); if (null != ndxSearch) { ndxSearch.RemoveRef(); ndxSearch = null; } ndxSearch = new Index(dst, dst.primaryKey.Key.GetIndexDesc(), DataViewRowState.OriginalRows | DataViewRowState.Added, (IFilter)null); ndxSearch.AddRef(); // need to addref twice, otherwise it will be collected ndxSearch.AddRef(); // in past first adref was done in const } } if (row.newRecord == -1 && row.oldRecord == -1) { continue; } DataRow targetRow = null; if (0 < dst.Rows.Count && ndxSearch != null) { targetRow = dst.FindMergeTarget(row, key, ndxSearch); } targetRow = dst.MergeRow(row, targetRow, preserveChanges, ndxSearch); if (targetRow.Table.dependentColumns != null && targetRow.Table.dependentColumns.Count > 0) { targetRow.Table.EvaluateExpressions(targetRow, DataRowAction.Change, null); } } if (null != ndxSearch) { ndxSearch.RemoveRef(); ndxSearch = null; } dataSet.EnforceConstraints = fEnforce; }
internal bool HasKeyChanged(DataKey key) => HasKeyChanged(key, DataRowVersion.Current, DataRowVersion.Proposed);
internal void MergeRows(DataRow[] rows) { DataTable dst = null; DataTable src = null; DataKey srcKey = new DataKey(); Index ndx = null; bool enforceConstraints = this.dataSet.EnforceConstraints; this.dataSet.EnforceConstraints = false; for (int i = 0; i < rows.Length; i++) { DataRow row = rows[i]; if (row == null) { throw ExceptionBuilder.ArgumentNull("rows[" + i + "]"); } if (row.Table == null) { throw ExceptionBuilder.ArgumentNull("rows[" + i + "].Table"); } if (row.Table.DataSet != this.dataSet) { if (src != row.Table) { src = row.Table; dst = this.MergeSchema(row.Table); if (dst == null) { this.dataSet.EnforceConstraints = enforceConstraints; return; } if (dst.primaryKey != null) { srcKey = this.GetSrcKey(src, dst); } if (srcKey.HasValue) { if (ndx != null) { ndx.RemoveRef(); ndx = null; } ndx = new Index(dst, dst.primaryKey.Key.GetIndexDesc(), DataViewRowState.OriginalRows | DataViewRowState.Added, null); ndx.AddRef(); ndx.AddRef(); } } if ((row.newRecord != -1) || (row.oldRecord != -1)) { DataRow targetRow = null; if ((0 < dst.Rows.Count) && (ndx != null)) { targetRow = dst.FindMergeTarget(row, srcKey, ndx); } targetRow = dst.MergeRow(row, targetRow, this.preserveChanges, ndx); if ((targetRow.Table.dependentColumns != null) && (targetRow.Table.dependentColumns.Count > 0)) { targetRow.Table.EvaluateExpressions(targetRow, DataRowAction.Change, null); } } } } if (ndx != null) { ndx.RemoveRef(); ndx = null; } this.dataSet.EnforceConstraints = enforceConstraints; }
internal bool HasKeyChanged(DataKey key, DataRowVersion version1, DataRowVersion version2) { if (!HasVersion(version1) || !HasVersion(version2)) { return true; } return !key.RecordsEqual(GetRecordFromVersion(version1), GetRecordFromVersion(version2)); }
private void Create(string relationName, DataColumn[] parentColumns, DataColumn[] childColumns, bool createConstraints) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<ds.DataRelation.Create|INFO> %d#, relationName='%ls', createConstraints=%d{bool}\n", ObjectID, relationName, createConstraints); try { this.parentKey = new DataKey(parentColumns, true); this.childKey = new DataKey(childColumns, true); if (parentColumns.Length != childColumns.Length) throw ExceptionBuilder.KeyLengthMismatch(); for(int i = 0; i < parentColumns.Length; i++){ if ((parentColumns[i].Table.DataSet == null) || (childColumns[i].Table.DataSet == null)) throw ExceptionBuilder.ParentOrChildColumnsDoNotHaveDataSet(); } CheckState(); this.relationName = (relationName == null ? "" : relationName); this.createConstraints = createConstraints; } finally{ Bid.ScopeLeave(ref hscp); } }
//check to see if this.columns && key2's columns are equal regardless of order internal bool ColumnsEqual(DataKey key) { return(ColumnsEqual(this.columns, ((DataKey)key).columns)); }
internal DataRow FindMergeTarget(DataRow row, DataKey key, Index ndx) { DataRow targetRow = null; // Primary key match if (key.HasValue) { Debug.Assert(ndx != null); int findRecord = (row.oldRecord == -1) ? row.newRecord : row.oldRecord; object[] values = key.GetKeyValues(findRecord); targetRow = FindByIndex(ndx, values); } return targetRow; }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if ((relation.ChildTable.DataSet != this.dataSet) || (relation.ParentTable.DataSet != this.dataSet)) { throw ExceptionBuilder.ForeignRelation(); } relation.CheckState(); if (relation.Nested) { relation.CheckNestedRelations(); } if (relation.relationName.Length == 0) { relation.relationName = base.AssignName(); } else { base.RegisterName(relation.relationName); } DataKey childKey = relation.ChildKey; for (int i = 0; i < this.relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation)this.relations[i]).ChildKey) && relation.ParentKey.ColumnsEqual(((DataRelation)this.relations[i]).ParentKey)) { throw ExceptionBuilder.RelationAlreadyExists(); } } this.relations.Add(relation); ((DataRelationCollection.DataTableRelationCollection)relation.ParentTable.ChildRelations).Add(relation); ((DataRelationCollection.DataTableRelationCollection)relation.ChildTable.ParentRelations).Add(relation); relation.SetDataSet(this.dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(); } ForeignKeyConstraint constraint = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference); if (relation.createConstraints && (constraint == null)) { relation.ChildTable.Constraints.Add(constraint = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference)); try { constraint.ConstraintName = relation.RelationName; } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ExceptionBuilder.TraceExceptionWithoutRethrow(exception); } } UniqueConstraint constraint2 = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference); relation.SetParentKeyConstraint(constraint2); relation.SetChildKeyConstraint(constraint); }
private IndexField [] NewIndexDesc(DataKey key) { Debug.Assert(key.HasValue); IndexField[] indexDesc = key.GetIndexDesc(); IndexField[] newIndexDesc = new IndexField[indexDesc.Length]; Array.Copy(indexDesc, 0, newIndexDesc, 0, indexDesc.Length); return newIndexDesc; }
internal bool Equals(DataKey value) { //check to see if this.columns && key2's columns are equal... DataColumn[] column1 = _columns; DataColumn[] column2 = value._columns; if (column1 == column2) { return true; } else if (column1 == null || column2 == null) { return false; } else if (column1.Length != column2.Length) { return false; } else { for (int i = 0; i < column1.Length; i++) { if (!column1[i].Equals(column2[i])) { return false; } } return true; } }