pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPQgetvalue failed to get non-text data under binary format
2+ messages / 2 participants
[nested] [flat]
* PQgetvalue failed to get non-text data under binary format
@ 2007-05-21 04:33 Y. Ming Lam <ymlam@rogers.com>
2007-05-28 22:39 ` Re: PQgetvalue failed to get non-text data under binary format Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 2+ messages in thread
From: Y. Ming Lam @ 2007-05-21 04:33 UTC (permalink / raw)
To: pgsql-interfaces
Hi,
I am new to PostgreSQL and tried using the libpq C library. I can read
a test table using PQgetvalue for text format, i.e. format = 0.
However, when I experiment with using binary output format, I was unable
to read anything else except result set fiend that is in char(x),
varchar(x), i.e., character string data.
What have I done wrong?
int * pId;
LPSTR pszName;
double * pSalary;
PGresult *pResult = PQexecParams(m_pConn, (LPCTSTR)strSelect, nParams,
parmTypes, paramValues, parmLengths, parmFormats, 1);
pId = (int *)PQgetvalue(pResult, row, 0);
pszName = (LPSTR)PQgetvalue(pResult, row, 1);
pSalary = (double *)PQgetvalue(pResult, row, 6);
printf("id: %d name: %s salary: %f", *pId, pszName, *pSalary);
What I got is as follow:
+ + + printing resultset, 2 rows, 8 columns
id: 167772160 name: Amy Who salary: 0.000000
id: 16777216 name: David Smith salary: 0.000000
Which supposed to return:
id: 10 name: Amy Who salary: 150000.00
id: 1 name: David Smith salary: 350000.00
Any help is greatly appreciated!
Jeff
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: PQgetvalue failed to get non-text data under binary format
2007-05-21 04:33 PQgetvalue failed to get non-text data under binary format Y. Ming Lam <ymlam@rogers.com>
@ 2007-05-28 22:39 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2007-05-28 22:39 UTC (permalink / raw)
To: Y. Ming Lam <ymlam@rogers.com>; +Cc: pgsql-interfaces
On Mon, May 21, 2007 at 12:33:28AM -0400, Y. Ming Lam wrote:
> I am new to PostgreSQL and tried using the libpq C library. I can read
> a test table using PQgetvalue for text format, i.e. format = 0.
> However, when I experiment with using binary output format, I was unable
> to read anything else except result set fiend that is in char(x),
> varchar(x), i.e., character string data.
[...]
> What I got is as follow:
>
> + + + printing resultset, 2 rows, 8 columns
> id: 167772160 name: Amy Who salary: 0.000000
> id: 16777216 name: David Smith salary: 0.000000
>
> Which supposed to return:
> id: 10 name: Amy Who salary: 150000.00
> id: 1 name: David Smith salary: 350000.00
For numeric types you'll need to convert binary values from network
byte order to host byte order (e.g., using ntohl() for 32-bit
values). Notice that 167772160 = 0x0a000000 and 16777216 = 0x01000000,
which are the values you're expecting except for the reversed byte
order.
--
Michael Fuhr
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-05-28 22:39 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-05-21 04:33 PQgetvalue failed to get non-text data under binary format Y. Ming Lam <ymlam@rogers.com>
2007-05-28 22:39 ` Michael Fuhr <mike@fuhr.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox