pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: philip.howell@cit.act.edu.au
To: pgsql-interfaces@postgresql.org
Subject: libpq PQstatus problem
Date: Wed, 14 Mar 2001 14:45:07 +1000
Message-ID: <0103149845.AA984548336@mh-cit.cit.act.edu.au> (raw)

Hi

I'm having problems with the PQstatus function in the libpq library.  It seems
to return CONNECTION_OK when I know that it is not.  I used the following test
program  and method to test it:

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

#include <stdlib.h>
#include <stdio.h>
#include "pgsql/libpq-fe.h"

PGconn *make_conn();

int main (int argc, char *argv[])
{
    PGconn      *conn;

    conn = make_conn();

    while (fgetc(stdin) != 'q')
    {
        printf("Connection status... ");
        if (PQstatus(conn) != CONNECTION_OK) {
            printf("BAD\n");
            PQreset(conn);
        } else {
            printf("OK\n");
        }

    }
    return(0);
}

PGconn *make_conn()
{
    PGconn      *conn;

    conn = PQconnectdb("hostaddr = 161.50.16.173 dbname = squid user = squid
password = squid");
    if (PQstatus(conn) == CONNECTION_BAD)
    {
        fprintf(stderr,"Failed to connect to database\n");
        fprintf(stderr,"%s\n",PQerrorMessage(conn));
        PQfinish(conn);
        exit(1);
    }
    return(conn);
}

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

I ran the program (with my postgreSQL server up and running) and hit <return> a
few times, I got the following expected output:

> 
> Connection status... OK
> 
> Connection status... OK
> 
> Connection status... OK

Then I stopped the network (eth0) on the postgreSQL server and hit <return>
again and still got

> Connection status... OK 

as the output.  However Trying to execute the program with the postgreSQL server
offline resulted in the expected error messages, so it seems that in this case
the status was detected successfully.

SYSTEM INFORMATION:
===================

postgreSQL Server:
Hardware: i386
OS Linux RedHat 6.2
Postgres was installed from RPMs version 7.0.3-2

Client Machine
Hardware: i386
OS: Linux RedHat 6.2 with the following RPMs installed:
postgresql-devel-7.0.3-2
postgresql-7.0.3-2

Regards
Phil

philip.howell@cit.act.edu.au





view thread (4+ messages)  latest in thread

Message-ID: <0103149845.AA984548336@mh-cit.cit.act.edu.au>
Permalink:  ../0103149845.AA984548336@mh-cit.cit.act.edu.au/
Also on:    postgresql.org/message-id/0103149845.AA984548336@mh-cit.cit.act.edu.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: philip.howell@cit.act.edu.au
  Subject: Re: libpq PQstatus problem
  In-Reply-To: <0103149845.AA984548336@mh-cit.cit.act.edu.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox