Changes between Version 2 and Version 3 of FDORfc30


Ignore:
Timestamp:
Nov 19, 2008, 5:46:33 AM (15 years ago)
Author:
brentrobinson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FDORfc30

    v2 v3  
    3838Data value type conversions are not always trivial and the supporting runtime functions sometimes differ between Win32 and Linux (e.g. converting between string and int64). Implementing these conversions in different places leads to the following problems:
    3939
    40ʉۢ there is no consistent handling of type conversions. For example, different parts of FDO might handle overflows (value is not valid for the destination type) differently
    41ʉۢ code duplication. More expensive maintenance if the same fix has to be applied in multiple places (this can easily happen when the type conversion code is cloned to different places)
    42ʉۢ more difficult for developers to find the type conversion functions currently available, since these can be in various places
     40* there is no consistent handling of type conversions. For example, different parts of FDO might handle overflows (value is not valid for the destination type) differently
     41
     42* code duplication. More expensive maintenance if the same fix has to be applied in multiple places (this can easily happen when the type conversion code is cloned to different places)
     43
     44* more difficult for developers to find the type conversion functions currently available, since these can be in various places
    4345
    4446Data values are encapsulated in the FdoDataValue class and its derivations. There is a derivation for each data type supported by FDO. Example data types include various integer types (8bit, 16bit, 32bit, 64bit), string and datetime.
     
    4850It is also possible to convert between various numeric types through simple casting. However, this leads to source code with sizeable switch statements when converting between two arbitrary data types.
    4951
     52== Proposed Solution ==
     53
    5054This RFC proposes that data type conversions be encapsulated in new API functions on the FdoDataValue class.
    5155
    52 
    53 == Proposed Solution ==
    54 
    55 This is a more detailed description of the actual changes desired.  The contents of this section will vary based on the target of the RFC, be it a technical change, website change, or process change.  For example, for a technical change, items such as files, XML schema changes, and API chances would be identified.  For a process change, the new process would be laid out in detail.  For a website change, the files affected would be listed.
     56Direct conversion from a source to a destination type will be supported by adding Create functions to each destination type, which take a value of the source type as a parameter.
     57
     58The following describes the changes to the unmanaged API. However, equivalent changes will also be made to the managed API.
     59
     60=Main Functions=
     61
     62The following functions will be added:
     63
     64{{{FDO_API static FdoDataValue* FdoDataValue::Create(
     65     FdoDataType dataType,
     66     FdoDataValue* src,
     67     FdoBoolean nullIfIncompatible = false,
     68     FdoBoolean shift = true,
     69     FdoBoolean truncate = false
     70);
     71 
     72FDO_API static FdoBooleanValue* FdoBooleanValue::Create(
     73     FdoDataValue* src,
     74     FdoBoolean nullIfIncompatible = false,
     75     FdoBoolean shift = true,
     76     FdoBoolean truncate = false
     77 );
     78 
     79FDO_API static FdoByteValue* FdoByteValue::Create(
     80     FdoDataValue* src,
     81     FdoBoolean nullIfIncompatible = false,
     82     FdoBoolean shift = true,
     83     FdoBoolean truncate = false
     84 );
     85 
     86FDO_API static FdoDecimalValue* FdoDecimalValue::Create(
     87     FdoDataValue* src,
     88     FdoBoolean nullIfIncompatible = false,
     89     FdoBoolean shift = true,
     90     FdoBoolean truncate = false
     91 );
     92 
     93FDO_API static FdoDoubleValue* FdoDoubleValue::Create(
     94     FdoDataValue* src,
     95     FdoBoolean nullIfIncompatible = false,
     96     FdoBoolean shift = true,
     97     FdoBoolean truncate = false
     98 );
     99 
     100FDO_API static FdoInt16Value* FdoInt16Value::Create(
     101     FdoDataValue* src,
     102     FdoBoolean nullIfIncompatible = false,
     103     FdoBoolean shift = true,
     104     FdoBoolean truncate = false
     105 );
     106 
     107FDO_API static FdoInt32Value* FdoInt32Value::Create(
     108     FdoDataValue* src,
     109     FdoBoolean nullIfIncompatible = false,
     110     FdoBoolean shift = true,
     111     FdoBoolean truncate = false
     112 );
     113 
     114FDO_API static FdoInt64Value* FdoInt64Value::Create(
     115     FdoDataValue* src,
     116     FdoBoolean nullIfIncompatible = false,
     117     FdoBoolean shift = true,
     118     FdoBoolean truncate = false
     119 );
     120 
     121FDO_API static FdoSingleValue* FdoSingleValue::Create(
     122     FdoDataValue* src,
     123     FdoBoolean nullIfIncompatible = false,
     124     FdoBoolean shift = true,
     125     FdoBoolean truncate = false
     126 );
     127FDO_API static FdoStringValue* FdoStringValue::Create(
     128     FdoDataValue* src,
     129     FdoBoolean nullIfIncompatible = false,
     130     FdoBoolean shift = true,
     131     FdoBoolean truncate = false
     132 );
     133 
     134FDO_API static FdoCLOBValue* FdoCLOBValue::Create(
     135     FdoDataValue* src,
     136     FdoBoolean nullIfIncompatible = false,
     137     FdoBoolean shift = true,
     138     FdoBoolean truncate = false
     139 );
     140}}}
     141
     142where:
     143
     144dataType – specifies the destination type. This parameter is only specified for FdoDataValue::Create(). For the other functions, the destination type is determined by the return type.
     145
     146src – specifies the source type and value. It is converted to an FdoDataValue of the destination type.
     147
     148nullIfIncompatible – determines what happens if the source and destination types are incompatible (e.g. pass FdoDataTimeValue as src to FdoBoolean::Create()):
     149
     150true: returns a null FdoDataValue (FdoDataValue::IsNull() = true)
     151
     152Note that the pointer returned is not null, the FdoDataValue returned has its null flag set
     153
     154false: throw an exception.
     155
     156shift – determines what happens if conversion would cause the value to change. This can happen when converting between numeric types and the destination type does not have enough precision to hold the value as is (e.g convert 1.9 from Double to Int32 ). Applicable only when both source and destination types are one of Byte, Decimal, Double, Int16, Int32, Int64 or Single:
     157
     158true: shift the value by rounding it to the precision allowed by the destination type
     159false: depends on the value of nullIfIncompatible:
     160
     161true: return a null FdoDataValue (FdoDataValue::IsNull() = true). Note that the pointer returned is not null, the FdoDataValue returned has its null flag set
     162
     163false: throw an exception
     164
     165truncate – determines what happens if the value is outside the valid range for the destination type (e.g. convert 1000000 from FdoInt32Value to FdoInt16Value). Applicable only when both source and destination types are one of Boolean, Byte, Decimal, Double, Int16, Int32, Int64 or Single:
     166
     167true: truncate the value to:
     168
     169the maximum value for the destination type if the input value is greater than the maximum value
     170the minimum value for the destination type if the input value is less than the minimum value
     171
     172false: depends on the value of nullIfIncompatible:
     173
     174true: return a null FdoDataValue (FdoDataValue::IsNull() = true). Note that the pointer returned is not null, the FdoDataValue returned has its null flag set
     175
     176false: throw an exception
     177
     178When the source type is numeric and the destination type is Boolean, the behaviour differs from the above and is as follows:
     179
     180true: convert 0 to false and other values to true
     181false: convert 0 to false and 1 to true. Throw an exception for other values
     182
     183See the chart in the attached document for information on which pairs of types are compatible and which are incompatible.
     184
     185Supporting Functions ¶
     186The following function will be added:
     187
     188FDO_API FdoInt64 FdoStringP::ToInt64()
     189which converts a string to int64 value, and
     190
     191FDO_API FdoStringP::FdoStringP( FdoInt64 value )
     192to convert an int64 to string. These functions hide the Win32 and Linux specific differences in doing these conversions.
     193
     194T
    56195
    57196== Implications ==