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 20100107202128.BB72C63356F@mail.postgresql.org
Whole thread Raw
In response to BUG #5268: PQgetvalue incorrectly returns 0  ("Mike Landis" <mlandis@pnmx.com>)
Responses Re: BUG #5268: PQgetvalue incorrectly returns 0  (Alvaro Herrera <alvherre@commandprompt.com>)
Re: BUG #5268: PQgetvalue incorrectly returns 0  (Mark Kirkwood <mark.kirkwood@catalyst.net.nz>)
List pgsql-bugs
#include <stdio.h>
#include <tchar.h>      // on Vista
#include <libpq-fe.h>   // from: the postgres 8.4 install include directory, for me...
D:\Programs\PostgreSQL\8.4\include

// configure these constants and get a '0' even though the same query produces a '1' in pgAdmin
const char*     pgUser = "us";          // PG user
const char*     pgDbms = "db";          // database
const char*     pgPass = "xyz";     // password
const char*     pgHost = "localhost";   // host domain or IP
const char*     pgTable = "tableName";  // a table that exists in the pgDbms

// on UNIX you can obviously revert the main() declaration to main( int argc, char** argv )
int _tmain( int argc, _TCHAR* argv[] )
{       char    connInfo[128];
        sprintf( connInfo, "host=%s dbname=%s user=%s password=%s",     pgHost, pgDbms, pgUser, pgPass );

        PGconn* conn = PQconnectdb( connInfo );
        if ( PQstatus(conn) == CONNECTION_OK )
        {               // in my case...  SELECT COUNT(*) FROM information_schema.tables WHERE table_name='proxies'
                sprintf( connInfo, "SELECT COUNT(*) FROM information_schema.tables WHERE table_name='%s'",
                        pgTable );
                PGresult*       res = PQexec( conn, connInfo );
                if ( res )
                {       if ( PQresultStatus(res) == PGRES_TUPLES_OK )
                        {       int nTuples = PQntuples(res);
                                int nFields = PQnfields(res);
                                if ( nTuples > 0  &&  nFields > 0 )
                                {       char*   val = PQgetvalue(res,0,0);      // get first column, first field
                                        fprintf( stderr, "val=%s\n", val );
                                }
                        }
                        PQclear( res );                                         // possibly moot
                        res = NULL;
                }
                PQfinish( conn );
        }
        return  0;
}
//--------------------------------------------------------------------
// you'll need to link with.libpq, in my case, that's:   D:\Programs\PostgreSQL\8.4\lib\libpq.lib

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #5267: initdb fails on AIX: could not identify current directory
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #5268: PQgetvalue incorrectly returns 0