CompareValueTo() private method

private CompareValueTo ( int record1, object value, bool checkType ) : bool
record1 int
value object
checkType bool
return bool
Exemplo n.º 1
0
        private int FindNodeByKey(object?originalKey)
        {
            int x, c;

            if (_indexFields.Length != 1)
            {
                throw ExceptionBuilder.IndexKeyLength(_indexFields.Length, 1);
            }

            x = _records.root;
            if (IndexTree.NIL != x)
            {
                // otherwise storage may not exist
                DataColumn column = _indexFields[0].Column;
                object?    key    = column.ConvertValue(originalKey);

                x = _records.root;
                if (_indexFields[0].IsDescending)
                {
                    while (IndexTree.NIL != x)
                    {
                        c = column.CompareValueTo(_records.Key(x), key);
                        if (c == 0)
                        {
                            break;
                        }
                        if (c < 0)
                        {
                            x = _records.Left(x);
                        }                                    // < for decsending
                        else
                        {
                            x = _records.Right(x);
                        }
                    }
                }
                else
                {
                    while (IndexTree.NIL != x)
                    {
                        c = column.CompareValueTo(_records.Key(x), key);
                        if (c == 0)
                        {
                            break;
                        }
                        if (c > 0)
                        {
                            x = _records.Left(x);
                        }                                    // > for ascending
                        else
                        {
                            x = _records.Right(x);
                        }
                    }
                }
            }
            return(x);
        }
Exemplo n.º 2
0
 private int FindNodeByKey(object originalKey)
 {
     if (this.IndexFields.Length != 1)
     {
         throw ExceptionBuilder.IndexKeyLength(this.IndexFields.Length, 1);
     }
     int root = this.records.root;
     if (root != 0)
     {
         int num2;
         DataColumn column = this.IndexFields[0].Column;
         object obj2 = column.ConvertValue(originalKey);
         root = this.records.root;
         if (!this.IndexFields[0].IsDescending)
         {
             while (root != 0)
             {
                 num2 = column.CompareValueTo(this.records.Key(root), obj2);
                 if (num2 == 0)
                 {
                     return root;
                 }
                 if (num2 > 0)
                 {
                     root = this.records.Left(root);
                 }
                 else
                 {
                     root = this.records.Right(root);
                 }
             }
             return root;
         }
         while (root != 0)
         {
             num2 = column.CompareValueTo(this.records.Key(root), obj2);
             if (num2 == 0)
             {
                 return root;
             }
             if (num2 < 0)
             {
                 root = this.records.Left(root);
             }
             else
             {
                 root = this.records.Right(root);
             }
         }
     }
     return root;
 }
Exemplo n.º 3
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.º 4
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.º 5
0
        internal void SilentlySetValue(DataRow dr, DataColumn dc, DataRowVersion version, object newValue) {
            // get record for version
            int record = dr.GetRecordFromVersion(version);

            bool equalValues = false;
            if (DataStorage.IsTypeCustomType(dc.DataType) && newValue != dc[record]) {
                // if UDT storage, need to check if reference changed. See bug 385182
                equalValues = false;
            }
            else {
                equalValues = dc.CompareValueTo(record, newValue, true);
            }

            // if expression has changed
            if (!equalValues) {
                int[] oldIndex = dr.Table.RemoveRecordFromIndexes(dr, version);// conditional, if it exists it will try to remove with no event fired
                dc.SetValue(record, newValue);
                int[] newIndex = dr.Table.InsertRecordToIndexes(dr, version);// conditional, it will insert if it qualifies, no event will be fired
                if (dr.HasVersion(version)) {
                    if (version != DataRowVersion.Original) {
                        dr.Table.RecordChanged(oldIndex, newIndex);
                    }
                    if (dc.dependentColumns != null) {
                        //BugBug - passing in null for cachedRows.  This means expression columns as keys does not work when key changes.
                        dc.Table.EvaluateDependentExpressions(dc.dependentColumns, dr, version, null);
                    }
                }
             }
             dr.ResetLastChangedColumn();
        }
 internal void SilentlySetValue(DataRow dr, DataColumn dc, DataRowVersion version, object newValue)
 {
     int recordFromVersion = dr.GetRecordFromVersion(version);
     bool flag = false;
     if (DataStorage.IsTypeCustomType(dc.DataType) && (newValue != dc[recordFromVersion]))
     {
         flag = false;
     }
     else
     {
         flag = dc.CompareValueTo(recordFromVersion, newValue, true);
     }
     if (!flag)
     {
         int[] oldIndex = dr.Table.RemoveRecordFromIndexes(dr, version);
         dc.SetValue(recordFromVersion, newValue);
         int[] newIndex = dr.Table.InsertRecordToIndexes(dr, version);
         if (dr.HasVersion(version))
         {
             if (version != DataRowVersion.Original)
             {
                 dr.Table.RecordChanged(oldIndex, newIndex);
             }
             if (dc.dependentColumns != null)
             {
                 dc.Table.EvaluateDependentExpressions(dc.dependentColumns, dr, version, null);
             }
         }
     }
     dr.ResetLastChangedColumn();
 }