Numeric types


In our PostgreSQL-database there are several fields defined as NUMERIC.
For example NUMERIC(38,0)
In FireDac and UniDac this is mapped to an integer.

In the Data Abstract schema modeler such fields are defined as DataType Decimal with precision/scale 38/0
When I inspect the NewValue of such fields in TDADeltaChange, the value is stored as a variant array of byte.

Is it possible to map such fields to integer and fields with scale > 0 as a double for instance ?



we treat such fields as integers if they can be put to it:

    else if (aDataType = 'decimal') or (aDataType = 'numeric') then begin
      if (ADecScale = 0) and (ADecPrec < 19) then begin
        case ADecPrec of
          0:    result := datFloat;
          1,2:  result := datShortInt;
          3,4:  result := datSmallInt;
          5..9: result := datInteger;
          result := datLargeInt;
        result := datDecimal

but in your case, we can’t guarantee that data won’t be lost so we use Decimal.

we have these methods in uROBinaryHelpers unit that work with Decimal:

function BCDToDecimal(const aBcd: TBcd): TDecimal;
function DecimalToBCD(const aDecimal: TDecimal): TBcd;
function DecimalToString(const aDecimal: TDecimal; aDot: Char): string;
function StringToDecimal(const aString: string; aDot: Char): TDecimal;
function DecimalToVariant(const aDecimal: TDecimal): Variant;
function VariantToDecimal(const aVariant: Variant): TDecimal;
function VariantToBCD(const aVariant: Variant): TBCD;
function BCDToVariant(const aBCD: TBCD; const StoreAsDecimal: Boolean = False): Variant;
// correctly convert DecimalVariant into string
function DecimalVariantToString(const aVariant: Variant): string;
{ ToDo: extend this to handle all common Variant types, and use it for
        marshaling OwnerData, instead of string. }

in your case, I can suggest to use something like

integer_value := BcdToInteger(VariantToBCD(field.value));
currency_value := BcdToCurr(VariantToBCD(field.value));
float_value := BcdToDouble(VariantToBCD(field.value));
string_value := DecimalVariantToString(field.value);

Edit: if you change declaration of such fields in schema as Integer and Float, these fields will be as you defined them