agora inbox for pgsql-interfaces@postgresql.org  
help / color / mirror / Atom feed
From: Thilo Rießner <thilo@riessner.de>
To: pgsql-interfaces@postgresql.org
Subject: Re: libpq binary data
Date: Thu, 02 Oct 2014 13:43:49 +0200
Message-ID: <1592919.kcsFzWfsGI@thilo.site> (raw)
In-Reply-To: <3808965.tNLrlL6qTR@thilo.site>
References: <3808965.tNLrlL6qTR@thilo.site>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-interfaces>

Hello again,
after trying the PQftype function on the date row, I realized, that the type 
is 701 which is a double. Treating the pointer as a double solved my problem, 
now I get the right number of seconds. But it is still necessary to swap the 
byte order from network to host with the function "ntohll" as shown below.
Hope this helps someone stucking in a similar problem.

Thilo

> Hello,
> I try to get the epoch value of a date via the
> PQexecParams(conn, "SELECT extract(epoch from date + time) as epoch, content
> FROM daten .....);
> In that database, the timestamp ist stored in the two fields date and time.
> I want to get this data in binary form. The
> PQfsize(res, 1);
> tells me, that the size of the returned data is 8 byte (in contrast to the
> standard size of epoch, which is meant to be 4 byte)
> I don't manage to get the epoch valule (seconds since 1970) from that
> returned value. After ntohll (which I wrote as a wrapper around ntohl for
> long int, see below) it is a very huge value (4743709917079142400) but it
> should be 1412179252 as I get it from the psql interface, when I type in
> the same command.
> What am I missing or doing wrong?
> Thanks for any help in advance
> 
> Thilo
> 
> unsigned long int ntohll(long int x)
> {
> 	if (ntohl(1) == 1)
> 		return x;
> 	else
> 		return (long int) (ntohl((int)((x << 32) >> 32))) << 32 | (long
> int)ntohl(((int)(x >> 32)));
> }



-- 
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces



view thread (3+ messages)

Message-ID: <1592919.kcsFzWfsGI@thilo.site>
Permalink:  ../1592919.kcsFzWfsGI@thilo.site/
Also on:    postgresql.org/message-id/1592919.kcsFzWfsGI@thilo.site

reply

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: thilo@riessner.de
  Subject: Re: libpq binary data
  In-Reply-To: <1592919.kcsFzWfsGI@thilo.site>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox