From: Stephane Raimbault <stephane.raimbault@free.fr>
To: pgsql-interfaces@postgresql.org
Subject: libpq 7.4 and binary cursor
Date: Thu, 10 Jun 2004 16:30:27 +0200
Message-ID: <1086877827.4646.22.camel@picasso.lan> (raw)
Hi,
It seems some changes occured in network protocol between 7.3 and 7.4.
In my simple libray above libpq, I used this call to extract float8 with
a binary cursor (on x86) :
-----------------------------------------------
memcpy(&float8,
PQgetvalue(pg_res, tup_num, field_num),
PQfsize(pg_res, field_num));
-----------------------------------------------
Now with PostgreSQL 7.4, I replaced this memcpy by theses lines :
-----------------------------------------------
union {
double d;
int64_t i64;
} swap;
uint32_t tab_uint32[2];
/* Read two uint32 */
memcpy(tab_uint32, PQgetvalue(pg_res, tup_num, field_num), 8);
/* Swap MSB -> LSB */
tab_uint32[0] = ntohl(tab_uint32[0]);
tab_uint32[1] = ntohl(tab_uint32[1]);
/* Fusion */
swap.i64 = tab_uint32[0];
swap.i64 <<= 32;
swap.i64 |= tab_uint32[1];
/* Cast */
return swap.d;
------------------------------------------------
Is it the right method to extract binary data ? Don't exist a easiest
method ?
Thank you.
Stephane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: stephane.raimbault@free.fr
Subject: Re: libpq 7.4 and binary cursor
In-Reply-To: <1086877827.4646.22.camel@picasso.lan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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