Beispiel #1
0
        private int FindFirstMatchingRecord()
        {
            int rec = -1;
            int lo  = 0;
            int hi  = _index.RecordCount - 1;

            while (lo <= hi)
            {
                int i     = lo + hi >> 1;
                int recNo = _index.GetRecord(i);
                int c     = Evaluate(recNo);
                if (c == 0)
                {
                    rec = i;
                }
                if (c < 0)
                {
                    lo = i + 1;
                }
                else
                {
                    hi = i - 1;
                }
            }
            return(rec);
        }
Beispiel #2
0
        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)]);
        }
Beispiel #3
0
        internal override void CheckConstraint(DataRow row, DataRowAction action)
        {
            if (Table.EnforceConstraints &&
                (action == DataRowAction.Add ||
                 action == DataRowAction.Change ||
                 (action == DataRowAction.Rollback && row.tempRecord != -1)))
            {
                if (row.HaveValuesChanged(Columns))
                {
                    Index    index  = Key.GetSortIndex();
                    object[] values = row.GetColumnValues(Columns);
                    if (index.IsKeyInIndex(values))
                    {
#if DEBUG
                        if (CompModSwitches.Data_Constraints.TraceVerbose)
                        {
                            Debug.WriteLine("UniqueConstraint violation...");
                            string valuesText = "";
                            for (int i = 0; i < values.Length; i++)
                            {
                                valuesText = Convert.ToString(values[i]) + (i < values.Length - 1 ? ", " : "");
                            }
                            Debug.WriteLine("   constraint: " + this.GetDebugString());
                            Debug.WriteLine("   key values: " + valuesText);
                            Range range  = index.FindRecords(values);
                            int   record = index.GetRecord(range.Min);
                            Debug.WriteLine("   conflicting record: " + record.ToString());
                        }
#endif
                        throw ExceptionBuilder.ConstraintViolation(Columns, values);
                    }
                }
            }
        }