Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJIDw-0003ii-4S for pgsql-bugs@arkaria.postgresql.org; Sat, 12 Oct 2019 14:18:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJICv-0001pQ-HN for pgsql-bugs@arkaria.postgresql.org; Sat, 12 Oct 2019 14:17:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJICv-0001p5-8v for pgsql-bugs@lists.postgresql.org; Sat, 12 Oct 2019 14:17:21 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJICs-00023y-M6 for pgsql-bugs@lists.postgresql.org; Sat, 12 Oct 2019 14:17:20 +0000 Received: from [192.168.127.1] (port=56026 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iJICp-00095y-HO; Sat, 12 Oct 2019 14:17:15 +0000 Received: from localhost ([127.0.0.1]:25434 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.1 (FreeBSD)) (envelope-from ) id 1iJICm-0009Df-Fz; Sat, 12 Oct 2019 14:17:12 +0000 From: Andrew Gierth 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 In-Reply-To: <16051-cf9069d07dd1df16@postgresql.org> (PG Bug reporting form's message of "Fri, 11 Oct 2019 22:42:06 +0000") Message-ID: <87mue6xdf1.fsf@news-spur.riddles.org.uk> References: <16051-cf9069d07dd1df16@postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (berkeley-unix) Date: Sat, 12 Oct 2019 15:17:12 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "PG" == PG Bug reporting form 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)