Search code examples
sql-serverdelphicomidltypelib

How to represent SQL Server type numeric(38,0) as IDL type (COM type library)?


How to represent SQL Server type numeric(38,0) as IDL type (COM type library)?

Thanks a lot for the help!

P.S. For example, SQL Server type int is long type in IDL.


Solution

  • Numbers in COM could be:

    • Integers up to 64 bits (Int64) - so up to 19 significant digits;
    • Floating-point values up to 64 bit (double) - from 15 - 17 significant decimal digits precision.

    So for 38 digits, none of those types would match your request. You can achieve the best resolution with Int64, but if your value is higher than 9,223,372,036,854,775,807, you will reach an overflow.

    I think the easier compliant type is a good old BSTR (widestring), in which you can store as many digit as wished - but encoded as plain text. On the code side, you will need to have a BCD library to process your high-resolution numbers: no Delphi native type (even extended) has such a resolution.

    Edit: Another option (thanks Ondrej for the proposal) is an array of bytes. IMHO a COM binary array is less easy than a text content (and less efficient about speed, even if it uses less memory). Encoding option could be good old BCD. You may be able to find libraries on both sides of the COM object.