Re: C++: get value for integral types?

From: Vassil Kriakov <vassilk(at)yahoo(dot)com>
To: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: C++: get value for integral types?
Date: 2002-11-11 19:44:09
Message-ID: 20021111194409.17058.qmail@web13906.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)maekitalo(at)epgmbh(dot)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(at)postgresql(dot)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(at)postgresql(dot)org)

__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Luc Lachance 2002-11-11 19:50:05 Re: Win2K Questions
Previous Message Josh Berkus 2002-11-11 19:17:27 Re: Hardware estimation