Re: what is the date format in binary query results

From: Andrew Chernow <andrew(at)esilo(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Samantha Atkins <sjatkins(at)mac(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: what is the date format in binary query results
Date: 2007-12-13 02:38:41
Message-ID: 47609B31.3080700@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Merlin Moncure wrote:
> On Dec 12, 2007 2:14 AM, Samantha Atkins <sjatkins(at)mac(dot)com> wrote:
>> This brings up a second question. How should I do byte order
>> conversion for 8 byte ints? I can't use hton ntoh routines as they
>> max out at 32 bits. Is there a better way? Also, are floating point
>> numbers guaranteed uniform?
>>
>> If any one knows a a clean code example of binary binding of
>> parameters and binary extraction of results for all major types in C
>> against lippq that would be a very useful thing to have in the
>> standard docs.
>
> We are working on a patch (not necessarily to be migrated with the
> source code) to allow simplified binding of binary types to native C
> types. You can see an older version here: it has examples how to read
> off a lot of the types in binary. We should have a new patch in a day
> or two that should demonstrate how to read the rest of the types in
> binary. We also handled 64 bit ints...
>
> the patch is here
> http://archives.postgresql.org/pgsql-patches/2007-12/msg00014.php
>
> if you are patient we can provide examples for all the basic built in
> types, including possibly arrays...
>
> merlin
>
> p.s don't top post, but I dig Ron Paul :-)
>
>

This is from the patch merlin mentioned.

static unsigned int *swap8(void *outp, void *inp, int tonet)
{
static int n = 1;
unsigned int *in = (unsigned int *)inp;
unsigned int *out = (unsigned int *)outp;

/* swap when needed */
if(*(char *)&n == 1)
{
out[0] = (unsigned int)(tonet ? htonl(in[1]) : ntohl(in[1]));
out[1] = (unsigned int)(tonet ? htonl(in[0]) : ntohl(in[0]));
}
else
{
out[0] = in[0];
out[1] = in[1];
}

return out;
}

// example
if(PQfformat(res, field_num) == 1)
{
long long n;
swap8(&n, PQgetvalue(res, 0, 0), 0);
printf("%lld\n", n);
}

andrew

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Chernow 2007-12-13 02:41:37 Re: what is the date format in binary query results
Previous Message Merlin Moncure 2007-12-13 02:08:31 Re: what is the date format in binary query results