From: | "Billy G(dot) Allie" <bga(at)mug(dot)org> |
---|---|
To: | "Jordi" <jordil2(at)hotmail(dot)com> |
Cc: | pgsql-interfaces(at)postgresql(dot)org, bga(at)mug(dot)org |
Subject: | Re: PQgetvalue and User defined types/Arrays fields |
Date: | 2001-08-29 01:50:48 |
Message-ID: | 200108290150.f7T1omU09085@bajor.mug.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
"Jordi" wrote:
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0011_01C1265A.0C3D9880
> Content-Type: text/plain; charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> Hi everybody,
>
> I'm using Postgresql 7.03 (but I'm going to migrate soon to 7.1) and I have=
> a big doubt about how to work with User defined types in my tables using l=
> ibpq and the documentation does not help at all.
>
> Anyone have any sample about how to use libpq with PQGetValue or similar to=
> read records which have fields defined as Arrays or User defined types?. =
> I looked for samples in the documentation or in the mailing list but I coul=
> dn't find anything.=20=20=20
>
> For example, if I define the user-defined type "complex" just like in http:=
> //www.postgresql.org/idocs/index.php?xtypes.html#XTYPES-USERDEFINED and the=
> n I use it in a table, how can I read the field?. Must I use the complex_in=
> (char *str) function passing as a parameter the PQGetValue result associate=
> d to this field number?. I have the same doubt when I define an array fiel=
> d.
>
> By the way, do you know if there is any documentation/sample about libpq ex=
> plaining these more advanced topics which are not fully explained in the ge=
> neral documentation?
>
> Best regards and thanks in advance,
>
> Jordi
Basicly, everything returned by PQGetValue is a string representation of the data (ignoring binary cursors for the moment). If you application wants to use an internal representation of the data, you will have to parse/convert the string (eg. strtol() for int2 and int4, strtoll() for int8, etc.). As an example, you can get the source for my PostgreSQL/Python interface (pyPgSQL) which contains code for converting PQgetvalue() results into Python Objects. Currently, the only types that are converted are INT2, INT8, BOOL, date/time types, NUMERIC, MONEY, and arrays of these types. All other types are left as strings. This code may provide some useful examples. In particular, look at pgresult.c and PgSQL.py.
--
____ | Billy G. Allie | Domain....: Bill(dot)Allie(at)mug(dot)org
| /| | 7436 Hartwell | MSN.......: B_G_Allie(at)email(dot)msn(dot)com
|-/-|----- | Dearborn, MI 48126|
|/ |LLIE | (313) 582-1540 |
From | Date | Subject | |
---|---|---|---|
Next Message | Marc G. Fournier | 2001-08-29 15:00:38 | List archives moved and cleaned up ... |
Previous Message | Bruce Momjian | 2001-08-28 16:34:16 | Re: libpq++ current sources don't compile with older C++ compilers |