Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10 - Mailing list pgsql-bugs

From Andrew Gierth
Subject Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
Date
Msg-id 87mue6xdf1.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
>>>>> "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)



pgsql-bugs by date:

Previous
From: Bart Smink
Date:
Subject: Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
Next
From: Tom Lane
Date:
Subject: Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10