Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 275AE9FB7E5 for ; Mon, 28 May 2007 19:39:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 48898-04 for ; Mon, 28 May 2007 19:39:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 151659FB799 for ; Mon, 28 May 2007 19:39:16 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l4SMdCrU081638 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 May 2007 16:39:15 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l4SMdCRs066219; Mon, 28 May 2007 16:39:12 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l4SMdB8L066218; Mon, 28 May 2007 16:39:11 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 28 May 2007 16:39:11 -0600 From: Michael Fuhr To: "Y. Ming Lam" Cc: pgsql-interfaces@postgresql.org Subject: Re: PQgetvalue failed to get non-text data under binary format Message-ID: <20070528223911.GA66138@winnie.fuhr.org> References: <46512118.2040105@rogers.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46512118.2040105@rogers.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/58 X-Sequence-Number: 6565 On Mon, May 21, 2007 at 12:33:28AM -0400, Y. Ming Lam wrote: > I am new to PostgreSQL and tried using the libpq C library. I can read > a test table using PQgetvalue for text format, i.e. format = 0. > However, when I experiment with using binary output format, I was unable > to read anything else except result set fiend that is in char(x), > varchar(x), i.e., character string data. [...] > What I got is as follow: > > + + + printing resultset, 2 rows, 8 columns > id: 167772160 name: Amy Who salary: 0.000000 > id: 16777216 name: David Smith salary: 0.000000 > > Which supposed to return: > id: 10 name: Amy Who salary: 150000.00 > id: 1 name: David Smith salary: 350000.00 For numeric types you'll need to convert binary values from network byte order to host byte order (e.g., using ntohl() for 32-bit values). Notice that 167772160 = 0x0a000000 and 16777216 = 0x01000000, which are the values you're expecting except for the reversed byte order. -- Michael Fuhr