Re: Problem with interface C++ for PostgreSQL - Mailing list pgsql-general

From Eric G. Miller
Subject Re: Problem with interface C++ for PostgreSQL
Date
Msg-id 20010321184959.A4409@calico.local
Whole thread Raw
In response to Problem with interface C++ for PostgreSQL  (Renaud Tthonnart <thonnart@amwdb.u-strasbg.fr>)
List pgsql-general
On Wed, Mar 21, 2001 at 03:31:51PM +0100, Renaud Tthonnart wrote:
> Good afernoon everyone
>
> I am developping an interface C++ for a DB PostgreSQL.
> I am using the 'libpq++ ' library to load and save in the base.
>
> Here is my problem :
> to save some data in the base, we have to build a string (here : query)
> for these functions  :
>
> Exec(char *query) or ExecTuplesOk(char* query)
>
> Then, if I want to save an integer in my DB, i have to do this :
>
> sprintf(query,"INSERT INTO myTable VALUES(...,%d,...)",myInt);
> myObject.ExecTupleOk(query);
>
> With integer, it is not so bad, but with float or double, the fact to
> convert data to string is very bad for precision.
>
> Could someone tell me how to avoid using a string to save in the DB

I'm not sure what the C++ equivalent is, but in C the <float.h> header
usually defines the constant DBL_DIG which is the number of significant
digits in a double:

#include <stdio.h>
#include <float.h>

...

printf ("%.*f", DBL_DIG, myDouble);

...


Granted, you may get more digits of precision than really exist this
way, but at least you won't lose any.  PostgreSQL will probably drop
those spurious extra digits anyway (depending on the data type).

--
Eric G. Miller <egm2@jps.net>

pgsql-general by date:

Previous
From: Limin Liu
Date:
Subject: Re: Can I use SPI in postgres.c
Next
From: elwood@agouros.de (Konstantinos Agouros)
Date:
Subject: Updates on Views?