Re: Problem with interface C++ for PostgreSQL

From: Brian Kurt Fujikawa <bkfujikawa(at)lbl(dot)gov>
To: thonnart(at)amwdb(dot)u-strasbg(dot)fr
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with interface C++ for PostgreSQL
Date: 2001-03-22 00:25:02
Message-ID: 3AB9465E.FCCB0E69@lbl.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)amwdb(dot)u-strasbg(dot)fr>
> To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)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(at)lbl(dot)gov
tel: +1-510-486-4398
fax: +1-510-486-6738

Browse pgsql-general by date

  From Date Subject
Next Message Franck Martin 2001-03-22 00:31:03 Re: Call for platforms (linux 2.4.x ?)
Previous Message Ned Lilly 2001-03-22 00:18:30 Re: Re: hang on (was: New Book: PostgreSQL: The ElephantNever Forgets)