Page 1 of 1

Wrong field mapping - Numeric -> Float

Posted: 02.08.2006, 22:15
by thiagothl
I checked the xxxxUtils, especially the Postgres one, and I found that it is treating Numeric and other field types that postgres return as Float, which is wrong. The correct mapping should be BDC or FMTBCD according to the precision and size. (Currency is also an option of the final TField).

I noticed this with some other drivers also, but didn't look deeper. I tried to just change the mapping there but got other errors... like instead getting a TBCDField I got a TIntegerField.... well, it was just a fast try.

Any patchs for this issue? Ideas? I can fix it but would need some guidelines.


regards... and congrats for making the project alive again. I'll be participating now onwards.

Thiago

Posted: 03.08.2006, 08:29
by mdaems
Hi Thiago.

Welcome back.

I suppose you are using the most recent package version from my 'site' or even better : SVN testing branch?

I've noticed some Postgres people around. I hope they react. If not, please correct any errors you find and send us the patch (using user patches forum). I'll apply it asap.

Mark

Posted: 03.08.2006, 17:16
by btrewern
I don't think Zeoslib supports BCD fields for any database. If you look in ZDbcIntfs.pas you'll see:

Code: Select all

  TZSQLType = (stUnknown, stBoolean, stByte, stShort, stInteger, stLong, stFloat,
    stDouble, stBigDecimal, stString, stUnicodeString, stBytes, stDate, stTime,
    stTimestamp, stAsciiStream, stUnicodeStream, stBinaryStream);
I had a quick look and it looks like quite a lot of work to add support for BCD or FMTBCD. I'm off work at the moment and will spend an hour or two looking to see if I can work it out. If anyone else has any ideas then please post them.

Regards,

Ben

Wrong field mapping - Numeric -> Float

Posted: 04.08.2006, 21:37
by thiagothl
This would be the proper behaviour for Postgres Numeric fields, as described in Delphi TBCDField:
... BCD values provide greater precision and accuracy than floating-point numbers. BCD fields are often used for storing and manipulating monetary values.

The IDE uses two different field types for representing BCD fields: TBCDField and TFMTBCDField. TBCDField uses the Currency (Delphi) or System::Currency (C++) type to manipulate BCD values. This is faster than storing and manipulating the value using a true BCD type, but limits the precision of the BCD values it can support to 4 decimal places and 20 significant digits.

TBCDField converts the data from a BCD value to a Currency value when it fetches the data from the database table, and converts it from a Currency value to a binary-coded decimal value when it posts the data. If the underlying database table contains a value that requires greater precision, TBCDField raises an exception. If your application requires BCD values with more than 4 decimal places or 20 significant digits, you should use TFMTBCDField instead. TFMTBCDField is a true BCD, with the precision of the binary-coded decimal type (TBCD) but with somewhat slower performance.
...
Another thing is that the TCurrencyField is not very usefull (as oposite I sugested before), since it is just a subclass of TFloatField which formats the display text, and does not use the actual Currency or BDC types.

We would have to map Numeric Postgres/OtherDBs result fields which have more then 4 decimal places or 20 significant digits as TFMTBCDField. TBCDField otherwise.

As Ben stated the current types in Zeos (TZSQLType) do not allow to fully properly implement it. But we hare already the type stBigDecimal, which may map to ftFMTBCD. The one note there yet is the stDecimal? And then, of course, we need to actually use then.

I'll by trying to figure it out, but since I just got into the SVN, it may take a bit to read the docs and figure out a way to do it without breaking everything (since my flash first try was not effective ;-) ).

I'll be updating any news about this here... if anybody else can help this out also will be great.

Best regards,

Thiago