Re: BUG #5268: PQgetvalue incorrectly returns 0 - Mailing list pgsql-bugs
From | Mike Landis |
---|---|
Subject | Re: BUG #5268: PQgetvalue incorrectly returns 0 |
Date | |
Msg-id | 20100107125237.0CF58632AE0@mail.postgresql.org Whole thread Raw |
In response to | Re: BUG #5268: PQgetvalue incorrectly returns 0 (tomas@tuxteam.de) |
Responses |
Re: BUG #5268: PQgetvalue incorrectly returns 0
|
List | pgsql-bugs |
Try the following, where mystring is an extension of std::string... mystring sql( "SELECT COUNT(*) FROM information_schema.tables WHERE table_name=3D'proxies' "); int GetIntFromSQL( mystring& sql ) { // if there's more than o= ne record in the ResultSet, still only returns the first float int retVal =3D -1; PGresult* res =3D GetQueryResult( sql ); if ( res ) { int nTuples =3D PQntuples(res); int nFields =3D PQnfields(res); if ( nTuples > 0 && nFields > 0 ) { char * val =3D PQgetvalue(res,0,0); // get first column, first field retVal =3D atoi( val ); } PQclear( res ); } return retVal; } PGresult* GetQueryResult( mystring& sql ) { // run a query that may return a result set PGresult* res =3D PQexec( conn, sql.c_str() ); if ( res ) { int status =3D PQresultStatus(res); if ( status !=3D PGRES_TUPLES_OK ) { // what happened? fprintf( stderr, "GetQueryResult(%s) -> %s\n", sql.c_str(), PQerrorMessage(conn) ); PQclear( res ); // possibly moot res =3D NULL; } } else { fprintf( stderr, "GetQueryResult: insufficient memory to run: %s\n", sql.c_str() ); throw "GetQueryResult: insufficient memory"; } return res; } At 02:14 AM 1/7/2010, you wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, Jan 07, 2010 at 04:11:03AM +0000, Mike Landis wrote: > > The following bug has been logged online: > > Bug reference: 5268 > Logged by: Mike Landis > Email address: mlandis@pnmx.com > PostgreSQL version: 8.4.1 > Operating system: Vista > Description: PQgetvalue incorrectly returns 0 > Details: > > When I execute the following SQL: > > "SELECT COUNT(*) FROM information_schema.tables WHERE table_name=3D'proxies'" > > in the PGAdmmin 1.10.0, rev 7945-7946 query tool, I get "1" (the correct > answer). When I run the exact same SQL in a C program, I get a result set > with one tuple and one field (so far so good), but when I run > PQgetvalue(resultSet,0,0) I get "0" (wrong answer). > > Am I missing something? You can't do squat in a client program without > PQgetvalue(). Is any sort of regression test being run against libpq > functions? Hm. I don't know for sure, but I'd assume that PGAdmin relies on libpq... > What can I do to get this resolved? Could you show us a more complete test case? That might help in pin-pointing the problem. Regards - -- tom=C3=A1s -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFLRYnoBcgs9XrR2kYRAjV/AJ9+HAZZu5sFKuHw1vp7aZNLKM7ykwCfQ+FX q+NXaFojGP7uS4O/4Km/stM=3D =3DzblK -----END PGP SIGNATURE----- No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.725 / Virus Database: 270.14.127/2603 - Release Date: 01/06/10 02:35:00
pgsql-bugs by date: