Changes between Version 4 and Version 5 of FdoDataValueCompare


Ignore:
Timestamp:
10/19/07 09:30:02 (17 years ago)
Author:
gregboone
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FdoDataValueCompare

    v4 v5  
    77There are a number of places in core FDO and Provider source code where data values are compared, which include but are not limited to:
    88
    9 • in the FdoIInsert and FdoIUpdate implementations of non-RDBMS providers that support Property Value Constraints. When a property has a constraint, each property value being inserted or updated is validated against this constraint.[[br]]
    10 • in the FdoIApplySchema implementation of the SDF Provider. This provider does not allow Value constraints, on Properties with data, to be made more restrictive, since the existing data might violate the updated constraint. Checking whether a range constraint is being made more restrictive, involves the comparing of its old and new range endpoints.[[br]]
     9        • in the FdoIInsert and FdoIUpdate implementations of non-RDBMS providers that support Property Value Constraints. When a property has a constraint, each property value being inserted or updated is validated against this constraint.[[br]]
     10        • in the FdoIApplySchema implementation of the SDF Provider. This provider does not allow Value constraints, on Properties with data, to be made more restrictive, since the existing data might violate the updated constraint. Checking whether a range constraint is being made more restrictive, involves the comparing of its old and new range endpoints.[[br]]
    1111
    1212These data values include property values for features and property constraint values.  Comparing data values is not a trivial operation because of the following:
    1313
    14 • there are 12 different types of data values. The numeric ones can be compared using basic operators ( >, <, ==, etc. ), but runtime functions are required for strings.  For !DateTimes each component ( year, month, etc. ) must be compared.[[br]]
    15 • the data values to be compared might be of different types, meaning that type conversion may need to be done before the values can be compared. Some types are not compatible and cannot be compared.[[br]]
    16 • one or both of the data values may be null. A null value cannot be compared to a not-null value even if both have the same data type.[[br]]
     14        • there are 12 different types of data values. The numeric ones can be compared using basic operators ( >, <, ==, etc. ), but runtime functions are required for strings.  For !DateTimes each component ( year, month, etc. ) must be compared.[[br]]
     15        • the data values to be compared might be of different types, meaning that type conversion may need to be done before the values can be compared. Some types are not compatible and cannot be compared.[[br]]
     16        • one or both of the data values may be null. A null value cannot be compared to a not-null value even if both have the same data type.[[br]]
    1717
    1818Data value comparisons are currently implemented at various other spots in core FDO and the FDO providers. Implementing these conversions at different spots leads to the following problems:
    1919
    20 • there is no consistent handling of type comparisons. For example, different parts of FDO might handle null values differently.[[br]]
    21 • code duplication. More expensive maintenance if the same fix has to be applied in multiple places (this can easily happen when the value comparison code is cloned to different places).[[br]]
    22 • more difficult for developers to find the value comparison functions currently available, since these can be in various places.[[br]]
     20        • there is no consistent handling of type comparisons. For example, different parts of FDO might handle null values differently.[[br]]
     21        • code duplication. More expensive maintenance if the same fix has to be applied in multiple places (this can easily happen when the value comparison code is cloned to different places).[[br]]
     22        • more difficult for developers to find the value comparison functions currently available, since these can be in various places.[[br]]
    2323
    2424Data values are encapsulated in the !FdoDataValue class and its derivations. There is a derivation for each data type supported by FDO. An FDO  data type is a scalar type that commonly occurs in the data sources supported by FDO. Examples include integer (8bit, 16bit, 32bit, 64bit), string and datetime.
     
    2626This document proposes to add a comparison function to !FdoDataValue. The function would take a second data value and return the result of comparing the current value to the second one. There would be 4 different possible results:
    2727
    28 • current value is greater than second value[[br]]
    29 • both values are equal or both null[[br]]
    30 • current value is less than second value[[br]]
    31 • the two values cannot be compared[[br]]
     28        • current value is greater than second value[[br]]
     29        • both values are equal or both null[[br]]
     30        • current value is less than second value[[br]]
     31        • the two values cannot be compared[[br]]
    3232
    3333=== API Changes ===
     
    4444The return values can be one of the following:
    4545
    46 ''!FdoCompareType_Equal'': this and the other value are equal or both null[[br]]
    47 ''!FdoCompareType_Greater'': this value is greater than the other value[[br]]
    48 ''!FdoCompareType_Less'': this value is less than the other value[[br]]
    49 ''!FdoCompareType_Undefined'': these two values are different but cannot be compared.
     46        ''!FdoCompareType_Equal'': this and the other value are equal or both null[[br]]
     47        ''!FdoCompareType_Greater'': this value is greater than the other value[[br]]
     48        ''!FdoCompareType_Less'': this value is less than the other value[[br]]
     49        ''!FdoCompareType_Undefined'': these two values are different but cannot be compared.
    5050
    5151Cases where !FdoCompareType_Undefined happens are:
    5252
    53 • their types are incompatible[[br]]
    54 • one value is null and the other value is not[[br]]
    55 • both values are Boolean and one is true and the other is false[[br]]
     53        • their types are incompatible[[br]]
     54        • one value is null and the other value is not[[br]]
     55        • both values are Boolean and one is true and the other is false[[br]]
    5656
    5757The following enumeration will be added:
    58 
    5958
    6059{{{
     
    8079This section describes how values of each type will be ordered for comparison purposes.
    8180
    82 '''Boolean''': Values will not be ordered. When !FdoBooleanValue::Compare() is passed another !FdoBooleanValue it will return:
     81        ''Boolean'': Values will not be ordered. When !FdoBooleanValue::Compare() is passed another !FdoBooleanValue it will return:
    8382
    84                 ''!FdoCompareType_Equal'' – if they are equal
     83                        ''!FdoCompareType_Equal'' – if they are equal[[br]]
     84                        ''!FdoCompareType_Undefined'' – if they are not equal [[br]]
    8585
    86                 ''!FdoCompareType_Undefined'' – if they are not equal
     86        ''Numeric Types'' ( Byte, Decimal, Double, Int16, Int32, Int64, Single ):  Values will be ordered numerically.
    8787
    88 '''Numeric Types''' ( Byte, Decimal, Double, Int16, Int32, Int64, Single ):  Values will be ordered numerically.
     88        ''!DateTime'': Values will be ordered from earliest to latest.
    8989
    90 '''!DateTime''': Values will be ordered from earliest to latest.
     90        ''String, CLOB'': Values will be ordered lexically. TBD: Should collation be a default binary one or the one for the current locale?
    9191
    92 '''String, CLOB''': Values will be ordered lexically. TBD: Should collation be a default binary one or the one for the current locale?
    93 
    94 '''BLOB''': each pair of bytes from the two values will be compared, starting at the first ones, until the first differing pair of bytes is reached. Comparison will be based on the binary values of these differing bytes. If the end of one BLOB is reached before the other one, the longer BLOB will be considered to be greater than the other BLOB.
     92        ''BLOB'': each pair of bytes from the two values will be compared, starting at the first ones, until the first differing pair of bytes is reached. Comparison will be based on the binary values of these differing bytes. If the end of one BLOB is reached before the other one, the longer BLOB will be considered to be greater than the other BLOB.
    9593
    9694=== Issues ===