pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: bartsmink@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
Date: Sat, 12 Oct 2019 15:17:12 +0100
Message-ID: <87mue6xdf1.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <16051-cf9069d07dd1df16@postgresql.org>
References: <16051-cf9069d07dd1df16@postgresql.org>

>>>>> "PG" == PG Bug reporting form <noreply@postgresql.org> writes:

 PG>         res = PQexecParams(conn, 
 PG>         "SELECT * FROM testdata;",
 PG>         0,
 PG>         NULL,
 PG>         NULL,
 PG>         NULL,
 PG>         NULL,
 PG>         1);

That "1" on the end there indicates that you are requesting binary
format results. But this:

 PG> std::cout << "value is: " << PQgetvalue(res, 0,0) << " length
 PG> is: " << PQgetlength(res,0,0) << std::endl;
 PG> REQUIRE(strcmp(PQgetvalue(res, 0,0), "1234") == 0);

is assuming text format.

The binary result for numeric '1234' will be 10 bytes long and consist
of: 00 01 00 00 00 00 00 00 04 d2:

  0001 = ndigits (meaning: 1 base-10000 digit)
  0000 = weight (first digit is * 10000^0)
  0000 = sign (0 = positive)
  0000 = dscale (0 base-10 digits after the point)
  04d2 = decimal 1234

-- 
Andrew (irc:RhodiumToad)





view thread (5+ messages)  latest in thread

Message-ID: <87mue6xdf1.fsf@news-spur.riddles.org.uk>
Permalink:  ../87mue6xdf1.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87mue6xdf1.fsf@news-spur.riddles.org.uk

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, bartsmink@gmail.com
  Subject: Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
  In-Reply-To: <87mue6xdf1.fsf@news-spur.riddles.org.uk>
  References: <16051-cf9069d07dd1df16@postgresql.org> <87mue6xdf1.fsf@news-spur.riddles.org.uk>

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

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