wiki:FdoDataValueTypeConversion

Version 2 (modified by gregboone, 17 years ago) ( diff )

--

FDO DataValue Type Conversions

Overview

There are a number of places in core FDO and Provider source code where data values are converted from one type to another. These data values include property values for features and property constraint values. Also, as various FDO client applications are written, some of them may also need to do data type conversion.

One current example is the FdoIDescribeSchema implementation for the RDBMS providers, which extracts check constraints from SQL expressions obtained from the RDBMS, and converts them into FDO Property Value Constraints. These constraints contain data values that represent ranges or lists of allowed values. The data types determined by the expression parser do not always exactly match the data type for the property that owns the constraint. When the types differ, the data values are converted to the property's data type.

Data 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:

  • 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
  • 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)
  • more difficult for developers to find the type conversion functions currently available, since these can be in various places

Data 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.

The FdoDataValue class effectively provides this type conversion now, by supporting the conversion from strings to other data types and vice-versa. For example, a double can be converted to an int32 by converting it to a string and then to an int32. However, providing a more direct conversion, without converting to and from strings, would provide better performance. It also allows very large or small values to be converted more accurately.

It 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 types.

This document looks at encapsulating data type conversions in new API functions on the FdoDataValue class.

API Changes

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.

Main Functions

The following functions will be added:

FDO_API static FdoDataValue* FdoDataValue::Create(
     FdoDataType dataType, 
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false,
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoBooleanValue* FdoBooleanValue::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false,
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoByteValue* FdoByteValue::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoDecimalValue* FdoDecimalValue::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoDoubleValue* FdoDoubleValue::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoInt16Value* FdoInt16Value::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoInt32Value* FdoInt32Value::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoInt64Value* FdoInt64Value::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoSingleValue* FdoSingleValue::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

FDO_API static FdoSingleValue* FdoCLOBValue::Create(
     FdoDataValue* src, 
     FdoBoolean shift = true,
     FdoBoolean truncate = false, 
     FdoBoolean nullIfIncompatible = false
 );

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.