Re: PQgetvalue and User defined types/Arrays fields
От | Billy G. Allie |
---|---|
Тема | Re: PQgetvalue and User defined types/Arrays fields |
Дата | |
Msg-id | 200108290150.f7T1omU09085@bajor.mug.org обсуждение исходный текст |
Ответ на | PQgetvalue and User defined types/Arrays fields ("Jordi" <jordil2@hotmail.com>) |
Список | 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/Pythoninterface (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.cand PgSQL.py. -- ____ | Billy G. Allie | Domain....: Bill.Allie@mug.org | /| | 7436 Hartwell | MSN.......: B_G_Allie@email.msn.com |-/-|----- | Dearborn, MI 48126| |/ |LLIE | (313) 582-1540 |
В списке pgsql-interfaces по дате отправления: