/// <summary>Disposes the given native value.</summary> public static void DisposeNative(IValueManager manager, Schema.IDataType dataType, object tempValue) { if (tempValue == null) { return; } Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { if (tempValue is StreamID) { manager.StreamManager.Deallocate((StreamID)tempValue); } if (scalarType.IsCompound) { DisposeNative(manager, scalarType.CompoundRowType, tempValue); } return; } using (IDataValue dataValue = DataValue.FromNative(manager, dataType, tempValue)) { dataValue.ValuesOwned = true; } }
internal IValueManager _manager; // Only used during the Add and Remove calls public bool CompareEqual(IValueManager manager, NativeRow indexKey, NativeRow compareKey) { // If AIndexKeyRowType is null, the index key must have the structure of an index key, // Otherwise, the IndexKey row could be a subset of the actual index key. // In that case, AIndexKeyRowType is the RowType for the IndexKey row. // It is the caller's responsibility to ensure that the passed IndexKey RowType // is a subset of the actual IndexKey with order intact. //Row LIndexKey = new Row(AManager, AIndexKeyRowType, AIndexKey); // If ACompareContext is null, the compare key must have the structure of an index key, // Otherwise the CompareKey could be a subset of the actual index key. // In that case, ACompareContext is the RowType for the CompareKey row. // It is the caller's responsibility to ensure that the passed CompareKey RowType // is a subset of the IndexKey with order intact. //Row LCompareKey = new Row(AManager, ACompareKeyRowType, ACompareKey); for (int index = 0; index < _keyRowType.Columns.Count; index++) { if (index >= compareKey.Values.Count()) { return(false); } if ((indexKey.Values[index] != null) && (compareKey.Values[index] != null)) { if (_keyRowType.Columns[index].DataType is Schema.ScalarType) { if (!manager.EvaluateEqualitySort(GetEqualitySort(Key.Columns[index].Name), indexKey.Values[index], compareKey.Values[index])) { return(false); } } else { using (var indexValue = DataValue.FromNative(manager, indexKey.DataTypes[index], indexKey.Values[index])) { using (var compareValue = DataValue.FromNative(manager, compareKey.DataTypes[index], compareKey.Values[index])) { if (!manager.EvaluateEqualitySort(GetEqualitySort(Key.Columns[index].Name), indexValue, compareValue)) { return(false); } } } } } else if (indexKey.Values[index] != null) { return(false); } else if (compareKey.Values[index] != null) { return(false); } } return(true); }
private IDataValue _writeValue; // saves the row instantiated to write the compound value if this is a compound scalar public override int GetPhysicalSize(bool expandStreams) { int size = 1; // Scalar header if (!IsNil) { if (IsNative) { if (DataType.IsCompound) { _writeValue = DataValue.FromNative(Manager, DataType.CompoundRowType, Value); return(size + _writeValue.GetPhysicalSize(expandStreams)); } else { Streams.IConveyor conveyor = Manager.GetConveyor(DataType); if (conveyor.IsStreaming) { _writeStream = new MemoryStream(64); conveyor.Write(Value, _writeStream); return(size + (int)_writeStream.Length); } return(size + conveyor.GetSize(Value)); } } if (expandStreams) { _writeStream = Manager.StreamManager.Open(StreamID, LockMode.Exclusive); return(size + (int)_writeStream.Length); } return(size + StreamID.CSizeOf); } return(size); }
public int Compare(IValueManager manager, Schema.IRowType indexKeyRowType, NativeRow indexKey, Schema.IRowType compareKeyRowType, NativeRow compareKey) { // If AIndexKeyRowType is null, the index key must have the structure of an index key, // Otherwise, the IndexKey row could be a subset of the actual index key. // In that case, AIndexKeyRowType is the RowType for the IndexKey row. // It is the caller's responsibility to ensure that the passed IndexKey RowType // is a subset of the actual IndexKey with order intact. //Row LIndexKey = new Row(AManager, AIndexKeyRowType, AIndexKey); // If ACompareContext is null, the compare key must have the structure of an index key, // Otherwise the CompareKey could be a subset of the actual index key. // In that case, ACompareContext is the RowType for the CompareKey row. // It is the caller's responsibility to ensure that the passed CompareKey RowType // is a subset of the IndexKey with order intact. //Row LCompareKey = new Row(AManager, ACompareKeyRowType, ACompareKey); int result = 0; for (int index = 0; index < indexKeyRowType.Columns.Count; index++) { if (index >= compareKeyRowType.Columns.Count) { break; } if ((indexKey.Values[index] != null) && (compareKey.Values[index] != null)) { if (indexKeyRowType.Columns[index].DataType is Schema.ScalarType) { result = manager.EvaluateSort(Key.Columns[index], indexKey.Values[index], compareKey.Values[index]); } else { using (var indexValue = DataValue.FromNative(manager, indexKey.DataTypes[index], indexKey.Values[index])) { using (var compareValue = DataValue.FromNative(manager, compareKey.DataTypes[index], compareKey.Values[index])) { result = manager.EvaluateSort(Key.Columns[index], indexValue, compareValue); } } } } else if (indexKey.Values[index] != null) { result = Key.Columns[index].Ascending ? 1 : -1; } else if (compareKey.Values[index] != null) { result = Key.Columns[index].Ascending ? -1 : 1; } else { result = 0; } if (result != 0) { break; } } //LIndexKey.Dispose(); //LCompareKey.Dispose(); return(result); }