return value for PQbinaryTuples

Started by bbheover 16 years ago4 messagesgeneral
Jump to latest
#1bbhe
bbhe_2001@163.com

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.

Are there any documents describe this?

------------------

Regards

Sam

------------------
Regards
Sam

#2Merlin Moncure
mmoncure@gmail.com
In reply to: bbhe (#1)
Re: return value for PQbinaryTuples

On Fri, Nov 27, 2009 at 3:33 AM, bbhe <bbhe_2001@163.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

#3Daniel Verite
daniel@manitou-mail.org
In reply to: Merlin Moncure (#2)
Re: return value for PQbinaryTuples

Merlin Moncure wrote:

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).

You mean 0 (i.e. text, not binary). And with an exception on PQexec("FETCH
c") when c is a binary cursor. In this case the result is binary and
PQbinaryTuples() reflects that.

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

#4Merlin Moncure
mmoncure@gmail.com
In reply to: Daniel Verite (#3)
Re: return value for PQbinaryTuples

On Wed, Dec 2, 2009 at 12:28 PM, Daniel Verite <daniel@manitou-mail.org> wrote:

       Merlin Moncure wrote:

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).

You mean 0 (i.e. text, not binary). And with an exception on PQexec("FETCH
c") when c is a binary cursor. In this case the result is binary and
PQbinaryTuples() reflects that.

quite right! I had completely forgotten about binary cursors (which
are, IMO, a total hack).

merlin

silonet=# declare test_cursor binary cursor with hold for select
1094795585::int;
DECLARE CURSOR
Time: 0.327 ms
silonet=# fetch from test_cursor;
int4
──────
AAAA
(1 row)