libpq 7.4 and binary cursor - Mailing list pgsql-interfaces

From Stephane Raimbault
Subject libpq 7.4 and binary cursor
Date
Msg-id 1086877827.4646.22.camel@picasso.lan
Whole thread Raw
Responses Re: libpq 7.4 and binary cursor
Re: libpq 7.4 and binary cursor
List pgsql-interfaces
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





pgsql-interfaces by date:

Previous
From: David Stanaway
Date:
Subject: Re: Problem with PQexecPrepared
Next
From: "Jeroen T. Vermeulen"
Date:
Subject: Re: Problem with PQexecPrepared