Re: C++: get value for integral types? - Mailing list pgsql-general
From | Vassil Kriakov |
---|---|
Subject | Re: C++: get value for integral types? |
Date | |
Msg-id | 20021111194409.17058.qmail@web13906.mail.yahoo.com Whole thread Raw |
In response to | Re: C++: get value for integral types? (Tommi Maekitalo <t.maekitalo@epgmbh.de>) |
Responses |
Re: C++: get value for integral types?
|
List | pgsql-general |
Exactly, It makes me very uneasy doing a (int *) on char* PQgetvalue(...) just because i EXPECT it to give me an int type. And of course the question of user-defined types!? Using C++ templates (template specialization, to be precise), it would be possible to get any kind of type, system-independent, from the database (as done in libpqxx). However, I have yet to see how they do the actual conversion since pqxx itself is, naturally, based on libpq. -- vassil --- Tommi Maekitalo <t.maekitalo@epgmbh.de> wrote: > Hi, > > it would be hard to interpret the binary value. I think it is not > specified, > how a specific type is represented as a binary value. The programmers > guide > just tells: "But if PQbinaryTuples() is 1, the value returned by > PQgetvalue > is the binary representation of the type in the internal format of > the > backend server". So its internal and platformspecific. It is even > hard to get > usable type-information. The types are defined in a systemtable > (pg_type). > But new types are created in some situations, when you just create a > new > table. > > I think the safest way to retrieve values in C++ is to convert the > stringrepresentation. > > It might be helpful to define some api-functions to retrieve some > integral > types (PGgetLong, PGgetDouble). The backendprocess knows better about > > datatypes. What do you think? > > > Tommi > > Am Sonntag, 10. November 2002 23:56 schrieb Frank Miles: > > On Sun, 10 Nov 2002, Vassil Kriakov wrote: > > > Does anyone know whether it is possible to get a tuple's value as > an > > > int, float, bool, etc. using the C++ postgresql library? > > > > > > Getting floats as string representations (via char* > GetValue(...)) of > > > the value is not acceptable! Using strings and streams to convert > the > > > values to the corresponding integral type may cause problems! > > > > > > Any ideas, workarounds? Is BinaryTuples really not implemnted > yet? > > > > Doesn't the C++ version work? Have you DECLAREd a binary cursor > and > > used FETCH to get the data? (It works with libpq) > > > > HTH-- > > > > -frank > > > > > > ---------------------------(end of > broadcast)--------------------------- > > TIP 2: you can get off all lists at once with the unregister > command > > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) > > -- > Dr. Eckhardt + Partner GmbH > http://www.epgmbh.de > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) __________________________________________________ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2
pgsql-general by date: