public int Compare(IRow x, IRow y)
 {
     return(_manager.EvaluateSort(_order, x[_order.Column.Name], y[_order.Column.Name]));
 }
Example #2
0
        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);
        }