Re: How To Get Numetic Value!!! using C ??? - Mailing list pgsql-general

From Mike Mascari
Subject Re: How To Get Numetic Value!!! using C ???
Date
Msg-id 3DE287FB.1070500@mascari.com
Whole thread Raw
In response to How To Get Numetic Value!!! using C ???  (Oleg Shalnev <ovs@megalog.ru>)
List pgsql-general
Oleg Shalnev wrote:
> Hi All!
>
>
> I want to GetValue numeric type from binary cursor, but I have no ideas
> how to do it.
> Now I am using
>
> double test;
> test=atof((char*)GetValue(0,0));
> in C function and doing
> to_char(my_numeric_field, '9999999999999D99')
> in database selection.
> May be there is another normal way to do it.
>
> Thanks a lot!!!
> Oleg Shalnev

First, I'd not use binary cursors because:

1) I have no clue regarding the binary representation of Numeric
2) Byte-ordering can differ if the client and server platforms
are different

I'm surprised the above works at all with a binary cursor.
Assuming a text cursor, I think you need some additional C/C++
library which has:

1) support for ASCII to fixed-point conversion
2) support for fixed-point to ASCII conversion
3) fixed-point operations

My clients are CORBA-based C++, which has a "Fixed" class
supplied by the vendor to handle the above. Java, likewise, has
BigDecimal. You might want to do a search for "arbitrary
precision library C". A quick search included this:

http://www.swox.com/gmp/#DOC

which appears to do what you need to do on the client, and a
whole lot more...

How that helps,

Mike Mascari
mascarm@mascari.com






pgsql-general by date:

Previous
From: Peter Childs
Date:
Subject: What are my foreign Keys?
Next
From: Robert Treat
Date:
Subject: Re: caveats upgrading from 7.0.3 to 7.2.x