libpq 7.4 and binary cursor

From: Stephane Raimbault <stephane(dot)raimbault(at)free(dot)fr>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: libpq 7.4 and binary cursor
Date: 2004-06-10 14:30:27
Message-ID: 1086877827.4646.22.camel@picasso.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jeroen T. Vermeulen 2004-06-10 14:56:29 Re: Problem with PQexecPrepared
Previous Message David Stanaway 2004-06-10 06:37:52 Re: Problem with PQexecPrepared