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. |
| 56 | Direct 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 | |
| 58 | The following describes the changes to the unmanaged API. However, equivalent changes will also be made to the managed API. |
| 59 | |
| 60 | =Main Functions= |
| 61 | |
| 62 | The 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 | |
| 72 | FDO_API static FdoBooleanValue* FdoBooleanValue::Create( |
| 73 | FdoDataValue* src, |
| 74 | FdoBoolean nullIfIncompatible = false, |
| 75 | FdoBoolean shift = true, |
| 76 | FdoBoolean truncate = false |
| 77 | ); |
| 78 | |
| 79 | FDO_API static FdoByteValue* FdoByteValue::Create( |
| 80 | FdoDataValue* src, |
| 81 | FdoBoolean nullIfIncompatible = false, |
| 82 | FdoBoolean shift = true, |
| 83 | FdoBoolean truncate = false |
| 84 | ); |
| 85 | |
| 86 | FDO_API static FdoDecimalValue* FdoDecimalValue::Create( |
| 87 | FdoDataValue* src, |
| 88 | FdoBoolean nullIfIncompatible = false, |
| 89 | FdoBoolean shift = true, |
| 90 | FdoBoolean truncate = false |
| 91 | ); |
| 92 | |
| 93 | FDO_API static FdoDoubleValue* FdoDoubleValue::Create( |
| 94 | FdoDataValue* src, |
| 95 | FdoBoolean nullIfIncompatible = false, |
| 96 | FdoBoolean shift = true, |
| 97 | FdoBoolean truncate = false |
| 98 | ); |
| 99 | |
| 100 | FDO_API static FdoInt16Value* FdoInt16Value::Create( |
| 101 | FdoDataValue* src, |
| 102 | FdoBoolean nullIfIncompatible = false, |
| 103 | FdoBoolean shift = true, |
| 104 | FdoBoolean truncate = false |
| 105 | ); |
| 106 | |
| 107 | FDO_API static FdoInt32Value* FdoInt32Value::Create( |
| 108 | FdoDataValue* src, |
| 109 | FdoBoolean nullIfIncompatible = false, |
| 110 | FdoBoolean shift = true, |
| 111 | FdoBoolean truncate = false |
| 112 | ); |
| 113 | |
| 114 | FDO_API static FdoInt64Value* FdoInt64Value::Create( |
| 115 | FdoDataValue* src, |
| 116 | FdoBoolean nullIfIncompatible = false, |
| 117 | FdoBoolean shift = true, |
| 118 | FdoBoolean truncate = false |
| 119 | ); |
| 120 | |
| 121 | FDO_API static FdoSingleValue* FdoSingleValue::Create( |
| 122 | FdoDataValue* src, |
| 123 | FdoBoolean nullIfIncompatible = false, |
| 124 | FdoBoolean shift = true, |
| 125 | FdoBoolean truncate = false |
| 126 | ); |
| 127 | FDO_API static FdoStringValue* FdoStringValue::Create( |
| 128 | FdoDataValue* src, |
| 129 | FdoBoolean nullIfIncompatible = false, |
| 130 | FdoBoolean shift = true, |
| 131 | FdoBoolean truncate = false |
| 132 | ); |
| 133 | |
| 134 | FDO_API static FdoCLOBValue* FdoCLOBValue::Create( |
| 135 | FdoDataValue* src, |
| 136 | FdoBoolean nullIfIncompatible = false, |
| 137 | FdoBoolean shift = true, |
| 138 | FdoBoolean truncate = false |
| 139 | ); |
| 140 | }}} |
| 141 | |
| 142 | where: |
| 143 | |
| 144 | dataType – 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 | |
| 146 | src – specifies the source type and value. It is converted to an FdoDataValue of the destination type. |
| 147 | |
| 148 | nullIfIncompatible – determines what happens if the source and destination types are incompatible (e.g. pass FdoDataTimeValue as src to FdoBoolean::Create()): |
| 149 | |
| 150 | true: returns a null FdoDataValue (FdoDataValue::IsNull() = true) |
| 151 | |
| 152 | Note that the pointer returned is not null, the FdoDataValue returned has its null flag set |
| 153 | |
| 154 | false: throw an exception. |
| 155 | |
| 156 | shift – 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 | |
| 158 | true: shift the value by rounding it to the precision allowed by the destination type |
| 159 | false: depends on the value of nullIfIncompatible: |
| 160 | |
| 161 | true: return a null FdoDataValue (FdoDataValue::IsNull() = true). Note that the pointer returned is not null, the FdoDataValue returned has its null flag set |
| 162 | |
| 163 | false: throw an exception |
| 164 | |
| 165 | truncate – 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 | |
| 167 | true: truncate the value to: |
| 168 | |
| 169 | the maximum value for the destination type if the input value is greater than the maximum value |
| 170 | the minimum value for the destination type if the input value is less than the minimum value |
| 171 | |
| 172 | false: depends on the value of nullIfIncompatible: |
| 173 | |
| 174 | true: return a null FdoDataValue (FdoDataValue::IsNull() = true). Note that the pointer returned is not null, the FdoDataValue returned has its null flag set |
| 175 | |
| 176 | false: throw an exception |
| 177 | |
| 178 | When the source type is numeric and the destination type is Boolean, the behaviour differs from the above and is as follows: |
| 179 | |
| 180 | true: convert 0 to false and other values to true |
| 181 | false: convert 0 to false and 1 to true. Throw an exception for other values |
| 182 | |
| 183 | See the chart in the attached document for information on which pairs of types are compatible and which are incompatible. |
| 184 | |
| 185 | Supporting Functions ¶ |
| 186 | The following function will be added: |
| 187 | |
| 188 | FDO_API FdoInt64 FdoStringP::ToInt64() |
| 189 | which converts a string to int64 value, and |
| 190 | |
| 191 | FDO_API FdoStringP::FdoStringP( FdoInt64 value ) |
| 192 | to convert an int64 to string. These functions hide the Win32 and Linux specific differences in doing these conversions. |
| 193 | |
| 194 | T |