Money field problem

Forum related to PostgreSQL

Moderators: gto, cipto_kh, EgonHugeist, olehs

Post Reply
aozbeyaz
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 06.06.2010, 17:53

Money field problem

Post by aozbeyaz »

Hi all,

I am new in forum. I have a question.

I use postgresql for my database application and I use Delphi 7 for programming. In delphi, I use Zeos6.6.6 components to connect to postgresql from delphi.

All values in money fields in postgresql table come to dbgrid as 0(zero) values. Namely, real values in money fields don't come to ZTable or ZQuery as real in Delphi.

if you help me, I will be able to happy.

thanks :)
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

Aparte the fact money field is deprecated, I suppose there are data saved on this field. But are this data different from 0? Becusase I'm trying to insert some data in a money field with pgAdmin,but I can't insert their. Which Postgres version are you using?
aozbeyaz
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 06.06.2010, 17:53

Post by aozbeyaz »

I use Postgresql 8.4
sfxcc
Senior Boarder
Senior Boarder
Posts: 95
Joined: 13.05.2010, 18:48

Post by sfxcc »

Any solution with this , i can add it on pgadmin or even on the grid but it show 0 , which means grid can write but cant read .

Any solution for this ?

This would be good, because on delphi currency calculations have a precision that float doesnt have, when we calc with float the rounds are done with a method that not every time is correct , but with currency is correct.

Why we use a database normaly is only to store data and applications do the calculation ( so float on postgres is error safe but calc are needed on client side not on server side, and is a bit mess to getting all float field and add a mask of 0.00 € manually ) so it shouldnt be deprecaded on zeos.

Thanks
where's the code ..
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

the docs of PG says this type is deprecated. But i've fixed this in branch tsting and my private branch testing-egonhugeist. PG results the regional-currency as prefix like €+2.000,12 which breaks the rules of StrToFloatDef. Problem 1: the prefix. Problem 2 the wrong defined thausends and floating-point operaters.

So can you please test my branch and do some additional bug-reports?

Best regards EgonHugeist
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
sfxcc
Senior Boarder
Senior Boarder
Posts: 95
Joined: 13.05.2010, 18:48

Post by sfxcc »

Where can i get your branch test ?


Why Money a float and not delphi currency ? Being currency is better because several components have already prepared for currency.

Even so float calc have round errors with will cause a huge money deviation on a calc, with a few line it could cause more than 1 euro deviation.

I looking for the code and i dont found where it gets the value from pg and convert it to dataset value, can you send me the filename
where's the code ..
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

sfxcc wrote:Where can i get your branch test ?


Why Money a float and not delphi currency ? Being currency is better because several components have already prepared for currency.
This is a Zeos-Internal function, which works generally with the Extendet-type. So don't worry everything is fine..

You can get thew sources either on http://zeoslib.svn.sourceforge.net/view ... es/testing or
http://zeoslib.svn.sourceforge.net/view ... gonhugeist

for the last one you have to know more about. Look at http://zeos.firmos.at/viewtopic.php?t=3427
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
sfxcc
Senior Boarder
Senior Boarder
Posts: 95
Joined: 13.05.2010, 18:48

Post by sfxcc »

I have done a simple change, try it out it worked because it results R$0,00
so it have R and , not correct it depends on location.

I change a value from a grid to 4,3 (Money on pg ) and it prints out 4,30000019073486

which is that round error i was talking about, can you check this and please change it to currency. it didnt even show the € not round to 2 places etc and the biggest prob is we use money to do calc with it .. is supposed to be the most accuracy or big probs coming out.

Money=ftFloat should be Money = ftCurrency delphi have this currency to avoid miscaculation with usual float error because math processor.
function SQLStrToFloatDef(Str: string; Def: Extended): Extended;
var
{$IFDEF DELPHI12_UP}
OldDecimalSeparator: WideChar;
OldThousandSeparator: WideChar;
{$ELSE}
OldDecimalSeparator: Char;
OldThousandSeparator: Char;
{$ENDIF}
aSymbolPos: Integer;
begin
OldDecimalSeparator := DecimalSeparator;
OldThousandSeparator := ThousandSeparator;
// DecimalSeparator := '.';
// ThousandSeparator := ',';
aSymbolPos := Pos('$', Str);
if aSymbolPos > 0 then
Str := Copy(Str, aSymbolPos+1, Pred(Length(Str)));
If Str = '' then
Result := Def
else
Result := StrToFloatDef(Str, Def);
DecimalSeparator := OldDecimalSeparator;
ThousandSeparator := OldThousandSeparator;
end;
where's the code ..
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Like i wrote you before the patch is done in the testing branches of sf.net. There i've also changed the ftFloat to ftDouble(Extendet-type) because i know about the rounding-problems. You can find the field-arrangements in ZDbcPostrgreUtils.pas...
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply