newbie libpq question...

Lists: pgsql-interfaces
From: Doug Homoelle <homoelle(at)ll(dot)mit(dot)edu>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: newbie libpq question...
Date: 2004-11-08 22:23:59
Message-ID: 1099952639.2819.8.camel@
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

I'm trying to use the libpq library for the first time and I'm
experiencing what seems to be a very basic problem. When I run the
following:

res = PQexec(conn, "select blah blah blah");
test_int=PQntuples(res);
fprintf(stdout,"number of rows: %f\n",test_int);
test_int=PQnfields(res);
fprintf(stdout,"number of cols: %f\n",test_int);

where "blah blah blah" is the selection criteria, I get zero rows and
zero columns. When I do the exact same "select" query through the psql
interface I get 547 rows and 3 columns. I've checked that
PQresultStatus = PGRES_TUPLES_OK, so it seems like it completed the
command correctly. I'm new to postgres and I haven't used C in a long
while so I'm a little rusty there. Am I missing something obvious?

thanks in advance for any insight,
dh


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Doug Homoelle <homoelle(at)ll(dot)mit(dot)edu>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: newbie libpq question...
Date: 2004-11-14 01:23:41
Message-ID: 20041114012339.GA73251@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Mon, Nov 08, 2004 at 05:23:59PM -0500, Doug Homoelle wrote:
>
> res = PQexec(conn, "select blah blah blah");
> test_int=PQntuples(res);
> fprintf(stdout,"number of rows: %f\n",test_int);
> test_int=PQnfields(res);
> fprintf(stdout,"number of cols: %f\n",test_int);
>
> where "blah blah blah" is the selection criteria, I get zero rows and
> zero columns.

You're using floating-point (%f) conversions to print integers; use
%d or %i instead. Some compilers have options to warn you of such
mistakes -- with gcc, for example, you can use -Wall.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/