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

From Brian Kurt Fujikawa
Subject Re: Problem with interface C++ for PostgreSQL
Date
Msg-id 3AB9465E.FCCB0E69@lbl.gov
Whole thread Raw
In response to Problem with interface C++ for PostgreSQL  (Renaud Tthonnart <thonnart@amwdb.u-strasbg.fr>)
List pgsql-general
Hi Renaud

I sent the same question to the list a few weeks ago, but I didn't get
any response. If you find out how to avoid using strings, please email
me. Thanks.

By the way, here's an ugly way to get full precision (e.g. for a double)
when building a query:

...

#include <float.h>
#include <string.h>

...

char fmt[10];
sprintf(fmt,"%c%d.%dg\0",'%',DBL_DIG+8,DBL_DIG);

...

long index=strlen(query);
sprintf(query+index,fmt,double_value);

...

Best Regards

Brian

Renaud Tthonnart wrote:
>
> Subject: Problem with interface C++ for PostgreSQL
> Date: Wed, 21 Mar 2001 15:31:51 +0100
> From: Renaud Tthonnart <thonnart@amwdb.u-strasbg.fr>
> To: "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
>
> 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
>
> Thank you all
> regards, Renaud THONNART
>

--
Brian Kurt Fujikawa
Weak Interactions Group
Institute for Nuclear and Particle Astrophysics
Lawrence Berkeley National Laboratory
1 Cyclotron Road, MS 50-208
Berkeley, CA 94720, USA
http://bkf0.lbl.gov/fujikawa/
mailto:bkfujikawa@lbl.gov
tel: +1-510-486-4398
fax: +1-510-486-6738

pgsql-general by date:

Previous
From: Ned Lilly
Date:
Subject: Re: Re: hang on (was: New Book: PostgreSQL: The ElephantNever Forgets)
Next
From: 100.179370@germanynet.de (Martin Jacobs)
Date:
Subject: Re: