From Georges.Brefort@sanofi-aventis.com Mon Oct 20 15:18:50 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 73CFC650267 for ; Mon, 20 Oct 2008 12:18:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 86144-06 for ; Mon, 20 Oct 2008 12:18:43 -0300 (ADT) X-Greylist: delayed 00:12:13.901937 by SQLgrey-1.7.6 Received: from gtassmtp01.sanofi-aventis.com (gtassmtp01.sanofi-aventis.com [194.51.237.30]) by postgresql.org (Postfix) with ESMTP id B7EFD64FE29 for ; Mon, 20 Oct 2008 12:18:42 -0300 (ADT) Received: from CLPW90.f2.enterprise ([192.168.202.81]) by gtassmtp01.sanofi-aventis.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 20 Oct 2008 16:54:21 +0200 Received: from CLPW44.f2.enterprise ([192.168.201.102]) by CLPW90.f2.enterprise with Microsoft SMTPSVC(6.0.3790.1830); Mon, 20 Oct 2008 17:06:26 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C932C5.6BE66353" Subject: Retrieving points, arrays, ... with libpq Date: Mon, 20 Oct 2008 17:06:25 +0200 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Retrieving points, arrays, ... with libpq Thread-Index: AckyxWu1BsYlnoTCSY2nlp1wvm9IAw== From: To: X-OriginalArrivalTime: 20 Oct 2008 15:06:26.0130 (UTC) FILETIME=[6C285B20:01C932C5] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200810/10 X-Sequence-Number: 6811 This is a multi-part message in MIME format. ------_=_NextPart_001_01C932C5.6BE66353 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, =20 Sorry to eventually bother you with questions coming from a newcomer to Postgres: I wonder how to retrieve data of such types as Points, enum, arrays (and all those fancy datatypes that have no directly equivalent representation in C) using the libpq library. =20 For example, imagine a table like this one, filed with the relevant information: =20 create type badluck as enum ( 'no more gas', 'flat tire', 'no keys' ); =20 create table myTable( id SERIAL, carStatus badluck, whereIsIt Point [, and other columns] ); =20 I have read the most recent documentation from the first to the very last line, and I guess I can retreive data of any type with the PQgetValue() function, something like:=20 =20 char* chunkOfMemory =3D PQgetvalue( (const PGresult*) myresult, row_number, column_number); =20 But then, is it possible to cast the char* pointer to some meaningfull C structure if column_number relates to some datatype other than text or integer ? =20 For example, with regards to enum values, the documentation states that the length takes 4 bytes and the label at most NAMEDATALEN bytes, so is it equivalent to (or laid out as) something like=20 struct pgenum { unsigned char length[4]; char label[NAMEDATALEN]; }; =20 (This is only one example, I have not been able to find the layout of datatypes like Point and Array). =20 Do you know of any document that describe all those data types in term of the equivalent C structure (if there is any such structure of course). =20 Thank you again for your help and your patience. =20 Georges Brefort =20 ------_=_NextPart_001_01C932C5.6BE66353 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hello,
 
Sorry to=20 eventually bother you with questions coming from a newcomer to Postgres: = I=20 wonder how to retrieve data of such types as Points, enum, arrays (and = all those=20 fancy datatypes that have no directly equivalent representation in C) = using the=20 libpq library.
 
For = example,=20 imagine a table like this one, filed with the relevant=20 information:
 
create type=20 badluck as enum ( 'no more gas', 'flat tire', 'no keys' = );
 
create table=20 myTable(
   =20 id SERIAL,
   =20 carStatus badluck,
   =20 whereIsIt Point [,
   =20 and other columns]
);
   =20
I = have read the=20 most recent documentation from the first to the very last line, and I = guess I=20 can retreive data of any type with the PQgetValue() function,=20  something like:
 
char*=20 chunkOfMemory =3D PQgetvalue( (const PGresult*) myresult, = row_number,=20 column_number);
 
But = then, is=20 it possible to cast the char* pointer to some meaningfull C = structure if=20 column_number relates to some datatype other than text or integer=20 ?
 
For = example, with=20 regards to enum values, the documentation states that the length takes 4 = bytes=20 and the label at most NAMEDATALEN bytes, so is it equivalent to (or laid = out as)=20 something like
struct pgenum=20 {
unsigned char=20 length[4];
char = label[NAMEDATALEN];
};
 
(This is only one=20 example, I have not been able to find the layout of datatypes like = Point=20 and Array).
 
Do = you know of any=20 document that describe all those data types in term of the equivalent C=20 structure (if there is any such structure of = course).
 
Thank you again=20 for your help and your patience.
 
Georges=20 Brefort
 
------_=_NextPart_001_01C932C5.6BE66353-- From jtv@xs4all.nl Wed Oct 22 05:27:46 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B70A064FCE0 for ; Wed, 22 Oct 2008 02:27:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 81067-01 for ; Wed, 22 Oct 2008 02:27:44 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp-vbr14.xs4all.nl (smtp-vbr14.xs4all.nl [194.109.24.34]) by postgresql.org (Postfix) with ESMTP id D76E264FCDA for ; Wed, 22 Oct 2008 02:27:43 -0300 (ADT) Received: from [192.168.1.100] (125.25.93.123.adsl.dynamic.totbb.net [125.25.93.123]) (authenticated bits=0) by smtp-vbr14.xs4all.nl (8.13.8/8.13.8) with ESMTP id m9M5RZI1046048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 22 Oct 2008 07:27:41 +0200 (CEST) (envelope-from jtv@xs4all.nl) Message-ID: <48FEB9C0.7030608@xs4all.nl> Date: Wed, 22 Oct 2008 12:27:28 +0700 From: Jeroen Vermeulen User-Agent: Thunderbird 2.0.0.17 (X11/20080925) MIME-Version: 1.0 To: Georges.Brefort@sanofi-aventis.com CC: pgsql-interfaces@postgresql.org Subject: Re: Retrieving points, arrays, ... with libpq References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200810/11 X-Sequence-Number: 6812 Georges.Brefort@sanofi-aventis.com wrote: > I have read the most recent documentation from the first to the very > last line, and I guess I can retreive data of any type with the > PQgetValue() function, something like: > > char* chunkOfMemory = PQgetvalue( (const PGresult*) myresult, > row_number, column_number); > > But then, is it possible to cast the char* pointer to some meaningfull C > structure if column_number relates to some datatype other than text or > integer ? By default, you get your data in a textual representation. So you need to parse the string that that char* points to. (It's also possible to work in binary mode, but then you've got a lot more worries about portability and such for not much gain in speed.) Jeroen