Skip site navigation (1) Skip section navigation (2)

Re: return value for PQbinaryTuples

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: bbhe <bbhe_2001(at)163(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: return value for PQbinaryTuples
Date: 2009-11-28 18:07:21
Message-ID: b42b73150911281007w58235db7md72d6260b9522fa2@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
On Fri, Nov 27, 2009 at 3:33 AM, bbhe <bbhe_2001(at)163(dot)com> wrote:
> hi all,
>
> I don't why PQbinaryTuples function returns 1
> even the select statement only returns two integer fields.
> Although there are some columns with type bytea in the table.

PQbinaryTuples is basically going to return whatever you passed into
resultformat when you executed the query (in the case of PQexec, it's
going to be 1 always).  The specific types of fields you are querying
is immaterial.  See the documentation for PQexecParams().

If you want data returned in binary you should ask for it that way
(this means not using PQexec to issue queries).  If you are looking
for a broader way of dealing with binary with libpq (especially if you
are using 8.4), you will want to check out libpqtypes (which uses
binary protocol always):

/* send some data */
PGresult *res = PQexecf(conn,
  "INSERT INTO t VALUES (%int4, %text)", 654321, "some text");

/* read some data out of a result */
PQgetf(res, 0, "#int4 #text", "a", &i4, "t", &text);

http://libpqtypes.esilo.com/

merlin

In response to

Responses

pgsql-general by date

Next:From: Adrian KlaverDate: 2009-11-28 19:00:17
Subject: Re: Date with time zone
Previous:From: Tom LaneDate: 2009-11-28 16:45:46
Subject: Re: Strange "bug" in dump ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group