Re: Problem with interface C++ for PostgreSQL
От | Renaud Tthonnart |
---|---|
Тема | Re: Problem with interface C++ for PostgreSQL |
Дата | |
Msg-id | 3AB9D957.DC0DC794@amwdb.u-strasbg.fr обсуждение исходный текст |
Ответ на | Problem with interface C++ for PostgreSQL (Renaud Tthonnart <thonnart@amwdb.u-strasbg.fr>) |
Список | pgsql-general |
Thank you for your advice, Eric Renaud THONNART "Eric G. Miller" wrote: > 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 по дате отправления: