Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-interfaces by date

Next:From: Jeroen T. VermeulenDate: 2004-06-10 14:56:29
Subject: Re: Problem with PQexecPrepared
Previous:From: David StanawayDate: 2004-06-10 06:37:52
Subject: Re: Problem with PQexecPrepared

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group